[ 'rules' => ['think', 'app/admin'], 'ignore' => [], ], 'wechat' => [ 'rules' => ['app/wechat'], 'ignore' => [], ], 'config' => [ 'rules' => [ 'config/app.php', 'config/log.php', 'config/route.php', 'config/trace.php', 'config/view.php', 'public/index.php', 'public/router.php', ], 'ignore' => [], ], 'static' => [ 'rules' => [ 'public/static/plugs', 'public/static/theme', 'public/static/admin.js', 'public/static/login.js', ], 'ignore' => [], ], ]; protected function configure() { $this->setName('xadmin:install'); $this->addArgument('name', Argument::OPTIONAL, 'ModuleName', ''); $this->setDescription("Source code Install and Update for ThinkAdmin"); } /** * @param Input $input * @param Output $output * @return void */ protected function execute(Input $input, Output $output) { $this->name = trim($input->getArgument('name')); if (empty($this->name)) { $this->output->writeln('Module name of online install cannot be empty'); } elseif ($this->name === 'all') { foreach ($this->bind as $bind) { $this->rules = array_merge($this->rules, $bind['rules']); $this->ignore = array_merge($this->ignore, $bind['ignore']); } [$this->installFile(), $this->installData()]; } elseif (isset($this->bind[$this->name])) { $this->rules = $this->bind[$this->name]['rules'] ?? []; $this->ignore = $this->bind[$this->name]['ignore'] ?? []; [$this->installFile(), $this->installData()]; } else { $this->output->writeln("The specified module {$this->name} is not configured with install rules"); } } /** * 安装本地文件 * @return boolean */ private function installFile(): bool { $module = ModuleService::instance(); $data = $module->grenerateDifference($this->rules, $this->ignore); if (empty($data)) { $this->output->writeln('No need to update the file if the file comparison is consistent'); return false; } [$total, $count] = [count($data), 0]; foreach ($data as $file) { [$state, $mode, $name] = $module->updateFileByDownload($file); if ($state) { if ($mode === 'add') $this->queue->message($total, ++$count, "--- {$name} add successfully"); if ($mode === 'mod') $this->queue->message($total, ++$count, "--- {$name} update successfully"); if ($mode === 'del') $this->queue->message($total, ++$count, "--- {$name} delete successfully"); } else { if ($mode === 'add') $this->queue->message($total, ++$count, "--- {$name} add failed"); if ($mode === 'mod') $this->queue->message($total, ++$count, "--- {$name} update failed"); if ($mode === 'del') $this->queue->message($total, ++$count, "--- {$name} delete failed"); } } return true; } /** * 安装数据库 * @return boolean */ protected function installData(): bool { return true; } }