Files
orderPRO/archive/2026-03-02_users-only-reset/bin/cron.php
Jacek Pyziak c489891d15 Add Orders and Order Status repositories with pagination and management features
- Implemented OrdersRepository for handling order data with pagination, filtering, and sorting capabilities.
- Added methods for retrieving order status options, quick stats, and detailed order information.
- Created OrderStatusRepository for managing order status groups and statuses, including CRUD operations and sorting.
- Introduced a bootstrap file for test environment setup and autoloading.
2026-03-03 01:32:28 +01:00

116 lines
4.0 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\Cron\ShopProOrderStatusSyncHandler;
use App\Modules\Cron\ShopProOrdersImportHandler;
use App\Modules\Cron\ShopProOfferTitlesRefreshHandler;
use App\Modules\Orders\OrderImportService;
use App\Modules\Orders\OrderStatusSyncService;
use App\Modules\Orders\OrdersRepository;
use App\Modules\ProductLinks\ChannelOffersRepository;
use App\Modules\ProductLinks\OfferImportService;
use App\Modules\ProductLinks\ProductLinksRepository;
use App\Modules\Settings\IntegrationRepository;
use App\Modules\Settings\OrderStatusMappingRepository;
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
);
$offerTitlesRefreshHandler = new ShopProOfferTitlesRefreshHandler(
$integrationRepository,
$offerImportService
);
$ordersRepository = new OrdersRepository($pdo);
$orderImportService = new OrderImportService(
$integrationRepository,
$ordersRepository,
$shopProClient,
$pdo
);
$orderStatusMappings = new OrderStatusMappingRepository($pdo);
$orderStatusSyncService = new OrderStatusSyncService(
$integrationRepository,
$ordersRepository,
$orderStatusMappings,
$shopProClient,
$pdo
);
$ordersImportHandler = new ShopProOrdersImportHandler($orderImportService);
$orderStatusSyncHandler = new ShopProOrderStatusSyncHandler($orderStatusSyncService);
$processor->registerHandler(CronJobType::PRODUCT_LINKS_HEALTH_CHECK, $linksHealthCheckHandler);
$processor->registerHandler(CronJobType::SHOPPRO_ORDERS_IMPORT, $ordersImportHandler);
$processor->registerHandler(CronJobType::SHOPPRO_ORDER_STATUS_SYNC, $orderStatusSyncHandler);
$processor->registerHandler(CronJobType::SHOPPRO_OFFER_TITLES_REFRESH, $offerTitlesRefreshHandler);
$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);
}