@@ -8,7 +8,7 @@ |
||
8 | 8 | function flt_mission_destroy($mission_data) { |
9 | 9 | $fleet_row = $mission_data['fleet']; |
10 | 10 | $destination_planet = $mission_data['dst_planet']; |
11 | - if(!$destination_planet || !is_array($destination_planet) || $destination_planet['planet_type'] != PT_MOON) { |
|
11 | + if (!$destination_planet || !is_array($destination_planet) || $destination_planet['planet_type'] != PT_MOON) { |
|
12 | 12 | fleet_send_back($fleet_row); |
13 | 13 | |
14 | 14 | return CACHE_FLEET; |
@@ -170,7 +170,7 @@ |
||
170 | 170 | |
171 | 171 | function upd_db_unit_by_location($user_id = 0, $location_type, $location_id, $unit_snid = 0, $for_update = false, $fields = '*') { |
172 | 172 | return db_fetch(upd_do_query( |
173 | - "SELECT {$fields} |
|
173 | + "select {$fields} |
|
174 | 174 | FROM {{unit}} |
175 | 175 | WHERE |
176 | 176 | `unit_location_type` = {$location_type} AND `unit_location_id` = {$location_id} AND " . DBStaticUnit::db_unit_time_restrictions() . |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if(!defined('IN_UPDATE')) { |
|
3 | +if (!defined('IN_UPDATE')) { |
|
4 | 4 | die('Trying to call update helpers externally!'); |
5 | 5 | } |
6 | 6 | |
@@ -8,12 +8,12 @@ discard block |
||
8 | 8 | global $update_tables; |
9 | 9 | |
10 | 10 | upd_add_more_time(); |
11 | - if(!$no_log) { |
|
11 | + if (!$no_log) { |
|
12 | 12 | upd_log_message("Performing query '{$query}'"); |
13 | 13 | } |
14 | 14 | |
15 | - if(strpos($query, '{{') !== false) { |
|
16 | - foreach($update_tables as $tableName => $cork) { |
|
15 | + if (strpos($query, '{{') !== false) { |
|
16 | + foreach ($update_tables as $tableName => $cork) { |
|
17 | 17 | $query = str_replace("{{{$tableName}}}", classSupernova::$db->db_prefix . $tableName, $query); |
18 | 18 | } |
19 | 19 | } |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | global $config, $sys_log_disabled; |
26 | 26 | |
27 | 27 | $config->db_loadItem($key); |
28 | - if($condition || !isset($config->$key)) { |
|
28 | + if ($condition || !isset($config->$key)) { |
|
29 | 29 | upd_add_more_time(); |
30 | - if(!$sys_log_disabled) { |
|
30 | + if (!$sys_log_disabled) { |
|
31 | 31 | upd_log_message("Updating config key '{$key}' with value '{$default_value}'"); |
32 | 32 | } |
33 | 33 | $config->db_saveItem($key, $default_value); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | function upd_log_message($message) { |
56 | 56 | global $sys_log_disabled, $upd_log, $debug; |
57 | 57 | |
58 | - if($sys_log_disabled) |
|
58 | + if ($sys_log_disabled) |
|
59 | 59 | { |
60 | 60 | // print("{$message}<br />"); |
61 | 61 | } else { |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | function upd_unset_table_info($table_name) { |
68 | 68 | global $update_tables, $update_indexes, $update_foreigns; |
69 | 69 | |
70 | - if(isset($update_tables[$table_name])) { |
|
70 | + if (isset($update_tables[$table_name])) { |
|
71 | 71 | unset($update_tables[$table_name]); |
72 | 72 | } |
73 | 73 | |
74 | - if(isset($update_indexes[$table_name])) { |
|
74 | + if (isset($update_indexes[$table_name])) { |
|
75 | 75 | unset($update_indexes[$table_name]); |
76 | 76 | } |
77 | 77 | |
78 | - if(isset($update_foreigns[$table_name])) { |
|
78 | + if (isset($update_foreigns[$table_name])) { |
|
79 | 79 | unset($update_foreigns[$table_name]); |
80 | 80 | } |
81 | 81 | } |
@@ -89,18 +89,18 @@ discard block |
||
89 | 89 | upd_unset_table_info($tableName); |
90 | 90 | |
91 | 91 | $q1 = upd_do_query("SHOW FULL COLUMNS FROM {$prefix_table_name};", true); |
92 | - while($r1 = db_fetch($q1)) { |
|
92 | + while ($r1 = db_fetch($q1)) { |
|
93 | 93 | $update_tables[$tableName][$r1['Field']] = $r1; |
94 | 94 | } |
95 | 95 | |
96 | 96 | $q1 = upd_do_query("SHOW INDEX FROM {$prefix_table_name};", true); |
97 | - while($r1 = db_fetch($q1)) { |
|
97 | + while ($r1 = db_fetch($q1)) { |
|
98 | 98 | $update_indexes[$tableName][$r1['Key_name']] .= "{$r1['Column_name']},"; |
99 | 99 | $update_indexes_full[$tableName][$r1['Key_name']][$r1['Column_name']] = $r1; |
100 | 100 | } |
101 | 101 | |
102 | - $q1 = upd_do_query("SELECT * FROM `information_schema`.`KEY_COLUMN_USAGE` WHERE `TABLE_SCHEMA` = '" . db_escape(classSupernova::$db_name). "' AND TABLE_NAME = '{$prefix_table_name}' AND REFERENCED_TABLE_NAME is not null;", true); |
|
103 | - while($r1 = db_fetch($q1)) { |
|
102 | + $q1 = upd_do_query("SELECT * FROM `information_schema`.`KEY_COLUMN_USAGE` WHERE `TABLE_SCHEMA` = '" . db_escape(classSupernova::$db_name) . "' AND TABLE_NAME = '{$prefix_table_name}' AND REFERENCED_TABLE_NAME is not null;", true); |
|
103 | + while ($r1 = db_fetch($q1)) { |
|
104 | 104 | $table_referenced = str_replace($config->db_prefix, '', $r1['REFERENCED_TABLE_NAME']); |
105 | 105 | |
106 | 106 | $update_foreigns[$tableName][$r1['CONSTRAINT_NAME']] .= "{$r1['COLUMN_NAME']},{$table_referenced},{$r1['REFERENCED_COLUMN_NAME']};"; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | function upd_alter_table($table, $alters, $condition = true) { |
111 | 111 | global $config, $update_tables; |
112 | 112 | |
113 | - if(!$condition) { |
|
113 | + if (!$condition) { |
|
114 | 114 | return; |
115 | 115 | } |
116 | 116 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $alters_print = is_array($alters) ? dump($alters) : $alters; |
119 | 119 | upd_log_message("Altering table '{$table}' with alterations {$alters_print}"); |
120 | 120 | |
121 | - if(!is_array($alters)) { |
|
121 | + if (!is_array($alters)) { |
|
122 | 122 | $alters = array($alters); |
123 | 123 | } |
124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | $result = upd_do_query($qry); |
130 | 130 | $error = db_error(); |
131 | - if($error) { |
|
131 | + if ($error) { |
|
132 | 132 | die("Altering error for table `{$table}`: {$error}<br />{$alters_print}"); |
133 | 133 | } |
134 | 134 | |
@@ -155,19 +155,19 @@ discard block |
||
155 | 155 | function upd_create_table($table_name, $declaration, $tableOptions = '') { |
156 | 156 | global $config, $update_tables; |
157 | 157 | |
158 | - if(!$update_tables[$table_name]) { |
|
158 | + if (!$update_tables[$table_name]) { |
|
159 | 159 | upd_do_query('set foreign_key_checks = 0;', true); |
160 | 160 | $declaration = trim($declaration); |
161 | - if(substr($declaration, 0, 1) != '(') { |
|
161 | + if (substr($declaration, 0, 1) != '(') { |
|
162 | 162 | $declaration = "($declaration)"; |
163 | 163 | } |
164 | 164 | $tableOptions = trim($tableOptions); |
165 | - if(!empty($tableOptions)) { |
|
165 | + if (!empty($tableOptions)) { |
|
166 | 166 | $declaration .= $tableOptions; |
167 | 167 | } |
168 | 168 | $result = upd_do_query("CREATE TABLE IF NOT EXISTS `{$config->db_prefix}{$table_name}` {$declaration}"); |
169 | 169 | $error = db_error(); |
170 | - if($error) { |
|
170 | + if ($error) { |
|
171 | 171 | die("Creating error for table `{$table_name}`: {$error}<br />" . dump($declaration)); |
172 | 172 | } |
173 | 173 | upd_do_query('set foreign_key_checks = 1;', true); |
@@ -193,14 +193,14 @@ discard block |
||
193 | 193 | |
194 | 194 | |
195 | 195 | function upd_db_unit_changeset_prepare($unit_id, $unit_value, $user, $planet_id = null) { |
196 | - if(!is_array($user)) { |
|
196 | + if (!is_array($user)) { |
|
197 | 197 | // TODO - remove later |
198 | 198 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: upd_db_unit_changeset_prepare() - USER is not ARRAY</h1>'); |
199 | 199 | pdump(debug_backtrace()); |
200 | 200 | die('USER is not ARRAY'); |
201 | 201 | } |
202 | 202 | |
203 | - if(!isset($user['id']) || !$user['id']) { |
|
203 | + if (!isset($user['id']) || !$user['id']) { |
|
204 | 204 | // TODO - remove later |
205 | 205 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: upd_db_unit_changeset_prepare() - USER[id] пустой</h1>'); |
206 | 206 | pdump($user); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | |
216 | 216 | $db_changeset = array(); |
217 | 217 | $temp = upd_db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id'); |
218 | - if($temp['unit_id']) { |
|
218 | + if ($temp['unit_id']) { |
|
219 | 219 | // update |
220 | 220 | $db_changeset = array( |
221 | 221 | 'action' => SQL_OP_UPDATE, |
@@ -261,53 +261,53 @@ discard block |
||
261 | 261 | |
262 | 262 | |
263 | 263 | function upd_db_changeset_apply($db_changeset) { |
264 | - if(!is_array($db_changeset) || empty($db_changeset)) { |
|
264 | + if (!is_array($db_changeset) || empty($db_changeset)) { |
|
265 | 265 | return; |
266 | 266 | } |
267 | 267 | |
268 | - foreach($db_changeset as $table_name => $table_data) { |
|
269 | - foreach($table_data as $record_id => $conditions) { |
|
268 | + foreach ($db_changeset as $table_name => $table_data) { |
|
269 | + foreach ($table_data as $record_id => $conditions) { |
|
270 | 270 | $where = ''; |
271 | - if(!empty($conditions['where'])) { |
|
271 | + if (!empty($conditions['where'])) { |
|
272 | 272 | $where = 'WHERE ' . implode(' AND ', $conditions['where']); |
273 | 273 | } |
274 | 274 | |
275 | 275 | $fields = array(); |
276 | - if($conditions['fields']) { |
|
277 | - foreach($conditions['fields'] as $field_name => $field_data) { |
|
276 | + if ($conditions['fields']) { |
|
277 | + foreach ($conditions['fields'] as $field_name => $field_data) { |
|
278 | 278 | $condition = "`{$field_name}` = "; |
279 | 279 | $value = ''; |
280 | - if($field_data['delta']) { |
|
280 | + if ($field_data['delta']) { |
|
281 | 281 | $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta']; |
282 | - } elseif($field_data['set']) { |
|
283 | - $value = (is_string($field_data['set']) ? "'{$field_data['set']}'": $field_data['set']); |
|
282 | + } elseif ($field_data['set']) { |
|
283 | + $value = (is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set']); |
|
284 | 284 | } |
285 | - if($value) { |
|
285 | + if ($value) { |
|
286 | 286 | $fields[] = $condition . $value; |
287 | 287 | } |
288 | 288 | } |
289 | 289 | } |
290 | 290 | $fields = implode(',', $fields); |
291 | 291 | |
292 | - switch($conditions['action']) { |
|
292 | + switch ($conditions['action']) { |
|
293 | 293 | case SQL_OP_DELETE: |
294 | 294 | upd_do_query("DELETE FROM {{{$table_name}}} {$where}"); |
295 | 295 | break; |
296 | 296 | |
297 | 297 | case SQL_OP_UPDATE: |
298 | - if($fields) { |
|
298 | + if ($fields) { |
|
299 | 299 | upd_do_query("UPDATE {{{$table_name}}} SET {$fields} {$where}"); |
300 | 300 | } |
301 | 301 | break; |
302 | 302 | |
303 | 303 | case SQL_OP_INSERT: |
304 | - if($fields) { |
|
304 | + if ($fields) { |
|
305 | 305 | upd_do_query("INSERT INTO {{{$table_name}}} SET {$fields}"); |
306 | 306 | } |
307 | 307 | break; |
308 | 308 | |
309 | 309 | case SQL_OP_REPLACE: |
310 | - if($fields) { |
|
310 | + if ($fields) { |
|
311 | 311 | upd_do_query("REPLACE INTO {{{$table_name}}} SET {$fields}"); |
312 | 312 | } |
313 | 313 | break; |
@@ -80,6 +80,9 @@ |
||
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | +/** |
|
84 | + * @param string $prefix_table_name |
|
85 | + */ |
|
83 | 86 | function upd_load_table_info($prefix_table_name, $prefixed = true) { |
84 | 87 | global $config, $update_tables, $update_indexes, $update_indexes_full, $update_foreigns; |
85 | 88 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | $source_planet = &$mission_data['src_planet']; |
15 | 15 | $destination_planet = &$mission_data['dst_planet']; |
16 | 16 | |
17 | - if(!isset($destination_planet['id']) || !$destination_planet['id_owner']) |
|
17 | + if (!isset($destination_planet['id']) || !$destination_planet['id_owner']) |
|
18 | 18 | { |
19 | 19 | // doquery("UPDATE {{fleets}} SET `fleet_mess` = 1 WHERE `fleet_id` = {$fleet_row['fleet_id']} LIMIT 1;"); |
20 | 20 | fleet_send_back($fleet_row); |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | $destination_planet['name'], uni_render_coordinates_href($fleet_row, 'fleet_end_', 3, ''), |
28 | 28 | $fleet_row['fleet_resource_metal'], $lang['Metal'], |
29 | 29 | $fleet_row['fleet_resource_crystal'], $lang['Crystal'], |
30 | - $fleet_row['fleet_resource_deuterium'], $lang['Deuterium'] ); |
|
30 | + $fleet_row['fleet_resource_deuterium'], $lang['Deuterium']); |
|
31 | 31 | msg_send_simple_message($fleet_row['fleet_target_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message); |
32 | 32 | |
33 | - if($fleet_row['fleet_target_owner'] <> $fleet_row['fleet_owner']) |
|
33 | + if ($fleet_row['fleet_target_owner'] <> $fleet_row['fleet_owner']) |
|
34 | 34 | { |
35 | 35 | msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message); |
36 | 36 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | * @copyright 2008 By Chlorel for XNova |
9 | 9 | */ |
10 | 10 | |
11 | -function flt_mission_transport(&$mission_data) |
|
12 | -{ |
|
11 | +function flt_mission_transport(&$mission_data) { |
|
13 | 12 | $fleet_row = &$mission_data['fleet']; |
14 | 13 | $source_planet = &$mission_data['src_planet']; |
15 | 14 | $destination_planet = &$mission_data['dst_planet']; |
@@ -14,6 +14,9 @@ |
||
14 | 14 | $this->design = $gc->design; |
15 | 15 | } |
16 | 16 | |
17 | + /** |
|
18 | + * @param integer $authorAccessLevel |
|
19 | + */ |
|
17 | 20 | protected function applyElements($elements, $text, $authorAccessLevel = AUTH_LEVEL_REGISTERED) { |
18 | 21 | foreach ($elements as $auth_level => $element) { |
19 | 22 | if ($auth_level > $authorAccessLevel) { |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * <p>null - транзакция НЕ должна быть запущена</p> |
310 | 310 | * <p>true - транзакция должна быть запущена - для совместимости с $for_update</p> |
311 | 311 | * <p>false - всё равно - для совместимости с $for_update</p> |
312 | - * @return bool Текущий статус транзакции |
|
312 | + * @return null|boolean Текущий статус транзакции |
|
313 | 313 | */ |
314 | 314 | public static function db_transaction_check($status = null) { |
315 | 315 | $error_msg = false; |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | /** |
377 | 377 | * Блокирует указанные таблицу/список таблиц |
378 | 378 | * |
379 | - * @param string|array $tables Таблица/список таблиц для блокировки. Названия таблиц - без префиксов |
|
379 | + * @param string $tables Таблица/список таблиц для блокировки. Названия таблиц - без префиксов |
|
380 | 380 | * <p>string - название таблицы для блокировки</p> |
381 | 381 | * <p>array - массив, где ключ - имя таблицы, а значение - условия блокировки элементов</p> |
382 | 382 | */ |
@@ -188,14 +188,18 @@ discard block |
||
188 | 188 | // Перепаковывает массив на заданную глубину, убирая поля с null |
189 | 189 | public static function array_repack(&$array, $level = 0) { |
190 | 190 | // TODO $lock_table не нужна тут |
191 | - if(!is_array($array)) return; |
|
191 | + if(!is_array($array)) { |
|
192 | + return; |
|
193 | + } |
|
192 | 194 | |
193 | 195 | foreach($array as $key => &$value) { |
194 | 196 | if($value === null) { |
195 | 197 | unset($array[$key]); |
196 | 198 | } elseif($level > 0 && is_array($value)) { |
197 | 199 | static::array_repack($value, $level - 1); |
198 | - if(empty($value)) unset($array[$key]); |
|
200 | + if(empty($value)) { |
|
201 | + unset($array[$key]); |
|
202 | + } |
|
199 | 203 | } |
200 | 204 | } |
201 | 205 | } |
@@ -204,7 +208,9 @@ discard block |
||
204 | 208 | // TODO Вынести в отдельный объект |
205 | 209 | public static function cache_repack($location_type, $record_id = 0) { |
206 | 210 | // Если есть $user_id - проверяем, а надо ли перепаковывать? |
207 | - if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) return; |
|
211 | + if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) { |
|
212 | + return; |
|
213 | + } |
|
208 | 214 | |
209 | 215 | static::array_repack(static::$data[$location_type]); |
210 | 216 | static::array_repack(static::$locator[$location_type], 3); // TODO У каждого типа локации - своя глубина!!!! Но можно и глубже ??? |
@@ -249,7 +255,9 @@ discard block |
||
249 | 255 | */ |
250 | 256 | public static function cache_set($location_type, $record_id, $record, $force_overwrite = false, $skip_lock = false) { |
251 | 257 | // нет идентификатора - выход |
252 | - if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) return; |
|
258 | + if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) { |
|
259 | + return; |
|
260 | + } |
|
253 | 261 | |
254 | 262 | $in_transaction = static::db_transaction_check(false); |
255 | 263 | if( |
@@ -283,8 +291,9 @@ discard block |
||
283 | 291 | return static::$locks[$location_type][$record_id] = true; // Не всегда - от результата |
284 | 292 | } |
285 | 293 | public static function cache_lock_unset($location_type, $record_id) { |
286 | - if(isset(static::$locks[$location_type][$record_id])) |
|
287 | - unset(static::$locks[$location_type][$record_id]); |
|
294 | + if(isset(static::$locks[$location_type][$record_id])) { |
|
295 | + unset(static::$locks[$location_type][$record_id]); |
|
296 | + } |
|
288 | 297 | return true; // Не всегда - от результата |
289 | 298 | } |
290 | 299 | public static function cache_lock_unset_all() { |
@@ -454,8 +463,9 @@ discard block |
||
454 | 463 | |
455 | 464 | while($row = db_fetch($query)) { |
456 | 465 | // Исключаем из списка родительских ИД уже заблокированные записи |
457 | - if(!static::cache_lock_get($owner_location_type, $row['parent_id'])) |
|
458 | - $parent_id_list[$row['parent_id']] = $row['parent_id']; |
|
466 | + if(!static::cache_lock_get($owner_location_type, $row['parent_id'])) { |
|
467 | + $parent_id_list[$row['parent_id']] = $row['parent_id']; |
|
468 | + } |
|
459 | 469 | } |
460 | 470 | |
461 | 471 | // Если все-таки какие-то записи еще не заблокированы - вынимаем текущие версии из базы |
@@ -483,7 +493,9 @@ discard block |
||
483 | 493 | if(is_array($query_cache)) { |
484 | 494 | foreach($query_cache as $key => $value) { |
485 | 495 | $result[$key] = $value; |
486 | - if($fetch) break; |
|
496 | + if($fetch) { |
|
497 | + break; |
|
498 | + } |
|
487 | 499 | } |
488 | 500 | } |
489 | 501 | return $fetch ? (is_array($result) ? reset($result) : false) : $result; |
@@ -491,12 +503,15 @@ discard block |
||
491 | 503 | } |
492 | 504 | |
493 | 505 | public static function db_upd_record_by_id($location_type, $record_id, $set) { |
494 | - if(!($record_id = idval($record_id)) || !($set = trim($set))) return false; |
|
506 | + if(!($record_id = idval($record_id)) || !($set = trim($set))) { |
|
507 | + return false; |
|
508 | + } |
|
495 | 509 | |
496 | 510 | $location_info = &static::$location_info[$location_type]; |
497 | 511 | $id_field = $location_info[P_ID]; |
498 | 512 | $table_name = $location_info[P_TABLE_NAME]; |
499 | - if($result = static::db_query_update("UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
513 | + if($result = static::db_query_update("UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) { |
|
514 | + // TODO Как-то вернуть может быть LIMIT 1 ? |
|
500 | 515 | { |
501 | 516 | if(static::$db->db_affected_rows()) { |
502 | 517 | // Обновляем данные только если ряд был затронут |
@@ -504,6 +519,7 @@ discard block |
||
504 | 519 | |
505 | 520 | // Тут именно так, а не cache_unset - что бы в кэшах автоматически обновилась запись. Будет нужно на будущее |
506 | 521 | static::$data[$location_type][$record_id] = null; |
522 | + } |
|
507 | 523 | // Вытаскиваем обновленную запись |
508 | 524 | static::db_get_record_by_id($location_type, $record_id); |
509 | 525 | static::cache_clear($location_type, false); // Мягкий сброс - только $queries |
@@ -513,7 +529,9 @@ discard block |
||
513 | 529 | return $result; |
514 | 530 | } |
515 | 531 | public static function db_upd_record_list($location_type, $condition, $set) { |
516 | - if(!($set = trim($set))) return false; |
|
532 | + if(!($set = trim($set))) { |
|
533 | + return false; |
|
534 | + } |
|
517 | 535 | |
518 | 536 | $condition = trim($condition); |
519 | 537 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
@@ -534,9 +552,11 @@ discard block |
||
534 | 552 | $set = trim($set); |
535 | 553 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
536 | 554 | if($result = static::db_query_insert("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
537 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
555 | + if(static::$db->db_affected_rows()) { |
|
556 | + // Обновляем данные только если ряд был затронут |
|
538 | 557 | { |
539 | 558 | $record_id = db_insert_id(); |
559 | + } |
|
540 | 560 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
541 | 561 | $result = static::db_get_record_by_id($location_type, $record_id); |
542 | 562 | // Очищаем второстепенные кэши - потому что вставленная запись могла повлиять на результаты запросов или локация или еще чего |
@@ -548,37 +568,43 @@ discard block |
||
548 | 568 | return $result; |
549 | 569 | } |
550 | 570 | |
551 | - public static function db_del_record_by_id($location_type, $safe_record_id) |
|
552 | - { |
|
553 | - if(!($safe_record_id = idval($safe_record_id))) return false; |
|
571 | + public static function db_del_record_by_id($location_type, $safe_record_id) { |
|
572 | + if(!($safe_record_id = idval($safe_record_id))) { |
|
573 | + return false; |
|
574 | + } |
|
554 | 575 | |
555 | 576 | $location_info = &static::$location_info[$location_type]; |
556 | 577 | $id_field = $location_info[P_ID]; |
557 | 578 | $table_name = $location_info[P_TABLE_NAME]; |
558 | 579 | if($result = static::db_query_delete("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) |
559 | 580 | { |
560 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
581 | + if(static::$db->db_affected_rows()) { |
|
582 | + // Обновляем данные только если ряд был затронут |
|
561 | 583 | { |
562 | 584 | static::cache_unset($location_type, $safe_record_id); |
563 | 585 | } |
586 | + } |
|
564 | 587 | } |
565 | 588 | |
566 | 589 | return $result; |
567 | 590 | } |
568 | - public static function db_del_record_list($location_type, $condition) |
|
569 | - { |
|
570 | - if(!($condition = trim($condition))) return false; |
|
591 | + public static function db_del_record_list($location_type, $condition) { |
|
592 | + if(!($condition = trim($condition))) { |
|
593 | + return false; |
|
594 | + } |
|
571 | 595 | |
572 | 596 | $location_info = &static::$location_info[$location_type]; |
573 | 597 | $table_name = $location_info[P_TABLE_NAME]; |
574 | 598 | |
575 | 599 | if($result = static::db_query_delete("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) |
576 | 600 | { |
577 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
601 | + if(static::$db->db_affected_rows()) { |
|
602 | + // Обновляем данные только если ряд был затронут |
|
578 | 603 | { |
579 | 604 | // Обнуление кэша, потому что непонятно, что поменялось |
580 | 605 | static::cache_clear($location_type); |
581 | 606 | } |
607 | + } |
|
582 | 608 | } |
583 | 609 | |
584 | 610 | return $result; |
@@ -604,8 +630,7 @@ discard block |
||
604 | 630 | * <p>false - Нет записи с указанным ID и $player</p> |
605 | 631 | * <p>array - запись типа $user</p> |
606 | 632 | */ |
607 | - public static function db_get_user_by_id($user_id_unsafe, $for_update = false, $fields = '*', $player = null) |
|
608 | - { |
|
633 | + public static function db_get_user_by_id($user_id_unsafe, $for_update = false, $fields = '*', $player = null) { |
|
609 | 634 | $user = static::db_get_record_by_id(LOC_USER, $user_id_unsafe, $for_update, $fields); |
610 | 635 | |
611 | 636 | return (is_array($user) && |
@@ -617,14 +642,15 @@ discard block |
||
617 | 642 | ($player === false && $user['user_as_ally']) |
618 | 643 | )) ? $user : false; |
619 | 644 | } |
620 | - public static function db_get_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) |
|
621 | - { |
|
645 | + public static function db_get_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) { |
|
622 | 646 | // TODO Проверить, кстати - а везде ли нужно выбирать юзеров или где-то все-таки ищутся Альянсы ? |
623 | - if(!($username_unsafe = trim($username_unsafe))) return false; |
|
647 | + if(!($username_unsafe = trim($username_unsafe))) { |
|
648 | + return false; |
|
649 | + } |
|
624 | 650 | |
625 | 651 | $user = null; |
626 | - if(is_array(static::$data[LOC_USER])) |
|
627 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) |
|
652 | + if(is_array(static::$data[LOC_USER])) { |
|
653 | + foreach(static::$data[LOC_USER] as $user_id => $user_data) |
|
628 | 654 | { |
629 | 655 | if(is_array($user_data) && isset($user_data['username'])) |
630 | 656 | { |
@@ -634,6 +660,7 @@ discard block |
||
634 | 660 | { |
635 | 661 | // $user_as_ally = intval($user_data['user_as_ally']); |
636 | 662 | $user_as_ally = idval($user_data['user_as_ally']); |
663 | + } |
|
637 | 664 | if($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) |
638 | 665 | { |
639 | 666 | $user = $user_data; |
@@ -659,7 +686,9 @@ discard block |
||
659 | 686 | } |
660 | 687 | // UNUSED |
661 | 688 | public static function db_get_user_by_email($email_unsafe, $use_both = false, $for_update = false, $fields = '*') { |
662 | - if(!($email_unsafe = strtolower(trim($email_unsafe)))) return false; |
|
689 | + if(!($email_unsafe = strtolower(trim($email_unsafe)))) { |
|
690 | + return false; |
|
691 | + } |
|
663 | 692 | |
664 | 693 | $user = null; |
665 | 694 | if(is_array(static::$data[LOC_USER])) { |
@@ -718,15 +747,13 @@ discard block |
||
718 | 747 | |
719 | 748 | |
720 | 749 | |
721 | - public static function db_unit_time_restrictions($date = SN_TIME_NOW) |
|
722 | - { |
|
750 | + public static function db_unit_time_restrictions($date = SN_TIME_NOW) { |
|
723 | 751 | $date = is_numeric($date) ? "FROM_UNIXTIME({$date})" : "'{$date}'"; |
724 | 752 | return |
725 | 753 | "(unit_time_start IS NULL OR unit_time_start <= {$date}) AND |
726 | 754 | (unit_time_finish IS NULL OR unit_time_finish = '1970-01-01 03:00:00' OR unit_time_finish >= {$date})"; |
727 | 755 | } |
728 | - public static function db_get_unit_by_id($unit_id, $for_update = false, $fields = '*') |
|
729 | - { |
|
756 | + public static function db_get_unit_by_id($unit_id, $for_update = false, $fields = '*') { |
|
730 | 757 | // TODO запихивать в $data[LOC_LOCATION][$location_type][$location_id] |
731 | 758 | $unit = static::db_get_record_by_id(LOC_UNIT, $unit_id, $for_update, $fields); |
732 | 759 | if(is_array($unit)) |
@@ -737,9 +764,10 @@ discard block |
||
737 | 764 | return $unit; |
738 | 765 | } |
739 | 766 | |
740 | - public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) |
|
741 | - { |
|
742 | - if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) return false; |
|
767 | + public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) { |
|
768 | + if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) { |
|
769 | + return false; |
|
770 | + } |
|
743 | 771 | |
744 | 772 | $query_cache = &static::$locator[LOC_UNIT][$location_type][$location_id]; |
745 | 773 | if(!isset($query_cache)) |
@@ -764,8 +792,7 @@ discard block |
||
764 | 792 | |
765 | 793 | return $result; |
766 | 794 | } |
767 | - public static function db_get_unit_by_location($user_id = 0, $location_type, $location_id, $unit_snid = 0, $for_update = false, $fields = '*') |
|
768 | - { |
|
795 | + public static function db_get_unit_by_location($user_id = 0, $location_type, $location_id, $unit_snid = 0, $for_update = false, $fields = '*') { |
|
769 | 796 | static::db_get_unit_list_by_location($user_id, $location_type, $location_id); |
770 | 797 | |
771 | 798 | return $unit_snid ? static::$locator[LOC_UNIT][$location_type][$location_id][$unit_snid] : static::$locator[LOC_UNIT][$location_type][$location_id]; |
@@ -793,8 +820,7 @@ discard block |
||
793 | 820 | * TODO Переформатировать вывод данных, что бы можно было возвращать данные по всем планетам и юзерам в одном запросе: добавить подмассивы 'que', 'planets', 'players' |
794 | 821 | * |
795 | 822 | */ |
796 | - public static function db_que_list_by_type_location($user_id, $planet_id = null, $que_type = false, $for_update = false) |
|
797 | - { |
|
823 | + public static function db_que_list_by_type_location($user_id, $planet_id = null, $que_type = false, $for_update = false) { |
|
798 | 824 | if(!$user_id) |
799 | 825 | { |
800 | 826 | pdump(debug_backtrace()); |
@@ -805,15 +831,18 @@ discard block |
||
805 | 831 | |
806 | 832 | $query = array(); |
807 | 833 | |
808 | - if($user_id = idval($user_id)) |
|
809 | - $query[] = "`que_player_id` = {$user_id}"; |
|
834 | + if($user_id = idval($user_id)) { |
|
835 | + $query[] = "`que_player_id` = {$user_id}"; |
|
836 | + } |
|
810 | 837 | |
811 | - if($que_type == QUE_RESEARCH || $planet_id === null) |
|
812 | - $query[] = "`que_planet_id` IS NULL"; |
|
813 | - elseif($planet_id) |
|
814 | - $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")"; |
|
815 | - if($que_type) |
|
816 | - $query[] = "`que_type` = {$que_type}"; |
|
838 | + if($que_type == QUE_RESEARCH || $planet_id === null) { |
|
839 | + $query[] = "`que_planet_id` IS NULL"; |
|
840 | + } elseif($planet_id) { |
|
841 | + $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")"; |
|
842 | + } |
|
843 | + if($que_type) { |
|
844 | + $query[] = "`que_type` = {$que_type}"; |
|
845 | + } |
|
817 | 846 | |
818 | 847 | $ques['items'] = static::db_get_record_list(LOC_QUE, implode(' AND ', $query)); |
819 | 848 | |
@@ -861,8 +890,7 @@ discard block |
||
861 | 890 | |
862 | 891 | |
863 | 892 | |
864 | - public static function db_changeset_revert() |
|
865 | - { |
|
893 | + public static function db_changeset_revert() { |
|
866 | 894 | // TODO Для этапа 1 - достаточно чистить только те таблицы, что были затронуты |
867 | 895 | // Для этапа 2 - чистить только записи |
868 | 896 | // Для этапа 3 - возвращать всё |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @return classSupernova |
200 | 200 | */ |
201 | 201 | public static function sn() { |
202 | - if(!isset(self::$_sn)) { |
|
202 | + if (!isset(self::$_sn)) { |
|
203 | 203 | self::$_sn = new self(); |
204 | 204 | } |
205 | 205 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | |
213 | 213 | |
214 | 214 | public static function log_file($message, $spaces = 0) { |
215 | - if(self::$debug) { |
|
215 | + if (self::$debug) { |
|
216 | 216 | self::$debug->log_file($message, $spaces); |
217 | 217 | } |
218 | 218 | } |
@@ -220,14 +220,14 @@ discard block |
||
220 | 220 | // Перепаковывает массив на заданную глубину, убирая поля с null |
221 | 221 | public static function array_repack(&$array, $level = 0) { |
222 | 222 | // TODO $lock_table не нужна тут |
223 | - if(!is_array($array)) return; |
|
223 | + if (!is_array($array)) return; |
|
224 | 224 | |
225 | - foreach($array as $key => &$value) { |
|
226 | - if($value === null) { |
|
225 | + foreach ($array as $key => &$value) { |
|
226 | + if ($value === null) { |
|
227 | 227 | unset($array[$key]); |
228 | - } elseif($level > 0 && is_array($value)) { |
|
228 | + } elseif ($level > 0 && is_array($value)) { |
|
229 | 229 | static::array_repack($value, $level - 1); |
230 | - if(empty($value)) unset($array[$key]); |
|
230 | + if (empty($value)) unset($array[$key]); |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | // TODO Вынести в отдельный объект |
237 | 237 | public static function cache_repack($location_type, $record_id = 0) { |
238 | 238 | // Если есть $user_id - проверяем, а надо ли перепаковывать? |
239 | - if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) return; |
|
239 | + if ($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) return; |
|
240 | 240 | |
241 | 241 | static::array_repack(static::$data[$location_type]); |
242 | 242 | static::array_repack(static::$locator[$location_type], 3); // TODO У каждого типа локации - своя глубина!!!! Но можно и глубже ??? |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | } |
245 | 245 | public static function cache_clear($location_type, $hard = true) { |
246 | 246 | //print("<br />CACHE CLEAR {$cache_id} " . ($hard ? 'HARD' : 'SOFT') . "<br />"); |
247 | - if($hard && !empty(static::$data[$location_type])) { |
|
247 | + if ($hard && !empty(static::$data[$location_type])) { |
|
248 | 248 | // Здесь нельзя делать unset - надо записывать NULL, что бы это отразилось на зависимых записях |
249 | - array_walk(static::$data[$location_type], function(&$item){$item = null;}); |
|
249 | + array_walk(static::$data[$location_type], function(&$item) {$item = null; }); |
|
250 | 250 | } |
251 | 251 | static::$locator[$location_type] = array(); |
252 | 252 | static::$queries[$location_type] = array(); |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | } |
255 | 255 | public static function cache_clear_all($hard = true) { |
256 | 256 | //print('<br />CACHE CLEAR ALL<br />'); |
257 | - if($hard) { |
|
257 | + if ($hard) { |
|
258 | 258 | static::$data = array(); |
259 | 259 | static::cache_lock_unset_all(); |
260 | 260 | } |
@@ -281,10 +281,10 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public static function cache_set($location_type, $record_id, $record, $force_overwrite = false, $skip_lock = false) { |
283 | 283 | // нет идентификатора - выход |
284 | - if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) return; |
|
284 | + if (!($record_id = $record[static::$location_info[$location_type][P_ID]])) return; |
|
285 | 285 | |
286 | 286 | $in_transaction = static::db_transaction_check(false); |
287 | - if( |
|
287 | + if ( |
|
288 | 288 | $force_overwrite |
289 | 289 | || |
290 | 290 | // Не заменяются заблокированные записи во время транзакции |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | !static::cache_isset($location_type, $record_id) |
295 | 295 | ) { |
296 | 296 | static::$data[$location_type][$record_id] = $record; |
297 | - if($in_transaction && !$skip_lock) { |
|
297 | + if ($in_transaction && !$skip_lock) { |
|
298 | 298 | static::cache_lock_set($location_type, $record_id); |
299 | 299 | } |
300 | 300 | } |
301 | 301 | } |
302 | 302 | public static function cache_unset($cache_id, $safe_record_id) { |
303 | 303 | // $record_id должен быть проверен заранее ! |
304 | - if(isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) { |
|
304 | + if (isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) { |
|
305 | 305 | // Выставляем запись в null |
306 | 306 | static::$data[$cache_id][$safe_record_id] = null; |
307 | 307 | // Очищаем кэш мягко - что бы удалить очистить связанные данные - кэш локаций и кэш запоросов и всё, что потребуется впредь |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | return static::$locks[$location_type][$record_id] = true; // Не всегда - от результата |
316 | 316 | } |
317 | 317 | public static function cache_lock_unset($location_type, $record_id) { |
318 | - if(isset(static::$locks[$location_type][$record_id])) |
|
318 | + if (isset(static::$locks[$location_type][$record_id])) |
|
319 | 319 | unset(static::$locks[$location_type][$record_id]); |
320 | 320 | return true; // Не всегда - от результата |
321 | 321 | } |
@@ -345,13 +345,13 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public static function db_transaction_check($status = null) { |
347 | 347 | $error_msg = false; |
348 | - if($status && !static::$db_in_transaction) { |
|
348 | + if ($status && !static::$db_in_transaction) { |
|
349 | 349 | $error_msg = 'No transaction started for current operation'; |
350 | - } elseif($status === null && static::$db_in_transaction) { |
|
350 | + } elseif ($status === null && static::$db_in_transaction) { |
|
351 | 351 | $error_msg = 'Transaction is already started'; |
352 | 352 | } |
353 | 353 | |
354 | - if($error_msg) { |
|
354 | + if ($error_msg) { |
|
355 | 355 | // TODO - Убрать позже |
356 | 356 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_transaction_check() - ' . $error_msg . '</h1>'); |
357 | 357 | $backtrace = debug_backtrace(); |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | static::$transaction_id++; |
373 | 373 | doquery('START TRANSACTION'); |
374 | 374 | |
375 | - if($config->db_manual_lock_enabled) { |
|
375 | + if ($config->db_manual_lock_enabled) { |
|
376 | 376 | $config->db_loadItem('var_db_manually_locked'); |
377 | 377 | $config->db_saveItem('var_db_manually_locked', SN_TIME_SQL); |
378 | 378 | } |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | */ |
415 | 415 | public static function db_lock_tables($tables) { |
416 | 416 | $tables = is_array($tables) ? $tables : array($tables => ''); |
417 | - foreach($tables as $table_name => $condition) { |
|
417 | + foreach ($tables as $table_name => $condition) { |
|
418 | 418 | self::$db->doquery("SELECT 1 FROM {{{$table_name}}}" . ($condition ? ' WHERE ' . $condition : '')); |
419 | 419 | } |
420 | 420 | } |
@@ -463,14 +463,14 @@ discard block |
||
463 | 463 | public static function db_get_record_list($location_type, $filter = '', $fetch = false, $no_return = false) { |
464 | 464 | $query_cache = &static::$queries[$location_type][$filter]; |
465 | 465 | |
466 | - if(!isset($query_cache) || $query_cache === null) { |
|
466 | + if (!isset($query_cache) || $query_cache === null) { |
|
467 | 467 | $location_info = &static::$location_info[$location_type]; |
468 | 468 | $id_field = $location_info[P_ID]; |
469 | 469 | $query_cache = array(); |
470 | 470 | |
471 | - if(static::db_transaction_check(false)) { |
|
471 | + if (static::db_transaction_check(false)) { |
|
472 | 472 | // Проходим по всем родителям данной записи |
473 | - foreach($location_info[P_OWNER_INFO] as $owner_data) { |
|
473 | + foreach ($location_info[P_OWNER_INFO] as $owner_data) { |
|
474 | 474 | $owner_location_type = $owner_data[P_LOCATION]; |
475 | 475 | $parent_id_list = array(); |
476 | 476 | // Выбираем родителей данного типа и соответствующие ИД текущего типа |
@@ -484,14 +484,14 @@ discard block |
||
484 | 484 | true |
485 | 485 | ); |
486 | 486 | |
487 | - while($row = db_fetch($query)) { |
|
487 | + while ($row = db_fetch($query)) { |
|
488 | 488 | // Исключаем из списка родительских ИД уже заблокированные записи |
489 | - if(!static::cache_lock_get($owner_location_type, $row['parent_id'])) |
|
489 | + if (!static::cache_lock_get($owner_location_type, $row['parent_id'])) |
|
490 | 490 | $parent_id_list[$row['parent_id']] = $row['parent_id']; |
491 | 491 | } |
492 | 492 | |
493 | 493 | // Если все-таки какие-то записи еще не заблокированы - вынимаем текущие версии из базы |
494 | - if($indexes_str = implode(',', $parent_id_list)) { |
|
494 | + if ($indexes_str = implode(',', $parent_id_list)) { |
|
495 | 495 | $parent_id_field = static::$location_info[$owner_location_type][P_ID]; |
496 | 496 | static::db_get_record_list($owner_location_type, |
497 | 497 | $parent_id_field . (count($parent_id_list) > 1 ? " IN ({$indexes_str})" : " = {$indexes_str}"), $fetch, true); |
@@ -502,20 +502,20 @@ discard block |
||
502 | 502 | $query = static::db_query_select( |
503 | 503 | "SELECT * FROM {{{$location_info[P_TABLE_NAME]}}}" . (($filter = trim($filter)) ? " WHERE {$filter}" : '') |
504 | 504 | ); |
505 | - while($row = db_fetch($query)) { |
|
505 | + while ($row = db_fetch($query)) { |
|
506 | 506 | static::cache_set($location_type, $row[$id_field], $row); |
507 | 507 | $query_cache[$row[$id_field]] = &static::$data[$location_type][$row[$id_field]]; |
508 | 508 | } |
509 | 509 | } |
510 | 510 | |
511 | - if($no_return) { |
|
511 | + if ($no_return) { |
|
512 | 512 | return true; |
513 | 513 | } else { |
514 | 514 | $result = false; |
515 | - if(is_array($query_cache)) { |
|
516 | - foreach($query_cache as $key => $value) { |
|
515 | + if (is_array($query_cache)) { |
|
516 | + foreach ($query_cache as $key => $value) { |
|
517 | 517 | $result[$key] = $value; |
518 | - if($fetch) break; |
|
518 | + if ($fetch) break; |
|
519 | 519 | } |
520 | 520 | } |
521 | 521 | return $fetch ? (is_array($result) ? reset($result) : false) : $result; |
@@ -523,14 +523,14 @@ discard block |
||
523 | 523 | } |
524 | 524 | |
525 | 525 | public static function db_upd_record_by_id($location_type, $record_id, $set) { |
526 | - if(!($record_id = idval($record_id)) || !($set = trim($set))) return false; |
|
526 | + if (!($record_id = idval($record_id)) || !($set = trim($set))) return false; |
|
527 | 527 | |
528 | 528 | $location_info = &static::$location_info[$location_type]; |
529 | 529 | $id_field = $location_info[P_ID]; |
530 | 530 | $table_name = $location_info[P_TABLE_NAME]; |
531 | - if($result = static::db_query_update("UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
531 | + if ($result = static::db_query_update("UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
532 | 532 | { |
533 | - if(static::$db->db_affected_rows()) { |
|
533 | + if (static::$db->db_affected_rows()) { |
|
534 | 534 | // Обновляем данные только если ряд был затронут |
535 | 535 | // TODO - переделать под работу со структурированными $set |
536 | 536 | |
@@ -545,14 +545,14 @@ discard block |
||
545 | 545 | return $result; |
546 | 546 | } |
547 | 547 | public static function db_upd_record_list($location_type, $condition, $set) { |
548 | - if(!($set = trim($set))) return false; |
|
548 | + if (!($set = trim($set))) return false; |
|
549 | 549 | |
550 | 550 | $condition = trim($condition); |
551 | 551 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
552 | 552 | |
553 | - if($result = static::db_query_update("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) { |
|
553 | + if ($result = static::db_query_update("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) { |
|
554 | 554 | |
555 | - if(static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут |
|
555 | + if (static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут |
|
556 | 556 | // Поскольку нам неизвестно, что и как обновилось - сбрасываем кэш этого типа полностью |
557 | 557 | // TODO - когда будет структурированный $condition и $set - перепаковывать данные |
558 | 558 | static::cache_clear($location_type, true); |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | public static function db_ins_record($location_type, $set) { |
566 | 566 | $set = trim($set); |
567 | 567 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
568 | - if($result = static::db_query_insert("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
|
569 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
568 | + if ($result = static::db_query_insert("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
|
569 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
570 | 570 | { |
571 | 571 | $record_id = db_insert_id(); |
572 | 572 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
@@ -582,14 +582,14 @@ discard block |
||
582 | 582 | |
583 | 583 | public static function db_del_record_by_id($location_type, $safe_record_id) |
584 | 584 | { |
585 | - if(!($safe_record_id = idval($safe_record_id))) return false; |
|
585 | + if (!($safe_record_id = idval($safe_record_id))) return false; |
|
586 | 586 | |
587 | 587 | $location_info = &static::$location_info[$location_type]; |
588 | 588 | $id_field = $location_info[P_ID]; |
589 | 589 | $table_name = $location_info[P_TABLE_NAME]; |
590 | - if($result = static::db_query_delete("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) |
|
590 | + if ($result = static::db_query_delete("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) |
|
591 | 591 | { |
592 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
592 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
593 | 593 | { |
594 | 594 | static::cache_unset($location_type, $safe_record_id); |
595 | 595 | } |
@@ -599,14 +599,14 @@ discard block |
||
599 | 599 | } |
600 | 600 | public static function db_del_record_list($location_type, $condition) |
601 | 601 | { |
602 | - if(!($condition = trim($condition))) return false; |
|
602 | + if (!($condition = trim($condition))) return false; |
|
603 | 603 | |
604 | 604 | $location_info = &static::$location_info[$location_type]; |
605 | 605 | $table_name = $location_info[P_TABLE_NAME]; |
606 | 606 | |
607 | - if($result = static::db_query_delete("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) |
|
607 | + if ($result = static::db_query_delete("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) |
|
608 | 608 | { |
609 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
609 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
610 | 610 | { |
611 | 611 | // Обнуление кэша, потому что непонятно, что поменялось |
612 | 612 | static::cache_clear($location_type); |
@@ -652,21 +652,21 @@ discard block |
||
652 | 652 | public static function db_get_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) |
653 | 653 | { |
654 | 654 | // TODO Проверить, кстати - а везде ли нужно выбирать юзеров или где-то все-таки ищутся Альянсы ? |
655 | - if(!($username_unsafe = trim($username_unsafe))) return false; |
|
655 | + if (!($username_unsafe = trim($username_unsafe))) return false; |
|
656 | 656 | |
657 | 657 | $user = null; |
658 | - if(is_array(static::$data[LOC_USER])) |
|
659 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) |
|
658 | + if (is_array(static::$data[LOC_USER])) |
|
659 | + foreach (static::$data[LOC_USER] as $user_id => $user_data) |
|
660 | 660 | { |
661 | - if(is_array($user_data) && isset($user_data['username'])) |
|
661 | + if (is_array($user_data) && isset($user_data['username'])) |
|
662 | 662 | { |
663 | 663 | // проверяем поле |
664 | 664 | // TODO Возможно есть смысл всегда искать по strtolower - но может игрок захочет переименоваться с другим регистром? Проверить! |
665 | - if((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) |
|
665 | + if ((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) |
|
666 | 666 | { |
667 | 667 | // $user_as_ally = intval($user_data['user_as_ally']); |
668 | 668 | $user_as_ally = idval($user_data['user_as_ally']); |
669 | - if($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) |
|
669 | + if ($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) |
|
670 | 670 | { |
671 | 671 | $user = $user_data; |
672 | 672 | break; |
@@ -675,13 +675,13 @@ discard block |
||
675 | 675 | } |
676 | 676 | } |
677 | 677 | |
678 | - if($user === null) |
|
678 | + if ($user === null) |
|
679 | 679 | { |
680 | 680 | // Вытаскиваем запись |
681 | 681 | $username_safe = db_escape($like ? strtolower($username_unsafe) : $username_unsafe); // тут на самом деле strtolower() лишняя, но пусть будет |
682 | 682 | |
683 | 683 | $user = static::db_query_select( |
684 | - "SELECT * FROM {{users}} WHERE `username` " . ($like ? 'LIKE' : '='). " '{$username_safe}'", |
|
684 | + "SELECT * FROM {{users}} WHERE `username` " . ($like ? 'LIKE' : '=') . " '{$username_safe}'", |
|
685 | 685 | true |
686 | 686 | ); |
687 | 687 | static::cache_set(LOC_USER, $user['id'], $user); // В кэш-юзер так же заполнять индексы |
@@ -691,14 +691,14 @@ discard block |
||
691 | 691 | } |
692 | 692 | // UNUSED |
693 | 693 | public static function db_get_user_by_email($email_unsafe, $use_both = false, $for_update = false, $fields = '*') { |
694 | - if(!($email_unsafe = strtolower(trim($email_unsafe)))) return false; |
|
694 | + if (!($email_unsafe = strtolower(trim($email_unsafe)))) return false; |
|
695 | 695 | |
696 | 696 | $user = null; |
697 | - if(is_array(static::$data[LOC_USER])) { |
|
698 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) { |
|
699 | - if(is_array($user_data) && isset($user_data['email_2'])) { |
|
697 | + if (is_array(static::$data[LOC_USER])) { |
|
698 | + foreach (static::$data[LOC_USER] as $user_id => $user_data) { |
|
699 | + if (is_array($user_data) && isset($user_data['email_2'])) { |
|
700 | 700 | // проверяем поле |
701 | - if(strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) { |
|
701 | + if (strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) { |
|
702 | 702 | $user = $user_data; |
703 | 703 | break; |
704 | 704 | } |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | } |
707 | 707 | } |
708 | 708 | |
709 | - if($user === null) { |
|
709 | + if ($user === null) { |
|
710 | 710 | // Вытаскиваем запись |
711 | 711 | $email_safe = db_escape($email_unsafe); |
712 | 712 | $user = static::db_query_select( |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | $user = null; |
724 | 724 | // TODO переделать на индексы |
725 | 725 | |
726 | - if($user === null && !empty($where_safe)) { |
|
726 | + if ($user === null && !empty($where_safe)) { |
|
727 | 727 | // Вытаскиваем запись |
728 | 728 | $user = static::db_query_select( |
729 | 729 | "SELECT * FROM {{users}} WHERE {$where_safe}", |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | { |
762 | 762 | // TODO запихивать в $data[LOC_LOCATION][$location_type][$location_id] |
763 | 763 | $unit = static::db_get_record_by_id(LOC_UNIT, $unit_id, $for_update, $fields); |
764 | - if(is_array($unit)) |
|
764 | + if (is_array($unit)) |
|
765 | 765 | { |
766 | 766 | static::$locator[LOC_UNIT][$unit['unit_location_type']][$unit['unit_location_id']][$unit['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
767 | 767 | } |
@@ -771,15 +771,15 @@ discard block |
||
771 | 771 | |
772 | 772 | public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) |
773 | 773 | { |
774 | - if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) return false; |
|
774 | + if (!($location_type = idval($location_type)) || !($location_id = idval($location_id))) return false; |
|
775 | 775 | |
776 | 776 | $query_cache = &static::$locator[LOC_UNIT][$location_type][$location_id]; |
777 | - if(!isset($query_cache)) |
|
777 | + if (!isset($query_cache)) |
|
778 | 778 | { |
779 | 779 | $got_data = static::db_get_record_list(LOC_UNIT, "unit_location_type = {$location_type} AND unit_location_id = {$location_id} AND " . static::db_unit_time_restrictions()); |
780 | - if(is_array($got_data)) |
|
780 | + if (is_array($got_data)) |
|
781 | 781 | { |
782 | - foreach($got_data as $unit_id => $unit_data) |
|
782 | + foreach ($got_data as $unit_id => $unit_data) |
|
783 | 783 | { |
784 | 784 | // static::$data[LOC_LOCATION][$location_type][$location_id][$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
785 | 785 | $query_cache[$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
@@ -788,8 +788,8 @@ discard block |
||
788 | 788 | } |
789 | 789 | |
790 | 790 | $result = false; |
791 | - if(is_array($query_cache)) { |
|
792 | - foreach($query_cache as $key => $value) { |
|
791 | + if (is_array($query_cache)) { |
|
792 | + foreach ($query_cache as $key => $value) { |
|
793 | 793 | $result[$key] = $value; |
794 | 794 | } |
795 | 795 | } |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | */ |
828 | 828 | public static function db_que_list_by_type_location($user_id, $planet_id = null, $que_type = false, $for_update = false) |
829 | 829 | { |
830 | - if(!$user_id) |
|
830 | + if (!$user_id) |
|
831 | 831 | { |
832 | 832 | pdump(debug_backtrace()); |
833 | 833 | die('No user_id for que_get_que()'); |
@@ -837,14 +837,14 @@ discard block |
||
837 | 837 | |
838 | 838 | $query = array(); |
839 | 839 | |
840 | - if($user_id = idval($user_id)) |
|
840 | + if ($user_id = idval($user_id)) |
|
841 | 841 | $query[] = "`que_player_id` = {$user_id}"; |
842 | 842 | |
843 | - if($que_type == QUE_RESEARCH || $planet_id === null) |
|
843 | + if ($que_type == QUE_RESEARCH || $planet_id === null) |
|
844 | 844 | $query[] = "`que_planet_id` IS NULL"; |
845 | - elseif($planet_id) |
|
845 | + elseif ($planet_id) |
|
846 | 846 | $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")"; |
847 | - if($que_type) |
|
847 | + if ($que_type) |
|
848 | 848 | $query[] = "`que_type` = {$que_type}"; |
849 | 849 | |
850 | 850 | $ques['items'] = static::db_get_record_list(LOC_QUE, implode(' AND ', $query)); |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | } |
969 | 969 | |
970 | 970 | |
971 | - public static function loadFileSettings () { |
|
971 | + public static function loadFileSettings() { |
|
972 | 972 | $dbsettings = array(); |
973 | 973 | |
974 | 974 | require(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX); |
@@ -1034,7 +1034,7 @@ discard block |
||
1034 | 1034 | * @return GlobalContainer |
1035 | 1035 | */ |
1036 | 1036 | public static function services() { |
1037 | - if(empty(self::$gc)) { |
|
1037 | + if (empty(self::$gc)) { |
|
1038 | 1038 | self::$gc = new GlobalContainer(array( |
1039 | 1039 | 'cachePrefix' => self::$cache_prefix, |
1040 | 1040 | )); |
@@ -97,9 +97,7 @@ |
||
97 | 97 | /** |
98 | 98 | * Gets accessor for later use |
99 | 99 | * |
100 | - * @param string $accessor |
|
101 | 100 | * |
102 | - * @param string $varName |
|
103 | 101 | * |
104 | 102 | * @return callable|null |
105 | 103 | */ |
@@ -94,6 +94,10 @@ discard block |
||
94 | 94 | * @param null|\db_mysql $db |
95 | 95 | */ |
96 | 96 | // TODO - $db should be supplied externally |
97 | + |
|
98 | + /** |
|
99 | + * @param db_mysql $db |
|
100 | + */ |
|
97 | 101 | public function __construct($db = null) { |
98 | 102 | $this->db = empty($db) ? classSupernova::$gc->db : $db; |
99 | 103 | } |
@@ -205,7 +209,7 @@ discard block |
||
205 | 209 | |
206 | 210 | |
207 | 211 | /** |
208 | - * @param $table |
|
212 | + * @param string $table |
|
209 | 213 | * |
210 | 214 | * @return $this |
211 | 215 | */ |
@@ -313,7 +317,7 @@ discard block |
||
313 | 317 | /** |
314 | 318 | * Wrapper for db_escape() |
315 | 319 | * |
316 | - * @param mixed $string |
|
320 | + * @param string $string |
|
317 | 321 | * |
318 | 322 | * @return string |
319 | 323 | */ |
@@ -344,7 +348,7 @@ discard block |
||
344 | 348 | /** |
345 | 349 | * Quote mysql DB identifier |
346 | 350 | * |
347 | - * @param mixed $fieldName |
|
351 | + * @param string $fieldName |
|
348 | 352 | * |
349 | 353 | * @return string |
350 | 354 | */ |
@@ -391,7 +395,7 @@ discard block |
||
391 | 395 | /** |
392 | 396 | * Quote table name with `{{ }}` |
393 | 397 | * |
394 | - * @param mixed $tableName |
|
398 | + * @param string $tableName |
|
395 | 399 | * |
396 | 400 | * @return string |
397 | 401 | */ |
@@ -438,7 +442,7 @@ discard block |
||
438 | 442 | |
439 | 443 | |
440 | 444 | /** |
441 | - * @param $command |
|
445 | + * @param string $command |
|
442 | 446 | */ |
443 | 447 | protected function buildCommand($command) { |
444 | 448 | switch ($this->command = $command) { |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | * @return string |
339 | 339 | */ |
340 | 340 | protected function stringValue($value) { |
341 | - return "'" . $this->escape((string)$value) . "'"; |
|
341 | + return "'" . $this->escape((string) $value) . "'"; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | * @return string |
350 | 350 | */ |
351 | 351 | public function quote($fieldName) { |
352 | - return "`" . $this->escape((string)$fieldName) . "`"; |
|
352 | + return "`" . $this->escape((string) $fieldName) . "`"; |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | /** |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * @return string |
397 | 397 | */ |
398 | 398 | protected function quoteTable($tableName) { |
399 | - return "`{{" . $this->escape((string)$tableName) . "}}`"; |
|
399 | + return "`{{" . $this->escape((string) $tableName) . "}}`"; |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -42,6 +42,9 @@ |
||
42 | 42 | $this->addSmiles($sn_data_smiles); |
43 | 43 | } |
44 | 44 | |
45 | + /** |
|
46 | + * @param integer $accessLevel |
|
47 | + */ |
|
45 | 48 | protected function detectElementsFormat($elements, $accessLevel = AUTH_LEVEL_REGISTERED) { |
46 | 49 | $firstElement = reset($elements); |
47 | 50 | if (!is_array($firstElement)) { |
@@ -70,6 +70,11 @@ |
||
70 | 70 | return $this->getImageFrom($this->activeSkin->getName(), $image_tag, $template); |
71 | 71 | } |
72 | 72 | |
73 | + /** |
|
74 | + * @param string $skinName |
|
75 | + * @param string $image_tag |
|
76 | + * @param template|null $template |
|
77 | + */ |
|
73 | 78 | public function getImageFrom($skinName, $image_tag, $template) { |
74 | 79 | return $this->getSkin($skinName)->imageFromStringTag($image_tag, $template); |
75 | 80 | } |