mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-22 11:41:27 +08:00
151 lines
3.2 KiB
PHP
151 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Tasks;
|
|
|
|
use App\Caches\Setting as SettingCache;
|
|
use App\Library\Cache\Backend\Redis as RedisCache;
|
|
use App\Models\Setting as SettingModel;
|
|
use Phalcon\Cli\Task;
|
|
use Phalcon\Config;
|
|
|
|
class MaintainTask extends Task
|
|
{
|
|
|
|
public function mainAction()
|
|
{
|
|
$this->resetSettingAction();
|
|
$this->resetAnnotationAction();
|
|
$this->resetMetadataAction();
|
|
$this->resetVoltAction();
|
|
}
|
|
|
|
/**
|
|
* 重置设置
|
|
*
|
|
* @command: php console.php maintain reset_setting
|
|
*/
|
|
public function resetSettingAction()
|
|
{
|
|
echo "start reset setting..." . PHP_EOL;
|
|
|
|
$rows = SettingModel::query()->columns('section')->distinct(true)->execute();
|
|
|
|
foreach ($rows as $row) {
|
|
$cache = new SettingCache();
|
|
$cache->rebuild($row->section);
|
|
}
|
|
|
|
echo "end reset setting..." . PHP_EOL;
|
|
}
|
|
|
|
/**
|
|
* 重置注解
|
|
*
|
|
* @command: php console.php maintain reset_annotation
|
|
*/
|
|
public function resetAnnotationAction()
|
|
{
|
|
$config = $this->getConfig();
|
|
$cache = $this->getCache();
|
|
$redis = $cache->getRedis();
|
|
|
|
$dbIndex = $config->path('annotation.db');
|
|
$statsKey = $config->path('annotation.statsKey');
|
|
|
|
$redis->select($dbIndex);
|
|
|
|
$keys = $redis->sMembers($statsKey);
|
|
|
|
echo "start reset annotation..." . PHP_EOL;
|
|
|
|
if (count($keys) > 0) {
|
|
|
|
$keys = $this->handlePhKeys($keys);
|
|
|
|
$redis->del(...$keys);
|
|
$redis->del($statsKey);
|
|
}
|
|
|
|
echo "end reset annotation..." . PHP_EOL;
|
|
}
|
|
|
|
/**
|
|
* 重置元数据
|
|
*
|
|
* @command: php console.php maintain reset_metadata
|
|
*/
|
|
public function resetMetadataAction()
|
|
{
|
|
$config = $this->getConfig();
|
|
$cache = $this->getCache();
|
|
$redis = $cache->getRedis();
|
|
|
|
$dbIndex = $config->path('metadata.db');
|
|
$statsKey = $config->path('metadata.statsKey');
|
|
|
|
$redis->select($dbIndex);
|
|
|
|
$keys = $redis->sMembers($statsKey);
|
|
|
|
echo "start reset metadata..." . PHP_EOL;
|
|
|
|
if (count($keys) > 0) {
|
|
|
|
$keys = $this->handlePhKeys($keys);
|
|
|
|
$redis->del(...$keys);
|
|
$redis->del($statsKey);
|
|
}
|
|
|
|
echo "start reset metadata..." . PHP_EOL;
|
|
}
|
|
|
|
/**
|
|
* 重置模板
|
|
*
|
|
* @command: php console.php maintain reset_volt
|
|
*/
|
|
public function resetVoltAction()
|
|
{
|
|
echo "start reset volt..." . PHP_EOL;
|
|
|
|
$dir = cache_path('volt');
|
|
|
|
foreach (scandir($dir) as $file) {
|
|
if (strpos($file, '.php')) {
|
|
unlink($dir . '/' . $file);
|
|
}
|
|
}
|
|
|
|
echo "end reset volt..." . PHP_EOL;
|
|
}
|
|
|
|
protected function getConfig()
|
|
{
|
|
/**
|
|
* @var Config $config
|
|
*/
|
|
$config = $this->getDI()->get('config');
|
|
|
|
return $config;
|
|
}
|
|
|
|
protected function getCache()
|
|
{
|
|
/**
|
|
* @var RedisCache $cache
|
|
*/
|
|
$cache = $this->getDI()->get('cache');
|
|
|
|
return $cache;
|
|
}
|
|
|
|
protected function handlePhKeys($keys)
|
|
{
|
|
return array_map(function ($key) {
|
|
return "_PHCR{$key}";
|
|
}, $keys);
|
|
}
|
|
|
|
}
|