Initial commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
class Cron extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('cron')
|
||||
->setDescription('定时数据清理任务');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
// 指令输出
|
||||
Db::name('querycache')->where('uptime','<',date('Y-m-d H:i:s', strtotime('-30 days')))->delete();
|
||||
$output->writeln('定时数据清理任务执行完毕');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\Output;
|
||||
use ZipArchive;
|
||||
|
||||
class PluginPackage extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('plugin:package')
|
||||
->addArgument('space', Argument::REQUIRED, '插件域,例如:utility')
|
||||
->setDescription('打包指定域的所有插件');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$space = $input->getArgument('space');
|
||||
// 指令输出
|
||||
$rootPath = app()->getRootPath() . '/plugin/';
|
||||
if (!is_dir($rootPath . $space)) {
|
||||
$output->writeln("该域不存在:[$space]");
|
||||
return;
|
||||
}
|
||||
$plugins = glob($rootPath . $space . '/*');
|
||||
$output->writeln("正在打包:[$space]下的文件");
|
||||
foreach ($plugins as $plugin) {
|
||||
$zip = new ZipArchive();
|
||||
$filename = $rootPath . 'output/' . $space . DIRECTORY_SEPARATOR . basename($plugin) . '.zip';
|
||||
if (!is_dir(dirname($filename))) {
|
||||
mkdir(dirname($filename), 0777, true);
|
||||
}
|
||||
if ($zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
|
||||
|
||||
$tree_relative = tree_relative($plugin);
|
||||
$files = multi2one($tree_relative, '', '/');
|
||||
foreach ($files as $file) {
|
||||
if ($file !== '.' && $file !== '..') {
|
||||
$zip->addFile($plugin . '/' . $file, $space . '/' . basename($plugin) . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
$output->writeln("打包成功:[$filename]");
|
||||
}
|
||||
|
||||
$output->writeln("该域所有文件都已打包完成:[$space]");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user