@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | array('query' => "DELETE FROM `{{planets}}` WHERE `id_owner` = 0 AND `destruyed` < UNIX_TIMESTAMP();", 'result' => false, 'error' => '', 'affected_rows' => 0), |
| 18 | 18 | ); |
| 19 | 19 | |
| 20 | - foreach($queries as &$query) |
|
| 20 | + foreach ($queries as &$query) |
|
| 21 | 21 | { |
| 22 | 22 | $query['result'] = doquery($query['query']); |
| 23 | 23 | $query['error'] = classSupernova::$db->db_error(); |
| 24 | - $query['affected_rows'] = classSupernova::$db->db_affected_rows(); |
|
| 24 | + $query['affected_rows'] = classSupernova::$db->db_affected_rows(); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | return $queries; |
@@ -53,30 +53,30 @@ discard block |
||
| 53 | 53 | $recorded_run = strtotime($recorded_run); |
| 54 | 54 | |
| 55 | 55 | $prev_run_array = getdate($recorded_run); |
| 56 | - $prev_run_array = array($prev_run_array['seconds'],$prev_run_array['minutes'],$prev_run_array['hours'],$prev_run_array['mday'],$prev_run_array['mon'],$prev_run_array['year']); |
|
| 56 | + $prev_run_array = array($prev_run_array['seconds'], $prev_run_array['minutes'], $prev_run_array['hours'], $prev_run_array['mday'], $prev_run_array['mon'], $prev_run_array['year']); |
|
| 57 | 57 | $today_array = getdate(SN_TIME_NOW); |
| 58 | - $today_array = array($today_array['seconds'],$today_array['minutes'],$today_array['hours'],$today_array['mday'],$today_array['mon'],$today_array['year']); |
|
| 58 | + $today_array = array($today_array['seconds'], $today_array['minutes'], $today_array['hours'], $today_array['mday'], $today_array['mon'], $today_array['year']); |
|
| 59 | 59 | $scheduleList = explode(',', $scheduleList); |
| 60 | 60 | array_walk($scheduleList, function(&$schedule) use ($prev_run_array, $today_array, $date_part_names_reverse, &$possible_schedules) { |
| 61 | 61 | $schedule = array('schedule_array' => array_reverse(explode(':', trim($schedule)))); |
| 62 | 62 | |
| 63 | 63 | $interval = $date_part_names_reverse[count($schedule['schedule_array'])]; |
| 64 | 64 | |
| 65 | - foreach($prev_run_array as $index => $date_part) { |
|
| 65 | + foreach ($prev_run_array as $index => $date_part) { |
|
| 66 | 66 | $schedule['array']['recorded'][$index] = isset($schedule['schedule_array'][$index]) ? intval($schedule['schedule_array'][$index]) : $date_part; |
| 67 | 67 | $schedule['array']['now'][$index] = isset($schedule['schedule_array'][$index]) ? intval($schedule['schedule_array'][$index]) : $today_array[$index]; |
| 68 | 68 | } |
| 69 | - if($schedule['array']['recorded'] == $schedule['array']['now']) { |
|
| 69 | + if ($schedule['array']['recorded'] == $schedule['array']['now']) { |
|
| 70 | 70 | unset($schedule['array']['now']); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - foreach($schedule['array'] as $name => $array) { |
|
| 73 | + foreach ($schedule['array'] as $name => $array) { |
|
| 74 | 74 | $schedule['string'][$name] = "{$array[5]}-{$array[4]}-{$array[3]} {$array[2]}:{$array[1]}:{$array[0]}"; |
| 75 | 75 | $schedule['string'][$name . '_next'] = $schedule['string'][$name] . ' +1 ' . $interval; |
| 76 | 76 | $schedule['string'][$name . '_prev'] = $schedule['string'][$name] . ' -1 ' . $interval; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - foreach($schedule['string'] as $string) { |
|
| 79 | + foreach ($schedule['string'] as $string) { |
|
| 80 | 80 | $timestamp = strtotime($string); |
| 81 | 81 | $schedule['timestamp'][$timestamp] = $possible_schedules[$timestamp] = date(FMT_DATE_TIME_SQL, strtotime($string)); |
| 82 | 82 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | $prev_run = 0; |
| 88 | 88 | $next_run = 0; |
| 89 | - foreach($possible_schedules as $timestamp => $string_date) { |
|
| 89 | + foreach ($possible_schedules as $timestamp => $string_date) { |
|
| 90 | 90 | $prev_run = SN_TIME_NOW >= $timestamp ? $timestamp : $prev_run; |
| 91 | 91 | $next_run = SN_TIME_NOW < $timestamp && !$next_run ? $timestamp : $next_run; |
| 92 | 92 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $planet_precache_query = DBStaticPlanet::db_planet_list_in_system($uni_galaxy, $uni_system); |
| 83 | 83 | if (!empty($planet_precache_query)) { |
| 84 | 84 | foreach ($planet_precache_query as $planet_row) { |
| 85 | - if(CheckAbandonPlanetState($planet_row)) { |
|
| 85 | + if (CheckAbandonPlanetState($planet_row)) { |
|
| 86 | 86 | continue; |
| 87 | 87 | } |
| 88 | 88 | $planet_list[$planet_row['planet']][$planet_row['planet_type']] = $planet_row; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | || |
| 126 | 126 | (!empty($uni_galaxyRowPlanet['destruyed']) && CheckAbandonPlanetState($uni_galaxyRowPlanet)) |
| 127 | 127 | ) { |
| 128 | - $template->assign_block_vars('galaxyrow', ['PLANET_NUM' => $Planet,]); |
|
| 128 | + $template->assign_block_vars('galaxyrow', ['PLANET_NUM' => $Planet, ]); |
|
| 129 | 129 | continue; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -25,14 +25,14 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public static function db_changeset_prepare_unit($unit_id, $unit_value, $user, $planet_id = null) |
| 27 | 27 | { |
| 28 | - if(!is_array($user)) |
|
| 28 | + if (!is_array($user)) |
|
| 29 | 29 | { |
| 30 | 30 | // TODO - remove later |
| 31 | 31 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: OldDbChangeSet::db_changeset_prepare_unit() - USER is not ARRAY</h1>'); |
| 32 | 32 | pdump(debug_backtrace()); |
| 33 | 33 | die('USER is not ARRAY'); |
| 34 | 34 | } |
| 35 | - if(!isset($user['id']) || !$user['id']) |
|
| 35 | + if (!isset($user['id']) || !$user['id']) |
|
| 36 | 36 | { |
| 37 | 37 | // TODO - remove later |
| 38 | 38 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: OldDbChangeSet::db_changeset_prepare_unit() - USER[id] пустой</h1>'); |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $location_id = $location_id ? $location_id : 'NULL'; |
| 48 | 48 | |
| 49 | 49 | $temp = DBStaticUnit::db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id); |
| 50 | - if(!empty($temp['unit_id'])) |
|
| 50 | + if (!empty($temp['unit_id'])) |
|
| 51 | 51 | { |
| 52 | 52 | $db_changeset = array( |
| 53 | 53 | 'action' => SQL_OP_UPDATE, |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | public static function db_changeset_condition_compile(&$conditions, &$table_name = '') { |
| 96 | - if(!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) { |
|
| 96 | + if (!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) { |
|
| 97 | 97 | $conditions[P_LOCATION] = LOC_NONE; |
| 98 | - switch($table_name) { |
|
| 98 | + switch ($table_name) { |
|
| 99 | 99 | case 'users': |
| 100 | 100 | case LOC_USER: |
| 101 | 101 | $conditions[P_TABLE_NAME] = $table_name = 'users'; |
@@ -117,18 +117,18 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $conditions[P_FIELDS_STR] = ''; |
| 120 | - if($conditions['fields']) { |
|
| 120 | + if ($conditions['fields']) { |
|
| 121 | 121 | $fields = array(); |
| 122 | - foreach($conditions['fields'] as $field_name => $field_data) { |
|
| 122 | + foreach ($conditions['fields'] as $field_name => $field_data) { |
|
| 123 | 123 | $condition = "`{$field_name}` = "; |
| 124 | 124 | $value = ''; |
| 125 | - if($field_data['delta']) { |
|
| 125 | + if ($field_data['delta']) { |
|
| 126 | 126 | $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta']; |
| 127 | - } elseif($field_data['set']) { |
|
| 128 | - $value = (is_string($field_data['set']) ? "'{$field_data['set']}'": $field_data['set']); |
|
| 127 | + } elseif ($field_data['set']) { |
|
| 128 | + $value = (is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set']); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if($value) { |
|
| 131 | + if ($value) { |
|
| 132 | 132 | $fields[] = $condition . $value; |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -136,16 +136,14 @@ discard block |
||
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | $conditions[P_WHERE_STR] = ''; |
| 139 | - if(!empty($conditions['where'])) { |
|
| 140 | - if($conditions[P_VERSION] == 1) { |
|
| 139 | + if (!empty($conditions['where'])) { |
|
| 140 | + if ($conditions[P_VERSION] == 1) { |
|
| 141 | 141 | $the_conditions = array(); |
| 142 | - foreach($conditions['where'] as $field_id => $field_value) { |
|
| 142 | + foreach ($conditions['where'] as $field_id => $field_value) { |
|
| 143 | 143 | // Простое условие - $field_id = $field_value |
| 144 | - if(is_string($field_id)) { |
|
| 144 | + if (is_string($field_id)) { |
|
| 145 | 145 | $field_value = |
| 146 | - $field_value === null ? 'NULL' : |
|
| 147 | - (is_string($field_value) ? "'" . db_escape($field_value) . "'" : |
|
| 148 | - (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
| 146 | + $field_value === null ? 'NULL' : (is_string($field_value) ? "'" . db_escape($field_value) . "'" : (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
| 149 | 147 | $the_conditions[] = "`{$field_id}` = {$field_value}"; |
| 150 | 148 | } else { |
| 151 | 149 | die('Неподдерживаемый тип условия'); |
@@ -157,7 +155,7 @@ discard block |
||
| 157 | 155 | $conditions[P_WHERE_STR] = implode(' AND ', $the_conditions); |
| 158 | 156 | } |
| 159 | 157 | |
| 160 | - switch($conditions['action']) { |
|
| 158 | + switch ($conditions['action']) { |
|
| 161 | 159 | case SQL_OP_DELETE: $conditions[P_ACTION_STR] = ("DELETE FROM {{{$table_name}}}"); break; |
| 162 | 160 | case SQL_OP_UPDATE: $conditions[P_ACTION_STR] = ("UPDATE {{{$table_name}}} SET"); break; |
| 163 | 161 | case SQL_OP_INSERT: $conditions[P_ACTION_STR] = ("INSERT INTO {{{$table_name}}} SET"); break; |
@@ -176,17 +174,17 @@ discard block |
||
| 176 | 174 | */ |
| 177 | 175 | public static function db_changeset_apply($db_changeset) { |
| 178 | 176 | $result = true; |
| 179 | - if(!is_array($db_changeset) || empty($db_changeset)) return $result; |
|
| 177 | + if (!is_array($db_changeset) || empty($db_changeset)) return $result; |
|
| 180 | 178 | |
| 181 | - foreach($db_changeset as $table_name => &$table_data) { |
|
| 182 | - foreach($table_data as $record_id => &$conditions) { |
|
| 179 | + foreach ($db_changeset as $table_name => &$table_data) { |
|
| 180 | + foreach ($table_data as $record_id => &$conditions) { |
|
| 183 | 181 | OldDbChangeSet::db_changeset_condition_compile($conditions, $table_name); |
| 184 | 182 | |
| 185 | - if($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) continue; |
|
| 186 | - if($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) continue; // Защита от случайного удаления всех данных в таблице |
|
| 183 | + if ($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) continue; |
|
| 184 | + if ($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) continue; // Защита от случайного удаления всех данных в таблице |
|
| 187 | 185 | |
| 188 | - if($conditions[P_LOCATION] != LOC_NONE) { |
|
| 189 | - switch($conditions['action']) |
|
| 186 | + if ($conditions[P_LOCATION] != LOC_NONE) { |
|
| 187 | + switch ($conditions['action']) |
|
| 190 | 188 | { |
| 191 | 189 | case SQL_OP_DELETE: $result = classSupernova::db_del_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR]) && $result; break; |
| 192 | 190 | case SQL_OP_UPDATE: $result = classSupernova::db_upd_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR], $conditions[P_FIELDS_STR]) && $result; break; |