<?php
declare(strict\_types=1);
namespace Nextag\Storemanager\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/\*\*
\* Class StoremanagerCommand
\* @package Nextag\Storemanager\Command
\*/
class StoremanagerCommand extends Command
{
protected $timestamp;
protected $lastSync = null;
protected $log;
protected $config;
public function \_\_construct(\Nextag\Storemanager\Helper\Log $log, \Shopware\Core\System\SystemConfig\SystemConfigService $config)
{
parent::\_\_construct();
$this-\>log = $log;
$this-\>config = $config;
}
protected function configure(): void
{
$this-\>setName('nextag:storemanager:execute');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this-\>log-\>info("Storemanager started");
$this-\>truncateversiontables();
$this-\>deleteCarts();
$this-\>log-\>info("Storemanager finished");
}
protected function truncateversiontables()
{
if ($this-\>config-\>get("NextagStoremanager.config.cleanUpVersionCommitTables")) {
$this-\>log-\>info("TruncateversiontablesCommand started");
$connectionParams = array(
'url' =\> getenv("DATABASE\_URL"),
);
/\*\* @var \Doctrine\DBAL\Connection $conn \*/
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
$query = "Delete from version\_commit";
$conn-\>executeQuery($query);
$query = "Delete from version\_commit\_data";
$conn-\>executeQuery($query);
$this-\>log-\>info("TruncateversiontablesCommand finished");
}
}
protected function deleteCarts()
{
if ($this-\>config-\>get("NextagStoremanager.config.deleteCarts")) {
$this-\>log-\>info("deleteCarts started");
$connectionParams = array(
'url' =\> getenv("DATABASE\_URL"),
);
/\*\* @var \Doctrine\DBAL\Connection $conn \*/
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
$query = "Delete from cart";
$conn-\>executeQuery($query);
$this-\>log-\>info("deleteCarts finished");
}
}
}