Skip to content

Commit 504242f

Browse files
committed
Do not create news about myaac, if any news already exist (on installation)
1 parent e2bab42 commit 504242f

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

install/steps/7-finish.php

+30-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use MyAAC\Models\News;
34
use MyAAC\Settings;
45

56
defined('MYAAC') or die('Direct access not allowed!');
@@ -104,19 +105,36 @@
104105
$player->save();
105106
}
106107

107-
$player_id = 0;
108-
$query = $db->query("SELECT `id` FROM `players` WHERE `name` = " . $db->quote($player_name) . ";");
109-
if($query->rowCount() == 1) {
110-
$query = $query->fetch();
111-
$player_id = $query['id'];
112-
}
113-
114-
$query = $db->query("SELECT `id` FROM `" . TABLE_PREFIX ."news` WHERE `title` LIKE 'Hello!';");
115-
if($query->rowCount() == 0) {
116-
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');
117-
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');")) {
118-
success($locale['step_database_created_news']);
108+
if(!News::all()->count()) {
109+
$player_id = 0;
110+
$tmpNewsPlayer = \MyAAC\Models\Player::where('name', $player_name)->first();
111+
if($tmpNewsPlayer) {
112+
$player_id = $tmpNewsPlayer->id;
119113
}
114+
115+
News::create([
116+
'type' => 1,
117+
'date' => time(),
118+
'category' => 2,
119+
'title' => 'Hello!',
120+
'body' => 'MyAAC is just READY to use!',
121+
'player_id' => $player_id,
122+
'comments' => 'https://my-aac.org',
123+
'hide' => 0,
124+
]);
125+
126+
News::create([
127+
'type' => 2,
128+
'date' => time(),
129+
'category' => 4,
130+
'title' => 'Hello tickers!',
131+
'body' => 'https://my-aac.org',
132+
'player_id' => $player_id,
133+
'comments' => '',
134+
'hide' => 0,
135+
]);
136+
137+
success($locale['step_database_created_news']);
120138
}
121139

122140
$settings = Settings::getInstance();

0 commit comments

Comments
 (0)