From 504242fb846b73b56b87bc1e39d070687ad7f5b4 Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 23 May 2024 23:40:27 +0200 Subject: [PATCH] Do not create news about myaac, if any news already exist (on installation) --- install/steps/7-finish.php | 42 +++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/install/steps/7-finish.php b/install/steps/7-finish.php index 3c4094dc..4dcb8cf8 100644 --- a/install/steps/7-finish.php +++ b/install/steps/7-finish.php @@ -1,5 +1,6 @@ save(); } - $player_id = 0; - $query = $db->query("SELECT `id` FROM `players` WHERE `name` = " . $db->quote($player_name) . ";"); - if($query->rowCount() == 1) { - $query = $query->fetch(); - $player_id = $query['id']; - } - - $query = $db->query("SELECT `id` FROM `" . TABLE_PREFIX ."news` WHERE `title` LIKE 'Hello!';"); - if($query->rowCount() == 0) { - if(query("INSERT INTO `" . TABLE_PREFIX ."news` (`id`, `type`, `date`, `category`, `title`, `body`, `player_id`, `comments`, `hide`) VALUES (NULL, '1', UNIX_TIMESTAMP(), '2', 'Hello!', 'MyAAC is just READY to use!', " . $player_id . ", 'https://my-aac.org', '0'); - INSERT INTO `myaac_news` (`id`, `type`, `date`, `category`, `title`, `body`, `player_id`, `comments`, `hide`) VALUES (NULL, '2', UNIX_TIMESTAMP(), '4', 'Hello tickets!', 'https://my-aac.org', " . $player_id . ", '', '0');")) { - success($locale['step_database_created_news']); + if(!News::all()->count()) { + $player_id = 0; + $tmpNewsPlayer = \MyAAC\Models\Player::where('name', $player_name)->first(); + if($tmpNewsPlayer) { + $player_id = $tmpNewsPlayer->id; } + + News::create([ + 'type' => 1, + 'date' => time(), + 'category' => 2, + 'title' => 'Hello!', + 'body' => 'MyAAC is just READY to use!', + 'player_id' => $player_id, + 'comments' => 'https://my-aac.org', + 'hide' => 0, + ]); + + News::create([ + 'type' => 2, + 'date' => time(), + 'category' => 4, + 'title' => 'Hello tickers!', + 'body' => 'https://my-aac.org', + 'player_id' => $player_id, + 'comments' => '', + 'hide' => 0, + ]); + + success($locale['step_database_created_news']); } $settings = Settings::getInstance();