Skip to content

Commit

Permalink
优化:安装、升级脚本优化
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Feb 16, 2023
1 parent 13deebd commit 28baba1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
34 changes: 33 additions & 1 deletion app/CodeFec/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,39 @@ public function step_3()

$exitCode = $application->run($input, $output);

$this->command->info('数据库迁移成功!');
foreach (getEnPlugins() as $name) {
$plugin_name = $name;

if (is_dir(plugin_path($plugin_name . '/resources/views')) && ! is_dir(BASE_PATH . '/resources/views/plugins')) {
\Swoole\Coroutine\System::exec('mkdir ' . BASE_PATH . '/resources/views/plugins');
}
if (is_dir(plugin_path($plugin_name . '/resources/assets'))) {
if (! is_dir(public_path('plugins'))) {
mkdir(public_path('plugins'));
}
if (! is_dir(public_path('plugins/' . $plugin_name))) {
mkdir(public_path('plugins/' . $plugin_name));
}
copy_dir(plugin_path($plugin_name . '/resources/assets'), public_path('plugins/' . $plugin_name));
}
if (is_dir(plugin_path($plugin_name . '/src/migrations'))) {
$params = ['command' => 'CodeFec:migrate', 'path' => plugin_path($plugin_name . '/src/migrations')];

$input = new ArrayInput($params);
$output = new NullOutput();

$container = \Hyperf\Utils\ApplicationContext::getContainer();

/** @var Application $application */
$application = $container->get(\Hyperf\Contract\ApplicationInterface::class);
$application->setAutoExit(false);

// 这种方式: 不会暴露出命令执行中的异常, 不会阻止程序返回
$exitCode = $application->run($input, $output);
}
}

$this->command->info('数据迁移成功!');


// 下一步
Expand Down
12 changes: 6 additions & 6 deletions app/CodeFec/Upgrading.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ public function removeFiles(...$values): void

private function download(string $download, string $path, $no_backup = false)
{
if(!file_exists(BASE_PATH . '/app/CodeFec/storage/update.lock')){
file_put_contents(BASE_PATH . '/app/CodeFec/storage/update.lock', time());
$this->command->info('更新锁已创建,请重新运行此命令...');
return ;
}
$this->command->info("开始更新...\n");
$this->command->info("生成更新锁...\n");
// 生成更新锁
file_put_contents(BASE_PATH . '/app/CodeFec/storage/update.lock', time());
// 备份网站数据
Expand Down Expand Up @@ -144,11 +148,7 @@ private function download(string $download, string $path, $no_backup = false)
$this->command->info("更新插件包...\n");
System::exec('php CodeFec CodeFec:PluginsComposerInstall');

// 重建索引
$this->command->info("重建索引...\n");
\Swoole\Coroutine\System::exec('php CodeFec ClearCache');

$this->command->info('升级完成!');
$this->command->alert("更新完成\n请重启服务");
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions app/Listener/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace App\Listener;

use App\CodeFec\CodeFec;
use App\CodeFec\Install;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Framework\Event\BootApplication;
Expand All @@ -23,7 +22,7 @@ class Boot implements ListenerInterface
/**
* @var ContainerInterface
*/
private $container;
private ContainerInterface $container;

public function __construct(ContainerInterface $container)
{
Expand All @@ -39,12 +38,15 @@ public function listen(): array

public function process(object $event): void
{
if(file_exists(BASE_PATH . '/app/CodeFec/storage/install.lock') || $this->get_step() >= 5){
(new CodeFec())->handle();
if (! file_exists(BASE_PATH . '/app/CodeFec/storage/update.lock')) {
if (file_exists(BASE_PATH . '/app/CodeFec/storage/install.lock') || $this->get_step() >= 5) {
(new CodeFec())->handle();
}
}
}

private function get_step(){
private function get_step()
{
if (! is_dir(BASE_PATH . '/app/CodeFec/storage')) {
mkdir(BASE_PATH . '/app/CodeFec/storage');
}
Expand Down

0 comments on commit 28baba1

Please sign in to comment.