Files
api/services/nginx/app/cli.php
T

117 lines
4.5 KiB
PHP

<?php
global $EMAIL_WASH_CERTIFICATE_TOKEN;
// This script only runs when the program is called from the command line. It is used to run the CLI script.
if (php_sapi_name() !== 'cli' && !isset($_GET['internalCronCall'])) {
exit;
}
// If the program was called from the command line, get the arguments
if (php_sapi_name() === 'cli') {
$args = $argv;
} else {
// If the program was called from the browser, get the arguments from the URL
$args = [];
$args[1] = $_GET['script'];
$args[2] = $_GET['action'];
$auth = $_GET['auth_key'] ?? null;
if ($auth !== $EMAIL_WASH_CERTIFICATE_TOKEN) {
echo json_encode([
'status' => 'error',
'message' => 'Invalid token'
]);
exit;
}
}
// Set the max execution time to 0
// This is used to prevent the script from timing out
// when running for a long time
set_time_limit(10 * 60); // 10 minutes
// Set the memory limit to 16 GB
ini_set('memory_limit', '16G');
require_once __DIR__ . '/classes/economic_transfer_executor.php';
require_once __DIR__ . '/classes/economic_transfer_queue_schema_bootstrap.php';
require_once __DIR__ . '/classes/economic_transfer_queue.php';
// If the first argument is 'run', switch to the second argument
if ($args[1] === 'run') {
switch ($args[2]) {
case 'minio-test':
echo "Running the minio test script";
require_once 'tests/minio/minioTest.php';
break;
case 'redis-test':
echo "Running the redis test script";
require_once 'tests/redis/redisTest.php';
break;
case 'redis-logSync-test':
echo "Running the redis log sync test script";
require_once 'tests/redis/redisLogSyncTest.php';
break;
case 'bookingModule-test':
echo "Running the bookingModule test script";
require_once 'tests/bookingModule/bookingModuleTest.php';
break;
case 'slackModule-test':
echo "Running the slack test script";
require_once 'tests/slackModule/SlackModuleTest.php';
break;
case 'bookingSync-test':
echo "Running the bookingSync test script";
require_once 'tests/bookingModule/bookingSyncTest.php';
break;
case 'bookingSync':
require_once 'cron/SyncBookings.php';
break;
case 'clearAllUsersEconomicCustomerDiscounts':
require_once 'cron/ClearAllUsersEconomicCustomerDiscounts.php';
break;
case 'clearAllUsersEconomicCustomerDetails':
require_once 'cron/ClearAllUsersEconomicCustomerDetails.php';
break;
case 'economic-v2-backfill':
require_once 'cron/BackfillEconomicV2History.php';
break;
case 'economicOrderParser-test':
echo "Running the economicOrderParser test script";
require_once 'tests/economicOrderParser/EconomicOrderParserTest.php';
break;
case 'subusers-grant-test':
echo "Running the Subusers grant initialization test script";
require_once 'tests/subusers/SubuserUserGrantInitTest.php';
break;
case 'permission-node-test':
echo "Running the Permission node mapping test script";
require_once 'tests/permissions/PermissionNodeTest.php';
break;
case 'selfserve-relay-gating-test':
echo "Running the Self-Serve relay gating test script";
require_once 'tests/selfserve/SelfServeRelayGatingTest.php';
break;
case 'logSync':
require_once 'cron/SyncLogs.php';
break;
case 'economic-transfer-queue':
echo "[" . date('Y-m-d H:i:s') . "][CRON] Running economic transfer queue worker\n";
$queue = new \classes\economic_transfer_queue();
$result = $queue->processPending(25);
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\n";
break;
case 'cron':
echo "[" . date('Y-m-d H:i:s') . "][CRON] Running the cron script\n";
require_once 'cron/Cron.php';
break;
case 'cron-worker':
echo "[" . date('Y-m-d H:i:s') . "][CRON_WORKER] Starting cron worker\n";
(new \classes\cron_worker())->run();
break;
default:
echo "Invalid script name";
break;
}
echo "[" . date('Y-m-d H:i:s') . "][CRON] Finished running the script\n";
} else {
echo "Invalid action";
}