66use App \ResourceItem ;
77use Carbon \Carbon ;
88use Illuminate \Console \Command ;
9+ use Illuminate \Support \Facades \Schema ;
910
1011/**
1112 * Training resources report for https://codeweek.eu/training and related Learn & Teach resources.
@@ -54,6 +55,10 @@ public function handle(): int
5455 }
5556
5657 if ($ onlineCoursesOnly ) {
58+ if (! Schema::hasTable ('online_courses ' )) {
59+ $ this ->error ('The online_courses table does not exist. Run: php artisan migrate ' );
60+ return self ::FAILURE ;
61+ }
5762 $ stats = $ this ->onlineCoursesStats ($ baseline );
5863 if ($ format === 'json ' ) {
5964 $ this ->line (json_encode ([
@@ -74,7 +79,7 @@ public function handle(): int
7479 'report_period_downloads ' => 'June/Sept 2024 – Jan 2026 (requested). Download data not collected by application. ' ,
7580 'training_page ' => $ this ->trainingPageStats (),
7681 'learn_teach_resources ' => $ this ->learnTeachResourcesStats ($ baseline ),
77- 'online_courses ' => $ this ->onlineCoursesStats ($ baseline ),
82+ 'online_courses ' => $ this ->onlineCoursesStats ($ baseline, true ),
7883 'downloads ' => $ this ->downloadsSection (),
7984 'geographical_distribution ' => $ this ->geographySection (),
8085 'downloads_over_time ' => $ this ->downloadsOverTimeSection (),
@@ -117,8 +122,22 @@ private function learnTeachResourcesStats(Carbon $baseline): array
117122 ];
118123 }
119124
120- private function onlineCoursesStats (Carbon $ baseline ): array
125+ /** @param bool $allowMissingTable When true (e.g. full report), return a placeholder instead of throwing. */
126+ private function onlineCoursesStats (Carbon $ baseline , bool $ allowMissingTable = false ): array
121127 {
128+ if (! Schema::hasTable ('online_courses ' )) {
129+ if ($ allowMissingTable ) {
130+ return [
131+ 'total_now ' => null ,
132+ 'added_since_baseline ' => null ,
133+ 'baseline_date ' => $ baseline ->format ('Y-m-d ' ),
134+ 'url ' => 'https://codeweek.eu/online-courses ' ,
135+ 'note ' => 'Online courses table not found. Run: php artisan migrate ' ,
136+ ];
137+ }
138+ throw new \RuntimeException ('The online_courses table does not exist. Run: php artisan migrate ' );
139+ }
140+
122141 $ total = OnlineCourse::query ()->where ('active ' , true )->count ();
123142 $ addedSince = OnlineCourse::query ()
124143 ->where ('active ' , true )
@@ -196,8 +215,10 @@ private function printTextReport(array $report, Carbon $baseline): void
196215 $ this ->line ('' );
197216
198217 $ this ->line ('--- Online Courses (https://codeweek.eu/online-courses) --- ' );
199- $ this ->line ('Total online courses now: ' . $ report ['online_courses ' ]['total_now ' ]);
200- $ this ->line ('Added since baseline ( ' . $ baseline ->format ('Y-m-d ' ) . '): ' . $ report ['online_courses ' ]['added_since_baseline ' ]);
218+ if (array_key_exists ('total_now ' , $ report ['online_courses ' ]) && $ report ['online_courses ' ]['total_now ' ] !== null ) {
219+ $ this ->line ('Total online courses now: ' . $ report ['online_courses ' ]['total_now ' ]);
220+ $ this ->line ('Added since baseline ( ' . $ baseline ->format ('Y-m-d ' ) . '): ' . $ report ['online_courses ' ]['added_since_baseline ' ]);
221+ }
201222 $ this ->line ($ report ['online_courses ' ]['note ' ]);
202223 $ this ->line ('' );
203224
0 commit comments