@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 28 | - return; |
|
| 28 | + return; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** Version de l'API SQL */ |
@@ -45,39 +45,39 @@ discard block |
||
| 45 | 45 | * contexte de l'erreur |
| 46 | 46 | **/ |
| 47 | 47 | function sql_error_backtrace($compil_info = false) { |
| 48 | - $trace = debug_backtrace(); |
|
| 49 | - $caller = array_shift($trace); |
|
| 50 | - while (count($trace) and (empty($trace[0]['file']) or $trace[0]['file'] === $caller['file'] or $trace[0]['file'] === __FILE__)) { |
|
| 51 | - array_shift($trace); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ($compil_info) { |
|
| 55 | - $contexte_compil = [ |
|
| 56 | - $trace[0]['file'],// sourcefile |
|
| 57 | - '', //nom |
|
| 58 | - (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 59 | - . $trace[0]['function'] . '();' |
|
| 60 | - . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 61 | - $trace[0]['line'], // ligne |
|
| 62 | - $GLOBALS['spip_lang'], // lang |
|
| 63 | - ]; |
|
| 64 | - |
|
| 65 | - return $contexte_compil; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 69 | - $f = []; |
|
| 70 | - while (count($trace) and $t = array_shift($trace)) { |
|
| 71 | - if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 72 | - break; |
|
| 73 | - } |
|
| 74 | - $f[] = $t['function']; |
|
| 75 | - } |
|
| 76 | - if (count($f)) { |
|
| 77 | - $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return $message; |
|
| 48 | + $trace = debug_backtrace(); |
|
| 49 | + $caller = array_shift($trace); |
|
| 50 | + while (count($trace) and (empty($trace[0]['file']) or $trace[0]['file'] === $caller['file'] or $trace[0]['file'] === __FILE__)) { |
|
| 51 | + array_shift($trace); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ($compil_info) { |
|
| 55 | + $contexte_compil = [ |
|
| 56 | + $trace[0]['file'],// sourcefile |
|
| 57 | + '', //nom |
|
| 58 | + (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 59 | + . $trace[0]['function'] . '();' |
|
| 60 | + . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 61 | + $trace[0]['line'], // ligne |
|
| 62 | + $GLOBALS['spip_lang'], // lang |
|
| 63 | + ]; |
|
| 64 | + |
|
| 65 | + return $contexte_compil; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 69 | + $f = []; |
|
| 70 | + while (count($trace) and $t = array_shift($trace)) { |
|
| 71 | + if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 72 | + break; |
|
| 73 | + } |
|
| 74 | + $f[] = $t['function']; |
|
| 75 | + } |
|
| 76 | + if (count($f)) { |
|
| 77 | + $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return $message; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
@@ -102,16 +102,16 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | **/ |
| 104 | 104 | function sql_serveur($ins_sql = '', $serveur = '', $continue = false) { |
| 105 | - static $sql_serveur = []; |
|
| 106 | - if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 107 | - $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 108 | - if (!is_string($f) or !$f) { |
|
| 109 | - return $f; |
|
| 110 | - } |
|
| 111 | - $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return $sql_serveur[$serveur][$ins_sql]; |
|
| 105 | + static $sql_serveur = []; |
|
| 106 | + if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 107 | + $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 108 | + if (!is_string($f) or !$f) { |
|
| 109 | + return $f; |
|
| 110 | + } |
|
| 111 | + $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return $sql_serveur[$serveur][$ins_sql]; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -133,23 +133,23 @@ discard block |
||
| 133 | 133 | * Retourne le nom du charset si effectivement trouvé, sinon false. |
| 134 | 134 | **/ |
| 135 | 135 | function sql_get_charset($charset, $serveur = '', $option = true) { |
| 136 | - // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 137 | - $desc = sql_serveur('', $serveur, true); |
|
| 138 | - $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 139 | - $c = $desc['charsets'][$charset]; |
|
| 140 | - if ($c) { |
|
| 141 | - if (function_exists($f = @$desc['get_charset'])) { |
|
| 142 | - if ($f($c, $serveur, $option !== false)) { |
|
| 143 | - return $c; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - spip_log( |
|
| 148 | - "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 149 | - _LOG_AVERTISSEMENT |
|
| 150 | - ); |
|
| 151 | - |
|
| 152 | - return false; |
|
| 136 | + // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 137 | + $desc = sql_serveur('', $serveur, true); |
|
| 138 | + $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 139 | + $c = $desc['charsets'][$charset]; |
|
| 140 | + if ($c) { |
|
| 141 | + if (function_exists($f = @$desc['get_charset'])) { |
|
| 142 | + if ($f($c, $serveur, $option !== false)) { |
|
| 143 | + return $c; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + spip_log( |
|
| 148 | + "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 149 | + _LOG_AVERTISSEMENT |
|
| 150 | + ); |
|
| 151 | + |
|
| 152 | + return false; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -175,12 +175,12 @@ discard block |
||
| 175 | 175 | * Retourne true si elle reussie. |
| 176 | 176 | **/ |
| 177 | 177 | function sql_set_charset($charset, $serveur = '', $option = true) { |
| 178 | - $f = sql_serveur('set_charset', $serveur, $option === 'continue' or $option === false); |
|
| 179 | - if (!is_string($f) or !$f) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 178 | + $f = sql_serveur('set_charset', $serveur, $option === 'continue' or $option === false); |
|
| 179 | + if (!is_string($f) or !$f) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $f($charset, $serveur, $option !== false); |
|
| 183 | + return $f($charset, $serveur, $option !== false); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
@@ -231,59 +231,59 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | **/ |
| 233 | 233 | function sql_select( |
| 234 | - $select = [], |
|
| 235 | - $from = [], |
|
| 236 | - $where = [], |
|
| 237 | - $groupby = [], |
|
| 238 | - $orderby = [], |
|
| 239 | - $limit = '', |
|
| 240 | - $having = [], |
|
| 241 | - $serveur = '', |
|
| 242 | - $option = true |
|
| 234 | + $select = [], |
|
| 235 | + $from = [], |
|
| 236 | + $where = [], |
|
| 237 | + $groupby = [], |
|
| 238 | + $orderby = [], |
|
| 239 | + $limit = '', |
|
| 240 | + $having = [], |
|
| 241 | + $serveur = '', |
|
| 242 | + $option = true |
|
| 243 | 243 | ) { |
| 244 | - $f = sql_serveur('select', $serveur, $option === 'continue' or $option === false); |
|
| 245 | - if (!is_string($f) or !$f) { |
|
| 246 | - return false; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $debug = (defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 250 | - if (($option !== false) and !$debug) { |
|
| 251 | - $res = $f( |
|
| 252 | - $select, |
|
| 253 | - $from, |
|
| 254 | - $where, |
|
| 255 | - $groupby, |
|
| 256 | - $orderby, |
|
| 257 | - $limit, |
|
| 258 | - $having, |
|
| 259 | - $serveur, |
|
| 260 | - is_array($option) ? true : $option |
|
| 261 | - ); |
|
| 262 | - } else { |
|
| 263 | - $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 264 | - if (!$option) { |
|
| 265 | - return $query; |
|
| 266 | - } |
|
| 267 | - // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 268 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 269 | - [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 270 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 271 | - $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 272 | - } |
|
| 273 | - $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // en cas d'erreur |
|
| 277 | - if (!is_string($res)) { |
|
| 278 | - return $res; |
|
| 279 | - } |
|
| 280 | - // denoncer l'erreur SQL dans sa version brute |
|
| 281 | - spip_sql_erreur($serveur); |
|
| 282 | - // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 283 | - $contexte_compil = sql_error_backtrace(true); |
|
| 284 | - erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 285 | - |
|
| 286 | - return false; |
|
| 244 | + $f = sql_serveur('select', $serveur, $option === 'continue' or $option === false); |
|
| 245 | + if (!is_string($f) or !$f) { |
|
| 246 | + return false; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $debug = (defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 250 | + if (($option !== false) and !$debug) { |
|
| 251 | + $res = $f( |
|
| 252 | + $select, |
|
| 253 | + $from, |
|
| 254 | + $where, |
|
| 255 | + $groupby, |
|
| 256 | + $orderby, |
|
| 257 | + $limit, |
|
| 258 | + $having, |
|
| 259 | + $serveur, |
|
| 260 | + is_array($option) ? true : $option |
|
| 261 | + ); |
|
| 262 | + } else { |
|
| 263 | + $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 264 | + if (!$option) { |
|
| 265 | + return $query; |
|
| 266 | + } |
|
| 267 | + // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 268 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 269 | + [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 270 | + $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 271 | + $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 272 | + } |
|
| 273 | + $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // en cas d'erreur |
|
| 277 | + if (!is_string($res)) { |
|
| 278 | + return $res; |
|
| 279 | + } |
|
| 280 | + // denoncer l'erreur SQL dans sa version brute |
|
| 281 | + spip_sql_erreur($serveur); |
|
| 282 | + // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 283 | + $contexte_compil = sql_error_backtrace(true); |
|
| 284 | + erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 285 | + |
|
| 286 | + return false; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | |
@@ -320,16 +320,16 @@ discard block |
||
| 320 | 320 | * |
| 321 | 321 | **/ |
| 322 | 322 | function sql_get_select( |
| 323 | - $select = [], |
|
| 324 | - $from = [], |
|
| 325 | - $where = [], |
|
| 326 | - $groupby = [], |
|
| 327 | - $orderby = [], |
|
| 328 | - $limit = '', |
|
| 329 | - $having = [], |
|
| 330 | - $serveur = '' |
|
| 323 | + $select = [], |
|
| 324 | + $from = [], |
|
| 325 | + $where = [], |
|
| 326 | + $groupby = [], |
|
| 327 | + $orderby = [], |
|
| 328 | + $limit = '', |
|
| 329 | + $having = [], |
|
| 330 | + $serveur = '' |
|
| 331 | 331 | ) { |
| 332 | - return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 332 | + return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -373,23 +373,23 @@ discard block |
||
| 373 | 373 | * |
| 374 | 374 | **/ |
| 375 | 375 | function sql_countsel( |
| 376 | - $from = [], |
|
| 377 | - $where = [], |
|
| 378 | - $groupby = [], |
|
| 379 | - $having = [], |
|
| 380 | - $serveur = '', |
|
| 381 | - $option = true |
|
| 376 | + $from = [], |
|
| 377 | + $where = [], |
|
| 378 | + $groupby = [], |
|
| 379 | + $having = [], |
|
| 380 | + $serveur = '', |
|
| 381 | + $option = true |
|
| 382 | 382 | ) { |
| 383 | - $f = sql_serveur('countsel', $serveur, $option === 'continue' or $option === false); |
|
| 384 | - if (!is_string($f) or !$f) { |
|
| 385 | - return false; |
|
| 386 | - } |
|
| 387 | - $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 388 | - if ($r === false) { |
|
| 389 | - spip_sql_erreur($serveur); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $r; |
|
| 383 | + $f = sql_serveur('countsel', $serveur, $option === 'continue' or $option === false); |
|
| 384 | + if (!is_string($f) or !$f) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 387 | + $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 388 | + if ($r === false) { |
|
| 389 | + spip_sql_erreur($serveur); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $r; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -421,16 +421,16 @@ discard block |
||
| 421 | 421 | * Ce retour n'est pas pertinent pour savoir si l'opération est correctement réalisée. |
| 422 | 422 | **/ |
| 423 | 423 | function sql_alter($q, $serveur = '', $option = true) { |
| 424 | - $f = sql_serveur('alter', $serveur, $option === 'continue' or $option === false); |
|
| 425 | - if (!is_string($f) or !$f) { |
|
| 426 | - return false; |
|
| 427 | - } |
|
| 428 | - $r = $f($q, $serveur, $option !== false); |
|
| 429 | - if ($r === false) { |
|
| 430 | - spip_sql_erreur($serveur); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - return $r; |
|
| 424 | + $f = sql_serveur('alter', $serveur, $option === 'continue' or $option === false); |
|
| 425 | + if (!is_string($f) or !$f) { |
|
| 426 | + return false; |
|
| 427 | + } |
|
| 428 | + $r = $f($q, $serveur, $option !== false); |
|
| 429 | + if ($r === false) { |
|
| 430 | + spip_sql_erreur($serveur); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + return $r; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -453,12 +453,12 @@ discard block |
||
| 453 | 453 | * presentant une ligne de resultat d'une selection |
| 454 | 454 | */ |
| 455 | 455 | function sql_fetch($res, $serveur = '', $option = true) { |
| 456 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 457 | - if (!is_string($f) or !$f) { |
|
| 458 | - return false; |
|
| 459 | - } |
|
| 456 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 457 | + if (!is_string($f) or !$f) { |
|
| 458 | + return false; |
|
| 459 | + } |
|
| 460 | 460 | |
| 461 | - return $f($res, null, $serveur, $option !== false); |
|
| 461 | + return $f($res, null, $serveur, $option !== false); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
@@ -485,20 +485,20 @@ discard block |
||
| 485 | 485 | * presentant une ligne de resultat d'une selection |
| 486 | 486 | */ |
| 487 | 487 | function sql_fetch_all($res, $serveur = '', $option = true) { |
| 488 | - $rows = []; |
|
| 489 | - if (!$res) { |
|
| 490 | - return $rows; |
|
| 491 | - } |
|
| 492 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 493 | - if (!is_string($f) or !$f) { |
|
| 494 | - return []; |
|
| 495 | - } |
|
| 496 | - while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 497 | - $rows[] = $r; |
|
| 498 | - } |
|
| 499 | - sql_free($res, $serveur); |
|
| 500 | - |
|
| 501 | - return $rows; |
|
| 488 | + $rows = []; |
|
| 489 | + if (!$res) { |
|
| 490 | + return $rows; |
|
| 491 | + } |
|
| 492 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 493 | + if (!is_string($f) or !$f) { |
|
| 494 | + return []; |
|
| 495 | + } |
|
| 496 | + while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 497 | + $rows[] = $r; |
|
| 498 | + } |
|
| 499 | + sql_free($res, $serveur); |
|
| 500 | + |
|
| 501 | + return $rows; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -526,16 +526,16 @@ discard block |
||
| 526 | 526 | * Operation effectuée (true), sinon false. |
| 527 | 527 | **/ |
| 528 | 528 | function sql_seek($res, $row_number, $serveur = '', $option = true) { |
| 529 | - $f = sql_serveur('seek', $serveur, $option === 'continue' or $option === false); |
|
| 530 | - if (!is_string($f) or !$f) { |
|
| 531 | - return false; |
|
| 532 | - } |
|
| 533 | - $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 534 | - if ($r === false) { |
|
| 535 | - spip_sql_erreur($serveur); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - return $r; |
|
| 529 | + $f = sql_serveur('seek', $serveur, $option === 'continue' or $option === false); |
|
| 530 | + if (!is_string($f) or !$f) { |
|
| 531 | + return false; |
|
| 532 | + } |
|
| 533 | + $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 534 | + if ($r === false) { |
|
| 535 | + spip_sql_erreur($serveur); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + return $r; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | |
@@ -560,16 +560,16 @@ discard block |
||
| 560 | 560 | * False en cas d'erreur. |
| 561 | 561 | **/ |
| 562 | 562 | function sql_listdbs($serveur = '', $option = true) { |
| 563 | - $f = sql_serveur('listdbs', $serveur, $option === 'continue' or $option === false); |
|
| 564 | - if (!is_string($f) or !$f) { |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - $r = $f($serveur); |
|
| 568 | - if ($r === false) { |
|
| 569 | - spip_sql_erreur($serveur); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - return $r; |
|
| 563 | + $f = sql_serveur('listdbs', $serveur, $option === 'continue' or $option === false); |
|
| 564 | + if (!is_string($f) or !$f) { |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + $r = $f($serveur); |
|
| 568 | + if ($r === false) { |
|
| 569 | + spip_sql_erreur($serveur); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return $r; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | |
@@ -592,16 +592,16 @@ discard block |
||
| 592 | 592 | * - False en cas d'erreur. |
| 593 | 593 | **/ |
| 594 | 594 | function sql_selectdb($nom, $serveur = '', $option = true) { |
| 595 | - $f = sql_serveur('selectdb', $serveur, $option === 'continue' or $option === false); |
|
| 596 | - if (!is_string($f) or !$f) { |
|
| 597 | - return false; |
|
| 598 | - } |
|
| 599 | - $r = $f($nom, $serveur, $option !== false); |
|
| 600 | - if ($r === false) { |
|
| 601 | - spip_sql_erreur($serveur); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - return $r; |
|
| 595 | + $f = sql_serveur('selectdb', $serveur, $option === 'continue' or $option === false); |
|
| 596 | + if (!is_string($f) or !$f) { |
|
| 597 | + return false; |
|
| 598 | + } |
|
| 599 | + $r = $f($nom, $serveur, $option !== false); |
|
| 600 | + if ($r === false) { |
|
| 601 | + spip_sql_erreur($serveur); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + return $r; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -626,16 +626,16 @@ discard block |
||
| 626 | 626 | * - false en cas d'erreur. |
| 627 | 627 | **/ |
| 628 | 628 | function sql_count($res, $serveur = '', $option = true) { |
| 629 | - $f = sql_serveur('count', $serveur, $option === 'continue' or $option === false); |
|
| 630 | - if (!is_string($f) or !$f) { |
|
| 631 | - return false; |
|
| 632 | - } |
|
| 633 | - $r = $f($res, $serveur, $option !== false); |
|
| 634 | - if ($r === false) { |
|
| 635 | - spip_sql_erreur($serveur); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - return $r; |
|
| 629 | + $f = sql_serveur('count', $serveur, $option === 'continue' or $option === false); |
|
| 630 | + if (!is_string($f) or !$f) { |
|
| 631 | + return false; |
|
| 632 | + } |
|
| 633 | + $r = $f($res, $serveur, $option !== false); |
|
| 634 | + if ($r === false) { |
|
| 635 | + spip_sql_erreur($serveur); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + return $r; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -657,12 +657,12 @@ discard block |
||
| 657 | 657 | * True si réussi |
| 658 | 658 | */ |
| 659 | 659 | function sql_free($res, $serveur = '', $option = true) { |
| 660 | - $f = sql_serveur('free', $serveur, $option === 'continue' or $option === false); |
|
| 661 | - if (!is_string($f) or !$f) { |
|
| 662 | - return false; |
|
| 663 | - } |
|
| 660 | + $f = sql_serveur('free', $serveur, $option === 'continue' or $option === false); |
|
| 661 | + if (!is_string($f) or !$f) { |
|
| 662 | + return false; |
|
| 663 | + } |
|
| 664 | 664 | |
| 665 | - return $f($res); |
|
| 665 | + return $f($res); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | |
@@ -700,17 +700,17 @@ discard block |
||
| 700 | 700 | * - False en cas d'erreur. |
| 701 | 701 | **/ |
| 702 | 702 | function sql_insert($table, $noms, $valeurs, $desc = [], $serveur = '', $option = true) { |
| 703 | - $f = sql_serveur('insert', $serveur, $option === 'continue' or $option === false); |
|
| 704 | - if (!is_string($f) or !$f) { |
|
| 705 | - return false; |
|
| 706 | - } |
|
| 707 | - $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 708 | - if ($r === false or $r === null) { |
|
| 709 | - spip_sql_erreur($serveur); |
|
| 710 | - $r = false; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - return $r; |
|
| 703 | + $f = sql_serveur('insert', $serveur, $option === 'continue' or $option === false); |
|
| 704 | + if (!is_string($f) or !$f) { |
|
| 705 | + return false; |
|
| 706 | + } |
|
| 707 | + $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 708 | + if ($r === false or $r === null) { |
|
| 709 | + spip_sql_erreur($serveur); |
|
| 710 | + $r = false; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + return $r; |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
@@ -751,17 +751,17 @@ discard block |
||
| 751 | 751 | * - False en cas d'erreur. |
| 752 | 752 | **/ |
| 753 | 753 | function sql_insertq($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 754 | - $f = sql_serveur('insertq', $serveur, $option === 'continue' or $option === false); |
|
| 755 | - if (!is_string($f) or !$f) { |
|
| 756 | - return false; |
|
| 757 | - } |
|
| 758 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 759 | - if ($r === false or $r === null) { |
|
| 760 | - spip_sql_erreur($serveur); |
|
| 761 | - $r = false; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - return $r; |
|
| 754 | + $f = sql_serveur('insertq', $serveur, $option === 'continue' or $option === false); |
|
| 755 | + if (!is_string($f) or !$f) { |
|
| 756 | + return false; |
|
| 757 | + } |
|
| 758 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 759 | + if ($r === false or $r === null) { |
|
| 760 | + spip_sql_erreur($serveur); |
|
| 761 | + $r = false; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + return $r; |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -796,17 +796,17 @@ discard block |
||
| 796 | 796 | * - False en cas d'erreur. |
| 797 | 797 | **/ |
| 798 | 798 | function sql_insertq_multi($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 799 | - $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' or $option === false); |
|
| 800 | - if (!is_string($f) or !$f) { |
|
| 801 | - return false; |
|
| 802 | - } |
|
| 803 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 804 | - if ($r === false or $r === null) { |
|
| 805 | - spip_sql_erreur($serveur); |
|
| 806 | - $r = false; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - return $r; |
|
| 799 | + $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' or $option === false); |
|
| 800 | + if (!is_string($f) or !$f) { |
|
| 801 | + return false; |
|
| 802 | + } |
|
| 803 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 804 | + if ($r === false or $r === null) { |
|
| 805 | + spip_sql_erreur($serveur); |
|
| 806 | + $r = false; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + return $r; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -846,16 +846,16 @@ discard block |
||
| 846 | 846 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 847 | 847 | */ |
| 848 | 848 | function sql_update($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 849 | - $f = sql_serveur('update', $serveur, $option === 'continue' or $option === false); |
|
| 850 | - if (!is_string($f) or !$f) { |
|
| 851 | - return false; |
|
| 852 | - } |
|
| 853 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 854 | - if ($r === false) { |
|
| 855 | - spip_sql_erreur($serveur); |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - return $r; |
|
| 849 | + $f = sql_serveur('update', $serveur, $option === 'continue' or $option === false); |
|
| 850 | + if (!is_string($f) or !$f) { |
|
| 851 | + return false; |
|
| 852 | + } |
|
| 853 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 854 | + if ($r === false) { |
|
| 855 | + spip_sql_erreur($serveur); |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + return $r; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | |
@@ -901,16 +901,16 @@ discard block |
||
| 901 | 901 | * - False en cas d'erreur. |
| 902 | 902 | **/ |
| 903 | 903 | function sql_updateq($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 904 | - $f = sql_serveur('updateq', $serveur, $option === 'continue' or $option === false); |
|
| 905 | - if (!is_string($f) or !$f) { |
|
| 906 | - return false; |
|
| 907 | - } |
|
| 908 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 909 | - if ($r === false) { |
|
| 910 | - spip_sql_erreur($serveur); |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - return $r; |
|
| 904 | + $f = sql_serveur('updateq', $serveur, $option === 'continue' or $option === false); |
|
| 905 | + if (!is_string($f) or !$f) { |
|
| 906 | + return false; |
|
| 907 | + } |
|
| 908 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 909 | + if ($r === false) { |
|
| 910 | + spip_sql_erreur($serveur); |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + return $r; |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | /** |
@@ -941,16 +941,16 @@ discard block |
||
| 941 | 941 | * - False en cas d'erreur. |
| 942 | 942 | **/ |
| 943 | 943 | function sql_delete($table, $where = '', $serveur = '', $option = true) { |
| 944 | - $f = sql_serveur('delete', $serveur, $option === 'continue' or $option === false); |
|
| 945 | - if (!is_string($f) or !$f) { |
|
| 946 | - return false; |
|
| 947 | - } |
|
| 948 | - $r = $f($table, $where, $serveur, $option !== false); |
|
| 949 | - if ($r === false) { |
|
| 950 | - spip_sql_erreur($serveur); |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - return $r; |
|
| 944 | + $f = sql_serveur('delete', $serveur, $option === 'continue' or $option === false); |
|
| 945 | + if (!is_string($f) or !$f) { |
|
| 946 | + return false; |
|
| 947 | + } |
|
| 948 | + $r = $f($table, $where, $serveur, $option !== false); |
|
| 949 | + if ($r === false) { |
|
| 950 | + spip_sql_erreur($serveur); |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + return $r; |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | /** |
@@ -986,16 +986,16 @@ discard block |
||
| 986 | 986 | * - False en cas d'erreur. |
| 987 | 987 | **/ |
| 988 | 988 | function sql_replace($table, $couples, $desc = [], $serveur = '', $option = true) { |
| 989 | - $f = sql_serveur('replace', $serveur, $option === 'continue' or $option === false); |
|
| 990 | - if (!is_string($f) or !$f) { |
|
| 991 | - return false; |
|
| 992 | - } |
|
| 993 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 994 | - if ($r === false) { |
|
| 995 | - spip_sql_erreur($serveur); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - return $r; |
|
| 989 | + $f = sql_serveur('replace', $serveur, $option === 'continue' or $option === false); |
|
| 990 | + if (!is_string($f) or !$f) { |
|
| 991 | + return false; |
|
| 992 | + } |
|
| 993 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 994 | + if ($r === false) { |
|
| 995 | + spip_sql_erreur($serveur); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + return $r; |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | |
@@ -1033,16 +1033,16 @@ discard block |
||
| 1033 | 1033 | * - False en cas d'erreur. |
| 1034 | 1034 | **/ |
| 1035 | 1035 | function sql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $option = true) { |
| 1036 | - $f = sql_serveur('replace_multi', $serveur, $option === 'continue' or $option === false); |
|
| 1037 | - if (!is_string($f) or !$f) { |
|
| 1038 | - return false; |
|
| 1039 | - } |
|
| 1040 | - $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1041 | - if ($r === false) { |
|
| 1042 | - spip_sql_erreur($serveur); |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - return $r; |
|
| 1036 | + $f = sql_serveur('replace_multi', $serveur, $option === 'continue' or $option === false); |
|
| 1037 | + if (!is_string($f) or !$f) { |
|
| 1038 | + return false; |
|
| 1039 | + } |
|
| 1040 | + $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1041 | + if ($r === false) { |
|
| 1042 | + spip_sql_erreur($serveur); |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + return $r; |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | /** |
@@ -1070,16 +1070,16 @@ discard block |
||
| 1070 | 1070 | * - False en cas d'erreur. |
| 1071 | 1071 | **/ |
| 1072 | 1072 | function sql_drop_table($table, $exist = '', $serveur = '', $option = true) { |
| 1073 | - $f = sql_serveur('drop_table', $serveur, $option === 'continue' or $option === false); |
|
| 1074 | - if (!is_string($f) or !$f) { |
|
| 1075 | - return false; |
|
| 1076 | - } |
|
| 1077 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1078 | - if ($r === false) { |
|
| 1079 | - spip_sql_erreur($serveur); |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - return $r; |
|
| 1073 | + $f = sql_serveur('drop_table', $serveur, $option === 'continue' or $option === false); |
|
| 1074 | + if (!is_string($f) or !$f) { |
|
| 1075 | + return false; |
|
| 1076 | + } |
|
| 1077 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1078 | + if ($r === false) { |
|
| 1079 | + spip_sql_erreur($serveur); |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + return $r; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | /** |
@@ -1103,16 +1103,16 @@ discard block |
||
| 1103 | 1103 | * - true si la requête a réussie, false sinon |
| 1104 | 1104 | */ |
| 1105 | 1105 | function sql_drop_view($table, $exist = '', $serveur = '', $option = true) { |
| 1106 | - $f = sql_serveur('drop_view', $serveur, $option === 'continue' or $option === false); |
|
| 1107 | - if (!is_string($f) or !$f) { |
|
| 1108 | - return false; |
|
| 1109 | - } |
|
| 1110 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1111 | - if ($r === false) { |
|
| 1112 | - spip_sql_erreur($serveur); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - return $r; |
|
| 1106 | + $f = sql_serveur('drop_view', $serveur, $option === 'continue' or $option === false); |
|
| 1107 | + if (!is_string($f) or !$f) { |
|
| 1108 | + return false; |
|
| 1109 | + } |
|
| 1110 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1111 | + if ($r === false) { |
|
| 1112 | + spip_sql_erreur($serveur); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + return $r; |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | /** |
@@ -1136,18 +1136,18 @@ discard block |
||
| 1136 | 1136 | * Ressource à utiliser avec sql_fetch() |
| 1137 | 1137 | **/ |
| 1138 | 1138 | function sql_showbase($spip = null, $serveur = '', $option = true) { |
| 1139 | - $f = sql_serveur('showbase', $serveur, $option === 'continue' or $option === false); |
|
| 1140 | - if (!is_string($f) or !$f) { |
|
| 1141 | - return false; |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1145 | - if ($spip == null) { |
|
| 1146 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1147 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - return $f($spip, $serveur, $option !== false); |
|
| 1139 | + $f = sql_serveur('showbase', $serveur, $option === 'continue' or $option === false); |
|
| 1140 | + if (!is_string($f) or !$f) { |
|
| 1141 | + return false; |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1145 | + if ($spip == null) { |
|
| 1146 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1147 | + $spip = $connexion['prefixe'] . '\_%'; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + return $f($spip, $serveur, $option !== false); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | /** |
@@ -1170,15 +1170,15 @@ discard block |
||
| 1170 | 1170 | * Liste des tables SQL |
| 1171 | 1171 | **/ |
| 1172 | 1172 | function sql_alltable($spip = null, $serveur = '', $option = true) { |
| 1173 | - $q = sql_showbase($spip, $serveur, $option); |
|
| 1174 | - $r = []; |
|
| 1175 | - if ($q) { |
|
| 1176 | - while ($t = sql_fetch($q, $serveur)) { |
|
| 1177 | - $r[] = array_shift($t); |
|
| 1178 | - } |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - return $r; |
|
| 1173 | + $q = sql_showbase($spip, $serveur, $option); |
|
| 1174 | + $r = []; |
|
| 1175 | + if ($q) { |
|
| 1176 | + while ($t = sql_fetch($q, $serveur)) { |
|
| 1177 | + $r[] = array_shift($t); |
|
| 1178 | + } |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + return $r; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1211,31 +1211,31 @@ discard block |
||
| 1211 | 1211 | * - 'join' => array() // jointures, si déclarées. |
| 1212 | 1212 | **/ |
| 1213 | 1213 | function sql_showtable($table, $table_spip = false, $serveur = '', $option = true) { |
| 1214 | - $f = sql_serveur('showtable', $serveur, $option === 'continue' or $option === false); |
|
| 1215 | - if (!is_string($f) or !$f) { |
|
| 1216 | - return false; |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1220 | - if ($table_spip) { |
|
| 1221 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1222 | - $prefixe = $connexion['prefixe']; |
|
| 1223 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1224 | - } else { |
|
| 1225 | - $vraie_table = $table; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1229 | - if (!$f) { |
|
| 1230 | - return []; |
|
| 1231 | - } |
|
| 1232 | - if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1233 | - $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1234 | - } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1235 | - $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - return $f; |
|
| 1214 | + $f = sql_serveur('showtable', $serveur, $option === 'continue' or $option === false); |
|
| 1215 | + if (!is_string($f) or !$f) { |
|
| 1216 | + return false; |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1220 | + if ($table_spip) { |
|
| 1221 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1222 | + $prefixe = $connexion['prefixe']; |
|
| 1223 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1224 | + } else { |
|
| 1225 | + $vraie_table = $table; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1229 | + if (!$f) { |
|
| 1230 | + return []; |
|
| 1231 | + } |
|
| 1232 | + if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1233 | + $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1234 | + } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1235 | + $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + return $f; |
|
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | |
@@ -1263,21 +1263,21 @@ discard block |
||
| 1263 | 1263 | * - False en cas d'erreur. |
| 1264 | 1264 | **/ |
| 1265 | 1265 | function sql_table_exists(string $table, bool $table_spip = true, $serveur = '', $option = true) { |
| 1266 | - $f = sql_serveur('table_exists', $serveur, $option === 'continue' or $option === false); |
|
| 1267 | - if (!is_string($f) or !$f) { |
|
| 1268 | - return false; |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1272 | - if ($table_spip) { |
|
| 1273 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1274 | - $prefixe = $connexion['prefixe']; |
|
| 1275 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1276 | - } else { |
|
| 1277 | - $vraie_table = $table; |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - return $f($vraie_table, $serveur, $option !== false); |
|
| 1266 | + $f = sql_serveur('table_exists', $serveur, $option === 'continue' or $option === false); |
|
| 1267 | + if (!is_string($f) or !$f) { |
|
| 1268 | + return false; |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1272 | + if ($table_spip) { |
|
| 1273 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1274 | + $prefixe = $connexion['prefixe']; |
|
| 1275 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1276 | + } else { |
|
| 1277 | + $vraie_table = $table; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + return $f($vraie_table, $serveur, $option !== false); |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | |
@@ -1323,24 +1323,24 @@ discard block |
||
| 1323 | 1323 | * true si succès, false en cas d'echec |
| 1324 | 1324 | **/ |
| 1325 | 1325 | function sql_create( |
| 1326 | - $nom, |
|
| 1327 | - $champs, |
|
| 1328 | - $cles = [], |
|
| 1329 | - $autoinc = false, |
|
| 1330 | - $temporary = false, |
|
| 1331 | - $serveur = '', |
|
| 1332 | - $option = true |
|
| 1326 | + $nom, |
|
| 1327 | + $champs, |
|
| 1328 | + $cles = [], |
|
| 1329 | + $autoinc = false, |
|
| 1330 | + $temporary = false, |
|
| 1331 | + $serveur = '', |
|
| 1332 | + $option = true |
|
| 1333 | 1333 | ) { |
| 1334 | - $f = sql_serveur('create', $serveur, $option === 'continue' or $option === false); |
|
| 1335 | - if (!is_string($f) or !$f) { |
|
| 1336 | - return false; |
|
| 1337 | - } |
|
| 1338 | - $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1339 | - if ($r === false) { |
|
| 1340 | - spip_sql_erreur($serveur); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - return $r; |
|
| 1334 | + $f = sql_serveur('create', $serveur, $option === 'continue' or $option === false); |
|
| 1335 | + if (!is_string($f) or !$f) { |
|
| 1336 | + return false; |
|
| 1337 | + } |
|
| 1338 | + $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1339 | + if ($r === false) { |
|
| 1340 | + spip_sql_erreur($serveur); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + return $r; |
|
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | 1346 | /** |
@@ -1358,16 +1358,16 @@ discard block |
||
| 1358 | 1358 | * @return bool true si la base est créee. |
| 1359 | 1359 | **/ |
| 1360 | 1360 | function sql_create_base($nom, $serveur = '', $option = true) { |
| 1361 | - $f = sql_serveur('create_base', $serveur, $option === 'continue' or $option === false); |
|
| 1362 | - if (!is_string($f) or !$f) { |
|
| 1363 | - return false; |
|
| 1364 | - } |
|
| 1365 | - $r = $f($nom, $serveur, $option !== false); |
|
| 1366 | - if ($r === false) { |
|
| 1367 | - spip_sql_erreur($serveur); |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - return $r; |
|
| 1361 | + $f = sql_serveur('create_base', $serveur, $option === 'continue' or $option === false); |
|
| 1362 | + if (!is_string($f) or !$f) { |
|
| 1363 | + return false; |
|
| 1364 | + } |
|
| 1365 | + $r = $f($nom, $serveur, $option !== false); |
|
| 1366 | + if ($r === false) { |
|
| 1367 | + spip_sql_erreur($serveur); |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + return $r; |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | |
@@ -1397,16 +1397,16 @@ discard block |
||
| 1397 | 1397 | * - false en cas d'échec. |
| 1398 | 1398 | **/ |
| 1399 | 1399 | function sql_create_view($nom, $select_query, $serveur = '', $option = true) { |
| 1400 | - $f = sql_serveur('create_view', $serveur, $option === 'continue' or $option === false); |
|
| 1401 | - if (!is_string($f) or !$f) { |
|
| 1402 | - return false; |
|
| 1403 | - } |
|
| 1404 | - $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1405 | - if ($r === false) { |
|
| 1406 | - spip_sql_erreur($serveur); |
|
| 1407 | - } |
|
| 1408 | - |
|
| 1409 | - return $r; |
|
| 1400 | + $f = sql_serveur('create_view', $serveur, $option === 'continue' or $option === false); |
|
| 1401 | + if (!is_string($f) or !$f) { |
|
| 1402 | + return false; |
|
| 1403 | + } |
|
| 1404 | + $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1405 | + if ($r === false) { |
|
| 1406 | + spip_sql_erreur($serveur); |
|
| 1407 | + } |
|
| 1408 | + |
|
| 1409 | + return $r; |
|
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | /** |
@@ -1435,12 +1435,12 @@ discard block |
||
| 1435 | 1435 | * Texte de sélection pour la requête |
| 1436 | 1436 | */ |
| 1437 | 1437 | function sql_multi($sel, $lang, $serveur = '', $option = true) { |
| 1438 | - $f = sql_serveur('multi', $serveur, $option === 'continue' or $option === false); |
|
| 1439 | - if (!is_string($f) or !$f) { |
|
| 1440 | - return false; |
|
| 1441 | - } |
|
| 1438 | + $f = sql_serveur('multi', $serveur, $option === 'continue' or $option === false); |
|
| 1439 | + if (!is_string($f) or !$f) { |
|
| 1440 | + return false; |
|
| 1441 | + } |
|
| 1442 | 1442 | |
| 1443 | - return $f($sel, $lang); |
|
| 1443 | + return $f($sel, $lang); |
|
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | |
@@ -1455,12 +1455,12 @@ discard block |
||
| 1455 | 1455 | * False si le serveur est indisponible |
| 1456 | 1456 | */ |
| 1457 | 1457 | function sql_error($serveur = '') { |
| 1458 | - $f = sql_serveur('error', $serveur, 'continue'); |
|
| 1459 | - if (!is_string($f) or !$f) { |
|
| 1460 | - return false; |
|
| 1461 | - } |
|
| 1458 | + $f = sql_serveur('error', $serveur, 'continue'); |
|
| 1459 | + if (!is_string($f) or !$f) { |
|
| 1460 | + return false; |
|
| 1461 | + } |
|
| 1462 | 1462 | |
| 1463 | - return $f('query inconnue', $serveur); |
|
| 1463 | + return $f('query inconnue', $serveur); |
|
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | /** |
@@ -1474,12 +1474,12 @@ discard block |
||
| 1474 | 1474 | * False si le serveur est indisponible |
| 1475 | 1475 | */ |
| 1476 | 1476 | function sql_errno($serveur = '') { |
| 1477 | - $f = sql_serveur('errno', $serveur, 'continue'); |
|
| 1478 | - if (!is_string($f) or !$f) { |
|
| 1479 | - return false; |
|
| 1480 | - } |
|
| 1477 | + $f = sql_serveur('errno', $serveur, 'continue'); |
|
| 1478 | + if (!is_string($f) or !$f) { |
|
| 1479 | + return false; |
|
| 1480 | + } |
|
| 1481 | 1481 | |
| 1482 | - return $f($serveur); |
|
| 1482 | + return $f($serveur); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | /** |
@@ -1497,16 +1497,16 @@ discard block |
||
| 1497 | 1497 | * @return array Tableau de l'explication |
| 1498 | 1498 | */ |
| 1499 | 1499 | function sql_explain($q, $serveur = '', $option = true) { |
| 1500 | - $f = sql_serveur('explain', $serveur, 'continue'); |
|
| 1501 | - if (!is_string($f) or !$f) { |
|
| 1502 | - return false; |
|
| 1503 | - } |
|
| 1504 | - $r = $f($q, $serveur, $option !== false); |
|
| 1505 | - if ($r === false) { |
|
| 1506 | - spip_sql_erreur($serveur); |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - return $r; |
|
| 1500 | + $f = sql_serveur('explain', $serveur, 'continue'); |
|
| 1501 | + if (!is_string($f) or !$f) { |
|
| 1502 | + return false; |
|
| 1503 | + } |
|
| 1504 | + $r = $f($q, $serveur, $option !== false); |
|
| 1505 | + if ($r === false) { |
|
| 1506 | + spip_sql_erreur($serveur); |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + return $r; |
|
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | 1512 | /** |
@@ -1524,16 +1524,16 @@ discard block |
||
| 1524 | 1524 | * @return bool Toujours true |
| 1525 | 1525 | */ |
| 1526 | 1526 | function sql_optimize($table, $serveur = '', $option = true) { |
| 1527 | - $f = sql_serveur('optimize', $serveur, $option === 'continue' or $option === false); |
|
| 1528 | - if (!is_string($f) or !$f) { |
|
| 1529 | - return false; |
|
| 1530 | - } |
|
| 1531 | - $r = $f($table, $serveur, $option !== false); |
|
| 1532 | - if ($r === false) { |
|
| 1533 | - spip_sql_erreur($serveur); |
|
| 1534 | - } |
|
| 1535 | - |
|
| 1536 | - return $r; |
|
| 1527 | + $f = sql_serveur('optimize', $serveur, $option === 'continue' or $option === false); |
|
| 1528 | + if (!is_string($f) or !$f) { |
|
| 1529 | + return false; |
|
| 1530 | + } |
|
| 1531 | + $r = $f($table, $serveur, $option !== false); |
|
| 1532 | + if ($r === false) { |
|
| 1533 | + spip_sql_erreur($serveur); |
|
| 1534 | + } |
|
| 1535 | + |
|
| 1536 | + return $r; |
|
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | /** |
@@ -1553,16 +1553,16 @@ discard block |
||
| 1553 | 1553 | * - true si la requête a réussie, false sinon |
| 1554 | 1554 | */ |
| 1555 | 1555 | function sql_repair($table, $serveur = '', $option = true) { |
| 1556 | - $f = sql_serveur('repair', $serveur, $option === 'continue' or $option === false); |
|
| 1557 | - if (!is_string($f) or !$f) { |
|
| 1558 | - return false; |
|
| 1559 | - } |
|
| 1560 | - $r = $f($table, $serveur, $option !== false); |
|
| 1561 | - if ($r === false) { |
|
| 1562 | - spip_sql_erreur($serveur); |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - return $r; |
|
| 1556 | + $f = sql_serveur('repair', $serveur, $option === 'continue' or $option === false); |
|
| 1557 | + if (!is_string($f) or !$f) { |
|
| 1558 | + return false; |
|
| 1559 | + } |
|
| 1560 | + $r = $f($table, $serveur, $option !== false); |
|
| 1561 | + if ($r === false) { |
|
| 1562 | + spip_sql_erreur($serveur); |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + return $r; |
|
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | 1568 | |
@@ -1587,16 +1587,16 @@ discard block |
||
| 1587 | 1587 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 1588 | 1588 | */ |
| 1589 | 1589 | function sql_query($ins, $serveur = '', $option = true) { |
| 1590 | - $f = sql_serveur('query', $serveur, $option === 'continue' or $option === false); |
|
| 1591 | - if (!is_string($f) or !$f) { |
|
| 1592 | - return false; |
|
| 1593 | - } |
|
| 1594 | - $r = $f($ins, $serveur, $option !== false); |
|
| 1595 | - if ($r === false) { |
|
| 1596 | - spip_sql_erreur($serveur); |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - return $r; |
|
| 1590 | + $f = sql_serveur('query', $serveur, $option === 'continue' or $option === false); |
|
| 1591 | + if (!is_string($f) or !$f) { |
|
| 1592 | + return false; |
|
| 1593 | + } |
|
| 1594 | + $r = $f($ins, $serveur, $option !== false); |
|
| 1595 | + if ($r === false) { |
|
| 1596 | + spip_sql_erreur($serveur); |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + return $r; |
|
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 1602 | 1602 | /** |
@@ -1644,27 +1644,27 @@ discard block |
||
| 1644 | 1644 | * |
| 1645 | 1645 | **/ |
| 1646 | 1646 | function sql_fetsel( |
| 1647 | - $select = [], |
|
| 1648 | - $from = [], |
|
| 1649 | - $where = [], |
|
| 1650 | - $groupby = [], |
|
| 1651 | - $orderby = [], |
|
| 1652 | - $limit = '', |
|
| 1653 | - $having = [], |
|
| 1654 | - $serveur = '', |
|
| 1655 | - $option = true |
|
| 1647 | + $select = [], |
|
| 1648 | + $from = [], |
|
| 1649 | + $where = [], |
|
| 1650 | + $groupby = [], |
|
| 1651 | + $orderby = [], |
|
| 1652 | + $limit = '', |
|
| 1653 | + $having = [], |
|
| 1654 | + $serveur = '', |
|
| 1655 | + $option = true |
|
| 1656 | 1656 | ) { |
| 1657 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1658 | - if ($option === false) { |
|
| 1659 | - return $q; |
|
| 1660 | - } |
|
| 1661 | - if (!$q) { |
|
| 1662 | - return []; |
|
| 1663 | - } |
|
| 1664 | - $r = sql_fetch($q, $serveur, $option); |
|
| 1665 | - sql_free($q, $serveur, $option); |
|
| 1666 | - |
|
| 1667 | - return $r; |
|
| 1657 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1658 | + if ($option === false) { |
|
| 1659 | + return $q; |
|
| 1660 | + } |
|
| 1661 | + if (!$q) { |
|
| 1662 | + return []; |
|
| 1663 | + } |
|
| 1664 | + $r = sql_fetch($q, $serveur, $option); |
|
| 1665 | + sql_free($q, $serveur, $option); |
|
| 1666 | + |
|
| 1667 | + return $r; |
|
| 1668 | 1668 | } |
| 1669 | 1669 | |
| 1670 | 1670 | |
@@ -1721,22 +1721,22 @@ discard block |
||
| 1721 | 1721 | * |
| 1722 | 1722 | **/ |
| 1723 | 1723 | function sql_allfetsel( |
| 1724 | - $select = [], |
|
| 1725 | - $from = [], |
|
| 1726 | - $where = [], |
|
| 1727 | - $groupby = [], |
|
| 1728 | - $orderby = [], |
|
| 1729 | - $limit = '', |
|
| 1730 | - $having = [], |
|
| 1731 | - $serveur = '', |
|
| 1732 | - $option = true |
|
| 1724 | + $select = [], |
|
| 1725 | + $from = [], |
|
| 1726 | + $where = [], |
|
| 1727 | + $groupby = [], |
|
| 1728 | + $orderby = [], |
|
| 1729 | + $limit = '', |
|
| 1730 | + $having = [], |
|
| 1731 | + $serveur = '', |
|
| 1732 | + $option = true |
|
| 1733 | 1733 | ) { |
| 1734 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1735 | - if ($option === false) { |
|
| 1736 | - return $q; |
|
| 1737 | - } |
|
| 1734 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1735 | + if ($option === false) { |
|
| 1736 | + return $q; |
|
| 1737 | + } |
|
| 1738 | 1738 | |
| 1739 | - return sql_fetch_all($q, $serveur, $option); |
|
| 1739 | + return sql_fetch_all($q, $serveur, $option); |
|
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | |
@@ -1783,33 +1783,33 @@ discard block |
||
| 1783 | 1783 | * |
| 1784 | 1784 | **/ |
| 1785 | 1785 | function sql_getfetsel( |
| 1786 | - $select, |
|
| 1787 | - $from = [], |
|
| 1788 | - $where = [], |
|
| 1789 | - $groupby = [], |
|
| 1790 | - $orderby = [], |
|
| 1791 | - $limit = '', |
|
| 1792 | - $having = [], |
|
| 1793 | - $serveur = '', |
|
| 1794 | - $option = true |
|
| 1786 | + $select, |
|
| 1787 | + $from = [], |
|
| 1788 | + $where = [], |
|
| 1789 | + $groupby = [], |
|
| 1790 | + $orderby = [], |
|
| 1791 | + $limit = '', |
|
| 1792 | + $having = [], |
|
| 1793 | + $serveur = '', |
|
| 1794 | + $option = true |
|
| 1795 | 1795 | ) { |
| 1796 | - if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1797 | - $id = $c[1]; |
|
| 1798 | - } elseif (!preg_match('/\W/', $select)) { |
|
| 1799 | - $id = $select; |
|
| 1800 | - } else { |
|
| 1801 | - $id = 'n'; |
|
| 1802 | - $select .= ' AS n'; |
|
| 1803 | - } |
|
| 1804 | - $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1805 | - if ($option === false) { |
|
| 1806 | - return $r; |
|
| 1807 | - } |
|
| 1808 | - if (!$r) { |
|
| 1809 | - return null; |
|
| 1810 | - } |
|
| 1811 | - |
|
| 1812 | - return $r[$id]; |
|
| 1796 | + if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1797 | + $id = $c[1]; |
|
| 1798 | + } elseif (!preg_match('/\W/', $select)) { |
|
| 1799 | + $id = $select; |
|
| 1800 | + } else { |
|
| 1801 | + $id = 'n'; |
|
| 1802 | + $select .= ' AS n'; |
|
| 1803 | + } |
|
| 1804 | + $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1805 | + if ($option === false) { |
|
| 1806 | + return $r; |
|
| 1807 | + } |
|
| 1808 | + if (!$r) { |
|
| 1809 | + return null; |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + return $r[$id]; |
|
| 1813 | 1813 | } |
| 1814 | 1814 | |
| 1815 | 1815 | /** |
@@ -1827,9 +1827,9 @@ discard block |
||
| 1827 | 1827 | * Numero de version du serveur SQL |
| 1828 | 1828 | **/ |
| 1829 | 1829 | function sql_version($serveur = '', $option = true) { |
| 1830 | - $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1830 | + $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1831 | 1831 | |
| 1832 | - return ($row['n']); |
|
| 1832 | + return ($row['n']); |
|
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | 1835 | /** |
@@ -1865,16 +1865,16 @@ discard block |
||
| 1865 | 1865 | * Le serveur SQL prefere t'il des transactions pour les insertions multiples ? |
| 1866 | 1866 | **/ |
| 1867 | 1867 | function sql_preferer_transaction($serveur = '', $option = true) { |
| 1868 | - $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
|
| 1869 | - if (!is_string($f) or !$f) { |
|
| 1870 | - return false; |
|
| 1871 | - } |
|
| 1872 | - $r = $f($serveur, $option !== false); |
|
| 1873 | - if ($r === false) { |
|
| 1874 | - spip_sql_erreur($serveur); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - return $r; |
|
| 1868 | + $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
|
| 1869 | + if (!is_string($f) or !$f) { |
|
| 1870 | + return false; |
|
| 1871 | + } |
|
| 1872 | + $r = $f($serveur, $option !== false); |
|
| 1873 | + if ($r === false) { |
|
| 1874 | + spip_sql_erreur($serveur); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + return $r; |
|
| 1878 | 1878 | } |
| 1879 | 1879 | |
| 1880 | 1880 | ; |
@@ -1899,16 +1899,16 @@ discard block |
||
| 1899 | 1899 | * false en cas d'erreur |
| 1900 | 1900 | **/ |
| 1901 | 1901 | function sql_demarrer_transaction($serveur = '', $option = true) { |
| 1902 | - $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
|
| 1903 | - if (!is_string($f) or !$f) { |
|
| 1904 | - return false; |
|
| 1905 | - } |
|
| 1906 | - $r = $f($serveur, $option !== false); |
|
| 1907 | - if ($r === false) { |
|
| 1908 | - spip_sql_erreur($serveur); |
|
| 1909 | - } |
|
| 1910 | - |
|
| 1911 | - return $r; |
|
| 1902 | + $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
|
| 1903 | + if (!is_string($f) or !$f) { |
|
| 1904 | + return false; |
|
| 1905 | + } |
|
| 1906 | + $r = $f($serveur, $option !== false); |
|
| 1907 | + if ($r === false) { |
|
| 1908 | + spip_sql_erreur($serveur); |
|
| 1909 | + } |
|
| 1910 | + |
|
| 1911 | + return $r; |
|
| 1912 | 1912 | } |
| 1913 | 1913 | |
| 1914 | 1914 | ; |
@@ -1933,16 +1933,16 @@ discard block |
||
| 1933 | 1933 | * false en cas d'erreur |
| 1934 | 1934 | **/ |
| 1935 | 1935 | function sql_terminer_transaction($serveur = '', $option = true) { |
| 1936 | - $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
|
| 1937 | - if (!is_string($f) or !$f) { |
|
| 1938 | - return false; |
|
| 1939 | - } |
|
| 1940 | - $r = $f($serveur, $option !== false); |
|
| 1941 | - if ($r === false) { |
|
| 1942 | - spip_sql_erreur($serveur); |
|
| 1943 | - } |
|
| 1944 | - |
|
| 1945 | - return $r; |
|
| 1936 | + $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
|
| 1937 | + if (!is_string($f) or !$f) { |
|
| 1938 | + return false; |
|
| 1939 | + } |
|
| 1940 | + $r = $f($serveur, $option !== false); |
|
| 1941 | + if ($r === false) { |
|
| 1942 | + spip_sql_erreur($serveur); |
|
| 1943 | + } |
|
| 1944 | + |
|
| 1945 | + return $r; |
|
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | 1948 | ; |
@@ -1969,12 +1969,12 @@ discard block |
||
| 1969 | 1969 | * Valeur hexadécimale attendue par le serveur SQL |
| 1970 | 1970 | **/ |
| 1971 | 1971 | function sql_hex($val, $serveur = '', $option = true) { |
| 1972 | - $f = sql_serveur('hex', $serveur, $option === 'continue' or $option === false); |
|
| 1973 | - if (!is_string($f) or !$f) { |
|
| 1974 | - return false; |
|
| 1975 | - } |
|
| 1972 | + $f = sql_serveur('hex', $serveur, $option === 'continue' or $option === false); |
|
| 1973 | + if (!is_string($f) or !$f) { |
|
| 1974 | + return false; |
|
| 1975 | + } |
|
| 1976 | 1976 | |
| 1977 | - return $f($val); |
|
| 1977 | + return $f($val); |
|
| 1978 | 1978 | } |
| 1979 | 1979 | |
| 1980 | 1980 | /** |
@@ -2000,12 +2000,12 @@ discard block |
||
| 2000 | 2000 | * La chaine echappee |
| 2001 | 2001 | **/ |
| 2002 | 2002 | function sql_quote($val, $serveur = '', $type = '') { |
| 2003 | - $f = sql_serveur('quote', $serveur, true); |
|
| 2004 | - if (!is_string($f) or !$f) { |
|
| 2005 | - $f = '_q'; |
|
| 2006 | - } |
|
| 2003 | + $f = sql_serveur('quote', $serveur, true); |
|
| 2004 | + if (!is_string($f) or !$f) { |
|
| 2005 | + $f = '_q'; |
|
| 2006 | + } |
|
| 2007 | 2007 | |
| 2008 | - return $f($val, $type); |
|
| 2008 | + return $f($val, $type); |
|
| 2009 | 2009 | } |
| 2010 | 2010 | |
| 2011 | 2011 | /** |
@@ -2030,12 +2030,12 @@ discard block |
||
| 2030 | 2030 | * - false si le serveur SQL est indisponible |
| 2031 | 2031 | **/ |
| 2032 | 2032 | function sql_date_proche($champ, $interval, $unite, $serveur = '', $option = true) { |
| 2033 | - $f = sql_serveur('date_proche', $serveur, true); |
|
| 2034 | - if (!is_string($f) or !$f) { |
|
| 2035 | - return false; |
|
| 2036 | - } |
|
| 2033 | + $f = sql_serveur('date_proche', $serveur, true); |
|
| 2034 | + if (!is_string($f) or !$f) { |
|
| 2035 | + return false; |
|
| 2036 | + } |
|
| 2037 | 2037 | |
| 2038 | - return $f($champ, $interval, $unite); |
|
| 2038 | + return $f($champ, $interval, $unite); |
|
| 2039 | 2039 | } |
| 2040 | 2040 | |
| 2041 | 2041 | /** |
@@ -2071,26 +2071,26 @@ discard block |
||
| 2071 | 2071 | * Expression de requête SQL |
| 2072 | 2072 | **/ |
| 2073 | 2073 | function sql_in_quote($champ, $valeurs, $not = '', $serveur = '', $type = '', $option = true) { |
| 2074 | - $quote = sql_serveur('quote', $serveur, true); |
|
| 2075 | - if (!is_string($quote) or !$quote) { |
|
| 2076 | - return false; |
|
| 2077 | - } |
|
| 2078 | - |
|
| 2079 | - // sql_quote produit une chaine dans tous les cas |
|
| 2080 | - $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2081 | - $valeurs = array_unique($valeurs); |
|
| 2082 | - $valeurs = $quote($valeurs, $type); |
|
| 2083 | - |
|
| 2084 | - if (!strlen(trim($valeurs))) { |
|
| 2085 | - return ($not ? '0=0' : '0=1'); |
|
| 2086 | - } |
|
| 2087 | - |
|
| 2088 | - $f = sql_serveur('in', $serveur, $option === 'continue' or $option === false); |
|
| 2089 | - if (!is_string($f) or !$f) { |
|
| 2090 | - return false; |
|
| 2091 | - } |
|
| 2092 | - |
|
| 2093 | - return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2074 | + $quote = sql_serveur('quote', $serveur, true); |
|
| 2075 | + if (!is_string($quote) or !$quote) { |
|
| 2076 | + return false; |
|
| 2077 | + } |
|
| 2078 | + |
|
| 2079 | + // sql_quote produit une chaine dans tous les cas |
|
| 2080 | + $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2081 | + $valeurs = array_unique($valeurs); |
|
| 2082 | + $valeurs = $quote($valeurs, $type); |
|
| 2083 | + |
|
| 2084 | + if (!strlen(trim($valeurs))) { |
|
| 2085 | + return ($not ? '0=0' : '0=1'); |
|
| 2086 | + } |
|
| 2087 | + |
|
| 2088 | + $f = sql_serveur('in', $serveur, $option === 'continue' or $option === false); |
|
| 2089 | + if (!is_string($f) or !$f) { |
|
| 2090 | + return false; |
|
| 2091 | + } |
|
| 2092 | + |
|
| 2093 | + return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2094 | 2094 | } |
| 2095 | 2095 | |
| 2096 | 2096 | /** |
@@ -2107,19 +2107,19 @@ discard block |
||
| 2107 | 2107 | * @param bool $option |
| 2108 | 2108 | */ |
| 2109 | 2109 | function sql_in($champ, $valeurs, $not = '', $serveur = '', $option = true) { |
| 2110 | - $type = ''; |
|
| 2111 | - if (!is_array($valeurs)) { |
|
| 2112 | - $valeurs = strval($valeurs); |
|
| 2113 | - if (isset($valeurs[0]) and $valeurs[0] === ',') { |
|
| 2114 | - $valeurs = substr($valeurs, 1); |
|
| 2115 | - } |
|
| 2116 | - // on explode en tableau pour pouvoir securiser le contenu |
|
| 2117 | - $valeurs = explode(',', $valeurs); |
|
| 2118 | - // et on force un cast de type int donc |
|
| 2119 | - $type = 'int'; |
|
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2110 | + $type = ''; |
|
| 2111 | + if (!is_array($valeurs)) { |
|
| 2112 | + $valeurs = strval($valeurs); |
|
| 2113 | + if (isset($valeurs[0]) and $valeurs[0] === ',') { |
|
| 2114 | + $valeurs = substr($valeurs, 1); |
|
| 2115 | + } |
|
| 2116 | + // on explode en tableau pour pouvoir securiser le contenu |
|
| 2117 | + $valeurs = explode(',', $valeurs); |
|
| 2118 | + // et on force un cast de type int donc |
|
| 2119 | + $type = 'int'; |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2123 | 2123 | } |
| 2124 | 2124 | |
| 2125 | 2125 | |
@@ -2160,24 +2160,24 @@ discard block |
||
| 2160 | 2160 | * Expression de requête SQL |
| 2161 | 2161 | **/ |
| 2162 | 2162 | function sql_in_select( |
| 2163 | - $in, |
|
| 2164 | - $select, |
|
| 2165 | - $from = [], |
|
| 2166 | - $where = [], |
|
| 2167 | - $groupby = [], |
|
| 2168 | - $orderby = [], |
|
| 2169 | - $limit = '', |
|
| 2170 | - $having = [], |
|
| 2171 | - $serveur = '' |
|
| 2163 | + $in, |
|
| 2164 | + $select, |
|
| 2165 | + $from = [], |
|
| 2166 | + $where = [], |
|
| 2167 | + $groupby = [], |
|
| 2168 | + $orderby = [], |
|
| 2169 | + $limit = '', |
|
| 2170 | + $having = [], |
|
| 2171 | + $serveur = '' |
|
| 2172 | 2172 | ) { |
| 2173 | - $liste = []; |
|
| 2174 | - $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2175 | - while ($r = sql_fetch($res)) { |
|
| 2176 | - $liste[] = array_shift($r); |
|
| 2177 | - } |
|
| 2178 | - sql_free($res); |
|
| 2179 | - |
|
| 2180 | - return sql_in($in, $liste); |
|
| 2173 | + $liste = []; |
|
| 2174 | + $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2175 | + while ($r = sql_fetch($res)) { |
|
| 2176 | + $liste[] = array_shift($r); |
|
| 2177 | + } |
|
| 2178 | + sql_free($res); |
|
| 2179 | + |
|
| 2180 | + return sql_in($in, $liste); |
|
| 2181 | 2181 | } |
| 2182 | 2182 | |
| 2183 | 2183 | /** |
@@ -2209,29 +2209,29 @@ discard block |
||
| 2209 | 2209 | * Position apres le saut. |
| 2210 | 2210 | */ |
| 2211 | 2211 | function sql_skip($res, $pos, $saut, $count, $serveur = '', $option = true) { |
| 2212 | - // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2213 | - if (($saut = intval($saut)) <= 0) { |
|
| 2214 | - return $pos; |
|
| 2215 | - } |
|
| 2216 | - |
|
| 2217 | - $seek = $pos + $saut; |
|
| 2218 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 2219 | - // et on sort |
|
| 2220 | - if ($seek >= $count) { |
|
| 2221 | - sql_free($res, $serveur, $option); |
|
| 2222 | - |
|
| 2223 | - return $count; |
|
| 2224 | - } |
|
| 2225 | - |
|
| 2226 | - if (sql_seek($res, $seek)) { |
|
| 2227 | - $pos = $seek; |
|
| 2228 | - } else { |
|
| 2229 | - while ($pos < $seek and sql_fetch($res, $serveur, $option)) { |
|
| 2230 | - $pos++; |
|
| 2231 | - } |
|
| 2232 | - } |
|
| 2233 | - |
|
| 2234 | - return $pos; |
|
| 2212 | + // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2213 | + if (($saut = intval($saut)) <= 0) { |
|
| 2214 | + return $pos; |
|
| 2215 | + } |
|
| 2216 | + |
|
| 2217 | + $seek = $pos + $saut; |
|
| 2218 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 2219 | + // et on sort |
|
| 2220 | + if ($seek >= $count) { |
|
| 2221 | + sql_free($res, $serveur, $option); |
|
| 2222 | + |
|
| 2223 | + return $count; |
|
| 2224 | + } |
|
| 2225 | + |
|
| 2226 | + if (sql_seek($res, $seek)) { |
|
| 2227 | + $pos = $seek; |
|
| 2228 | + } else { |
|
| 2229 | + while ($pos < $seek and sql_fetch($res, $serveur, $option)) { |
|
| 2230 | + $pos++; |
|
| 2231 | + } |
|
| 2232 | + } |
|
| 2233 | + |
|
| 2234 | + return $pos; |
|
| 2235 | 2235 | } |
| 2236 | 2236 | |
| 2237 | 2237 | |
@@ -2251,7 +2251,7 @@ discard block |
||
| 2251 | 2251 | * True si le champ est de type entier |
| 2252 | 2252 | */ |
| 2253 | 2253 | function sql_test_int($type, $serveur = '', $option = true) { |
| 2254 | - return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2254 | + return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2255 | 2255 | } |
| 2256 | 2256 | |
| 2257 | 2257 | /** |
@@ -2270,7 +2270,7 @@ discard block |
||
| 2270 | 2270 | * True si le champ est de type entier |
| 2271 | 2271 | */ |
| 2272 | 2272 | function sql_test_date($type, $serveur = '', $option = true) { |
| 2273 | - return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2273 | + return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2274 | 2274 | } |
| 2275 | 2275 | |
| 2276 | 2276 | /** |
@@ -2292,19 +2292,19 @@ discard block |
||
| 2292 | 2292 | * La date formatee |
| 2293 | 2293 | */ |
| 2294 | 2294 | function sql_format_date($annee = 0, $mois = 0, $jour = 0, $h = 0, $m = 0, $s = 0, $serveur = '') { |
| 2295 | - $annee = sprintf('%04s', $annee); |
|
| 2296 | - $mois = sprintf('%02s', $mois); |
|
| 2297 | - |
|
| 2298 | - if ($annee == '0000') { |
|
| 2299 | - $mois = 0; |
|
| 2300 | - } |
|
| 2301 | - if ($mois == '00') { |
|
| 2302 | - $jour = 0; |
|
| 2303 | - } |
|
| 2304 | - |
|
| 2305 | - return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2306 | - . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2307 | - . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2295 | + $annee = sprintf('%04s', $annee); |
|
| 2296 | + $mois = sprintf('%02s', $mois); |
|
| 2297 | + |
|
| 2298 | + if ($annee == '0000') { |
|
| 2299 | + $mois = 0; |
|
| 2300 | + } |
|
| 2301 | + if ($mois == '00') { |
|
| 2302 | + $jour = 0; |
|
| 2303 | + } |
|
| 2304 | + |
|
| 2305 | + return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2306 | + . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2307 | + . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2308 | 2308 | } |
| 2309 | 2309 | |
| 2310 | 2310 | |
@@ -2327,32 +2327,32 @@ discard block |
||
| 2327 | 2327 | **/ |
| 2328 | 2328 | function description_table($nom, $serveur = '') { |
| 2329 | 2329 | |
| 2330 | - static $trouver_table; |
|
| 2330 | + static $trouver_table; |
|
| 2331 | 2331 | |
| 2332 | - /* toujours utiliser trouver_table |
|
| 2332 | + /* toujours utiliser trouver_table |
|
| 2333 | 2333 | qui renverra la description theorique |
| 2334 | 2334 | car sinon on va se comporter differement selon que la table est declaree |
| 2335 | 2335 | ou non |
| 2336 | 2336 | */ |
| 2337 | - if (!$trouver_table) { |
|
| 2338 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2339 | - } |
|
| 2340 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2341 | - return $desc; |
|
| 2342 | - } |
|
| 2343 | - |
|
| 2344 | - // sauf a l'installation : |
|
| 2345 | - include_spip('base/serial'); |
|
| 2346 | - if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2347 | - return $GLOBALS['tables_principales'][$nom]; |
|
| 2348 | - } |
|
| 2349 | - |
|
| 2350 | - include_spip('base/auxiliaires'); |
|
| 2351 | - if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2352 | - return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2353 | - } |
|
| 2354 | - |
|
| 2355 | - return false; |
|
| 2337 | + if (!$trouver_table) { |
|
| 2338 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2339 | + } |
|
| 2340 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2341 | + return $desc; |
|
| 2342 | + } |
|
| 2343 | + |
|
| 2344 | + // sauf a l'installation : |
|
| 2345 | + include_spip('base/serial'); |
|
| 2346 | + if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2347 | + return $GLOBALS['tables_principales'][$nom]; |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + include_spip('base/auxiliaires'); |
|
| 2351 | + if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2352 | + return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2353 | + } |
|
| 2354 | + |
|
| 2355 | + return false; |
|
| 2356 | 2356 | } |
| 2357 | 2357 | |
| 2358 | 2358 | /** |
@@ -2365,8 +2365,8 @@ discard block |
||
| 2365 | 2365 | * @return string Table sql éventuellement renommée |
| 2366 | 2366 | */ |
| 2367 | 2367 | function prefixer_table_spip($table, $prefixe) { |
| 2368 | - if ($prefixe) { |
|
| 2369 | - $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2370 | - } |
|
| 2371 | - return $table; |
|
| 2368 | + if ($prefixe) { |
|
| 2369 | + $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2370 | + } |
|
| 2371 | + return $table; |
|
| 2372 | 2372 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | require_once _ROOT_RESTREINT . 'base/objets.php'; |
| 22 | 22 | |
@@ -42,118 +42,118 @@ discard block |
||
| 42 | 42 | **/ |
| 43 | 43 | function spip_connect($serveur = '', $version = '') { |
| 44 | 44 | |
| 45 | - $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | - $index = $serveur ?: 0; |
|
| 47 | - if (!$version) { |
|
| 48 | - $version = $GLOBALS['spip_sql_version']; |
|
| 49 | - } |
|
| 50 | - if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | - return $GLOBALS['connexions'][$index]; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - include_spip('base/abstract_sql'); |
|
| 55 | - $install = (_request('exec') == 'install'); |
|
| 56 | - |
|
| 57 | - // Premiere connexion ? |
|
| 58 | - if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | - $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | - ? '' // nom de serveur mal ecrit |
|
| 61 | - : ($serveur ? |
|
| 62 | - (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | - : (_FILE_CONNECT ?: ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 64 | - : ''))); // installation pas faite |
|
| 65 | - |
|
| 66 | - unset($GLOBALS['db_ok']); |
|
| 67 | - unset($GLOBALS['spip_connect_version']); |
|
| 68 | - if ($f) { |
|
| 69 | - if (is_readable($f)) { |
|
| 70 | - include($f); |
|
| 71 | - } elseif ($serveur and !$install) { |
|
| 72 | - // chercher une declaration de serveur dans le path |
|
| 73 | - // qui pourra un jour servir a declarer des bases sqlite |
|
| 74 | - // par des plugins. Et sert aussi aux boucles POUR. |
|
| 75 | - find_in_path("$serveur.php", 'connect/', true); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 79 | - // fera mieux la prochaine fois |
|
| 80 | - if ($install) { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - if ($f and is_readable($f)) { |
|
| 84 | - spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 85 | - } else { |
|
| 86 | - spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 87 | - } |
|
| 88 | - spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 89 | - |
|
| 90 | - // ne plus reessayer si ce n'est pas l'install |
|
| 91 | - return $GLOBALS['connexions'][$index] = false; |
|
| 92 | - } |
|
| 93 | - $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 94 | - } |
|
| 95 | - // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 96 | - if (!$GLOBALS['connexions'][$index]) { |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // la connexion a reussi ou etait deja faite. |
|
| 101 | - // chargement de la version du jeu de fonctions |
|
| 102 | - // si pas dans le fichier par defaut |
|
| 103 | - $type = $GLOBALS['db_ok']['type']; |
|
| 104 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 105 | - if (!isset($GLOBALS[$jeu])) { |
|
| 106 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 107 | - spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 108 | - |
|
| 109 | - // ne plus reessayer |
|
| 110 | - return $GLOBALS['connexions'][$index][$version] = []; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 114 | - if ($old) { |
|
| 115 | - return $GLOBALS['connexions'][$index]; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0; |
|
| 119 | - |
|
| 120 | - // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 121 | - // si l'installation l'a determine. |
|
| 122 | - // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 123 | - // s'ils le connaissent |
|
| 124 | - |
|
| 125 | - if (!$serveur) { |
|
| 126 | - $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 127 | - if (!$charset) { |
|
| 128 | - unset($GLOBALS['connexions'][$index]); |
|
| 129 | - spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 130 | - |
|
| 131 | - return false; |
|
| 132 | - } |
|
| 133 | - } else { |
|
| 134 | - if ($GLOBALS['db_ok']['charset']) { |
|
| 135 | - $charset = $GLOBALS['db_ok']['charset']; |
|
| 136 | - } |
|
| 137 | - // spip_meta n'existe pas toujours dans la base |
|
| 138 | - // C'est le cas d'un dump sqlite par exemple |
|
| 139 | - elseif ( |
|
| 140 | - $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 141 | - and sql_showtable('spip_meta', true, $serveur) |
|
| 142 | - and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 143 | - ) { |
|
| 144 | - $charset = $r; |
|
| 145 | - } else { |
|
| 146 | - $charset = -1; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - if ($charset != -1) { |
|
| 150 | - $f = $GLOBALS[$jeu]['set_charset']; |
|
| 151 | - if (function_exists($f)) { |
|
| 152 | - $f($charset, $serveur); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $GLOBALS['connexions'][$index]; |
|
| 45 | + $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | + $index = $serveur ?: 0; |
|
| 47 | + if (!$version) { |
|
| 48 | + $version = $GLOBALS['spip_sql_version']; |
|
| 49 | + } |
|
| 50 | + if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | + return $GLOBALS['connexions'][$index]; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + include_spip('base/abstract_sql'); |
|
| 55 | + $install = (_request('exec') == 'install'); |
|
| 56 | + |
|
| 57 | + // Premiere connexion ? |
|
| 58 | + if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | + $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | + ? '' // nom de serveur mal ecrit |
|
| 61 | + : ($serveur ? |
|
| 62 | + (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | + : (_FILE_CONNECT ?: ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 64 | + : ''))); // installation pas faite |
|
| 65 | + |
|
| 66 | + unset($GLOBALS['db_ok']); |
|
| 67 | + unset($GLOBALS['spip_connect_version']); |
|
| 68 | + if ($f) { |
|
| 69 | + if (is_readable($f)) { |
|
| 70 | + include($f); |
|
| 71 | + } elseif ($serveur and !$install) { |
|
| 72 | + // chercher une declaration de serveur dans le path |
|
| 73 | + // qui pourra un jour servir a declarer des bases sqlite |
|
| 74 | + // par des plugins. Et sert aussi aux boucles POUR. |
|
| 75 | + find_in_path("$serveur.php", 'connect/', true); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 79 | + // fera mieux la prochaine fois |
|
| 80 | + if ($install) { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + if ($f and is_readable($f)) { |
|
| 84 | + spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 85 | + } else { |
|
| 86 | + spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 87 | + } |
|
| 88 | + spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 89 | + |
|
| 90 | + // ne plus reessayer si ce n'est pas l'install |
|
| 91 | + return $GLOBALS['connexions'][$index] = false; |
|
| 92 | + } |
|
| 93 | + $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 94 | + } |
|
| 95 | + // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 96 | + if (!$GLOBALS['connexions'][$index]) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // la connexion a reussi ou etait deja faite. |
|
| 101 | + // chargement de la version du jeu de fonctions |
|
| 102 | + // si pas dans le fichier par defaut |
|
| 103 | + $type = $GLOBALS['db_ok']['type']; |
|
| 104 | + $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 105 | + if (!isset($GLOBALS[$jeu])) { |
|
| 106 | + if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 107 | + spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 108 | + |
|
| 109 | + // ne plus reessayer |
|
| 110 | + return $GLOBALS['connexions'][$index][$version] = []; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 114 | + if ($old) { |
|
| 115 | + return $GLOBALS['connexions'][$index]; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0; |
|
| 119 | + |
|
| 120 | + // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 121 | + // si l'installation l'a determine. |
|
| 122 | + // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 123 | + // s'ils le connaissent |
|
| 124 | + |
|
| 125 | + if (!$serveur) { |
|
| 126 | + $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 127 | + if (!$charset) { |
|
| 128 | + unset($GLOBALS['connexions'][$index]); |
|
| 129 | + spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 130 | + |
|
| 131 | + return false; |
|
| 132 | + } |
|
| 133 | + } else { |
|
| 134 | + if ($GLOBALS['db_ok']['charset']) { |
|
| 135 | + $charset = $GLOBALS['db_ok']['charset']; |
|
| 136 | + } |
|
| 137 | + // spip_meta n'existe pas toujours dans la base |
|
| 138 | + // C'est le cas d'un dump sqlite par exemple |
|
| 139 | + elseif ( |
|
| 140 | + $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 141 | + and sql_showtable('spip_meta', true, $serveur) |
|
| 142 | + and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 143 | + ) { |
|
| 144 | + $charset = $r; |
|
| 145 | + } else { |
|
| 146 | + $charset = -1; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + if ($charset != -1) { |
|
| 150 | + $f = $GLOBALS[$jeu]['set_charset']; |
|
| 151 | + if (function_exists($f)) { |
|
| 152 | + $f($charset, $serveur); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $GLOBALS['connexions'][$index]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | * @param string $serveur Nom du connecteur de bdd utilisé |
| 163 | 163 | **/ |
| 164 | 164 | function spip_sql_erreur($serveur = '') { |
| 165 | - $connexion = spip_connect($serveur); |
|
| 166 | - $e = sql_errno($serveur); |
|
| 167 | - $t = ($connexion['type'] ?? 'sql'); |
|
| 168 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | - $f = $t . $serveur; |
|
| 170 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 165 | + $connexion = spip_connect($serveur); |
|
| 166 | + $e = sql_errno($serveur); |
|
| 167 | + $t = ($connexion['type'] ?? 'sql'); |
|
| 168 | + $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | + $f = $t . $serveur; |
|
| 170 | + spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -189,23 +189,23 @@ discard block |
||
| 189 | 189 | * - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion |
| 190 | 190 | **/ |
| 191 | 191 | function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) { |
| 192 | - $desc = spip_connect($serveur, $version); |
|
| 193 | - if ( |
|
| 194 | - $desc |
|
| 195 | - and $f = ($desc[$version][$ins] ?? '') |
|
| 196 | - and function_exists($f) |
|
| 197 | - ) { |
|
| 198 | - return $f; |
|
| 199 | - } |
|
| 200 | - if ($continue) { |
|
| 201 | - return $desc; |
|
| 202 | - } |
|
| 203 | - if ($ins) { |
|
| 204 | - spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 205 | - } |
|
| 206 | - include_spip('inc/minipres'); |
|
| 207 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 208 | - exit; |
|
| 192 | + $desc = spip_connect($serveur, $version); |
|
| 193 | + if ( |
|
| 194 | + $desc |
|
| 195 | + and $f = ($desc[$version][$ins] ?? '') |
|
| 196 | + and function_exists($f) |
|
| 197 | + ) { |
|
| 198 | + return $f; |
|
| 199 | + } |
|
| 200 | + if ($continue) { |
|
| 201 | + return $desc; |
|
| 202 | + } |
|
| 203 | + if ($ins) { |
|
| 204 | + spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 205 | + } |
|
| 206 | + include_spip('inc/minipres'); |
|
| 207 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 208 | + exit; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -231,69 +231,69 @@ discard block |
||
| 231 | 231 | * @return array Description de la connexion |
| 232 | 232 | */ |
| 233 | 233 | function spip_connect_db( |
| 234 | - $host, |
|
| 235 | - $port, |
|
| 236 | - $login, |
|
| 237 | - $pass, |
|
| 238 | - $db = '', |
|
| 239 | - $type = 'mysql', |
|
| 240 | - $prefixe = '', |
|
| 241 | - $auth = '', |
|
| 242 | - $charset = '' |
|
| 234 | + $host, |
|
| 235 | + $port, |
|
| 236 | + $login, |
|
| 237 | + $pass, |
|
| 238 | + $db = '', |
|
| 239 | + $type = 'mysql', |
|
| 240 | + $prefixe = '', |
|
| 241 | + $auth = '', |
|
| 242 | + $charset = '' |
|
| 243 | 243 | ) { |
| 244 | - // temps avant nouvelle tentative de connexion |
|
| 245 | - // suite a une connection echouee |
|
| 246 | - if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 247 | - define('_CONNECT_RETRY_DELAY', 30); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $f = ''; |
|
| 251 | - // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 252 | - // pour ne pas declarer tout indisponible d'un coup |
|
| 253 | - // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 254 | - // car c'est un test de connexion |
|
| 255 | - if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') { |
|
| 256 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 257 | - } elseif ($db == '@test@') { |
|
| 258 | - $db = ''; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if ( |
|
| 262 | - $f |
|
| 263 | - and @file_exists($f) |
|
| 264 | - and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 265 | - ) { |
|
| 266 | - spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 267 | - |
|
| 268 | - return; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - if (!$prefixe) { |
|
| 272 | - $prefixe = $GLOBALS['table_prefix'] ?? $db; |
|
| 273 | - } |
|
| 274 | - $h = charger_fonction($type, 'req', true); |
|
| 275 | - if (!$h) { |
|
| 276 | - spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 277 | - |
|
| 278 | - return; |
|
| 279 | - } |
|
| 280 | - if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 281 | - if (!is_array($auth)) { |
|
| 282 | - // compatibilite version 0.7 initiale |
|
| 283 | - $g['ldap'] = $auth; |
|
| 284 | - $auth = ['ldap' => $auth]; |
|
| 285 | - } |
|
| 286 | - $g['authentification'] = $auth; |
|
| 287 | - $g['type'] = $type; |
|
| 288 | - $g['charset'] = $charset; |
|
| 289 | - |
|
| 290 | - return $GLOBALS['db_ok'] = $g; |
|
| 291 | - } |
|
| 292 | - // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 293 | - if ($f) { |
|
| 294 | - @touch($f); |
|
| 295 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 296 | - } |
|
| 244 | + // temps avant nouvelle tentative de connexion |
|
| 245 | + // suite a une connection echouee |
|
| 246 | + if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 247 | + define('_CONNECT_RETRY_DELAY', 30); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $f = ''; |
|
| 251 | + // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 252 | + // pour ne pas declarer tout indisponible d'un coup |
|
| 253 | + // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 254 | + // car c'est un test de connexion |
|
| 255 | + if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') { |
|
| 256 | + $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 257 | + } elseif ($db == '@test@') { |
|
| 258 | + $db = ''; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if ( |
|
| 262 | + $f |
|
| 263 | + and @file_exists($f) |
|
| 264 | + and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 265 | + ) { |
|
| 266 | + spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 267 | + |
|
| 268 | + return; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + if (!$prefixe) { |
|
| 272 | + $prefixe = $GLOBALS['table_prefix'] ?? $db; |
|
| 273 | + } |
|
| 274 | + $h = charger_fonction($type, 'req', true); |
|
| 275 | + if (!$h) { |
|
| 276 | + spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 277 | + |
|
| 278 | + return; |
|
| 279 | + } |
|
| 280 | + if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 281 | + if (!is_array($auth)) { |
|
| 282 | + // compatibilite version 0.7 initiale |
|
| 283 | + $g['ldap'] = $auth; |
|
| 284 | + $auth = ['ldap' => $auth]; |
|
| 285 | + } |
|
| 286 | + $g['authentification'] = $auth; |
|
| 287 | + $g['type'] = $type; |
|
| 288 | + $g['charset'] = $charset; |
|
| 289 | + |
|
| 290 | + return $GLOBALS['db_ok'] = $g; |
|
| 291 | + } |
|
| 292 | + // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 293 | + if ($f) { |
|
| 294 | + @touch($f); |
|
| 295 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 296 | + } |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
@@ -325,32 +325,32 @@ discard block |
||
| 325 | 325 | * - nom du charset sinon |
| 326 | 326 | **/ |
| 327 | 327 | function spip_connect_main($connexion, $charset_sql_connexion = '') { |
| 328 | - if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 329 | - include_spip('inc/headers'); |
|
| 330 | - redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - if (!($f = $connexion['select'])) { |
|
| 334 | - return false; |
|
| 335 | - } |
|
| 336 | - // si le charset est fourni, l'utiliser |
|
| 337 | - if ($charset_sql_connexion) { |
|
| 338 | - return $charset_sql_connexion; |
|
| 339 | - } |
|
| 340 | - // sinon on regarde la table spip_meta |
|
| 341 | - // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 342 | - if ( |
|
| 343 | - !$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 344 | - or is_string($r) |
|
| 345 | - ) { |
|
| 346 | - return false; |
|
| 347 | - } |
|
| 348 | - if (!($f = $connexion['fetch'])) { |
|
| 349 | - return false; |
|
| 350 | - } |
|
| 351 | - $r = $f($r); |
|
| 352 | - |
|
| 353 | - return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 328 | + if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 329 | + include_spip('inc/headers'); |
|
| 330 | + redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + if (!($f = $connexion['select'])) { |
|
| 334 | + return false; |
|
| 335 | + } |
|
| 336 | + // si le charset est fourni, l'utiliser |
|
| 337 | + if ($charset_sql_connexion) { |
|
| 338 | + return $charset_sql_connexion; |
|
| 339 | + } |
|
| 340 | + // sinon on regarde la table spip_meta |
|
| 341 | + // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 342 | + if ( |
|
| 343 | + !$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 344 | + or is_string($r) |
|
| 345 | + ) { |
|
| 346 | + return false; |
|
| 347 | + } |
|
| 348 | + if (!($f = $connexion['fetch'])) { |
|
| 349 | + return false; |
|
| 350 | + } |
|
| 351 | + $r = $f($r); |
|
| 352 | + |
|
| 353 | + return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -366,9 +366,9 @@ discard block |
||
| 366 | 366 | * @return array |
| 367 | 367 | */ |
| 368 | 368 | function spip_connect_ldap($serveur = '') { |
| 369 | - include_spip('auth/ldap'); |
|
| 369 | + include_spip('auth/ldap'); |
|
| 370 | 370 | |
| 371 | - return auth_ldap_connect($serveur); |
|
| 371 | + return auth_ldap_connect($serveur); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -384,16 +384,16 @@ discard block |
||
| 384 | 384 | * @return string Valeur échappée. |
| 385 | 385 | **/ |
| 386 | 386 | function _q($a): string { |
| 387 | - if (is_numeric($a)) { |
|
| 388 | - return strval($a); |
|
| 389 | - } elseif (is_array($a)) { |
|
| 390 | - return join(',', array_map('_q', $a)); |
|
| 391 | - } elseif (is_scalar($a)) { |
|
| 392 | - return ("'" . addslashes($a) . "'"); |
|
| 393 | - } elseif ($a === null) { |
|
| 394 | - return "''"; |
|
| 395 | - } |
|
| 396 | - throw new \RuntimeException("Can’t use _q with " . gettype($a)); |
|
| 387 | + if (is_numeric($a)) { |
|
| 388 | + return strval($a); |
|
| 389 | + } elseif (is_array($a)) { |
|
| 390 | + return join(',', array_map('_q', $a)); |
|
| 391 | + } elseif (is_scalar($a)) { |
|
| 392 | + return ("'" . addslashes($a) . "'"); |
|
| 393 | + } elseif ($a === null) { |
|
| 394 | + return "''"; |
|
| 395 | + } |
|
| 396 | + throw new \RuntimeException("Can’t use _q with " . gettype($a)); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -409,66 +409,66 @@ discard block |
||
| 409 | 409 | * @return array |
| 410 | 410 | */ |
| 411 | 411 | function query_echappe_textes($query, $uniqid = null) { |
| 412 | - static $codeEchappements = null; |
|
| 413 | - if (is_null($codeEchappements) or $uniqid) { |
|
| 414 | - if (is_null($uniqid)) { |
|
| 415 | - $uniqid = uniqid(); |
|
| 416 | - } |
|
| 417 | - $uniqid = substr(md5($uniqid), 0, 4); |
|
| 418 | - $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3"]; |
|
| 419 | - } |
|
| 420 | - if ($query === null) { |
|
| 421 | - return $codeEchappements; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 425 | - // ce n'est pas un cas legitime |
|
| 426 | - foreach ($codeEchappements as $codeEchappement) { |
|
| 427 | - if (strpos($query, (string) $codeEchappement) !== false) { |
|
| 428 | - return [$query, []]; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 433 | - if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 434 | - $textes = reset($textes); // indice 0 du match |
|
| 435 | - switch (count($textes)) { |
|
| 436 | - case 0: |
|
| 437 | - $replace = []; |
|
| 438 | - break; |
|
| 439 | - case 1: |
|
| 440 | - $replace = ['%1$s']; |
|
| 441 | - break; |
|
| 442 | - case 2: |
|
| 443 | - $replace = ['%1$s', '%2$s']; |
|
| 444 | - break; |
|
| 445 | - case 3: |
|
| 446 | - $replace = ['%1$s', '%2$s', '%3$s']; |
|
| 447 | - break; |
|
| 448 | - case 4: |
|
| 449 | - $replace = ['%1$s', '%2$s', '%3$s', '%4$s']; |
|
| 450 | - break; |
|
| 451 | - case 5: |
|
| 452 | - $replace = ['%1$s', '%2$s', '%3$s', '%4$s', '%5$s']; |
|
| 453 | - break; |
|
| 454 | - default: |
|
| 455 | - $replace = range(1, count($textes)); |
|
| 456 | - $replace = '%' . implode('$s,%', $replace) . '$s'; |
|
| 457 | - $replace = explode(',', $replace); |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - $query_echappees = str_replace($textes, $replace, $query_echappees); |
|
| 461 | - } else { |
|
| 462 | - $textes = []; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelles les pinceaux |
|
| 466 | - // dans le doute on ne touche a rien |
|
| 467 | - if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 468 | - return [$query, []]; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - return [$query_echappees, $textes]; |
|
| 412 | + static $codeEchappements = null; |
|
| 413 | + if (is_null($codeEchappements) or $uniqid) { |
|
| 414 | + if (is_null($uniqid)) { |
|
| 415 | + $uniqid = uniqid(); |
|
| 416 | + } |
|
| 417 | + $uniqid = substr(md5($uniqid), 0, 4); |
|
| 418 | + $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3"]; |
|
| 419 | + } |
|
| 420 | + if ($query === null) { |
|
| 421 | + return $codeEchappements; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 425 | + // ce n'est pas un cas legitime |
|
| 426 | + foreach ($codeEchappements as $codeEchappement) { |
|
| 427 | + if (strpos($query, (string) $codeEchappement) !== false) { |
|
| 428 | + return [$query, []]; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 433 | + if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 434 | + $textes = reset($textes); // indice 0 du match |
|
| 435 | + switch (count($textes)) { |
|
| 436 | + case 0: |
|
| 437 | + $replace = []; |
|
| 438 | + break; |
|
| 439 | + case 1: |
|
| 440 | + $replace = ['%1$s']; |
|
| 441 | + break; |
|
| 442 | + case 2: |
|
| 443 | + $replace = ['%1$s', '%2$s']; |
|
| 444 | + break; |
|
| 445 | + case 3: |
|
| 446 | + $replace = ['%1$s', '%2$s', '%3$s']; |
|
| 447 | + break; |
|
| 448 | + case 4: |
|
| 449 | + $replace = ['%1$s', '%2$s', '%3$s', '%4$s']; |
|
| 450 | + break; |
|
| 451 | + case 5: |
|
| 452 | + $replace = ['%1$s', '%2$s', '%3$s', '%4$s', '%5$s']; |
|
| 453 | + break; |
|
| 454 | + default: |
|
| 455 | + $replace = range(1, count($textes)); |
|
| 456 | + $replace = '%' . implode('$s,%', $replace) . '$s'; |
|
| 457 | + $replace = explode(',', $replace); |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + $query_echappees = str_replace($textes, $replace, $query_echappees); |
|
| 461 | + } else { |
|
| 462 | + $textes = []; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelles les pinceaux |
|
| 466 | + // dans le doute on ne touche a rien |
|
| 467 | + if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 468 | + return [$query, []]; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + return [$query_echappees, $textes]; |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | /** |
@@ -482,14 +482,14 @@ discard block |
||
| 482 | 482 | * @return string |
| 483 | 483 | */ |
| 484 | 484 | function query_reinjecte_textes($query, $textes) { |
| 485 | - // recuperer les codes echappements |
|
| 486 | - $codeEchappements = query_echappe_textes(null); |
|
| 485 | + // recuperer les codes echappements |
|
| 486 | + $codeEchappements = query_echappe_textes(null); |
|
| 487 | 487 | |
| 488 | - $query = sprintf($query, ...$textes); |
|
| 488 | + $query = sprintf($query, ...$textes); |
|
| 489 | 489 | |
| 490 | - $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 490 | + $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 491 | 491 | |
| 492 | - return $query; |
|
| 492 | + return $query; |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | **/ |
| 509 | 509 | function spip_query($query, $serveur = '') { |
| 510 | 510 | |
| 511 | - $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 511 | + $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 512 | 512 | |
| 513 | - return function_exists($f) ? $f($query, $serveur) : false; |
|
| 513 | + return function_exists($f) ? $f($query, $serveur) : false; |
|
| 514 | 514 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | define('_VERSION_ARCHIVE', '1.3'); |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return string |
| 39 | 39 | **/ |
| 40 | 40 | function base_dump_meta_name($rub) { |
| 41 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | + return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -53,15 +53,15 @@ discard block |
||
| 53 | 53 | * @return string |
| 54 | 54 | **/ |
| 55 | 55 | function base_dump_dir($meta) { |
| 56 | - include_spip('inc/documents'); |
|
| 57 | - // determine upload va aussi initialiser l'index "restreint" |
|
| 58 | - $maindir = determine_upload(); |
|
| 59 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 60 | - $maindir = _DIR_DUMP; |
|
| 61 | - } |
|
| 62 | - $dir = sous_repertoire($maindir, $meta); |
|
| 63 | - |
|
| 64 | - return $dir; |
|
| 56 | + include_spip('inc/documents'); |
|
| 57 | + // determine upload va aussi initialiser l'index "restreint" |
|
| 58 | + $maindir = determine_upload(); |
|
| 59 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 60 | + $maindir = _DIR_DUMP; |
|
| 61 | + } |
|
| 62 | + $dir = sous_repertoire($maindir, $meta); |
|
| 63 | + |
|
| 64 | + return $dir; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -75,28 +75,28 @@ discard block |
||
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | 77 | function base_lister_toutes_tables( |
| 78 | - $serveur = '', |
|
| 79 | - $tables = [], |
|
| 80 | - $exclude = [], |
|
| 81 | - $affiche_vrai_prefixe = false |
|
| 78 | + $serveur = '', |
|
| 79 | + $tables = [], |
|
| 80 | + $exclude = [], |
|
| 81 | + $affiche_vrai_prefixe = false |
|
| 82 | 82 | ) { |
| 83 | - spip_connect($serveur); |
|
| 84 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 85 | - $prefixe = $connexion['prefixe']; |
|
| 86 | - |
|
| 87 | - $p = '/^' . $prefixe . '/'; |
|
| 88 | - $res = $tables; |
|
| 89 | - foreach (sql_alltable(null, $serveur) as $t) { |
|
| 90 | - if (preg_match($p, $t)) { |
|
| 91 | - $t1 = preg_replace($p, 'spip', $t); |
|
| 92 | - if (!in_array($t1, $tables) and !in_array($t1, $exclude)) { |
|
| 93 | - $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - sort($res); |
|
| 98 | - |
|
| 99 | - return $res; |
|
| 83 | + spip_connect($serveur); |
|
| 84 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 85 | + $prefixe = $connexion['prefixe']; |
|
| 86 | + |
|
| 87 | + $p = '/^' . $prefixe . '/'; |
|
| 88 | + $res = $tables; |
|
| 89 | + foreach (sql_alltable(null, $serveur) as $t) { |
|
| 90 | + if (preg_match($p, $t)) { |
|
| 91 | + $t1 = preg_replace($p, 'spip', $t); |
|
| 92 | + if (!in_array($t1, $tables) and !in_array($t1, $exclude)) { |
|
| 93 | + $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + sort($res); |
|
| 98 | + |
|
| 99 | + return $res; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | 108 | function base_prefixe_tables($serveur = '') { |
| 109 | - spip_connect($serveur); |
|
| 110 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 111 | - $prefixe = $connexion['prefixe']; |
|
| 109 | + spip_connect($serveur); |
|
| 110 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 111 | + $prefixe = $connexion['prefixe']; |
|
| 112 | 112 | |
| 113 | - return $prefixe; |
|
| 113 | + return $prefixe; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -125,31 +125,31 @@ discard block |
||
| 125 | 125 | * @return array |
| 126 | 126 | */ |
| 127 | 127 | function base_saisie_tables($name, $tables, $exclude = [], $post = null, $serveur = '') { |
| 128 | - include_spip('inc/filtres'); |
|
| 129 | - $res = []; |
|
| 130 | - foreach ($tables as $k => $t) { |
|
| 131 | - // par defaut tout est coche sauf les tables dans $exclude |
|
| 132 | - if (is_null($post)) { |
|
| 133 | - $check = (in_array($t, $exclude) ? false : true); |
|
| 134 | - } // mais si on a poste une selection, la reprendre |
|
| 135 | - else { |
|
| 136 | - $check = in_array($t, $post); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 140 | - . "[]' id='$name$k'" |
|
| 141 | - . ($check ? " checked='checked'" : '') |
|
| 142 | - . "/>\n" |
|
| 143 | - . "<label for='$name$k'>$t</label>" |
|
| 144 | - . ' (' |
|
| 145 | - . sinon( |
|
| 146 | - singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 147 | - _T('dump:aucune_donnee') |
|
| 148 | - ) |
|
| 149 | - . ')'; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $res; |
|
| 128 | + include_spip('inc/filtres'); |
|
| 129 | + $res = []; |
|
| 130 | + foreach ($tables as $k => $t) { |
|
| 131 | + // par defaut tout est coche sauf les tables dans $exclude |
|
| 132 | + if (is_null($post)) { |
|
| 133 | + $check = (in_array($t, $exclude) ? false : true); |
|
| 134 | + } // mais si on a poste une selection, la reprendre |
|
| 135 | + else { |
|
| 136 | + $check = in_array($t, $post); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 140 | + . "[]' id='$name$k'" |
|
| 141 | + . ($check ? " checked='checked'" : '') |
|
| 142 | + . "/>\n" |
|
| 143 | + . "<label for='$name$k'>$t</label>" |
|
| 144 | + . ' (' |
|
| 145 | + . sinon( |
|
| 146 | + singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 147 | + _T('dump:aucune_donnee') |
|
| 148 | + ) |
|
| 149 | + . ')'; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $res; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -161,27 +161,27 @@ discard block |
||
| 161 | 161 | * @return array |
| 162 | 162 | */ |
| 163 | 163 | function lister_tables_noexport() { |
| 164 | - // par defaut tout est exporte sauf les tables ci-dessous |
|
| 165 | - static $EXPORT_tables_noexport = null; |
|
| 166 | - if (!is_null($EXPORT_tables_noexport)) { |
|
| 167 | - return $EXPORT_tables_noexport; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $EXPORT_tables_noexport = [ |
|
| 171 | - 'spip_caches', // plugin invalideur |
|
| 172 | - 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 173 | - 'spip_test', // c'est un test ! |
|
| 174 | - #'spip_referers', |
|
| 175 | - #'spip_referers_articles', |
|
| 176 | - #'spip_visites', |
|
| 177 | - #'spip_visites_articles', |
|
| 178 | - #'spip_versions', |
|
| 179 | - #'spip_versions_fragments' |
|
| 180 | - ]; |
|
| 181 | - |
|
| 182 | - $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 183 | - |
|
| 184 | - return $EXPORT_tables_noexport; |
|
| 164 | + // par defaut tout est exporte sauf les tables ci-dessous |
|
| 165 | + static $EXPORT_tables_noexport = null; |
|
| 166 | + if (!is_null($EXPORT_tables_noexport)) { |
|
| 167 | + return $EXPORT_tables_noexport; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $EXPORT_tables_noexport = [ |
|
| 171 | + 'spip_caches', // plugin invalideur |
|
| 172 | + 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 173 | + 'spip_test', // c'est un test ! |
|
| 174 | + #'spip_referers', |
|
| 175 | + #'spip_referers_articles', |
|
| 176 | + #'spip_visites', |
|
| 177 | + #'spip_visites_articles', |
|
| 178 | + #'spip_versions', |
|
| 179 | + #'spip_versions_fragments' |
|
| 180 | + ]; |
|
| 181 | + |
|
| 182 | + $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 183 | + |
|
| 184 | + return $EXPORT_tables_noexport; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -192,25 +192,25 @@ discard block |
||
| 192 | 192 | * @return array |
| 193 | 193 | */ |
| 194 | 194 | function lister_tables_noimport() { |
| 195 | - static $IMPORT_tables_noimport = null; |
|
| 196 | - if (!is_null($IMPORT_tables_noimport)) { |
|
| 197 | - return $IMPORT_tables_noimport; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $IMPORT_tables_noimport = []; |
|
| 201 | - // par defaut tout est importe sauf les tables ci-dessous |
|
| 202 | - // possibiliter de definir cela tables via la meta |
|
| 203 | - // compatibilite |
|
| 204 | - if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 205 | - $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 206 | - if (!is_array($IMPORT_tables_noimport)) { |
|
| 207 | - include_spip('inc/meta'); |
|
| 208 | - effacer_meta('IMPORT_tables_noimport'); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 212 | - |
|
| 213 | - return $IMPORT_tables_noimport; |
|
| 195 | + static $IMPORT_tables_noimport = null; |
|
| 196 | + if (!is_null($IMPORT_tables_noimport)) { |
|
| 197 | + return $IMPORT_tables_noimport; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $IMPORT_tables_noimport = []; |
|
| 201 | + // par defaut tout est importe sauf les tables ci-dessous |
|
| 202 | + // possibiliter de definir cela tables via la meta |
|
| 203 | + // compatibilite |
|
| 204 | + if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 205 | + $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 206 | + if (!is_array($IMPORT_tables_noimport)) { |
|
| 207 | + include_spip('inc/meta'); |
|
| 208 | + effacer_meta('IMPORT_tables_noimport'); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 212 | + |
|
| 213 | + return $IMPORT_tables_noimport; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
@@ -222,23 +222,23 @@ discard block |
||
| 222 | 222 | * @return array |
| 223 | 223 | */ |
| 224 | 224 | function lister_tables_noerase() { |
| 225 | - static $IMPORT_tables_noerase = null; |
|
| 226 | - if (!is_null($IMPORT_tables_noerase)) { |
|
| 227 | - return $IMPORT_tables_noerase; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $IMPORT_tables_noerase = [ |
|
| 231 | - 'spip_meta', |
|
| 232 | - // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 233 | - // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 234 | - 'spip_referers', |
|
| 235 | - 'spip_referers_articles', |
|
| 236 | - 'spip_visites', |
|
| 237 | - 'spip_visites_articles' |
|
| 238 | - ]; |
|
| 239 | - $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 240 | - |
|
| 241 | - return $IMPORT_tables_noerase; |
|
| 225 | + static $IMPORT_tables_noerase = null; |
|
| 226 | + if (!is_null($IMPORT_tables_noerase)) { |
|
| 227 | + return $IMPORT_tables_noerase; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $IMPORT_tables_noerase = [ |
|
| 231 | + 'spip_meta', |
|
| 232 | + // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 233 | + // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 234 | + 'spip_referers', |
|
| 235 | + 'spip_referers_articles', |
|
| 236 | + 'spip_visites', |
|
| 237 | + 'spip_visites_articles' |
|
| 238 | + ]; |
|
| 239 | + $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 240 | + |
|
| 241 | + return $IMPORT_tables_noerase; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -252,86 +252,86 @@ discard block |
||
| 252 | 252 | * @return array |
| 253 | 253 | */ |
| 254 | 254 | function base_liste_table_for_dump($exclude_tables = []) { |
| 255 | - $tables_for_dump = []; |
|
| 256 | - $tables_pointees = []; |
|
| 257 | - $tables = []; |
|
| 258 | - $tables_principales = $GLOBALS['tables_principales']; |
|
| 259 | - $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 260 | - $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 261 | - |
|
| 262 | - if ( |
|
| 263 | - include_spip('base/objets') |
|
| 264 | - and function_exists('lister_tables_objets_sql') |
|
| 265 | - ) { |
|
| 266 | - $tables = lister_tables_objets_sql(); |
|
| 267 | - foreach ($tables as $t => $infos) { |
|
| 268 | - if ($infos['principale'] and !isset($tables_principales[$t])) { |
|
| 269 | - $tables_principales[$t] = true; |
|
| 270 | - } |
|
| 271 | - if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) { |
|
| 272 | - $tables_auxiliaires[$t] = true; |
|
| 273 | - } |
|
| 274 | - if (is_countable($infos['tables_jointures']) ? count($infos['tables_jointures']) : 0) { |
|
| 275 | - $tables_jointures[$t] = array_merge( |
|
| 276 | - $tables_jointures[$t] ?? [], |
|
| 277 | - $infos['tables_jointures'] |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // on construit un index des tables de liens |
|
| 284 | - // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 285 | - $tables_for_link = []; |
|
| 286 | - foreach ($tables_jointures as $table => $liste_relations) { |
|
| 287 | - if (is_array($liste_relations)) { |
|
| 288 | - $nom = $table; |
|
| 289 | - if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 290 | - $nom = "spip_$table"; |
|
| 291 | - } |
|
| 292 | - if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 293 | - foreach ($liste_relations as $link_table) { |
|
| 294 | - if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 295 | - $tables_for_link[$link_table][] = $nom; |
|
| 296 | - } else { |
|
| 297 | - if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 298 | - $tables_for_link["spip_$link_table"][] = $nom; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - $liste_tables = [...array_keys($tables_principales), ...array_keys($tables_auxiliaires), ...array_keys($tables)]; |
|
| 307 | - foreach ($liste_tables as $table) { |
|
| 308 | - // $name = preg_replace("{^spip_}","",$table); |
|
| 309 | - if ( |
|
| 310 | - !isset($tables_pointees[$table]) |
|
| 311 | - && !in_array($table, $exclude_tables) |
|
| 312 | - && !isset($tables_for_link[$table]) |
|
| 313 | - ) { |
|
| 314 | - $tables_for_dump[] = $table; |
|
| 315 | - $tables_pointees[$table] = 1; |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - foreach ($tables_for_link as $link_table => $liste) { |
|
| 319 | - $connecte = true; |
|
| 320 | - foreach ($liste as $connect_table) { |
|
| 321 | - if (!in_array($connect_table, $tables_for_dump)) { |
|
| 322 | - $connecte = false; |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - if ($connecte) { |
|
| 326 | - # on ajoute les liaisons en premier |
|
| 327 | - # si une restauration est interrompue, |
|
| 328 | - # cela se verra mieux si il manque des objets |
|
| 329 | - # que des liens |
|
| 330 | - array_unshift($tables_for_dump, $link_table); |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - return [$tables_for_dump, $tables_for_link]; |
|
| 255 | + $tables_for_dump = []; |
|
| 256 | + $tables_pointees = []; |
|
| 257 | + $tables = []; |
|
| 258 | + $tables_principales = $GLOBALS['tables_principales']; |
|
| 259 | + $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 260 | + $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 261 | + |
|
| 262 | + if ( |
|
| 263 | + include_spip('base/objets') |
|
| 264 | + and function_exists('lister_tables_objets_sql') |
|
| 265 | + ) { |
|
| 266 | + $tables = lister_tables_objets_sql(); |
|
| 267 | + foreach ($tables as $t => $infos) { |
|
| 268 | + if ($infos['principale'] and !isset($tables_principales[$t])) { |
|
| 269 | + $tables_principales[$t] = true; |
|
| 270 | + } |
|
| 271 | + if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) { |
|
| 272 | + $tables_auxiliaires[$t] = true; |
|
| 273 | + } |
|
| 274 | + if (is_countable($infos['tables_jointures']) ? count($infos['tables_jointures']) : 0) { |
|
| 275 | + $tables_jointures[$t] = array_merge( |
|
| 276 | + $tables_jointures[$t] ?? [], |
|
| 277 | + $infos['tables_jointures'] |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // on construit un index des tables de liens |
|
| 284 | + // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 285 | + $tables_for_link = []; |
|
| 286 | + foreach ($tables_jointures as $table => $liste_relations) { |
|
| 287 | + if (is_array($liste_relations)) { |
|
| 288 | + $nom = $table; |
|
| 289 | + if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 290 | + $nom = "spip_$table"; |
|
| 291 | + } |
|
| 292 | + if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 293 | + foreach ($liste_relations as $link_table) { |
|
| 294 | + if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 295 | + $tables_for_link[$link_table][] = $nom; |
|
| 296 | + } else { |
|
| 297 | + if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 298 | + $tables_for_link["spip_$link_table"][] = $nom; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + $liste_tables = [...array_keys($tables_principales), ...array_keys($tables_auxiliaires), ...array_keys($tables)]; |
|
| 307 | + foreach ($liste_tables as $table) { |
|
| 308 | + // $name = preg_replace("{^spip_}","",$table); |
|
| 309 | + if ( |
|
| 310 | + !isset($tables_pointees[$table]) |
|
| 311 | + && !in_array($table, $exclude_tables) |
|
| 312 | + && !isset($tables_for_link[$table]) |
|
| 313 | + ) { |
|
| 314 | + $tables_for_dump[] = $table; |
|
| 315 | + $tables_pointees[$table] = 1; |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + foreach ($tables_for_link as $link_table => $liste) { |
|
| 319 | + $connecte = true; |
|
| 320 | + foreach ($liste as $connect_table) { |
|
| 321 | + if (!in_array($connect_table, $tables_for_dump)) { |
|
| 322 | + $connecte = false; |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + if ($connecte) { |
|
| 326 | + # on ajoute les liaisons en premier |
|
| 327 | + # si une restauration est interrompue, |
|
| 328 | + # cela se verra mieux si il manque des objets |
|
| 329 | + # que des liens |
|
| 330 | + array_unshift($tables_for_dump, $link_table); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + return [$tables_for_dump, $tables_for_link]; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -346,37 +346,37 @@ discard block |
||
| 346 | 346 | * @param string $serveur |
| 347 | 347 | */ |
| 348 | 348 | function base_vider_tables_destination_copie($tables, $exclure_tables = [], $serveur = '') { |
| 349 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 350 | - |
|
| 351 | - spip_log( |
|
| 352 | - 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 353 | - 'base.' . _LOG_INFO_IMPORTANTE |
|
| 354 | - ); |
|
| 355 | - foreach ($tables as $table) { |
|
| 356 | - if (!in_array($table, $exclure_tables)) { |
|
| 357 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 358 | - if (($table != 'spip_auteurs') or $serveur != '') { |
|
| 359 | - // regarder si il y a au moins un champ impt='non' |
|
| 360 | - $desc = $trouver_table($table, $serveur); |
|
| 361 | - if (isset($desc['field']['impt'])) { |
|
| 362 | - sql_delete($table, "impt='oui'", $serveur); |
|
| 363 | - } elseif ($desc) { |
|
| 364 | - sql_delete($table, '', $serveur); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 371 | - // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 372 | - if ( |
|
| 373 | - $serveur == '' |
|
| 374 | - and in_array('spip_auteurs', $tables) |
|
| 375 | - and !in_array('spip_auteurs', $exclure_tables) |
|
| 376 | - ) { |
|
| 377 | - base_conserver_copieur(true, $serveur); |
|
| 378 | - sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 379 | - } |
|
| 349 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 350 | + |
|
| 351 | + spip_log( |
|
| 352 | + 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 353 | + 'base.' . _LOG_INFO_IMPORTANTE |
|
| 354 | + ); |
|
| 355 | + foreach ($tables as $table) { |
|
| 356 | + if (!in_array($table, $exclure_tables)) { |
|
| 357 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 358 | + if (($table != 'spip_auteurs') or $serveur != '') { |
|
| 359 | + // regarder si il y a au moins un champ impt='non' |
|
| 360 | + $desc = $trouver_table($table, $serveur); |
|
| 361 | + if (isset($desc['field']['impt'])) { |
|
| 362 | + sql_delete($table, "impt='oui'", $serveur); |
|
| 363 | + } elseif ($desc) { |
|
| 364 | + sql_delete($table, '', $serveur); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 371 | + // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 372 | + if ( |
|
| 373 | + $serveur == '' |
|
| 374 | + and in_array('spip_auteurs', $tables) |
|
| 375 | + and !in_array('spip_auteurs', $exclure_tables) |
|
| 376 | + ) { |
|
| 377 | + base_conserver_copieur(true, $serveur); |
|
| 378 | + sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 379 | + } |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -387,36 +387,36 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | */ |
| 389 | 389 | function base_conserver_copieur($move = true, $serveur = '') { |
| 390 | - // s'asurer qu'on a pas deja fait la manip ! |
|
| 391 | - if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 392 | - spip_log( |
|
| 393 | - 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 394 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 395 | - ); |
|
| 396 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 397 | - if ($move) { |
|
| 398 | - sql_updateq( |
|
| 399 | - 'spip_auteurs', |
|
| 400 | - ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 401 | - 'id_auteur=' . intval($GLOBALS['visiteur_session']['id_auteur']), |
|
| 402 | - [], |
|
| 403 | - $serveur |
|
| 404 | - ); |
|
| 405 | - } else { |
|
| 406 | - $row = sql_fetsel( |
|
| 407 | - '*', |
|
| 408 | - 'spip_auteurs', |
|
| 409 | - 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 410 | - '', |
|
| 411 | - '', |
|
| 412 | - '', |
|
| 413 | - '', |
|
| 414 | - $serveur |
|
| 415 | - ); |
|
| 416 | - $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 417 | - sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 418 | - } |
|
| 419 | - } |
|
| 390 | + // s'asurer qu'on a pas deja fait la manip ! |
|
| 391 | + if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 392 | + spip_log( |
|
| 393 | + 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 394 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 395 | + ); |
|
| 396 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 397 | + if ($move) { |
|
| 398 | + sql_updateq( |
|
| 399 | + 'spip_auteurs', |
|
| 400 | + ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 401 | + 'id_auteur=' . intval($GLOBALS['visiteur_session']['id_auteur']), |
|
| 402 | + [], |
|
| 403 | + $serveur |
|
| 404 | + ); |
|
| 405 | + } else { |
|
| 406 | + $row = sql_fetsel( |
|
| 407 | + '*', |
|
| 408 | + 'spip_auteurs', |
|
| 409 | + 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 410 | + '', |
|
| 411 | + '', |
|
| 412 | + '', |
|
| 413 | + '', |
|
| 414 | + $serveur |
|
| 415 | + ); |
|
| 416 | + $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 417 | + sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -431,21 +431,21 @@ discard block |
||
| 431 | 431 | * @param string $serveur |
| 432 | 432 | */ |
| 433 | 433 | function base_detruire_copieur_si_besoin($serveur = '') { |
| 434 | - // rien a faire si ce n'est pas le serveur principal ! |
|
| 435 | - if ($serveur == '') { |
|
| 436 | - if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 437 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 439 | - } else { |
|
| 440 | - spip_log( |
|
| 441 | - "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 442 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 443 | - ); |
|
| 444 | - sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 445 | - } |
|
| 446 | - } else { |
|
| 447 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | - } |
|
| 434 | + // rien a faire si ce n'est pas le serveur principal ! |
|
| 435 | + if ($serveur == '') { |
|
| 436 | + if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 437 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 439 | + } else { |
|
| 440 | + spip_log( |
|
| 441 | + "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 442 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 443 | + ); |
|
| 444 | + sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 445 | + } |
|
| 446 | + } else { |
|
| 447 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | + } |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -460,40 +460,40 @@ discard block |
||
| 460 | 460 | * @return array |
| 461 | 461 | */ |
| 462 | 462 | function base_preparer_table_dest($table, $desc, $serveur_dest, $init = false) { |
| 463 | - $upgrade = false; |
|
| 464 | - // si la table existe et qu'on est a l'init, la dropper |
|
| 465 | - if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) { |
|
| 466 | - if ($serveur_dest == '' and in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 467 | - // ne pas dropper auteurs et meta sur le serveur principal |
|
| 468 | - // faire un simple upgrade a la place |
|
| 469 | - // pour ajouter les champs manquants |
|
| 470 | - $upgrade = true; |
|
| 471 | - // coherence avec le drop sur les autres tables |
|
| 472 | - base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 473 | - if ($table == 'spip_meta') { |
|
| 474 | - // virer les version base qui vont venir avec l'import |
|
| 475 | - sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 476 | - // hum casse la base si pas version_installee a l'import ... |
|
| 477 | - sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 478 | - } |
|
| 479 | - } else { |
|
| 480 | - sql_drop_table($table, '', $serveur_dest); |
|
| 481 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 482 | - } |
|
| 483 | - $desc_dest = false; |
|
| 484 | - } |
|
| 485 | - // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 486 | - if (!$desc_dest) { |
|
| 487 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 488 | - include_spip('base/create'); |
|
| 489 | - creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 490 | - $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 491 | - } |
|
| 492 | - if (!$desc_dest) { |
|
| 493 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $desc_dest; |
|
| 463 | + $upgrade = false; |
|
| 464 | + // si la table existe et qu'on est a l'init, la dropper |
|
| 465 | + if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) { |
|
| 466 | + if ($serveur_dest == '' and in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 467 | + // ne pas dropper auteurs et meta sur le serveur principal |
|
| 468 | + // faire un simple upgrade a la place |
|
| 469 | + // pour ajouter les champs manquants |
|
| 470 | + $upgrade = true; |
|
| 471 | + // coherence avec le drop sur les autres tables |
|
| 472 | + base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 473 | + if ($table == 'spip_meta') { |
|
| 474 | + // virer les version base qui vont venir avec l'import |
|
| 475 | + sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 476 | + // hum casse la base si pas version_installee a l'import ... |
|
| 477 | + sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 478 | + } |
|
| 479 | + } else { |
|
| 480 | + sql_drop_table($table, '', $serveur_dest); |
|
| 481 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 482 | + } |
|
| 483 | + $desc_dest = false; |
|
| 484 | + } |
|
| 485 | + // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 486 | + if (!$desc_dest) { |
|
| 487 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 488 | + include_spip('base/create'); |
|
| 489 | + creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 490 | + $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 491 | + } |
|
| 492 | + if (!$desc_dest) { |
|
| 493 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $desc_dest; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -539,211 +539,211 @@ discard block |
||
| 539 | 539 | */ |
| 540 | 540 | function base_copier_tables($status_file, $tables, $serveur_source, $serveur_dest, $options = []) { |
| 541 | 541 | |
| 542 | - $status = []; |
|
| 543 | - $callback_progression = $options['callback_progression'] ?? ''; |
|
| 544 | - $max_time = $options['max_time'] ?? 0; |
|
| 545 | - $drop_source = $options['drop_source'] ?? false; |
|
| 546 | - $no_erase_dest = $options['no_erase_dest'] ?? []; |
|
| 547 | - $where = $options['where'] ?? []; |
|
| 548 | - $fonction_base_inserer = $options['fonction_base_inserer'] ?? 'inserer_copie'; |
|
| 549 | - $desc_tables_dest = $options['desc_tables_dest'] ?? []; |
|
| 550 | - $racine_fonctions = $options['racine_fonctions_dest'] ?? 'base'; |
|
| 551 | - $data_pool = $options['data_pool'] ?? 50 * 1024; |
|
| 552 | - |
|
| 553 | - spip_log( |
|
| 554 | - 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 555 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 556 | - ); |
|
| 557 | - |
|
| 558 | - if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 559 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 560 | - |
|
| 561 | - return true; // echec mais on a fini, donc true |
|
| 562 | - } |
|
| 563 | - if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 564 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 565 | - |
|
| 566 | - return true; // echec mais on a fini, donc true |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - if ( |
|
| 570 | - !lire_fichier($status_file, $status) |
|
| 571 | - or !$status = unserialize($status) |
|
| 572 | - ) { |
|
| 573 | - $status = []; |
|
| 574 | - } |
|
| 575 | - $status['etape'] = 'basecopie'; |
|
| 576 | - |
|
| 577 | - // puis relister les tables a importer |
|
| 578 | - // et les vider si besoin, au moment du premier passage ici |
|
| 579 | - $initialisation_copie = (!isset($status['dump_status_copie'])) ? 0 : $status['dump_status_copie']; |
|
| 580 | - |
|
| 581 | - // si init pas encore faite, vider les tables du serveur destination |
|
| 582 | - if (!$initialisation_copie) { |
|
| 583 | - if ( |
|
| 584 | - !$vider_tables_destination_copie = charger_fonction( |
|
| 585 | - 'vider_tables_destination_copie', |
|
| 586 | - $racine_fonctions, |
|
| 587 | - true |
|
| 588 | - ) |
|
| 589 | - ) { |
|
| 590 | - spip_log( |
|
| 591 | - "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 592 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 593 | - ); |
|
| 594 | - |
|
| 595 | - return true; // echec mais on a fini, donc true |
|
| 596 | - } |
|
| 597 | - $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 598 | - $status['dump_status_copie'] = 'ok'; |
|
| 599 | - ecrire_fichier($status_file, serialize($status)); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 603 | - if (in_array('spip_auteurs', $tables)) { |
|
| 604 | - $tables = array_diff($tables, ['spip_auteurs']); |
|
| 605 | - $tables[] = 'spip_auteurs'; |
|
| 606 | - } |
|
| 607 | - if (in_array('spip_meta', $tables)) { |
|
| 608 | - $tables = array_diff($tables, ['spip_meta']); |
|
| 609 | - $tables[] = 'spip_meta'; |
|
| 610 | - } |
|
| 611 | - spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 612 | - |
|
| 613 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 614 | - |
|
| 615 | - foreach ($tables as $table) { |
|
| 616 | - // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 617 | - // sinon chercher la vraie table |
|
| 618 | - $desc_source = false; |
|
| 619 | - if (strncmp($table, 'spip_', 5) == 0) { |
|
| 620 | - $desc_source = $trouver_table(preg_replace(',^spip_,', '', $table), $serveur_source, true); |
|
| 621 | - } |
|
| 622 | - if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) { |
|
| 623 | - $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // verifier que la table est presente dans la base source |
|
| 627 | - if ($desc_source) { |
|
| 628 | - // $status['tables_copiees'][$table] contient l'avancement |
|
| 629 | - // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 630 | - if (!isset($status['tables_copiees'][$table])) { |
|
| 631 | - $status['tables_copiees'][$table] = 0; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if ( |
|
| 635 | - is_numeric($status['tables_copiees'][$table]) |
|
| 636 | - and $status['tables_copiees'][$table] >= 0 |
|
| 637 | - and $desc_dest = $preparer_table_dest( |
|
| 638 | - $table, |
|
| 639 | - $desc_tables_dest[$table] ?? $desc_source, |
|
| 640 | - $serveur_dest, |
|
| 641 | - $status['tables_copiees'][$table] == 0 |
|
| 642 | - ) |
|
| 643 | - ) { |
|
| 644 | - if ($callback_progression) { |
|
| 645 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 646 | - } |
|
| 647 | - while (true) { |
|
| 648 | - $n = intval($status['tables_copiees'][$table]); |
|
| 649 | - // on copie par lot de 400 |
|
| 650 | - $res = sql_select( |
|
| 651 | - '*', |
|
| 652 | - $table, |
|
| 653 | - $where[$table] ?? '', |
|
| 654 | - '', |
|
| 655 | - '', |
|
| 656 | - "$n,400", |
|
| 657 | - '', |
|
| 658 | - $serveur_source |
|
| 659 | - ); |
|
| 660 | - while ($row = sql_fetch($res, $serveur_source)) { |
|
| 661 | - $rows = [$row]; |
|
| 662 | - // lire un groupe de donnees si demande en option |
|
| 663 | - // (permet un envoi par lot vers la destination) |
|
| 664 | - if ($data_pool > 0) { |
|
| 665 | - $s = strlen(serialize($row)); |
|
| 666 | - while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) { |
|
| 667 | - $s += strlen(serialize($row)); |
|
| 668 | - $rows[] = $row; |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 672 | - // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 673 | - if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 674 | - // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 675 | - spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 676 | - $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 677 | - ecrire_fichier($status_file, serialize($status)); |
|
| 678 | - |
|
| 679 | - // copie finie |
|
| 680 | - return true; |
|
| 681 | - } |
|
| 682 | - $status['tables_copiees'][$table] += count($rows); |
|
| 683 | - if ($max_time and time() > $max_time) { |
|
| 684 | - break; |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - if ($n == $status['tables_copiees'][$table]) { |
|
| 688 | - break; |
|
| 689 | - } |
|
| 690 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 691 | - if ($callback_progression) { |
|
| 692 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 693 | - } |
|
| 694 | - ecrire_fichier($status_file, serialize($status)); |
|
| 695 | - if ($max_time and time() > $max_time) { |
|
| 696 | - return false; |
|
| 697 | - } // on a pas fini, mais le temps imparti est ecoule |
|
| 698 | - } |
|
| 699 | - if ($drop_source) { |
|
| 700 | - sql_drop_table($table, '', $serveur_source); |
|
| 701 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 702 | - } |
|
| 703 | - $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 704 | - ecrire_fichier($status_file, serialize($status)); |
|
| 705 | - spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 706 | - if ($callback_progression) { |
|
| 707 | - $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 708 | - } |
|
| 709 | - } else { |
|
| 710 | - if ($status['tables_copiees'][$table] < 0) { |
|
| 711 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 712 | - } |
|
| 713 | - if ($callback_progression) { |
|
| 714 | - $callback_progression( |
|
| 715 | - 0, |
|
| 716 | - $status['tables_copiees'][$table], |
|
| 717 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 718 | - ); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - } else { |
|
| 722 | - $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 723 | - ecrire_fichier($status_file, serialize($status)); |
|
| 724 | - spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 729 | - // abandonner |
|
| 730 | - if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
|
| 731 | - spip_log( |
|
| 732 | - 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 733 | - 'dump.' . _LOG_ERREUR |
|
| 734 | - ); |
|
| 735 | - $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 736 | - ecrire_fichier($status_file, serialize($status)); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 740 | - $detruire_copieur_si_besoin($serveur_dest); |
|
| 741 | - } else { |
|
| 742 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - // OK, copie complete |
|
| 746 | - return true; |
|
| 542 | + $status = []; |
|
| 543 | + $callback_progression = $options['callback_progression'] ?? ''; |
|
| 544 | + $max_time = $options['max_time'] ?? 0; |
|
| 545 | + $drop_source = $options['drop_source'] ?? false; |
|
| 546 | + $no_erase_dest = $options['no_erase_dest'] ?? []; |
|
| 547 | + $where = $options['where'] ?? []; |
|
| 548 | + $fonction_base_inserer = $options['fonction_base_inserer'] ?? 'inserer_copie'; |
|
| 549 | + $desc_tables_dest = $options['desc_tables_dest'] ?? []; |
|
| 550 | + $racine_fonctions = $options['racine_fonctions_dest'] ?? 'base'; |
|
| 551 | + $data_pool = $options['data_pool'] ?? 50 * 1024; |
|
| 552 | + |
|
| 553 | + spip_log( |
|
| 554 | + 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 555 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 556 | + ); |
|
| 557 | + |
|
| 558 | + if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 559 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 560 | + |
|
| 561 | + return true; // echec mais on a fini, donc true |
|
| 562 | + } |
|
| 563 | + if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 564 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 565 | + |
|
| 566 | + return true; // echec mais on a fini, donc true |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + if ( |
|
| 570 | + !lire_fichier($status_file, $status) |
|
| 571 | + or !$status = unserialize($status) |
|
| 572 | + ) { |
|
| 573 | + $status = []; |
|
| 574 | + } |
|
| 575 | + $status['etape'] = 'basecopie'; |
|
| 576 | + |
|
| 577 | + // puis relister les tables a importer |
|
| 578 | + // et les vider si besoin, au moment du premier passage ici |
|
| 579 | + $initialisation_copie = (!isset($status['dump_status_copie'])) ? 0 : $status['dump_status_copie']; |
|
| 580 | + |
|
| 581 | + // si init pas encore faite, vider les tables du serveur destination |
|
| 582 | + if (!$initialisation_copie) { |
|
| 583 | + if ( |
|
| 584 | + !$vider_tables_destination_copie = charger_fonction( |
|
| 585 | + 'vider_tables_destination_copie', |
|
| 586 | + $racine_fonctions, |
|
| 587 | + true |
|
| 588 | + ) |
|
| 589 | + ) { |
|
| 590 | + spip_log( |
|
| 591 | + "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 592 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 593 | + ); |
|
| 594 | + |
|
| 595 | + return true; // echec mais on a fini, donc true |
|
| 596 | + } |
|
| 597 | + $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 598 | + $status['dump_status_copie'] = 'ok'; |
|
| 599 | + ecrire_fichier($status_file, serialize($status)); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 603 | + if (in_array('spip_auteurs', $tables)) { |
|
| 604 | + $tables = array_diff($tables, ['spip_auteurs']); |
|
| 605 | + $tables[] = 'spip_auteurs'; |
|
| 606 | + } |
|
| 607 | + if (in_array('spip_meta', $tables)) { |
|
| 608 | + $tables = array_diff($tables, ['spip_meta']); |
|
| 609 | + $tables[] = 'spip_meta'; |
|
| 610 | + } |
|
| 611 | + spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 612 | + |
|
| 613 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 614 | + |
|
| 615 | + foreach ($tables as $table) { |
|
| 616 | + // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 617 | + // sinon chercher la vraie table |
|
| 618 | + $desc_source = false; |
|
| 619 | + if (strncmp($table, 'spip_', 5) == 0) { |
|
| 620 | + $desc_source = $trouver_table(preg_replace(',^spip_,', '', $table), $serveur_source, true); |
|
| 621 | + } |
|
| 622 | + if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) { |
|
| 623 | + $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + // verifier que la table est presente dans la base source |
|
| 627 | + if ($desc_source) { |
|
| 628 | + // $status['tables_copiees'][$table] contient l'avancement |
|
| 629 | + // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 630 | + if (!isset($status['tables_copiees'][$table])) { |
|
| 631 | + $status['tables_copiees'][$table] = 0; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if ( |
|
| 635 | + is_numeric($status['tables_copiees'][$table]) |
|
| 636 | + and $status['tables_copiees'][$table] >= 0 |
|
| 637 | + and $desc_dest = $preparer_table_dest( |
|
| 638 | + $table, |
|
| 639 | + $desc_tables_dest[$table] ?? $desc_source, |
|
| 640 | + $serveur_dest, |
|
| 641 | + $status['tables_copiees'][$table] == 0 |
|
| 642 | + ) |
|
| 643 | + ) { |
|
| 644 | + if ($callback_progression) { |
|
| 645 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 646 | + } |
|
| 647 | + while (true) { |
|
| 648 | + $n = intval($status['tables_copiees'][$table]); |
|
| 649 | + // on copie par lot de 400 |
|
| 650 | + $res = sql_select( |
|
| 651 | + '*', |
|
| 652 | + $table, |
|
| 653 | + $where[$table] ?? '', |
|
| 654 | + '', |
|
| 655 | + '', |
|
| 656 | + "$n,400", |
|
| 657 | + '', |
|
| 658 | + $serveur_source |
|
| 659 | + ); |
|
| 660 | + while ($row = sql_fetch($res, $serveur_source)) { |
|
| 661 | + $rows = [$row]; |
|
| 662 | + // lire un groupe de donnees si demande en option |
|
| 663 | + // (permet un envoi par lot vers la destination) |
|
| 664 | + if ($data_pool > 0) { |
|
| 665 | + $s = strlen(serialize($row)); |
|
| 666 | + while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) { |
|
| 667 | + $s += strlen(serialize($row)); |
|
| 668 | + $rows[] = $row; |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 672 | + // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 673 | + if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 674 | + // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 675 | + spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 676 | + $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 677 | + ecrire_fichier($status_file, serialize($status)); |
|
| 678 | + |
|
| 679 | + // copie finie |
|
| 680 | + return true; |
|
| 681 | + } |
|
| 682 | + $status['tables_copiees'][$table] += count($rows); |
|
| 683 | + if ($max_time and time() > $max_time) { |
|
| 684 | + break; |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + if ($n == $status['tables_copiees'][$table]) { |
|
| 688 | + break; |
|
| 689 | + } |
|
| 690 | + spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 691 | + if ($callback_progression) { |
|
| 692 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 693 | + } |
|
| 694 | + ecrire_fichier($status_file, serialize($status)); |
|
| 695 | + if ($max_time and time() > $max_time) { |
|
| 696 | + return false; |
|
| 697 | + } // on a pas fini, mais le temps imparti est ecoule |
|
| 698 | + } |
|
| 699 | + if ($drop_source) { |
|
| 700 | + sql_drop_table($table, '', $serveur_source); |
|
| 701 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 702 | + } |
|
| 703 | + $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 704 | + ecrire_fichier($status_file, serialize($status)); |
|
| 705 | + spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 706 | + if ($callback_progression) { |
|
| 707 | + $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 708 | + } |
|
| 709 | + } else { |
|
| 710 | + if ($status['tables_copiees'][$table] < 0) { |
|
| 711 | + spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 712 | + } |
|
| 713 | + if ($callback_progression) { |
|
| 714 | + $callback_progression( |
|
| 715 | + 0, |
|
| 716 | + $status['tables_copiees'][$table], |
|
| 717 | + "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 718 | + ); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + } else { |
|
| 722 | + $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 723 | + ecrire_fichier($status_file, serialize($status)); |
|
| 724 | + spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 729 | + // abandonner |
|
| 730 | + if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
|
| 731 | + spip_log( |
|
| 732 | + 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 733 | + 'dump.' . _LOG_ERREUR |
|
| 734 | + ); |
|
| 735 | + $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 736 | + ecrire_fichier($status_file, serialize($status)); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 740 | + $detruire_copieur_si_besoin($serveur_dest); |
|
| 741 | + } else { |
|
| 742 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + // OK, copie complete |
|
| 746 | + return true; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -757,31 +757,31 @@ discard block |
||
| 757 | 757 | */ |
| 758 | 758 | function base_inserer_copie($table, $rows, $desc_dest, $serveur_dest) { |
| 759 | 759 | |
| 760 | - // verifier le nombre d'insertion |
|
| 761 | - $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 762 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 763 | - $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 764 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 765 | - if ($nb - $nb1 < count($rows)) { |
|
| 766 | - spip_log( |
|
| 767 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 768 | - 'dump' . _LOG_INFO_IMPORTANTE |
|
| 769 | - ); |
|
| 770 | - foreach ($rows as $row) { |
|
| 771 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 772 | - $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 773 | - } |
|
| 774 | - // on reverifie le total |
|
| 775 | - $r = 0; |
|
| 776 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 777 | - if ($nb - $nb1 < count($rows)) { |
|
| 778 | - spip_log( |
|
| 779 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 780 | - 'dump' . _LOG_ERREUR |
|
| 781 | - ); |
|
| 782 | - $r = false; |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - return $r; |
|
| 760 | + // verifier le nombre d'insertion |
|
| 761 | + $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 762 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 763 | + $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 764 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 765 | + if ($nb - $nb1 < count($rows)) { |
|
| 766 | + spip_log( |
|
| 767 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 768 | + 'dump' . _LOG_INFO_IMPORTANTE |
|
| 769 | + ); |
|
| 770 | + foreach ($rows as $row) { |
|
| 771 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 772 | + $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 773 | + } |
|
| 774 | + // on reverifie le total |
|
| 775 | + $r = 0; |
|
| 776 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 777 | + if ($nb - $nb1 < count($rows)) { |
|
| 778 | + spip_log( |
|
| 779 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 780 | + 'dump' . _LOG_ERREUR |
|
| 781 | + ); |
|
| 782 | + $r = false; |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + return $r; |
|
| 787 | 787 | } |
@@ -17,17 +17,17 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_UPGRADE_TIME_OUT')) { |
| 24 | - /** |
|
| 25 | - * Durée en secondes pour relancer les scripts de mises à jour, x secondes |
|
| 26 | - * avant que la durée d'exécution du script provoque un timeout |
|
| 27 | - * |
|
| 28 | - * @var int |
|
| 29 | - **/ |
|
| 30 | - define('_UPGRADE_TIME_OUT', 20); |
|
| 24 | + /** |
|
| 25 | + * Durée en secondes pour relancer les scripts de mises à jour, x secondes |
|
| 26 | + * avant que la durée d'exécution du script provoque un timeout |
|
| 27 | + * |
|
| 28 | + * @var int |
|
| 29 | + **/ |
|
| 30 | + define('_UPGRADE_TIME_OUT', 20); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -50,40 +50,40 @@ discard block |
||
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | 52 | function base_upgrade_dist($titre = '', $reprise = '') { |
| 53 | - if (!$titre) { |
|
| 54 | - return; |
|
| 55 | - } // anti-testeur automatique |
|
| 56 | - if ($GLOBALS['spip_version_base'] != $GLOBALS['meta']['version_installee']) { |
|
| 57 | - if (!is_numeric(_request('reinstall'))) { |
|
| 58 | - include_spip('base/create'); |
|
| 59 | - spip_log('recree les tables eventuellement disparues', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 60 | - creer_base(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // quand on rentre par ici, c'est toujours une mise a jour de SPIP |
|
| 64 | - // lancement de l'upgrade SPIP |
|
| 65 | - $res = maj_base(); |
|
| 66 | - |
|
| 67 | - if ($res) { |
|
| 68 | - // on arrete tout ici ! |
|
| 69 | - exit; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - spip_log('Fin de mise a jour SQL. Debut m-a-j acces et config', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 73 | - |
|
| 74 | - // supprimer quelques fichiers temporaires qui peuvent se retrouver invalides |
|
| 75 | - @spip_unlink(_CACHE_RUBRIQUES); |
|
| 76 | - @spip_unlink(_CACHE_PIPELINES); |
|
| 77 | - @spip_unlink(_CACHE_PLUGINS_PATH); |
|
| 78 | - @spip_unlink(_CACHE_PLUGINS_OPT); |
|
| 79 | - @spip_unlink(_CACHE_PLUGINS_FCT); |
|
| 80 | - @spip_unlink(_CACHE_CHEMIN); |
|
| 81 | - @spip_unlink(_DIR_TMP . 'plugin_xml_cache.gz'); |
|
| 82 | - |
|
| 83 | - include_spip('inc/auth'); |
|
| 84 | - auth_synchroniser_distant(); |
|
| 85 | - $config = charger_fonction('config', 'inc'); |
|
| 86 | - $config(); |
|
| 53 | + if (!$titre) { |
|
| 54 | + return; |
|
| 55 | + } // anti-testeur automatique |
|
| 56 | + if ($GLOBALS['spip_version_base'] != $GLOBALS['meta']['version_installee']) { |
|
| 57 | + if (!is_numeric(_request('reinstall'))) { |
|
| 58 | + include_spip('base/create'); |
|
| 59 | + spip_log('recree les tables eventuellement disparues', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 60 | + creer_base(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // quand on rentre par ici, c'est toujours une mise a jour de SPIP |
|
| 64 | + // lancement de l'upgrade SPIP |
|
| 65 | + $res = maj_base(); |
|
| 66 | + |
|
| 67 | + if ($res) { |
|
| 68 | + // on arrete tout ici ! |
|
| 69 | + exit; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + spip_log('Fin de mise a jour SQL. Debut m-a-j acces et config', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 73 | + |
|
| 74 | + // supprimer quelques fichiers temporaires qui peuvent se retrouver invalides |
|
| 75 | + @spip_unlink(_CACHE_RUBRIQUES); |
|
| 76 | + @spip_unlink(_CACHE_PIPELINES); |
|
| 77 | + @spip_unlink(_CACHE_PLUGINS_PATH); |
|
| 78 | + @spip_unlink(_CACHE_PLUGINS_OPT); |
|
| 79 | + @spip_unlink(_CACHE_PLUGINS_FCT); |
|
| 80 | + @spip_unlink(_CACHE_CHEMIN); |
|
| 81 | + @spip_unlink(_DIR_TMP . 'plugin_xml_cache.gz'); |
|
| 82 | + |
|
| 83 | + include_spip('inc/auth'); |
|
| 84 | + auth_synchroniser_distant(); |
|
| 85 | + $config = charger_fonction('config', 'inc'); |
|
| 86 | + $config(); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -114,51 +114,51 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | function maj_base($version_cible = 0, $redirect = '', $debut_page = true) { |
| 116 | 116 | |
| 117 | - $version_installee = $GLOBALS['meta']['version_installee'] ?? null; |
|
| 118 | - |
|
| 119 | - spip_log( |
|
| 120 | - "Version anterieure: $version_installee. Courante: " . $GLOBALS['spip_version_base'], |
|
| 121 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 122 | - ); |
|
| 123 | - if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 124 | - sql_replace( |
|
| 125 | - 'spip_meta', |
|
| 126 | - [ |
|
| 127 | - 'nom' => 'version_installee', |
|
| 128 | - 'valeur' => $GLOBALS['spip_version_base'], |
|
| 129 | - 'impt' => 'non' |
|
| 130 | - ] |
|
| 131 | - ); |
|
| 132 | - return false; |
|
| 133 | - } |
|
| 134 | - if (!upgrade_test()) { |
|
| 135 | - return true; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $cible = ($version_cible ?: $GLOBALS['spip_version_base']); |
|
| 139 | - |
|
| 140 | - if ($version_installee < 2021_01_01_00) { |
|
| 141 | - include_spip('maj/legacy/v21'); |
|
| 142 | - include_spip('maj/legacy/v30'); |
|
| 143 | - include_spip('maj/legacy/v31'); |
|
| 144 | - include_spip('maj/legacy/v32'); |
|
| 145 | - include_spip('maj/legacy/v40'); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - include_spip('maj/2021'); |
|
| 149 | - |
|
| 150 | - ksort($GLOBALS['maj']); |
|
| 151 | - $res = maj_while($version_installee, $cible, $GLOBALS['maj'], 'version_installee', 'meta', $redirect, $debut_page); |
|
| 152 | - if ($res) { |
|
| 153 | - if (!is_array($res)) { |
|
| 154 | - spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_INFO_ERREUR); |
|
| 155 | - } else { |
|
| 156 | - echo _T('avis_operation_echec') . ' ' . join(' ', $res); |
|
| 157 | - echo install_fin_html(); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $res; |
|
| 117 | + $version_installee = $GLOBALS['meta']['version_installee'] ?? null; |
|
| 118 | + |
|
| 119 | + spip_log( |
|
| 120 | + "Version anterieure: $version_installee. Courante: " . $GLOBALS['spip_version_base'], |
|
| 121 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 122 | + ); |
|
| 123 | + if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 124 | + sql_replace( |
|
| 125 | + 'spip_meta', |
|
| 126 | + [ |
|
| 127 | + 'nom' => 'version_installee', |
|
| 128 | + 'valeur' => $GLOBALS['spip_version_base'], |
|
| 129 | + 'impt' => 'non' |
|
| 130 | + ] |
|
| 131 | + ); |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | + if (!upgrade_test()) { |
|
| 135 | + return true; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $cible = ($version_cible ?: $GLOBALS['spip_version_base']); |
|
| 139 | + |
|
| 140 | + if ($version_installee < 2021_01_01_00) { |
|
| 141 | + include_spip('maj/legacy/v21'); |
|
| 142 | + include_spip('maj/legacy/v30'); |
|
| 143 | + include_spip('maj/legacy/v31'); |
|
| 144 | + include_spip('maj/legacy/v32'); |
|
| 145 | + include_spip('maj/legacy/v40'); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + include_spip('maj/2021'); |
|
| 149 | + |
|
| 150 | + ksort($GLOBALS['maj']); |
|
| 151 | + $res = maj_while($version_installee, $cible, $GLOBALS['maj'], 'version_installee', 'meta', $redirect, $debut_page); |
|
| 152 | + if ($res) { |
|
| 153 | + if (!is_array($res)) { |
|
| 154 | + spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_INFO_ERREUR); |
|
| 155 | + } else { |
|
| 156 | + echo _T('avis_operation_echec') . ' ' . join(' ', $res); |
|
| 157 | + echo install_fin_html(); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $res; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -200,53 +200,53 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | function maj_plugin($nom_meta_base_version, $version_cible, $maj, $table_meta = 'meta') { |
| 202 | 202 | |
| 203 | - if ($table_meta !== 'meta') { |
|
| 204 | - installer_table_meta($table_meta); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $current_version = null; |
|
| 208 | - |
|
| 209 | - if ( |
|
| 210 | - (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) |
|
| 211 | - || (!spip_version_compare($current_version = $GLOBALS[$table_meta][$nom_meta_base_version], $version_cible, '=')) |
|
| 212 | - ) { |
|
| 213 | - // $maj['create'] contient les directives propres a la premiere creation de base |
|
| 214 | - // c'est une operation derogatoire qui fait aboutir directement dans la version_cible |
|
| 215 | - if (isset($maj['create'])) { |
|
| 216 | - if (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) { |
|
| 217 | - // installation : on ne fait que l'operation create |
|
| 218 | - $maj = ['init' => $maj['create']]; |
|
| 219 | - // et on lui ajoute un appel a inc/config |
|
| 220 | - // pour creer les metas par defaut |
|
| 221 | - $config = charger_fonction('config', 'inc'); |
|
| 222 | - $maj[$version_cible] = [[$config]]; |
|
| 223 | - } |
|
| 224 | - // dans tous les cas enlever cet index du tableau |
|
| 225 | - unset($maj['create']); |
|
| 226 | - } |
|
| 227 | - // si init, deja dans le bon ordre |
|
| 228 | - if (!isset($maj['init'])) { |
|
| 229 | - include_spip('inc/plugin'); // pour spip_version_compare |
|
| 230 | - uksort($maj, 'spip_version_compare'); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // la redirection se fait par defaut sur la page d'administration des plugins |
|
| 234 | - // sauf lorsque nous sommes sur l'installation de SPIP |
|
| 235 | - // ou define _REDIRECT_MAJ_PLUGIN |
|
| 236 | - $redirect = (defined('_REDIRECT_MAJ_PLUGIN') ? _REDIRECT_MAJ_PLUGIN : generer_url_ecrire('admin_plugin')); |
|
| 237 | - if (defined('_ECRIRE_INSTALL')) { |
|
| 238 | - $redirect = parametre_url(generer_url_ecrire('install'), 'etape', _request('etape')); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $res = maj_while($current_version, $version_cible, $maj, $nom_meta_base_version, $table_meta, $redirect); |
|
| 242 | - if ($res) { |
|
| 243 | - if (!is_array($res)) { |
|
| 244 | - spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_INFO_ERREUR); |
|
| 245 | - } else { |
|
| 246 | - echo '<p>' . _T('avis_operation_echec') . ' ' . join(' ', $res) . '</p>'; |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - } |
|
| 203 | + if ($table_meta !== 'meta') { |
|
| 204 | + installer_table_meta($table_meta); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $current_version = null; |
|
| 208 | + |
|
| 209 | + if ( |
|
| 210 | + (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) |
|
| 211 | + || (!spip_version_compare($current_version = $GLOBALS[$table_meta][$nom_meta_base_version], $version_cible, '=')) |
|
| 212 | + ) { |
|
| 213 | + // $maj['create'] contient les directives propres a la premiere creation de base |
|
| 214 | + // c'est une operation derogatoire qui fait aboutir directement dans la version_cible |
|
| 215 | + if (isset($maj['create'])) { |
|
| 216 | + if (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) { |
|
| 217 | + // installation : on ne fait que l'operation create |
|
| 218 | + $maj = ['init' => $maj['create']]; |
|
| 219 | + // et on lui ajoute un appel a inc/config |
|
| 220 | + // pour creer les metas par defaut |
|
| 221 | + $config = charger_fonction('config', 'inc'); |
|
| 222 | + $maj[$version_cible] = [[$config]]; |
|
| 223 | + } |
|
| 224 | + // dans tous les cas enlever cet index du tableau |
|
| 225 | + unset($maj['create']); |
|
| 226 | + } |
|
| 227 | + // si init, deja dans le bon ordre |
|
| 228 | + if (!isset($maj['init'])) { |
|
| 229 | + include_spip('inc/plugin'); // pour spip_version_compare |
|
| 230 | + uksort($maj, 'spip_version_compare'); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // la redirection se fait par defaut sur la page d'administration des plugins |
|
| 234 | + // sauf lorsque nous sommes sur l'installation de SPIP |
|
| 235 | + // ou define _REDIRECT_MAJ_PLUGIN |
|
| 236 | + $redirect = (defined('_REDIRECT_MAJ_PLUGIN') ? _REDIRECT_MAJ_PLUGIN : generer_url_ecrire('admin_plugin')); |
|
| 237 | + if (defined('_ECRIRE_INSTALL')) { |
|
| 238 | + $redirect = parametre_url(generer_url_ecrire('install'), 'etape', _request('etape')); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $res = maj_while($current_version, $version_cible, $maj, $nom_meta_base_version, $table_meta, $redirect); |
|
| 242 | + if ($res) { |
|
| 243 | + if (!is_array($res)) { |
|
| 244 | + spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_INFO_ERREUR); |
|
| 245 | + } else { |
|
| 246 | + echo '<p>' . _T('avis_operation_echec') . ' ' . join(' ', $res) . '</p>'; |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -263,17 +263,17 @@ discard block |
||
| 263 | 263 | * @return void |
| 264 | 264 | */ |
| 265 | 265 | function relance_maj($meta, $table, $redirect = '') { |
| 266 | - include_spip('inc/headers'); |
|
| 267 | - if (!$redirect) { |
|
| 268 | - // recuperer la valeur installee en cours |
|
| 269 | - // on la tronque numeriquement, elle ne sert pas reellement |
|
| 270 | - // sauf pour verifier que ce n'est pas oui ou non |
|
| 271 | - // sinon is_numeric va echouer sur un numero de version 1.2.3 |
|
| 272 | - $installee = intval($GLOBALS[$table][$meta]); |
|
| 273 | - $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 274 | - } |
|
| 275 | - echo redirige_formulaire($redirect); |
|
| 276 | - exit(); |
|
| 266 | + include_spip('inc/headers'); |
|
| 267 | + if (!$redirect) { |
|
| 268 | + // recuperer la valeur installee en cours |
|
| 269 | + // on la tronque numeriquement, elle ne sert pas reellement |
|
| 270 | + // sauf pour verifier que ce n'est pas oui ou non |
|
| 271 | + // sinon is_numeric va echouer sur un numero de version 1.2.3 |
|
| 272 | + $installee = intval($GLOBALS[$table][$meta]); |
|
| 273 | + $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 274 | + } |
|
| 275 | + echo redirige_formulaire($redirect); |
|
| 276 | + exit(); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -286,26 +286,26 @@ discard block |
||
| 286 | 286 | * @return void |
| 287 | 287 | */ |
| 288 | 288 | function maj_debut_page($installee, $meta, $table) { |
| 289 | - static $done = false; |
|
| 290 | - if ($done) { |
|
| 291 | - return; |
|
| 292 | - } |
|
| 293 | - include_spip('inc/minipres'); |
|
| 294 | - @ini_set('zlib.output_compression', '0'); // pour permettre l'affichage au fur et a mesure |
|
| 295 | - $timeout = _UPGRADE_TIME_OUT * 2; |
|
| 296 | - $titre = _T('titre_page_upgrade'); |
|
| 297 | - $balise_img = charger_filtre('balise_img'); |
|
| 298 | - $titre .= $balise_img(chemin_image('loader.svg'), '', 'loader'); |
|
| 299 | - echo(install_debut_html($titre)); |
|
| 300 | - // script de rechargement auto sur timeout |
|
| 301 | - $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 302 | - echo http_script("window.setTimeout('location.href=\"" . $redirect . "\";'," . ($timeout * 1000) . ')'); |
|
| 303 | - echo "<div style='text-align: left'>\n"; |
|
| 304 | - if (ob_get_level()) { |
|
| 305 | - ob_flush(); |
|
| 306 | - } |
|
| 307 | - flush(); |
|
| 308 | - $done = true; |
|
| 289 | + static $done = false; |
|
| 290 | + if ($done) { |
|
| 291 | + return; |
|
| 292 | + } |
|
| 293 | + include_spip('inc/minipres'); |
|
| 294 | + @ini_set('zlib.output_compression', '0'); // pour permettre l'affichage au fur et a mesure |
|
| 295 | + $timeout = _UPGRADE_TIME_OUT * 2; |
|
| 296 | + $titre = _T('titre_page_upgrade'); |
|
| 297 | + $balise_img = charger_filtre('balise_img'); |
|
| 298 | + $titre .= $balise_img(chemin_image('loader.svg'), '', 'loader'); |
|
| 299 | + echo(install_debut_html($titre)); |
|
| 300 | + // script de rechargement auto sur timeout |
|
| 301 | + $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 302 | + echo http_script("window.setTimeout('location.href=\"" . $redirect . "\";'," . ($timeout * 1000) . ')'); |
|
| 303 | + echo "<div style='text-align: left'>\n"; |
|
| 304 | + if (ob_get_level()) { |
|
| 305 | + ob_flush(); |
|
| 306 | + } |
|
| 307 | + flush(); |
|
| 308 | + $done = true; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -349,64 +349,64 @@ discard block |
||
| 349 | 349 | * - tableau vide sinon. |
| 350 | 350 | */ |
| 351 | 351 | function maj_while($installee, $cible, $maj, $meta = '', $table = 'meta', $redirect = '', $debut_page = false) { |
| 352 | - # inclusions pour que les procedures d'upgrade disposent des fonctions de base |
|
| 353 | - include_spip('base/create'); |
|
| 354 | - include_spip('base/abstract_sql'); |
|
| 355 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 356 | - include_spip('inc/plugin'); // pour spip_version_compare |
|
| 357 | - $n = 0; |
|
| 358 | - $time = time(); |
|
| 359 | - |
|
| 360 | - if (!defined('_TIME_OUT')) { |
|
| 361 | - /** |
|
| 362 | - * Définir le timeout qui peut-être utilisé dans les fonctions |
|
| 363 | - * de mises à jour qui durent trop longtemps |
|
| 364 | - * |
|
| 365 | - * À utiliser tel que : `if (time() >= _TIME_OUT)` |
|
| 366 | - * |
|
| 367 | - * @var int |
|
| 368 | - */ |
|
| 369 | - define('_TIME_OUT', $time + _UPGRADE_TIME_OUT); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - foreach ($maj as $v => $operations) { |
|
| 373 | - // si une maj pour cette version |
|
| 374 | - if ( |
|
| 375 | - $v == 'init' or |
|
| 376 | - (spip_version_compare($v, $installee, '>') |
|
| 377 | - and spip_version_compare($v, $cible, '<=')) |
|
| 378 | - ) { |
|
| 379 | - if ($debut_page) { |
|
| 380 | - maj_debut_page($v, $meta, $table); |
|
| 381 | - } |
|
| 382 | - echo "MAJ $v"; |
|
| 383 | - $etape = serie_alter($v, $operations, $meta, $table, $redirect); |
|
| 384 | - $trouver_table(''); // vider le cache des descriptions de table |
|
| 385 | - # echec sur une etape en cours ? |
|
| 386 | - # on sort |
|
| 387 | - if ($etape) { |
|
| 388 | - return [$v, $etape]; |
|
| 389 | - } |
|
| 390 | - $n = time() - $time; |
|
| 391 | - spip_log("$table $meta: $v en $n secondes", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 392 | - if ($meta) { |
|
| 393 | - ecrire_meta($meta, $installee = $v, 'oui', $table); |
|
| 394 | - } |
|
| 395 | - echo (_IS_CLI ? "\n" : '<br />'); |
|
| 396 | - } |
|
| 397 | - if (time() >= _TIME_OUT) { |
|
| 398 | - relance_maj($meta, $table, $redirect); |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - $trouver_table(''); // vider le cache des descriptions de table |
|
| 402 | - // indispensable pour les chgt de versions qui n'ecrivent pas en base |
|
| 403 | - // tant pis pour la redondance eventuelle avec ci-dessus |
|
| 404 | - if ($meta) { |
|
| 405 | - ecrire_meta($meta, $cible, 'oui', $table); |
|
| 406 | - } |
|
| 407 | - spip_log("MAJ terminee. $meta: $installee", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 408 | - |
|
| 409 | - return []; |
|
| 352 | + # inclusions pour que les procedures d'upgrade disposent des fonctions de base |
|
| 353 | + include_spip('base/create'); |
|
| 354 | + include_spip('base/abstract_sql'); |
|
| 355 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 356 | + include_spip('inc/plugin'); // pour spip_version_compare |
|
| 357 | + $n = 0; |
|
| 358 | + $time = time(); |
|
| 359 | + |
|
| 360 | + if (!defined('_TIME_OUT')) { |
|
| 361 | + /** |
|
| 362 | + * Définir le timeout qui peut-être utilisé dans les fonctions |
|
| 363 | + * de mises à jour qui durent trop longtemps |
|
| 364 | + * |
|
| 365 | + * À utiliser tel que : `if (time() >= _TIME_OUT)` |
|
| 366 | + * |
|
| 367 | + * @var int |
|
| 368 | + */ |
|
| 369 | + define('_TIME_OUT', $time + _UPGRADE_TIME_OUT); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + foreach ($maj as $v => $operations) { |
|
| 373 | + // si une maj pour cette version |
|
| 374 | + if ( |
|
| 375 | + $v == 'init' or |
|
| 376 | + (spip_version_compare($v, $installee, '>') |
|
| 377 | + and spip_version_compare($v, $cible, '<=')) |
|
| 378 | + ) { |
|
| 379 | + if ($debut_page) { |
|
| 380 | + maj_debut_page($v, $meta, $table); |
|
| 381 | + } |
|
| 382 | + echo "MAJ $v"; |
|
| 383 | + $etape = serie_alter($v, $operations, $meta, $table, $redirect); |
|
| 384 | + $trouver_table(''); // vider le cache des descriptions de table |
|
| 385 | + # echec sur une etape en cours ? |
|
| 386 | + # on sort |
|
| 387 | + if ($etape) { |
|
| 388 | + return [$v, $etape]; |
|
| 389 | + } |
|
| 390 | + $n = time() - $time; |
|
| 391 | + spip_log("$table $meta: $v en $n secondes", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 392 | + if ($meta) { |
|
| 393 | + ecrire_meta($meta, $installee = $v, 'oui', $table); |
|
| 394 | + } |
|
| 395 | + echo (_IS_CLI ? "\n" : '<br />'); |
|
| 396 | + } |
|
| 397 | + if (time() >= _TIME_OUT) { |
|
| 398 | + relance_maj($meta, $table, $redirect); |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + $trouver_table(''); // vider le cache des descriptions de table |
|
| 402 | + // indispensable pour les chgt de versions qui n'ecrivent pas en base |
|
| 403 | + // tant pis pour la redondance eventuelle avec ci-dessus |
|
| 404 | + if ($meta) { |
|
| 405 | + ecrire_meta($meta, $cible, 'oui', $table); |
|
| 406 | + } |
|
| 407 | + spip_log("MAJ terminee. $meta: $installee", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 408 | + |
|
| 409 | + return []; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -429,53 +429,53 @@ discard block |
||
| 429 | 429 | * @return int |
| 430 | 430 | */ |
| 431 | 431 | function serie_alter($serie, $q = [], $meta = '', $table = 'meta', $redirect = '') { |
| 432 | - $meta2 = $meta . '_maj_' . $serie; |
|
| 433 | - $etape = 0; |
|
| 434 | - if (isset($GLOBALS[$table][$meta2])) { |
|
| 435 | - $etape = intval($GLOBALS[$table][$meta2]); |
|
| 436 | - } |
|
| 437 | - foreach ($q as $i => $r) { |
|
| 438 | - if ($i >= $etape) { |
|
| 439 | - $msg = "maj $table $meta2 etape $i"; |
|
| 440 | - if ( |
|
| 441 | - is_array($r) |
|
| 442 | - and function_exists($f = array_shift($r)) |
|
| 443 | - ) { |
|
| 444 | - // note: $r (arguments de la fonction $f) peut avoir des données tabulaires |
|
| 445 | - spip_log("$msg: $f " . @join(',', $r), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 446 | - // pour les fonctions atomiques sql_xx |
|
| 447 | - // on enregistre le meta avant de lancer la fonction, |
|
| 448 | - // de maniere a eviter de boucler sur timeout |
|
| 449 | - // mais pour les fonctions complexes, |
|
| 450 | - // il faut les rejouer jusqu'a achevement. |
|
| 451 | - // C'est a elle d'assurer qu'elles progressent a chaque rappel |
|
| 452 | - if (strncmp($f, 'sql_', 4) == 0) { |
|
| 453 | - ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 454 | - } |
|
| 455 | - echo (_IS_CLI ? '.' : " <span title='$i'>.</span>"); |
|
| 456 | - call_user_func_array($f, $r); |
|
| 457 | - // si temps imparti depasse, on relance sans ecrire en meta |
|
| 458 | - // car on est peut etre sorti sur timeout si c'est une fonction longue |
|
| 459 | - if (time() >= _TIME_OUT) { |
|
| 460 | - relance_maj($meta, $table, $redirect); |
|
| 461 | - } |
|
| 462 | - ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 463 | - spip_log("$meta2: ok", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 464 | - } else { |
|
| 465 | - if (!is_array($r)) { |
|
| 466 | - spip_log("maj $i format incorrect", 'maj.' . _LOG_ERREUR); |
|
| 467 | - } else { |
|
| 468 | - spip_log("maj $i fonction $f non definie", 'maj.' . _LOG_ERREUR); |
|
| 469 | - } |
|
| 470 | - // en cas d'erreur serieuse, on s'arrete |
|
| 471 | - // mais on permet de passer par dessus en rechargeant la page. |
|
| 472 | - return $i + 1; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - effacer_meta($meta2, $table); |
|
| 477 | - |
|
| 478 | - return 0; |
|
| 432 | + $meta2 = $meta . '_maj_' . $serie; |
|
| 433 | + $etape = 0; |
|
| 434 | + if (isset($GLOBALS[$table][$meta2])) { |
|
| 435 | + $etape = intval($GLOBALS[$table][$meta2]); |
|
| 436 | + } |
|
| 437 | + foreach ($q as $i => $r) { |
|
| 438 | + if ($i >= $etape) { |
|
| 439 | + $msg = "maj $table $meta2 etape $i"; |
|
| 440 | + if ( |
|
| 441 | + is_array($r) |
|
| 442 | + and function_exists($f = array_shift($r)) |
|
| 443 | + ) { |
|
| 444 | + // note: $r (arguments de la fonction $f) peut avoir des données tabulaires |
|
| 445 | + spip_log("$msg: $f " . @join(',', $r), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 446 | + // pour les fonctions atomiques sql_xx |
|
| 447 | + // on enregistre le meta avant de lancer la fonction, |
|
| 448 | + // de maniere a eviter de boucler sur timeout |
|
| 449 | + // mais pour les fonctions complexes, |
|
| 450 | + // il faut les rejouer jusqu'a achevement. |
|
| 451 | + // C'est a elle d'assurer qu'elles progressent a chaque rappel |
|
| 452 | + if (strncmp($f, 'sql_', 4) == 0) { |
|
| 453 | + ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 454 | + } |
|
| 455 | + echo (_IS_CLI ? '.' : " <span title='$i'>.</span>"); |
|
| 456 | + call_user_func_array($f, $r); |
|
| 457 | + // si temps imparti depasse, on relance sans ecrire en meta |
|
| 458 | + // car on est peut etre sorti sur timeout si c'est une fonction longue |
|
| 459 | + if (time() >= _TIME_OUT) { |
|
| 460 | + relance_maj($meta, $table, $redirect); |
|
| 461 | + } |
|
| 462 | + ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 463 | + spip_log("$meta2: ok", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 464 | + } else { |
|
| 465 | + if (!is_array($r)) { |
|
| 466 | + spip_log("maj $i format incorrect", 'maj.' . _LOG_ERREUR); |
|
| 467 | + } else { |
|
| 468 | + spip_log("maj $i fonction $f non definie", 'maj.' . _LOG_ERREUR); |
|
| 469 | + } |
|
| 470 | + // en cas d'erreur serieuse, on s'arrete |
|
| 471 | + // mais on permet de passer par dessus en rechargeant la page. |
|
| 472 | + return $i + 1; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + effacer_meta($meta2, $table); |
|
| 477 | + |
|
| 478 | + return 0; |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | /** |
@@ -484,16 +484,16 @@ discard block |
||
| 484 | 484 | * @return bool True si possible. |
| 485 | 485 | **/ |
| 486 | 486 | function upgrade_test() { |
| 487 | - sql_drop_table('spip_test', true); |
|
| 488 | - sql_create('spip_test', ['a' => 'int']); |
|
| 489 | - sql_alter('TABLE spip_test ADD b INT'); |
|
| 490 | - sql_insertq('spip_test', ['b' => 1], ['field' => ['b' => 'int']]); |
|
| 491 | - $result = sql_select('b', 'spip_test'); |
|
| 492 | - // ne pas garder le resultat de la requete sinon sqlite3 |
|
| 493 | - // ne peut pas supprimer la table spip_test lors du sql_alter qui suit |
|
| 494 | - // car cette table serait alors 'verouillee' |
|
| 495 | - $result = $result ? true : false; |
|
| 496 | - sql_alter('TABLE spip_test DROP b'); |
|
| 497 | - |
|
| 498 | - return $result; |
|
| 487 | + sql_drop_table('spip_test', true); |
|
| 488 | + sql_create('spip_test', ['a' => 'int']); |
|
| 489 | + sql_alter('TABLE spip_test ADD b INT'); |
|
| 490 | + sql_insertq('spip_test', ['b' => 1], ['field' => ['b' => 'int']]); |
|
| 491 | + $result = sql_select('b', 'spip_test'); |
|
| 492 | + // ne pas garder le resultat de la requete sinon sqlite3 |
|
| 493 | + // ne peut pas supprimer la table spip_test lors du sql_alter qui suit |
|
| 494 | + // car cette table serait alors 'verouillee' |
|
| 495 | + $result = $result ? true : false; |
|
| 496 | + sql_alter('TABLE spip_test DROP b'); |
|
| 497 | + |
|
| 498 | + return $result; |
|
| 499 | 499 | } |
@@ -19,14 +19,14 @@ discard block |
||
| 19 | 19 | /** Drapeau indiquant que l'on est dans l'espace privé */ |
| 20 | 20 | define('_ESPACE_PRIVE', true); |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - include 'inc_version.php'; |
|
| 22 | + include 'inc_version.php'; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // Verification anti magic_quotes_sybase, pour qui addslashes("'") = "''" |
| 26 | 26 | // On prefere la faire ici plutot que dans inc_version, c'est moins souvent et |
| 27 | 27 | // si le reglage est modifie sur un site en prod, ca fait moins mal |
| 28 | 28 | if (addslashes("'") !== "\\'") { |
| 29 | - die('SPIP incompatible magic_quotes_sybase'); |
|
| 29 | + die('SPIP incompatible magic_quotes_sybase'); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | include_spip('inc/cookie'); |
@@ -42,18 +42,18 @@ discard block |
||
| 42 | 42 | // alors il faut blinder les variables d'URL |
| 43 | 43 | // |
| 44 | 44 | if (autoriser_sans_cookie($exec, false)) { |
| 45 | - if (!isset($reinstall)) { |
|
| 46 | - $reinstall = 'non'; |
|
| 47 | - } |
|
| 48 | - $var_auth = true; |
|
| 45 | + if (!isset($reinstall)) { |
|
| 46 | + $reinstall = 'non'; |
|
| 47 | + } |
|
| 48 | + $var_auth = true; |
|
| 49 | 49 | } else { |
| 50 | - // Authentification, redefinissable |
|
| 51 | - $auth = charger_fonction('auth', 'inc'); |
|
| 52 | - $var_auth = $auth(); |
|
| 53 | - if ($var_auth) { |
|
| 54 | - echo auth_echec($var_auth); |
|
| 55 | - exit; |
|
| 56 | - } |
|
| 50 | + // Authentification, redefinissable |
|
| 51 | + $auth = charger_fonction('auth', 'inc'); |
|
| 52 | + $var_auth = $auth(); |
|
| 53 | + if ($var_auth) { |
|
| 54 | + echo auth_echec($var_auth); |
|
| 55 | + exit; |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // initialiser a la langue par defaut |
@@ -64,29 +64,29 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | if (_request('action') or _request('var_ajax') or _request('formulaire_action')) { |
| 67 | - if (!autoriser_sans_cookie($exec)) { |
|
| 68 | - // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires |
|
| 69 | - include_spip('public/aiguiller'); |
|
| 70 | - if ( |
|
| 71 | - // cas des appels actions ?action=xxx |
|
| 72 | - traiter_appels_actions() |
|
| 73 | - or |
|
| 74 | - // cas des hits ajax sur les inclusions ajax |
|
| 75 | - traiter_appels_inclusions_ajax() |
|
| 76 | - or |
|
| 77 | - // cas des formulaires charger/verifier/traiter |
|
| 78 | - traiter_formulaires_dynamiques() |
|
| 79 | - ) { |
|
| 80 | - exit; |
|
| 81 | - } // le hit est fini ! |
|
| 82 | - } |
|
| 67 | + if (!autoriser_sans_cookie($exec)) { |
|
| 68 | + // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires |
|
| 69 | + include_spip('public/aiguiller'); |
|
| 70 | + if ( |
|
| 71 | + // cas des appels actions ?action=xxx |
|
| 72 | + traiter_appels_actions() |
|
| 73 | + or |
|
| 74 | + // cas des hits ajax sur les inclusions ajax |
|
| 75 | + traiter_appels_inclusions_ajax() |
|
| 76 | + or |
|
| 77 | + // cas des formulaires charger/verifier/traiter |
|
| 78 | + traiter_formulaires_dynamiques() |
|
| 79 | + ) { |
|
| 80 | + exit; |
|
| 81 | + } // le hit est fini ! |
|
| 82 | + } |
|
| 83 | 83 | } |
| 84 | 84 | // securiser les redirect du back-office |
| 85 | 85 | if (_request('redirect')) { |
| 86 | - if (!function_exists('securiser_redirect_action')) { |
|
| 87 | - include_spip('public/aiguiller'); |
|
| 88 | - } |
|
| 89 | - set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 86 | + if (!function_exists('securiser_redirect_action')) { |
|
| 87 | + include_spip('public/aiguiller'); |
|
| 88 | + } |
|
| 89 | + set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
@@ -96,12 +96,12 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | // Controle de la version, sauf si on est deja en train de s'en occuper |
| 98 | 98 | if ( |
| 99 | - !$reinstall == 'oui' |
|
| 100 | - and !_AJAX |
|
| 101 | - and isset($GLOBALS['meta']['version_installee']) |
|
| 102 | - and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 99 | + !$reinstall == 'oui' |
|
| 100 | + and !_AJAX |
|
| 101 | + and isset($GLOBALS['meta']['version_installee']) |
|
| 102 | + and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 103 | 103 | ) { |
| 104 | - $exec = 'demande_mise_a_jour'; |
|
| 104 | + $exec = 'demande_mise_a_jour'; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // Quand une action d'administration est en cours (meta "admin"), |
@@ -111,39 +111,39 @@ discard block |
||
| 111 | 111 | // sinon c'est qu'elle a ete interrompue et il faut la reprendre |
| 112 | 112 | |
| 113 | 113 | elseif (isset($GLOBALS['meta']['admin'])) { |
| 114 | - if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)) { |
|
| 115 | - [, $var_f, $n] = $l; |
|
| 116 | - } |
|
| 117 | - if ( |
|
| 118 | - _AJAX |
|
| 119 | - or !( |
|
| 120 | - isset($_COOKIE['spip_admin']) |
|
| 121 | - or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
|
| 122 | - ) |
|
| 123 | - ) { |
|
| 124 | - spip_log('Quand la meta admin vaut ' . |
|
| 125 | - $GLOBALS['meta']['admin'] . |
|
| 126 | - ' seul un admin peut se connecter et sans AJAX.' . |
|
| 127 | - ' En cas de probleme, detruire cette meta.'); |
|
| 128 | - die(_T('info_travaux_texte')); |
|
| 129 | - } |
|
| 130 | - if ($n) { |
|
| 131 | - [, $var_f, $n] = $l; |
|
| 132 | - if (tester_url_ecrire("base_$var_f")) { |
|
| 133 | - $var_f = "base_$var_f"; |
|
| 134 | - } |
|
| 135 | - if ($var_f != $exec) { |
|
| 136 | - spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec"); |
|
| 137 | - $exec = $var_f; |
|
| 138 | - set_request('exec', $exec); |
|
| 139 | - } |
|
| 140 | - } |
|
| 114 | + if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)) { |
|
| 115 | + [, $var_f, $n] = $l; |
|
| 116 | + } |
|
| 117 | + if ( |
|
| 118 | + _AJAX |
|
| 119 | + or !( |
|
| 120 | + isset($_COOKIE['spip_admin']) |
|
| 121 | + or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
|
| 122 | + ) |
|
| 123 | + ) { |
|
| 124 | + spip_log('Quand la meta admin vaut ' . |
|
| 125 | + $GLOBALS['meta']['admin'] . |
|
| 126 | + ' seul un admin peut se connecter et sans AJAX.' . |
|
| 127 | + ' En cas de probleme, detruire cette meta.'); |
|
| 128 | + die(_T('info_travaux_texte')); |
|
| 129 | + } |
|
| 130 | + if ($n) { |
|
| 131 | + [, $var_f, $n] = $l; |
|
| 132 | + if (tester_url_ecrire("base_$var_f")) { |
|
| 133 | + $var_f = "base_$var_f"; |
|
| 134 | + } |
|
| 135 | + if ($var_f != $exec) { |
|
| 136 | + spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec"); |
|
| 137 | + $exec = $var_f; |
|
| 138 | + set_request('exec', $exec); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | // si nom pas plausible, prendre le script par defaut |
| 143 | 143 | // attention aux deux cas 404/403 qui commencent par un 4 ! |
| 144 | 144 | elseif (!preg_match(',^[a-z4_][0-9a-z_-]*$,i', $exec)) { |
| 145 | - $exec = 'accueil'; |
|
| 146 | - set_request('exec', $exec); |
|
| 145 | + $exec = 'accueil'; |
|
| 146 | + set_request('exec', $exec); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // compatibilite ascendante : obsolete, ne plus utiliser |
@@ -155,19 +155,19 @@ discard block |
||
| 155 | 155 | // on appelle directement la fonction, car un appel d'action peut conduire a une boucle infinie |
| 156 | 156 | // si le cookie n'est pas pose correctement dans l'action |
| 157 | 157 | if ( |
| 158 | - !$var_auth and isset($_COOKIE['spip_lang_ecrire']) |
|
| 159 | - and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang'] |
|
| 158 | + !$var_auth and isset($_COOKIE['spip_lang_ecrire']) |
|
| 159 | + and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang'] |
|
| 160 | 160 | ) { |
| 161 | - include_spip('action/converser'); |
|
| 162 | - action_converser_post($GLOBALS['visiteur_session']['lang'], true); |
|
| 161 | + include_spip('action/converser'); |
|
| 162 | + action_converser_post($GLOBALS['visiteur_session']['lang'], true); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | if ($var_f = tester_url_ecrire($exec)) { |
| 166 | - $var_f = charger_fonction($var_f); |
|
| 167 | - $var_f(); // at last |
|
| 166 | + $var_f = charger_fonction($var_f); |
|
| 167 | + $var_f(); // at last |
|
| 168 | 168 | } else { |
| 169 | - // Rien de connu: rerouter vers exec=404 au lieu d'echouer |
|
| 170 | - // ce qui permet de laisser la main a un plugin |
|
| 171 | - $var_f = charger_fonction('404'); |
|
| 172 | - $var_f($exec); |
|
| 169 | + // Rien de connu: rerouter vers exec=404 au lieu d'echouer |
|
| 170 | + // ce qui permet de laisser la main a un plugin |
|
| 171 | + $var_f = charger_fonction('404'); |
|
| 172 | + $var_f($exec); |
|
| 173 | 173 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -35,45 +35,45 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | */ |
| 37 | 37 | function install_etape_1_dist() { |
| 38 | - echo install_debut_html(); |
|
| 38 | + echo install_debut_html(); |
|
| 39 | 39 | |
| 40 | - // stopper en cas de grosse incompatibilite de l'hebergement |
|
| 41 | - tester_compatibilite_hebergement(); |
|
| 40 | + // stopper en cas de grosse incompatibilite de l'hebergement |
|
| 41 | + tester_compatibilite_hebergement(); |
|
| 42 | 42 | |
| 43 | - // Recuperer les anciennes donnees pour plus de facilite (si presentes) |
|
| 44 | - $s = !@is_readable(_FILE_CONNECT_TMP) ? '' |
|
| 45 | - : analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 43 | + // Recuperer les anciennes donnees pour plus de facilite (si presentes) |
|
| 44 | + $s = !@is_readable(_FILE_CONNECT_TMP) ? '' |
|
| 45 | + : analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 46 | 46 | |
| 47 | - [$adresse_db, $login_db] = $s ?: login_hebergeur(); |
|
| 47 | + [$adresse_db, $login_db] = $s ?: login_hebergeur(); |
|
| 48 | 48 | |
| 49 | - $chmod = (isset($_GET['chmod']) and preg_match(',^[0-9]+$,', $_GET['chmod'])) ? |
|
| 50 | - sprintf('%04o', $_GET['chmod']) : '0777'; |
|
| 49 | + $chmod = (isset($_GET['chmod']) and preg_match(',^[0-9]+$,', $_GET['chmod'])) ? |
|
| 50 | + sprintf('%04o', $_GET['chmod']) : '0777'; |
|
| 51 | 51 | |
| 52 | - if (@is_readable(_FILE_CHMOD_TMP)) { |
|
| 53 | - $s = @join('', @file(_FILE_CHMOD_TMP)); |
|
| 54 | - if (preg_match("#define\('_SPIP_CHMOD', (.*)\)#", $s, $regs)) { |
|
| 55 | - $chmod = $regs[1]; |
|
| 56 | - } |
|
| 57 | - } |
|
| 52 | + if (@is_readable(_FILE_CHMOD_TMP)) { |
|
| 53 | + $s = @join('', @file(_FILE_CHMOD_TMP)); |
|
| 54 | + if (preg_match("#define\('_SPIP_CHMOD', (.*)\)#", $s, $regs)) { |
|
| 55 | + $chmod = $regs[1]; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - $db = [$adresse_db, _T('entree_base_donnee_2')]; |
|
| 61 | - $login = [$login_db, _T('entree_login_connexion_2')]; |
|
| 62 | - $pass = ['', _T('entree_mot_passe_2')]; |
|
| 60 | + $db = [$adresse_db, _T('entree_base_donnee_2')]; |
|
| 61 | + $login = [$login_db, _T('entree_login_connexion_2')]; |
|
| 62 | + $pass = ['', _T('entree_mot_passe_2')]; |
|
| 63 | 63 | |
| 64 | - $predef = [ |
|
| 65 | - defined('_INSTALL_SERVER_DB') ? _INSTALL_SERVER_DB : '', |
|
| 66 | - defined('_INSTALL_HOST_DB'), |
|
| 67 | - defined('_INSTALL_USER_DB'), |
|
| 68 | - defined('_INSTALL_PASS_DB') |
|
| 69 | - ]; |
|
| 64 | + $predef = [ |
|
| 65 | + defined('_INSTALL_SERVER_DB') ? _INSTALL_SERVER_DB : '', |
|
| 66 | + defined('_INSTALL_HOST_DB'), |
|
| 67 | + defined('_INSTALL_USER_DB'), |
|
| 68 | + defined('_INSTALL_PASS_DB') |
|
| 69 | + ]; |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - echo info_progression_etape(1, 'etape_', 'install/'); |
|
| 72 | + echo info_progression_etape(1, 'etape_', 'install/'); |
|
| 73 | 73 | |
| 74 | - // ces deux chaines de langues doivent etre reecrites |
|
| 74 | + // ces deux chaines de langues doivent etre reecrites |
|
| 75 | 75 | # echo info_etape(_T('info_connexion_mysql'), _T('texte_connexion_mysql').aide ("install1", true)); |
| 76 | - echo info_etape(_T('info_connexion_base_donnee')); |
|
| 77 | - echo install_connexion_form($db, $login, $pass, $predef, "\n<input type='hidden' name='chmod' value='$chmod' />", 2); |
|
| 78 | - echo install_fin_html(); |
|
| 76 | + echo info_etape(_T('info_connexion_base_donnee')); |
|
| 77 | + echo install_connexion_form($db, $login, $pass, $predef, "\n<input type='hidden' name='chmod' value='$chmod' />", 2); |
|
| 78 | + echo install_fin_html(); |
|
| 79 | 79 | } |
@@ -11,147 +11,147 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/headers'); |
| 18 | 18 | |
| 19 | 19 | function install_etape_3b_dist() { |
| 20 | - $auth_spip = null; |
|
| 21 | - $session = null; |
|
| 22 | - $row = null; |
|
| 23 | - $login = _request('login'); |
|
| 24 | - $email = _request('email'); |
|
| 25 | - $nom = _request('nom'); |
|
| 26 | - $pass = _request('pass'); |
|
| 27 | - $pass_verif = _request('pass_verif'); |
|
| 28 | - |
|
| 29 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 30 | - ? _INSTALL_SERVER_DB |
|
| 31 | - : _request('server_db'); |
|
| 32 | - |
|
| 33 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 34 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 35 | - } |
|
| 36 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 37 | - define('_LOGIN_TROP_COURT', 4); |
|
| 38 | - } |
|
| 39 | - if ($login) { |
|
| 40 | - $echec = ($pass != $pass_verif) ? |
|
| 41 | - _T('info_passes_identiques') |
|
| 42 | - : ((strlen($pass) < _PASS_LONGUEUR_MINI) ? |
|
| 43 | - _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]) |
|
| 44 | - : ((strlen($login) < _LOGIN_TROP_COURT) ? |
|
| 45 | - _T('info_login_trop_court') |
|
| 46 | - : '')); |
|
| 47 | - include_spip('inc/filtres'); |
|
| 48 | - if (!$echec and $email and !email_valide($email)) { |
|
| 49 | - $echec = _T('form_email_non_valide'); |
|
| 50 | - } |
|
| 51 | - if ($echec) { |
|
| 52 | - echo minipres( |
|
| 53 | - 'AUTO', |
|
| 54 | - info_progression_etape(3, 'etape_', 'install/', true) . |
|
| 55 | - "<div class='error'><h3>$echec</h3>\n" . |
|
| 56 | - '<p>' . _T('avis_connexion_echec_2') . '</p>' . |
|
| 57 | - '</div>' |
|
| 58 | - ); |
|
| 59 | - exit; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - if (@file_exists(_FILE_CHMOD_TMP)) { |
|
| 64 | - include(_FILE_CHMOD_TMP); |
|
| 65 | - } else { |
|
| 66 | - redirige_url_ecrire('install'); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if (!@file_exists(_FILE_CONNECT_TMP)) { |
|
| 70 | - redirige_url_ecrire('install'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - # maintenant on connait le vrai charset du site s'il est deja configure |
|
| 74 | - # sinon par defaut lire_meta reglera _DEFAULT_CHARSET |
|
| 75 | - # (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET) |
|
| 76 | - |
|
| 77 | - lire_metas(); |
|
| 78 | - if ($login) { |
|
| 79 | - include_spip('inc/charsets'); |
|
| 80 | - |
|
| 81 | - $nom = (importer_charset($nom, _DEFAULT_CHARSET)); |
|
| 82 | - $login = (importer_charset($login, _DEFAULT_CHARSET)); |
|
| 83 | - $email = (importer_charset($email, _DEFAULT_CHARSET)); |
|
| 84 | - # pour le passwd, bizarrement il faut le convertir comme s'il avait |
|
| 85 | - # ete tape en iso-8859-1 ; car c'est en fait ce que voit md5.js |
|
| 86 | - $pass = unicode2charset(utf_8_to_unicode($pass), 'iso-8859-1'); |
|
| 87 | - include_spip('auth/sha256.inc'); |
|
| 88 | - include_spip('inc/acces'); |
|
| 89 | - $htpass = generer_htpass($pass); |
|
| 90 | - $alea_actuel = creer_uniqid(); |
|
| 91 | - $alea_futur = creer_uniqid(); |
|
| 92 | - $shapass = spip_sha256($alea_actuel . $pass); |
|
| 93 | - // prelablement, creer le champ webmestre si il n'existe pas (install neuve |
|
| 94 | - // sur une vieille base |
|
| 95 | - $t = sql_showtable('spip_auteurs', true); |
|
| 96 | - if (!isset($t['field']['webmestre'])) { |
|
| 97 | - @sql_alter("TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login)); |
|
| 101 | - if ($id_auteur !== null) { |
|
| 102 | - sql_updateq('spip_auteurs', [ |
|
| 103 | - 'nom' => $nom, |
|
| 104 | - 'email' => $email, |
|
| 105 | - 'login' => $login, |
|
| 106 | - 'pass' => $shapass, |
|
| 107 | - 'alea_actuel' => $alea_actuel, |
|
| 108 | - 'alea_futur' => $alea_futur, |
|
| 109 | - 'htpass' => $htpass, |
|
| 110 | - 'statut' => '0minirezo' |
|
| 111 | - ], "id_auteur=$id_auteur"); |
|
| 112 | - } else { |
|
| 113 | - $id_auteur = sql_insertq('spip_auteurs', [ |
|
| 114 | - 'nom' => $nom, |
|
| 115 | - 'email' => $email, |
|
| 116 | - 'login' => $login, |
|
| 117 | - 'pass' => $shapass, |
|
| 118 | - 'htpass' => $htpass, |
|
| 119 | - 'alea_actuel' => $alea_actuel, |
|
| 120 | - 'alea_futur' => $alea_futur, |
|
| 121 | - 'statut' => '0minirezo' |
|
| 122 | - ]); |
|
| 123 | - } |
|
| 124 | - // le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 125 | - @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
|
| 126 | - |
|
| 127 | - // inserer email comme email webmaster principal |
|
| 128 | - // (sauf s'il est vide: cas de la re-installation) |
|
| 129 | - if ($email) { |
|
| 130 | - ecrire_meta('email_webmaster', $email); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // Connecter directement celui qui vient de (re)donner son login |
|
| 134 | - // mais sans cookie d'admin ni connexion longue |
|
| 135 | - include_spip('inc/auth'); |
|
| 136 | - if ( |
|
| 137 | - !$auteur = auth_identifier_login($login, $pass) |
|
| 138 | - or !auth_loger($auteur) |
|
| 139 | - ) { |
|
| 140 | - spip_log("login automatique impossible $auth_spip $session" . (is_countable($row) ? count($row) : 0)); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // installer les metas |
|
| 145 | - $config = charger_fonction('config', 'inc'); |
|
| 146 | - $config(); |
|
| 147 | - |
|
| 148 | - // activer les plugins |
|
| 149 | - // leur installation ne peut pas se faire sur le meme hit, il faudra donc |
|
| 150 | - // poursuivre au hit suivant |
|
| 151 | - include_spip('inc/plugin'); |
|
| 152 | - actualise_plugins_actifs(); |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - include_spip('inc/distant'); |
|
| 156 | - redirige_par_entete(parametre_url(self(), 'etape', '4', '&')); |
|
| 20 | + $auth_spip = null; |
|
| 21 | + $session = null; |
|
| 22 | + $row = null; |
|
| 23 | + $login = _request('login'); |
|
| 24 | + $email = _request('email'); |
|
| 25 | + $nom = _request('nom'); |
|
| 26 | + $pass = _request('pass'); |
|
| 27 | + $pass_verif = _request('pass_verif'); |
|
| 28 | + |
|
| 29 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 30 | + ? _INSTALL_SERVER_DB |
|
| 31 | + : _request('server_db'); |
|
| 32 | + |
|
| 33 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 34 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 35 | + } |
|
| 36 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 37 | + define('_LOGIN_TROP_COURT', 4); |
|
| 38 | + } |
|
| 39 | + if ($login) { |
|
| 40 | + $echec = ($pass != $pass_verif) ? |
|
| 41 | + _T('info_passes_identiques') |
|
| 42 | + : ((strlen($pass) < _PASS_LONGUEUR_MINI) ? |
|
| 43 | + _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]) |
|
| 44 | + : ((strlen($login) < _LOGIN_TROP_COURT) ? |
|
| 45 | + _T('info_login_trop_court') |
|
| 46 | + : '')); |
|
| 47 | + include_spip('inc/filtres'); |
|
| 48 | + if (!$echec and $email and !email_valide($email)) { |
|
| 49 | + $echec = _T('form_email_non_valide'); |
|
| 50 | + } |
|
| 51 | + if ($echec) { |
|
| 52 | + echo minipres( |
|
| 53 | + 'AUTO', |
|
| 54 | + info_progression_etape(3, 'etape_', 'install/', true) . |
|
| 55 | + "<div class='error'><h3>$echec</h3>\n" . |
|
| 56 | + '<p>' . _T('avis_connexion_echec_2') . '</p>' . |
|
| 57 | + '</div>' |
|
| 58 | + ); |
|
| 59 | + exit; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + if (@file_exists(_FILE_CHMOD_TMP)) { |
|
| 64 | + include(_FILE_CHMOD_TMP); |
|
| 65 | + } else { |
|
| 66 | + redirige_url_ecrire('install'); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if (!@file_exists(_FILE_CONNECT_TMP)) { |
|
| 70 | + redirige_url_ecrire('install'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + # maintenant on connait le vrai charset du site s'il est deja configure |
|
| 74 | + # sinon par defaut lire_meta reglera _DEFAULT_CHARSET |
|
| 75 | + # (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET) |
|
| 76 | + |
|
| 77 | + lire_metas(); |
|
| 78 | + if ($login) { |
|
| 79 | + include_spip('inc/charsets'); |
|
| 80 | + |
|
| 81 | + $nom = (importer_charset($nom, _DEFAULT_CHARSET)); |
|
| 82 | + $login = (importer_charset($login, _DEFAULT_CHARSET)); |
|
| 83 | + $email = (importer_charset($email, _DEFAULT_CHARSET)); |
|
| 84 | + # pour le passwd, bizarrement il faut le convertir comme s'il avait |
|
| 85 | + # ete tape en iso-8859-1 ; car c'est en fait ce que voit md5.js |
|
| 86 | + $pass = unicode2charset(utf_8_to_unicode($pass), 'iso-8859-1'); |
|
| 87 | + include_spip('auth/sha256.inc'); |
|
| 88 | + include_spip('inc/acces'); |
|
| 89 | + $htpass = generer_htpass($pass); |
|
| 90 | + $alea_actuel = creer_uniqid(); |
|
| 91 | + $alea_futur = creer_uniqid(); |
|
| 92 | + $shapass = spip_sha256($alea_actuel . $pass); |
|
| 93 | + // prelablement, creer le champ webmestre si il n'existe pas (install neuve |
|
| 94 | + // sur une vieille base |
|
| 95 | + $t = sql_showtable('spip_auteurs', true); |
|
| 96 | + if (!isset($t['field']['webmestre'])) { |
|
| 97 | + @sql_alter("TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login)); |
|
| 101 | + if ($id_auteur !== null) { |
|
| 102 | + sql_updateq('spip_auteurs', [ |
|
| 103 | + 'nom' => $nom, |
|
| 104 | + 'email' => $email, |
|
| 105 | + 'login' => $login, |
|
| 106 | + 'pass' => $shapass, |
|
| 107 | + 'alea_actuel' => $alea_actuel, |
|
| 108 | + 'alea_futur' => $alea_futur, |
|
| 109 | + 'htpass' => $htpass, |
|
| 110 | + 'statut' => '0minirezo' |
|
| 111 | + ], "id_auteur=$id_auteur"); |
|
| 112 | + } else { |
|
| 113 | + $id_auteur = sql_insertq('spip_auteurs', [ |
|
| 114 | + 'nom' => $nom, |
|
| 115 | + 'email' => $email, |
|
| 116 | + 'login' => $login, |
|
| 117 | + 'pass' => $shapass, |
|
| 118 | + 'htpass' => $htpass, |
|
| 119 | + 'alea_actuel' => $alea_actuel, |
|
| 120 | + 'alea_futur' => $alea_futur, |
|
| 121 | + 'statut' => '0minirezo' |
|
| 122 | + ]); |
|
| 123 | + } |
|
| 124 | + // le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 125 | + @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
|
| 126 | + |
|
| 127 | + // inserer email comme email webmaster principal |
|
| 128 | + // (sauf s'il est vide: cas de la re-installation) |
|
| 129 | + if ($email) { |
|
| 130 | + ecrire_meta('email_webmaster', $email); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // Connecter directement celui qui vient de (re)donner son login |
|
| 134 | + // mais sans cookie d'admin ni connexion longue |
|
| 135 | + include_spip('inc/auth'); |
|
| 136 | + if ( |
|
| 137 | + !$auteur = auth_identifier_login($login, $pass) |
|
| 138 | + or !auth_loger($auteur) |
|
| 139 | + ) { |
|
| 140 | + spip_log("login automatique impossible $auth_spip $session" . (is_countable($row) ? count($row) : 0)); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // installer les metas |
|
| 145 | + $config = charger_fonction('config', 'inc'); |
|
| 146 | + $config(); |
|
| 147 | + |
|
| 148 | + // activer les plugins |
|
| 149 | + // leur installation ne peut pas se faire sur le meme hit, il faudra donc |
|
| 150 | + // poursuivre au hit suivant |
|
| 151 | + include_spip('inc/plugin'); |
|
| 152 | + actualise_plugins_actifs(); |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + include_spip('inc/distant'); |
|
| 156 | + redirige_par_entete(parametre_url(self(), 'etape', '4', '&')); |
|
| 157 | 157 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -27,15 +27,15 @@ discard block |
||
| 27 | 27 | * @return int |
| 28 | 28 | */ |
| 29 | 29 | function genie_mise_a_jour_dist($t) { |
| 30 | - include_spip('inc/meta'); |
|
| 31 | - $maj = info_maj('spip', 'SPIP', $GLOBALS['spip_version_branche']); |
|
| 32 | - ecrire_meta('info_maj_spip', $maj ? ($GLOBALS['spip_version_branche'] . "|$maj") : '', 'non'); |
|
| 30 | + include_spip('inc/meta'); |
|
| 31 | + $maj = info_maj('spip', 'SPIP', $GLOBALS['spip_version_branche']); |
|
| 32 | + ecrire_meta('info_maj_spip', $maj ? ($GLOBALS['spip_version_branche'] . "|$maj") : '', 'non'); |
|
| 33 | 33 | |
| 34 | - mise_a_jour_ecran_securite(); |
|
| 34 | + mise_a_jour_ecran_securite(); |
|
| 35 | 35 | |
| 36 | - spip_log('Verification version SPIP : ' . ($maj ?: 'version a jour'), 'verifie_maj'); |
|
| 36 | + spip_log('Verification version SPIP : ' . ($maj ?: 'version a jour'), 'verifie_maj'); |
|
| 37 | 37 | |
| 38 | - return 1; |
|
| 38 | + return 1; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // TODO : fournir une URL sur spip.net pour maitriser la diffusion d'une nouvelle version de l'ecran via l'update auto |
@@ -52,46 +52,46 @@ discard block |
||
| 52 | 52 | * ou de ne repondre une 304 que si le md5 est bon |
| 53 | 53 | */ |
| 54 | 54 | function mise_a_jour_ecran_securite() { |
| 55 | - // TODO : url https avec verification du certificat |
|
| 56 | - return; |
|
| 57 | - |
|
| 58 | - // si l'ecran n'est pas deja present ou pas updatable, sortir |
|
| 59 | - if ( |
|
| 60 | - !_URL_ECRAN_SECURITE |
|
| 61 | - or !file_exists($filename = _DIR_ETC . 'ecran_securite.php') |
|
| 62 | - or !is_writable($filename) |
|
| 63 | - or !$last_modified = filemtime($filename) |
|
| 64 | - or !$md5 = md5_file($filename) |
|
| 65 | - ) { |
|
| 66 | - return false; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - include_spip('inc/distant'); |
|
| 70 | - $tmp_file = _DIR_TMP . 'ecran_securite.php'; |
|
| 71 | - $url = parametre_url(_URL_ECRAN_SECURITE, 'md5', $md5); |
|
| 72 | - $url = parametre_url($url, 'vspip', $GLOBALS['spip_version_branche']); |
|
| 73 | - $res = recuperer_url($url, [ |
|
| 74 | - 'if_modified_since' => $last_modified, |
|
| 75 | - 'file' => $tmp_file |
|
| 76 | - ]); |
|
| 77 | - |
|
| 78 | - // si il y a une version plus recente que l'on a recu correctement |
|
| 79 | - if ( |
|
| 80 | - $res['status'] == 200 |
|
| 81 | - and $res['length'] |
|
| 82 | - and $tmp_file = $res['file'] |
|
| 83 | - ) { |
|
| 84 | - if ($md5 !== md5_file($tmp_file)) { |
|
| 85 | - // on essaye de l'inclure pour verifier que ca ne fait pas erreur fatale |
|
| 86 | - include_once $tmp_file; |
|
| 87 | - // ok, on le copie a la place de l'ecran existant |
|
| 88 | - // en backupant l'ecran avant, au cas ou |
|
| 89 | - @copy($filename, $filename . '-bck-' . date('Y-m-d-His', $last_modified)); |
|
| 90 | - @rename($tmp_file, $filename); |
|
| 91 | - } else { |
|
| 92 | - @unlink($tmp_file); |
|
| 93 | - } |
|
| 94 | - } |
|
| 55 | + // TODO : url https avec verification du certificat |
|
| 56 | + return; |
|
| 57 | + |
|
| 58 | + // si l'ecran n'est pas deja present ou pas updatable, sortir |
|
| 59 | + if ( |
|
| 60 | + !_URL_ECRAN_SECURITE |
|
| 61 | + or !file_exists($filename = _DIR_ETC . 'ecran_securite.php') |
|
| 62 | + or !is_writable($filename) |
|
| 63 | + or !$last_modified = filemtime($filename) |
|
| 64 | + or !$md5 = md5_file($filename) |
|
| 65 | + ) { |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + include_spip('inc/distant'); |
|
| 70 | + $tmp_file = _DIR_TMP . 'ecran_securite.php'; |
|
| 71 | + $url = parametre_url(_URL_ECRAN_SECURITE, 'md5', $md5); |
|
| 72 | + $url = parametre_url($url, 'vspip', $GLOBALS['spip_version_branche']); |
|
| 73 | + $res = recuperer_url($url, [ |
|
| 74 | + 'if_modified_since' => $last_modified, |
|
| 75 | + 'file' => $tmp_file |
|
| 76 | + ]); |
|
| 77 | + |
|
| 78 | + // si il y a une version plus recente que l'on a recu correctement |
|
| 79 | + if ( |
|
| 80 | + $res['status'] == 200 |
|
| 81 | + and $res['length'] |
|
| 82 | + and $tmp_file = $res['file'] |
|
| 83 | + ) { |
|
| 84 | + if ($md5 !== md5_file($tmp_file)) { |
|
| 85 | + // on essaye de l'inclure pour verifier que ca ne fait pas erreur fatale |
|
| 86 | + include_once $tmp_file; |
|
| 87 | + // ok, on le copie a la place de l'ecran existant |
|
| 88 | + // en backupant l'ecran avant, au cas ou |
|
| 89 | + @copy($filename, $filename . '-bck-' . date('Y-m-d-His', $last_modified)); |
|
| 90 | + @rename($tmp_file, $filename); |
|
| 91 | + } else { |
|
| 92 | + @unlink($tmp_file); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -109,54 +109,54 @@ discard block |
||
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | 111 | function info_maj($dir, $file, $version) { |
| 112 | - include_spip('inc/plugin'); |
|
| 113 | - |
|
| 114 | - [$maj, $min, $rev] = preg_split('/\D+/', $version); |
|
| 115 | - |
|
| 116 | - $nom = _DIR_CACHE_XML . _VERSIONS_LISTE; |
|
| 117 | - $page = !file_exists($nom) ? '' : file_get_contents($nom); |
|
| 118 | - $page = info_maj_cache($nom, $dir, $page); |
|
| 119 | - |
|
| 120 | - // reperer toutes les versions de numero majeur superieur ou egal |
|
| 121 | - // (a revoir quand on arrivera a SPIP V10 ...) |
|
| 122 | - $p = substr('0123456789', intval($maj)); |
|
| 123 | - $p = ',/' . $file . '\D+([' . $p . ']+)\D+(\d+)(\D+(\d+))?.*?[.]zip",i'; |
|
| 124 | - preg_match_all($p, $page, $m, PREG_SET_ORDER); |
|
| 125 | - $page = $page_majeure = ''; |
|
| 126 | - |
|
| 127 | - // branche en cours d'utilisation |
|
| 128 | - $branche = implode('.', array_slice(explode('.', $version, 3), 0, 2)); |
|
| 129 | - |
|
| 130 | - foreach ($m as $v) { |
|
| 131 | - $v = array_pad($v, 5, 0); |
|
| 132 | - [, $maj2, $min2, , $rev2] = $v; |
|
| 133 | - $branche_maj = $maj2 . '.' . $min2; |
|
| 134 | - $version_maj = $maj2 . '.' . $min2 . '.' . $rev2; |
|
| 135 | - // d'abord les mises à jour de la même branche |
|
| 136 | - if ( |
|
| 137 | - (spip_version_compare($version, $version_maj, '<')) |
|
| 138 | - and (spip_version_compare($page, $version_maj, '<')) |
|
| 139 | - and spip_version_compare($branche, $branche_maj, '=') |
|
| 140 | - ) { |
|
| 141 | - $page = $version_maj; |
|
| 142 | - } |
|
| 143 | - // puis les mises à jours majeures |
|
| 144 | - if ( |
|
| 145 | - (spip_version_compare($version, $version_maj, '<')) |
|
| 146 | - and (spip_version_compare($page, $version_maj, '<')) |
|
| 147 | - and spip_version_compare($branche, $branche_maj, '<') |
|
| 148 | - ) { |
|
| 149 | - $page_majeure = $version_maj; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - if (!$page and !$page_majeure) { |
|
| 153 | - return ''; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $message = $page ? _T('nouvelle_version_spip', ['version' => $page]) . ($page_majeure ? ' | ' : '') : ''; |
|
| 157 | - $message .= $page_majeure ? _T('nouvelle_version_spip_majeure', ['version' => $page_majeure]) : ''; |
|
| 158 | - |
|
| 159 | - return "<a class='info_maj_spip' href='https://www.spip.net/fr_update' title='$page'>" . $message . '</a>'; |
|
| 112 | + include_spip('inc/plugin'); |
|
| 113 | + |
|
| 114 | + [$maj, $min, $rev] = preg_split('/\D+/', $version); |
|
| 115 | + |
|
| 116 | + $nom = _DIR_CACHE_XML . _VERSIONS_LISTE; |
|
| 117 | + $page = !file_exists($nom) ? '' : file_get_contents($nom); |
|
| 118 | + $page = info_maj_cache($nom, $dir, $page); |
|
| 119 | + |
|
| 120 | + // reperer toutes les versions de numero majeur superieur ou egal |
|
| 121 | + // (a revoir quand on arrivera a SPIP V10 ...) |
|
| 122 | + $p = substr('0123456789', intval($maj)); |
|
| 123 | + $p = ',/' . $file . '\D+([' . $p . ']+)\D+(\d+)(\D+(\d+))?.*?[.]zip",i'; |
|
| 124 | + preg_match_all($p, $page, $m, PREG_SET_ORDER); |
|
| 125 | + $page = $page_majeure = ''; |
|
| 126 | + |
|
| 127 | + // branche en cours d'utilisation |
|
| 128 | + $branche = implode('.', array_slice(explode('.', $version, 3), 0, 2)); |
|
| 129 | + |
|
| 130 | + foreach ($m as $v) { |
|
| 131 | + $v = array_pad($v, 5, 0); |
|
| 132 | + [, $maj2, $min2, , $rev2] = $v; |
|
| 133 | + $branche_maj = $maj2 . '.' . $min2; |
|
| 134 | + $version_maj = $maj2 . '.' . $min2 . '.' . $rev2; |
|
| 135 | + // d'abord les mises à jour de la même branche |
|
| 136 | + if ( |
|
| 137 | + (spip_version_compare($version, $version_maj, '<')) |
|
| 138 | + and (spip_version_compare($page, $version_maj, '<')) |
|
| 139 | + and spip_version_compare($branche, $branche_maj, '=') |
|
| 140 | + ) { |
|
| 141 | + $page = $version_maj; |
|
| 142 | + } |
|
| 143 | + // puis les mises à jours majeures |
|
| 144 | + if ( |
|
| 145 | + (spip_version_compare($version, $version_maj, '<')) |
|
| 146 | + and (spip_version_compare($page, $version_maj, '<')) |
|
| 147 | + and spip_version_compare($branche, $branche_maj, '<') |
|
| 148 | + ) { |
|
| 149 | + $page_majeure = $version_maj; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + if (!$page and !$page_majeure) { |
|
| 153 | + return ''; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $message = $page ? _T('nouvelle_version_spip', ['version' => $page]) . ($page_majeure ? ' | ' : '') : ''; |
|
| 157 | + $message .= $page_majeure ? _T('nouvelle_version_spip_majeure', ['version' => $page_majeure]) : ''; |
|
| 158 | + |
|
| 159 | + return "<a class='info_maj_spip' href='https://www.spip.net/fr_update' title='$page'>" . $message . '</a>'; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -177,25 +177,25 @@ discard block |
||
| 177 | 177 | * Contenu du fichier de cache de l'info de maj de SPIP. |
| 178 | 178 | */ |
| 179 | 179 | function info_maj_cache($nom, $dir, $page = '') { |
| 180 | - include_spip('inc/acces'); |
|
| 181 | - $alea_ephemere = charger_aleas(); |
|
| 182 | - $re = '<archives id="a' . $alea_ephemere . '">'; |
|
| 183 | - if (preg_match("/$re/", $page)) { |
|
| 184 | - return $page; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $url = _VERSIONS_SERVEUR . $dir . '/' . _VERSIONS_LISTE; |
|
| 188 | - $a = file_exists($nom) ? filemtime($nom) : ''; |
|
| 189 | - include_spip('inc/distant'); |
|
| 190 | - $res = recuperer_url_cache($url, ['if_modified_since' => $a]); |
|
| 191 | - // Si rien de neuf (ou inaccessible), garder l'ancienne |
|
| 192 | - if ($res) { |
|
| 193 | - $page = $res['page'] ?: $page; |
|
| 194 | - } |
|
| 195 | - // Placer l'indicateur de fraicheur |
|
| 196 | - $page = preg_replace('/^<archives.*?>/', $re, $page); |
|
| 197 | - sous_repertoire(_DIR_CACHE_XML); |
|
| 198 | - ecrire_fichier($nom, $page); |
|
| 199 | - |
|
| 200 | - return $page; |
|
| 180 | + include_spip('inc/acces'); |
|
| 181 | + $alea_ephemere = charger_aleas(); |
|
| 182 | + $re = '<archives id="a' . $alea_ephemere . '">'; |
|
| 183 | + if (preg_match("/$re/", $page)) { |
|
| 184 | + return $page; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $url = _VERSIONS_SERVEUR . $dir . '/' . _VERSIONS_LISTE; |
|
| 188 | + $a = file_exists($nom) ? filemtime($nom) : ''; |
|
| 189 | + include_spip('inc/distant'); |
|
| 190 | + $res = recuperer_url_cache($url, ['if_modified_since' => $a]); |
|
| 191 | + // Si rien de neuf (ou inaccessible), garder l'ancienne |
|
| 192 | + if ($res) { |
|
| 193 | + $page = $res['page'] ?: $page; |
|
| 194 | + } |
|
| 195 | + // Placer l'indicateur de fraicheur |
|
| 196 | + $page = preg_replace('/^<archives.*?>/', $re, $page); |
|
| 197 | + sous_repertoire(_DIR_CACHE_XML); |
|
| 198 | + ecrire_fichier($nom, $page); |
|
| 199 | + |
|
| 200 | + return $page; |
|
| 201 | 201 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/abstract_sql'); |
@@ -35,26 +35,26 @@ discard block |
||
| 35 | 35 | **/ |
| 36 | 36 | function genie_optimiser_dist($t) { |
| 37 | 37 | |
| 38 | - optimiser_base_une_table(); |
|
| 39 | - optimiser_base(); |
|
| 40 | - optimiser_caches_contextes(); |
|
| 38 | + optimiser_base_une_table(); |
|
| 39 | + optimiser_base(); |
|
| 40 | + optimiser_caches_contextes(); |
|
| 41 | 41 | |
| 42 | - // la date souhaitee pour le tour suivant = apres-demain a 4h du mat ; |
|
| 43 | - // sachant qu'on a un delai de 48h, on renvoie aujourd'hui a 4h du mat |
|
| 44 | - // avec une periode de flou entre 2h et 6h pour ne pas saturer un hebergeur |
|
| 45 | - // qui aurait beaucoup de sites SPIP |
|
| 46 | - return -(mktime(2, 0, 0) + random_int(0, 3600 * 4)); |
|
| 42 | + // la date souhaitee pour le tour suivant = apres-demain a 4h du mat ; |
|
| 43 | + // sachant qu'on a un delai de 48h, on renvoie aujourd'hui a 4h du mat |
|
| 44 | + // avec une periode de flou entre 2h et 6h pour ne pas saturer un hebergeur |
|
| 45 | + // qui aurait beaucoup de sites SPIP |
|
| 46 | + return -(mktime(2, 0, 0) + random_int(0, 3600 * 4)); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Vider les contextes ajax de plus de 48h |
| 51 | 51 | */ |
| 52 | 52 | function optimiser_caches_contextes() { |
| 53 | - sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 54 | - if (is_dir($d = _DIR_CACHE . 'contextes')) { |
|
| 55 | - include_spip('inc/invalideur'); |
|
| 56 | - purger_repertoire($d, ['mtime' => time() - 48 * 24 * 3600, 'limit' => 10000]); |
|
| 57 | - } |
|
| 53 | + sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 54 | + if (is_dir($d = _DIR_CACHE . 'contextes')) { |
|
| 55 | + include_spip('inc/invalideur'); |
|
| 56 | + purger_repertoire($d, ['mtime' => time() - 48 * 24 * 3600, 'limit' => 10000]); |
|
| 57 | + } |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @return void |
| 70 | 70 | **/ |
| 71 | 71 | function optimiser_base($attente = 86400) { |
| 72 | - optimiser_base_disparus($attente); |
|
| 72 | + optimiser_base_disparus($attente); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -86,28 +86,28 @@ discard block |
||
| 86 | 86 | **/ |
| 87 | 87 | function optimiser_base_une_table() { |
| 88 | 88 | |
| 89 | - $tables = []; |
|
| 90 | - $result = sql_showbase(); |
|
| 91 | - |
|
| 92 | - // on n'optimise qu'une seule table a chaque fois, |
|
| 93 | - // pour ne pas vautrer le systeme |
|
| 94 | - // lire http://dev.mysql.com/doc/refman/5.0/fr/optimize-table.html |
|
| 95 | - while ($row = sql_fetch($result)) { |
|
| 96 | - $tables[] = array_shift($row); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - spip_log('optimiser_base_une_table ' . json_encode($tables, JSON_THROW_ON_ERROR), 'genie' . _LOG_DEBUG); |
|
| 100 | - if ($tables) { |
|
| 101 | - $table_op = intval(lire_config('optimiser_table', 0) + 1) % sizeof($tables); |
|
| 102 | - ecrire_config('optimiser_table', $table_op); |
|
| 103 | - $q = $tables[$table_op]; |
|
| 104 | - spip_log("optimiser_base_une_table : debut d'optimisation de la table $q", 'genie' . _LOG_DEBUG); |
|
| 105 | - if (sql_optimize($q)) { |
|
| 106 | - spip_log("optimiser_base_une_table : fin d'optimisation de la table $q", 'genie' . _LOG_DEBUG); |
|
| 107 | - } else { |
|
| 108 | - spip_log("optimiser_base_une_table : Pas d'optimiseur necessaire", 'genie' . _LOG_DEBUG); |
|
| 109 | - } |
|
| 110 | - } |
|
| 89 | + $tables = []; |
|
| 90 | + $result = sql_showbase(); |
|
| 91 | + |
|
| 92 | + // on n'optimise qu'une seule table a chaque fois, |
|
| 93 | + // pour ne pas vautrer le systeme |
|
| 94 | + // lire http://dev.mysql.com/doc/refman/5.0/fr/optimize-table.html |
|
| 95 | + while ($row = sql_fetch($result)) { |
|
| 96 | + $tables[] = array_shift($row); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + spip_log('optimiser_base_une_table ' . json_encode($tables, JSON_THROW_ON_ERROR), 'genie' . _LOG_DEBUG); |
|
| 100 | + if ($tables) { |
|
| 101 | + $table_op = intval(lire_config('optimiser_table', 0) + 1) % sizeof($tables); |
|
| 102 | + ecrire_config('optimiser_table', $table_op); |
|
| 103 | + $q = $tables[$table_op]; |
|
| 104 | + spip_log("optimiser_base_une_table : debut d'optimisation de la table $q", 'genie' . _LOG_DEBUG); |
|
| 105 | + if (sql_optimize($q)) { |
|
| 106 | + spip_log("optimiser_base_une_table : fin d'optimisation de la table $q", 'genie' . _LOG_DEBUG); |
|
| 107 | + } else { |
|
| 108 | + spip_log("optimiser_base_une_table : Pas d'optimiseur necessaire", 'genie' . _LOG_DEBUG); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -133,18 +133,18 @@ discard block |
||
| 133 | 133 | * Nombre de suppressions |
| 134 | 134 | **/ |
| 135 | 135 | function optimiser_sansref($table, $id, $sel, $and = '') { |
| 136 | - $in = []; |
|
| 137 | - while ($row = sql_fetch($sel)) { |
|
| 138 | - $in[$row['id']] = true; |
|
| 139 | - } |
|
| 140 | - sql_free($sel); |
|
| 141 | - |
|
| 142 | - if ($in) { |
|
| 143 | - sql_delete($table, sql_in($id, array_keys($in)) . ($and ? " AND $and" : '')); |
|
| 144 | - spip_log("optimiser_sansref: Numeros des entrees $id supprimees dans la table $table: " . implode(', ', array_keys($in)), 'genie' . _LOG_DEBUG); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return count($in); |
|
| 136 | + $in = []; |
|
| 137 | + while ($row = sql_fetch($sel)) { |
|
| 138 | + $in[$row['id']] = true; |
|
| 139 | + } |
|
| 140 | + sql_free($sel); |
|
| 141 | + |
|
| 142 | + if ($in) { |
|
| 143 | + sql_delete($table, sql_in($id, array_keys($in)) . ($and ? " AND $and" : '')); |
|
| 144 | + spip_log("optimiser_sansref: Numeros des entrees $id supprimees dans la table $table: " . implode(', ', array_keys($in)), 'genie' . _LOG_DEBUG); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return count($in); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -166,81 +166,81 @@ discard block |
||
| 166 | 166 | **/ |
| 167 | 167 | function optimiser_base_disparus($attente = 86400) { |
| 168 | 168 | |
| 169 | - # format = 20060610110141, si on veut forcer une optimisation tout de suite |
|
| 170 | - $mydate = date('Y-m-d H:i:s', time() - $attente); |
|
| 171 | - $mydate_quote = sql_quote($mydate); |
|
| 169 | + # format = 20060610110141, si on veut forcer une optimisation tout de suite |
|
| 170 | + $mydate = date('Y-m-d H:i:s', time() - $attente); |
|
| 171 | + $mydate_quote = sql_quote($mydate); |
|
| 172 | 172 | |
| 173 | - $n = 0; |
|
| 173 | + $n = 0; |
|
| 174 | 174 | |
| 175 | - // |
|
| 176 | - // Rubriques |
|
| 177 | - // |
|
| 175 | + // |
|
| 176 | + // Rubriques |
|
| 177 | + // |
|
| 178 | 178 | |
| 179 | - # les articles qui sont dans une id_rubrique inexistante |
|
| 180 | - # attention on controle id_rubrique>0 pour ne pas tuer les articles |
|
| 181 | - # specialement affectes a une rubrique non-existante (plugin, |
|
| 182 | - # cf. https://core.spip.net/issues/1549 ) |
|
| 183 | - $res = sql_select( |
|
| 184 | - 'A.id_article AS id', |
|
| 185 | - 'spip_articles AS A |
|
| 179 | + # les articles qui sont dans une id_rubrique inexistante |
|
| 180 | + # attention on controle id_rubrique>0 pour ne pas tuer les articles |
|
| 181 | + # specialement affectes a une rubrique non-existante (plugin, |
|
| 182 | + # cf. https://core.spip.net/issues/1549 ) |
|
| 183 | + $res = sql_select( |
|
| 184 | + 'A.id_article AS id', |
|
| 185 | + 'spip_articles AS A |
|
| 186 | 186 | LEFT JOIN spip_rubriques AS R |
| 187 | 187 | ON A.id_rubrique=R.id_rubrique', |
| 188 | - "A.id_rubrique > 0 |
|
| 188 | + "A.id_rubrique > 0 |
|
| 189 | 189 | AND R.id_rubrique IS NULL |
| 190 | 190 | AND A.maj < $mydate_quote" |
| 191 | - ); |
|
| 191 | + ); |
|
| 192 | 192 | |
| 193 | - $n += optimiser_sansref('spip_articles', 'id_article', $res); |
|
| 193 | + $n += optimiser_sansref('spip_articles', 'id_article', $res); |
|
| 194 | 194 | |
| 195 | - // les articles a la poubelle |
|
| 196 | - sql_delete('spip_articles', "statut='poubelle' AND maj < $mydate_quote"); |
|
| 195 | + // les articles a la poubelle |
|
| 196 | + sql_delete('spip_articles', "statut='poubelle' AND maj < $mydate_quote"); |
|
| 197 | 197 | |
| 198 | - // |
|
| 199 | - // Auteurs |
|
| 200 | - // |
|
| 198 | + // |
|
| 199 | + // Auteurs |
|
| 200 | + // |
|
| 201 | 201 | |
| 202 | - include_spip('action/editer_liens'); |
|
| 203 | - // optimiser les liens de tous les auteurs vers des objets effaces |
|
| 204 | - // et depuis des auteurs effaces |
|
| 205 | - $n += objet_optimiser_liens(['auteur' => '*'], '*'); |
|
| 202 | + include_spip('action/editer_liens'); |
|
| 203 | + // optimiser les liens de tous les auteurs vers des objets effaces |
|
| 204 | + // et depuis des auteurs effaces |
|
| 205 | + $n += objet_optimiser_liens(['auteur' => '*'], '*'); |
|
| 206 | 206 | |
| 207 | - # effacer les auteurs poubelle qui ne sont lies a rien |
|
| 208 | - $res = sql_select( |
|
| 209 | - 'A.id_auteur AS id', |
|
| 210 | - 'spip_auteurs AS A |
|
| 207 | + # effacer les auteurs poubelle qui ne sont lies a rien |
|
| 208 | + $res = sql_select( |
|
| 209 | + 'A.id_auteur AS id', |
|
| 210 | + 'spip_auteurs AS A |
|
| 211 | 211 | LEFT JOIN spip_auteurs_liens AS L |
| 212 | 212 | ON L.id_auteur=A.id_auteur', |
| 213 | - "L.id_auteur IS NULL |
|
| 213 | + "L.id_auteur IS NULL |
|
| 214 | 214 | AND A.statut='5poubelle' AND A.maj < $mydate_quote" |
| 215 | - ); |
|
| 216 | - |
|
| 217 | - $n += optimiser_sansref('spip_auteurs', 'id_auteur', $res); |
|
| 218 | - |
|
| 219 | - # supprimer les auteurs 'nouveau' qui n'ont jamais donne suite |
|
| 220 | - # au mail de confirmation (45 jours pour repondre, ca devrait suffire) |
|
| 221 | - if (!defined('_AUTEURS_DELAI_REJET_NOUVEAU')) { |
|
| 222 | - define('_AUTEURS_DELAI_REJET_NOUVEAU', 45 * 24 * 3600); |
|
| 223 | - } |
|
| 224 | - sql_delete('spip_auteurs', "statut='nouveau' AND maj < " . sql_quote(date('Y-m-d', time() - intval(_AUTEURS_DELAI_REJET_NOUVEAU)))); |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Permet aux plugins de compléter l'optimisation suite aux éléments disparus |
|
| 228 | - * |
|
| 229 | - * L'index 'data' est un entier indiquant le nombre d'optimisations |
|
| 230 | - * qui ont été réalisées (par exemple le nombre de suppressions faites) |
|
| 231 | - * et qui doit être incrémenté par les fonctions |
|
| 232 | - * utilisant ce pipeline si elles suppriment des éléments. |
|
| 233 | - * |
|
| 234 | - * @pipeline_appel optimiser_base_disparus |
|
| 235 | - */ |
|
| 236 | - $n = pipeline('optimiser_base_disparus', [ |
|
| 237 | - 'args' => [ |
|
| 238 | - 'attente' => $attente, |
|
| 239 | - 'date' => $mydate |
|
| 240 | - ], |
|
| 241 | - 'data' => $n |
|
| 242 | - ]); |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - spip_log("optimiser_base_disparus : {$n} lien(s) mort(s)", 'genie' . _LOG_DEBUG); |
|
| 215 | + ); |
|
| 216 | + |
|
| 217 | + $n += optimiser_sansref('spip_auteurs', 'id_auteur', $res); |
|
| 218 | + |
|
| 219 | + # supprimer les auteurs 'nouveau' qui n'ont jamais donne suite |
|
| 220 | + # au mail de confirmation (45 jours pour repondre, ca devrait suffire) |
|
| 221 | + if (!defined('_AUTEURS_DELAI_REJET_NOUVEAU')) { |
|
| 222 | + define('_AUTEURS_DELAI_REJET_NOUVEAU', 45 * 24 * 3600); |
|
| 223 | + } |
|
| 224 | + sql_delete('spip_auteurs', "statut='nouveau' AND maj < " . sql_quote(date('Y-m-d', time() - intval(_AUTEURS_DELAI_REJET_NOUVEAU)))); |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Permet aux plugins de compléter l'optimisation suite aux éléments disparus |
|
| 228 | + * |
|
| 229 | + * L'index 'data' est un entier indiquant le nombre d'optimisations |
|
| 230 | + * qui ont été réalisées (par exemple le nombre de suppressions faites) |
|
| 231 | + * et qui doit être incrémenté par les fonctions |
|
| 232 | + * utilisant ce pipeline si elles suppriment des éléments. |
|
| 233 | + * |
|
| 234 | + * @pipeline_appel optimiser_base_disparus |
|
| 235 | + */ |
|
| 236 | + $n = pipeline('optimiser_base_disparus', [ |
|
| 237 | + 'args' => [ |
|
| 238 | + 'attente' => $attente, |
|
| 239 | + 'date' => $mydate |
|
| 240 | + ], |
|
| 241 | + 'data' => $n |
|
| 242 | + ]); |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + spip_log("optimiser_base_disparus : {$n} lien(s) mort(s)", 'genie' . _LOG_DEBUG); |
|
| 246 | 246 | } |