Add script for importing schedules
parent
a788bc9cde
commit
b1cb122b86
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use Engelsystem\Controllers\Admin\Schedule\ImportSchedule;
|
||||
use ErrorException;
|
||||
use stdClass;
|
||||
|
||||
require_once __DIR__ . '/../includes/application.php';
|
||||
|
||||
$script = array_shift($argv);
|
||||
if (count($argv) === 0) {
|
||||
echo "usage: $script '*'|SCHEDULE_ID [SCHEDULE_ID...]" . PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
|
||||
$app = app();
|
||||
|
||||
$scheduleIds = $argv;
|
||||
if ($argv[0] === '*') {
|
||||
$db = $app->get('database');
|
||||
$scheduleIds = array_map(fn(stdClass $schedule) => $schedule->id, $db->select('SELECT id FROM schedules');
|
||||
}
|
||||
|
||||
$importer = $app->get(ImportSchedule::class);
|
||||
|
||||
foreach ($scheduleIds as $id) {
|
||||
try {
|
||||
$importer->doImport($id);
|
||||
} catch (ErrorException $e) {
|
||||
echo "import '$id' failed:" . PHP_EOL . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue