Skip to content

Commit

Permalink
MAJ univers
Browse files Browse the repository at this point in the history
Modification ajout univers : insertion des id player est alliance
utilisation transaction et de sql_escape_string pour nettoyer les champs
  • Loading branch information
machine62 committed Mar 1, 2024
1 parent de62b4b commit d175635
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
11 changes: 7 additions & 4 deletions include/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ function _is_out_of_date($type, $origin)

function my_encodage($str)
{
global $db;
// return utf8_decode($str);
return $str;
return $db->sql_escape_string($str);
}

function stream_copy($src, $dest)
Expand Down Expand Up @@ -349,7 +350,6 @@ function traitement_universe($value)

$timestamp = find_timestamp($value);


$query = array();

$fields = "g, s, r, id_player , datadate , name_planete ,name_moon , moon , sender_id ";
Expand All @@ -367,7 +367,8 @@ function traitement_universe($value)
//$sender_id =

$query[] = "( " . $g . ", " . $s . " , " . $r . " , " . $id_player . " , " . $datadate . " , '" . my_encodage($name_planete) . "' , '" . $name_moon . "' , '" . $moon . "' , " . $sender_id . " ) ";
}

}

//$db->sql_query('REPLACE INTO '.$table.' ('.$fields.') VALUES '.implode(',', $query));
mass_replace_into($table, $fields, $query);
Expand All @@ -387,7 +388,9 @@ function traitement_universe($value)
$sql .= "( A.id_alliance = P.id_ally ) ";
$sql .= " SET ";
//$sql .= " U.player_id = T.id_player , U.ally_id = P.id_ally , U.moon = T.moon , U.name = T.name_planete , U.ally = A.tag , U.player = P.name_player , U.status = P.status , U.last_update = T.datadate , U.last_update_user_id = T.sender_id ";
$sql .= " U.moon = T.moon , U.name = T.name_planete , U.ally = A.tag , U.player = P.name_player , U.status = P.status , U.last_update = T.datadate , U.last_update_user_id = T.sender_id ";
// $sql .= " U.moon = T.moon , U.name = T.name_planete , U.ally = A.tag , U.player = P.name_player , U.status = P.status , U.last_update = T.datadate , U.last_update_user_id = T.sender_id ";
$sql .= " U.moon = T.moon , U.player_id = T.id_player , U.ally_id = P.id_ally , U.name = T.name_planete , U.ally = A.tag , U.player = P.name_player , U.status = P.status , U.last_update = T.datadate, U.last_update_user_id = T.sender_id ";

$sql .= " WHERE ";
$sql .= " U.last_update <= T.datadate "; // <= pour permettre d ecraser la derniere importation si plantage de la derniere

Expand Down
29 changes: 24 additions & 5 deletions model/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function mass_replace_into($table, $field, $query)
{
global $db;
$max_requete = (int)find_config("requete_max");
// Échapper $table et $field une seule fois avant la boucle
$table = $db->sql_escape_string($table);
$field = $db->sql_escape_string($field);

$new_query = array();
if ($max_requete != 0) {
Expand All @@ -23,14 +26,30 @@ function mass_replace_into($table, $field, $query)
$new_query[] = $query;
}

$db->sql_query("START TRANSACTION;");
// maintenant on lance les requetes de replace
try {
foreach ($new_query as $q) {

$query = 'REPLACE INTO ' . $table . ' (' . $field . ') VALUES ' . implode(',', $q);
$db->sql_query($query);
}
} catch (Exception $e) {
$db->sql_query("ROLLBACK;");
throw new Exception($e);
}

foreach ($new_query as $q) {
$db->sql_query('REPLACE INTO ' . $table . ' (' . $field . ') VALUES ' . implode(',', $q));
// avant de finir boucle on va faire patienter une demi seconde
// usleep(500000) ;

$db->sql_query("COMMIT;");
}


function escape($value)
{
global $db;
// Si la valeur est une chaîne de caractères, échapper et mettre des guillemets simples
if (is_string($value)) {
return "'" . $db->sql_escape_string($value) . "'";
}
// Pour les autres types de données, retourner la valeur telle quelle
return $value;
}
3 changes: 3 additions & 0 deletions model/model_CST_UNIVERSE.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
if (!defined('IN_SPYOGAME') || !defined('IN_SUPERAPIX')) die("Hacking attempt");
global $db, $user_data, $server_config;


/// ATTENTION : cette page ne sert a rien !!!!! tout est dans function/traitement

global $db, $user_data, $server_config, $pub_timestamp;
$timestamp = (int)$pub_timestamp;

Expand Down

0 comments on commit d175635

Please sign in to comment.