| 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 : |
<?php
declare(strict_types=1);
namespace App\Console;
use App\Controller\Api\ApiController;
use App\Model\ErrorsModel;
use App\Model\MigrateMagentoCategoryModel;
use DateTime;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
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 MigrateCategoryCreateCommand extends Command
{
protected function configure(): void
{
$this
->setName('migrate:category:create')
->setDescription('Migrate Catalog Category from Magento')
->setHelp('This command allows you to load catalog category to DB Magento');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
new ApiController();
$migracion = new MigrateMagentoCategoryModel();
$categories = $migracion->getParentCategories();
if ($categories->num_rows > 0) :
try {
$start = new DateTime();
$output->writeln('Start: ' . date('Y-m-d H:i:s', time()));
foreach ($categories->rows as $category) {
$category['name'] = $category['name_1'] == NULL ? $category['name_0'] : $category['name_1'];
$status = $category['status_1'] == NULL ? $category['status_0'] : $category['status_1'];
if ($status == 1) {
$migracion->insertCategoria((array) $category, (int) 0);
$firstChilds = $migracion->getChildCategories((int) $category['entity_id']);
if ($firstChilds->num_rows > 0) {
foreach ($firstChilds->rows as $firstChild) {
$firstChild['name'] = $firstChild['name_1'] == NULL ?
$firstChild['name_0'] :
$firstChild['name_1'];
$statusFirst = $firstChild['status_1'] == NULL ?
$firstChild['status_0'] :
$firstChild['status_1'];
if ($statusFirst == 1) {
$migracion->insertCategoria(
(array) $firstChild,
(int) $category['entity_id']
);
$secondChilds = $migracion->getChildCategories((int) $firstChild['entity_id']);
if ($secondChilds->num_rows > 0) {
foreach ($secondChilds->rows as $secondChild) {
$secondChild['name'] = $secondChild['name_1'] == NULL ?
$secondChild['name_0'] :
$secondChild['name_1'];
$statusSecond = $secondChild['status_1'] == NULL ?
$secondChild['status_0'] :
$secondChild['status_1'];
if ($statusSecond == 1) {
$migracion->insertCategoria(
(array) $secondChild,
(int) $firstChild['entity_id']
);
}
}
}
}
}
}
}
}
$end = new DateTime();
$output->writeln('End: ' . date('Y-m-d H:i:s', time()));
$total = $start->diff($end);
$output->writeln('Time: ' . $total->format('%H:%I:%S'));
} catch (Exception $e) {
$this->debugError($e);
} else :
$output->writeln('No new data');
endif;
return 0;
}
public function logError(object $error): void
{
$log = new Logger('MigrateBrandCreate');
$log->pushHandler(new StreamHandler(__DIR__ . '/../../logs/brands/migrate-error.log', Logger::ERROR));
$log->error($error);
}
public function logInfo(array $info)
{
}
public function debugError(object $error, OutputInterface $output)
{
$output->writeln('error');
$output->writeln($e);
}
}