85 lines
2.6 KiB
PHP
85 lines
2.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use App\Core\Database\ConnectionFactory;
|
|
use App\Core\Support\Env;
|
|
use App\Modules\Cron\CronJobProcessor;
|
|
use App\Modules\Cron\CronJobRepository;
|
|
use App\Modules\Cron\CronJobType;
|
|
use App\Modules\Cron\ProductLinksHealthCheckHandler;
|
|
use App\Modules\ProductLinks\ChannelOffersRepository;
|
|
use App\Modules\ProductLinks\OfferImportService;
|
|
use App\Modules\ProductLinks\ProductLinksRepository;
|
|
use App\Modules\Settings\IntegrationRepository;
|
|
use App\Modules\Settings\ShopProClient;
|
|
|
|
$basePath = dirname(__DIR__);
|
|
$vendorAutoload = $basePath . '/vendor/autoload.php';
|
|
|
|
if (is_file($vendorAutoload)) {
|
|
require $vendorAutoload;
|
|
} else {
|
|
spl_autoload_register(static function (string $class) use ($basePath): void {
|
|
$prefix = 'App\\';
|
|
if (!str_starts_with($class, $prefix)) {
|
|
return;
|
|
}
|
|
|
|
$relative = substr($class, strlen($prefix));
|
|
$file = $basePath . '/src/' . str_replace('\\', '/', $relative) . '.php';
|
|
if (is_file($file)) {
|
|
require $file;
|
|
}
|
|
});
|
|
}
|
|
|
|
Env::load($basePath . '/.env');
|
|
|
|
/** @var array<string, mixed> $dbConfig */
|
|
$dbConfig = require $basePath . '/config/database.php';
|
|
/** @var array<string, mixed> $appConfig */
|
|
$appConfig = require $basePath . '/config/app.php';
|
|
|
|
$limit = 20;
|
|
foreach ($argv as $argument) {
|
|
if (!str_starts_with((string) $argument, '--limit=')) {
|
|
continue;
|
|
}
|
|
|
|
$limitValue = (int) substr((string) $argument, strlen('--limit='));
|
|
if ($limitValue > 0) {
|
|
$limit = min(200, $limitValue);
|
|
}
|
|
}
|
|
|
|
try {
|
|
$pdo = ConnectionFactory::make($dbConfig);
|
|
|
|
$cronJobs = new CronJobRepository($pdo);
|
|
$processor = new CronJobProcessor($cronJobs);
|
|
|
|
$integrationRepository = new IntegrationRepository(
|
|
$pdo,
|
|
(string) (($appConfig['integrations']['secret'] ?? '') ?: '')
|
|
);
|
|
$offersRepository = new ChannelOffersRepository($pdo);
|
|
$linksRepository = new ProductLinksRepository($pdo);
|
|
$shopProClient = new ShopProClient();
|
|
$offerImportService = new OfferImportService($shopProClient, $offersRepository, $pdo);
|
|
$linksHealthCheckHandler = new ProductLinksHealthCheckHandler(
|
|
$integrationRepository,
|
|
$offerImportService,
|
|
$linksRepository,
|
|
$offersRepository
|
|
);
|
|
|
|
$processor->registerHandler(CronJobType::PRODUCT_LINKS_HEALTH_CHECK, $linksHealthCheckHandler);
|
|
|
|
$result = $processor->run($limit);
|
|
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL;
|
|
} catch (\Throwable $exception) {
|
|
fwrite(STDERR, '[error] ' . $exception->getMessage() . PHP_EOL);
|
|
exit(1);
|
|
}
|