upgrade add init tag

This commit is contained in:
xiaomlove
2022-03-08 15:25:15 +08:00
parent 718a57539d
commit 98a33baf81

View File

@@ -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--;
}
}
}