You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aquaculture/app/Console/Commands/InstallShop.php

81 lines
2.4 KiB

<?php
namespace App\Console\Commands; // 定义命名空间
use App\Models\Product; // 引入 Product 模型
/**
* 安装商城命令
*
* 该命令用于初始化商城项目,包括数据库迁移、数据填充和资源复制等操作。
*/
class InstallShop extends BaseCommand
{
/**
* 控制台命令的名称和签名
*
* @var string
*/
protected $signature = 'moon:install'; // 定义命令的名称和签名
/**
* 控制台命令的描述
*
* @var string
*/
protected $description = '初始化商城项目'; // 描述该命令的用途
/**
* 创建一个新的命令实例.
*
* @return void
*/
public function __construct()
{
parent::__construct(); // 调用父类构造函数
}
/**
* 执行商城安装命令
*
* 该方法执行初始化商城项目的逻辑,包括数据库迁移、数据填充和静态资源处理等。
*
* @return mixed
*/
public function handle()
{
// 生成应用的加密密钥
$this->call('key:generate');
// 删除上一次保留的数据表
$this->call('migrate:reset'); // 重置数据库迁移,删除所有表
// 删除上一次保留的文件
$this->call('moon:delete'); // 删除之前的文件或数据
// 禁止在安装过程中将产品添加到搜索索引
Product::$addToSearch = false;
/****************************************
* 1. 迁移数据表
* 2. 数据库迁移
* 3. 复制静态资源
* 4. 创建软链接
****************************************/
$this->call('migrate'); // 执行数据库迁移,创建所需的数据表
$this->call('db:seed'); // 填充数据库,插入初始数据
$this->call('moon:copy'); // 复制静态资源到公共目录
$this->call('storage:link'); // 创建存储目录的软链接,以便访问存储的文件
// 更新首页数据,防止上一次遗留数据的影响
$this->call('moon:update-home'); // 更新首页相关数据
// 生成全文索引
$this->call('add:shop-to-search'); // 为商城产品生成搜索索引
// 直接开启监听队列
// $this->info('queue starting please don`t close cmd windows!!!');
// $this->call('queue:work', ['--tries' => '3']); // 启动队列工作进程,处理队列任务
}
}