Do not create news about myaac, if any news already exist (on installation)

This commit is contained in:
slawkens 2024-05-23 23:40:27 +02:00
parent e2bab4220b
commit 504242fb84

View File

@ -1,5 +1,6 @@
<?php <?php
use MyAAC\Models\News;
use MyAAC\Settings; use MyAAC\Settings;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
@ -104,20 +105,37 @@ else {
$player->save(); $player->save();
} }
if(!News::all()->count()) {
$player_id = 0; $player_id = 0;
$query = $db->query("SELECT `id` FROM `players` WHERE `name` = " . $db->quote($player_name) . ";"); $tmpNewsPlayer = \MyAAC\Models\Player::where('name', $player_name)->first();
if($query->rowCount() == 1) { if($tmpNewsPlayer) {
$query = $query->fetch(); $player_id = $tmpNewsPlayer->id;
$player_id = $query['id'];
} }
$query = $db->query("SELECT `id` FROM `" . TABLE_PREFIX ."news` WHERE `title` LIKE 'Hello!';"); News::create([
if($query->rowCount() == 0) { 'type' => 1,
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'); 'date' => time(),
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');")) { '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']); success($locale['step_database_created_news']);
} }
}
$settings = Settings::getInstance(); $settings = Settings::getInstance();
foreach($_SESSION as $key => $value) { foreach($_SESSION as $key => $value) {