feat(02-bug-fixes): extract CronHandlerFactory, complete Phase 2
Phase 2 complete (4/4 plans): - Plan 02-01: Fix dead ZPL page size condition in AllegroShipmentService - Plan 02-02: Add time-based cursor to AllegroStatusSyncService - Plan 02-03: Fix ShopproOrdersSyncService using wrong state repository - Plan 02-04: Extract CronHandlerFactory as single cron composition point Plan 02-04 specifics: - New CronHandlerFactory builds complete cron object graph - Application::maybeRunCronOnWeb() reduced from 80+ to ~20 lines - bin/cron.php reduced from 123 to 26 lines - Fixed 2 bugs: AllegroOAuthClient→AllegroTokenManager, AllegroOrderSyncStateRepository→ShopproOrderSyncStateRepository Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
103
src/Modules/Cron/CronHandlerFactory.php
Normal file
103
src/Modules/Cron/CronHandlerFactory.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Cron;
|
||||
|
||||
use App\Core\Support\Logger;
|
||||
use App\Modules\Orders\OrderImportRepository;
|
||||
use App\Modules\Orders\OrdersRepository;
|
||||
use App\Modules\Settings\AllegroApiClient;
|
||||
use App\Modules\Settings\AllegroIntegrationRepository;
|
||||
use App\Modules\Settings\AllegroOAuthClient;
|
||||
use App\Modules\Settings\AllegroOrderImportService;
|
||||
use App\Modules\Settings\AllegroOrdersSyncService;
|
||||
use App\Modules\Settings\AllegroOrderSyncStateRepository;
|
||||
use App\Modules\Settings\AllegroStatusMappingRepository;
|
||||
use App\Modules\Settings\AllegroStatusSyncService;
|
||||
use App\Modules\Settings\AllegroTokenManager;
|
||||
use App\Modules\Settings\ShopproApiClient;
|
||||
use App\Modules\Settings\ShopproIntegrationsRepository;
|
||||
use App\Modules\Settings\ShopproOrdersSyncService;
|
||||
use App\Modules\Settings\ShopproOrderSyncStateRepository;
|
||||
use App\Modules\Settings\ShopproPaymentStatusSyncService;
|
||||
use App\Modules\Settings\ShopproStatusMappingRepository;
|
||||
use App\Modules\Settings\ShopproStatusSyncService;
|
||||
use PDO;
|
||||
|
||||
final class CronHandlerFactory
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PDO $db,
|
||||
private readonly string $integrationSecret
|
||||
) {}
|
||||
|
||||
public function build(CronRepository $cronRepository, Logger $logger): CronRunner
|
||||
{
|
||||
$integrationRepository = new AllegroIntegrationRepository($this->db, $this->integrationSecret);
|
||||
$oauthClient = new AllegroOAuthClient();
|
||||
$tokenManager = new AllegroTokenManager($integrationRepository, $oauthClient);
|
||||
$apiClient = new AllegroApiClient();
|
||||
$statusMappingRepository = new AllegroStatusMappingRepository($this->db);
|
||||
$orderImportService = new AllegroOrderImportService(
|
||||
$integrationRepository,
|
||||
$tokenManager,
|
||||
$apiClient,
|
||||
new OrderImportRepository($this->db),
|
||||
$statusMappingRepository,
|
||||
new OrdersRepository($this->db)
|
||||
);
|
||||
$ordersSyncService = new AllegroOrdersSyncService(
|
||||
$integrationRepository,
|
||||
new AllegroOrderSyncStateRepository($this->db),
|
||||
$tokenManager,
|
||||
$apiClient,
|
||||
$orderImportService
|
||||
);
|
||||
$shopproIntegrationsRepo = new ShopproIntegrationsRepository($this->db, $this->integrationSecret);
|
||||
$shopproSyncService = new ShopproOrdersSyncService(
|
||||
$shopproIntegrationsRepo,
|
||||
new ShopproOrderSyncStateRepository($this->db),
|
||||
new ShopproApiClient(),
|
||||
new OrderImportRepository($this->db),
|
||||
new ShopproStatusMappingRepository($this->db),
|
||||
new OrdersRepository($this->db)
|
||||
);
|
||||
$shopproStatusSyncService = new ShopproStatusSyncService($shopproIntegrationsRepo, $shopproSyncService);
|
||||
$shopproPaymentSyncService = new ShopproPaymentStatusSyncService(
|
||||
$shopproIntegrationsRepo,
|
||||
new ShopproApiClient(),
|
||||
new OrdersRepository($this->db),
|
||||
$this->db
|
||||
);
|
||||
|
||||
return new CronRunner(
|
||||
$cronRepository,
|
||||
$logger,
|
||||
[
|
||||
'allegro_token_refresh' => new AllegroTokenRefreshHandler(
|
||||
$integrationRepository,
|
||||
$oauthClient
|
||||
),
|
||||
'allegro_orders_import' => new AllegroOrdersImportHandler(
|
||||
$ordersSyncService
|
||||
),
|
||||
'allegro_status_sync' => new AllegroStatusSyncHandler(
|
||||
new AllegroStatusSyncService(
|
||||
$cronRepository,
|
||||
$orderImportService,
|
||||
$this->db
|
||||
)
|
||||
),
|
||||
'shoppro_orders_import' => new ShopproOrdersImportHandler(
|
||||
$shopproSyncService
|
||||
),
|
||||
'shoppro_order_status_sync' => new ShopproStatusSyncHandler(
|
||||
$shopproStatusSyncService
|
||||
),
|
||||
'shoppro_payment_status_sync' => new ShopproPaymentStatusSyncHandler(
|
||||
$shopproPaymentSyncService
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user