added PHPUinit

This commit is contained in:
2022-12-28 12:39:02 +01:00
parent 97a4f63946
commit cb3cacb2dd
84 changed files with 18549 additions and 824 deletions

View File

@@ -6,6 +6,7 @@ use App\Repository\UserRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -22,27 +23,23 @@ class CronRunCommand extends Command
protected function configure(): void
{
/*
$this
->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
;
*/
//$this->addOption(name: 'verbose', shortcut: null, mode: InputOption::VALUE_NONE, description: 'Option description');
// ->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
}
protected function execute(InputInterface $input, OutputInterface $output): int
public function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io = new SymfonyStyle(input: $input, output: $output);
$verbose = $input->getOption('verbose');
$verbose = $input->getOption(name: 'verbose');
$staleCount = $this->deleteStaleAvatars();
if ($verbose) {
if ($staleCount > 0) {
$io->writeln("There were " . $staleCount . " stale avatars.");
$io->writeln(messages: "There were " . $staleCount . " stale avatars.");
} else {
$io->writeln("There were no stale avatars younger than 24 hours.");
$io->writeln(messages: "There were no stale avatars younger than 24 hours.");
}
}
@@ -51,18 +48,18 @@ class CronRunCommand extends Command
private function deleteStaleAvatars(): int
{
$avatarDir = dirname(__DIR__, 2) . '/public/uploads/avatars';
$avatarDir = dirname(path: __DIR__, levels: 2) . '/public/uploads/avatars';
$keepTime = 86400; // 24 hours
$deletedFiles = 0;
foreach (glob($avatarDir . '/*') as $entry) {
$filectime = filectime($entry);
foreach (glob(pattern: $avatarDir . '/*') as $entry) {
$filectime = filectime(filename: $entry);
if ($filectime && $filectime + $keepTime < time()) {
// check if it in use
if ($user = $this->userRepository->findOneBy(['avatar' => basename($entry)])) {
echo basename($entry) . " is in use by: " . $user->getUserIdentifier() . PHP_EOL;
if ($user = $this->userRepository->findOneBy(['avatar' => basename(path: $entry)])) {
echo basename(path: $entry) . " is in use by: " . $user->getUserIdentifier() . PHP_EOL;
}
unlink($entry);
unlink(filename: $entry);
$deletedFiles++;
}