images = DatabaseConnection::i()->getContext()->table("photos"); parent::__construct(); } protected function configure(): void { $this->setDescription("Create resized versions of images") ->setHelp("This command allows you to resize all your images after configuration change") ->addOption("upgrade-only", "U", InputOption::VALUE_NEGATABLE, "Only upgrade images which aren't resized?"); } protected function execute(InputInterface $input, OutputInterface $output): int { $header = $output->section(); $counter = $output->section(); $header->writeln([ "Image Rebuild Utility", "=====================", "", ]); $filter = ["deleted" => false]; if($input->getOption("upgrade-only")) $filter["sizes"] = NULL; $selection = $this->images->select("id")->where($filter); $totalPics = $selection->count(); $header->writeln([ "Total of $totalPics images found.", "", ]); $count = 0; $avgTime = NULL; $begin = new \DateTimeImmutable("now"); foreach($selection as $idHolder) { $start = microtime(true); $photo = (new Photos)->get($idHolder->id); $photo->getSizes(true, true); $photo->getDimensions(); $timeConsumed = microtime(true) - $start; if(!$avgTime) $avgTime = $timeConsumed; else $avgTime = ($avgTime + $timeConsumed) / 2; $eta = $begin->getTimestamp() + ceil($totalPics * $avgTime); $int = (new \DateTimeImmutable("now"))->diff(new \DateTimeImmutable("@$eta")); $int = $int->d . "d" . $int->h . "h" . $int->i . "m" . $int->s . "s"; $pct = floor(100 * ($count / $totalPics)); $counter->overwrite("Processed " . ++$count . " images... ($pct% $int left)"); } $counter->overwrite("Processing finished :3"); return Command::SUCCESS; } }