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 @@
{% if parent.id > 0 %} - 返回 + 返回 {{ parent.name }} {% endif %} 分类管理 @@ -87,4 +87,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/chapter/lessons.volt b/app/Http/Admin/Views/chapter/lessons.volt index 3650915a..3e813758 100644 --- a/app/Http/Admin/Views/chapter/lessons.volt +++ b/app/Http/Admin/Views/chapter/lessons.volt @@ -43,7 +43,7 @@
- 返回 + 返回 {{ course.title }} {{ chapter.title }} 课时管理 @@ -126,4 +126,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/course/chapters.volt b/app/Http/Admin/Views/course/chapters.volt index 2622ee59..1a653fff 100644 --- a/app/Http/Admin/Views/course/chapters.volt +++ b/app/Http/Admin/Views/course/chapters.volt @@ -9,7 +9,7 @@
- 返回 + 返回 {{ course.title }} 章节管理 @@ -79,4 +79,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/nav/list.volt b/app/Http/Admin/Views/nav/list.volt index 28a6a367..cb0e2bd6 100644 --- a/app/Http/Admin/Views/nav/list.volt +++ b/app/Http/Admin/Views/nav/list.volt @@ -25,9 +25,7 @@
{% if parent.id > 0 %} - - 返回 - + 返回 {{ parent.name }} {% endif %} 导航管理 diff --git a/app/Http/Home/Views/templates/main.volt b/app/Http/Home/Views/templates/main.volt index 106c9b85..4dbe95c4 100644 --- a/app/Http/Home/Views/templates/main.volt +++ b/app/Http/Home/Views/templates/main.volt @@ -1,6 +1,9 @@ + {% if site_info.analytics_enabled == 1 %} + {{ site_info.analytics_script }} + {% endif %} @@ -38,12 +41,5 @@ {% block include_js %}{% endblock %} {% block inline_js %}{% endblock %} - -{% if site_info.analytics_enabled == 1 %} -
- {{ site_info.analytics_script }} -
-{% endif %} - - \ No newline at end of file + diff --git a/app/Services/LiveNotify.php b/app/Services/LiveNotify.php index 5ae0554c..bee69c8e 100644 --- a/app/Services/LiveNotify.php +++ b/app/Services/LiveNotify.php @@ -7,7 +7,7 @@ namespace App\Services; -use App\Caches\CourseChapterList as CatalogCache; +use App\Caches\CourseChapterList as CourseChapterListCache; use App\Models\Chapter as ChapterModel; use App\Models\ChapterLive as ChapterLiveModel; use App\Repos\Chapter as ChapterRepo; @@ -175,7 +175,7 @@ class LiveNotify extends Service protected function rebuildCatalogCache(ChapterModel $chapter) { - $cache = new CatalogCache(); + $cache = new CourseChapterListCache(); $cache->rebuild($chapter->course_id); } @@ -216,4 +216,4 @@ class LiveNotify extends Service return $sign == $mySign; } -} \ No newline at end of file +} diff --git a/scheduler.php b/scheduler.php index f6556b56..01d4f573 100644 --- a/scheduler.php +++ b/scheduler.php @@ -63,6 +63,9 @@ $scheduler->php($script, $bin, ['--task' => 'sync_article_score', '--action' => $scheduler->php($script, $bin, ['--task' => 'sync_question_score', '--action' => 'main']) ->hourly(29); +$scheduler->php($script, $bin, ['--task' => 'close_live', '--action' => 'main']) + ->hourly(31); + $scheduler->php($script, $bin, ['--task' => 'clean_log', '--action' => 'main']) ->daily(3, 3);