mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-02 23:16:49 +08:00
1.增加清理demo数据脚本
2.用户课程列表增加角色限定 3.精简模块加载和路由扫描
This commit is contained in:
parent
34da1deae6
commit
175737f274
126
app/Console/Tasks/CleanDemoDataTask.php
Normal file
126
app/Console/Tasks/CleanDemoDataTask.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Console\Tasks;
|
||||
|
||||
use App\Caches\CategoryList as CategoryListCache;
|
||||
use App\Caches\CategoryTreeList as CategoryTreeListCache;
|
||||
use App\Caches\IndexSlideList as IndexSlideListCache;
|
||||
use App\Models\Account as AccountModel;
|
||||
use App\Models\Category as CategoryModel;
|
||||
use App\Repos\User as UserRepo;
|
||||
use App\Services\Utils\IndexCourseCache as IndexCourseCacheUtil;
|
||||
|
||||
class CleanDemoDataTask extends Task
|
||||
{
|
||||
|
||||
public function mainAction()
|
||||
{
|
||||
if ($this->isDemoEnv()) {
|
||||
|
||||
$this->truncateTables();
|
||||
$this->createRootUser();
|
||||
$this->cleanSearchIndex();
|
||||
$this->cleanCache();
|
||||
|
||||
} else {
|
||||
|
||||
echo '------ access denied ------' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
protected function truncateTables()
|
||||
{
|
||||
echo '------ start truncate tables ------' . PHP_EOL;
|
||||
|
||||
$excludeTables = [
|
||||
'kg_area', 'kg_migration', 'kg_nav', 'kg_page',
|
||||
'kg_reward', 'kg_role', 'kg_setting', 'kg_vip',
|
||||
];
|
||||
|
||||
$tables = $this->db->listTables();
|
||||
|
||||
foreach ($tables as $table) {
|
||||
if (!in_array($table, $excludeTables)) {
|
||||
$this->db->execute("TRUNCATE TABLE {$table}");
|
||||
}
|
||||
}
|
||||
|
||||
echo '------ end truncate tables ------' . PHP_EOL;
|
||||
}
|
||||
|
||||
protected function createRootUser()
|
||||
{
|
||||
echo '------ start create root user ------' . PHP_EOL;
|
||||
|
||||
$account = new AccountModel();
|
||||
|
||||
$account->create([
|
||||
'id' => 10000,
|
||||
'email' => '10000@163.com',
|
||||
'password' => '1a1e4568f1a3740b8853a8a16e29bc87',
|
||||
'salt' => 'MbZWxN3L',
|
||||
'create_time' => time(),
|
||||
]);
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$user = $userRepo->findById($account->id);
|
||||
|
||||
$user->update([
|
||||
'admin_role' => 1,
|
||||
'edu_role' => 2,
|
||||
]);
|
||||
|
||||
echo '------ end create root user ------' . PHP_EOL;
|
||||
}
|
||||
|
||||
protected function cleanCache()
|
||||
{
|
||||
$util = new IndexCourseCacheUtil();
|
||||
$util->rebuild();
|
||||
|
||||
$slideListCache = new IndexSlideListCache();
|
||||
$slideListCache->rebuild();
|
||||
|
||||
$categoryListCache = new CategoryListCache();
|
||||
$categoryTreeListCache = new CategoryTreeListCache();
|
||||
|
||||
foreach (CategoryModel::types() as $key => $value) {
|
||||
$categoryListCache->rebuild($key);
|
||||
$categoryTreeListCache->rebuild($key);
|
||||
}
|
||||
}
|
||||
|
||||
protected function cleanSearchIndex()
|
||||
{
|
||||
$articleIndexTask = new ArticleIndexTask();
|
||||
$articleIndexTask->cleanAction();
|
||||
|
||||
$courseIndexTask = new CourseIndexTask();
|
||||
$courseIndexTask->cleanAction();
|
||||
|
||||
$groupIndexTask = new GroupIndexTask();
|
||||
$groupIndexTask->cleanAction();
|
||||
|
||||
$questionIndexTask = new QuestionIndexTask();
|
||||
$questionIndexTask->cleanAction();
|
||||
|
||||
$userIndexTask = new UserIndexTask();
|
||||
$userIndexTask->cleanAction();
|
||||
}
|
||||
|
||||
protected function isDemoEnv()
|
||||
{
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$user = $userRepo->findById(100015);
|
||||
|
||||
return $user ? true : false;
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ namespace App\Services\Logic\User;
|
||||
|
||||
use App\Builders\CourseUserList as CourseUserListBuilder;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Models\CourseUser as CourseUserModel;
|
||||
use App\Repos\CourseUser as CourseUserRepo;
|
||||
use App\Services\Logic\Service as LogicService;
|
||||
use App\Services\Logic\UserTrait;
|
||||
@ -27,6 +28,7 @@ class CourseList extends LogicService
|
||||
$params = $pagerQuery->getParams();
|
||||
|
||||
$params['user_id'] = $user->id;
|
||||
$params['role_type'] = CourseUserModel::ROLE_STUDENT;
|
||||
$params['deleted'] = 0;
|
||||
|
||||
$sort = $pagerQuery->getSort();
|
||||
|
@ -105,20 +105,17 @@ class HttpKernel extends Kernel
|
||||
|
||||
protected function registerModules()
|
||||
{
|
||||
$modules = [
|
||||
'api' => [
|
||||
'className' => 'App\Http\Api\Module',
|
||||
'path' => app_path('Http/Api/Module.php'),
|
||||
],
|
||||
'admin' => [
|
||||
'className' => 'App\Http\Admin\Module',
|
||||
'path' => app_path('Http/Admin/Module.php'),
|
||||
],
|
||||
'home' => [
|
||||
'className' => 'App\Http\Home\Module',
|
||||
'path' => app_path('Http/Home/Module.php'),
|
||||
],
|
||||
];
|
||||
$aliases = ['api', 'home', 'admin'];
|
||||
|
||||
$modules = [];
|
||||
|
||||
foreach ($aliases as $alias) {
|
||||
$moduleName = ucfirst($alias);
|
||||
$modules[$alias] = [
|
||||
'className' => 'App\Http\\' . $moduleName . '\Module',
|
||||
'path' => app_path('Http/' . $moduleName . '/Module.php'),
|
||||
];
|
||||
}
|
||||
|
||||
$this->app->registerModules($modules);
|
||||
}
|
||||
|
@ -19,30 +19,16 @@ $router->notFound([
|
||||
'action' => 'show404',
|
||||
]);
|
||||
|
||||
$webFiles = scandir(app_path('Http/Home/Controllers'));
|
||||
$modules = ['api', 'home', 'admin'];
|
||||
|
||||
foreach ($webFiles as $file) {
|
||||
if (strpos($file, 'Controller.php')) {
|
||||
$className = str_replace('Controller.php', '', $file);
|
||||
$router->addModuleResource('home', 'App\Http\Home\Controllers\\' . $className);
|
||||
}
|
||||
}
|
||||
|
||||
$apiFiles = scandir(app_path('Http/Api/Controllers'));
|
||||
|
||||
foreach ($apiFiles as $file) {
|
||||
if (strpos($file, 'Controller.php')) {
|
||||
$className = str_replace('Controller.php', '', $file);
|
||||
$router->addModuleResource('api', 'App\Http\Api\Controllers\\' . $className);
|
||||
}
|
||||
}
|
||||
|
||||
$adminFiles = scandir(app_path('Http/Admin/Controllers'));
|
||||
|
||||
foreach ($adminFiles as $file) {
|
||||
if (strpos($file, 'Controller.php')) {
|
||||
$className = str_replace('Controller.php', '', $file);
|
||||
$router->addModuleResource('admin', 'App\Http\Admin\Controllers\\' . $className);
|
||||
foreach ($modules as $module) {
|
||||
$moduleName = ucfirst($module);
|
||||
$files = scandir(app_path('Http/' . $moduleName . '/Controllers'));
|
||||
foreach ($files as $file) {
|
||||
if (strpos($file, 'Controller.php')) {
|
||||
$className = str_replace('Controller.php', '', $file);
|
||||
$router->addModuleResource($module, 'App\Http\\' . $moduleName . '\Controllers\\' . $className);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user