feat(v1.5): complete phases 40-43 workflow cleanup

This commit is contained in:
2026-03-25 22:46:51 +01:00
parent b8dda81e7b
commit 3610571949
37 changed files with 1557 additions and 259 deletions

View File

@@ -3,7 +3,15 @@ declare(strict_types=1);
namespace App\Modules\Cron;
use App\Core\I18n\Translator;
use App\Core\Support\Logger;
use App\Core\View\Template;
use App\Modules\Accounting\ReceiptRepository;
use App\Modules\Automation\AutomationRepository;
use App\Modules\Automation\AutomationService;
use App\Modules\Email\AttachmentGenerator;
use App\Modules\Email\EmailSendingService;
use App\Modules\Email\VariableResolver;
use App\Modules\Orders\OrderImportRepository;
use App\Modules\Orders\OrdersRepository;
use App\Modules\Settings\AllegroApiClient;
@@ -15,13 +23,21 @@ use App\Modules\Settings\AllegroOrderSyncStateRepository;
use App\Modules\Settings\AllegroStatusMappingRepository;
use App\Modules\Settings\AllegroStatusSyncService;
use App\Modules\Settings\AllegroTokenManager;
use App\Modules\Settings\ApaczkaApiClient;
use App\Modules\Settings\ApaczkaIntegrationRepository;
use App\Modules\Settings\CompanySettingsRepository;
use App\Modules\Settings\EmailMailboxRepository;
use App\Modules\Settings\EmailTemplateRepository;
use App\Modules\Settings\InpostIntegrationRepository;
use App\Modules\Settings\IntegrationSecretCipher;
use App\Modules\Settings\ReceiptConfigRepository;
use App\Modules\Settings\ShopproApiClient;
use App\Modules\Settings\ShopproIntegrationsRepository;
use App\Modules\Settings\ShopproOrderMapper;
use App\Modules\Settings\ShopproOrdersSyncService;
use App\Modules\Settings\ShopproOrderSyncStateRepository;
use App\Modules\Settings\ShopproProductImageResolver;
use App\Modules\Settings\ShopproPaymentStatusSyncService;
use App\Modules\Settings\ShopproProductImageResolver;
use App\Modules\Settings\ShopproStatusMappingRepository;
use App\Modules\Settings\ShopproStatusSyncService;
use App\Modules\Shipments\AllegroTrackingService;
@@ -29,17 +45,16 @@ use App\Modules\Shipments\ApaczkaTrackingService;
use App\Modules\Shipments\InpostTrackingService;
use App\Modules\Shipments\ShipmentPackageRepository;
use App\Modules\Shipments\ShipmentTrackingRegistry;
use App\Modules\Settings\ApaczkaApiClient;
use App\Modules\Settings\ApaczkaIntegrationRepository;
use App\Modules\Settings\InpostIntegrationRepository;
use PDO;
final class CronHandlerFactory
{
public function __construct(
private readonly PDO $db,
private readonly string $integrationSecret
) {}
private readonly string $integrationSecret,
private readonly string $basePath
) {
}
public function build(CronRepository $cronRepository, Logger $logger): CronRunner
{
@@ -48,14 +63,17 @@ final class CronHandlerFactory
$tokenManager = new AllegroTokenManager($integrationRepository, $oauthClient);
$apiClient = new AllegroApiClient();
$statusMappingRepository = new AllegroStatusMappingRepository($this->db);
$ordersRepository = new OrdersRepository($this->db);
$orderImportService = new AllegroOrderImportService(
$integrationRepository,
$tokenManager,
$apiClient,
new OrderImportRepository($this->db),
$statusMappingRepository,
new OrdersRepository($this->db)
$ordersRepository
);
$ordersSyncService = new AllegroOrdersSyncService(
$integrationRepository,
new AllegroOrderSyncStateRepository($this->db),
@@ -63,6 +81,7 @@ final class CronHandlerFactory
$apiClient,
$orderImportService
);
$shopproIntegrationsRepo = new ShopproIntegrationsRepository($this->db, $this->integrationSecret);
$shopproApiClient = new ShopproApiClient();
$shopproSyncService = new ShopproOrdersSyncService(
@@ -71,18 +90,21 @@ final class CronHandlerFactory
$shopproApiClient,
new OrderImportRepository($this->db),
new ShopproStatusMappingRepository($this->db),
new OrdersRepository($this->db),
$ordersRepository,
new ShopproOrderMapper(),
new ShopproProductImageResolver($shopproApiClient)
);
$shopproStatusSyncService = new ShopproStatusSyncService($shopproIntegrationsRepo, $shopproSyncService);
$shopproPaymentSyncService = new ShopproPaymentStatusSyncService(
$shopproIntegrationsRepo,
new ShopproApiClient(),
new OrdersRepository($this->db),
$ordersRepository,
$this->db
);
$automationService = $this->buildAutomationService($ordersRepository);
return new CronRunner(
$cronRepository,
$logger,
@@ -124,9 +146,45 @@ final class CronHandlerFactory
$tokenManager
),
]),
new ShipmentPackageRepository($this->db)
new ShipmentPackageRepository($this->db),
$automationService
),
]
);
}
private function buildAutomationService(OrdersRepository $ordersRepository): AutomationService
{
$automationRepository = new AutomationRepository($this->db);
$companySettingsRepository = new CompanySettingsRepository($this->db);
$emailTemplateRepository = new EmailTemplateRepository($this->db);
$emailMailboxRepository = new EmailMailboxRepository(
$this->db,
new IntegrationSecretCipher($this->integrationSecret)
);
$template = new Template(
$this->basePath . '/resources/views',
new Translator($this->basePath . '/resources/lang', 'pl')
);
$emailService = new EmailSendingService(
$this->db,
$ordersRepository,
$emailTemplateRepository,
$emailMailboxRepository,
new VariableResolver(),
new AttachmentGenerator(
new ReceiptRepository($this->db),
new ReceiptConfigRepository($this->db),
$template
)
);
return new AutomationService(
$automationRepository,
$emailService,
$ordersRepository,
$companySettingsRepository
);
}
}