From 98a33baf816aad289f33e7f089bce2061096f655 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Tue, 8 Mar 2022 15:25:15 +0800 Subject: [PATCH] upgrade add init tag --- nexus/Install/Update.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/nexus/Install/Update.php b/nexus/Install/Update.php index af736bb0..5aa0b83e 100644 --- a/nexus/Install/Update.php +++ b/nexus/Install/Update.php @@ -160,6 +160,17 @@ class Update extends Install $this->doLog("[ADD_ID_TO_AGENT_ALLOWED_EXCEPTION]"); } + /** + * @since 1.6.0 + * + * init tag + */ + if (WITH_LARAVEL && !NexusDB::schema()->hasTable('tags')) { + $this->runMigrate('database/migrations/2022_03_07_012545_create_tags_table.php'); + $this->initTag(); + $this->doLog("[INIT_TAG]"); + } + @@ -326,6 +337,25 @@ class Update extends Install $this->doLog("[COMPOSER INSTALL] SUCCESS"); } + public function initTag() + { + $priority = count(Tag::DEFAULTS); + $dateTimeStringNow = date('Y-m-d H:i:s'); + foreach (Tag::DEFAULTS as $value) { + $attributes = [ + 'name' => $value['name'], + ]; + $values = [ + 'priority' => $priority, + 'color' => $value['color'], + 'created_at' => $dateTimeStringNow, + 'updated_at' => $dateTimeStringNow, + ]; + Tag::query()->firstOrCreate($attributes, $values); + $priority--; + } + } + }