mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-26 14:04:17 +01:00
Database import tables on every install with "IF NOT EXISTS"
This fixed errors when one table is missing or is duplicated
This commit is contained in:
68
install/includes/import_base_data.php
Normal file
68
install/includes/import_base_data.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
use MyAAC\Models\Changelog;
|
||||
use MyAAC\Models\Config;
|
||||
use MyAAC\Models\ForumBoard;
|
||||
use MyAAC\Models\Gallery;
|
||||
use MyAAC\Models\NewsCategory;
|
||||
|
||||
if (NewsCategory::count() === 0) {
|
||||
$newsCategories = [
|
||||
0, 1, 2, 3, 4
|
||||
];
|
||||
|
||||
foreach ($newsCategories as $iconId) {
|
||||
NewsCategory::create([
|
||||
'icon_id' => $iconId,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (Changelog::count() === 0) {
|
||||
Changelog::create([
|
||||
'type' => 3,
|
||||
'where' => 2,
|
||||
'date' => time(),
|
||||
'body' => 'MyAAC installed. (:',
|
||||
'hide' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
if (Config::where('name', 'database_version')->count() === 0) {
|
||||
Config::create([
|
||||
'name' => 'database_version',
|
||||
'value' => DATABASE_VERSION,
|
||||
]);
|
||||
}
|
||||
|
||||
if (ForumBoard::count() === 0) {
|
||||
$forumBoards = [
|
||||
['name' => 'News', 'description' => 'News commenting', 'closed' => 1],
|
||||
['name' => 'Trade', 'description' => 'Trade offers.', 'closed' => 0],
|
||||
['name' => 'Quests', 'description' => 'Quest making.', 'closed' => 0],
|
||||
['name' => 'Pictures', 'description' => 'Your pictures.', 'closed' => 0],
|
||||
['name' => 'Bug Report', 'description' => 'Report bugs there.', 'closed' => 0],
|
||||
];
|
||||
|
||||
$i = 0;
|
||||
foreach ($forumBoards as $forumBoard) {
|
||||
ForumBoard::create([
|
||||
'name' => $forumBoard['name'],
|
||||
'description' => $forumBoard['description'],
|
||||
'ordering' => $i++,
|
||||
'closed' => $forumBoard['closed'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (Gallery::count() === 0) {
|
||||
Gallery::create([
|
||||
'comment' => 'Demon',
|
||||
'image' => 'images/gallery/demon.jpg',
|
||||
'thumb' => 'images/gallery/demon_thumb.gif',
|
||||
'author' => 'MyAAC',
|
||||
'ordering' => 0,
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user