From d0add06ca02944e87c0e36b27c74061c745c90f3 Mon Sep 17 00:00:00 2001 From: augushong Date: Tue, 15 Oct 2024 18:06:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9ELoadMigrationFiles=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E6=94=AF=E6=8C=81=E6=89=A9=E5=B1=95=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E7=9A=84=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/event.php | 3 +++ extend/base/helper.php | 9 +++++++++ extend/think/migration/command/Migrate.php | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/app/event.php b/app/event.php index 1be2df1..8b9fe55 100644 --- a/app/event.php +++ b/app/event.php @@ -18,6 +18,9 @@ return [ 'AdminLoginType' => [ ], + 'LoadMigrationFiles'=>[ + + ] ], 'subscribe' => [ diff --git a/extend/base/helper.php b/extend/base/helper.php index f7798b7..1980e1e 100644 --- a/extend/base/helper.php +++ b/extend/base/helper.php @@ -233,6 +233,15 @@ function build_upload_url($url, $upload_type = null) return Filesystem::disk($upload_type)->url($url); } +/** + * 执行扩展事件 + * + * @param string $name 事件名称 + * @param string $key 处理的key + * @param string $type 处理模式 + * @param array $params 传参 + * @return array + */ function event_handle_result($name, $key, $type = 'all', $params = []) : array { $list_result = Event::trigger($name, $params); diff --git a/extend/think/migration/command/Migrate.php b/extend/think/migration/command/Migrate.php index b16619a..1bafcfc 100644 --- a/extend/think/migration/command/Migrate.php +++ b/extend/think/migration/command/Migrate.php @@ -104,6 +104,14 @@ abstract class Migrate extends Command if (null === $this->migrations) { $phpFiles = glob($this->getPath() . DIRECTORY_SEPARATOR . '*.php', defined('GLOB_BRACE') ? GLOB_BRACE : 0); + $event_files = event_handle_result('LoadMigrationFiles','file_list'); + + foreach ($event_files as $file_list) { + foreach ($file_list as $file_path) { + $phpFiles[] = $file_path; + } + } + // filter the files to only get the ones that match our naming scheme $fileNames = []; /** @var Migrator[] $versions */