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

declare(strict_types=1);

namespace App\Console;

use App\Controller\Api\ApiController;
use App\Model\ErrorsModel;
use App\Model\BlogModel;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Mosaico\BigCommerce\BaseApi;
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 ContentBlogUpdateCommand extends Command
{
    protected function configure(): void
    {
        $this
            ->setName('content:blog:update')
            ->setDescription('Update Blog Post BigCommerce Post')
            ->setHelp('This command allows you to update BigCommerce post');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        new ApiController();
        $blogModel = new BlogModel();
        $errorsModel = new ErrorsModel();
        $errorData = [];
        $httpMethod = 'PUT';
        $posts = (object) $blogModel->getPostsUpdate();
        $array = [];

        if ($posts->num_rows > 0) :
            $client = new BaseApi();
            foreach ($posts->rows as $value) {
                $url_name = (string) substr($value['url'], strrpos($value['url'], '/'));
                $url_name = str_replace('/', '', $url_name);
                $download_image = $value['image_url'];
                $output->writeln('url name' . $url_name);

                // Store the original filename
                $original_name = basename($download_image); // "img1.jpg"
                $output->writeln('original name' . $original_name);
                // Original extension by string manipulation
                $original_extension = (string) substr($original_name, strrpos($original_name, '.')); // ".jpg"
                $output->writeln('original extension' . $original_extension);
                
                $types = array(
                  'image/jpeg' => '.jpg',
                  'image/png' => '.png',
                  'image/gif' => '.gif'
                  // Other types as needed...
                );
                //print_r($img);
                
                $original_name = str_replace('%20', ' ', $original_name);
                $original_name = str_replace('%28', '(', $original_name);
                $original_name = str_replace('%29', ')', $original_name);
                $image_path = '/product_images/uploaded_images/';
                $image_name =  $url_name . $original_extension;
                $image_url = $image_path . $image_name;
                $output->writeln('image: ' . $image_url);

                $array = [
                    'is_published' => true,
                    'thumbnail_path' => $image_url
                ];
                $output->writeln('method: ' . $httpMethod);
                $output->writeln('blog/posts/' . $value['id_bigcommerce']);
                try {
                    $handler = HandlerStack::create();
                    $tapMiddleware = Middleware::tap(function ($request) {
                        echo $request->getBody() . "\r\n";
                    });
                    $response = $client->api()->request($httpMethod, 'blog/posts/' . $value['id_bigcommerce'], [
                        'headers' => [
                            'X-Auth-Token' => $client->token(),
                            'Accept' => 'application/json',
                        ],
                        'content-type' => 'application/json',
                        'json' => $array,
                        'handler' => $tapMiddleware($handler),
                    ]);
                    $body = $response->getBody();
                    $post = json_decode((string) $body, true);
                    print_r($post);
                    //$post = $response->getBody();
                    //return 0;
                    if ($post) {
                        $blogModel->updateThumbnailBigcommerce(
                            (int) $value['id_blog'],
                            (string) $image_url
                        );
                        $this->logInfo([
                            'status' => $response->getStatusCode(),
                            'image' => $image_url,
                            'id' => $post['id'],
                        ]);
                    }
                    $output->writeln($value['id_blog'] . '-' . $image_url);
                } catch (\GuzzleHttp\Exception\ClientException $e) {
                    $response = $e->getResponse();
                    $error = json_decode((string) $response->getBody());
                    $error_string = '[' . date('y-m-d h:i:s') . '] updateBlog.ERROR: ' . (string) $response->getBody();
                    //$this->logError($error, $value);
                    print_r($error);
                    $blogModel->updateStatusErrorBigcommerce(
                        (int) $value['id_blog'],
                        (int) 2,
                        (string) addslashes($error_string)
                    );

                    $output->writeln($error_string);

                    $arrayErrors = (array) $error->errors;
                    $errorData['id_api'] = 3;
                    $errorData['id_resource'] = $value['id_blog'];
                    $errorData['request_method'] = $httpMethod;
                    $errorData['status_code'] = $error->status;
                    $errorData['title'] = addslashes($error->title);
                    $errorData['detail'] = addslashes(array_key_first($arrayErrors) .
                    ' - ' . reset($arrayErrors));
                    $errorsModel->addResponseError($errorData);
                }
                
            }
        else :
            $output->writeln('No new data');
        endif;
        return 0;
    }

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

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

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

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

    public function debugError(object $error, OutputInterface $output)
    {
        $output->writeln('error');
        $output->writeln($error->message);
        $output->writeln($error->details->conflict_reason);
        $output->writeln('errorEof');
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit