mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-29 22:01:38 +08:00
Merge branch 'koogua/v1.5.5' into demo
This commit is contained in:
commit
926b5285e2
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,3 +1,14 @@
|
||||
### [v1.5.5](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.5)(2022-07-27)
|
||||
|
||||
- 修正获分类查询条件
|
||||
- 修正锁定账户还能登录的问题
|
||||
- 发货增加noMatchedHandler
|
||||
- 增加demo数据清理脚本
|
||||
- 用户课程列表增加角色限定条件
|
||||
- 精简模块加载和路由扫描
|
||||
- 优化CsrfToken
|
||||
- 去除无实质作用的数据表优化
|
||||
|
||||
### [v1.5.4](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.4)(2022-06-15)
|
||||
|
||||
- 增加migration助手SettingTrait
|
||||
|
@ -23,15 +23,15 @@ class QuestionList extends Builder
|
||||
return $questions;
|
||||
}
|
||||
|
||||
public function handleCategories(array $articles)
|
||||
public function handleCategories(array $questions)
|
||||
{
|
||||
$categories = $this->getCategories();
|
||||
|
||||
foreach ($articles as $key => $article) {
|
||||
$articles[$key]['category'] = $categories[$article['category_id']] ?? new \stdClass();
|
||||
foreach ($questions as $key => $article) {
|
||||
$questions[$key]['category'] = $categories[$article['category_id']] ?? new \stdClass();
|
||||
}
|
||||
|
||||
return $articles;
|
||||
return $questions;
|
||||
}
|
||||
|
||||
public function handleUsers(array $questions)
|
||||
|
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;
|
||||
}
|
||||
|
||||
}
|
@ -58,6 +58,9 @@ class DeliverTask extends Task
|
||||
case OrderModel::ITEM_VIP:
|
||||
$this->handleVipOrder($order);
|
||||
break;
|
||||
default:
|
||||
$this->noMatchedHandler($order);
|
||||
break;
|
||||
}
|
||||
|
||||
$order->status = OrderModel::STATUS_FINISHED;
|
||||
@ -153,6 +156,11 @@ class DeliverTask extends Task
|
||||
$this->closePendingOrders($user->id);
|
||||
}
|
||||
|
||||
protected function noMatchedHandler(OrderModel $order)
|
||||
{
|
||||
throw new \RuntimeException("No Matched Handler For Order: {$order->id}");
|
||||
}
|
||||
|
||||
protected function closePendingOrders($userId)
|
||||
{
|
||||
$orders = $this->findUserPendingOrders($userId);
|
||||
|
@ -1,139 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Console\Tasks;
|
||||
|
||||
use App\Models\ImMessage as ImMessageModel;
|
||||
use App\Models\Learning as LearningModel;
|
||||
use App\Models\Task as TaskModel;
|
||||
use App\Models\UserSession as UserSessionModel;
|
||||
use App\Models\UserToken as UserTokenModel;
|
||||
|
||||
class OptimizeTableTask extends Task
|
||||
{
|
||||
|
||||
public function mainAction()
|
||||
{
|
||||
$this->optimizeUserSessionTable();
|
||||
$this->optimizeUserTokenTable();
|
||||
$this->optimizeImMessageTable();
|
||||
$this->optimizeLearningTable();
|
||||
$this->optimizeTaskTable();
|
||||
}
|
||||
|
||||
protected function optimizeUserSessionTable()
|
||||
{
|
||||
$sessionModel = new UserSessionModel();
|
||||
|
||||
$tableName = $sessionModel->getSource();
|
||||
|
||||
if (UserSessionModel::count() < 1000000) {
|
||||
echo sprintf('no need to optimize table: %s', $tableName) . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
echo sprintf('------ start optimize table: %s ------', $tableName) . PHP_EOL;
|
||||
|
||||
$this->db->delete($tableName, 'expire_time < :expire_time', [
|
||||
'expire_time' => strtotime('-3 days'),
|
||||
]);
|
||||
|
||||
$this->db->execute("OPTIMIZE TABLE {$tableName}");
|
||||
|
||||
echo sprintf('------ end optimize table: %s ------', $tableName) . PHP_EOL;
|
||||
}
|
||||
|
||||
protected function optimizeUserTokenTable()
|
||||
{
|
||||
$tokenModel = new UserTokenModel();
|
||||
|
||||
$tableName = $tokenModel->getSource();
|
||||
|
||||
if (UserTokenModel::count() < 1000000) {
|
||||
echo sprintf('no need to optimize table: %s', $tableName) . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
echo sprintf('------ start optimize table: %s ------', $tableName) . PHP_EOL;
|
||||
|
||||
$this->db->delete($tableName, 'expire_time < :expire_time', [
|
||||
'expire_time' => strtotime('-3 days'),
|
||||
]);
|
||||
|
||||
$this->db->execute("OPTIMIZE TABLE {$tableName}");
|
||||
|
||||
echo sprintf('------ end optimize table: %s ------', $tableName) . PHP_EOL;
|
||||
}
|
||||
|
||||
protected function optimizeImMessageTable()
|
||||
{
|
||||
$messageModel = new ImMessageModel();
|
||||
|
||||
$tableName = $messageModel->getSource();
|
||||
|
||||
if (ImMessageModel::count() < 1000000) {
|
||||
echo sprintf('no need to optimize table: %s', $tableName) . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
echo sprintf('------ start optimize table: %s ------', $tableName) . PHP_EOL;
|
||||
|
||||
$this->db->delete($tableName, 'create_time < :create_time', [
|
||||
'create_time' => strtotime('-6 months'),
|
||||
]);
|
||||
|
||||
$this->db->execute("OPTIMIZE TABLE {$tableName}");
|
||||
|
||||
echo sprintf('------ end optimize table: %s ------', $tableName) . PHP_EOL;
|
||||
}
|
||||
|
||||
protected function optimizeLearningTable()
|
||||
{
|
||||
$learningModel = new LearningModel();
|
||||
|
||||
$tableName = $learningModel->getSource();
|
||||
|
||||
if (LearningModel::count() < 1000000) {
|
||||
echo sprintf('no need to optimize table: %s', $tableName) . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
echo sprintf('------ start optimize table: %s ------', $tableName) . PHP_EOL;
|
||||
|
||||
$this->db->delete($tableName, 'create_time < :create_time', [
|
||||
'create_time' => strtotime('-6 months'),
|
||||
]);
|
||||
|
||||
$this->db->execute("OPTIMIZE TABLE {$tableName}");
|
||||
|
||||
echo sprintf('------ end optimize table: %s ------', $tableName) . PHP_EOL;
|
||||
}
|
||||
|
||||
protected function optimizeTaskTable()
|
||||
{
|
||||
$taskModel = new TaskModel();
|
||||
|
||||
$tableName = $taskModel->getSource();
|
||||
|
||||
if (TaskModel::count() < 1000000) {
|
||||
echo sprintf('no need to optimize table: %s', $tableName) . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
echo sprintf('------ start optimize table: %s ------', $tableName) . PHP_EOL;
|
||||
|
||||
$this->db->delete($tableName, 'create_time < :create_time AND status > :status', [
|
||||
'create_time' => strtotime('-6 months'),
|
||||
'status' => TaskModel::STATUS_PENDING,
|
||||
]);
|
||||
|
||||
$this->db->execute("OPTIMIZE TABLE {$tableName}");
|
||||
|
||||
echo sprintf('------ end optimize table: %s ------', $tableName) . PHP_EOL;
|
||||
}
|
||||
|
||||
}
|
@ -46,7 +46,7 @@ class Question extends Service
|
||||
$categoryRepo = new CategoryRepo();
|
||||
|
||||
return $categoryRepo->findAll([
|
||||
'type' => CategoryModel::TYPE_ARTICLE,
|
||||
'type' => CategoryModel::TYPE_QUESTION,
|
||||
'level' => 1,
|
||||
'published' => 1,
|
||||
'deleted' => 0,
|
||||
|
@ -16,7 +16,7 @@ class AppInfo
|
||||
|
||||
protected $link = 'https://koogua.com';
|
||||
|
||||
protected $version = '1.5.4';
|
||||
protected $version = '1.5.5';
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
namespace App\Library;
|
||||
|
||||
use Phalcon\Config;
|
||||
use Phalcon\Crypt;
|
||||
use Phalcon\Di;
|
||||
use Phalcon\Text;
|
||||
@ -19,7 +20,7 @@ class CsrfToken
|
||||
*/
|
||||
protected $crypt;
|
||||
|
||||
protected $lifetime = 600;
|
||||
protected $lifetime = 86400;
|
||||
|
||||
protected $delimiter = '@@';
|
||||
|
||||
@ -33,7 +34,7 @@ class CsrfToken
|
||||
public function getToken()
|
||||
{
|
||||
$content = [
|
||||
time() + $this->lifetime,
|
||||
$this->getExpiredTime(),
|
||||
$this->fixed,
|
||||
Text::random(8),
|
||||
];
|
||||
@ -62,4 +63,16 @@ class CsrfToken
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getExpiredTime()
|
||||
{
|
||||
/**
|
||||
* @var $config Config
|
||||
*/
|
||||
$config = Di::getDefault()->getShared('config');
|
||||
|
||||
$lifetime = $config->path('csrf_token.lifetime') ?: $this->lifetime;
|
||||
|
||||
return $lifetime + time();
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
|
@ -177,10 +177,10 @@ class Account extends Validator
|
||||
|
||||
public function checkIfAllowLogin(UserModel $user)
|
||||
{
|
||||
$locked = $user->locked == 1;
|
||||
$expired = $user->lock_expiry_time > time();
|
||||
$case1 = $user->locked == 1;
|
||||
$case2 = $user->lock_expiry_time > time();
|
||||
|
||||
if ($locked && !$expired) {
|
||||
if ($case1 && $case2) {
|
||||
throw new ForbiddenException('account.locked');
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -117,6 +117,11 @@ $config['metadata']['lifetime'] = 7 * 86400;
|
||||
*/
|
||||
$config['annotation']['lifetime'] = 7 * 86400;
|
||||
|
||||
/**
|
||||
* CsrfToken有效期(秒)
|
||||
*/
|
||||
$config['csrf_token']['lifetime'] = 86400;
|
||||
|
||||
/**
|
||||
* 允许跨域
|
||||
*/
|
||||
|
@ -19,30 +19,16 @@ $router->notFound([
|
||||
'action' => 'show404',
|
||||
]);
|
||||
|
||||
$webFiles = scandir(app_path('Http/Home/Controllers'));
|
||||
$modules = ['api', 'home', 'admin'];
|
||||
|
||||
foreach ($webFiles as $file) {
|
||||
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('home', 'App\Http\Home\Controllers\\' . $className);
|
||||
$router->addModuleResource($module, 'App\Http\\' . $moduleName . '\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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,4 @@ $scheduler->php($script, $bin, ['--task' => 'renew_demo_live_course', '--action'
|
||||
$scheduler->php($script, $bin, ['--task' => 'teacher_live_notice', '--action' => 'provide'])
|
||||
->daily(4, 7);
|
||||
|
||||
$scheduler->php($script, $bin, ['--task' => 'optimize_table', '--action' => 'main'])
|
||||
->weekly(6, 5, 3);
|
||||
|
||||
$scheduler->run();
|
||||
|
Loading…
x
Reference in New Issue
Block a user