first commit

This commit is contained in:
2025-01-06 20:47:25 +01:00
commit 3bdbd78c2f
25591 changed files with 3586440 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
<?php
namespace Empik\Marketplace\Handler;
use Context;
use EmpikMarketplace;
use Empik\Marketplace\Adapter\ToolsAdapter;
use Empik\Marketplace\Processor\OrderProcessor;
use Empik\Marketplace\Processor\ExportProductProcessor;
use Empik\Marketplace\Processor\ExportOfferProcessor;
use Empik\Marketplace\Exception\InvalidActionException;
class CronJobsHandler
{
const ACTION_EXPORT_PRODUCTS = 'exportProducts';
const ACTION_EXPORT_OFFERS = 'exportOffers';
const ACTION_IMPORT_ORDERS = 'importOrders';
const ACTIONS = [
self::ACTION_EXPORT_PRODUCTS,
self::ACTION_EXPORT_OFFERS,
self::ACTION_IMPORT_ORDERS,
];
/** @var Context */
protected $context;
/** @var EmpikMarketplace */
protected $module;
/** @var ToolsAdapter */
protected $tools;
/** @var ExportProductProcessor */
protected $exportProductProcessor;
/** @var ExportOfferProcessor */
protected $exportOfferProcessor;
/** @var OrderProcessor */
protected $orderProcessor;
public function __construct(
EmpikMarketplace $module,
ToolsAdapter $tools,
ExportProductProcessor $exportProductProcessor,
ExportOfferProcessor $exportOfferProcessor,
OrderProcessor $orderProcessor
) {
$this->module = $module;
$this->tools = $tools;
$this->exportProductProcessor = $exportProductProcessor;
$this->exportOfferProcessor = $exportOfferProcessor;
$this->orderProcessor = $orderProcessor;
$this->context = Context::getContext();
}
public function handle($action)
{
set_time_limit(0);
switch ($action) {
case self::ACTION_EXPORT_PRODUCTS:
$this->exportProductProcessor->process();
break;
case self::ACTION_EXPORT_OFFERS:
$this->exportOfferProcessor->process();
file_put_contents('logs/empik.log', date( 'Y-m-d H:i:s' ) . ' - export offers' . PHP_EOL, FILE_APPEND );
break;
case self::ACTION_IMPORT_ORDERS:
$this->orderProcessor->process();
break;
default:
throw new InvalidActionException();
}
}
public function getAvailableActionsUrls()
{
$urls = [];
foreach (self::ACTIONS as $action) {
$urls[$action] = $this->getActionUrl($action);
}
return $urls;
}
public function checkToken($token)
{
return $token === $this->getToken();
}
protected function getActionUrl($action)
{
return $this->context->link->getModuleLink($this->module->name, 'cron', [
'action' => $action,
'token' => $this->getToken(),
]);
}
protected function getToken()
{
return $this->tools->hash($this->module->name . '_cron');
}
}