diff --git a/app/Console/Migrations/Migration.php b/app/Console/Migrations/Migration.php index dab29370..061db96c 100644 --- a/app/Console/Migrations/Migration.php +++ b/app/Console/Migrations/Migration.php @@ -18,6 +18,13 @@ abstract class Migration abstract public function run(); + protected function saveSettings(array $settings) + { + foreach ($settings as $setting) { + $this->saveSetting($setting); + } + } + protected function saveSetting(array $setting) { $settingRepo = new SettingRepo(); @@ -32,4 +39,4 @@ abstract class Migration } } -} \ No newline at end of file +} diff --git a/app/Console/Tasks/CloseLiveTask.php b/app/Console/Tasks/CloseLiveTask.php new file mode 100644 index 00000000..8cfd3d86 --- /dev/null +++ b/app/Console/Tasks/CloseLiveTask.php @@ -0,0 +1,72 @@ +findChapterLives(); + + echo sprintf('pending lives: %s', $chapterLives->count()) . PHP_EOL; + + if ($chapterLives->count() == 0) return; + + echo '------ start close live task ------' . PHP_EOL; + + foreach ($chapterLives as $chapterLive) { + + $chapterLive->status = ChapterLiveModel::STATUS_INACTIVE; + + $chapterLive->update(); + + $chapterRepo = new ChapterRepo(); + + $chapter = $chapterRepo->findById($chapterLive->chapter_id); + + $attrs = $chapter->attrs; + $attrs['stream']['status'] = ChapterModel::SS_INACTIVE; + $chapter->attrs = $attrs; + + $chapter->update(); + + $cache = new CourseChapterListCache(); + + $cache->rebuild($chapterLive->course_id); + } + + echo '------ end close live task ------' . PHP_EOL; + } + + /** + * 查找待关闭直播 + * + * @param int $limit + * @return ResultsetInterface|Resultset|ChapterLiveModel[] + */ + protected function findChapterLives(int $limit = 100) + { + $status = ChapterLiveModel::STATUS_ACTIVE; + $endTime = time() - 3600; + + return ChapterLiveModel::query() + ->where('status = :status:', ['status' => $status]) + ->andWhere('end_time < :end_time:', ['end_time' => $endTime]) + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Http/Admin/Views/category/list.volt b/app/Http/Admin/Views/category/list.volt index 7e2efff7..837e4f26 100644 --- a/app/Http/Admin/Views/category/list.volt +++ b/app/Http/Admin/Views/category/list.volt @@ -9,7 +9,7 @@