Completed
Push — trunk ( 09520e...7ac6b6 )
by SuperNova.WS
03:48
created

dbPatchGetCurrent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Gorlum
5
 * Date: 26.12.2015
6
 * Time: 17:19
7
 */
8
9
/**
10
 * Normalize and make ID safe
11
 *
12
 * @param $db_row
13
 *
14
 * @return float|int
15
 */
16
function db_normalize_id($db_row, $field_name = 'id') {
17
  return idval(is_array($db_row) && !empty($db_row[$field_name]) ? $db_row[$field_name] : $db_row);
18
}
19
20
/**
21
 * Makes set safe
22
 *
23
 * @param array $set
24
 * @param bool $delta - Is it delta set?
25
 *
26
 * @return string
27
 */
28
function db_set_make_safe_string($set, $delta = false) {
29
  $set_safe = array();
30
  foreach($set as $field => $value) {
31
    if(empty($field)) {
32
      continue;
33
    }
34
35
    $field = '`' . db_escape($field) . '`';
36
    $new_value = $value;
37
    if($value === null) {
38
      $new_value = 'NULL';
39
    } elseif(is_string($value) && (string)($new_value = floatval($value)) != (string)$value) {
40
      // non-float
41
      $new_value = '"' . db_escape($value) . '"';
42
    } elseif($delta) {
43
      // float and DELTA-set
44
      $new_value = "{$field} + ({$new_value})";
45
    }
46
    $set_safe[] = "{$field} = {$new_value}";
47
  }
48
49
  $set_safe = implode(',', $set_safe);
50
51
  return $set_safe;
52
}
53
54
/**
55
 * Converts IRAK table record to FLEET one
56
 *
57
 * @param array $missile_db_list
58
 * @param array $fleet_db_list
59
 */
60
function missile_list_convert_to_fleet(&$missile_db_list, &$fleet_db_list) {
61
  // Missile attack
62
  foreach($missile_db_list as $irak) {
63
    if($irak['fleet_end_time'] >= SN_TIME_NOW) {
64
      $irak['fleet_start_type'] = PT_PLANET;
65
      $planet_start = DBStaticPlanet::db_planet_by_vector($irak, 'fleet_start_', false, 'name');
66
      $irak['fleet_id'] = -$irak['id'];
67
      $irak['fleet_mission'] = MT_MISSILE;
68
      $irak['fleet_array'] = UNIT_DEF_MISSILE_INTERPLANET . ",{$irak['fleet_amount']};";
69
      $irak['fleet_start_name'] = $planet_start['name'];
70
    }
71
    $fleet_db_list[] = $irak;
72
  }
73
}
74
75
/**
76
 * Get current DB patch version
77
 *
78
 * @return int|null
79
 */
80
function dbPatchGetCurrent() {
81
  return SN::$db->selectValue("SELECT MAX(`id`) FROM {{server_patches}}");
82
}