update
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Core\Http\Request;
|
||||
use App\Core\Http\Response;
|
||||
use App\Modules\Auth\AuthController;
|
||||
use App\Modules\Auth\AuthMiddleware;
|
||||
use App\Modules\Cron\CronHandlerFactory;
|
||||
use App\Modules\Cron\CronRepository;
|
||||
use App\Modules\Orders\OrdersController;
|
||||
use App\Modules\Orders\OrderImportRepository;
|
||||
@@ -50,6 +51,7 @@ use App\Modules\Accounting\ReceiptRepository;
|
||||
use App\Modules\Automation\AutomationController;
|
||||
use App\Modules\Automation\AutomationRepository;
|
||||
use App\Modules\Automation\AutomationService;
|
||||
use App\Modules\Automation\AutomationExecutionLogRepository;
|
||||
use App\Modules\Settings\CronSettingsController;
|
||||
use App\Modules\Settings\DeliveryStatusMappingController;
|
||||
use App\Modules\Settings\SettingsController;
|
||||
@@ -229,14 +231,16 @@ return static function (Application $app): void {
|
||||
$emailMailboxRepository
|
||||
);
|
||||
$automationRepository = new AutomationRepository($app->db());
|
||||
$automationExecutionLogRepository = new AutomationExecutionLogRepository($app->db());
|
||||
$automationController = new AutomationController(
|
||||
$template,
|
||||
$translator,
|
||||
$auth,
|
||||
$automationRepository,
|
||||
$automationExecutionLogRepository,
|
||||
$receiptConfigRepository
|
||||
);
|
||||
$variableResolver = new VariableResolver();
|
||||
$variableResolver = new VariableResolver($shipmentPackageRepositoryForOrders);
|
||||
$attachmentGenerator = new AttachmentGenerator($receiptRepository, $receiptConfigRepository, $template);
|
||||
$emailSendingService = new EmailSendingService(
|
||||
$app->db(),
|
||||
@@ -248,6 +252,7 @@ return static function (Application $app): void {
|
||||
);
|
||||
$automationService = new AutomationService(
|
||||
$automationRepository,
|
||||
$automationExecutionLogRepository,
|
||||
$emailSendingService,
|
||||
new OrdersRepository($app->db()),
|
||||
$companySettingsRepository,
|
||||
@@ -316,11 +321,67 @@ return static function (Application $app): void {
|
||||
);
|
||||
$authMiddleware = new AuthMiddleware($auth);
|
||||
|
||||
$publicCronHandler = static function (Request $request) use ($app, $cronRepository): Response {
|
||||
$token = trim((string) $request->input('token', ''));
|
||||
if ($token === '') {
|
||||
$token = trim((string) $request->input('tokenValue', ''));
|
||||
if (str_starts_with($token, 'token=')) {
|
||||
$token = substr($token, 6);
|
||||
}
|
||||
}
|
||||
|
||||
$expectedToken = trim((string) $app->config('app.cron.public_token', ''));
|
||||
if ($expectedToken === '' || $token === '' || !hash_equals($expectedToken, $token)) {
|
||||
return Response::json([
|
||||
'ok' => false,
|
||||
'message' => 'Unauthorized',
|
||||
], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
$limit = $cronRepository->getIntSetting(
|
||||
'cron_web_limit',
|
||||
(int) $app->config('app.cron.web_limit_default', 5),
|
||||
1,
|
||||
100
|
||||
);
|
||||
|
||||
$factory = new CronHandlerFactory(
|
||||
$app->db(),
|
||||
(string) $app->config('app.integrations.secret', ''),
|
||||
$app->basePath()
|
||||
);
|
||||
$runner = $factory->build($cronRepository, $app->logger());
|
||||
$runner->run($limit);
|
||||
|
||||
return Response::json([
|
||||
'ok' => true,
|
||||
'message' => 'Cron executed',
|
||||
'limit' => $limit,
|
||||
'timestamp' => date(DATE_ATOM),
|
||||
]);
|
||||
} catch (\Throwable $exception) {
|
||||
$app->logger()->error('Public cron endpoint failed', [
|
||||
'message' => $exception->getMessage(),
|
||||
'path' => $request->path(),
|
||||
]);
|
||||
|
||||
$debug = (bool) $app->config('app.debug', false);
|
||||
return Response::json([
|
||||
'ok' => false,
|
||||
'message' => 'Cron execution failed',
|
||||
'error' => $debug ? $exception->getMessage() : null,
|
||||
], 500);
|
||||
}
|
||||
};
|
||||
|
||||
$router->get('/health', static fn (Request $request): Response => Response::json([
|
||||
'status' => 'ok',
|
||||
'app' => (string) $app->config('app.name', 'orderPRO'),
|
||||
'timestamp' => date(DATE_ATOM),
|
||||
]));
|
||||
$router->get('/cron', $publicCronHandler);
|
||||
$router->get('/cron/{tokenValue}', $publicCronHandler);
|
||||
|
||||
$router->get('/', static function (Request $request) use ($auth): Response {
|
||||
return $auth->check()
|
||||
|
||||
Reference in New Issue
Block a user