@@ -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 | /** |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @return void |
| 34 | 34 | **/ |
| 35 | 35 | function array_set_merge(&$table, $index, $valeur) { |
| 36 | - $table[$index] = isset($table[$index]) ? array_merge($table[$index], $valeur) : $valeur; |
|
| 36 | + $table[$index] = isset($table[$index]) ? array_merge($table[$index], $valeur) : $valeur; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -52,441 +52,441 @@ discard block |
||
| 52 | 52 | * - string (interne) si table '::md5' retourne un hash |
| 53 | 53 | */ |
| 54 | 54 | function lister_tables_objets_sql(?string $table_sql = null, $desc = []) { |
| 55 | - static $deja_la = false; |
|
| 56 | - static $infos_tables = null; |
|
| 57 | - static $md5 = null; |
|
| 58 | - static $plugin_hash = null; |
|
| 59 | - |
|
| 60 | - // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 61 | - $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 62 | - |
|
| 63 | - // prealablement recuperer les tables_principales |
|
| 64 | - if (is_null($infos_tables) || $plugin_hash !== $_PLUGINS_HASH) { |
|
| 65 | - // pas de reentrance (cas base/serial) |
|
| 66 | - if ($deja_la) { |
|
| 67 | - spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 68 | - . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 69 | - |
|
| 70 | - return ($table_sql === '::md5' ? $md5 : []); |
|
| 71 | - } |
|
| 72 | - $deja_la = true; |
|
| 73 | - $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 74 | - |
|
| 75 | - // recuperer les declarations explicites ancienne mode |
|
| 76 | - // qui servent a completer declarer_tables_objets_sql |
|
| 77 | - base_serial($GLOBALS['tables_principales']); |
|
| 78 | - base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 79 | - $infos_tables = [ |
|
| 80 | - 'spip_articles' => [ |
|
| 81 | - 'page' => 'article', |
|
| 82 | - 'texte_retour' => 'icone_retour_article', |
|
| 83 | - 'texte_modifier' => 'icone_modifier_article', |
|
| 84 | - 'texte_creer' => 'icone_ecrire_article', |
|
| 85 | - 'texte_objets' => 'public:articles', |
|
| 86 | - 'texte_objet' => 'public:article', |
|
| 87 | - 'texte_signale_edition' => 'texte_travail_article', |
|
| 88 | - 'info_aucun_objet' => 'info_aucun_article', |
|
| 89 | - 'info_1_objet' => 'info_1_article', |
|
| 90 | - 'info_nb_objets' => 'info_nb_articles', |
|
| 91 | - 'texte_logo_objet' => 'logo_article', |
|
| 92 | - 'texte_langue_objet' => 'titre_langue_article', |
|
| 93 | - 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 94 | - 'titre' => 'titre, lang', |
|
| 95 | - 'date' => 'date', |
|
| 96 | - 'principale' => 'oui', |
|
| 97 | - 'introduction_longueur' => '500', |
|
| 98 | - 'champs_editables' => [ |
|
| 99 | - 'surtitre', |
|
| 100 | - 'titre', |
|
| 101 | - 'soustitre', |
|
| 102 | - 'descriptif', |
|
| 103 | - 'nom_site', |
|
| 104 | - 'url_site', |
|
| 105 | - 'chapo', |
|
| 106 | - 'texte', |
|
| 107 | - 'ps', |
|
| 108 | - 'virtuel' |
|
| 109 | - ], |
|
| 110 | - 'champs_versionnes' => [ |
|
| 111 | - 'id_rubrique', |
|
| 112 | - 'surtitre', |
|
| 113 | - 'titre', |
|
| 114 | - 'soustitre', |
|
| 115 | - 'jointure_auteurs', |
|
| 116 | - 'descriptif', |
|
| 117 | - 'nom_site', |
|
| 118 | - 'url_site', |
|
| 119 | - 'chapo', |
|
| 120 | - 'texte', |
|
| 121 | - 'ps' |
|
| 122 | - ], |
|
| 123 | - 'field' => [ |
|
| 124 | - 'id_article' => 'bigint(21) NOT NULL', |
|
| 125 | - 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 126 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 127 | - 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 128 | - 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 129 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 130 | - 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 131 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 132 | - 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 133 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 134 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 135 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 136 | - 'maj' => 'TIMESTAMP', |
|
| 137 | - 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 138 | - 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 139 | - 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 140 | - 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | - 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 142 | - 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 143 | - 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 144 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 145 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 146 | - 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 147 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 148 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 149 | - 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 150 | - ], |
|
| 151 | - 'key' => [ |
|
| 152 | - 'PRIMARY KEY' => 'id_article', |
|
| 153 | - 'KEY id_rubrique' => 'id_rubrique', |
|
| 154 | - 'KEY id_secteur' => 'id_secteur', |
|
| 155 | - 'KEY id_trad' => 'id_trad', |
|
| 156 | - 'KEY lang' => 'lang', |
|
| 157 | - 'KEY statut' => 'statut, date', |
|
| 158 | - ], |
|
| 159 | - 'join' => [ |
|
| 160 | - 'id_article' => 'id_article', |
|
| 161 | - 'id_rubrique' => 'id_rubrique' |
|
| 162 | - ], |
|
| 163 | - 'parent' => [ |
|
| 164 | - ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 165 | - ], |
|
| 166 | - 'rechercher_champs' => [ |
|
| 167 | - 'surtitre' => 5, |
|
| 168 | - 'titre' => 8, |
|
| 169 | - 'soustitre' => 5, |
|
| 170 | - 'chapo' => 3, |
|
| 171 | - 'texte' => 1, |
|
| 172 | - 'ps' => 1, |
|
| 173 | - 'nom_site' => 1, |
|
| 174 | - 'url_site' => 1, |
|
| 175 | - 'descriptif' => 4 |
|
| 176 | - ], |
|
| 177 | - 'rechercher_jointures' => [ |
|
| 178 | - 'auteur' => ['nom' => 10], |
|
| 179 | - ], |
|
| 180 | - 'statut' => [ |
|
| 181 | - [ |
|
| 182 | - 'champ' => 'statut', |
|
| 183 | - 'publie' => 'publie', |
|
| 184 | - 'previsu' => 'publie,prop,prepa/auteur', |
|
| 185 | - 'post_date' => 'date', |
|
| 186 | - 'exception' => ['statut', 'tout'] |
|
| 187 | - ] |
|
| 188 | - ], |
|
| 189 | - 'statut_titres' => [ |
|
| 190 | - 'prepa' => 'info_article_redaction', |
|
| 191 | - 'prop' => 'info_article_propose', |
|
| 192 | - 'publie' => 'info_article_publie', |
|
| 193 | - 'refuse' => 'info_article_refuse', |
|
| 194 | - 'poubelle' => 'info_article_supprime' |
|
| 195 | - ], |
|
| 196 | - 'statut_textes_instituer' => [ |
|
| 197 | - 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 198 | - 'prop' => 'texte_statut_propose_evaluation', |
|
| 199 | - 'publie' => 'texte_statut_publie', |
|
| 200 | - 'refuse' => 'texte_statut_refuse', |
|
| 201 | - 'poubelle' => 'texte_statut_poubelle', |
|
| 202 | - ], |
|
| 203 | - 'texte_changer_statut' => 'texte_article_statut', |
|
| 204 | - 'aide_changer_statut' => 'artstatut', |
|
| 205 | - 'tables_jointures' => [ |
|
| 206 | - 'profondeur' => 'rubriques', |
|
| 207 | - #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 208 | - ], |
|
| 209 | - ], |
|
| 210 | - 'spip_auteurs' => [ |
|
| 211 | - 'page' => 'auteur', |
|
| 212 | - 'texte_retour' => 'icone_retour', |
|
| 213 | - 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 214 | - 'texte_modifier' => 'admin_modifier_auteur', |
|
| 215 | - 'texte_objets' => 'icone_auteurs', |
|
| 216 | - 'texte_objet' => 'public:auteur', |
|
| 217 | - 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 218 | - 'info_1_objet' => 'info_1_auteur', |
|
| 219 | - 'info_nb_objets' => 'info_nb_auteurs', |
|
| 220 | - 'texte_logo_objet' => 'logo_auteur', |
|
| 221 | - 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 222 | - 'titre' => "nom AS titre, '' AS lang", |
|
| 223 | - 'date' => 'date', |
|
| 224 | - 'principale' => 'oui', |
|
| 225 | - 'champs_editables' => ['nom', 'email', 'lang', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 226 | - 'champs_versionnes' => ['nom', 'bio', 'lang', 'email', 'nom_site', 'url_site', 'login'], |
|
| 227 | - 'field' => [ |
|
| 228 | - 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 229 | - 'nom' => "text DEFAULT '' NOT NULL", |
|
| 230 | - 'bio' => "text DEFAULT '' NOT NULL", |
|
| 231 | - 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 232 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 234 | - 'login' => 'VARCHAR(255) BINARY', |
|
| 235 | - 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 236 | - 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | - 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 238 | - 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 239 | - 'maj' => 'TIMESTAMP', |
|
| 240 | - 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 241 | - 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 242 | - 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 243 | - 'alea_actuel' => 'tinytext', |
|
| 244 | - 'alea_futur' => 'tinytext', |
|
| 245 | - 'prefs' => 'text', |
|
| 246 | - 'cookie_oubli' => 'tinytext', |
|
| 247 | - 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 248 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 249 | - 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL", |
|
| 250 | - 'backup_cles' => "mediumtext DEFAULT '' NOT NULL", |
|
| 251 | - ], |
|
| 252 | - 'key' => [ |
|
| 253 | - 'PRIMARY KEY' => 'id_auteur', |
|
| 254 | - 'KEY login' => 'login', |
|
| 255 | - 'KEY statut' => 'statut', |
|
| 256 | - 'KEY en_ligne' => 'en_ligne', |
|
| 257 | - ], |
|
| 258 | - 'join' => [ |
|
| 259 | - 'id_auteur' => 'id_auteur', |
|
| 260 | - 'login' => 'login' |
|
| 261 | - ], |
|
| 262 | - 'rechercher_champs' => [ |
|
| 263 | - 'nom' => 5, |
|
| 264 | - 'bio' => 1, |
|
| 265 | - 'email' => 1, |
|
| 266 | - 'nom_site' => 1, |
|
| 267 | - 'url_site' => 1, |
|
| 268 | - 'login' => 1 |
|
| 269 | - ], |
|
| 270 | - // 2 conditions pour les auteurs : statut!=poubelle, |
|
| 271 | - // et avoir des articles publies |
|
| 272 | - 'statut' => [ |
|
| 273 | - [ |
|
| 274 | - 'champ' => 'statut', |
|
| 275 | - 'publie' => '!5poubelle', |
|
| 276 | - 'previsu' => '!5poubelle', |
|
| 277 | - 'exception' => 'statut' |
|
| 278 | - ], |
|
| 279 | - [ |
|
| 280 | - 'champ' => [ |
|
| 281 | - ['spip_auteurs_liens', 'id_auteur'], |
|
| 282 | - [ |
|
| 283 | - 'spip_articles', |
|
| 284 | - ['id_objet', 'id_article', 'objet', 'article'] |
|
| 285 | - ], |
|
| 286 | - 'statut' |
|
| 287 | - ], |
|
| 288 | - 'publie' => 'publie', |
|
| 289 | - 'previsu' => '!', |
|
| 290 | - 'post_date' => 'date', |
|
| 291 | - 'exception' => ['statut', 'lien', 'tout'] |
|
| 292 | - ], |
|
| 293 | - ], |
|
| 294 | - 'statut_images' => [ |
|
| 295 | - 'auteur-6forum-16.png', |
|
| 296 | - '0minirezo' => 'auteur-0minirezo-16.png', |
|
| 297 | - '1comite' => 'auteur-1comite-16.png', |
|
| 298 | - '6forum' => 'auteur-6forum-16.png', |
|
| 299 | - '5poubelle' => 'auteur-5poubelle-16.png', |
|
| 300 | - 'nouveau' => '' |
|
| 301 | - ], |
|
| 302 | - 'statut_titres' => [ |
|
| 303 | - 'titre_image_visiteur', |
|
| 304 | - '0minirezo' => 'titre_image_administrateur', |
|
| 305 | - '1comite' => 'titre_image_redacteur_02', |
|
| 306 | - '6forum' => 'titre_image_visiteur', |
|
| 307 | - '5poubelle' => 'titre_image_auteur_supprime', |
|
| 308 | - ], |
|
| 309 | - 'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas |
|
| 310 | - ], |
|
| 311 | - ], |
|
| 312 | - 'spip_rubriques' => [ |
|
| 313 | - 'page' => 'rubrique', |
|
| 314 | - 'url_voir' => 'rubrique', |
|
| 315 | - 'url_edit' => 'rubrique_edit', |
|
| 316 | - 'texte_retour' => 'icone_retour', |
|
| 317 | - 'texte_objets' => 'public:rubriques', |
|
| 318 | - 'texte_objet' => 'public:rubrique', |
|
| 319 | - 'texte_modifier' => 'icone_modifier_rubrique', |
|
| 320 | - 'texte_creer' => 'icone_creer_rubrique', |
|
| 321 | - 'texte_ajouter' => 'titre_ajouter_une_rubrique', |
|
| 322 | - 'texte_creer_associer' => 'creer_et_associer_une_rubrique', |
|
| 323 | - 'info_aucun_objet' => 'info_aucun_rubrique', |
|
| 324 | - 'info_1_objet' => 'info_1_rubrique', |
|
| 325 | - 'info_nb_objets' => 'info_nb_rubriques', |
|
| 326 | - 'texte_logo_objet' => 'logo_rubrique', |
|
| 327 | - 'texte_langue_objet' => 'titre_langue_rubrique', |
|
| 328 | - 'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique', |
|
| 329 | - 'titre' => 'titre, lang', |
|
| 330 | - 'date' => 'date', |
|
| 331 | - 'principale' => 'oui', |
|
| 332 | - 'introduction_longueur' => '600', |
|
| 333 | - 'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'], |
|
| 334 | - 'champs_versionnes' => ['titre', 'descriptif', 'texte'], |
|
| 335 | - 'field' => [ |
|
| 336 | - 'id_rubrique' => 'bigint(21) NOT NULL', |
|
| 337 | - 'id_parent' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 338 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 339 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 340 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 341 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 342 | - 'maj' => 'TIMESTAMP', |
|
| 343 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 344 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 345 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 346 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 347 | - 'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 348 | - 'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 349 | - 'profondeur' => "smallint(5) DEFAULT '0' NOT NULL" |
|
| 350 | - ], |
|
| 351 | - 'key' => [ |
|
| 352 | - 'PRIMARY KEY' => 'id_rubrique', |
|
| 353 | - 'KEY lang' => 'lang', |
|
| 354 | - 'KEY id_parent' => 'id_parent', |
|
| 355 | - ], |
|
| 356 | - 'parent' => [ |
|
| 357 | - ['type' => 'rubrique', 'champ' => 'id_parent'] |
|
| 358 | - ], |
|
| 359 | - 'rechercher_champs' => [ |
|
| 360 | - 'titre' => 8, |
|
| 361 | - 'descriptif' => 5, |
|
| 362 | - 'texte' => 1 |
|
| 363 | - ], |
|
| 364 | - 'statut' => [ |
|
| 365 | - [ |
|
| 366 | - 'champ' => 'statut', |
|
| 367 | - 'publie' => 'publie', |
|
| 368 | - 'previsu' => '!', |
|
| 369 | - 'exception' => ['statut', 'tout'] |
|
| 370 | - ], |
|
| 371 | - ], |
|
| 372 | - 'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 373 | - ], |
|
| 374 | - ], |
|
| 375 | - // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 376 | - ['tables_jointures' => ['id_auteur' => 'auteurs_liens']] |
|
| 377 | - ]; |
|
| 378 | - |
|
| 379 | - // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install |
|
| 380 | - // initialiser la signature |
|
| 381 | - $md5 = md5(serialize($infos_tables)); |
|
| 382 | - |
|
| 383 | - $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 384 | - $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 385 | - $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 386 | - |
|
| 387 | - // completer les informations manquantes ou implicites |
|
| 388 | - $all = []; |
|
| 389 | - foreach (array_keys($infos_tables) as $t) { |
|
| 390 | - // les cles numeriques servent a declarer |
|
| 391 | - // les proprietes applicables a tous les objets |
|
| 392 | - // on les mets de cote |
|
| 393 | - if (is_numeric($t)) { |
|
| 394 | - $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 395 | - unset($infos_tables[$t]); |
|
| 396 | - } else { |
|
| 397 | - $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - // repercuter les proprietes generales communes a tous les objets |
|
| 402 | - foreach (array_keys($infos_tables) as $t) { |
|
| 403 | - foreach (array_keys($all) as $i) { |
|
| 404 | - if (in_array($i, ['tables_jointures', 'champs_versionnes'])) { |
|
| 405 | - $add = $all[$i]; |
|
| 406 | - // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
|
| 407 | - // pour les declarations generiques avec cles numeriques |
|
| 408 | - if ($i == 'tables_jointures' && isset($infos_tables[$t][$i]) && (is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0)) { |
|
| 409 | - $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 410 | - foreach ($doublons as $d) { |
|
| 411 | - if ( |
|
| 412 | - is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 413 | - && is_numeric($k = array_search($d, $add)) |
|
| 414 | - ) { |
|
| 415 | - unset($add[$k]); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add); |
|
| 420 | - } else { |
|
| 421 | - $infos_tables[$t][$i] = array_merge_recursive( |
|
| 422 | - $infos_tables[$t][$i] ?? [], |
|
| 423 | - $all[$i] |
|
| 424 | - ); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // completer les tables principales et auxiliaires |
|
| 430 | - // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 431 | - // pour assurer la compat en transition |
|
| 432 | - foreach ($infos_tables as $table => $infos) { |
|
| 433 | - $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 434 | - // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 435 | - // qui a ete appelle avant |
|
| 436 | - $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []); |
|
| 437 | - // l'ajouter au tableau |
|
| 438 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 439 | - if (isset($infos['field']) && isset($infos['key'])) { |
|
| 440 | - foreach (['field', 'key', 'join'] as $k) { |
|
| 441 | - if (isset($infos_tables[$table][$k])) { |
|
| 442 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } else { |
|
| 446 | - // ici on ne renvoie que les declarations, donc RIEN |
|
| 447 | - // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 448 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 449 | - } |
|
| 450 | - if (is_countable($mem) ? count($mem) : 0) { |
|
| 451 | - foreach (array_keys($mem) as $k) { |
|
| 452 | - if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 453 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 454 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 455 | - $mem[$k] |
|
| 456 | - ); |
|
| 457 | - } else { |
|
| 458 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - // recuperer les interfaces (table_titre, table_date) |
|
| 465 | - // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 466 | - // dans le pipeline de declarer_tables_interfaces |
|
| 467 | - include_spip('public/interfaces'); |
|
| 468 | - foreach (array_keys($infos_tables) as $t) { |
|
| 469 | - $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - $deja_la = false; |
|
| 473 | - // signature |
|
| 474 | - $md5 = md5(serialize($infos_tables)); |
|
| 475 | - } |
|
| 476 | - if ($table_sql === '::md5') { |
|
| 477 | - return $md5; |
|
| 478 | - } |
|
| 479 | - if ($table_sql && !isset($infos_tables[$table_sql])) { |
|
| 480 | - #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 481 | - $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 482 | - |
|
| 483 | - return $desc; |
|
| 484 | - } |
|
| 485 | - if ($table_sql) { |
|
| 486 | - return $infos_tables[$table_sql] ?? []; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - return $infos_tables; |
|
| 55 | + static $deja_la = false; |
|
| 56 | + static $infos_tables = null; |
|
| 57 | + static $md5 = null; |
|
| 58 | + static $plugin_hash = null; |
|
| 59 | + |
|
| 60 | + // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 61 | + $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 62 | + |
|
| 63 | + // prealablement recuperer les tables_principales |
|
| 64 | + if (is_null($infos_tables) || $plugin_hash !== $_PLUGINS_HASH) { |
|
| 65 | + // pas de reentrance (cas base/serial) |
|
| 66 | + if ($deja_la) { |
|
| 67 | + spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 68 | + . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 69 | + |
|
| 70 | + return ($table_sql === '::md5' ? $md5 : []); |
|
| 71 | + } |
|
| 72 | + $deja_la = true; |
|
| 73 | + $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 74 | + |
|
| 75 | + // recuperer les declarations explicites ancienne mode |
|
| 76 | + // qui servent a completer declarer_tables_objets_sql |
|
| 77 | + base_serial($GLOBALS['tables_principales']); |
|
| 78 | + base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 79 | + $infos_tables = [ |
|
| 80 | + 'spip_articles' => [ |
|
| 81 | + 'page' => 'article', |
|
| 82 | + 'texte_retour' => 'icone_retour_article', |
|
| 83 | + 'texte_modifier' => 'icone_modifier_article', |
|
| 84 | + 'texte_creer' => 'icone_ecrire_article', |
|
| 85 | + 'texte_objets' => 'public:articles', |
|
| 86 | + 'texte_objet' => 'public:article', |
|
| 87 | + 'texte_signale_edition' => 'texte_travail_article', |
|
| 88 | + 'info_aucun_objet' => 'info_aucun_article', |
|
| 89 | + 'info_1_objet' => 'info_1_article', |
|
| 90 | + 'info_nb_objets' => 'info_nb_articles', |
|
| 91 | + 'texte_logo_objet' => 'logo_article', |
|
| 92 | + 'texte_langue_objet' => 'titre_langue_article', |
|
| 93 | + 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 94 | + 'titre' => 'titre, lang', |
|
| 95 | + 'date' => 'date', |
|
| 96 | + 'principale' => 'oui', |
|
| 97 | + 'introduction_longueur' => '500', |
|
| 98 | + 'champs_editables' => [ |
|
| 99 | + 'surtitre', |
|
| 100 | + 'titre', |
|
| 101 | + 'soustitre', |
|
| 102 | + 'descriptif', |
|
| 103 | + 'nom_site', |
|
| 104 | + 'url_site', |
|
| 105 | + 'chapo', |
|
| 106 | + 'texte', |
|
| 107 | + 'ps', |
|
| 108 | + 'virtuel' |
|
| 109 | + ], |
|
| 110 | + 'champs_versionnes' => [ |
|
| 111 | + 'id_rubrique', |
|
| 112 | + 'surtitre', |
|
| 113 | + 'titre', |
|
| 114 | + 'soustitre', |
|
| 115 | + 'jointure_auteurs', |
|
| 116 | + 'descriptif', |
|
| 117 | + 'nom_site', |
|
| 118 | + 'url_site', |
|
| 119 | + 'chapo', |
|
| 120 | + 'texte', |
|
| 121 | + 'ps' |
|
| 122 | + ], |
|
| 123 | + 'field' => [ |
|
| 124 | + 'id_article' => 'bigint(21) NOT NULL', |
|
| 125 | + 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 126 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 127 | + 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 128 | + 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 129 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 130 | + 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 131 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 132 | + 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 133 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 134 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 135 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 136 | + 'maj' => 'TIMESTAMP', |
|
| 137 | + 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 138 | + 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 139 | + 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 140 | + 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | + 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 142 | + 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 143 | + 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 144 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 145 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 146 | + 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 147 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 148 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 149 | + 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 150 | + ], |
|
| 151 | + 'key' => [ |
|
| 152 | + 'PRIMARY KEY' => 'id_article', |
|
| 153 | + 'KEY id_rubrique' => 'id_rubrique', |
|
| 154 | + 'KEY id_secteur' => 'id_secteur', |
|
| 155 | + 'KEY id_trad' => 'id_trad', |
|
| 156 | + 'KEY lang' => 'lang', |
|
| 157 | + 'KEY statut' => 'statut, date', |
|
| 158 | + ], |
|
| 159 | + 'join' => [ |
|
| 160 | + 'id_article' => 'id_article', |
|
| 161 | + 'id_rubrique' => 'id_rubrique' |
|
| 162 | + ], |
|
| 163 | + 'parent' => [ |
|
| 164 | + ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 165 | + ], |
|
| 166 | + 'rechercher_champs' => [ |
|
| 167 | + 'surtitre' => 5, |
|
| 168 | + 'titre' => 8, |
|
| 169 | + 'soustitre' => 5, |
|
| 170 | + 'chapo' => 3, |
|
| 171 | + 'texte' => 1, |
|
| 172 | + 'ps' => 1, |
|
| 173 | + 'nom_site' => 1, |
|
| 174 | + 'url_site' => 1, |
|
| 175 | + 'descriptif' => 4 |
|
| 176 | + ], |
|
| 177 | + 'rechercher_jointures' => [ |
|
| 178 | + 'auteur' => ['nom' => 10], |
|
| 179 | + ], |
|
| 180 | + 'statut' => [ |
|
| 181 | + [ |
|
| 182 | + 'champ' => 'statut', |
|
| 183 | + 'publie' => 'publie', |
|
| 184 | + 'previsu' => 'publie,prop,prepa/auteur', |
|
| 185 | + 'post_date' => 'date', |
|
| 186 | + 'exception' => ['statut', 'tout'] |
|
| 187 | + ] |
|
| 188 | + ], |
|
| 189 | + 'statut_titres' => [ |
|
| 190 | + 'prepa' => 'info_article_redaction', |
|
| 191 | + 'prop' => 'info_article_propose', |
|
| 192 | + 'publie' => 'info_article_publie', |
|
| 193 | + 'refuse' => 'info_article_refuse', |
|
| 194 | + 'poubelle' => 'info_article_supprime' |
|
| 195 | + ], |
|
| 196 | + 'statut_textes_instituer' => [ |
|
| 197 | + 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 198 | + 'prop' => 'texte_statut_propose_evaluation', |
|
| 199 | + 'publie' => 'texte_statut_publie', |
|
| 200 | + 'refuse' => 'texte_statut_refuse', |
|
| 201 | + 'poubelle' => 'texte_statut_poubelle', |
|
| 202 | + ], |
|
| 203 | + 'texte_changer_statut' => 'texte_article_statut', |
|
| 204 | + 'aide_changer_statut' => 'artstatut', |
|
| 205 | + 'tables_jointures' => [ |
|
| 206 | + 'profondeur' => 'rubriques', |
|
| 207 | + #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 208 | + ], |
|
| 209 | + ], |
|
| 210 | + 'spip_auteurs' => [ |
|
| 211 | + 'page' => 'auteur', |
|
| 212 | + 'texte_retour' => 'icone_retour', |
|
| 213 | + 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 214 | + 'texte_modifier' => 'admin_modifier_auteur', |
|
| 215 | + 'texte_objets' => 'icone_auteurs', |
|
| 216 | + 'texte_objet' => 'public:auteur', |
|
| 217 | + 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 218 | + 'info_1_objet' => 'info_1_auteur', |
|
| 219 | + 'info_nb_objets' => 'info_nb_auteurs', |
|
| 220 | + 'texte_logo_objet' => 'logo_auteur', |
|
| 221 | + 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 222 | + 'titre' => "nom AS titre, '' AS lang", |
|
| 223 | + 'date' => 'date', |
|
| 224 | + 'principale' => 'oui', |
|
| 225 | + 'champs_editables' => ['nom', 'email', 'lang', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 226 | + 'champs_versionnes' => ['nom', 'bio', 'lang', 'email', 'nom_site', 'url_site', 'login'], |
|
| 227 | + 'field' => [ |
|
| 228 | + 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 229 | + 'nom' => "text DEFAULT '' NOT NULL", |
|
| 230 | + 'bio' => "text DEFAULT '' NOT NULL", |
|
| 231 | + 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 232 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 234 | + 'login' => 'VARCHAR(255) BINARY', |
|
| 235 | + 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 236 | + 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | + 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 238 | + 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 239 | + 'maj' => 'TIMESTAMP', |
|
| 240 | + 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 241 | + 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 242 | + 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 243 | + 'alea_actuel' => 'tinytext', |
|
| 244 | + 'alea_futur' => 'tinytext', |
|
| 245 | + 'prefs' => 'text', |
|
| 246 | + 'cookie_oubli' => 'tinytext', |
|
| 247 | + 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 248 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 249 | + 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL", |
|
| 250 | + 'backup_cles' => "mediumtext DEFAULT '' NOT NULL", |
|
| 251 | + ], |
|
| 252 | + 'key' => [ |
|
| 253 | + 'PRIMARY KEY' => 'id_auteur', |
|
| 254 | + 'KEY login' => 'login', |
|
| 255 | + 'KEY statut' => 'statut', |
|
| 256 | + 'KEY en_ligne' => 'en_ligne', |
|
| 257 | + ], |
|
| 258 | + 'join' => [ |
|
| 259 | + 'id_auteur' => 'id_auteur', |
|
| 260 | + 'login' => 'login' |
|
| 261 | + ], |
|
| 262 | + 'rechercher_champs' => [ |
|
| 263 | + 'nom' => 5, |
|
| 264 | + 'bio' => 1, |
|
| 265 | + 'email' => 1, |
|
| 266 | + 'nom_site' => 1, |
|
| 267 | + 'url_site' => 1, |
|
| 268 | + 'login' => 1 |
|
| 269 | + ], |
|
| 270 | + // 2 conditions pour les auteurs : statut!=poubelle, |
|
| 271 | + // et avoir des articles publies |
|
| 272 | + 'statut' => [ |
|
| 273 | + [ |
|
| 274 | + 'champ' => 'statut', |
|
| 275 | + 'publie' => '!5poubelle', |
|
| 276 | + 'previsu' => '!5poubelle', |
|
| 277 | + 'exception' => 'statut' |
|
| 278 | + ], |
|
| 279 | + [ |
|
| 280 | + 'champ' => [ |
|
| 281 | + ['spip_auteurs_liens', 'id_auteur'], |
|
| 282 | + [ |
|
| 283 | + 'spip_articles', |
|
| 284 | + ['id_objet', 'id_article', 'objet', 'article'] |
|
| 285 | + ], |
|
| 286 | + 'statut' |
|
| 287 | + ], |
|
| 288 | + 'publie' => 'publie', |
|
| 289 | + 'previsu' => '!', |
|
| 290 | + 'post_date' => 'date', |
|
| 291 | + 'exception' => ['statut', 'lien', 'tout'] |
|
| 292 | + ], |
|
| 293 | + ], |
|
| 294 | + 'statut_images' => [ |
|
| 295 | + 'auteur-6forum-16.png', |
|
| 296 | + '0minirezo' => 'auteur-0minirezo-16.png', |
|
| 297 | + '1comite' => 'auteur-1comite-16.png', |
|
| 298 | + '6forum' => 'auteur-6forum-16.png', |
|
| 299 | + '5poubelle' => 'auteur-5poubelle-16.png', |
|
| 300 | + 'nouveau' => '' |
|
| 301 | + ], |
|
| 302 | + 'statut_titres' => [ |
|
| 303 | + 'titre_image_visiteur', |
|
| 304 | + '0minirezo' => 'titre_image_administrateur', |
|
| 305 | + '1comite' => 'titre_image_redacteur_02', |
|
| 306 | + '6forum' => 'titre_image_visiteur', |
|
| 307 | + '5poubelle' => 'titre_image_auteur_supprime', |
|
| 308 | + ], |
|
| 309 | + 'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas |
|
| 310 | + ], |
|
| 311 | + ], |
|
| 312 | + 'spip_rubriques' => [ |
|
| 313 | + 'page' => 'rubrique', |
|
| 314 | + 'url_voir' => 'rubrique', |
|
| 315 | + 'url_edit' => 'rubrique_edit', |
|
| 316 | + 'texte_retour' => 'icone_retour', |
|
| 317 | + 'texte_objets' => 'public:rubriques', |
|
| 318 | + 'texte_objet' => 'public:rubrique', |
|
| 319 | + 'texte_modifier' => 'icone_modifier_rubrique', |
|
| 320 | + 'texte_creer' => 'icone_creer_rubrique', |
|
| 321 | + 'texte_ajouter' => 'titre_ajouter_une_rubrique', |
|
| 322 | + 'texte_creer_associer' => 'creer_et_associer_une_rubrique', |
|
| 323 | + 'info_aucun_objet' => 'info_aucun_rubrique', |
|
| 324 | + 'info_1_objet' => 'info_1_rubrique', |
|
| 325 | + 'info_nb_objets' => 'info_nb_rubriques', |
|
| 326 | + 'texte_logo_objet' => 'logo_rubrique', |
|
| 327 | + 'texte_langue_objet' => 'titre_langue_rubrique', |
|
| 328 | + 'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique', |
|
| 329 | + 'titre' => 'titre, lang', |
|
| 330 | + 'date' => 'date', |
|
| 331 | + 'principale' => 'oui', |
|
| 332 | + 'introduction_longueur' => '600', |
|
| 333 | + 'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'], |
|
| 334 | + 'champs_versionnes' => ['titre', 'descriptif', 'texte'], |
|
| 335 | + 'field' => [ |
|
| 336 | + 'id_rubrique' => 'bigint(21) NOT NULL', |
|
| 337 | + 'id_parent' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 338 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 339 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 340 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 341 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 342 | + 'maj' => 'TIMESTAMP', |
|
| 343 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 344 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 345 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 346 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 347 | + 'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 348 | + 'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 349 | + 'profondeur' => "smallint(5) DEFAULT '0' NOT NULL" |
|
| 350 | + ], |
|
| 351 | + 'key' => [ |
|
| 352 | + 'PRIMARY KEY' => 'id_rubrique', |
|
| 353 | + 'KEY lang' => 'lang', |
|
| 354 | + 'KEY id_parent' => 'id_parent', |
|
| 355 | + ], |
|
| 356 | + 'parent' => [ |
|
| 357 | + ['type' => 'rubrique', 'champ' => 'id_parent'] |
|
| 358 | + ], |
|
| 359 | + 'rechercher_champs' => [ |
|
| 360 | + 'titre' => 8, |
|
| 361 | + 'descriptif' => 5, |
|
| 362 | + 'texte' => 1 |
|
| 363 | + ], |
|
| 364 | + 'statut' => [ |
|
| 365 | + [ |
|
| 366 | + 'champ' => 'statut', |
|
| 367 | + 'publie' => 'publie', |
|
| 368 | + 'previsu' => '!', |
|
| 369 | + 'exception' => ['statut', 'tout'] |
|
| 370 | + ], |
|
| 371 | + ], |
|
| 372 | + 'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 373 | + ], |
|
| 374 | + ], |
|
| 375 | + // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 376 | + ['tables_jointures' => ['id_auteur' => 'auteurs_liens']] |
|
| 377 | + ]; |
|
| 378 | + |
|
| 379 | + // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install |
|
| 380 | + // initialiser la signature |
|
| 381 | + $md5 = md5(serialize($infos_tables)); |
|
| 382 | + |
|
| 383 | + $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 384 | + $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 385 | + $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 386 | + |
|
| 387 | + // completer les informations manquantes ou implicites |
|
| 388 | + $all = []; |
|
| 389 | + foreach (array_keys($infos_tables) as $t) { |
|
| 390 | + // les cles numeriques servent a declarer |
|
| 391 | + // les proprietes applicables a tous les objets |
|
| 392 | + // on les mets de cote |
|
| 393 | + if (is_numeric($t)) { |
|
| 394 | + $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 395 | + unset($infos_tables[$t]); |
|
| 396 | + } else { |
|
| 397 | + $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + // repercuter les proprietes generales communes a tous les objets |
|
| 402 | + foreach (array_keys($infos_tables) as $t) { |
|
| 403 | + foreach (array_keys($all) as $i) { |
|
| 404 | + if (in_array($i, ['tables_jointures', 'champs_versionnes'])) { |
|
| 405 | + $add = $all[$i]; |
|
| 406 | + // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
|
| 407 | + // pour les declarations generiques avec cles numeriques |
|
| 408 | + if ($i == 'tables_jointures' && isset($infos_tables[$t][$i]) && (is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0)) { |
|
| 409 | + $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 410 | + foreach ($doublons as $d) { |
|
| 411 | + if ( |
|
| 412 | + is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 413 | + && is_numeric($k = array_search($d, $add)) |
|
| 414 | + ) { |
|
| 415 | + unset($add[$k]); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add); |
|
| 420 | + } else { |
|
| 421 | + $infos_tables[$t][$i] = array_merge_recursive( |
|
| 422 | + $infos_tables[$t][$i] ?? [], |
|
| 423 | + $all[$i] |
|
| 424 | + ); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // completer les tables principales et auxiliaires |
|
| 430 | + // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 431 | + // pour assurer la compat en transition |
|
| 432 | + foreach ($infos_tables as $table => $infos) { |
|
| 433 | + $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 434 | + // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 435 | + // qui a ete appelle avant |
|
| 436 | + $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []); |
|
| 437 | + // l'ajouter au tableau |
|
| 438 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 439 | + if (isset($infos['field']) && isset($infos['key'])) { |
|
| 440 | + foreach (['field', 'key', 'join'] as $k) { |
|
| 441 | + if (isset($infos_tables[$table][$k])) { |
|
| 442 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } else { |
|
| 446 | + // ici on ne renvoie que les declarations, donc RIEN |
|
| 447 | + // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 448 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 449 | + } |
|
| 450 | + if (is_countable($mem) ? count($mem) : 0) { |
|
| 451 | + foreach (array_keys($mem) as $k) { |
|
| 452 | + if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 453 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 454 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 455 | + $mem[$k] |
|
| 456 | + ); |
|
| 457 | + } else { |
|
| 458 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + // recuperer les interfaces (table_titre, table_date) |
|
| 465 | + // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 466 | + // dans le pipeline de declarer_tables_interfaces |
|
| 467 | + include_spip('public/interfaces'); |
|
| 468 | + foreach (array_keys($infos_tables) as $t) { |
|
| 469 | + $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + $deja_la = false; |
|
| 473 | + // signature |
|
| 474 | + $md5 = md5(serialize($infos_tables)); |
|
| 475 | + } |
|
| 476 | + if ($table_sql === '::md5') { |
|
| 477 | + return $md5; |
|
| 478 | + } |
|
| 479 | + if ($table_sql && !isset($infos_tables[$table_sql])) { |
|
| 480 | + #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 481 | + $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 482 | + |
|
| 483 | + return $desc; |
|
| 484 | + } |
|
| 485 | + if ($table_sql) { |
|
| 486 | + return $infos_tables[$table_sql] ?? []; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + return $infos_tables; |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | |
@@ -501,27 +501,27 @@ discard block |
||
| 501 | 501 | **/ |
| 502 | 502 | function base_serial(&$tables_principales) { |
| 503 | 503 | |
| 504 | - $spip_jobs = [ |
|
| 505 | - 'id_job' => 'bigint(21) NOT NULL', |
|
| 506 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 507 | - 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 508 | - 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 509 | - 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 510 | - 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 511 | - 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 512 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 513 | - 'status' => 'tinyint NOT NULL default 1', |
|
| 514 | - ]; |
|
| 515 | - |
|
| 516 | - $spip_jobs_key = [ |
|
| 517 | - 'PRIMARY KEY' => 'id_job', |
|
| 518 | - 'KEY date' => 'date', |
|
| 519 | - 'KEY status' => 'status', |
|
| 520 | - ]; |
|
| 521 | - |
|
| 522 | - /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 523 | - /// il faut donc rajouter, mais pas reinitialiser |
|
| 524 | - $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key]; |
|
| 504 | + $spip_jobs = [ |
|
| 505 | + 'id_job' => 'bigint(21) NOT NULL', |
|
| 506 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 507 | + 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 508 | + 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 509 | + 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 510 | + 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 511 | + 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 512 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 513 | + 'status' => 'tinyint NOT NULL default 1', |
|
| 514 | + ]; |
|
| 515 | + |
|
| 516 | + $spip_jobs_key = [ |
|
| 517 | + 'PRIMARY KEY' => 'id_job', |
|
| 518 | + 'KEY date' => 'date', |
|
| 519 | + 'KEY status' => 'status', |
|
| 520 | + ]; |
|
| 521 | + |
|
| 522 | + /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 523 | + /// il faut donc rajouter, mais pas reinitialiser |
|
| 524 | + $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key]; |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | |
@@ -533,71 +533,71 @@ discard block |
||
| 533 | 533 | * @return void |
| 534 | 534 | **/ |
| 535 | 535 | function base_auxiliaires(&$tables_auxiliaires) { |
| 536 | - $spip_resultats = [ |
|
| 537 | - 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 538 | - 'id' => 'INT UNSIGNED NOT NULL', |
|
| 539 | - 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 540 | - 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 541 | - 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 542 | - 'maj' => 'TIMESTAMP' |
|
| 543 | - ]; |
|
| 544 | - |
|
| 545 | - $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 546 | - ]; |
|
| 547 | - |
|
| 548 | - $spip_auteurs_liens = [ |
|
| 549 | - 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 550 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 551 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 552 | - 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 553 | - ]; |
|
| 554 | - |
|
| 555 | - $spip_auteurs_liens_key = [ |
|
| 556 | - 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 557 | - 'KEY id_auteur' => 'id_auteur', |
|
| 558 | - 'KEY id_objet' => 'id_objet', |
|
| 559 | - 'KEY objet' => 'objet', |
|
| 560 | - ]; |
|
| 561 | - |
|
| 562 | - $spip_meta = [ |
|
| 563 | - 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 564 | - 'valeur' => "text DEFAULT ''", |
|
| 565 | - 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 566 | - 'maj' => 'TIMESTAMP' |
|
| 567 | - ]; |
|
| 568 | - |
|
| 569 | - $spip_meta_key = [ |
|
| 570 | - 'PRIMARY KEY' => 'nom' |
|
| 571 | - ]; |
|
| 572 | - |
|
| 573 | - $spip_jobs_liens = [ |
|
| 574 | - 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 575 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 576 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 577 | - ]; |
|
| 578 | - |
|
| 579 | - $spip_jobs_liens_key = [ |
|
| 580 | - 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 581 | - 'KEY id_job' => 'id_job' |
|
| 582 | - ]; |
|
| 583 | - |
|
| 584 | - $tables_auxiliaires['spip_auteurs_liens'] = [ |
|
| 585 | - 'field' => &$spip_auteurs_liens, |
|
| 586 | - 'key' => &$spip_auteurs_liens_key |
|
| 587 | - ]; |
|
| 588 | - |
|
| 589 | - $tables_auxiliaires['spip_meta'] = [ |
|
| 590 | - 'field' => &$spip_meta, |
|
| 591 | - 'key' => &$spip_meta_key |
|
| 592 | - ]; |
|
| 593 | - $tables_auxiliaires['spip_resultats'] = [ |
|
| 594 | - 'field' => &$spip_resultats, |
|
| 595 | - 'key' => &$spip_resultats_key |
|
| 596 | - ]; |
|
| 597 | - $tables_auxiliaires['spip_jobs_liens'] = [ |
|
| 598 | - 'field' => &$spip_jobs_liens, |
|
| 599 | - 'key' => &$spip_jobs_liens_key |
|
| 600 | - ]; |
|
| 536 | + $spip_resultats = [ |
|
| 537 | + 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 538 | + 'id' => 'INT UNSIGNED NOT NULL', |
|
| 539 | + 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 540 | + 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 541 | + 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 542 | + 'maj' => 'TIMESTAMP' |
|
| 543 | + ]; |
|
| 544 | + |
|
| 545 | + $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 546 | + ]; |
|
| 547 | + |
|
| 548 | + $spip_auteurs_liens = [ |
|
| 549 | + 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 550 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 551 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 552 | + 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 553 | + ]; |
|
| 554 | + |
|
| 555 | + $spip_auteurs_liens_key = [ |
|
| 556 | + 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 557 | + 'KEY id_auteur' => 'id_auteur', |
|
| 558 | + 'KEY id_objet' => 'id_objet', |
|
| 559 | + 'KEY objet' => 'objet', |
|
| 560 | + ]; |
|
| 561 | + |
|
| 562 | + $spip_meta = [ |
|
| 563 | + 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 564 | + 'valeur' => "text DEFAULT ''", |
|
| 565 | + 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 566 | + 'maj' => 'TIMESTAMP' |
|
| 567 | + ]; |
|
| 568 | + |
|
| 569 | + $spip_meta_key = [ |
|
| 570 | + 'PRIMARY KEY' => 'nom' |
|
| 571 | + ]; |
|
| 572 | + |
|
| 573 | + $spip_jobs_liens = [ |
|
| 574 | + 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 575 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 576 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 577 | + ]; |
|
| 578 | + |
|
| 579 | + $spip_jobs_liens_key = [ |
|
| 580 | + 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 581 | + 'KEY id_job' => 'id_job' |
|
| 582 | + ]; |
|
| 583 | + |
|
| 584 | + $tables_auxiliaires['spip_auteurs_liens'] = [ |
|
| 585 | + 'field' => &$spip_auteurs_liens, |
|
| 586 | + 'key' => &$spip_auteurs_liens_key |
|
| 587 | + ]; |
|
| 588 | + |
|
| 589 | + $tables_auxiliaires['spip_meta'] = [ |
|
| 590 | + 'field' => &$spip_meta, |
|
| 591 | + 'key' => &$spip_meta_key |
|
| 592 | + ]; |
|
| 593 | + $tables_auxiliaires['spip_resultats'] = [ |
|
| 594 | + 'field' => &$spip_resultats, |
|
| 595 | + 'key' => &$spip_resultats_key |
|
| 596 | + ]; |
|
| 597 | + $tables_auxiliaires['spip_jobs_liens'] = [ |
|
| 598 | + 'field' => &$spip_jobs_liens, |
|
| 599 | + 'key' => &$spip_jobs_liens_key |
|
| 600 | + ]; |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | |
@@ -654,129 +654,129 @@ discard block |
||
| 654 | 654 | * @return array |
| 655 | 655 | */ |
| 656 | 656 | function renseigner_table_objet_sql($table_sql, &$infos) { |
| 657 | - if (!isset($infos['type'])) { |
|
| 658 | - // si on arrive de base/trouver_table, on a la cle primaire : |
|
| 659 | - // s'en servir pour extrapoler le type |
|
| 660 | - if (isset($infos['key']['PRIMARY KEY'])) { |
|
| 661 | - $primary = $infos['key']['PRIMARY KEY']; |
|
| 662 | - $primary = explode(',', (string) $primary); |
|
| 663 | - $primary = reset($primary); |
|
| 664 | - $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
|
| 665 | - } else { |
|
| 666 | - $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql); |
|
| 667 | - } |
|
| 668 | - } |
|
| 669 | - if (!isset($infos['type_surnoms'])) { |
|
| 670 | - $infos['type_surnoms'] = []; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - if (!isset($infos['table_objet'])) { |
|
| 674 | - $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql); |
|
| 675 | - } |
|
| 676 | - if (!isset($infos['table_objet_surnoms'])) { |
|
| 677 | - $infos['table_objet_surnoms'] = []; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - if (!isset($infos['principale'])) { |
|
| 681 | - $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - // normaliser pour pouvoir tester en php $infos['principale']? |
|
| 685 | - // et dans une boucle {principale=oui} |
|
| 686 | - $infos['principale'] = (($infos['principale'] && $infos['principale'] != 'non') ? 'oui' : false); |
|
| 687 | - |
|
| 688 | - // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
|
| 689 | - // et dans une boucle {editable=oui} |
|
| 690 | - if (!isset($infos['editable'])) { |
|
| 691 | - $infos['editable'] = 'oui'; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - $infos['editable'] = (($infos['editable'] && $infos['editable'] != 'non') ? 'oui' : false); |
|
| 695 | - |
|
| 696 | - // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
|
| 697 | - // seules les exceptions sont donc a declarer |
|
| 698 | - if (!isset($infos['page'])) { |
|
| 699 | - $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - if (!isset($infos['url_voir'])) { |
|
| 703 | - $infos['url_voir'] = $infos['type']; |
|
| 704 | - } |
|
| 705 | - if (!isset($infos['url_edit'])) { |
|
| 706 | - $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 707 | - } |
|
| 708 | - if (!isset($infos['icone_objet'])) { |
|
| 709 | - $infos['icone_objet'] = $infos['type']; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - // chaines de langue |
|
| 713 | - // par defaut : objet:icone_xxx_objet |
|
| 714 | - if (!isset($infos['texte_retour'])) { |
|
| 715 | - $infos['texte_retour'] = 'icone_retour'; |
|
| 716 | - } |
|
| 717 | - if (!isset($infos['texte_modifier'])) { |
|
| 718 | - $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 719 | - } |
|
| 720 | - if (!isset($infos['texte_creer'])) { |
|
| 721 | - $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 722 | - } |
|
| 723 | - if (!isset($infos['texte_creer_associer'])) { |
|
| 724 | - $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 725 | - } |
|
| 726 | - if (!isset($infos['texte_ajouter'])) { |
|
| 727 | - // Ajouter un X |
|
| 728 | - $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 729 | - } |
|
| 730 | - if (!isset($infos['texte_objets'])) { |
|
| 731 | - $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 732 | - } |
|
| 733 | - if (!isset($infos['texte_objet'])) { |
|
| 734 | - $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 735 | - } |
|
| 736 | - if (!isset($infos['texte_logo_objet'])) { |
|
| 737 | - // objet:titre_logo_objet "Logo de ce X" |
|
| 738 | - $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 739 | - } |
|
| 740 | - if (!isset($infos['texte_langue_objet'])) { |
|
| 741 | - // objet:texte_langue_objet "Langue de ce X" |
|
| 742 | - $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 743 | - } |
|
| 744 | - if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
|
| 745 | - // "Ce X est une traduction du X numéro :" |
|
| 746 | - $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - // objet:info_aucun_objet |
|
| 750 | - if (!isset($infos['info_aucun_objet'])) { |
|
| 751 | - $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 752 | - } |
|
| 753 | - // objet:info_1_objet |
|
| 754 | - if (!isset($infos['info_1_objet'])) { |
|
| 755 | - $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 756 | - } |
|
| 757 | - // objet:info_nb_objets |
|
| 758 | - if (!isset($infos['info_nb_objets'])) { |
|
| 759 | - $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - if (!isset($infos['champs_editables'])) { |
|
| 763 | - $infos['champs_editables'] = []; |
|
| 764 | - } |
|
| 765 | - if (!isset($infos['champs_versionnes'])) { |
|
| 766 | - $infos['champs_versionnes'] = []; |
|
| 767 | - } |
|
| 768 | - if (!isset($infos['rechercher_champs'])) { |
|
| 769 | - $infos['rechercher_champs'] = []; |
|
| 770 | - } |
|
| 771 | - if (!isset($infos['rechercher_jointures'])) { |
|
| 772 | - $infos['rechercher_jointures'] = []; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - if (!isset($infos['modeles'])) { |
|
| 776 | - $infos['modeles'] = [$infos['type']]; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - return $infos; |
|
| 657 | + if (!isset($infos['type'])) { |
|
| 658 | + // si on arrive de base/trouver_table, on a la cle primaire : |
|
| 659 | + // s'en servir pour extrapoler le type |
|
| 660 | + if (isset($infos['key']['PRIMARY KEY'])) { |
|
| 661 | + $primary = $infos['key']['PRIMARY KEY']; |
|
| 662 | + $primary = explode(',', (string) $primary); |
|
| 663 | + $primary = reset($primary); |
|
| 664 | + $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
|
| 665 | + } else { |
|
| 666 | + $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql); |
|
| 667 | + } |
|
| 668 | + } |
|
| 669 | + if (!isset($infos['type_surnoms'])) { |
|
| 670 | + $infos['type_surnoms'] = []; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + if (!isset($infos['table_objet'])) { |
|
| 674 | + $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql); |
|
| 675 | + } |
|
| 676 | + if (!isset($infos['table_objet_surnoms'])) { |
|
| 677 | + $infos['table_objet_surnoms'] = []; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + if (!isset($infos['principale'])) { |
|
| 681 | + $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + // normaliser pour pouvoir tester en php $infos['principale']? |
|
| 685 | + // et dans une boucle {principale=oui} |
|
| 686 | + $infos['principale'] = (($infos['principale'] && $infos['principale'] != 'non') ? 'oui' : false); |
|
| 687 | + |
|
| 688 | + // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
|
| 689 | + // et dans une boucle {editable=oui} |
|
| 690 | + if (!isset($infos['editable'])) { |
|
| 691 | + $infos['editable'] = 'oui'; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + $infos['editable'] = (($infos['editable'] && $infos['editable'] != 'non') ? 'oui' : false); |
|
| 695 | + |
|
| 696 | + // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
|
| 697 | + // seules les exceptions sont donc a declarer |
|
| 698 | + if (!isset($infos['page'])) { |
|
| 699 | + $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + if (!isset($infos['url_voir'])) { |
|
| 703 | + $infos['url_voir'] = $infos['type']; |
|
| 704 | + } |
|
| 705 | + if (!isset($infos['url_edit'])) { |
|
| 706 | + $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 707 | + } |
|
| 708 | + if (!isset($infos['icone_objet'])) { |
|
| 709 | + $infos['icone_objet'] = $infos['type']; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + // chaines de langue |
|
| 713 | + // par defaut : objet:icone_xxx_objet |
|
| 714 | + if (!isset($infos['texte_retour'])) { |
|
| 715 | + $infos['texte_retour'] = 'icone_retour'; |
|
| 716 | + } |
|
| 717 | + if (!isset($infos['texte_modifier'])) { |
|
| 718 | + $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 719 | + } |
|
| 720 | + if (!isset($infos['texte_creer'])) { |
|
| 721 | + $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 722 | + } |
|
| 723 | + if (!isset($infos['texte_creer_associer'])) { |
|
| 724 | + $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 725 | + } |
|
| 726 | + if (!isset($infos['texte_ajouter'])) { |
|
| 727 | + // Ajouter un X |
|
| 728 | + $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 729 | + } |
|
| 730 | + if (!isset($infos['texte_objets'])) { |
|
| 731 | + $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 732 | + } |
|
| 733 | + if (!isset($infos['texte_objet'])) { |
|
| 734 | + $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 735 | + } |
|
| 736 | + if (!isset($infos['texte_logo_objet'])) { |
|
| 737 | + // objet:titre_logo_objet "Logo de ce X" |
|
| 738 | + $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 739 | + } |
|
| 740 | + if (!isset($infos['texte_langue_objet'])) { |
|
| 741 | + // objet:texte_langue_objet "Langue de ce X" |
|
| 742 | + $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 743 | + } |
|
| 744 | + if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
|
| 745 | + // "Ce X est une traduction du X numéro :" |
|
| 746 | + $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + // objet:info_aucun_objet |
|
| 750 | + if (!isset($infos['info_aucun_objet'])) { |
|
| 751 | + $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 752 | + } |
|
| 753 | + // objet:info_1_objet |
|
| 754 | + if (!isset($infos['info_1_objet'])) { |
|
| 755 | + $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 756 | + } |
|
| 757 | + // objet:info_nb_objets |
|
| 758 | + if (!isset($infos['info_nb_objets'])) { |
|
| 759 | + $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + if (!isset($infos['champs_editables'])) { |
|
| 763 | + $infos['champs_editables'] = []; |
|
| 764 | + } |
|
| 765 | + if (!isset($infos['champs_versionnes'])) { |
|
| 766 | + $infos['champs_versionnes'] = []; |
|
| 767 | + } |
|
| 768 | + if (!isset($infos['rechercher_champs'])) { |
|
| 769 | + $infos['rechercher_champs'] = []; |
|
| 770 | + } |
|
| 771 | + if (!isset($infos['rechercher_jointures'])) { |
|
| 772 | + $infos['rechercher_jointures'] = []; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + if (!isset($infos['modeles'])) { |
|
| 776 | + $infos['modeles'] = [$infos['type']]; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + return $infos; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -793,30 +793,30 @@ discard block |
||
| 793 | 793 | * @return array |
| 794 | 794 | */ |
| 795 | 795 | function renseigner_table_objet_interfaces($table_sql, &$infos) { |
| 796 | - if (!isset($infos['titre'])) { |
|
| 797 | - if (isset($infos['table_objet']) && isset($GLOBALS['table_titre'][$infos['table_objet']])) { |
|
| 798 | - $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
|
| 799 | - } else { |
|
| 800 | - $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,"); |
|
| 801 | - $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang"); |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - if (!isset($infos['date'])) { |
|
| 805 | - if (isset($infos['table_objet']) && isset($GLOBALS['table_date'][$infos['table_objet']])) { |
|
| 806 | - $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
|
| 807 | - } else { |
|
| 808 | - $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : ''); |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? ''; |
|
| 813 | - $infos['tables_jointures'] ??= []; |
|
| 814 | - |
|
| 815 | - if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 816 | - $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - return $infos; |
|
| 796 | + if (!isset($infos['titre'])) { |
|
| 797 | + if (isset($infos['table_objet']) && isset($GLOBALS['table_titre'][$infos['table_objet']])) { |
|
| 798 | + $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
|
| 799 | + } else { |
|
| 800 | + $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,"); |
|
| 801 | + $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang"); |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + if (!isset($infos['date'])) { |
|
| 805 | + if (isset($infos['table_objet']) && isset($GLOBALS['table_date'][$infos['table_objet']])) { |
|
| 806 | + $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
|
| 807 | + } else { |
|
| 808 | + $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : ''); |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? ''; |
|
| 813 | + $infos['tables_jointures'] ??= []; |
|
| 814 | + |
|
| 815 | + if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 816 | + $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + return $infos; |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -827,13 +827,13 @@ discard block |
||
| 827 | 827 | * Liste et descriptions des tables principales |
| 828 | 828 | **/ |
| 829 | 829 | function lister_tables_principales() { |
| 830 | - static $done = false; |
|
| 831 | - if (!$done || !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) { |
|
| 832 | - lister_tables_objets_sql(); |
|
| 833 | - $done = true; |
|
| 834 | - } |
|
| 830 | + static $done = false; |
|
| 831 | + if (!$done || !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) { |
|
| 832 | + lister_tables_objets_sql(); |
|
| 833 | + $done = true; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | - return $GLOBALS['tables_principales']; |
|
| 836 | + return $GLOBALS['tables_principales']; |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -844,13 +844,13 @@ discard block |
||
| 844 | 844 | * Liste et descriptions des tables auxiliaires |
| 845 | 845 | **/ |
| 846 | 846 | function lister_tables_auxiliaires() { |
| 847 | - static $done = false; |
|
| 848 | - if (!$done || !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) { |
|
| 849 | - lister_tables_objets_sql(); |
|
| 850 | - $done = true; |
|
| 851 | - } |
|
| 847 | + static $done = false; |
|
| 848 | + if (!$done || !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) { |
|
| 849 | + lister_tables_objets_sql(); |
|
| 850 | + $done = true; |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | - return $GLOBALS['tables_auxiliaires']; |
|
| 853 | + return $GLOBALS['tables_auxiliaires']; |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | /** |
@@ -859,44 +859,44 @@ discard block |
||
| 859 | 859 | * @return array |
| 860 | 860 | */ |
| 861 | 861 | function lister_tables_objets_surnoms() { |
| 862 | - static $surnoms = null; |
|
| 863 | - static $md5 = null; |
|
| 864 | - if ( |
|
| 865 | - !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 866 | - ) { |
|
| 867 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 868 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 869 | - // declarer_table_objets_sql |
|
| 870 | - $surnoms = pipeline( |
|
| 871 | - 'declarer_tables_objets_surnoms', |
|
| 872 | - [ |
|
| 873 | - # pour les modeles |
|
| 874 | - # a enlever ? |
|
| 875 | - 'doc' => 'documents', |
|
| 876 | - 'img' => 'documents', |
|
| 877 | - 'emb' => 'documents', |
|
| 878 | - ] |
|
| 879 | - ); |
|
| 880 | - $infos_tables = lister_tables_objets_sql(); |
|
| 881 | - foreach ($infos_tables as $t => $infos) { |
|
| 882 | - // cas de base type=>table |
|
| 883 | - // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 884 | - if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 885 | - // optimisations pour table_objet |
|
| 886 | - //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 887 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['table_objet']; |
|
| 888 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['table_objet']; |
|
| 889 | - if (is_array($infos['table_objet_surnoms']) && count($infos['table_objet_surnoms'])) { |
|
| 890 | - foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 891 | - $surnoms[$surnom] = $infos['table_objet']; |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - return $surnoms; |
|
| 862 | + static $surnoms = null; |
|
| 863 | + static $md5 = null; |
|
| 864 | + if ( |
|
| 865 | + !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 866 | + ) { |
|
| 867 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 868 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 869 | + // declarer_table_objets_sql |
|
| 870 | + $surnoms = pipeline( |
|
| 871 | + 'declarer_tables_objets_surnoms', |
|
| 872 | + [ |
|
| 873 | + # pour les modeles |
|
| 874 | + # a enlever ? |
|
| 875 | + 'doc' => 'documents', |
|
| 876 | + 'img' => 'documents', |
|
| 877 | + 'emb' => 'documents', |
|
| 878 | + ] |
|
| 879 | + ); |
|
| 880 | + $infos_tables = lister_tables_objets_sql(); |
|
| 881 | + foreach ($infos_tables as $t => $infos) { |
|
| 882 | + // cas de base type=>table |
|
| 883 | + // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 884 | + if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 885 | + // optimisations pour table_objet |
|
| 886 | + //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 887 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['table_objet']; |
|
| 888 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['table_objet']; |
|
| 889 | + if (is_array($infos['table_objet_surnoms']) && count($infos['table_objet_surnoms'])) { |
|
| 890 | + foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 891 | + $surnoms[$surnom] = $infos['table_objet']; |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + return $surnoms; |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | /** |
@@ -905,34 +905,34 @@ discard block |
||
| 905 | 905 | * @return array |
| 906 | 906 | */ |
| 907 | 907 | function lister_types_surnoms() { |
| 908 | - static $surnoms = null; |
|
| 909 | - static $md5 = null; |
|
| 910 | - if ( |
|
| 911 | - !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 912 | - ) { |
|
| 913 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 914 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 915 | - // declarer_table_objets_sql |
|
| 916 | - $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 917 | - $infos_tables = lister_tables_objets_sql(); |
|
| 918 | - foreach ($infos_tables as $t => $infos) { |
|
| 919 | - if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 920 | - // optimisations pour objet_type |
|
| 921 | - //$surnoms[$infos['type']] = $infos['type']; |
|
| 922 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['type']; |
|
| 923 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['type']; |
|
| 924 | - // surnoms declares |
|
| 925 | - if (is_array($infos['type_surnoms']) && count($infos['type_surnoms'])) { |
|
| 926 | - foreach ($infos['type_surnoms'] as $surnom) { |
|
| 927 | - $surnoms[$surnom] = $infos['type']; |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - return $surnoms; |
|
| 908 | + static $surnoms = null; |
|
| 909 | + static $md5 = null; |
|
| 910 | + if ( |
|
| 911 | + !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 912 | + ) { |
|
| 913 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 914 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 915 | + // declarer_table_objets_sql |
|
| 916 | + $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 917 | + $infos_tables = lister_tables_objets_sql(); |
|
| 918 | + foreach ($infos_tables as $t => $infos) { |
|
| 919 | + if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 920 | + // optimisations pour objet_type |
|
| 921 | + //$surnoms[$infos['type']] = $infos['type']; |
|
| 922 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['type']; |
|
| 923 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['type']; |
|
| 924 | + // surnoms declares |
|
| 925 | + if (is_array($infos['type_surnoms']) && count($infos['type_surnoms'])) { |
|
| 926 | + foreach ($infos['type_surnoms'] as $surnom) { |
|
| 927 | + $surnoms[$surnom] = $infos['type']; |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + return $surnoms; |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | /** |
@@ -946,22 +946,22 @@ discard block |
||
| 946 | 946 | * Couples (nom de la table SQL => même nom, sans 'spip_' devant) |
| 947 | 947 | **/ |
| 948 | 948 | function lister_tables_spip($serveur = '') { |
| 949 | - static $tables = []; |
|
| 950 | - if (!isset($tables[$serveur])) { |
|
| 951 | - $tables[$serveur] = []; |
|
| 952 | - if (!function_exists('sql_alltable')) { |
|
| 953 | - include_spip('base/abstract_sql'); |
|
| 954 | - } |
|
| 955 | - $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 956 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 957 | - $spip = $connexion['prefixe'] . '_'; |
|
| 958 | - foreach ($ts as $t) { |
|
| 959 | - $t = substr((string) $t, strlen($spip)); |
|
| 960 | - $tables[$serveur]["spip_$t"] = $t; |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - return $tables[$serveur]; |
|
| 949 | + static $tables = []; |
|
| 950 | + if (!isset($tables[$serveur])) { |
|
| 951 | + $tables[$serveur] = []; |
|
| 952 | + if (!function_exists('sql_alltable')) { |
|
| 953 | + include_spip('base/abstract_sql'); |
|
| 954 | + } |
|
| 955 | + $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 956 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 957 | + $spip = $connexion['prefixe'] . '_'; |
|
| 958 | + foreach ($ts as $t) { |
|
| 959 | + $t = substr((string) $t, strlen($spip)); |
|
| 960 | + $tables[$serveur]["spip_$t"] = $t; |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + return $tables[$serveur]; |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | |
@@ -976,18 +976,18 @@ discard block |
||
| 976 | 976 | * Couples (nom de la table SQL => même nom) |
| 977 | 977 | **/ |
| 978 | 978 | function lister_toutes_tables($serveur) { |
| 979 | - static $tables = []; |
|
| 980 | - if (!isset($tables[$serveur])) { |
|
| 981 | - $tables[$serveur] = []; |
|
| 982 | - if (!function_exists('sql_alltable')) { |
|
| 983 | - include_spip('base/abstract_sql'); |
|
| 984 | - } |
|
| 985 | - $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 986 | - foreach ($ts as $t) { |
|
| 987 | - $tables[$serveur][$t] = $t; |
|
| 988 | - } |
|
| 989 | - } |
|
| 990 | - return $tables[$serveur]; |
|
| 979 | + static $tables = []; |
|
| 980 | + if (!isset($tables[$serveur])) { |
|
| 981 | + $tables[$serveur] = []; |
|
| 982 | + if (!function_exists('sql_alltable')) { |
|
| 983 | + include_spip('base/abstract_sql'); |
|
| 984 | + } |
|
| 985 | + $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 986 | + foreach ($ts as $t) { |
|
| 987 | + $tables[$serveur][$t] = $t; |
|
| 988 | + } |
|
| 989 | + } |
|
| 990 | + return $tables[$serveur]; |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | /** |
@@ -1008,37 +1008,37 @@ discard block |
||
| 1008 | 1008 | **/ |
| 1009 | 1009 | function table_objet(string $type, string $serveur = ''): string { |
| 1010 | 1010 | |
| 1011 | - if ($type) { |
|
| 1012 | - $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1013 | - } |
|
| 1014 | - if (!strlen($type)) { |
|
| 1015 | - return ''; |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - $surnoms = lister_tables_objets_surnoms(); |
|
| 1019 | - if (isset($surnoms[$type])) { |
|
| 1020 | - return $surnoms[$type]; |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - if ($serveur !== false) { |
|
| 1024 | - $t = lister_tables_spip($serveur); |
|
| 1025 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1026 | - $typetrim = rtrim($type, 's') . 's'; |
|
| 1027 | - if ( |
|
| 1028 | - (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1029 | - ) { |
|
| 1030 | - return $desc['id_table']; |
|
| 1031 | - } elseif ( |
|
| 1032 | - (isset($t[$type]) || in_array($type, $t)) && ($desc = $trouver_table($type, $serveur)) |
|
| 1033 | - ) { |
|
| 1034 | - return $desc['id_table']; |
|
| 1035 | - } |
|
| 1036 | - |
|
| 1037 | - spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1038 | - #spip_log(debug_backtrace(),'db'); |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1011 | + if ($type) { |
|
| 1012 | + $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1013 | + } |
|
| 1014 | + if (!strlen($type)) { |
|
| 1015 | + return ''; |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + $surnoms = lister_tables_objets_surnoms(); |
|
| 1019 | + if (isset($surnoms[$type])) { |
|
| 1020 | + return $surnoms[$type]; |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + if ($serveur !== false) { |
|
| 1024 | + $t = lister_tables_spip($serveur); |
|
| 1025 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1026 | + $typetrim = rtrim($type, 's') . 's'; |
|
| 1027 | + if ( |
|
| 1028 | + (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1029 | + ) { |
|
| 1030 | + return $desc['id_table']; |
|
| 1031 | + } elseif ( |
|
| 1032 | + (isset($t[$type]) || in_array($type, $t)) && ($desc = $trouver_table($type, $serveur)) |
|
| 1033 | + ) { |
|
| 1034 | + return $desc['id_table']; |
|
| 1035 | + } |
|
| 1036 | + |
|
| 1037 | + spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1038 | + #spip_log(debug_backtrace(),'db'); |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | /** |
@@ -1059,33 +1059,33 @@ discard block |
||
| 1059 | 1059 | **/ |
| 1060 | 1060 | function table_objet_sql(string $type, string $serveur = ''): string { |
| 1061 | 1061 | |
| 1062 | - $nom = table_objet($type, $serveur); |
|
| 1063 | - if (!strlen($nom)) { |
|
| 1064 | - return ''; |
|
| 1065 | - } |
|
| 1066 | - if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1067 | - // eviter de multiples inclusions |
|
| 1068 | - include_spip('public/interfaces'); |
|
| 1069 | - } |
|
| 1070 | - if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1071 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1072 | - $nom = "spip_$nom"; |
|
| 1073 | - } else { |
|
| 1074 | - $infos_tables = lister_tables_objets_sql(); |
|
| 1075 | - if (isset($infos_tables["spip_$nom"])) { |
|
| 1076 | - $nom = "spip_$nom"; |
|
| 1077 | - } elseif ($serveur !== false) { |
|
| 1078 | - $t = lister_tables_spip($serveur); |
|
| 1079 | - if (isset($t[$nom]) || in_array($nom, $t)) { |
|
| 1080 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1081 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1082 | - return $desc['table_sql']; |
|
| 1083 | - } |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - return $nom; |
|
| 1062 | + $nom = table_objet($type, $serveur); |
|
| 1063 | + if (!strlen($nom)) { |
|
| 1064 | + return ''; |
|
| 1065 | + } |
|
| 1066 | + if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1067 | + // eviter de multiples inclusions |
|
| 1068 | + include_spip('public/interfaces'); |
|
| 1069 | + } |
|
| 1070 | + if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1071 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1072 | + $nom = "spip_$nom"; |
|
| 1073 | + } else { |
|
| 1074 | + $infos_tables = lister_tables_objets_sql(); |
|
| 1075 | + if (isset($infos_tables["spip_$nom"])) { |
|
| 1076 | + $nom = "spip_$nom"; |
|
| 1077 | + } elseif ($serveur !== false) { |
|
| 1078 | + $t = lister_tables_spip($serveur); |
|
| 1079 | + if (isset($t[$nom]) || in_array($nom, $t)) { |
|
| 1080 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1081 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1082 | + return $desc['table_sql']; |
|
| 1083 | + } |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + return $nom; |
|
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | 1091 | /** |
@@ -1104,34 +1104,34 @@ discard block |
||
| 1104 | 1104 | * Nom de la clé primaire |
| 1105 | 1105 | **/ |
| 1106 | 1106 | function id_table_objet(string $type, string $serveur = ''): ?string { |
| 1107 | - static $trouver_table = null; |
|
| 1108 | - $type = objet_type($type, $serveur); |
|
| 1109 | - if (!$type) { |
|
| 1110 | - return null; |
|
| 1111 | - } |
|
| 1112 | - $t = table_objet($type); |
|
| 1113 | - if (!$trouver_table) { |
|
| 1114 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - $ts = lister_tables_spip($serveur); |
|
| 1118 | - if ( |
|
| 1119 | - in_array($t, $ts) || in_array($t, lister_toutes_tables($serveur)) |
|
| 1120 | - ) { |
|
| 1121 | - $desc = $trouver_table($t, $serveur); |
|
| 1122 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1123 | - return $desc['key']['PRIMARY KEY']; |
|
| 1124 | - } |
|
| 1125 | - if (!$desc || isset($desc['field']["id_$type"])) { |
|
| 1126 | - return "id_$type"; |
|
| 1127 | - } |
|
| 1128 | - // sinon renvoyer le premier champ de la table... |
|
| 1129 | - $keys = array_keys($desc['field']); |
|
| 1130 | - |
|
| 1131 | - return array_shift($keys); |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - return "id_$type"; |
|
| 1107 | + static $trouver_table = null; |
|
| 1108 | + $type = objet_type($type, $serveur); |
|
| 1109 | + if (!$type) { |
|
| 1110 | + return null; |
|
| 1111 | + } |
|
| 1112 | + $t = table_objet($type); |
|
| 1113 | + if (!$trouver_table) { |
|
| 1114 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + $ts = lister_tables_spip($serveur); |
|
| 1118 | + if ( |
|
| 1119 | + in_array($t, $ts) || in_array($t, lister_toutes_tables($serveur)) |
|
| 1120 | + ) { |
|
| 1121 | + $desc = $trouver_table($t, $serveur); |
|
| 1122 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1123 | + return $desc['key']['PRIMARY KEY']; |
|
| 1124 | + } |
|
| 1125 | + if (!$desc || isset($desc['field']["id_$type"])) { |
|
| 1126 | + return "id_$type"; |
|
| 1127 | + } |
|
| 1128 | + // sinon renvoyer le premier champ de la table... |
|
| 1129 | + $keys = array_keys($desc['field']); |
|
| 1130 | + |
|
| 1131 | + return array_shift($keys); |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + return "id_$type"; |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | /** |
@@ -1150,60 +1150,60 @@ discard block |
||
| 1150 | 1150 | * Type de l'objet |
| 1151 | 1151 | **/ |
| 1152 | 1152 | function objet_type(string $table_objet, string $serveur = ''): ?string { |
| 1153 | - if (!$table_objet) { |
|
| 1154 | - return null; |
|
| 1155 | - } |
|
| 1156 | - $surnoms = lister_types_surnoms(); |
|
| 1157 | - |
|
| 1158 | - // scenario de base |
|
| 1159 | - // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1160 | - // et la marque du pluriel |
|
| 1161 | - // on accepte id_xx en entree aussi |
|
| 1162 | - $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1163 | - if (isset($surnoms[$type])) { |
|
| 1164 | - return $surnoms[$type]; |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - // securite : eliminer les caracteres non \w |
|
| 1168 | - $type = preg_replace(',[^\w-],', '', $type); |
|
| 1169 | - |
|
| 1170 | - // si le type redonne bien la table c'est bon |
|
| 1171 | - // oui si table_objet ressemblait deja a un type |
|
| 1172 | - if ( |
|
| 1173 | - $type == $table_objet |
|
| 1174 | - || table_objet($type, $serveur) === $table_objet |
|
| 1175 | - || table_objet_sql($type, $serveur) === $table_objet |
|
| 1176 | - ) { |
|
| 1177 | - return $type; |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - // si on ne veut pas chercher en base |
|
| 1181 | - if ($serveur === false) { |
|
| 1182 | - return $type; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1186 | - // car le s a la fin est incertain |
|
| 1187 | - // notamment en cas de pluriel derogatoire |
|
| 1188 | - // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1189 | - // une declaration jeu => jeux, journal => journaux |
|
| 1190 | - // dans le pipeline declarer_tables_objets_surnoms |
|
| 1191 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1192 | - $ts = lister_tables_spip($serveur); |
|
| 1193 | - $desc = false; |
|
| 1194 | - if (in_array($table_objet, $ts)) { |
|
| 1195 | - $desc = $trouver_table($table_objet); |
|
| 1196 | - } |
|
| 1197 | - if (!$desc && in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1198 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 1199 | - } |
|
| 1200 | - // si le type est declare : bingo ! |
|
| 1201 | - if ($desc && isset($desc['type'])) { |
|
| 1202 | - return $desc['type']; |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - // on a fait ce qu'on a pu |
|
| 1206 | - return $type; |
|
| 1153 | + if (!$table_objet) { |
|
| 1154 | + return null; |
|
| 1155 | + } |
|
| 1156 | + $surnoms = lister_types_surnoms(); |
|
| 1157 | + |
|
| 1158 | + // scenario de base |
|
| 1159 | + // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1160 | + // et la marque du pluriel |
|
| 1161 | + // on accepte id_xx en entree aussi |
|
| 1162 | + $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1163 | + if (isset($surnoms[$type])) { |
|
| 1164 | + return $surnoms[$type]; |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + // securite : eliminer les caracteres non \w |
|
| 1168 | + $type = preg_replace(',[^\w-],', '', $type); |
|
| 1169 | + |
|
| 1170 | + // si le type redonne bien la table c'est bon |
|
| 1171 | + // oui si table_objet ressemblait deja a un type |
|
| 1172 | + if ( |
|
| 1173 | + $type == $table_objet |
|
| 1174 | + || table_objet($type, $serveur) === $table_objet |
|
| 1175 | + || table_objet_sql($type, $serveur) === $table_objet |
|
| 1176 | + ) { |
|
| 1177 | + return $type; |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + // si on ne veut pas chercher en base |
|
| 1181 | + if ($serveur === false) { |
|
| 1182 | + return $type; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1186 | + // car le s a la fin est incertain |
|
| 1187 | + // notamment en cas de pluriel derogatoire |
|
| 1188 | + // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1189 | + // une declaration jeu => jeux, journal => journaux |
|
| 1190 | + // dans le pipeline declarer_tables_objets_surnoms |
|
| 1191 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1192 | + $ts = lister_tables_spip($serveur); |
|
| 1193 | + $desc = false; |
|
| 1194 | + if (in_array($table_objet, $ts)) { |
|
| 1195 | + $desc = $trouver_table($table_objet); |
|
| 1196 | + } |
|
| 1197 | + if (!$desc && in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1198 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 1199 | + } |
|
| 1200 | + // si le type est declare : bingo ! |
|
| 1201 | + if ($desc && isset($desc['type'])) { |
|
| 1202 | + return $desc['type']; |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + // on a fait ce qu'on a pu |
|
| 1206 | + return $type; |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | /** |
@@ -1219,58 +1219,58 @@ discard block |
||
| 1219 | 1219 | * @return bool |
| 1220 | 1220 | */ |
| 1221 | 1221 | function objet_test_si_publie($objet, $id_objet, $serveur = '') { |
| 1222 | - // voir si une fonction est definie pour faire le boulot |
|
| 1223 | - // elle a la priorite dans ce cas |
|
| 1224 | - if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1225 | - return $f($objet, $id_objet, $serveur); |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - // sinon on se fie a la declaration de l'objet si presente |
|
| 1229 | - $id_table = $table_objet = table_objet($objet); |
|
| 1230 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1231 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1232 | - if ( |
|
| 1233 | - ($desc = $trouver_table($table_objet, $serveur)) |
|
| 1234 | - && isset($desc['statut']) |
|
| 1235 | - && $desc['statut'] |
|
| 1236 | - ) { |
|
| 1237 | - $boucle = new Boucle(); |
|
| 1238 | - $boucle->show = $desc; |
|
| 1239 | - $boucle->nom = 'objet_test_si_publie'; |
|
| 1240 | - $boucle->id_boucle = $id_table; |
|
| 1241 | - $boucle->id_table = $id_table; |
|
| 1242 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 1243 | - $boucle->sql_serveur = $serveur; |
|
| 1244 | - $boucle->select[] = $id_table_objet; |
|
| 1245 | - $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1246 | - $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet; |
|
| 1247 | - |
|
| 1248 | - $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1249 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 1250 | - $boucle->descr['gram'] = 'html'; |
|
| 1251 | - |
|
| 1252 | - include_spip('public/compiler'); |
|
| 1253 | - include_spip('public/composer'); |
|
| 1254 | - instituer_boucle($boucle, false, true); |
|
| 1255 | - $res = calculer_select( |
|
| 1256 | - $boucle->select, |
|
| 1257 | - $boucle->from, |
|
| 1258 | - $boucle->from_type, |
|
| 1259 | - $boucle->where, |
|
| 1260 | - $boucle->join, |
|
| 1261 | - $boucle->group, |
|
| 1262 | - $boucle->order, |
|
| 1263 | - $boucle->limit, |
|
| 1264 | - $boucle->having, |
|
| 1265 | - $table_objet, |
|
| 1266 | - $id_table, |
|
| 1267 | - $serveur |
|
| 1268 | - ); |
|
| 1269 | - return (bool) sql_fetch($res); |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1273 | - return true; |
|
| 1222 | + // voir si une fonction est definie pour faire le boulot |
|
| 1223 | + // elle a la priorite dans ce cas |
|
| 1224 | + if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1225 | + return $f($objet, $id_objet, $serveur); |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + // sinon on se fie a la declaration de l'objet si presente |
|
| 1229 | + $id_table = $table_objet = table_objet($objet); |
|
| 1230 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1231 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1232 | + if ( |
|
| 1233 | + ($desc = $trouver_table($table_objet, $serveur)) |
|
| 1234 | + && isset($desc['statut']) |
|
| 1235 | + && $desc['statut'] |
|
| 1236 | + ) { |
|
| 1237 | + $boucle = new Boucle(); |
|
| 1238 | + $boucle->show = $desc; |
|
| 1239 | + $boucle->nom = 'objet_test_si_publie'; |
|
| 1240 | + $boucle->id_boucle = $id_table; |
|
| 1241 | + $boucle->id_table = $id_table; |
|
| 1242 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 1243 | + $boucle->sql_serveur = $serveur; |
|
| 1244 | + $boucle->select[] = $id_table_objet; |
|
| 1245 | + $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1246 | + $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet; |
|
| 1247 | + |
|
| 1248 | + $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1249 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 1250 | + $boucle->descr['gram'] = 'html'; |
|
| 1251 | + |
|
| 1252 | + include_spip('public/compiler'); |
|
| 1253 | + include_spip('public/composer'); |
|
| 1254 | + instituer_boucle($boucle, false, true); |
|
| 1255 | + $res = calculer_select( |
|
| 1256 | + $boucle->select, |
|
| 1257 | + $boucle->from, |
|
| 1258 | + $boucle->from_type, |
|
| 1259 | + $boucle->where, |
|
| 1260 | + $boucle->join, |
|
| 1261 | + $boucle->group, |
|
| 1262 | + $boucle->order, |
|
| 1263 | + $boucle->limit, |
|
| 1264 | + $boucle->having, |
|
| 1265 | + $table_objet, |
|
| 1266 | + $id_table, |
|
| 1267 | + $serveur |
|
| 1268 | + ); |
|
| 1269 | + return (bool) sql_fetch($res); |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1273 | + return true; |
|
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | 1276 | |
@@ -1305,124 +1305,124 @@ discard block |
||
| 1305 | 1305 | * Retourne un tableau décrivant les parents trouvés |
| 1306 | 1306 | */ |
| 1307 | 1307 | function objet_lister_parents($objet, $id_objet, $parent_direct_seulement = false) { |
| 1308 | - $parents = []; |
|
| 1309 | - |
|
| 1310 | - // Si on trouve une ou des méthodes de parent |
|
| 1311 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1312 | - // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1313 | - include_spip('base/abstract_sql'); |
|
| 1314 | - $table_objet = table_objet_sql($objet); |
|
| 1315 | - $cle_objet = id_table_objet($objet); |
|
| 1316 | - $id_objet = (int) $id_objet; |
|
| 1317 | - |
|
| 1318 | - // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1319 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1320 | - // Champ identifiant le parent (id et éventuellement le type) |
|
| 1321 | - // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1322 | - // de celle de l'objet source |
|
| 1323 | - $select = []; |
|
| 1324 | - if (isset($parent_methode['champ'])) { |
|
| 1325 | - $select[] = $parent_methode['champ']; |
|
| 1326 | - } |
|
| 1327 | - if (isset($parent_methode['champ_type'])) { |
|
| 1328 | - $select[] = $parent_methode['champ_type']; |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1332 | - $condition_objet_invalide = false; |
|
| 1333 | - $where = []; |
|
| 1334 | - if (!isset($parent_methode['table'])) { |
|
| 1335 | - // Le parent est stocké dans la même table que l'objet source : |
|
| 1336 | - // -- toutes les conditions s'appliquent à la table source. |
|
| 1337 | - $table = $table_objet; |
|
| 1338 | - $where = ["$cle_objet = $id_objet"]; |
|
| 1339 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1340 | - if (isset($parent_methode['condition'])) { |
|
| 1341 | - $where[] = $parent_methode['condition']; |
|
| 1342 | - } |
|
| 1343 | - } elseif (!$parent_direct_seulement) { |
|
| 1344 | - // Le parent est stocké dans une table différente de l'objet source. |
|
| 1345 | - // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1346 | - // Si non, on peut arrêter le traitement. |
|
| 1347 | - if (isset($parent_methode['condition'])) { |
|
| 1348 | - $where = [ |
|
| 1349 | - "$cle_objet = $id_objet", |
|
| 1350 | - $parent_methode['condition'] |
|
| 1351 | - ]; |
|
| 1352 | - if (!sql_countsel($table_objet, $where)) { |
|
| 1353 | - $condition_objet_invalide = true; |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1356 | - |
|
| 1357 | - // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1358 | - // la requête sur la table qui accueille le parent. |
|
| 1359 | - if (!$condition_objet_invalide) { |
|
| 1360 | - $table = $parent_methode['table']; |
|
| 1361 | - // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1362 | - $where = []; |
|
| 1363 | - // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est |
|
| 1364 | - // le même que celui de l'objet source. |
|
| 1365 | - $where[] = isset($parent_methode['source_champ']) |
|
| 1366 | - ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1367 | - : "$cle_objet = $id_objet"; |
|
| 1368 | - if (isset($parent_methode['source_champ_type'])) { |
|
| 1369 | - $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1370 | - } |
|
| 1371 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1372 | - if (isset($parent_methode['table_condition'])) { |
|
| 1373 | - $where[] = $parent_methode['table_condition']; |
|
| 1374 | - } |
|
| 1375 | - } |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - // On lance la requête de récupération du parent |
|
| 1379 | - $is_table_lien = (str_contains((string) $table, '_liens') && str_ends_with((string) $table, '_liens')); |
|
| 1380 | - if ( |
|
| 1381 | - !$condition_objet_invalide |
|
| 1382 | - && $where |
|
| 1383 | - && ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1384 | - ) { |
|
| 1385 | - foreach ($lignes as $ligne) { |
|
| 1386 | - // Si le type est fixe |
|
| 1387 | - if (isset($parent_methode['type'])) { |
|
| 1388 | - $parent = [ |
|
| 1389 | - 'objet' => $parent_methode['type'], |
|
| 1390 | - 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1391 | - 'champ' => $parent_methode['champ'], |
|
| 1392 | - 'table' => $table, |
|
| 1393 | - ]; |
|
| 1394 | - } |
|
| 1395 | - elseif (isset($parent_methode['champ_type'])) { |
|
| 1396 | - $parent = [ |
|
| 1397 | - 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1398 | - 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1399 | - 'champ' => $parent_methode['champ'], |
|
| 1400 | - 'champ_type' => $parent_methode['champ_type'], |
|
| 1401 | - 'table' => $table, |
|
| 1402 | - ]; |
|
| 1403 | - } |
|
| 1404 | - if ($is_table_lien) { |
|
| 1405 | - $parent['lien'] = $ligne; |
|
| 1406 | - } |
|
| 1407 | - $parents[] = $parent; |
|
| 1408 | - } |
|
| 1409 | - } |
|
| 1410 | - } |
|
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - // On passe par un pipeline avant de retourner |
|
| 1414 | - $parents = pipeline( |
|
| 1415 | - 'objet_lister_parents', |
|
| 1416 | - [ |
|
| 1417 | - 'args' => [ |
|
| 1418 | - 'objet' => $objet, |
|
| 1419 | - 'id_objet' => $id_objet, |
|
| 1420 | - ], |
|
| 1421 | - 'data' => $parents, |
|
| 1422 | - ] |
|
| 1423 | - ); |
|
| 1424 | - |
|
| 1425 | - return $parents; |
|
| 1308 | + $parents = []; |
|
| 1309 | + |
|
| 1310 | + // Si on trouve une ou des méthodes de parent |
|
| 1311 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1312 | + // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1313 | + include_spip('base/abstract_sql'); |
|
| 1314 | + $table_objet = table_objet_sql($objet); |
|
| 1315 | + $cle_objet = id_table_objet($objet); |
|
| 1316 | + $id_objet = (int) $id_objet; |
|
| 1317 | + |
|
| 1318 | + // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1319 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1320 | + // Champ identifiant le parent (id et éventuellement le type) |
|
| 1321 | + // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1322 | + // de celle de l'objet source |
|
| 1323 | + $select = []; |
|
| 1324 | + if (isset($parent_methode['champ'])) { |
|
| 1325 | + $select[] = $parent_methode['champ']; |
|
| 1326 | + } |
|
| 1327 | + if (isset($parent_methode['champ_type'])) { |
|
| 1328 | + $select[] = $parent_methode['champ_type']; |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1332 | + $condition_objet_invalide = false; |
|
| 1333 | + $where = []; |
|
| 1334 | + if (!isset($parent_methode['table'])) { |
|
| 1335 | + // Le parent est stocké dans la même table que l'objet source : |
|
| 1336 | + // -- toutes les conditions s'appliquent à la table source. |
|
| 1337 | + $table = $table_objet; |
|
| 1338 | + $where = ["$cle_objet = $id_objet"]; |
|
| 1339 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1340 | + if (isset($parent_methode['condition'])) { |
|
| 1341 | + $where[] = $parent_methode['condition']; |
|
| 1342 | + } |
|
| 1343 | + } elseif (!$parent_direct_seulement) { |
|
| 1344 | + // Le parent est stocké dans une table différente de l'objet source. |
|
| 1345 | + // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1346 | + // Si non, on peut arrêter le traitement. |
|
| 1347 | + if (isset($parent_methode['condition'])) { |
|
| 1348 | + $where = [ |
|
| 1349 | + "$cle_objet = $id_objet", |
|
| 1350 | + $parent_methode['condition'] |
|
| 1351 | + ]; |
|
| 1352 | + if (!sql_countsel($table_objet, $where)) { |
|
| 1353 | + $condition_objet_invalide = true; |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | + |
|
| 1357 | + // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1358 | + // la requête sur la table qui accueille le parent. |
|
| 1359 | + if (!$condition_objet_invalide) { |
|
| 1360 | + $table = $parent_methode['table']; |
|
| 1361 | + // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1362 | + $where = []; |
|
| 1363 | + // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est |
|
| 1364 | + // le même que celui de l'objet source. |
|
| 1365 | + $where[] = isset($parent_methode['source_champ']) |
|
| 1366 | + ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1367 | + : "$cle_objet = $id_objet"; |
|
| 1368 | + if (isset($parent_methode['source_champ_type'])) { |
|
| 1369 | + $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1370 | + } |
|
| 1371 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1372 | + if (isset($parent_methode['table_condition'])) { |
|
| 1373 | + $where[] = $parent_methode['table_condition']; |
|
| 1374 | + } |
|
| 1375 | + } |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + // On lance la requête de récupération du parent |
|
| 1379 | + $is_table_lien = (str_contains((string) $table, '_liens') && str_ends_with((string) $table, '_liens')); |
|
| 1380 | + if ( |
|
| 1381 | + !$condition_objet_invalide |
|
| 1382 | + && $where |
|
| 1383 | + && ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1384 | + ) { |
|
| 1385 | + foreach ($lignes as $ligne) { |
|
| 1386 | + // Si le type est fixe |
|
| 1387 | + if (isset($parent_methode['type'])) { |
|
| 1388 | + $parent = [ |
|
| 1389 | + 'objet' => $parent_methode['type'], |
|
| 1390 | + 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1391 | + 'champ' => $parent_methode['champ'], |
|
| 1392 | + 'table' => $table, |
|
| 1393 | + ]; |
|
| 1394 | + } |
|
| 1395 | + elseif (isset($parent_methode['champ_type'])) { |
|
| 1396 | + $parent = [ |
|
| 1397 | + 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1398 | + 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1399 | + 'champ' => $parent_methode['champ'], |
|
| 1400 | + 'champ_type' => $parent_methode['champ_type'], |
|
| 1401 | + 'table' => $table, |
|
| 1402 | + ]; |
|
| 1403 | + } |
|
| 1404 | + if ($is_table_lien) { |
|
| 1405 | + $parent['lien'] = $ligne; |
|
| 1406 | + } |
|
| 1407 | + $parents[] = $parent; |
|
| 1408 | + } |
|
| 1409 | + } |
|
| 1410 | + } |
|
| 1411 | + } |
|
| 1412 | + |
|
| 1413 | + // On passe par un pipeline avant de retourner |
|
| 1414 | + $parents = pipeline( |
|
| 1415 | + 'objet_lister_parents', |
|
| 1416 | + [ |
|
| 1417 | + 'args' => [ |
|
| 1418 | + 'objet' => $objet, |
|
| 1419 | + 'id_objet' => $id_objet, |
|
| 1420 | + ], |
|
| 1421 | + 'data' => $parents, |
|
| 1422 | + ] |
|
| 1423 | + ); |
|
| 1424 | + |
|
| 1425 | + return $parents; |
|
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | 1428 | /** |
@@ -1434,17 +1434,17 @@ discard block |
||
| 1434 | 1434 | * @return array |
| 1435 | 1435 | */ |
| 1436 | 1436 | function objet_lister_parents_par_type($objet, $id_objet) { |
| 1437 | - $parents = objet_lister_parents($objet, $id_objet); |
|
| 1437 | + $parents = objet_lister_parents($objet, $id_objet); |
|
| 1438 | 1438 | |
| 1439 | - $parents_par_type = []; |
|
| 1440 | - foreach ($parents as $parent) { |
|
| 1441 | - if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1442 | - $parents_par_type[$parent['objet']] = []; |
|
| 1443 | - } |
|
| 1444 | - $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1445 | - } |
|
| 1439 | + $parents_par_type = []; |
|
| 1440 | + foreach ($parents as $parent) { |
|
| 1441 | + if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1442 | + $parents_par_type[$parent['objet']] = []; |
|
| 1443 | + } |
|
| 1444 | + $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1445 | + } |
|
| 1446 | 1446 | |
| 1447 | - return $parents_par_type; |
|
| 1447 | + return $parents_par_type; |
|
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | |
@@ -1477,85 +1477,85 @@ discard block |
||
| 1477 | 1477 | * Retourne un tableau de tableaux, avec comme clés les types des objets, et dans chacun un tableau des identifiants trouvés |
| 1478 | 1478 | */ |
| 1479 | 1479 | function objet_lister_enfants($objet, $id_objet) { |
| 1480 | - $enfants = []; |
|
| 1481 | - |
|
| 1482 | - // Si on trouve des types d'enfants et leurs méthodes |
|
| 1483 | - if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1484 | - include_spip('base/abstract_sql'); |
|
| 1485 | - $id_objet = (int) $id_objet; |
|
| 1486 | - |
|
| 1487 | - // On parcourt tous les types d'enfants trouvés |
|
| 1488 | - foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1489 | - // On construit les conditions d'identification du parent |
|
| 1490 | - $where = []; |
|
| 1491 | - // -- L'identifiant du parent |
|
| 1492 | - if (isset($_methode_parent['champ'])) { |
|
| 1493 | - $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1494 | - } |
|
| 1495 | - // -- Si le parent est variable |
|
| 1496 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1497 | - $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1498 | - } |
|
| 1499 | - |
|
| 1500 | - // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1501 | - if (!isset($_methode_parent['table'])) { |
|
| 1502 | - // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1503 | - $table_enfant = table_objet_sql($objet_enfant); |
|
| 1504 | - $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1505 | - |
|
| 1506 | - // S'il y a une condition supplémentaire |
|
| 1507 | - if (isset($_methode_parent['condition'])) { |
|
| 1508 | - $where[] = $_methode_parent['condition']; |
|
| 1509 | - } |
|
| 1510 | - } else { |
|
| 1511 | - // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1512 | - $table_enfant = $_methode_parent['table']; |
|
| 1513 | - $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant); |
|
| 1514 | - |
|
| 1515 | - // S'il y a une condition supplémentaire |
|
| 1516 | - if (isset($_methode_parent['table_condition'])) { |
|
| 1517 | - $where[] = $_methode_parent['table_condition']; |
|
| 1518 | - } |
|
| 1519 | - } |
|
| 1520 | - |
|
| 1521 | - // On lance la requête |
|
| 1522 | - $is_table_lien = (str_contains((string) $table_enfant, '_liens') && str_ends_with((string) $table_enfant, '_liens')); |
|
| 1523 | - if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1524 | - $enfant = [ |
|
| 1525 | - 'objet' => $objet_enfant, |
|
| 1526 | - 'id_objet' => 0, |
|
| 1527 | - 'table' => $table_enfant |
|
| 1528 | - ]; |
|
| 1529 | - if (isset($_methode_parent['champ'])) { |
|
| 1530 | - $enfant['champ'] = $_methode_parent['champ']; |
|
| 1531 | - } |
|
| 1532 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1533 | - $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1534 | - } |
|
| 1535 | - foreach ($rows as $row) { |
|
| 1536 | - $enfant['id_objet'] = (int) $row[$cle_objet_enfant]; |
|
| 1537 | - if ($is_table_lien) { |
|
| 1538 | - $enfant['lien'] = $row; |
|
| 1539 | - } |
|
| 1540 | - $enfants[] = $enfant; |
|
| 1541 | - } |
|
| 1542 | - } |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - // On passe par un pipeline avant de retourner |
|
| 1547 | - $enfants = pipeline( |
|
| 1548 | - 'objet_lister_enfants', |
|
| 1549 | - [ |
|
| 1550 | - 'args' => [ |
|
| 1551 | - 'objet' => $objet, |
|
| 1552 | - 'id_objet' => $id_objet, |
|
| 1553 | - ], |
|
| 1554 | - 'data' => $enfants, |
|
| 1555 | - ] |
|
| 1556 | - ); |
|
| 1557 | - |
|
| 1558 | - return $enfants; |
|
| 1480 | + $enfants = []; |
|
| 1481 | + |
|
| 1482 | + // Si on trouve des types d'enfants et leurs méthodes |
|
| 1483 | + if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1484 | + include_spip('base/abstract_sql'); |
|
| 1485 | + $id_objet = (int) $id_objet; |
|
| 1486 | + |
|
| 1487 | + // On parcourt tous les types d'enfants trouvés |
|
| 1488 | + foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1489 | + // On construit les conditions d'identification du parent |
|
| 1490 | + $where = []; |
|
| 1491 | + // -- L'identifiant du parent |
|
| 1492 | + if (isset($_methode_parent['champ'])) { |
|
| 1493 | + $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1494 | + } |
|
| 1495 | + // -- Si le parent est variable |
|
| 1496 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1497 | + $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1498 | + } |
|
| 1499 | + |
|
| 1500 | + // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1501 | + if (!isset($_methode_parent['table'])) { |
|
| 1502 | + // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1503 | + $table_enfant = table_objet_sql($objet_enfant); |
|
| 1504 | + $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1505 | + |
|
| 1506 | + // S'il y a une condition supplémentaire |
|
| 1507 | + if (isset($_methode_parent['condition'])) { |
|
| 1508 | + $where[] = $_methode_parent['condition']; |
|
| 1509 | + } |
|
| 1510 | + } else { |
|
| 1511 | + // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1512 | + $table_enfant = $_methode_parent['table']; |
|
| 1513 | + $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant); |
|
| 1514 | + |
|
| 1515 | + // S'il y a une condition supplémentaire |
|
| 1516 | + if (isset($_methode_parent['table_condition'])) { |
|
| 1517 | + $where[] = $_methode_parent['table_condition']; |
|
| 1518 | + } |
|
| 1519 | + } |
|
| 1520 | + |
|
| 1521 | + // On lance la requête |
|
| 1522 | + $is_table_lien = (str_contains((string) $table_enfant, '_liens') && str_ends_with((string) $table_enfant, '_liens')); |
|
| 1523 | + if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1524 | + $enfant = [ |
|
| 1525 | + 'objet' => $objet_enfant, |
|
| 1526 | + 'id_objet' => 0, |
|
| 1527 | + 'table' => $table_enfant |
|
| 1528 | + ]; |
|
| 1529 | + if (isset($_methode_parent['champ'])) { |
|
| 1530 | + $enfant['champ'] = $_methode_parent['champ']; |
|
| 1531 | + } |
|
| 1532 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1533 | + $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1534 | + } |
|
| 1535 | + foreach ($rows as $row) { |
|
| 1536 | + $enfant['id_objet'] = (int) $row[$cle_objet_enfant]; |
|
| 1537 | + if ($is_table_lien) { |
|
| 1538 | + $enfant['lien'] = $row; |
|
| 1539 | + } |
|
| 1540 | + $enfants[] = $enfant; |
|
| 1541 | + } |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + // On passe par un pipeline avant de retourner |
|
| 1547 | + $enfants = pipeline( |
|
| 1548 | + 'objet_lister_enfants', |
|
| 1549 | + [ |
|
| 1550 | + 'args' => [ |
|
| 1551 | + 'objet' => $objet, |
|
| 1552 | + 'id_objet' => $id_objet, |
|
| 1553 | + ], |
|
| 1554 | + 'data' => $enfants, |
|
| 1555 | + ] |
|
| 1556 | + ); |
|
| 1557 | + |
|
| 1558 | + return $enfants; |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | /** |
@@ -1567,17 +1567,17 @@ discard block |
||
| 1567 | 1567 | * @return array |
| 1568 | 1568 | */ |
| 1569 | 1569 | function objet_lister_enfants_par_type($objet, $id_objet) { |
| 1570 | - $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1570 | + $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1571 | 1571 | |
| 1572 | - $enfants_par_type = []; |
|
| 1573 | - foreach ($enfants as $enfant) { |
|
| 1574 | - if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1575 | - $enfants_par_type[$enfant['objet']] = []; |
|
| 1576 | - } |
|
| 1577 | - $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1578 | - } |
|
| 1572 | + $enfants_par_type = []; |
|
| 1573 | + foreach ($enfants as $enfant) { |
|
| 1574 | + if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1575 | + $enfants_par_type[$enfant['objet']] = []; |
|
| 1576 | + } |
|
| 1577 | + $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1578 | + } |
|
| 1579 | 1579 | |
| 1580 | - return $enfants_par_type; |
|
| 1580 | + return $enfants_par_type; |
|
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | 1583 | /** |
@@ -1589,31 +1589,31 @@ discard block |
||
| 1589 | 1589 | * Retourne un tableau de tableau contenant les informations de type et de champ pour trouver le parent ou false sinon |
| 1590 | 1590 | */ |
| 1591 | 1591 | function objet_type_decrire_infos_parents($objet) { |
| 1592 | - static $parents = []; |
|
| 1593 | - |
|
| 1594 | - // Si on ne l'a pas encore cherché pour cet objet |
|
| 1595 | - if (!isset($parents[$objet])) { |
|
| 1596 | - $parents[$objet] = false; |
|
| 1597 | - $table = table_objet_sql($objet); |
|
| 1598 | - |
|
| 1599 | - // Si on trouve bien la description de cet objet |
|
| 1600 | - if ($infos = lister_tables_objets_sql($table)) { |
|
| 1601 | - if (isset($infos['parent']) && is_array($infos['parent'])) { |
|
| 1602 | - // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1603 | - // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1604 | - // de description |
|
| 1605 | - $parents[$objet] = isset($infos['parent'][0]) ? $infos['parent'] : [$infos['parent']]; |
|
| 1606 | - } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1607 | - // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1608 | - $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1609 | - } elseif (isset($infos['field']['id_parent'])) { |
|
| 1610 | - // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1611 | - $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1612 | - } |
|
| 1613 | - } |
|
| 1614 | - } |
|
| 1615 | - |
|
| 1616 | - return $parents[$objet]; |
|
| 1592 | + static $parents = []; |
|
| 1593 | + |
|
| 1594 | + // Si on ne l'a pas encore cherché pour cet objet |
|
| 1595 | + if (!isset($parents[$objet])) { |
|
| 1596 | + $parents[$objet] = false; |
|
| 1597 | + $table = table_objet_sql($objet); |
|
| 1598 | + |
|
| 1599 | + // Si on trouve bien la description de cet objet |
|
| 1600 | + if ($infos = lister_tables_objets_sql($table)) { |
|
| 1601 | + if (isset($infos['parent']) && is_array($infos['parent'])) { |
|
| 1602 | + // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1603 | + // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1604 | + // de description |
|
| 1605 | + $parents[$objet] = isset($infos['parent'][0]) ? $infos['parent'] : [$infos['parent']]; |
|
| 1606 | + } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1607 | + // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1608 | + $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1609 | + } elseif (isset($infos['field']['id_parent'])) { |
|
| 1610 | + // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1611 | + $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1612 | + } |
|
| 1613 | + } |
|
| 1614 | + } |
|
| 1615 | + |
|
| 1616 | + return $parents[$objet]; |
|
| 1617 | 1617 | } |
| 1618 | 1618 | |
| 1619 | 1619 | /** |
@@ -1625,36 +1625,36 @@ discard block |
||
| 1625 | 1625 | * Retourne un tableau de tableaux contenant chacun les informations d'un type d'enfant |
| 1626 | 1626 | */ |
| 1627 | 1627 | function objet_type_decrire_infos_enfants($objet) { |
| 1628 | - static $enfants = []; |
|
| 1629 | - |
|
| 1630 | - // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1631 | - if (!isset($enfants[$objet])) { |
|
| 1632 | - $enfants[$objet] = []; |
|
| 1633 | - $tables = lister_tables_objets_sql(); |
|
| 1634 | - |
|
| 1635 | - // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1636 | - foreach ($tables as $table => $infos) { |
|
| 1637 | - $objet_enfant = objet_type($table); |
|
| 1638 | - |
|
| 1639 | - // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1640 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1641 | - // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1642 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1643 | - // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1644 | - if (!isset($parent_methode['exclus']) || !in_array($objet, $parent_methode['exclus'])) { |
|
| 1645 | - // Si le type du parent est fixe et directement l'objet demandé |
|
| 1646 | - if (isset($parent_methode['type']) && isset($parent_methode['champ']) && $parent_methode['type'] == $objet) { |
|
| 1647 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1648 | - } |
|
| 1649 | - // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1650 | - elseif (isset($parent_methode['champ_type']) && isset($parent_methode['champ'])) { |
|
| 1651 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1652 | - } |
|
| 1653 | - } |
|
| 1654 | - } |
|
| 1655 | - } |
|
| 1656 | - } |
|
| 1657 | - } |
|
| 1658 | - |
|
| 1659 | - return $enfants[$objet]; |
|
| 1628 | + static $enfants = []; |
|
| 1629 | + |
|
| 1630 | + // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1631 | + if (!isset($enfants[$objet])) { |
|
| 1632 | + $enfants[$objet] = []; |
|
| 1633 | + $tables = lister_tables_objets_sql(); |
|
| 1634 | + |
|
| 1635 | + // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1636 | + foreach ($tables as $table => $infos) { |
|
| 1637 | + $objet_enfant = objet_type($table); |
|
| 1638 | + |
|
| 1639 | + // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1640 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1641 | + // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1642 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1643 | + // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1644 | + if (!isset($parent_methode['exclus']) || !in_array($objet, $parent_methode['exclus'])) { |
|
| 1645 | + // Si le type du parent est fixe et directement l'objet demandé |
|
| 1646 | + if (isset($parent_methode['type']) && isset($parent_methode['champ']) && $parent_methode['type'] == $objet) { |
|
| 1647 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1648 | + } |
|
| 1649 | + // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1650 | + elseif (isset($parent_methode['champ_type']) && isset($parent_methode['champ'])) { |
|
| 1651 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1652 | + } |
|
| 1653 | + } |
|
| 1654 | + } |
|
| 1655 | + } |
|
| 1656 | + } |
|
| 1657 | + } |
|
| 1658 | + |
|
| 1659 | + return $enfants[$objet]; |
|
| 1660 | 1660 | } |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | $infos['url_voir'] = $infos['type']; |
| 704 | 704 | } |
| 705 | 705 | if (!isset($infos['url_edit'])) { |
| 706 | - $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 706 | + $infos['url_edit'] = $infos['url_voir'].($infos['editable'] ? '_edit' : ''); |
|
| 707 | 707 | } |
| 708 | 708 | if (!isset($infos['icone_objet'])) { |
| 709 | 709 | $infos['icone_objet'] = $infos['type']; |
@@ -715,48 +715,48 @@ discard block |
||
| 715 | 715 | $infos['texte_retour'] = 'icone_retour'; |
| 716 | 716 | } |
| 717 | 717 | if (!isset($infos['texte_modifier'])) { |
| 718 | - $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 718 | + $infos['texte_modifier'] = $infos['type'].':'.'icone_modifier_'.$infos['type']; |
|
| 719 | 719 | } |
| 720 | 720 | if (!isset($infos['texte_creer'])) { |
| 721 | - $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 721 | + $infos['texte_creer'] = $infos['type'].':'.'icone_creer_'.$infos['type']; |
|
| 722 | 722 | } |
| 723 | 723 | if (!isset($infos['texte_creer_associer'])) { |
| 724 | - $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 724 | + $infos['texte_creer_associer'] = $infos['type'].':'.'texte_creer_associer_'.$infos['type']; |
|
| 725 | 725 | } |
| 726 | 726 | if (!isset($infos['texte_ajouter'])) { |
| 727 | 727 | // Ajouter un X |
| 728 | - $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 728 | + $infos['texte_ajouter'] = $infos['type'].':'.'texte_ajouter_'.$infos['type']; |
|
| 729 | 729 | } |
| 730 | 730 | if (!isset($infos['texte_objets'])) { |
| 731 | - $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 731 | + $infos['texte_objets'] = $infos['type'].':'.'titre_'.$infos['table_objet']; |
|
| 732 | 732 | } |
| 733 | 733 | if (!isset($infos['texte_objet'])) { |
| 734 | - $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 734 | + $infos['texte_objet'] = $infos['type'].':'.'titre_'.$infos['type']; |
|
| 735 | 735 | } |
| 736 | 736 | if (!isset($infos['texte_logo_objet'])) { |
| 737 | 737 | // objet:titre_logo_objet "Logo de ce X" |
| 738 | - $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 738 | + $infos['texte_logo_objet'] = $infos['type'].':'.'titre_logo_'.$infos['type']; |
|
| 739 | 739 | } |
| 740 | 740 | if (!isset($infos['texte_langue_objet'])) { |
| 741 | 741 | // objet:texte_langue_objet "Langue de ce X" |
| 742 | - $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 742 | + $infos['texte_langue_objet'] = $infos['type'].':'.'titre_langue_'.$infos['type']; |
|
| 743 | 743 | } |
| 744 | 744 | if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
| 745 | 745 | // "Ce X est une traduction du X numéro :" |
| 746 | - $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 746 | + $infos['texte_definir_comme_traduction_objet'] = $infos['type'].':'.'texte_definir_comme_traduction_'.$infos['type']; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | // objet:info_aucun_objet |
| 750 | 750 | if (!isset($infos['info_aucun_objet'])) { |
| 751 | - $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 751 | + $infos['info_aucun_objet'] = $infos['type'].':'.'info_aucun_'.$infos['type']; |
|
| 752 | 752 | } |
| 753 | 753 | // objet:info_1_objet |
| 754 | 754 | if (!isset($infos['info_1_objet'])) { |
| 755 | - $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 755 | + $infos['info_1_objet'] = $infos['type'].':'.'info_1_'.$infos['type']; |
|
| 756 | 756 | } |
| 757 | 757 | // objet:info_nb_objets |
| 758 | 758 | if (!isset($infos['info_nb_objets'])) { |
| 759 | - $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 759 | + $infos['info_nb_objets'] = $infos['type'].':'.'info_nb_'.$infos['table_objet']; |
|
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | if (!isset($infos['champs_editables'])) { |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | } |
| 955 | 955 | $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
| 956 | 956 | $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
| 957 | - $spip = $connexion['prefixe'] . '_'; |
|
| 957 | + $spip = $connexion['prefixe'].'_'; |
|
| 958 | 958 | foreach ($ts as $t) { |
| 959 | 959 | $t = substr((string) $t, strlen($spip)); |
| 960 | 960 | $tables[$serveur]["spip_$t"] = $t; |
@@ -1023,9 +1023,9 @@ discard block |
||
| 1023 | 1023 | if ($serveur !== false) { |
| 1024 | 1024 | $t = lister_tables_spip($serveur); |
| 1025 | 1025 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 1026 | - $typetrim = rtrim($type, 's') . 's'; |
|
| 1026 | + $typetrim = rtrim($type, 's').'s'; |
|
| 1027 | 1027 | if ( |
| 1028 | - (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1028 | + (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's').'s', $serveur)) |
|
| 1029 | 1029 | ) { |
| 1030 | 1030 | return $desc['id_table']; |
| 1031 | 1031 | } elseif ( |
@@ -1034,11 +1034,11 @@ discard block |
||
| 1034 | 1034 | return $desc['id_table']; |
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | - spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1037 | + spip_log('table_objet('.$type.') calculee sans verification'); |
|
| 1038 | 1038 | #spip_log(debug_backtrace(),'db'); |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | - return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1041 | + return rtrim($type, 's').'s'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | /** |
@@ -1221,7 +1221,7 @@ discard block |
||
| 1221 | 1221 | function objet_test_si_publie($objet, $id_objet, $serveur = '') { |
| 1222 | 1222 | // voir si une fonction est definie pour faire le boulot |
| 1223 | 1223 | // elle a la priorite dans ce cas |
| 1224 | - if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1224 | + if ($f = charger_fonction($objet.'_test_si_publie', 'base', true)) { |
|
| 1225 | 1225 | return $f($objet, $id_objet, $serveur); |
| 1226 | 1226 | } |
| 1227 | 1227 | |
@@ -1243,7 +1243,7 @@ discard block |
||
| 1243 | 1243 | $boucle->sql_serveur = $serveur; |
| 1244 | 1244 | $boucle->select[] = $id_table_objet; |
| 1245 | 1245 | $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
| 1246 | - $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet; |
|
| 1246 | + $boucle->where[] = $id_table.'.'.$id_table_objet.'='.(int) $id_objet; |
|
| 1247 | 1247 | |
| 1248 | 1248 | $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
| 1249 | 1249 | $boucle->descr['sourcefile'] = 'internal'; |
@@ -1366,7 +1366,7 @@ discard block |
||
| 1366 | 1366 | ? "{$parent_methode['source_champ']} = $id_objet" |
| 1367 | 1367 | : "$cle_objet = $id_objet"; |
| 1368 | 1368 | if (isset($parent_methode['source_champ_type'])) { |
| 1369 | - $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1369 | + $where[] = "{$parent_methode['source_champ_type']} = ".sql_quote($objet); |
|
| 1370 | 1370 | } |
| 1371 | 1371 | // -- Condition supplémentaire sur la détection du parent |
| 1372 | 1372 | if (isset($parent_methode['table_condition'])) { |
@@ -1490,11 +1490,11 @@ discard block |
||
| 1490 | 1490 | $where = []; |
| 1491 | 1491 | // -- L'identifiant du parent |
| 1492 | 1492 | if (isset($_methode_parent['champ'])) { |
| 1493 | - $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1493 | + $where[] = $_methode_parent['champ'].' = '.$id_objet; |
|
| 1494 | 1494 | } |
| 1495 | 1495 | // -- Si le parent est variable |
| 1496 | 1496 | if (isset($_methode_parent['champ_type'])) { |
| 1497 | - $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1497 | + $where[] = $_methode_parent['champ_type'].' = '.sql_quote($objet); |
|
| 1498 | 1498 | } |
| 1499 | 1499 | |
| 1500 | 1500 | // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
@@ -1391,8 +1391,7 @@ |
||
| 1391 | 1391 | 'champ' => $parent_methode['champ'], |
| 1392 | 1392 | 'table' => $table, |
| 1393 | 1393 | ]; |
| 1394 | - } |
|
| 1395 | - elseif (isset($parent_methode['champ_type'])) { |
|
| 1394 | + } elseif (isset($parent_methode['champ_type'])) { |
|
| 1396 | 1395 | $parent = [ |
| 1397 | 1396 | 'objet' => $ligne[$parent_methode['champ_type']], |
| 1398 | 1397 | 'id_objet' => (int) $ligne[$parent_methode['champ']], |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -28,27 +28,27 @@ discard block |
||
| 28 | 28 | * @param string $titre Inutilisé |
| 29 | 29 | **/ |
| 30 | 30 | function base_delete_all_dist($titre) { |
| 31 | - $delete = _request('delete'); |
|
| 32 | - $res = []; |
|
| 33 | - if (is_array($delete)) { |
|
| 34 | - foreach ($delete as $table) { |
|
| 35 | - if (sql_drop_table($table)) { |
|
| 36 | - $res[] = $table; |
|
| 37 | - } else { |
|
| 38 | - spip_log("SPIP n'a pas pu detruire $table.", _LOG_ERREUR); |
|
| 39 | - } |
|
| 40 | - } |
|
| 31 | + $delete = _request('delete'); |
|
| 32 | + $res = []; |
|
| 33 | + if (is_array($delete)) { |
|
| 34 | + foreach ($delete as $table) { |
|
| 35 | + if (sql_drop_table($table)) { |
|
| 36 | + $res[] = $table; |
|
| 37 | + } else { |
|
| 38 | + spip_log("SPIP n'a pas pu detruire $table.", _LOG_ERREUR); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - // un pipeline pour detruire les tables installees par les plugins |
|
| 43 | - pipeline('delete_tables', ''); |
|
| 42 | + // un pipeline pour detruire les tables installees par les plugins |
|
| 43 | + pipeline('delete_tables', ''); |
|
| 44 | 44 | |
| 45 | - spip_unlink(_FILE_CONNECT); |
|
| 46 | - spip_unlink(_FILE_CHMOD); |
|
| 47 | - spip_unlink(_FILE_META); |
|
| 48 | - spip_unlink(_ACCESS_FILE_NAME); |
|
| 49 | - spip_unlink(_CACHE_RUBRIQUES); |
|
| 50 | - } |
|
| 51 | - $d = is_countable($delete) ? count($delete) : 0; |
|
| 52 | - $r = count($res); |
|
| 53 | - spip_log("Tables detruites: $r sur $d: " . implode(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 45 | + spip_unlink(_FILE_CONNECT); |
|
| 46 | + spip_unlink(_FILE_CHMOD); |
|
| 47 | + spip_unlink(_FILE_META); |
|
| 48 | + spip_unlink(_ACCESS_FILE_NAME); |
|
| 49 | + spip_unlink(_CACHE_RUBRIQUES); |
|
| 50 | + } |
|
| 51 | + $d = is_countable($delete) ? count($delete) : 0; |
|
| 52 | + $r = count($res); |
|
| 53 | + spip_log("Tables detruites: $r sur $d: " . implode(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 54 | 54 | } |
@@ -50,5 +50,5 @@ |
||
| 50 | 50 | } |
| 51 | 51 | $d = is_countable($delete) ? count($delete) : 0; |
| 52 | 52 | $r = count($res); |
| 53 | - spip_log("Tables detruites: $r sur $d: " . implode(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 53 | + spip_log("Tables detruites: $r sur $d: ".implode(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 54 | 54 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | 26 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 27 | - return; |
|
| 27 | + return; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** Version de l'API SQL */ |
@@ -44,37 +44,37 @@ discard block |
||
| 44 | 44 | * contexte de l'erreur |
| 45 | 45 | **/ |
| 46 | 46 | function sql_error_backtrace($compil_info = false) { |
| 47 | - $trace = debug_backtrace(); |
|
| 48 | - $caller = array_shift($trace); |
|
| 49 | - while (count($trace) && (empty($trace[0]['file']) || $trace[0]['file'] === $caller['file'] || $trace[0]['file'] === __FILE__)) { |
|
| 50 | - array_shift($trace); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($compil_info) { |
|
| 54 | - return [ |
|
| 55 | - $trace[0]['file'],// sourcefile |
|
| 56 | - '', //nom |
|
| 57 | - (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 58 | - . $trace[0]['function'] . '();' |
|
| 59 | - . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 60 | - $trace[0]['line'], // ligne |
|
| 61 | - $GLOBALS['spip_lang'], // lang |
|
| 62 | - ]; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 66 | - $f = []; |
|
| 67 | - while (count($trace) && ($t = array_shift($trace))) { |
|
| 68 | - if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 69 | - break; |
|
| 70 | - } |
|
| 71 | - $f[] = $t['function']; |
|
| 72 | - } |
|
| 73 | - if ($f !== []) { |
|
| 74 | - $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - return $message; |
|
| 47 | + $trace = debug_backtrace(); |
|
| 48 | + $caller = array_shift($trace); |
|
| 49 | + while (count($trace) && (empty($trace[0]['file']) || $trace[0]['file'] === $caller['file'] || $trace[0]['file'] === __FILE__)) { |
|
| 50 | + array_shift($trace); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($compil_info) { |
|
| 54 | + return [ |
|
| 55 | + $trace[0]['file'],// sourcefile |
|
| 56 | + '', //nom |
|
| 57 | + (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 58 | + . $trace[0]['function'] . '();' |
|
| 59 | + . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 60 | + $trace[0]['line'], // ligne |
|
| 61 | + $GLOBALS['spip_lang'], // lang |
|
| 62 | + ]; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 66 | + $f = []; |
|
| 67 | + while (count($trace) && ($t = array_shift($trace))) { |
|
| 68 | + if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 69 | + break; |
|
| 70 | + } |
|
| 71 | + $f[] = $t['function']; |
|
| 72 | + } |
|
| 73 | + if ($f !== []) { |
|
| 74 | + $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + return $message; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -99,16 +99,16 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | **/ |
| 101 | 101 | function sql_serveur($ins_sql = '', $serveur = '', $continue = false) { |
| 102 | - static $sql_serveur = []; |
|
| 103 | - if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 104 | - $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 105 | - if (!is_string($f) || !$f) { |
|
| 106 | - return $f; |
|
| 107 | - } |
|
| 108 | - $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $sql_serveur[$serveur][$ins_sql]; |
|
| 102 | + static $sql_serveur = []; |
|
| 103 | + if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 104 | + $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 105 | + if (!is_string($f) || !$f) { |
|
| 106 | + return $f; |
|
| 107 | + } |
|
| 108 | + $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $sql_serveur[$serveur][$ins_sql]; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -130,23 +130,23 @@ discard block |
||
| 130 | 130 | * Retourne le nom du charset si effectivement trouvé, sinon false. |
| 131 | 131 | **/ |
| 132 | 132 | function sql_get_charset($charset, $serveur = '', $option = true) { |
| 133 | - // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 134 | - $desc = sql_serveur('', $serveur, true); |
|
| 135 | - $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 136 | - $c = $desc['charsets'][$charset]; |
|
| 137 | - if ( |
|
| 138 | - $c |
|
| 139 | - && function_exists($f = @$desc['get_charset']) |
|
| 140 | - && $f($c, $serveur, $option) |
|
| 141 | - ) { |
|
| 142 | - return $c; |
|
| 143 | - } |
|
| 144 | - spip_log( |
|
| 145 | - "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 146 | - _LOG_AVERTISSEMENT |
|
| 147 | - ); |
|
| 148 | - |
|
| 149 | - return false; |
|
| 133 | + // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 134 | + $desc = sql_serveur('', $serveur, true); |
|
| 135 | + $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 136 | + $c = $desc['charsets'][$charset]; |
|
| 137 | + if ( |
|
| 138 | + $c |
|
| 139 | + && function_exists($f = @$desc['get_charset']) |
|
| 140 | + && $f($c, $serveur, $option) |
|
| 141 | + ) { |
|
| 142 | + return $c; |
|
| 143 | + } |
|
| 144 | + spip_log( |
|
| 145 | + "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 146 | + _LOG_AVERTISSEMENT |
|
| 147 | + ); |
|
| 148 | + |
|
| 149 | + return false; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -172,12 +172,12 @@ discard block |
||
| 172 | 172 | * Retourne true si elle reussie. |
| 173 | 173 | **/ |
| 174 | 174 | function sql_set_charset($charset, $serveur = '', $option = true) { |
| 175 | - $f = sql_serveur('set_charset', $serveur, $option === 'continue' || $option === false); |
|
| 176 | - if (!is_string($f) || !$f) { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 175 | + $f = sql_serveur('set_charset', $serveur, $option === 'continue' || $option === false); |
|
| 176 | + if (!is_string($f) || !$f) { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - return $f($charset, $serveur, $option !== false); |
|
| 180 | + return $f($charset, $serveur, $option !== false); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
@@ -228,59 +228,59 @@ discard block |
||
| 228 | 228 | * |
| 229 | 229 | **/ |
| 230 | 230 | function sql_select( |
| 231 | - $select = [], |
|
| 232 | - $from = [], |
|
| 233 | - $where = [], |
|
| 234 | - $groupby = [], |
|
| 235 | - $orderby = [], |
|
| 236 | - $limit = '', |
|
| 237 | - $having = [], |
|
| 238 | - $serveur = '', |
|
| 239 | - $option = true |
|
| 231 | + $select = [], |
|
| 232 | + $from = [], |
|
| 233 | + $where = [], |
|
| 234 | + $groupby = [], |
|
| 235 | + $orderby = [], |
|
| 236 | + $limit = '', |
|
| 237 | + $having = [], |
|
| 238 | + $serveur = '', |
|
| 239 | + $option = true |
|
| 240 | 240 | ) { |
| 241 | - $f = sql_serveur('select', $serveur, $option === 'continue' || $option === false); |
|
| 242 | - if (!is_string($f) || !$f) { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 247 | - if ($option !== false && !$debug) { |
|
| 248 | - $res = $f( |
|
| 249 | - $select, |
|
| 250 | - $from, |
|
| 251 | - $where, |
|
| 252 | - $groupby, |
|
| 253 | - $orderby, |
|
| 254 | - $limit, |
|
| 255 | - $having, |
|
| 256 | - $serveur, |
|
| 257 | - is_array($option) ? true : $option |
|
| 258 | - ); |
|
| 259 | - } else { |
|
| 260 | - $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 261 | - if (!$option) { |
|
| 262 | - return $query; |
|
| 263 | - } |
|
| 264 | - // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 265 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 266 | - [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 267 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 268 | - $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 269 | - } |
|
| 270 | - $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // en cas d'erreur |
|
| 274 | - if (!is_string($res)) { |
|
| 275 | - return $res; |
|
| 276 | - } |
|
| 277 | - // denoncer l'erreur SQL dans sa version brute |
|
| 278 | - spip_sql_erreur($serveur); |
|
| 279 | - // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 280 | - $contexte_compil = sql_error_backtrace(true); |
|
| 281 | - erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 282 | - |
|
| 283 | - return false; |
|
| 241 | + $f = sql_serveur('select', $serveur, $option === 'continue' || $option === false); |
|
| 242 | + if (!is_string($f) || !$f) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 247 | + if ($option !== false && !$debug) { |
|
| 248 | + $res = $f( |
|
| 249 | + $select, |
|
| 250 | + $from, |
|
| 251 | + $where, |
|
| 252 | + $groupby, |
|
| 253 | + $orderby, |
|
| 254 | + $limit, |
|
| 255 | + $having, |
|
| 256 | + $serveur, |
|
| 257 | + is_array($option) ? true : $option |
|
| 258 | + ); |
|
| 259 | + } else { |
|
| 260 | + $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 261 | + if (!$option) { |
|
| 262 | + return $query; |
|
| 263 | + } |
|
| 264 | + // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 265 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 266 | + [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 267 | + $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 268 | + $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 269 | + } |
|
| 270 | + $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // en cas d'erreur |
|
| 274 | + if (!is_string($res)) { |
|
| 275 | + return $res; |
|
| 276 | + } |
|
| 277 | + // denoncer l'erreur SQL dans sa version brute |
|
| 278 | + spip_sql_erreur($serveur); |
|
| 279 | + // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 280 | + $contexte_compil = sql_error_backtrace(true); |
|
| 281 | + erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 282 | + |
|
| 283 | + return false; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -317,16 +317,16 @@ discard block |
||
| 317 | 317 | * |
| 318 | 318 | **/ |
| 319 | 319 | function sql_get_select( |
| 320 | - $select = [], |
|
| 321 | - $from = [], |
|
| 322 | - $where = [], |
|
| 323 | - $groupby = [], |
|
| 324 | - $orderby = [], |
|
| 325 | - $limit = '', |
|
| 326 | - $having = [], |
|
| 327 | - $serveur = '' |
|
| 320 | + $select = [], |
|
| 321 | + $from = [], |
|
| 322 | + $where = [], |
|
| 323 | + $groupby = [], |
|
| 324 | + $orderby = [], |
|
| 325 | + $limit = '', |
|
| 326 | + $having = [], |
|
| 327 | + $serveur = '' |
|
| 328 | 328 | ) { |
| 329 | - return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 329 | + return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -370,23 +370,23 @@ discard block |
||
| 370 | 370 | * |
| 371 | 371 | **/ |
| 372 | 372 | function sql_countsel( |
| 373 | - $from = [], |
|
| 374 | - $where = [], |
|
| 375 | - $groupby = [], |
|
| 376 | - $having = [], |
|
| 377 | - $serveur = '', |
|
| 378 | - $option = true |
|
| 373 | + $from = [], |
|
| 374 | + $where = [], |
|
| 375 | + $groupby = [], |
|
| 376 | + $having = [], |
|
| 377 | + $serveur = '', |
|
| 378 | + $option = true |
|
| 379 | 379 | ) { |
| 380 | - $f = sql_serveur('countsel', $serveur, $option === 'continue' || $option === false); |
|
| 381 | - if (!is_string($f) || !$f) { |
|
| 382 | - return false; |
|
| 383 | - } |
|
| 384 | - $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 385 | - if ($r === false) { |
|
| 386 | - spip_sql_erreur($serveur); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - return $r; |
|
| 380 | + $f = sql_serveur('countsel', $serveur, $option === 'continue' || $option === false); |
|
| 381 | + if (!is_string($f) || !$f) { |
|
| 382 | + return false; |
|
| 383 | + } |
|
| 384 | + $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 385 | + if ($r === false) { |
|
| 386 | + spip_sql_erreur($serveur); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + return $r; |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | /** |
@@ -418,16 +418,16 @@ discard block |
||
| 418 | 418 | * Ce retour n'est pas pertinent pour savoir si l'opération est correctement réalisée. |
| 419 | 419 | **/ |
| 420 | 420 | function sql_alter($q, $serveur = '', $option = true) { |
| 421 | - $f = sql_serveur('alter', $serveur, $option === 'continue' || $option === false); |
|
| 422 | - if (!is_string($f) || !$f) { |
|
| 423 | - return false; |
|
| 424 | - } |
|
| 425 | - $r = $f($q, $serveur, $option !== false); |
|
| 426 | - if ($r === false) { |
|
| 427 | - spip_sql_erreur($serveur); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return $r; |
|
| 421 | + $f = sql_serveur('alter', $serveur, $option === 'continue' || $option === false); |
|
| 422 | + if (!is_string($f) || !$f) { |
|
| 423 | + return false; |
|
| 424 | + } |
|
| 425 | + $r = $f($q, $serveur, $option !== false); |
|
| 426 | + if ($r === false) { |
|
| 427 | + spip_sql_erreur($serveur); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return $r; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -450,12 +450,12 @@ discard block |
||
| 450 | 450 | * presentant une ligne de resultat d'une selection |
| 451 | 451 | */ |
| 452 | 452 | function sql_fetch(mixed $res, $serveur = '', $option = true) { |
| 453 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' || $option === false); |
|
| 454 | - if (!is_string($f) || !$f) { |
|
| 455 | - return false; |
|
| 456 | - } |
|
| 453 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' || $option === false); |
|
| 454 | + if (!is_string($f) || !$f) { |
|
| 455 | + return false; |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | - return $f($res, null, $serveur, $option !== false); |
|
| 458 | + return $f($res, null, $serveur, $option !== false); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | |
@@ -482,20 +482,20 @@ discard block |
||
| 482 | 482 | * presentant une ligne de resultat d'une selection |
| 483 | 483 | */ |
| 484 | 484 | function sql_fetch_all(mixed $res, $serveur = '', $option = true) { |
| 485 | - $rows = []; |
|
| 486 | - if (!$res) { |
|
| 487 | - return $rows; |
|
| 488 | - } |
|
| 489 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' || $option === false); |
|
| 490 | - if (!is_string($f) || !$f) { |
|
| 491 | - return []; |
|
| 492 | - } |
|
| 493 | - while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 494 | - $rows[] = $r; |
|
| 495 | - } |
|
| 496 | - sql_free($res, $serveur); |
|
| 497 | - |
|
| 498 | - return $rows; |
|
| 485 | + $rows = []; |
|
| 486 | + if (!$res) { |
|
| 487 | + return $rows; |
|
| 488 | + } |
|
| 489 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' || $option === false); |
|
| 490 | + if (!is_string($f) || !$f) { |
|
| 491 | + return []; |
|
| 492 | + } |
|
| 493 | + while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 494 | + $rows[] = $r; |
|
| 495 | + } |
|
| 496 | + sql_free($res, $serveur); |
|
| 497 | + |
|
| 498 | + return $rows; |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | /** |
@@ -523,16 +523,16 @@ discard block |
||
| 523 | 523 | * Operation effectuée (true), sinon false. |
| 524 | 524 | **/ |
| 525 | 525 | function sql_seek(mixed $res, $row_number, $serveur = '', $option = true) { |
| 526 | - $f = sql_serveur('seek', $serveur, $option === 'continue' || $option === false); |
|
| 527 | - if (!is_string($f) || !$f) { |
|
| 528 | - return false; |
|
| 529 | - } |
|
| 530 | - $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 531 | - if ($r === false) { |
|
| 532 | - spip_sql_erreur($serveur); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - return $r; |
|
| 526 | + $f = sql_serveur('seek', $serveur, $option === 'continue' || $option === false); |
|
| 527 | + if (!is_string($f) || !$f) { |
|
| 528 | + return false; |
|
| 529 | + } |
|
| 530 | + $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 531 | + if ($r === false) { |
|
| 532 | + spip_sql_erreur($serveur); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + return $r; |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | |
@@ -557,16 +557,16 @@ discard block |
||
| 557 | 557 | * False en cas d'erreur. |
| 558 | 558 | **/ |
| 559 | 559 | function sql_listdbs($serveur = '', $option = true) { |
| 560 | - $f = sql_serveur('listdbs', $serveur, $option === 'continue' || $option === false); |
|
| 561 | - if (!is_string($f) || !$f) { |
|
| 562 | - return false; |
|
| 563 | - } |
|
| 564 | - $r = $f($serveur); |
|
| 565 | - if ($r === false) { |
|
| 566 | - spip_sql_erreur($serveur); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - return $r; |
|
| 560 | + $f = sql_serveur('listdbs', $serveur, $option === 'continue' || $option === false); |
|
| 561 | + if (!is_string($f) || !$f) { |
|
| 562 | + return false; |
|
| 563 | + } |
|
| 564 | + $r = $f($serveur); |
|
| 565 | + if ($r === false) { |
|
| 566 | + spip_sql_erreur($serveur); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + return $r; |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | |
@@ -589,16 +589,16 @@ discard block |
||
| 589 | 589 | * - False en cas d'erreur. |
| 590 | 590 | **/ |
| 591 | 591 | function sql_selectdb($nom, $serveur = '', $option = true) { |
| 592 | - $f = sql_serveur('selectdb', $serveur, $option === 'continue' || $option === false); |
|
| 593 | - if (!is_string($f) || !$f) { |
|
| 594 | - return false; |
|
| 595 | - } |
|
| 596 | - $r = $f($nom, $serveur, $option !== false); |
|
| 597 | - if ($r === false) { |
|
| 598 | - spip_sql_erreur($serveur); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - return $r; |
|
| 592 | + $f = sql_serveur('selectdb', $serveur, $option === 'continue' || $option === false); |
|
| 593 | + if (!is_string($f) || !$f) { |
|
| 594 | + return false; |
|
| 595 | + } |
|
| 596 | + $r = $f($nom, $serveur, $option !== false); |
|
| 597 | + if ($r === false) { |
|
| 598 | + spip_sql_erreur($serveur); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + return $r; |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
@@ -623,16 +623,16 @@ discard block |
||
| 623 | 623 | * - false en cas d'erreur. |
| 624 | 624 | **/ |
| 625 | 625 | function sql_count($res, $serveur = '', $option = true) { |
| 626 | - $f = sql_serveur('count', $serveur, $option === 'continue' || $option === false); |
|
| 627 | - if (!is_string($f) || !$f) { |
|
| 628 | - return false; |
|
| 629 | - } |
|
| 630 | - $r = $f($res, $serveur, $option !== false); |
|
| 631 | - if ($r === false) { |
|
| 632 | - spip_sql_erreur($serveur); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - return $r; |
|
| 626 | + $f = sql_serveur('count', $serveur, $option === 'continue' || $option === false); |
|
| 627 | + if (!is_string($f) || !$f) { |
|
| 628 | + return false; |
|
| 629 | + } |
|
| 630 | + $r = $f($res, $serveur, $option !== false); |
|
| 631 | + if ($r === false) { |
|
| 632 | + spip_sql_erreur($serveur); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + return $r; |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
@@ -654,12 +654,12 @@ discard block |
||
| 654 | 654 | * True si réussi |
| 655 | 655 | */ |
| 656 | 656 | function sql_free($res, $serveur = '', $option = true) { |
| 657 | - $f = sql_serveur('free', $serveur, $option === 'continue' || $option === false); |
|
| 658 | - if (!is_string($f) || !$f) { |
|
| 659 | - return false; |
|
| 660 | - } |
|
| 657 | + $f = sql_serveur('free', $serveur, $option === 'continue' || $option === false); |
|
| 658 | + if (!is_string($f) || !$f) { |
|
| 659 | + return false; |
|
| 660 | + } |
|
| 661 | 661 | |
| 662 | - return $f($res); |
|
| 662 | + return $f($res); |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | |
@@ -697,17 +697,17 @@ discard block |
||
| 697 | 697 | * - False en cas d'erreur. |
| 698 | 698 | **/ |
| 699 | 699 | function sql_insert($table, $noms, $valeurs, $desc = [], $serveur = '', $option = true) { |
| 700 | - $f = sql_serveur('insert', $serveur, $option === 'continue' || $option === false); |
|
| 701 | - if (!is_string($f) || !$f) { |
|
| 702 | - return false; |
|
| 703 | - } |
|
| 704 | - $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 705 | - if ($r === false || $r === null) { |
|
| 706 | - spip_sql_erreur($serveur); |
|
| 707 | - $r = false; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return $r; |
|
| 700 | + $f = sql_serveur('insert', $serveur, $option === 'continue' || $option === false); |
|
| 701 | + if (!is_string($f) || !$f) { |
|
| 702 | + return false; |
|
| 703 | + } |
|
| 704 | + $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 705 | + if ($r === false || $r === null) { |
|
| 706 | + spip_sql_erreur($serveur); |
|
| 707 | + $r = false; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return $r; |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | /** |
@@ -748,17 +748,17 @@ discard block |
||
| 748 | 748 | * - False en cas d'erreur. |
| 749 | 749 | **/ |
| 750 | 750 | function sql_insertq($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 751 | - $f = sql_serveur('insertq', $serveur, $option === 'continue' || $option === false); |
|
| 752 | - if (!is_string($f) || !$f) { |
|
| 753 | - return false; |
|
| 754 | - } |
|
| 755 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 756 | - if ($r === false || $r === null) { |
|
| 757 | - spip_sql_erreur($serveur); |
|
| 758 | - $r = false; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - return $r; |
|
| 751 | + $f = sql_serveur('insertq', $serveur, $option === 'continue' || $option === false); |
|
| 752 | + if (!is_string($f) || !$f) { |
|
| 753 | + return false; |
|
| 754 | + } |
|
| 755 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 756 | + if ($r === false || $r === null) { |
|
| 757 | + spip_sql_erreur($serveur); |
|
| 758 | + $r = false; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + return $r; |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | /** |
@@ -793,17 +793,17 @@ discard block |
||
| 793 | 793 | * - false en cas d'erreur. |
| 794 | 794 | **/ |
| 795 | 795 | function sql_insertq_multi($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 796 | - $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' || $option === false); |
|
| 797 | - if (!is_string($f) || !$f) { |
|
| 798 | - return false; |
|
| 799 | - } |
|
| 800 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 801 | - if ($r === false || $r === null) { |
|
| 802 | - spip_sql_erreur($serveur); |
|
| 803 | - $r = false; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - return $r; |
|
| 796 | + $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' || $option === false); |
|
| 797 | + if (!is_string($f) || !$f) { |
|
| 798 | + return false; |
|
| 799 | + } |
|
| 800 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 801 | + if ($r === false || $r === null) { |
|
| 802 | + spip_sql_erreur($serveur); |
|
| 803 | + $r = false; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + return $r; |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
@@ -843,16 +843,16 @@ discard block |
||
| 843 | 843 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 844 | 844 | */ |
| 845 | 845 | function sql_update($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 846 | - $f = sql_serveur('update', $serveur, $option === 'continue' || $option === false); |
|
| 847 | - if (!is_string($f) || !$f) { |
|
| 848 | - return false; |
|
| 849 | - } |
|
| 850 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 851 | - if ($r === false) { |
|
| 852 | - spip_sql_erreur($serveur); |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - return $r; |
|
| 846 | + $f = sql_serveur('update', $serveur, $option === 'continue' || $option === false); |
|
| 847 | + if (!is_string($f) || !$f) { |
|
| 848 | + return false; |
|
| 849 | + } |
|
| 850 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 851 | + if ($r === false) { |
|
| 852 | + spip_sql_erreur($serveur); |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + return $r; |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | |
@@ -898,16 +898,16 @@ discard block |
||
| 898 | 898 | * - false en cas d'erreur. |
| 899 | 899 | **/ |
| 900 | 900 | function sql_updateq($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 901 | - $f = sql_serveur('updateq', $serveur, $option === 'continue' || $option === false); |
|
| 902 | - if (!is_string($f) || !$f) { |
|
| 903 | - return false; |
|
| 904 | - } |
|
| 905 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 906 | - if ($r === false) { |
|
| 907 | - spip_sql_erreur($serveur); |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - return $r; |
|
| 901 | + $f = sql_serveur('updateq', $serveur, $option === 'continue' || $option === false); |
|
| 902 | + if (!is_string($f) || !$f) { |
|
| 903 | + return false; |
|
| 904 | + } |
|
| 905 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 906 | + if ($r === false) { |
|
| 907 | + spip_sql_erreur($serveur); |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + return $r; |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -938,16 +938,16 @@ discard block |
||
| 938 | 938 | * - false en cas d'erreur. |
| 939 | 939 | **/ |
| 940 | 940 | function sql_delete($table, $where = '', $serveur = '', $option = true) { |
| 941 | - $f = sql_serveur('delete', $serveur, $option === 'continue' || $option === false); |
|
| 942 | - if (!is_string($f) || !$f) { |
|
| 943 | - return false; |
|
| 944 | - } |
|
| 945 | - $r = $f($table, $where, $serveur, $option !== false); |
|
| 946 | - if ($r === false) { |
|
| 947 | - spip_sql_erreur($serveur); |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - return $r; |
|
| 941 | + $f = sql_serveur('delete', $serveur, $option === 'continue' || $option === false); |
|
| 942 | + if (!is_string($f) || !$f) { |
|
| 943 | + return false; |
|
| 944 | + } |
|
| 945 | + $r = $f($table, $where, $serveur, $option !== false); |
|
| 946 | + if ($r === false) { |
|
| 947 | + spip_sql_erreur($serveur); |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + return $r; |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | /** |
@@ -983,16 +983,16 @@ discard block |
||
| 983 | 983 | * - false en cas d'erreur. |
| 984 | 984 | **/ |
| 985 | 985 | function sql_replace($table, $couples, $desc = [], $serveur = '', $option = true) { |
| 986 | - $f = sql_serveur('replace', $serveur, $option === 'continue' || $option === false); |
|
| 987 | - if (!is_string($f) || !$f) { |
|
| 988 | - return false; |
|
| 989 | - } |
|
| 990 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 991 | - if ($r === false) { |
|
| 992 | - spip_sql_erreur($serveur); |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - return $r; |
|
| 986 | + $f = sql_serveur('replace', $serveur, $option === 'continue' || $option === false); |
|
| 987 | + if (!is_string($f) || !$f) { |
|
| 988 | + return false; |
|
| 989 | + } |
|
| 990 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 991 | + if ($r === false) { |
|
| 992 | + spip_sql_erreur($serveur); |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + return $r; |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | |
@@ -1030,16 +1030,16 @@ discard block |
||
| 1030 | 1030 | * - false en cas d'erreur. |
| 1031 | 1031 | **/ |
| 1032 | 1032 | function sql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $option = true) { |
| 1033 | - $f = sql_serveur('replace_multi', $serveur, $option === 'continue' || $option === false); |
|
| 1034 | - if (!is_string($f) || !$f) { |
|
| 1035 | - return false; |
|
| 1036 | - } |
|
| 1037 | - $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1038 | - if ($r === false) { |
|
| 1039 | - spip_sql_erreur($serveur); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - return $r; |
|
| 1033 | + $f = sql_serveur('replace_multi', $serveur, $option === 'continue' || $option === false); |
|
| 1034 | + if (!is_string($f) || !$f) { |
|
| 1035 | + return false; |
|
| 1036 | + } |
|
| 1037 | + $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1038 | + if ($r === false) { |
|
| 1039 | + spip_sql_erreur($serveur); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + return $r; |
|
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | /** |
@@ -1067,16 +1067,16 @@ discard block |
||
| 1067 | 1067 | * - false en cas d'erreur. |
| 1068 | 1068 | **/ |
| 1069 | 1069 | function sql_drop_table($table, $exist = '', $serveur = '', $option = true) { |
| 1070 | - $f = sql_serveur('drop_table', $serveur, $option === 'continue' || $option === false); |
|
| 1071 | - if (!is_string($f) || !$f) { |
|
| 1072 | - return false; |
|
| 1073 | - } |
|
| 1074 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1075 | - if ($r === false) { |
|
| 1076 | - spip_sql_erreur($serveur); |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - return $r; |
|
| 1070 | + $f = sql_serveur('drop_table', $serveur, $option === 'continue' || $option === false); |
|
| 1071 | + if (!is_string($f) || !$f) { |
|
| 1072 | + return false; |
|
| 1073 | + } |
|
| 1074 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1075 | + if ($r === false) { |
|
| 1076 | + spip_sql_erreur($serveur); |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + return $r; |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1100,16 +1100,16 @@ discard block |
||
| 1100 | 1100 | * - true si la requête a réussie, false sinon |
| 1101 | 1101 | */ |
| 1102 | 1102 | function sql_drop_view($table, $exist = '', $serveur = '', $option = true) { |
| 1103 | - $f = sql_serveur('drop_view', $serveur, $option === 'continue' || $option === false); |
|
| 1104 | - if (!is_string($f) || !$f) { |
|
| 1105 | - return false; |
|
| 1106 | - } |
|
| 1107 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1108 | - if ($r === false) { |
|
| 1109 | - spip_sql_erreur($serveur); |
|
| 1110 | - } |
|
| 1111 | - |
|
| 1112 | - return $r; |
|
| 1103 | + $f = sql_serveur('drop_view', $serveur, $option === 'continue' || $option === false); |
|
| 1104 | + if (!is_string($f) || !$f) { |
|
| 1105 | + return false; |
|
| 1106 | + } |
|
| 1107 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1108 | + if ($r === false) { |
|
| 1109 | + spip_sql_erreur($serveur); |
|
| 1110 | + } |
|
| 1111 | + |
|
| 1112 | + return $r; |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | /** |
@@ -1133,18 +1133,18 @@ discard block |
||
| 1133 | 1133 | * Ressource à utiliser avec sql_fetch() |
| 1134 | 1134 | **/ |
| 1135 | 1135 | function sql_showbase($spip = null, $serveur = '', $option = true) { |
| 1136 | - $f = sql_serveur('showbase', $serveur, $option === 'continue' || $option === false); |
|
| 1137 | - if (!is_string($f) || !$f) { |
|
| 1138 | - return false; |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1142 | - if ($spip == null) { |
|
| 1143 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1144 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - return $f($spip, $serveur, $option !== false); |
|
| 1136 | + $f = sql_serveur('showbase', $serveur, $option === 'continue' || $option === false); |
|
| 1137 | + if (!is_string($f) || !$f) { |
|
| 1138 | + return false; |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1142 | + if ($spip == null) { |
|
| 1143 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1144 | + $spip = $connexion['prefixe'] . '\_%'; |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + return $f($spip, $serveur, $option !== false); |
|
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | /** |
@@ -1167,15 +1167,15 @@ discard block |
||
| 1167 | 1167 | * Liste des tables SQL |
| 1168 | 1168 | **/ |
| 1169 | 1169 | function sql_alltable($spip = null, $serveur = '', $option = true) { |
| 1170 | - $q = sql_showbase($spip, $serveur, $option); |
|
| 1171 | - $r = []; |
|
| 1172 | - if ($q) { |
|
| 1173 | - while ($t = sql_fetch($q, $serveur)) { |
|
| 1174 | - $r[] = array_shift($t); |
|
| 1175 | - } |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - return $r; |
|
| 1170 | + $q = sql_showbase($spip, $serveur, $option); |
|
| 1171 | + $r = []; |
|
| 1172 | + if ($q) { |
|
| 1173 | + while ($t = sql_fetch($q, $serveur)) { |
|
| 1174 | + $r[] = array_shift($t); |
|
| 1175 | + } |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + return $r; |
|
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | /** |
@@ -1208,31 +1208,31 @@ discard block |
||
| 1208 | 1208 | * - 'join' => array() // jointures, si déclarées. |
| 1209 | 1209 | **/ |
| 1210 | 1210 | function sql_showtable($table, $table_spip = false, $serveur = '', $option = true) { |
| 1211 | - $f = sql_serveur('showtable', $serveur, $option === 'continue' || $option === false); |
|
| 1212 | - if (!is_string($f) || !$f) { |
|
| 1213 | - return false; |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1217 | - if ($table_spip) { |
|
| 1218 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1219 | - $prefixe = $connexion['prefixe']; |
|
| 1220 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1221 | - } else { |
|
| 1222 | - $vraie_table = $table; |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1226 | - if (!$f) { |
|
| 1227 | - return []; |
|
| 1228 | - } |
|
| 1229 | - if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1230 | - $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1231 | - } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1232 | - $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - return $f; |
|
| 1211 | + $f = sql_serveur('showtable', $serveur, $option === 'continue' || $option === false); |
|
| 1212 | + if (!is_string($f) || !$f) { |
|
| 1213 | + return false; |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1217 | + if ($table_spip) { |
|
| 1218 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1219 | + $prefixe = $connexion['prefixe']; |
|
| 1220 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1221 | + } else { |
|
| 1222 | + $vraie_table = $table; |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1226 | + if (!$f) { |
|
| 1227 | + return []; |
|
| 1228 | + } |
|
| 1229 | + if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1230 | + $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1231 | + } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1232 | + $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + return $f; |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | |
@@ -1259,21 +1259,21 @@ discard block |
||
| 1259 | 1259 | * - false en cas d'erreur. |
| 1260 | 1260 | **/ |
| 1261 | 1261 | function sql_table_exists(string $table, bool $table_spip = true, $serveur = '', $option = true) { |
| 1262 | - $f = sql_serveur('table_exists', $serveur, $option === 'continue' || $option === false); |
|
| 1263 | - if (!is_string($f) || !$f) { |
|
| 1264 | - return false; |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1268 | - if ($table_spip) { |
|
| 1269 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1270 | - $prefixe = $connexion['prefixe']; |
|
| 1271 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1272 | - } else { |
|
| 1273 | - $vraie_table = $table; |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - return $f($vraie_table, $serveur, $option !== false); |
|
| 1262 | + $f = sql_serveur('table_exists', $serveur, $option === 'continue' || $option === false); |
|
| 1263 | + if (!is_string($f) || !$f) { |
|
| 1264 | + return false; |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1268 | + if ($table_spip) { |
|
| 1269 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1270 | + $prefixe = $connexion['prefixe']; |
|
| 1271 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1272 | + } else { |
|
| 1273 | + $vraie_table = $table; |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + return $f($vraie_table, $serveur, $option !== false); |
|
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | 1279 | |
@@ -1319,24 +1319,24 @@ discard block |
||
| 1319 | 1319 | * true si succès, false en cas d'echec |
| 1320 | 1320 | **/ |
| 1321 | 1321 | function sql_create( |
| 1322 | - $nom, |
|
| 1323 | - $champs, |
|
| 1324 | - $cles = [], |
|
| 1325 | - $autoinc = false, |
|
| 1326 | - $temporary = false, |
|
| 1327 | - $serveur = '', |
|
| 1328 | - $option = true |
|
| 1322 | + $nom, |
|
| 1323 | + $champs, |
|
| 1324 | + $cles = [], |
|
| 1325 | + $autoinc = false, |
|
| 1326 | + $temporary = false, |
|
| 1327 | + $serveur = '', |
|
| 1328 | + $option = true |
|
| 1329 | 1329 | ) { |
| 1330 | - $f = sql_serveur('create', $serveur, $option === 'continue' || $option === false); |
|
| 1331 | - if (!is_string($f) || !$f) { |
|
| 1332 | - return false; |
|
| 1333 | - } |
|
| 1334 | - $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1335 | - if ($r === false) { |
|
| 1336 | - spip_sql_erreur($serveur); |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - return $r; |
|
| 1330 | + $f = sql_serveur('create', $serveur, $option === 'continue' || $option === false); |
|
| 1331 | + if (!is_string($f) || !$f) { |
|
| 1332 | + return false; |
|
| 1333 | + } |
|
| 1334 | + $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1335 | + if ($r === false) { |
|
| 1336 | + spip_sql_erreur($serveur); |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + return $r; |
|
| 1340 | 1340 | } |
| 1341 | 1341 | |
| 1342 | 1342 | /** |
@@ -1354,16 +1354,16 @@ discard block |
||
| 1354 | 1354 | * @return bool true si la base est créee. |
| 1355 | 1355 | **/ |
| 1356 | 1356 | function sql_create_base($nom, $serveur = '', $option = true) { |
| 1357 | - $f = sql_serveur('create_base', $serveur, $option === 'continue' || $option === false); |
|
| 1358 | - if (!is_string($f) || !$f) { |
|
| 1359 | - return false; |
|
| 1360 | - } |
|
| 1361 | - $r = $f($nom, $serveur, $option !== false); |
|
| 1362 | - if ($r === false) { |
|
| 1363 | - spip_sql_erreur($serveur); |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - return $r; |
|
| 1357 | + $f = sql_serveur('create_base', $serveur, $option === 'continue' || $option === false); |
|
| 1358 | + if (!is_string($f) || !$f) { |
|
| 1359 | + return false; |
|
| 1360 | + } |
|
| 1361 | + $r = $f($nom, $serveur, $option !== false); |
|
| 1362 | + if ($r === false) { |
|
| 1363 | + spip_sql_erreur($serveur); |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + return $r; |
|
| 1367 | 1367 | } |
| 1368 | 1368 | |
| 1369 | 1369 | |
@@ -1393,16 +1393,16 @@ discard block |
||
| 1393 | 1393 | * - false en cas d'échec. |
| 1394 | 1394 | **/ |
| 1395 | 1395 | function sql_create_view($nom, $select_query, $serveur = '', $option = true) { |
| 1396 | - $f = sql_serveur('create_view', $serveur, $option === 'continue' || $option === false); |
|
| 1397 | - if (!is_string($f) || !$f) { |
|
| 1398 | - return false; |
|
| 1399 | - } |
|
| 1400 | - $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1401 | - if ($r === false) { |
|
| 1402 | - spip_sql_erreur($serveur); |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - return $r; |
|
| 1396 | + $f = sql_serveur('create_view', $serveur, $option === 'continue' || $option === false); |
|
| 1397 | + if (!is_string($f) || !$f) { |
|
| 1398 | + return false; |
|
| 1399 | + } |
|
| 1400 | + $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1401 | + if ($r === false) { |
|
| 1402 | + spip_sql_erreur($serveur); |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + return $r; |
|
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | 1408 | /** |
@@ -1431,12 +1431,12 @@ discard block |
||
| 1431 | 1431 | * texte de sélection pour la requête |
| 1432 | 1432 | */ |
| 1433 | 1433 | function sql_multi($sel, $lang, $serveur = '', $option = true) { |
| 1434 | - $f = sql_serveur('multi', $serveur, $option === 'continue' || $option === false); |
|
| 1435 | - if (!is_string($f) || !$f) { |
|
| 1436 | - return false; |
|
| 1437 | - } |
|
| 1434 | + $f = sql_serveur('multi', $serveur, $option === 'continue' || $option === false); |
|
| 1435 | + if (!is_string($f) || !$f) { |
|
| 1436 | + return false; |
|
| 1437 | + } |
|
| 1438 | 1438 | |
| 1439 | - return $f($sel, $lang); |
|
| 1439 | + return $f($sel, $lang); |
|
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | |
@@ -1451,12 +1451,12 @@ discard block |
||
| 1451 | 1451 | * False si le serveur est indisponible |
| 1452 | 1452 | */ |
| 1453 | 1453 | function sql_error($serveur = '') { |
| 1454 | - $f = sql_serveur('error', $serveur, true); |
|
| 1455 | - if (!is_string($f) || !$f) { |
|
| 1456 | - return false; |
|
| 1457 | - } |
|
| 1454 | + $f = sql_serveur('error', $serveur, true); |
|
| 1455 | + if (!is_string($f) || !$f) { |
|
| 1456 | + return false; |
|
| 1457 | + } |
|
| 1458 | 1458 | |
| 1459 | - return $f('query inconnue', $serveur); |
|
| 1459 | + return $f('query inconnue', $serveur); |
|
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | 1462 | /** |
@@ -1470,12 +1470,12 @@ discard block |
||
| 1470 | 1470 | * False si le serveur est indisponible |
| 1471 | 1471 | */ |
| 1472 | 1472 | function sql_errno($serveur = '') { |
| 1473 | - $f = sql_serveur('errno', $serveur, true); |
|
| 1474 | - if (!is_string($f) || !$f) { |
|
| 1475 | - return false; |
|
| 1476 | - } |
|
| 1473 | + $f = sql_serveur('errno', $serveur, true); |
|
| 1474 | + if (!is_string($f) || !$f) { |
|
| 1475 | + return false; |
|
| 1476 | + } |
|
| 1477 | 1477 | |
| 1478 | - return $f($serveur); |
|
| 1478 | + return $f($serveur); |
|
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | 1481 | /** |
@@ -1493,16 +1493,16 @@ discard block |
||
| 1493 | 1493 | * @return array|false Tableau de l'explication |
| 1494 | 1494 | */ |
| 1495 | 1495 | function sql_explain($q, $serveur = '', $option = true) { |
| 1496 | - $f = sql_serveur('explain', $serveur, true); |
|
| 1497 | - if (!is_string($f) || !$f) { |
|
| 1498 | - return false; |
|
| 1499 | - } |
|
| 1500 | - $r = $f($q, $serveur, $option !== false); |
|
| 1501 | - if ($r === false) { |
|
| 1502 | - spip_sql_erreur($serveur); |
|
| 1503 | - } |
|
| 1504 | - |
|
| 1505 | - return $r; |
|
| 1496 | + $f = sql_serveur('explain', $serveur, true); |
|
| 1497 | + if (!is_string($f) || !$f) { |
|
| 1498 | + return false; |
|
| 1499 | + } |
|
| 1500 | + $r = $f($q, $serveur, $option !== false); |
|
| 1501 | + if ($r === false) { |
|
| 1502 | + spip_sql_erreur($serveur); |
|
| 1503 | + } |
|
| 1504 | + |
|
| 1505 | + return $r; |
|
| 1506 | 1506 | } |
| 1507 | 1507 | |
| 1508 | 1508 | /** |
@@ -1520,16 +1520,16 @@ discard block |
||
| 1520 | 1520 | * @return bool Toujours true |
| 1521 | 1521 | */ |
| 1522 | 1522 | function sql_optimize($table, $serveur = '', $option = true) { |
| 1523 | - $f = sql_serveur('optimize', $serveur, $option === 'continue' || $option === false); |
|
| 1524 | - if (!is_string($f) || !$f) { |
|
| 1525 | - return false; |
|
| 1526 | - } |
|
| 1527 | - $r = $f($table, $serveur, $option); |
|
| 1528 | - if ($r === false) { |
|
| 1529 | - spip_sql_erreur($serveur); |
|
| 1530 | - } |
|
| 1531 | - |
|
| 1532 | - return $r; |
|
| 1523 | + $f = sql_serveur('optimize', $serveur, $option === 'continue' || $option === false); |
|
| 1524 | + if (!is_string($f) || !$f) { |
|
| 1525 | + return false; |
|
| 1526 | + } |
|
| 1527 | + $r = $f($table, $serveur, $option); |
|
| 1528 | + if ($r === false) { |
|
| 1529 | + spip_sql_erreur($serveur); |
|
| 1530 | + } |
|
| 1531 | + |
|
| 1532 | + return $r; |
|
| 1533 | 1533 | } |
| 1534 | 1534 | |
| 1535 | 1535 | /** |
@@ -1549,16 +1549,16 @@ discard block |
||
| 1549 | 1549 | * - true si la requête a réussie, false sinon |
| 1550 | 1550 | */ |
| 1551 | 1551 | function sql_repair($table, $serveur = '', $option = true) { |
| 1552 | - $f = sql_serveur('repair', $serveur, $option === 'continue' || $option === false); |
|
| 1553 | - if (!is_string($f) || !$f) { |
|
| 1554 | - return false; |
|
| 1555 | - } |
|
| 1556 | - $r = $f($table, $serveur, $option !== false); |
|
| 1557 | - if ($r === false) { |
|
| 1558 | - spip_sql_erreur($serveur); |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - return $r; |
|
| 1552 | + $f = sql_serveur('repair', $serveur, $option === 'continue' || $option === false); |
|
| 1553 | + if (!is_string($f) || !$f) { |
|
| 1554 | + return false; |
|
| 1555 | + } |
|
| 1556 | + $r = $f($table, $serveur, $option !== false); |
|
| 1557 | + if ($r === false) { |
|
| 1558 | + spip_sql_erreur($serveur); |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + return $r; |
|
| 1562 | 1562 | } |
| 1563 | 1563 | |
| 1564 | 1564 | |
@@ -1583,16 +1583,16 @@ discard block |
||
| 1583 | 1583 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 1584 | 1584 | */ |
| 1585 | 1585 | function sql_query($ins, $serveur = '', $option = true) { |
| 1586 | - $f = sql_serveur('query', $serveur, $option === 'continue' || $option === false); |
|
| 1587 | - if (!is_string($f) || !$f) { |
|
| 1588 | - return false; |
|
| 1589 | - } |
|
| 1590 | - $r = $f($ins, $serveur, $option !== false); |
|
| 1591 | - if ($r === false) { |
|
| 1592 | - spip_sql_erreur($serveur); |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - return $r; |
|
| 1586 | + $f = sql_serveur('query', $serveur, $option === 'continue' || $option === false); |
|
| 1587 | + if (!is_string($f) || !$f) { |
|
| 1588 | + return false; |
|
| 1589 | + } |
|
| 1590 | + $r = $f($ins, $serveur, $option !== false); |
|
| 1591 | + if ($r === false) { |
|
| 1592 | + spip_sql_erreur($serveur); |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + return $r; |
|
| 1596 | 1596 | } |
| 1597 | 1597 | |
| 1598 | 1598 | /** |
@@ -1640,27 +1640,27 @@ discard block |
||
| 1640 | 1640 | * |
| 1641 | 1641 | **/ |
| 1642 | 1642 | function sql_fetsel( |
| 1643 | - $select = [], |
|
| 1644 | - $from = [], |
|
| 1645 | - $where = [], |
|
| 1646 | - $groupby = [], |
|
| 1647 | - $orderby = [], |
|
| 1648 | - $limit = '', |
|
| 1649 | - $having = [], |
|
| 1650 | - $serveur = '', |
|
| 1651 | - $option = true |
|
| 1643 | + $select = [], |
|
| 1644 | + $from = [], |
|
| 1645 | + $where = [], |
|
| 1646 | + $groupby = [], |
|
| 1647 | + $orderby = [], |
|
| 1648 | + $limit = '', |
|
| 1649 | + $having = [], |
|
| 1650 | + $serveur = '', |
|
| 1651 | + $option = true |
|
| 1652 | 1652 | ) { |
| 1653 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1654 | - if ($option === false) { |
|
| 1655 | - return $q; |
|
| 1656 | - } |
|
| 1657 | - if (!$q) { |
|
| 1658 | - return []; |
|
| 1659 | - } |
|
| 1660 | - $r = sql_fetch($q, $serveur, $option); |
|
| 1661 | - sql_free($q, $serveur, $option); |
|
| 1662 | - |
|
| 1663 | - return $r; |
|
| 1653 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1654 | + if ($option === false) { |
|
| 1655 | + return $q; |
|
| 1656 | + } |
|
| 1657 | + if (!$q) { |
|
| 1658 | + return []; |
|
| 1659 | + } |
|
| 1660 | + $r = sql_fetch($q, $serveur, $option); |
|
| 1661 | + sql_free($q, $serveur, $option); |
|
| 1662 | + |
|
| 1663 | + return $r; |
|
| 1664 | 1664 | } |
| 1665 | 1665 | |
| 1666 | 1666 | |
@@ -1717,22 +1717,22 @@ discard block |
||
| 1717 | 1717 | * |
| 1718 | 1718 | **/ |
| 1719 | 1719 | function sql_allfetsel( |
| 1720 | - $select = [], |
|
| 1721 | - $from = [], |
|
| 1722 | - $where = [], |
|
| 1723 | - $groupby = [], |
|
| 1724 | - $orderby = [], |
|
| 1725 | - $limit = '', |
|
| 1726 | - $having = [], |
|
| 1727 | - $serveur = '', |
|
| 1728 | - $option = true |
|
| 1720 | + $select = [], |
|
| 1721 | + $from = [], |
|
| 1722 | + $where = [], |
|
| 1723 | + $groupby = [], |
|
| 1724 | + $orderby = [], |
|
| 1725 | + $limit = '', |
|
| 1726 | + $having = [], |
|
| 1727 | + $serveur = '', |
|
| 1728 | + $option = true |
|
| 1729 | 1729 | ) { |
| 1730 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1731 | - if ($option === false) { |
|
| 1732 | - return $q; |
|
| 1733 | - } |
|
| 1730 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1731 | + if ($option === false) { |
|
| 1732 | + return $q; |
|
| 1733 | + } |
|
| 1734 | 1734 | |
| 1735 | - return sql_fetch_all($q, $serveur, $option); |
|
| 1735 | + return sql_fetch_all($q, $serveur, $option); |
|
| 1736 | 1736 | } |
| 1737 | 1737 | |
| 1738 | 1738 | |
@@ -1779,33 +1779,33 @@ discard block |
||
| 1779 | 1779 | * |
| 1780 | 1780 | **/ |
| 1781 | 1781 | function sql_getfetsel( |
| 1782 | - $select, |
|
| 1783 | - $from = [], |
|
| 1784 | - $where = [], |
|
| 1785 | - $groupby = [], |
|
| 1786 | - $orderby = [], |
|
| 1787 | - $limit = '', |
|
| 1788 | - $having = [], |
|
| 1789 | - $serveur = '', |
|
| 1790 | - $option = true |
|
| 1782 | + $select, |
|
| 1783 | + $from = [], |
|
| 1784 | + $where = [], |
|
| 1785 | + $groupby = [], |
|
| 1786 | + $orderby = [], |
|
| 1787 | + $limit = '', |
|
| 1788 | + $having = [], |
|
| 1789 | + $serveur = '', |
|
| 1790 | + $option = true |
|
| 1791 | 1791 | ) { |
| 1792 | - if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1793 | - $id = $c[1]; |
|
| 1794 | - } elseif (!preg_match('/\W/', $select)) { |
|
| 1795 | - $id = $select; |
|
| 1796 | - } else { |
|
| 1797 | - $id = 'n'; |
|
| 1798 | - $select .= ' AS n'; |
|
| 1799 | - } |
|
| 1800 | - $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1801 | - if ($option === false) { |
|
| 1802 | - return $r; |
|
| 1803 | - } |
|
| 1804 | - if (!$r) { |
|
| 1805 | - return null; |
|
| 1806 | - } |
|
| 1807 | - |
|
| 1808 | - return $r[$id]; |
|
| 1792 | + if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1793 | + $id = $c[1]; |
|
| 1794 | + } elseif (!preg_match('/\W/', $select)) { |
|
| 1795 | + $id = $select; |
|
| 1796 | + } else { |
|
| 1797 | + $id = 'n'; |
|
| 1798 | + $select .= ' AS n'; |
|
| 1799 | + } |
|
| 1800 | + $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1801 | + if ($option === false) { |
|
| 1802 | + return $r; |
|
| 1803 | + } |
|
| 1804 | + if (!$r) { |
|
| 1805 | + return null; |
|
| 1806 | + } |
|
| 1807 | + |
|
| 1808 | + return $r[$id]; |
|
| 1809 | 1809 | } |
| 1810 | 1810 | |
| 1811 | 1811 | /** |
@@ -1823,9 +1823,9 @@ discard block |
||
| 1823 | 1823 | * Numero de version du serveur SQL |
| 1824 | 1824 | **/ |
| 1825 | 1825 | function sql_version($serveur = '', $option = true) { |
| 1826 | - $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1826 | + $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1827 | 1827 | |
| 1828 | - return ($row['n']); |
|
| 1828 | + return ($row['n']); |
|
| 1829 | 1829 | } |
| 1830 | 1830 | |
| 1831 | 1831 | /** |
@@ -1861,16 +1861,16 @@ discard block |
||
| 1861 | 1861 | * Le serveur SQL prefere t'il des transactions pour les insertions multiples ? |
| 1862 | 1862 | **/ |
| 1863 | 1863 | function sql_preferer_transaction($serveur = '', $option = true) { |
| 1864 | - $f = sql_serveur('preferer_transaction', $serveur, true); |
|
| 1865 | - if (!is_string($f) || !$f) { |
|
| 1866 | - return false; |
|
| 1867 | - } |
|
| 1868 | - $r = $f($serveur, $option !== false); |
|
| 1869 | - if ($r === false) { |
|
| 1870 | - spip_sql_erreur($serveur); |
|
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - return $r; |
|
| 1864 | + $f = sql_serveur('preferer_transaction', $serveur, true); |
|
| 1865 | + if (!is_string($f) || !$f) { |
|
| 1866 | + return false; |
|
| 1867 | + } |
|
| 1868 | + $r = $f($serveur, $option !== false); |
|
| 1869 | + if ($r === false) { |
|
| 1870 | + spip_sql_erreur($serveur); |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + return $r; |
|
| 1874 | 1874 | } |
| 1875 | 1875 | |
| 1876 | 1876 | ; |
@@ -1895,16 +1895,16 @@ discard block |
||
| 1895 | 1895 | * false en cas d'erreur |
| 1896 | 1896 | **/ |
| 1897 | 1897 | function sql_demarrer_transaction($serveur = '', $option = true) { |
| 1898 | - $f = sql_serveur('demarrer_transaction', $serveur, true); |
|
| 1899 | - if (!is_string($f) || !$f) { |
|
| 1900 | - return false; |
|
| 1901 | - } |
|
| 1902 | - $r = $f($serveur, $option !== false); |
|
| 1903 | - if ($r === false) { |
|
| 1904 | - spip_sql_erreur($serveur); |
|
| 1905 | - } |
|
| 1906 | - |
|
| 1907 | - return $r; |
|
| 1898 | + $f = sql_serveur('demarrer_transaction', $serveur, true); |
|
| 1899 | + if (!is_string($f) || !$f) { |
|
| 1900 | + return false; |
|
| 1901 | + } |
|
| 1902 | + $r = $f($serveur, $option !== false); |
|
| 1903 | + if ($r === false) { |
|
| 1904 | + spip_sql_erreur($serveur); |
|
| 1905 | + } |
|
| 1906 | + |
|
| 1907 | + return $r; |
|
| 1908 | 1908 | } |
| 1909 | 1909 | |
| 1910 | 1910 | ; |
@@ -1929,16 +1929,16 @@ discard block |
||
| 1929 | 1929 | * false en cas d'erreur |
| 1930 | 1930 | **/ |
| 1931 | 1931 | function sql_terminer_transaction($serveur = '', $option = true) { |
| 1932 | - $f = sql_serveur('terminer_transaction', $serveur, true); |
|
| 1933 | - if (!is_string($f) || !$f) { |
|
| 1934 | - return false; |
|
| 1935 | - } |
|
| 1936 | - $r = $f($serveur, $option !== false); |
|
| 1937 | - if ($r === false) { |
|
| 1938 | - spip_sql_erreur($serveur); |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - return $r; |
|
| 1932 | + $f = sql_serveur('terminer_transaction', $serveur, true); |
|
| 1933 | + if (!is_string($f) || !$f) { |
|
| 1934 | + return false; |
|
| 1935 | + } |
|
| 1936 | + $r = $f($serveur, $option !== false); |
|
| 1937 | + if ($r === false) { |
|
| 1938 | + spip_sql_erreur($serveur); |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + return $r; |
|
| 1942 | 1942 | } |
| 1943 | 1943 | |
| 1944 | 1944 | ; |
@@ -1965,12 +1965,12 @@ discard block |
||
| 1965 | 1965 | * Valeur hexadécimale attendue par le serveur SQL |
| 1966 | 1966 | **/ |
| 1967 | 1967 | function sql_hex($val, $serveur = '', $option = true) { |
| 1968 | - $f = sql_serveur('hex', $serveur, $option === 'continue' || $option === false); |
|
| 1969 | - if (!is_string($f) || !$f) { |
|
| 1970 | - return false; |
|
| 1971 | - } |
|
| 1968 | + $f = sql_serveur('hex', $serveur, $option === 'continue' || $option === false); |
|
| 1969 | + if (!is_string($f) || !$f) { |
|
| 1970 | + return false; |
|
| 1971 | + } |
|
| 1972 | 1972 | |
| 1973 | - return $f($val); |
|
| 1973 | + return $f($val); |
|
| 1974 | 1974 | } |
| 1975 | 1975 | |
| 1976 | 1976 | /** |
@@ -1996,12 +1996,12 @@ discard block |
||
| 1996 | 1996 | * La chaine echappee |
| 1997 | 1997 | **/ |
| 1998 | 1998 | function sql_quote($val, $serveur = '', $type = '') { |
| 1999 | - $f = sql_serveur('quote', $serveur, true); |
|
| 2000 | - if (!is_string($f) || !$f) { |
|
| 2001 | - $f = '_q'; |
|
| 2002 | - } |
|
| 1999 | + $f = sql_serveur('quote', $serveur, true); |
|
| 2000 | + if (!is_string($f) || !$f) { |
|
| 2001 | + $f = '_q'; |
|
| 2002 | + } |
|
| 2003 | 2003 | |
| 2004 | - return $f($val, $type); |
|
| 2004 | + return $f($val, $type); |
|
| 2005 | 2005 | } |
| 2006 | 2006 | |
| 2007 | 2007 | /** |
@@ -2026,12 +2026,12 @@ discard block |
||
| 2026 | 2026 | * - false si le serveur SQL est indisponible |
| 2027 | 2027 | **/ |
| 2028 | 2028 | function sql_date_proche($champ, $interval, $unite, $serveur = '', $option = true) { |
| 2029 | - $f = sql_serveur('date_proche', $serveur, true); |
|
| 2030 | - if (!is_string($f) || !$f) { |
|
| 2031 | - return false; |
|
| 2032 | - } |
|
| 2029 | + $f = sql_serveur('date_proche', $serveur, true); |
|
| 2030 | + if (!is_string($f) || !$f) { |
|
| 2031 | + return false; |
|
| 2032 | + } |
|
| 2033 | 2033 | |
| 2034 | - return $f($champ, $interval, $unite); |
|
| 2034 | + return $f($champ, $interval, $unite); |
|
| 2035 | 2035 | } |
| 2036 | 2036 | |
| 2037 | 2037 | /** |
@@ -2067,26 +2067,26 @@ discard block |
||
| 2067 | 2067 | * Expression de requête SQL |
| 2068 | 2068 | **/ |
| 2069 | 2069 | function sql_in_quote($champ, $valeurs, $not = '', $serveur = '', $type = '', $option = true) { |
| 2070 | - $quote = sql_serveur('quote', $serveur, true); |
|
| 2071 | - if (!is_string($quote) || !$quote) { |
|
| 2072 | - return false; |
|
| 2073 | - } |
|
| 2074 | - |
|
| 2075 | - // sql_quote produit une chaine dans tous les cas |
|
| 2076 | - $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2077 | - $valeurs = array_unique($valeurs); |
|
| 2078 | - $valeurs = $quote($valeurs, $type); |
|
| 2079 | - |
|
| 2080 | - if (!strlen(trim((string) $valeurs))) { |
|
| 2081 | - return ($not ? '0=0' : '0=1'); |
|
| 2082 | - } |
|
| 2083 | - |
|
| 2084 | - $f = sql_serveur('in', $serveur, $option === 'continue' || $option === false); |
|
| 2085 | - if (!is_string($f) || !$f) { |
|
| 2086 | - return false; |
|
| 2087 | - } |
|
| 2088 | - |
|
| 2089 | - return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2070 | + $quote = sql_serveur('quote', $serveur, true); |
|
| 2071 | + if (!is_string($quote) || !$quote) { |
|
| 2072 | + return false; |
|
| 2073 | + } |
|
| 2074 | + |
|
| 2075 | + // sql_quote produit une chaine dans tous les cas |
|
| 2076 | + $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2077 | + $valeurs = array_unique($valeurs); |
|
| 2078 | + $valeurs = $quote($valeurs, $type); |
|
| 2079 | + |
|
| 2080 | + if (!strlen(trim((string) $valeurs))) { |
|
| 2081 | + return ($not ? '0=0' : '0=1'); |
|
| 2082 | + } |
|
| 2083 | + |
|
| 2084 | + $f = sql_serveur('in', $serveur, $option === 'continue' || $option === false); |
|
| 2085 | + if (!is_string($f) || !$f) { |
|
| 2086 | + return false; |
|
| 2087 | + } |
|
| 2088 | + |
|
| 2089 | + return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2090 | 2090 | } |
| 2091 | 2091 | |
| 2092 | 2092 | /** |
@@ -2103,19 +2103,19 @@ discard block |
||
| 2103 | 2103 | * @param bool $option |
| 2104 | 2104 | */ |
| 2105 | 2105 | function sql_in($champ, $valeurs, $not = '', $serveur = '', $option = true) { |
| 2106 | - $type = ''; |
|
| 2107 | - if (!is_array($valeurs)) { |
|
| 2108 | - $valeurs = (string) $valeurs; |
|
| 2109 | - if (isset($valeurs[0]) && $valeurs[0] === ',') { |
|
| 2110 | - $valeurs = substr($valeurs, 1); |
|
| 2111 | - } |
|
| 2112 | - // on explode en tableau pour pouvoir securiser le contenu |
|
| 2113 | - $valeurs = explode(',', $valeurs); |
|
| 2114 | - // et on force un cast de type int donc |
|
| 2115 | - $type = 'int'; |
|
| 2116 | - } |
|
| 2117 | - |
|
| 2118 | - return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2106 | + $type = ''; |
|
| 2107 | + if (!is_array($valeurs)) { |
|
| 2108 | + $valeurs = (string) $valeurs; |
|
| 2109 | + if (isset($valeurs[0]) && $valeurs[0] === ',') { |
|
| 2110 | + $valeurs = substr($valeurs, 1); |
|
| 2111 | + } |
|
| 2112 | + // on explode en tableau pour pouvoir securiser le contenu |
|
| 2113 | + $valeurs = explode(',', $valeurs); |
|
| 2114 | + // et on force un cast de type int donc |
|
| 2115 | + $type = 'int'; |
|
| 2116 | + } |
|
| 2117 | + |
|
| 2118 | + return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2119 | 2119 | } |
| 2120 | 2120 | |
| 2121 | 2121 | |
@@ -2156,24 +2156,24 @@ discard block |
||
| 2156 | 2156 | * Expression de requête SQL |
| 2157 | 2157 | **/ |
| 2158 | 2158 | function sql_in_select( |
| 2159 | - $in, |
|
| 2160 | - $select, |
|
| 2161 | - $from = [], |
|
| 2162 | - $where = [], |
|
| 2163 | - $groupby = [], |
|
| 2164 | - $orderby = [], |
|
| 2165 | - $limit = '', |
|
| 2166 | - $having = [], |
|
| 2167 | - $serveur = '' |
|
| 2159 | + $in, |
|
| 2160 | + $select, |
|
| 2161 | + $from = [], |
|
| 2162 | + $where = [], |
|
| 2163 | + $groupby = [], |
|
| 2164 | + $orderby = [], |
|
| 2165 | + $limit = '', |
|
| 2166 | + $having = [], |
|
| 2167 | + $serveur = '' |
|
| 2168 | 2168 | ) { |
| 2169 | - $liste = []; |
|
| 2170 | - $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2171 | - while ($r = sql_fetch($res)) { |
|
| 2172 | - $liste[] = array_shift($r); |
|
| 2173 | - } |
|
| 2174 | - sql_free($res); |
|
| 2175 | - |
|
| 2176 | - return sql_in($in, $liste); |
|
| 2169 | + $liste = []; |
|
| 2170 | + $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2171 | + while ($r = sql_fetch($res)) { |
|
| 2172 | + $liste[] = array_shift($r); |
|
| 2173 | + } |
|
| 2174 | + sql_free($res); |
|
| 2175 | + |
|
| 2176 | + return sql_in($in, $liste); |
|
| 2177 | 2177 | } |
| 2178 | 2178 | |
| 2179 | 2179 | /** |
@@ -2205,29 +2205,29 @@ discard block |
||
| 2205 | 2205 | * Position apres le saut. |
| 2206 | 2206 | */ |
| 2207 | 2207 | function sql_skip($res, $pos, $saut, $count, $serveur = '', $option = true) { |
| 2208 | - // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2209 | - if (($saut = (int) $saut) <= 0) { |
|
| 2210 | - return $pos; |
|
| 2211 | - } |
|
| 2212 | - |
|
| 2213 | - $seek = $pos + $saut; |
|
| 2214 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 2215 | - // et on sort |
|
| 2216 | - if ($seek >= $count) { |
|
| 2217 | - sql_free($res, $serveur, $option); |
|
| 2218 | - |
|
| 2219 | - return $count; |
|
| 2220 | - } |
|
| 2221 | - |
|
| 2222 | - if (sql_seek($res, $seek)) { |
|
| 2223 | - $pos = $seek; |
|
| 2224 | - } else { |
|
| 2225 | - while ($pos < $seek && sql_fetch($res, $serveur, $option)) { |
|
| 2226 | - $pos++; |
|
| 2227 | - } |
|
| 2228 | - } |
|
| 2229 | - |
|
| 2230 | - return $pos; |
|
| 2208 | + // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2209 | + if (($saut = (int) $saut) <= 0) { |
|
| 2210 | + return $pos; |
|
| 2211 | + } |
|
| 2212 | + |
|
| 2213 | + $seek = $pos + $saut; |
|
| 2214 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 2215 | + // et on sort |
|
| 2216 | + if ($seek >= $count) { |
|
| 2217 | + sql_free($res, $serveur, $option); |
|
| 2218 | + |
|
| 2219 | + return $count; |
|
| 2220 | + } |
|
| 2221 | + |
|
| 2222 | + if (sql_seek($res, $seek)) { |
|
| 2223 | + $pos = $seek; |
|
| 2224 | + } else { |
|
| 2225 | + while ($pos < $seek && sql_fetch($res, $serveur, $option)) { |
|
| 2226 | + $pos++; |
|
| 2227 | + } |
|
| 2228 | + } |
|
| 2229 | + |
|
| 2230 | + return $pos; |
|
| 2231 | 2231 | } |
| 2232 | 2232 | |
| 2233 | 2233 | |
@@ -2247,7 +2247,7 @@ discard block |
||
| 2247 | 2247 | * True si le champ est de type entier |
| 2248 | 2248 | */ |
| 2249 | 2249 | function sql_test_int($type, $serveur = '', $option = true) { |
| 2250 | - return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2250 | + return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2251 | 2251 | } |
| 2252 | 2252 | |
| 2253 | 2253 | /** |
@@ -2266,7 +2266,7 @@ discard block |
||
| 2266 | 2266 | * True si le champ est de type entier |
| 2267 | 2267 | */ |
| 2268 | 2268 | function sql_test_date($type, $serveur = '', $option = true) { |
| 2269 | - return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2269 | + return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2270 | 2270 | } |
| 2271 | 2271 | |
| 2272 | 2272 | /** |
@@ -2288,19 +2288,19 @@ discard block |
||
| 2288 | 2288 | * La date formatee |
| 2289 | 2289 | */ |
| 2290 | 2290 | function sql_format_date($annee = 0, $mois = 0, $jour = 0, $h = 0, $m = 0, $s = 0, $serveur = '') { |
| 2291 | - $annee = sprintf('%04s', $annee); |
|
| 2292 | - $mois = sprintf('%02s', $mois); |
|
| 2293 | - |
|
| 2294 | - if ($annee == '0000') { |
|
| 2295 | - $mois = 0; |
|
| 2296 | - } |
|
| 2297 | - if ($mois == '00') { |
|
| 2298 | - $jour = 0; |
|
| 2299 | - } |
|
| 2300 | - |
|
| 2301 | - return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2302 | - . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2303 | - . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2291 | + $annee = sprintf('%04s', $annee); |
|
| 2292 | + $mois = sprintf('%02s', $mois); |
|
| 2293 | + |
|
| 2294 | + if ($annee == '0000') { |
|
| 2295 | + $mois = 0; |
|
| 2296 | + } |
|
| 2297 | + if ($mois == '00') { |
|
| 2298 | + $jour = 0; |
|
| 2299 | + } |
|
| 2300 | + |
|
| 2301 | + return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2302 | + . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2303 | + . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2304 | 2304 | } |
| 2305 | 2305 | |
| 2306 | 2306 | |
@@ -2323,32 +2323,32 @@ discard block |
||
| 2323 | 2323 | **/ |
| 2324 | 2324 | function description_table($nom, $serveur = '') { |
| 2325 | 2325 | |
| 2326 | - static $trouver_table; |
|
| 2326 | + static $trouver_table; |
|
| 2327 | 2327 | |
| 2328 | - /* toujours utiliser trouver_table |
|
| 2328 | + /* toujours utiliser trouver_table |
|
| 2329 | 2329 | qui renverra la description theorique |
| 2330 | 2330 | car sinon on va se comporter differement selon que la table est declaree |
| 2331 | 2331 | ou non |
| 2332 | 2332 | */ |
| 2333 | - if (!$trouver_table) { |
|
| 2334 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2335 | - } |
|
| 2336 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2337 | - return $desc; |
|
| 2338 | - } |
|
| 2339 | - |
|
| 2340 | - // sauf a l'installation : |
|
| 2341 | - include_spip('base/serial'); |
|
| 2342 | - if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2343 | - return $GLOBALS['tables_principales'][$nom]; |
|
| 2344 | - } |
|
| 2345 | - |
|
| 2346 | - include_spip('base/auxiliaires'); |
|
| 2347 | - if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2348 | - return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2349 | - } |
|
| 2350 | - |
|
| 2351 | - return false; |
|
| 2333 | + if (!$trouver_table) { |
|
| 2334 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2335 | + } |
|
| 2336 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2337 | + return $desc; |
|
| 2338 | + } |
|
| 2339 | + |
|
| 2340 | + // sauf a l'installation : |
|
| 2341 | + include_spip('base/serial'); |
|
| 2342 | + if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2343 | + return $GLOBALS['tables_principales'][$nom]; |
|
| 2344 | + } |
|
| 2345 | + |
|
| 2346 | + include_spip('base/auxiliaires'); |
|
| 2347 | + if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2348 | + return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2349 | + } |
|
| 2350 | + |
|
| 2351 | + return false; |
|
| 2352 | 2352 | } |
| 2353 | 2353 | |
| 2354 | 2354 | /** |
@@ -2361,8 +2361,8 @@ discard block |
||
| 2361 | 2361 | * @return string Table sql éventuellement renommée |
| 2362 | 2362 | */ |
| 2363 | 2363 | function prefixer_table_spip($table, $prefixe) { |
| 2364 | - if ($prefixe) { |
|
| 2365 | - $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2366 | - } |
|
| 2367 | - return $table; |
|
| 2364 | + if ($prefixe) { |
|
| 2365 | + $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2366 | + } |
|
| 2367 | + return $table; |
|
| 2368 | 2368 | } |
@@ -52,17 +52,17 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | if ($compil_info) { |
| 54 | 54 | return [ |
| 55 | - $trace[0]['file'],// sourcefile |
|
| 55 | + $trace[0]['file'], // sourcefile |
|
| 56 | 56 | '', //nom |
| 57 | - (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 58 | - . $trace[0]['function'] . '();' |
|
| 57 | + (isset($trace[1]) ? $trace[1]['function']."(){\n" : '') |
|
| 58 | + . $trace[0]['function'].'();' |
|
| 59 | 59 | . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
| 60 | 60 | $trace[0]['line'], // ligne |
| 61 | 61 | $GLOBALS['spip_lang'], // lang |
| 62 | 62 | ]; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 65 | + $message = count($trace) ? $trace[0]['file'].' L'.$trace[0]['line'] : ''; |
|
| 66 | 66 | $f = []; |
| 67 | 67 | while (count($trace) && ($t = array_shift($trace))) { |
| 68 | 68 | if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | $f[] = $t['function']; |
| 72 | 72 | } |
| 73 | 73 | if ($f !== []) { |
| 74 | - $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 74 | + $message .= ' ['.implode('(),', $f).'()]'; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | return $message; |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | // le debug, c'est pour ce qui a ete produit par le compilateur |
| 265 | 265 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 266 | 266 | [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
| 267 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 267 | + $nom = $GLOBALS['debug_objets']['courant'].$id; |
|
| 268 | 268 | $GLOBALS['debug_objets']['requete'][$nom] = $query; |
| 269 | 269 | } |
| 270 | 270 | $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
@@ -1141,7 +1141,7 @@ discard block |
||
| 1141 | 1141 | // la globale n'est remplie qu'apres l'appel de sql_serveur. |
| 1142 | 1142 | if ($spip == null) { |
| 1143 | 1143 | $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 1144 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 1144 | + $spip = $connexion['prefixe'].'\_%'; |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | return $f($spip, $serveur, $option !== false); |
@@ -2298,9 +2298,9 @@ discard block |
||
| 2298 | 2298 | $jour = 0; |
| 2299 | 2299 | } |
| 2300 | 2300 | |
| 2301 | - return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2302 | - . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2303 | - . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2301 | + return sprintf('%04u', $annee).'-'.sprintf('%02u', $mois).'-' |
|
| 2302 | + . sprintf('%02u', $jour).' '.sprintf('%02u', $h).':' |
|
| 2303 | + . sprintf('%02u', $m).':'.sprintf('%02u', $s); |
|
| 2304 | 2304 | } |
| 2305 | 2305 | |
| 2306 | 2306 | |
@@ -2362,7 +2362,7 @@ discard block |
||
| 2362 | 2362 | */ |
| 2363 | 2363 | function prefixer_table_spip($table, $prefixe) { |
| 2364 | 2364 | if ($prefixe) { |
| 2365 | - $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2365 | + $table = preg_replace('/^spip_/', $prefixe.'_', $table); |
|
| 2366 | 2366 | } |
| 2367 | 2367 | return $table; |
| 2368 | 2368 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\SQL |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | require_once _ROOT_RESTREINT . 'base/objets.php'; |
| 21 | 21 | |
@@ -41,125 +41,125 @@ discard block |
||
| 41 | 41 | **/ |
| 42 | 42 | function spip_connect($serveur = '', $version = '') { |
| 43 | 43 | |
| 44 | - $serveur = is_string($serveur) ? strtolower($serveur) : ''; |
|
| 45 | - $index = $serveur ?: 0; |
|
| 46 | - if (!$version) { |
|
| 47 | - $version = $GLOBALS['spip_sql_version']; |
|
| 48 | - } |
|
| 49 | - if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 50 | - return $GLOBALS['connexions'][$index]; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - include_spip('base/abstract_sql'); |
|
| 54 | - $install = (_request('exec') == 'install'); |
|
| 55 | - |
|
| 56 | - // Premiere connexion ? |
|
| 57 | - if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 58 | - $f = ''; |
|
| 59 | - if ($serveur) { |
|
| 60 | - // serveur externe et nom de serveur bien ecrit ? |
|
| 61 | - if ( |
|
| 62 | - defined('_DIR_CONNECT') |
|
| 63 | - && preg_match('/^[\w\.]*$/', $serveur) |
|
| 64 | - ) { |
|
| 65 | - $f = _DIR_CONNECT . $serveur . '.php'; |
|
| 66 | - if (!is_readable($f) && !$install) { |
|
| 67 | - // chercher une declaration de serveur dans le path |
|
| 68 | - // qui peut servir à des plugins à declarer des connexions à une base sqlite |
|
| 69 | - // Ex: sert aux boucles POUR et au plugin-dist dump pour se connecter sur le sqlite du dump |
|
| 70 | - $f = find_in_path("$serveur.php", 'connect/'); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } else { |
|
| 74 | - if (defined('_FILE_CONNECT') && _FILE_CONNECT) { |
|
| 75 | - // init du serveur principal |
|
| 76 | - $f = _FILE_CONNECT; |
|
| 77 | - } elseif ($install && defined('_FILE_CONNECT_TMP')) { |
|
| 78 | - // installation en cours |
|
| 79 | - $f = _FILE_CONNECT_TMP; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - unset($GLOBALS['db_ok']); |
|
| 84 | - unset($GLOBALS['spip_connect_version']); |
|
| 85 | - if ($f && is_readable($f)) { |
|
| 86 | - include($f); |
|
| 87 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 88 | - spip_log("spip_connect: fichier de connexion '$f' OK mais echec connexion au serveur", _LOG_HS); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - else { |
|
| 92 | - spip_log("spip_connect: fichier de connexion '$f' non trouve, pas de connexion serveur", _LOG_HS); |
|
| 93 | - } |
|
| 94 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 95 | - // fera mieux la prochaine fois |
|
| 96 | - if ($install) { |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 99 | - // ne plus reessayer si ce n'est pas l'install |
|
| 100 | - return $GLOBALS['connexions'][$index] = false; |
|
| 101 | - } |
|
| 102 | - $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 103 | - } |
|
| 104 | - // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 105 | - if (!$GLOBALS['connexions'][$index]) { |
|
| 106 | - return false; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // la connexion a reussi ou etait deja faite. |
|
| 110 | - // chargement de la version du jeu de fonctions |
|
| 111 | - // si pas dans le fichier par defaut |
|
| 112 | - $type = $GLOBALS['db_ok']['type']; |
|
| 113 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 114 | - if (!isset($GLOBALS[$jeu]) && !find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 115 | - spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 116 | - // ne plus reessayer |
|
| 117 | - return $GLOBALS['connexions'][$index][$version] = []; |
|
| 118 | - } |
|
| 119 | - $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 120 | - if ($old) { |
|
| 121 | - return $GLOBALS['connexions'][$index]; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0; |
|
| 125 | - |
|
| 126 | - // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 127 | - // si l'installation l'a determine. |
|
| 128 | - // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 129 | - // s'ils le connaissent |
|
| 130 | - |
|
| 131 | - if (!$serveur) { |
|
| 132 | - $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 133 | - if (!$charset) { |
|
| 134 | - unset($GLOBALS['connexions'][$index]); |
|
| 135 | - spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 136 | - |
|
| 137 | - return false; |
|
| 138 | - } |
|
| 139 | - } else { |
|
| 140 | - if ($GLOBALS['db_ok']['charset']) { |
|
| 141 | - $charset = $GLOBALS['db_ok']['charset']; |
|
| 142 | - } |
|
| 143 | - // spip_meta n'existe pas toujours dans la base |
|
| 144 | - // C'est le cas d'un dump sqlite par exemple |
|
| 145 | - elseif ( |
|
| 146 | - $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 147 | - && sql_showtable('spip_meta', true, $serveur) |
|
| 148 | - && ($r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)) |
|
| 149 | - ) { |
|
| 150 | - $charset = $r; |
|
| 151 | - } else { |
|
| 152 | - $charset = -1; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - if ($charset != -1) { |
|
| 156 | - $f = $GLOBALS[$jeu]['set_charset']; |
|
| 157 | - if (function_exists($f)) { |
|
| 158 | - $f($charset, $serveur); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return $GLOBALS['connexions'][$index]; |
|
| 44 | + $serveur = is_string($serveur) ? strtolower($serveur) : ''; |
|
| 45 | + $index = $serveur ?: 0; |
|
| 46 | + if (!$version) { |
|
| 47 | + $version = $GLOBALS['spip_sql_version']; |
|
| 48 | + } |
|
| 49 | + if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 50 | + return $GLOBALS['connexions'][$index]; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + include_spip('base/abstract_sql'); |
|
| 54 | + $install = (_request('exec') == 'install'); |
|
| 55 | + |
|
| 56 | + // Premiere connexion ? |
|
| 57 | + if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 58 | + $f = ''; |
|
| 59 | + if ($serveur) { |
|
| 60 | + // serveur externe et nom de serveur bien ecrit ? |
|
| 61 | + if ( |
|
| 62 | + defined('_DIR_CONNECT') |
|
| 63 | + && preg_match('/^[\w\.]*$/', $serveur) |
|
| 64 | + ) { |
|
| 65 | + $f = _DIR_CONNECT . $serveur . '.php'; |
|
| 66 | + if (!is_readable($f) && !$install) { |
|
| 67 | + // chercher une declaration de serveur dans le path |
|
| 68 | + // qui peut servir à des plugins à declarer des connexions à une base sqlite |
|
| 69 | + // Ex: sert aux boucles POUR et au plugin-dist dump pour se connecter sur le sqlite du dump |
|
| 70 | + $f = find_in_path("$serveur.php", 'connect/'); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } else { |
|
| 74 | + if (defined('_FILE_CONNECT') && _FILE_CONNECT) { |
|
| 75 | + // init du serveur principal |
|
| 76 | + $f = _FILE_CONNECT; |
|
| 77 | + } elseif ($install && defined('_FILE_CONNECT_TMP')) { |
|
| 78 | + // installation en cours |
|
| 79 | + $f = _FILE_CONNECT_TMP; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + unset($GLOBALS['db_ok']); |
|
| 84 | + unset($GLOBALS['spip_connect_version']); |
|
| 85 | + if ($f && is_readable($f)) { |
|
| 86 | + include($f); |
|
| 87 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 88 | + spip_log("spip_connect: fichier de connexion '$f' OK mais echec connexion au serveur", _LOG_HS); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + else { |
|
| 92 | + spip_log("spip_connect: fichier de connexion '$f' non trouve, pas de connexion serveur", _LOG_HS); |
|
| 93 | + } |
|
| 94 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 95 | + // fera mieux la prochaine fois |
|
| 96 | + if ($install) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | + // ne plus reessayer si ce n'est pas l'install |
|
| 100 | + return $GLOBALS['connexions'][$index] = false; |
|
| 101 | + } |
|
| 102 | + $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 103 | + } |
|
| 104 | + // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 105 | + if (!$GLOBALS['connexions'][$index]) { |
|
| 106 | + return false; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // la connexion a reussi ou etait deja faite. |
|
| 110 | + // chargement de la version du jeu de fonctions |
|
| 111 | + // si pas dans le fichier par defaut |
|
| 112 | + $type = $GLOBALS['db_ok']['type']; |
|
| 113 | + $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 114 | + if (!isset($GLOBALS[$jeu]) && !find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 115 | + spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 116 | + // ne plus reessayer |
|
| 117 | + return $GLOBALS['connexions'][$index][$version] = []; |
|
| 118 | + } |
|
| 119 | + $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 120 | + if ($old) { |
|
| 121 | + return $GLOBALS['connexions'][$index]; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0; |
|
| 125 | + |
|
| 126 | + // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 127 | + // si l'installation l'a determine. |
|
| 128 | + // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 129 | + // s'ils le connaissent |
|
| 130 | + |
|
| 131 | + if (!$serveur) { |
|
| 132 | + $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 133 | + if (!$charset) { |
|
| 134 | + unset($GLOBALS['connexions'][$index]); |
|
| 135 | + spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 136 | + |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 139 | + } else { |
|
| 140 | + if ($GLOBALS['db_ok']['charset']) { |
|
| 141 | + $charset = $GLOBALS['db_ok']['charset']; |
|
| 142 | + } |
|
| 143 | + // spip_meta n'existe pas toujours dans la base |
|
| 144 | + // C'est le cas d'un dump sqlite par exemple |
|
| 145 | + elseif ( |
|
| 146 | + $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 147 | + && sql_showtable('spip_meta', true, $serveur) |
|
| 148 | + && ($r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)) |
|
| 149 | + ) { |
|
| 150 | + $charset = $r; |
|
| 151 | + } else { |
|
| 152 | + $charset = -1; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + if ($charset != -1) { |
|
| 156 | + $f = $GLOBALS[$jeu]['set_charset']; |
|
| 157 | + if (function_exists($f)) { |
|
| 158 | + $f($charset, $serveur); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return $GLOBALS['connexions'][$index]; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | * @param string $serveur Nom du connecteur de bdd utilisé |
| 169 | 169 | **/ |
| 170 | 170 | function spip_sql_erreur($serveur = '') { |
| 171 | - $connexion = spip_connect($serveur); |
|
| 172 | - $e = sql_errno($serveur); |
|
| 173 | - $t = ($connexion['type'] ?? 'sql'); |
|
| 174 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim((string) $connexion['last']); |
|
| 175 | - $f = $t . $serveur; |
|
| 176 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 171 | + $connexion = spip_connect($serveur); |
|
| 172 | + $e = sql_errno($serveur); |
|
| 173 | + $t = ($connexion['type'] ?? 'sql'); |
|
| 174 | + $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim((string) $connexion['last']); |
|
| 175 | + $f = $t . $serveur; |
|
| 176 | + spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -195,23 +195,23 @@ discard block |
||
| 195 | 195 | * - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion |
| 196 | 196 | **/ |
| 197 | 197 | function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) { |
| 198 | - $desc = spip_connect($serveur, $version); |
|
| 199 | - if ( |
|
| 200 | - $desc |
|
| 201 | - && ($f = ($desc[$version][$ins] ?? '')) |
|
| 202 | - && function_exists($f) |
|
| 203 | - ) { |
|
| 204 | - return $f; |
|
| 205 | - } |
|
| 206 | - if ($continue) { |
|
| 207 | - return $desc; |
|
| 208 | - } |
|
| 209 | - if ($ins) { |
|
| 210 | - spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 211 | - } |
|
| 212 | - include_spip('inc/minipres'); |
|
| 213 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 214 | - exit; |
|
| 198 | + $desc = spip_connect($serveur, $version); |
|
| 199 | + if ( |
|
| 200 | + $desc |
|
| 201 | + && ($f = ($desc[$version][$ins] ?? '')) |
|
| 202 | + && function_exists($f) |
|
| 203 | + ) { |
|
| 204 | + return $f; |
|
| 205 | + } |
|
| 206 | + if ($continue) { |
|
| 207 | + return $desc; |
|
| 208 | + } |
|
| 209 | + if ($ins) { |
|
| 210 | + spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 211 | + } |
|
| 212 | + include_spip('inc/minipres'); |
|
| 213 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 214 | + exit; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -237,70 +237,70 @@ discard block |
||
| 237 | 237 | * @return array|null Description de la connexion |
| 238 | 238 | */ |
| 239 | 239 | function spip_connect_db( |
| 240 | - $host, |
|
| 241 | - $port, |
|
| 242 | - $login, |
|
| 243 | - #[\SensitiveParameter] $pass, |
|
| 244 | - $db = '', |
|
| 245 | - $type = 'mysql', |
|
| 246 | - $prefixe = '', |
|
| 247 | - $auth = '', |
|
| 248 | - $charset = '' |
|
| 240 | + $host, |
|
| 241 | + $port, |
|
| 242 | + $login, |
|
| 243 | + #[\SensitiveParameter] $pass, |
|
| 244 | + $db = '', |
|
| 245 | + $type = 'mysql', |
|
| 246 | + $prefixe = '', |
|
| 247 | + $auth = '', |
|
| 248 | + $charset = '' |
|
| 249 | 249 | ) { |
| 250 | - // temps avant nouvelle tentative de connexion |
|
| 251 | - // suite a une connection echouee |
|
| 252 | - if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 253 | - define('_CONNECT_RETRY_DELAY', 30); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $f = ''; |
|
| 257 | - // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 258 | - // pour ne pas declarer tout indisponible d'un coup |
|
| 259 | - // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 260 | - // car c'est un test de connexion |
|
| 261 | - if (!defined('_ECRIRE_INSTALL') && $db !== '@test@') { |
|
| 262 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 263 | - } elseif ($db == '@test@') { |
|
| 264 | - $db = ''; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - if ( |
|
| 268 | - $f |
|
| 269 | - && @file_exists($f) |
|
| 270 | - && (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 271 | - ) { |
|
| 272 | - spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 273 | - |
|
| 274 | - return null; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - if (!$prefixe) { |
|
| 278 | - $prefixe = $GLOBALS['table_prefix'] ?? $db; |
|
| 279 | - } |
|
| 280 | - $h = charger_fonction($type, 'req', true); |
|
| 281 | - if (!$h) { |
|
| 282 | - spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 283 | - |
|
| 284 | - return null; |
|
| 285 | - } |
|
| 286 | - if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 287 | - if (!is_array($auth)) { |
|
| 288 | - // compatibilite version 0.7 initiale |
|
| 289 | - $g['ldap'] = $auth; |
|
| 290 | - $auth = ['ldap' => $auth]; |
|
| 291 | - } |
|
| 292 | - $g['authentification'] = $auth; |
|
| 293 | - $g['type'] = $type; |
|
| 294 | - $g['charset'] = $charset; |
|
| 295 | - |
|
| 296 | - return $GLOBALS['db_ok'] = $g; |
|
| 297 | - } |
|
| 298 | - // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 299 | - if ($f) { |
|
| 300 | - @touch($f); |
|
| 301 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 302 | - } |
|
| 303 | - return null; |
|
| 250 | + // temps avant nouvelle tentative de connexion |
|
| 251 | + // suite a une connection echouee |
|
| 252 | + if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 253 | + define('_CONNECT_RETRY_DELAY', 30); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $f = ''; |
|
| 257 | + // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 258 | + // pour ne pas declarer tout indisponible d'un coup |
|
| 259 | + // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 260 | + // car c'est un test de connexion |
|
| 261 | + if (!defined('_ECRIRE_INSTALL') && $db !== '@test@') { |
|
| 262 | + $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 263 | + } elseif ($db == '@test@') { |
|
| 264 | + $db = ''; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + if ( |
|
| 268 | + $f |
|
| 269 | + && @file_exists($f) |
|
| 270 | + && (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 271 | + ) { |
|
| 272 | + spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 273 | + |
|
| 274 | + return null; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + if (!$prefixe) { |
|
| 278 | + $prefixe = $GLOBALS['table_prefix'] ?? $db; |
|
| 279 | + } |
|
| 280 | + $h = charger_fonction($type, 'req', true); |
|
| 281 | + if (!$h) { |
|
| 282 | + spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 283 | + |
|
| 284 | + return null; |
|
| 285 | + } |
|
| 286 | + if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 287 | + if (!is_array($auth)) { |
|
| 288 | + // compatibilite version 0.7 initiale |
|
| 289 | + $g['ldap'] = $auth; |
|
| 290 | + $auth = ['ldap' => $auth]; |
|
| 291 | + } |
|
| 292 | + $g['authentification'] = $auth; |
|
| 293 | + $g['type'] = $type; |
|
| 294 | + $g['charset'] = $charset; |
|
| 295 | + |
|
| 296 | + return $GLOBALS['db_ok'] = $g; |
|
| 297 | + } |
|
| 298 | + // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 299 | + if ($f) { |
|
| 300 | + @touch($f); |
|
| 301 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 302 | + } |
|
| 303 | + return null; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | |
@@ -332,32 +332,32 @@ discard block |
||
| 332 | 332 | * - nom du charset sinon |
| 333 | 333 | **/ |
| 334 | 334 | function spip_connect_main($connexion, $charset_sql_connexion = '') { |
| 335 | - if ($GLOBALS['spip_connect_version'] < 0.1 && _DIR_RESTREINT) { |
|
| 336 | - include_spip('inc/headers'); |
|
| 337 | - redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - if (!($f = $connexion['select'])) { |
|
| 341 | - return false; |
|
| 342 | - } |
|
| 343 | - // si le charset est fourni, l'utiliser |
|
| 344 | - if ($charset_sql_connexion) { |
|
| 345 | - return $charset_sql_connexion; |
|
| 346 | - } |
|
| 347 | - // sinon on regarde la table spip_meta |
|
| 348 | - // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 349 | - if ( |
|
| 350 | - !($r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")) |
|
| 351 | - || is_string($r) |
|
| 352 | - ) { |
|
| 353 | - return false; |
|
| 354 | - } |
|
| 355 | - if (!($f = $connexion['fetch'])) { |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - $r = $f($r); |
|
| 359 | - |
|
| 360 | - return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 335 | + if ($GLOBALS['spip_connect_version'] < 0.1 && _DIR_RESTREINT) { |
|
| 336 | + include_spip('inc/headers'); |
|
| 337 | + redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + if (!($f = $connexion['select'])) { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 343 | + // si le charset est fourni, l'utiliser |
|
| 344 | + if ($charset_sql_connexion) { |
|
| 345 | + return $charset_sql_connexion; |
|
| 346 | + } |
|
| 347 | + // sinon on regarde la table spip_meta |
|
| 348 | + // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 349 | + if ( |
|
| 350 | + !($r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")) |
|
| 351 | + || is_string($r) |
|
| 352 | + ) { |
|
| 353 | + return false; |
|
| 354 | + } |
|
| 355 | + if (!($f = $connexion['fetch'])) { |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + $r = $f($r); |
|
| 359 | + |
|
| 360 | + return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -373,8 +373,8 @@ discard block |
||
| 373 | 373 | * @return array |
| 374 | 374 | */ |
| 375 | 375 | function spip_connect_ldap($serveur = '') { |
| 376 | - include_spip('auth/ldap'); |
|
| 377 | - return auth_ldap_connect($serveur); |
|
| 376 | + include_spip('auth/ldap'); |
|
| 377 | + return auth_ldap_connect($serveur); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -390,16 +390,16 @@ discard block |
||
| 390 | 390 | * @return string Valeur échappée. |
| 391 | 391 | **/ |
| 392 | 392 | function _q($a): string { |
| 393 | - if (is_numeric($a)) { |
|
| 394 | - return (string) $a; |
|
| 395 | - } elseif (is_array($a)) { |
|
| 396 | - return implode(',', array_map('_q', $a)); |
|
| 397 | - } elseif (is_scalar($a)) { |
|
| 398 | - return ("'" . addslashes($a) . "'"); |
|
| 399 | - } elseif ($a === null) { |
|
| 400 | - return "''"; |
|
| 401 | - } |
|
| 402 | - throw new \RuntimeException('Can’t use _q with ' . gettype($a)); |
|
| 393 | + if (is_numeric($a)) { |
|
| 394 | + return (string) $a; |
|
| 395 | + } elseif (is_array($a)) { |
|
| 396 | + return implode(',', array_map('_q', $a)); |
|
| 397 | + } elseif (is_scalar($a)) { |
|
| 398 | + return ("'" . addslashes($a) . "'"); |
|
| 399 | + } elseif ($a === null) { |
|
| 400 | + return "''"; |
|
| 401 | + } |
|
| 402 | + throw new \RuntimeException('Can’t use _q with ' . gettype($a)); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -415,75 +415,75 @@ discard block |
||
| 415 | 415 | * @return array |
| 416 | 416 | */ |
| 417 | 417 | function query_echappe_textes($query, $uniqid = null) { |
| 418 | - static $codeEchappements = null; |
|
| 419 | - if (is_null($codeEchappements) || $uniqid) { |
|
| 420 | - if (is_null($uniqid)) { |
|
| 421 | - $uniqid = uniqid(); |
|
| 422 | - } |
|
| 423 | - $uniqid = substr(md5((string) $uniqid), 0, 4); |
|
| 424 | - $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"]; |
|
| 425 | - } |
|
| 426 | - if ($query === null) { |
|
| 427 | - return $codeEchappements; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 431 | - // ce n'est pas un cas legitime |
|
| 432 | - foreach ($codeEchappements as $codeEchappement) { |
|
| 433 | - if (str_contains($query, (string) $codeEchappement)) { |
|
| 434 | - return [$query, []]; |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 439 | - if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 440 | - $textes = reset($textes); |
|
| 441 | - |
|
| 442 | - $parts = []; |
|
| 443 | - $currentpos = 0; |
|
| 444 | - $k = 0; |
|
| 445 | - while (count($textes)) { |
|
| 446 | - $part = array_shift($textes); |
|
| 447 | - $nextpos = strpos($query_echappees, (string) $part, $currentpos); |
|
| 448 | - // si besoin recoller ensemble les doubles '' de sqlite (echappement des ') |
|
| 449 | - while (count($textes) && str_ends_with((string) $part, "'")) { |
|
| 450 | - $next = reset($textes); |
|
| 451 | - if ( |
|
| 452 | - str_starts_with((string) $next, "'") |
|
| 453 | - && strpos($query_echappees, $part . $next, $currentpos) === $nextpos |
|
| 454 | - ) { |
|
| 455 | - $part .= array_shift($textes); |
|
| 456 | - } |
|
| 457 | - else { |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - $k++; |
|
| 462 | - $parts[$k] = [ |
|
| 463 | - 'texte' => $part, |
|
| 464 | - 'position' => $nextpos, |
|
| 465 | - 'placeholder' => '%' . $k . '$s', |
|
| 466 | - ]; |
|
| 467 | - $currentpos = $nextpos + strlen((string) $part); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - // et on replace les parts une par une en commencant par la fin |
|
| 471 | - while ($k > 0) { |
|
| 472 | - $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen((string) $parts[$k]['texte'])); |
|
| 473 | - $k--; |
|
| 474 | - } |
|
| 475 | - $textes = array_column($parts, 'texte'); |
|
| 476 | - } else { |
|
| 477 | - $textes = []; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux |
|
| 481 | - // dans le doute on ne touche a rien |
|
| 482 | - if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 483 | - return [$query, []]; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return [$query_echappees, $textes]; |
|
| 418 | + static $codeEchappements = null; |
|
| 419 | + if (is_null($codeEchappements) || $uniqid) { |
|
| 420 | + if (is_null($uniqid)) { |
|
| 421 | + $uniqid = uniqid(); |
|
| 422 | + } |
|
| 423 | + $uniqid = substr(md5((string) $uniqid), 0, 4); |
|
| 424 | + $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"]; |
|
| 425 | + } |
|
| 426 | + if ($query === null) { |
|
| 427 | + return $codeEchappements; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 431 | + // ce n'est pas un cas legitime |
|
| 432 | + foreach ($codeEchappements as $codeEchappement) { |
|
| 433 | + if (str_contains($query, (string) $codeEchappement)) { |
|
| 434 | + return [$query, []]; |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 439 | + if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 440 | + $textes = reset($textes); |
|
| 441 | + |
|
| 442 | + $parts = []; |
|
| 443 | + $currentpos = 0; |
|
| 444 | + $k = 0; |
|
| 445 | + while (count($textes)) { |
|
| 446 | + $part = array_shift($textes); |
|
| 447 | + $nextpos = strpos($query_echappees, (string) $part, $currentpos); |
|
| 448 | + // si besoin recoller ensemble les doubles '' de sqlite (echappement des ') |
|
| 449 | + while (count($textes) && str_ends_with((string) $part, "'")) { |
|
| 450 | + $next = reset($textes); |
|
| 451 | + if ( |
|
| 452 | + str_starts_with((string) $next, "'") |
|
| 453 | + && strpos($query_echappees, $part . $next, $currentpos) === $nextpos |
|
| 454 | + ) { |
|
| 455 | + $part .= array_shift($textes); |
|
| 456 | + } |
|
| 457 | + else { |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + $k++; |
|
| 462 | + $parts[$k] = [ |
|
| 463 | + 'texte' => $part, |
|
| 464 | + 'position' => $nextpos, |
|
| 465 | + 'placeholder' => '%' . $k . '$s', |
|
| 466 | + ]; |
|
| 467 | + $currentpos = $nextpos + strlen((string) $part); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + // et on replace les parts une par une en commencant par la fin |
|
| 471 | + while ($k > 0) { |
|
| 472 | + $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen((string) $parts[$k]['texte'])); |
|
| 473 | + $k--; |
|
| 474 | + } |
|
| 475 | + $textes = array_column($parts, 'texte'); |
|
| 476 | + } else { |
|
| 477 | + $textes = []; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux |
|
| 481 | + // dans le doute on ne touche a rien |
|
| 482 | + if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 483 | + return [$query, []]; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return [$query_echappees, $textes]; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -497,14 +497,14 @@ discard block |
||
| 497 | 497 | * @return string |
| 498 | 498 | */ |
| 499 | 499 | function query_reinjecte_textes($query, $textes) { |
| 500 | - // recuperer les codes echappements |
|
| 501 | - $codeEchappements = query_echappe_textes(null); |
|
| 500 | + // recuperer les codes echappements |
|
| 501 | + $codeEchappements = query_echappe_textes(null); |
|
| 502 | 502 | |
| 503 | - if (!empty($textes)) { |
|
| 504 | - $query = sprintf($query, ...$textes); |
|
| 505 | - } |
|
| 503 | + if (!empty($textes)) { |
|
| 504 | + $query = sprintf($query, ...$textes); |
|
| 505 | + } |
|
| 506 | 506 | |
| 507 | - return str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 507 | + return str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | **/ |
| 524 | 524 | function spip_query($query, $serveur = '') { |
| 525 | 525 | |
| 526 | - $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 526 | + $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 527 | 527 | |
| 528 | - return function_exists($f) ? $f($query, $serveur) : false; |
|
| 528 | + return function_exists($f) ? $f($query, $serveur) : false; |
|
| 529 | 529 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | 18 | return; |
| 19 | 19 | } |
| 20 | -require_once _ROOT_RESTREINT . 'base/objets.php'; |
|
| 20 | +require_once _ROOT_RESTREINT.'base/objets.php'; |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | defined('_DIR_CONNECT') |
| 63 | 63 | && preg_match('/^[\w\.]*$/', $serveur) |
| 64 | 64 | ) { |
| 65 | - $f = _DIR_CONNECT . $serveur . '.php'; |
|
| 65 | + $f = _DIR_CONNECT.$serveur.'.php'; |
|
| 66 | 66 | if (!is_readable($f) && !$install) { |
| 67 | 67 | // chercher une declaration de serveur dans le path |
| 68 | 68 | // qui peut servir à des plugins à declarer des connexions à une base sqlite |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | // chargement de la version du jeu de fonctions |
| 111 | 111 | // si pas dans le fichier par defaut |
| 112 | 112 | $type = $GLOBALS['db_ok']['type']; |
| 113 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 114 | - if (!isset($GLOBALS[$jeu]) && !find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 113 | + $jeu = 'spip_'.$type.'_functions_'.$version; |
|
| 114 | + if (!isset($GLOBALS[$jeu]) && !find_in_path($type.'_'.$version.'.php', 'req/', true)) { |
|
| 115 | 115 | spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
| 116 | 116 | // ne plus reessayer |
| 117 | 117 | return $GLOBALS['connexions'][$index][$version] = []; |
@@ -171,9 +171,9 @@ discard block |
||
| 171 | 171 | $connexion = spip_connect($serveur); |
| 172 | 172 | $e = sql_errno($serveur); |
| 173 | 173 | $t = ($connexion['type'] ?? 'sql'); |
| 174 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim((string) $connexion['last']); |
|
| 175 | - $f = $t . $serveur; |
|
| 176 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 174 | + $m = "Erreur $e de $t: ".sql_error($serveur)."\nin ".sql_error_backtrace()."\n".trim((string) $connexion['last']); |
|
| 175 | + $f = $t.$serveur; |
|
| 176 | + spip_log($m, $f.'.'._LOG_ERREUR); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | // si en cours d'installation ou si db=@test@ on ne pose rien |
| 260 | 260 | // car c'est un test de connexion |
| 261 | 261 | if (!defined('_ECRIRE_INSTALL') && $db !== '@test@') { |
| 262 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 262 | + $f = _DIR_TMP.$type.'.'.substr(md5($host.$port.$db), 0, 8).'.out'; |
|
| 263 | 263 | } elseif ($db == '@test@') { |
| 264 | 264 | $db = ''; |
| 265 | 265 | } |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | // En cas d'indisponibilite du serveur, eviter de le bombarder |
| 299 | 299 | if ($f) { |
| 300 | 300 | @touch($f); |
| 301 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 301 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS); |
|
| 302 | 302 | } |
| 303 | 303 | return null; |
| 304 | 304 | } |
@@ -395,11 +395,11 @@ discard block |
||
| 395 | 395 | } elseif (is_array($a)) { |
| 396 | 396 | return implode(',', array_map('_q', $a)); |
| 397 | 397 | } elseif (is_scalar($a)) { |
| 398 | - return ("'" . addslashes($a) . "'"); |
|
| 398 | + return ("'".addslashes($a)."'"); |
|
| 399 | 399 | } elseif ($a === null) { |
| 400 | 400 | return "''"; |
| 401 | 401 | } |
| 402 | - throw new \RuntimeException('Can’t use _q with ' . gettype($a)); |
|
| 402 | + throw new \RuntimeException('Can’t use _q with '.gettype($a)); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $next = reset($textes); |
| 451 | 451 | if ( |
| 452 | 452 | str_starts_with((string) $next, "'") |
| 453 | - && strpos($query_echappees, $part . $next, $currentpos) === $nextpos |
|
| 453 | + && strpos($query_echappees, $part.$next, $currentpos) === $nextpos |
|
| 454 | 454 | ) { |
| 455 | 455 | $part .= array_shift($textes); |
| 456 | 456 | } |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | $parts[$k] = [ |
| 463 | 463 | 'texte' => $part, |
| 464 | 464 | 'position' => $nextpos, |
| 465 | - 'placeholder' => '%' . $k . '$s', |
|
| 465 | + 'placeholder' => '%'.$k.'$s', |
|
| 466 | 466 | ]; |
| 467 | 467 | $currentpos = $nextpos + strlen((string) $part); |
| 468 | 468 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | define('_VERSION_ARCHIVE', '1.3'); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @return string |
| 38 | 38 | **/ |
| 39 | 39 | function base_dump_meta_name($rub) { |
| 40 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 40 | + return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -52,14 +52,14 @@ discard block |
||
| 52 | 52 | * @return string |
| 53 | 53 | **/ |
| 54 | 54 | function base_dump_dir($meta) { |
| 55 | - include_spip('inc/documents'); |
|
| 56 | - // determine upload va aussi initialiser l'index "restreint" |
|
| 57 | - $maindir = determine_upload(); |
|
| 58 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 59 | - $maindir = _DIR_DUMP; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return sous_repertoire($maindir, $meta); |
|
| 55 | + include_spip('inc/documents'); |
|
| 56 | + // determine upload va aussi initialiser l'index "restreint" |
|
| 57 | + $maindir = determine_upload(); |
|
| 58 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 59 | + $maindir = _DIR_DUMP; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return sous_repertoire($maindir, $meta); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -73,28 +73,28 @@ discard block |
||
| 73 | 73 | * @return array |
| 74 | 74 | */ |
| 75 | 75 | function base_lister_toutes_tables( |
| 76 | - $serveur = '', |
|
| 77 | - $tables = [], |
|
| 78 | - $exclude = [], |
|
| 79 | - $affiche_vrai_prefixe = false |
|
| 76 | + $serveur = '', |
|
| 77 | + $tables = [], |
|
| 78 | + $exclude = [], |
|
| 79 | + $affiche_vrai_prefixe = false |
|
| 80 | 80 | ) { |
| 81 | - spip_connect($serveur); |
|
| 82 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 83 | - $prefixe = $connexion['prefixe']; |
|
| 84 | - |
|
| 85 | - $p = '/^' . $prefixe . '/'; |
|
| 86 | - $res = $tables; |
|
| 87 | - foreach (sql_alltable(null, $serveur) as $t) { |
|
| 88 | - if (preg_match($p, (string) $t)) { |
|
| 89 | - $t1 = preg_replace($p, 'spip', (string) $t); |
|
| 90 | - if (!in_array($t1, $tables) && !in_array($t1, $exclude)) { |
|
| 91 | - $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - sort($res); |
|
| 96 | - |
|
| 97 | - return $res; |
|
| 81 | + spip_connect($serveur); |
|
| 82 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 83 | + $prefixe = $connexion['prefixe']; |
|
| 84 | + |
|
| 85 | + $p = '/^' . $prefixe . '/'; |
|
| 86 | + $res = $tables; |
|
| 87 | + foreach (sql_alltable(null, $serveur) as $t) { |
|
| 88 | + if (preg_match($p, (string) $t)) { |
|
| 89 | + $t1 = preg_replace($p, 'spip', (string) $t); |
|
| 90 | + if (!in_array($t1, $tables) && !in_array($t1, $exclude)) { |
|
| 91 | + $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + sort($res); |
|
| 96 | + |
|
| 97 | + return $res; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | * @return string |
| 105 | 105 | */ |
| 106 | 106 | function base_prefixe_tables($serveur = '') { |
| 107 | - spip_connect($serveur); |
|
| 108 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 107 | + spip_connect($serveur); |
|
| 108 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 109 | 109 | |
| 110 | - return $connexion['prefixe']; |
|
| 110 | + return $connexion['prefixe']; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -122,26 +122,26 @@ discard block |
||
| 122 | 122 | * @return array |
| 123 | 123 | */ |
| 124 | 124 | function base_saisie_tables($name, $tables, $exclude = [], $post = null, $serveur = '') { |
| 125 | - include_spip('inc/filtres'); |
|
| 126 | - $res = []; |
|
| 127 | - foreach ($tables as $k => $t) { |
|
| 128 | - // par defaut tout est coche sauf les tables dans $exclude |
|
| 129 | - $check = is_null($post) ? !in_array($t, $exclude) : in_array($t, $post); |
|
| 130 | - |
|
| 131 | - $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 132 | - . "[]' id='$name$k'" |
|
| 133 | - . ($check ? " checked='checked'" : '') |
|
| 134 | - . "/>\n" |
|
| 135 | - . "<label for='$name$k'>$t</label>" |
|
| 136 | - . ' (' |
|
| 137 | - . sinon( |
|
| 138 | - singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 139 | - _T('dump:aucune_donnee') |
|
| 140 | - ) |
|
| 141 | - . ')'; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $res; |
|
| 125 | + include_spip('inc/filtres'); |
|
| 126 | + $res = []; |
|
| 127 | + foreach ($tables as $k => $t) { |
|
| 128 | + // par defaut tout est coche sauf les tables dans $exclude |
|
| 129 | + $check = is_null($post) ? !in_array($t, $exclude) : in_array($t, $post); |
|
| 130 | + |
|
| 131 | + $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 132 | + . "[]' id='$name$k'" |
|
| 133 | + . ($check ? " checked='checked'" : '') |
|
| 134 | + . "/>\n" |
|
| 135 | + . "<label for='$name$k'>$t</label>" |
|
| 136 | + . ' (' |
|
| 137 | + . sinon( |
|
| 138 | + singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 139 | + _T('dump:aucune_donnee') |
|
| 140 | + ) |
|
| 141 | + . ')'; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $res; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -153,27 +153,27 @@ discard block |
||
| 153 | 153 | * @return array |
| 154 | 154 | */ |
| 155 | 155 | function lister_tables_noexport() { |
| 156 | - // par defaut tout est exporte sauf les tables ci-dessous |
|
| 157 | - static $EXPORT_tables_noexport = null; |
|
| 158 | - if (!is_null($EXPORT_tables_noexport)) { |
|
| 159 | - return $EXPORT_tables_noexport; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $EXPORT_tables_noexport = [ |
|
| 163 | - 'spip_caches', // plugin invalideur |
|
| 164 | - 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 165 | - 'spip_test', // c'est un test ! |
|
| 166 | - #'spip_referers', |
|
| 167 | - #'spip_referers_articles', |
|
| 168 | - #'spip_visites', |
|
| 169 | - #'spip_visites_articles', |
|
| 170 | - #'spip_versions', |
|
| 171 | - #'spip_versions_fragments' |
|
| 172 | - ]; |
|
| 173 | - |
|
| 174 | - $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 175 | - |
|
| 176 | - return $EXPORT_tables_noexport; |
|
| 156 | + // par defaut tout est exporte sauf les tables ci-dessous |
|
| 157 | + static $EXPORT_tables_noexport = null; |
|
| 158 | + if (!is_null($EXPORT_tables_noexport)) { |
|
| 159 | + return $EXPORT_tables_noexport; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $EXPORT_tables_noexport = [ |
|
| 163 | + 'spip_caches', // plugin invalideur |
|
| 164 | + 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 165 | + 'spip_test', // c'est un test ! |
|
| 166 | + #'spip_referers', |
|
| 167 | + #'spip_referers_articles', |
|
| 168 | + #'spip_visites', |
|
| 169 | + #'spip_visites_articles', |
|
| 170 | + #'spip_versions', |
|
| 171 | + #'spip_versions_fragments' |
|
| 172 | + ]; |
|
| 173 | + |
|
| 174 | + $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 175 | + |
|
| 176 | + return $EXPORT_tables_noexport; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -184,25 +184,25 @@ discard block |
||
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | 186 | function lister_tables_noimport() { |
| 187 | - static $IMPORT_tables_noimport = null; |
|
| 188 | - if (!is_null($IMPORT_tables_noimport)) { |
|
| 189 | - return $IMPORT_tables_noimport; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - $IMPORT_tables_noimport = []; |
|
| 193 | - // par defaut tout est importe sauf les tables ci-dessous |
|
| 194 | - // possibiliter de definir cela tables via la meta |
|
| 195 | - // compatibilite |
|
| 196 | - if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 197 | - $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 198 | - if (!is_array($IMPORT_tables_noimport)) { |
|
| 199 | - include_spip('inc/meta'); |
|
| 200 | - effacer_meta('IMPORT_tables_noimport'); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 204 | - |
|
| 205 | - return $IMPORT_tables_noimport; |
|
| 187 | + static $IMPORT_tables_noimport = null; |
|
| 188 | + if (!is_null($IMPORT_tables_noimport)) { |
|
| 189 | + return $IMPORT_tables_noimport; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + $IMPORT_tables_noimport = []; |
|
| 193 | + // par defaut tout est importe sauf les tables ci-dessous |
|
| 194 | + // possibiliter de definir cela tables via la meta |
|
| 195 | + // compatibilite |
|
| 196 | + if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 197 | + $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 198 | + if (!is_array($IMPORT_tables_noimport)) { |
|
| 199 | + include_spip('inc/meta'); |
|
| 200 | + effacer_meta('IMPORT_tables_noimport'); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 204 | + |
|
| 205 | + return $IMPORT_tables_noimport; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
@@ -214,23 +214,23 @@ discard block |
||
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | 216 | function lister_tables_noerase() { |
| 217 | - static $IMPORT_tables_noerase = null; |
|
| 218 | - if (!is_null($IMPORT_tables_noerase)) { |
|
| 219 | - return $IMPORT_tables_noerase; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $IMPORT_tables_noerase = [ |
|
| 223 | - 'spip_meta', |
|
| 224 | - // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 225 | - // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 226 | - 'spip_referers', |
|
| 227 | - 'spip_referers_articles', |
|
| 228 | - 'spip_visites', |
|
| 229 | - 'spip_visites_articles' |
|
| 230 | - ]; |
|
| 231 | - $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 232 | - |
|
| 233 | - return $IMPORT_tables_noerase; |
|
| 217 | + static $IMPORT_tables_noerase = null; |
|
| 218 | + if (!is_null($IMPORT_tables_noerase)) { |
|
| 219 | + return $IMPORT_tables_noerase; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $IMPORT_tables_noerase = [ |
|
| 223 | + 'spip_meta', |
|
| 224 | + // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 225 | + // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 226 | + 'spip_referers', |
|
| 227 | + 'spip_referers_articles', |
|
| 228 | + 'spip_visites', |
|
| 229 | + 'spip_visites_articles' |
|
| 230 | + ]; |
|
| 231 | + $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 232 | + |
|
| 233 | + return $IMPORT_tables_noerase; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
@@ -244,86 +244,86 @@ discard block |
||
| 244 | 244 | * @return array |
| 245 | 245 | */ |
| 246 | 246 | function base_liste_table_for_dump($exclude_tables = []) { |
| 247 | - $tables_for_dump = []; |
|
| 248 | - $tables_pointees = []; |
|
| 249 | - $tables = []; |
|
| 250 | - $tables_principales = $GLOBALS['tables_principales']; |
|
| 251 | - $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 252 | - $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 253 | - |
|
| 254 | - if ( |
|
| 255 | - include_spip('base/objets') |
|
| 256 | - && function_exists('lister_tables_objets_sql') |
|
| 257 | - ) { |
|
| 258 | - $tables = lister_tables_objets_sql(); |
|
| 259 | - foreach ($tables as $t => $infos) { |
|
| 260 | - if ($infos['principale'] && !isset($tables_principales[$t])) { |
|
| 261 | - $tables_principales[$t] = true; |
|
| 262 | - } |
|
| 263 | - if (!$infos['principale'] && !isset($tables_auxiliaires[$t])) { |
|
| 264 | - $tables_auxiliaires[$t] = true; |
|
| 265 | - } |
|
| 266 | - if (is_countable($infos['tables_jointures']) ? count($infos['tables_jointures']) : 0) { |
|
| 267 | - $tables_jointures[$t] = array_merge( |
|
| 268 | - $tables_jointures[$t] ?? [], |
|
| 269 | - $infos['tables_jointures'] |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // on construit un index des tables de liens |
|
| 276 | - // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 277 | - $tables_for_link = []; |
|
| 278 | - foreach ($tables_jointures as $table => $liste_relations) { |
|
| 279 | - if (is_array($liste_relations)) { |
|
| 280 | - $nom = $table; |
|
| 281 | - if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 282 | - $nom = "spip_$table"; |
|
| 283 | - } |
|
| 284 | - if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 285 | - foreach ($liste_relations as $link_table) { |
|
| 286 | - if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 287 | - $tables_for_link[$link_table][] = $nom; |
|
| 288 | - } else { |
|
| 289 | - if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 290 | - $tables_for_link["spip_$link_table"][] = $nom; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $liste_tables = [...array_keys($tables_principales), ...array_keys($tables_auxiliaires), ...array_keys($tables)]; |
|
| 299 | - foreach ($liste_tables as $table) { |
|
| 300 | - // $name = preg_replace("{^spip_}","",$table); |
|
| 301 | - if ( |
|
| 302 | - !isset($tables_pointees[$table]) |
|
| 303 | - && !in_array($table, $exclude_tables) |
|
| 304 | - && !isset($tables_for_link[$table]) |
|
| 305 | - ) { |
|
| 306 | - $tables_for_dump[] = $table; |
|
| 307 | - $tables_pointees[$table] = 1; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - foreach ($tables_for_link as $link_table => $liste) { |
|
| 311 | - $connecte = true; |
|
| 312 | - foreach ($liste as $connect_table) { |
|
| 313 | - if (!in_array($connect_table, $tables_for_dump)) { |
|
| 314 | - $connecte = false; |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - if ($connecte) { |
|
| 318 | - # on ajoute les liaisons en premier |
|
| 319 | - # si une restauration est interrompue, |
|
| 320 | - # cela se verra mieux si il manque des objets |
|
| 321 | - # que des liens |
|
| 322 | - array_unshift($tables_for_dump, $link_table); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - return [$tables_for_dump, $tables_for_link]; |
|
| 247 | + $tables_for_dump = []; |
|
| 248 | + $tables_pointees = []; |
|
| 249 | + $tables = []; |
|
| 250 | + $tables_principales = $GLOBALS['tables_principales']; |
|
| 251 | + $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 252 | + $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 253 | + |
|
| 254 | + if ( |
|
| 255 | + include_spip('base/objets') |
|
| 256 | + && function_exists('lister_tables_objets_sql') |
|
| 257 | + ) { |
|
| 258 | + $tables = lister_tables_objets_sql(); |
|
| 259 | + foreach ($tables as $t => $infos) { |
|
| 260 | + if ($infos['principale'] && !isset($tables_principales[$t])) { |
|
| 261 | + $tables_principales[$t] = true; |
|
| 262 | + } |
|
| 263 | + if (!$infos['principale'] && !isset($tables_auxiliaires[$t])) { |
|
| 264 | + $tables_auxiliaires[$t] = true; |
|
| 265 | + } |
|
| 266 | + if (is_countable($infos['tables_jointures']) ? count($infos['tables_jointures']) : 0) { |
|
| 267 | + $tables_jointures[$t] = array_merge( |
|
| 268 | + $tables_jointures[$t] ?? [], |
|
| 269 | + $infos['tables_jointures'] |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // on construit un index des tables de liens |
|
| 276 | + // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 277 | + $tables_for_link = []; |
|
| 278 | + foreach ($tables_jointures as $table => $liste_relations) { |
|
| 279 | + if (is_array($liste_relations)) { |
|
| 280 | + $nom = $table; |
|
| 281 | + if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 282 | + $nom = "spip_$table"; |
|
| 283 | + } |
|
| 284 | + if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 285 | + foreach ($liste_relations as $link_table) { |
|
| 286 | + if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 287 | + $tables_for_link[$link_table][] = $nom; |
|
| 288 | + } else { |
|
| 289 | + if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 290 | + $tables_for_link["spip_$link_table"][] = $nom; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $liste_tables = [...array_keys($tables_principales), ...array_keys($tables_auxiliaires), ...array_keys($tables)]; |
|
| 299 | + foreach ($liste_tables as $table) { |
|
| 300 | + // $name = preg_replace("{^spip_}","",$table); |
|
| 301 | + if ( |
|
| 302 | + !isset($tables_pointees[$table]) |
|
| 303 | + && !in_array($table, $exclude_tables) |
|
| 304 | + && !isset($tables_for_link[$table]) |
|
| 305 | + ) { |
|
| 306 | + $tables_for_dump[] = $table; |
|
| 307 | + $tables_pointees[$table] = 1; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + foreach ($tables_for_link as $link_table => $liste) { |
|
| 311 | + $connecte = true; |
|
| 312 | + foreach ($liste as $connect_table) { |
|
| 313 | + if (!in_array($connect_table, $tables_for_dump)) { |
|
| 314 | + $connecte = false; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + if ($connecte) { |
|
| 318 | + # on ajoute les liaisons en premier |
|
| 319 | + # si une restauration est interrompue, |
|
| 320 | + # cela se verra mieux si il manque des objets |
|
| 321 | + # que des liens |
|
| 322 | + array_unshift($tables_for_dump, $link_table); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + return [$tables_for_dump, $tables_for_link]; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -338,35 +338,35 @@ discard block |
||
| 338 | 338 | * @param string $serveur |
| 339 | 339 | */ |
| 340 | 340 | function base_vider_tables_destination_copie($tables, $exclure_tables = [], $serveur = '') { |
| 341 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 342 | - |
|
| 343 | - spip_log( |
|
| 344 | - 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . implode(', ', $tables), |
|
| 345 | - 'base.' . _LOG_INFO_IMPORTANTE |
|
| 346 | - ); |
|
| 347 | - foreach ($tables as $table) { |
|
| 348 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 349 | - if (!in_array($table, $exclure_tables) && ($table != 'spip_auteurs' || $serveur != '')) { |
|
| 350 | - // regarder si il y a au moins un champ impt='non' |
|
| 351 | - $desc = $trouver_table($table, $serveur); |
|
| 352 | - if (isset($desc['field']['impt'])) { |
|
| 353 | - sql_delete($table, "impt='oui'", $serveur); |
|
| 354 | - } elseif ($desc) { |
|
| 355 | - sql_delete($table, '', $serveur); |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 361 | - // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 362 | - if ( |
|
| 363 | - $serveur == '' |
|
| 364 | - && in_array('spip_auteurs', $tables) |
|
| 365 | - && !in_array('spip_auteurs', $exclure_tables) |
|
| 366 | - ) { |
|
| 367 | - base_conserver_copieur(true, $serveur); |
|
| 368 | - sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 369 | - } |
|
| 341 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 342 | + |
|
| 343 | + spip_log( |
|
| 344 | + 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . implode(', ', $tables), |
|
| 345 | + 'base.' . _LOG_INFO_IMPORTANTE |
|
| 346 | + ); |
|
| 347 | + foreach ($tables as $table) { |
|
| 348 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 349 | + if (!in_array($table, $exclure_tables) && ($table != 'spip_auteurs' || $serveur != '')) { |
|
| 350 | + // regarder si il y a au moins un champ impt='non' |
|
| 351 | + $desc = $trouver_table($table, $serveur); |
|
| 352 | + if (isset($desc['field']['impt'])) { |
|
| 353 | + sql_delete($table, "impt='oui'", $serveur); |
|
| 354 | + } elseif ($desc) { |
|
| 355 | + sql_delete($table, '', $serveur); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 361 | + // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 362 | + if ( |
|
| 363 | + $serveur == '' |
|
| 364 | + && in_array('spip_auteurs', $tables) |
|
| 365 | + && !in_array('spip_auteurs', $exclure_tables) |
|
| 366 | + ) { |
|
| 367 | + base_conserver_copieur(true, $serveur); |
|
| 368 | + sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 369 | + } |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -377,36 +377,36 @@ discard block |
||
| 377 | 377 | * @return void |
| 378 | 378 | */ |
| 379 | 379 | function base_conserver_copieur($move = true, $serveur = '') { |
| 380 | - // s'asurer qu'on a pas deja fait la manip ! |
|
| 381 | - if ($GLOBALS['visiteur_session']['id_auteur'] > 0 && sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 382 | - spip_log( |
|
| 383 | - 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 384 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 385 | - ); |
|
| 386 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 387 | - if ($move) { |
|
| 388 | - sql_updateq( |
|
| 389 | - 'spip_auteurs', |
|
| 390 | - ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 391 | - 'id_auteur=' . (int) $GLOBALS['visiteur_session']['id_auteur'], |
|
| 392 | - [], |
|
| 393 | - $serveur |
|
| 394 | - ); |
|
| 395 | - } else { |
|
| 396 | - $row = sql_fetsel( |
|
| 397 | - '*', |
|
| 398 | - 'spip_auteurs', |
|
| 399 | - 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 400 | - '', |
|
| 401 | - '', |
|
| 402 | - '', |
|
| 403 | - '', |
|
| 404 | - $serveur |
|
| 405 | - ); |
|
| 406 | - $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 407 | - sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 408 | - } |
|
| 409 | - } |
|
| 380 | + // s'asurer qu'on a pas deja fait la manip ! |
|
| 381 | + if ($GLOBALS['visiteur_session']['id_auteur'] > 0 && sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 382 | + spip_log( |
|
| 383 | + 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 384 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 385 | + ); |
|
| 386 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 387 | + if ($move) { |
|
| 388 | + sql_updateq( |
|
| 389 | + 'spip_auteurs', |
|
| 390 | + ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 391 | + 'id_auteur=' . (int) $GLOBALS['visiteur_session']['id_auteur'], |
|
| 392 | + [], |
|
| 393 | + $serveur |
|
| 394 | + ); |
|
| 395 | + } else { |
|
| 396 | + $row = sql_fetsel( |
|
| 397 | + '*', |
|
| 398 | + 'spip_auteurs', |
|
| 399 | + 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 400 | + '', |
|
| 401 | + '', |
|
| 402 | + '', |
|
| 403 | + '', |
|
| 404 | + $serveur |
|
| 405 | + ); |
|
| 406 | + $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 407 | + sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -421,21 +421,21 @@ discard block |
||
| 421 | 421 | * @param string $serveur |
| 422 | 422 | */ |
| 423 | 423 | function base_detruire_copieur_si_besoin($serveur = '') { |
| 424 | - // rien a faire si ce n'est pas le serveur principal ! |
|
| 425 | - if ($serveur == '') { |
|
| 426 | - if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 427 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 428 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 429 | - } else { |
|
| 430 | - spip_log( |
|
| 431 | - "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 432 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 433 | - ); |
|
| 434 | - sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 435 | - } |
|
| 436 | - } else { |
|
| 437 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | - } |
|
| 424 | + // rien a faire si ce n'est pas le serveur principal ! |
|
| 425 | + if ($serveur == '') { |
|
| 426 | + if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 427 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 428 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 429 | + } else { |
|
| 430 | + spip_log( |
|
| 431 | + "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 432 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 433 | + ); |
|
| 434 | + sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 435 | + } |
|
| 436 | + } else { |
|
| 437 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | + } |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | /** |
@@ -450,40 +450,40 @@ discard block |
||
| 450 | 450 | * @return array |
| 451 | 451 | */ |
| 452 | 452 | function base_preparer_table_dest($table, $desc, $serveur_dest, $init = false) { |
| 453 | - $upgrade = false; |
|
| 454 | - // si la table existe et qu'on est a l'init, la dropper |
|
| 455 | - if (($desc_dest = sql_showtable($table, true, $serveur_dest)) && $init) { |
|
| 456 | - if ($serveur_dest == '' && in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 457 | - // ne pas dropper auteurs et meta sur le serveur principal |
|
| 458 | - // faire un simple upgrade a la place |
|
| 459 | - // pour ajouter les champs manquants |
|
| 460 | - $upgrade = true; |
|
| 461 | - // coherence avec le drop sur les autres tables |
|
| 462 | - base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 463 | - if ($table == 'spip_meta') { |
|
| 464 | - // virer les version base qui vont venir avec l'import |
|
| 465 | - sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 466 | - // hum casse la base si pas version_installee a l'import ... |
|
| 467 | - sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 468 | - } |
|
| 469 | - } else { |
|
| 470 | - sql_drop_table($table, '', $serveur_dest); |
|
| 471 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 472 | - } |
|
| 473 | - $desc_dest = false; |
|
| 474 | - } |
|
| 475 | - // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 476 | - if (!$desc_dest) { |
|
| 477 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 478 | - include_spip('base/create'); |
|
| 479 | - creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 480 | - $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 481 | - } |
|
| 482 | - if (!$desc_dest) { |
|
| 483 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return $desc_dest; |
|
| 453 | + $upgrade = false; |
|
| 454 | + // si la table existe et qu'on est a l'init, la dropper |
|
| 455 | + if (($desc_dest = sql_showtable($table, true, $serveur_dest)) && $init) { |
|
| 456 | + if ($serveur_dest == '' && in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 457 | + // ne pas dropper auteurs et meta sur le serveur principal |
|
| 458 | + // faire un simple upgrade a la place |
|
| 459 | + // pour ajouter les champs manquants |
|
| 460 | + $upgrade = true; |
|
| 461 | + // coherence avec le drop sur les autres tables |
|
| 462 | + base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 463 | + if ($table == 'spip_meta') { |
|
| 464 | + // virer les version base qui vont venir avec l'import |
|
| 465 | + sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 466 | + // hum casse la base si pas version_installee a l'import ... |
|
| 467 | + sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 468 | + } |
|
| 469 | + } else { |
|
| 470 | + sql_drop_table($table, '', $serveur_dest); |
|
| 471 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 472 | + } |
|
| 473 | + $desc_dest = false; |
|
| 474 | + } |
|
| 475 | + // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 476 | + if (!$desc_dest) { |
|
| 477 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 478 | + include_spip('base/create'); |
|
| 479 | + creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 480 | + $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 481 | + } |
|
| 482 | + if (!$desc_dest) { |
|
| 483 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return $desc_dest; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -529,211 +529,211 @@ discard block |
||
| 529 | 529 | */ |
| 530 | 530 | function base_copier_tables($status_file, $tables, $serveur_source, $serveur_dest, $options = []) { |
| 531 | 531 | |
| 532 | - $status = []; |
|
| 533 | - $callback_progression = $options['callback_progression'] ?? ''; |
|
| 534 | - $max_time = $options['max_time'] ?? 0; |
|
| 535 | - $drop_source = $options['drop_source'] ?? false; |
|
| 536 | - $no_erase_dest = $options['no_erase_dest'] ?? []; |
|
| 537 | - $where = $options['where'] ?? []; |
|
| 538 | - $fonction_base_inserer = $options['fonction_base_inserer'] ?? 'inserer_copie'; |
|
| 539 | - $desc_tables_dest = $options['desc_tables_dest'] ?? []; |
|
| 540 | - $racine_fonctions = $options['racine_fonctions_dest'] ?? 'base'; |
|
| 541 | - $data_pool = $options['data_pool'] ?? 50 * 1024; |
|
| 542 | - |
|
| 543 | - spip_log( |
|
| 544 | - 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 545 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 546 | - ); |
|
| 547 | - |
|
| 548 | - if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 549 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 550 | - |
|
| 551 | - return true; // echec mais on a fini, donc true |
|
| 552 | - } |
|
| 553 | - if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 554 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 555 | - |
|
| 556 | - return true; // echec mais on a fini, donc true |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - if ( |
|
| 560 | - !lire_fichier($status_file, $status) |
|
| 561 | - || !($status = unserialize($status)) |
|
| 562 | - ) { |
|
| 563 | - $status = []; |
|
| 564 | - } |
|
| 565 | - $status['etape'] = 'basecopie'; |
|
| 566 | - |
|
| 567 | - // puis relister les tables a importer |
|
| 568 | - // et les vider si besoin, au moment du premier passage ici |
|
| 569 | - $initialisation_copie = $status['dump_status_copie'] ?? 0; |
|
| 570 | - |
|
| 571 | - // si init pas encore faite, vider les tables du serveur destination |
|
| 572 | - if (!$initialisation_copie) { |
|
| 573 | - if ( |
|
| 574 | - !$vider_tables_destination_copie = charger_fonction( |
|
| 575 | - 'vider_tables_destination_copie', |
|
| 576 | - $racine_fonctions, |
|
| 577 | - true |
|
| 578 | - ) |
|
| 579 | - ) { |
|
| 580 | - spip_log( |
|
| 581 | - "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 582 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 583 | - ); |
|
| 584 | - |
|
| 585 | - return true; // echec mais on a fini, donc true |
|
| 586 | - } |
|
| 587 | - $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 588 | - $status['dump_status_copie'] = 'ok'; |
|
| 589 | - ecrire_fichier($status_file, serialize($status)); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 593 | - if (in_array('spip_auteurs', $tables)) { |
|
| 594 | - $tables = array_diff($tables, ['spip_auteurs']); |
|
| 595 | - $tables[] = 'spip_auteurs'; |
|
| 596 | - } |
|
| 597 | - if (in_array('spip_meta', $tables)) { |
|
| 598 | - $tables = array_diff($tables, ['spip_meta']); |
|
| 599 | - $tables[] = 'spip_meta'; |
|
| 600 | - } |
|
| 601 | - spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 602 | - |
|
| 603 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 604 | - |
|
| 605 | - foreach ($tables as $table) { |
|
| 606 | - // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 607 | - // sinon chercher la vraie table |
|
| 608 | - $desc_source = false; |
|
| 609 | - if (str_starts_with((string) $table, 'spip_')) { |
|
| 610 | - $desc_source = $trouver_table(preg_replace(',^spip_,', '', (string) $table), $serveur_source, true); |
|
| 611 | - } |
|
| 612 | - if (!$desc_source || !isset($desc_source['exist']) || !$desc_source['exist']) { |
|
| 613 | - $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - // verifier que la table est presente dans la base source |
|
| 617 | - if ($desc_source) { |
|
| 618 | - // $status['tables_copiees'][$table] contient l'avancement |
|
| 619 | - // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 620 | - if (!isset($status['tables_copiees'][$table])) { |
|
| 621 | - $status['tables_copiees'][$table] = 0; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - if ( |
|
| 625 | - is_numeric($status['tables_copiees'][$table]) |
|
| 626 | - && $status['tables_copiees'][$table] >= 0 |
|
| 627 | - && ($desc_dest = $preparer_table_dest( |
|
| 628 | - $table, |
|
| 629 | - $desc_tables_dest[$table] ?? $desc_source, |
|
| 630 | - $serveur_dest, |
|
| 631 | - $status['tables_copiees'][$table] == 0 |
|
| 632 | - )) |
|
| 633 | - ) { |
|
| 634 | - if ($callback_progression) { |
|
| 635 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 636 | - } |
|
| 637 | - while (true) { |
|
| 638 | - $n = (int) $status['tables_copiees'][$table]; |
|
| 639 | - // on copie par lot de 400 |
|
| 640 | - $res = sql_select( |
|
| 641 | - '*', |
|
| 642 | - $table, |
|
| 643 | - $where[$table] ?? '', |
|
| 644 | - '', |
|
| 645 | - '', |
|
| 646 | - "$n,400", |
|
| 647 | - '', |
|
| 648 | - $serveur_source |
|
| 649 | - ); |
|
| 650 | - while ($row = sql_fetch($res, $serveur_source)) { |
|
| 651 | - $rows = [$row]; |
|
| 652 | - // lire un groupe de donnees si demande en option |
|
| 653 | - // (permet un envoi par lot vers la destination) |
|
| 654 | - if ($data_pool > 0) { |
|
| 655 | - $s = strlen(serialize($row)); |
|
| 656 | - while ($s < $data_pool && ($row = sql_fetch($res, $serveur_source))) { |
|
| 657 | - $s += strlen(serialize($row)); |
|
| 658 | - $rows[] = $row; |
|
| 659 | - } |
|
| 660 | - } |
|
| 661 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 662 | - // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 663 | - if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 664 | - // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 665 | - spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 666 | - $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 667 | - ecrire_fichier($status_file, serialize($status)); |
|
| 668 | - |
|
| 669 | - // copie finie |
|
| 670 | - return true; |
|
| 671 | - } |
|
| 672 | - $status['tables_copiees'][$table] += count($rows); |
|
| 673 | - if ($max_time && time() > $max_time) { |
|
| 674 | - break; |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - if ($n == $status['tables_copiees'][$table]) { |
|
| 678 | - break; |
|
| 679 | - } |
|
| 680 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 681 | - if ($callback_progression) { |
|
| 682 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 683 | - } |
|
| 684 | - ecrire_fichier($status_file, serialize($status)); |
|
| 685 | - if ($max_time && time() > $max_time) { |
|
| 686 | - return false; |
|
| 687 | - } // on a pas fini, mais le temps imparti est ecoule |
|
| 688 | - } |
|
| 689 | - if ($drop_source) { |
|
| 690 | - sql_drop_table($table, '', $serveur_source); |
|
| 691 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 692 | - } |
|
| 693 | - $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 694 | - ecrire_fichier($status_file, serialize($status)); |
|
| 695 | - spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 696 | - if ($callback_progression) { |
|
| 697 | - $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 698 | - } |
|
| 699 | - } else { |
|
| 700 | - if ($status['tables_copiees'][$table] < 0) { |
|
| 701 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 702 | - } |
|
| 703 | - if ($callback_progression) { |
|
| 704 | - $callback_progression( |
|
| 705 | - 0, |
|
| 706 | - $status['tables_copiees'][$table], |
|
| 707 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) && $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 708 | - ); |
|
| 709 | - } |
|
| 710 | - } |
|
| 711 | - } else { |
|
| 712 | - $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 713 | - ecrire_fichier($status_file, serialize($status)); |
|
| 714 | - spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 715 | - } |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 719 | - // abandonner |
|
| 720 | - if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
|
| 721 | - spip_log( |
|
| 722 | - 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 723 | - 'dump.' . _LOG_ERREUR |
|
| 724 | - ); |
|
| 725 | - $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 726 | - ecrire_fichier($status_file, serialize($status)); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 730 | - $detruire_copieur_si_besoin($serveur_dest); |
|
| 731 | - } else { |
|
| 732 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - // OK, copie complete |
|
| 736 | - return true; |
|
| 532 | + $status = []; |
|
| 533 | + $callback_progression = $options['callback_progression'] ?? ''; |
|
| 534 | + $max_time = $options['max_time'] ?? 0; |
|
| 535 | + $drop_source = $options['drop_source'] ?? false; |
|
| 536 | + $no_erase_dest = $options['no_erase_dest'] ?? []; |
|
| 537 | + $where = $options['where'] ?? []; |
|
| 538 | + $fonction_base_inserer = $options['fonction_base_inserer'] ?? 'inserer_copie'; |
|
| 539 | + $desc_tables_dest = $options['desc_tables_dest'] ?? []; |
|
| 540 | + $racine_fonctions = $options['racine_fonctions_dest'] ?? 'base'; |
|
| 541 | + $data_pool = $options['data_pool'] ?? 50 * 1024; |
|
| 542 | + |
|
| 543 | + spip_log( |
|
| 544 | + 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 545 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 546 | + ); |
|
| 547 | + |
|
| 548 | + if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 549 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 550 | + |
|
| 551 | + return true; // echec mais on a fini, donc true |
|
| 552 | + } |
|
| 553 | + if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 554 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 555 | + |
|
| 556 | + return true; // echec mais on a fini, donc true |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + if ( |
|
| 560 | + !lire_fichier($status_file, $status) |
|
| 561 | + || !($status = unserialize($status)) |
|
| 562 | + ) { |
|
| 563 | + $status = []; |
|
| 564 | + } |
|
| 565 | + $status['etape'] = 'basecopie'; |
|
| 566 | + |
|
| 567 | + // puis relister les tables a importer |
|
| 568 | + // et les vider si besoin, au moment du premier passage ici |
|
| 569 | + $initialisation_copie = $status['dump_status_copie'] ?? 0; |
|
| 570 | + |
|
| 571 | + // si init pas encore faite, vider les tables du serveur destination |
|
| 572 | + if (!$initialisation_copie) { |
|
| 573 | + if ( |
|
| 574 | + !$vider_tables_destination_copie = charger_fonction( |
|
| 575 | + 'vider_tables_destination_copie', |
|
| 576 | + $racine_fonctions, |
|
| 577 | + true |
|
| 578 | + ) |
|
| 579 | + ) { |
|
| 580 | + spip_log( |
|
| 581 | + "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 582 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 583 | + ); |
|
| 584 | + |
|
| 585 | + return true; // echec mais on a fini, donc true |
|
| 586 | + } |
|
| 587 | + $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 588 | + $status['dump_status_copie'] = 'ok'; |
|
| 589 | + ecrire_fichier($status_file, serialize($status)); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 593 | + if (in_array('spip_auteurs', $tables)) { |
|
| 594 | + $tables = array_diff($tables, ['spip_auteurs']); |
|
| 595 | + $tables[] = 'spip_auteurs'; |
|
| 596 | + } |
|
| 597 | + if (in_array('spip_meta', $tables)) { |
|
| 598 | + $tables = array_diff($tables, ['spip_meta']); |
|
| 599 | + $tables[] = 'spip_meta'; |
|
| 600 | + } |
|
| 601 | + spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 602 | + |
|
| 603 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 604 | + |
|
| 605 | + foreach ($tables as $table) { |
|
| 606 | + // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 607 | + // sinon chercher la vraie table |
|
| 608 | + $desc_source = false; |
|
| 609 | + if (str_starts_with((string) $table, 'spip_')) { |
|
| 610 | + $desc_source = $trouver_table(preg_replace(',^spip_,', '', (string) $table), $serveur_source, true); |
|
| 611 | + } |
|
| 612 | + if (!$desc_source || !isset($desc_source['exist']) || !$desc_source['exist']) { |
|
| 613 | + $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + // verifier que la table est presente dans la base source |
|
| 617 | + if ($desc_source) { |
|
| 618 | + // $status['tables_copiees'][$table] contient l'avancement |
|
| 619 | + // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 620 | + if (!isset($status['tables_copiees'][$table])) { |
|
| 621 | + $status['tables_copiees'][$table] = 0; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + if ( |
|
| 625 | + is_numeric($status['tables_copiees'][$table]) |
|
| 626 | + && $status['tables_copiees'][$table] >= 0 |
|
| 627 | + && ($desc_dest = $preparer_table_dest( |
|
| 628 | + $table, |
|
| 629 | + $desc_tables_dest[$table] ?? $desc_source, |
|
| 630 | + $serveur_dest, |
|
| 631 | + $status['tables_copiees'][$table] == 0 |
|
| 632 | + )) |
|
| 633 | + ) { |
|
| 634 | + if ($callback_progression) { |
|
| 635 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 636 | + } |
|
| 637 | + while (true) { |
|
| 638 | + $n = (int) $status['tables_copiees'][$table]; |
|
| 639 | + // on copie par lot de 400 |
|
| 640 | + $res = sql_select( |
|
| 641 | + '*', |
|
| 642 | + $table, |
|
| 643 | + $where[$table] ?? '', |
|
| 644 | + '', |
|
| 645 | + '', |
|
| 646 | + "$n,400", |
|
| 647 | + '', |
|
| 648 | + $serveur_source |
|
| 649 | + ); |
|
| 650 | + while ($row = sql_fetch($res, $serveur_source)) { |
|
| 651 | + $rows = [$row]; |
|
| 652 | + // lire un groupe de donnees si demande en option |
|
| 653 | + // (permet un envoi par lot vers la destination) |
|
| 654 | + if ($data_pool > 0) { |
|
| 655 | + $s = strlen(serialize($row)); |
|
| 656 | + while ($s < $data_pool && ($row = sql_fetch($res, $serveur_source))) { |
|
| 657 | + $s += strlen(serialize($row)); |
|
| 658 | + $rows[] = $row; |
|
| 659 | + } |
|
| 660 | + } |
|
| 661 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 662 | + // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 663 | + if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 664 | + // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 665 | + spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 666 | + $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 667 | + ecrire_fichier($status_file, serialize($status)); |
|
| 668 | + |
|
| 669 | + // copie finie |
|
| 670 | + return true; |
|
| 671 | + } |
|
| 672 | + $status['tables_copiees'][$table] += count($rows); |
|
| 673 | + if ($max_time && time() > $max_time) { |
|
| 674 | + break; |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + if ($n == $status['tables_copiees'][$table]) { |
|
| 678 | + break; |
|
| 679 | + } |
|
| 680 | + spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 681 | + if ($callback_progression) { |
|
| 682 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 683 | + } |
|
| 684 | + ecrire_fichier($status_file, serialize($status)); |
|
| 685 | + if ($max_time && time() > $max_time) { |
|
| 686 | + return false; |
|
| 687 | + } // on a pas fini, mais le temps imparti est ecoule |
|
| 688 | + } |
|
| 689 | + if ($drop_source) { |
|
| 690 | + sql_drop_table($table, '', $serveur_source); |
|
| 691 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 692 | + } |
|
| 693 | + $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 694 | + ecrire_fichier($status_file, serialize($status)); |
|
| 695 | + spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 696 | + if ($callback_progression) { |
|
| 697 | + $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 698 | + } |
|
| 699 | + } else { |
|
| 700 | + if ($status['tables_copiees'][$table] < 0) { |
|
| 701 | + spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 702 | + } |
|
| 703 | + if ($callback_progression) { |
|
| 704 | + $callback_progression( |
|
| 705 | + 0, |
|
| 706 | + $status['tables_copiees'][$table], |
|
| 707 | + "$table" . ((is_numeric($status['tables_copiees'][$table]) && $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 708 | + ); |
|
| 709 | + } |
|
| 710 | + } |
|
| 711 | + } else { |
|
| 712 | + $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 713 | + ecrire_fichier($status_file, serialize($status)); |
|
| 714 | + spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 715 | + } |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 719 | + // abandonner |
|
| 720 | + if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
|
| 721 | + spip_log( |
|
| 722 | + 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 723 | + 'dump.' . _LOG_ERREUR |
|
| 724 | + ); |
|
| 725 | + $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 726 | + ecrire_fichier($status_file, serialize($status)); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 730 | + $detruire_copieur_si_besoin($serveur_dest); |
|
| 731 | + } else { |
|
| 732 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + // OK, copie complete |
|
| 736 | + return true; |
|
| 737 | 737 | } |
| 738 | 738 | |
| 739 | 739 | /** |
@@ -747,31 +747,31 @@ discard block |
||
| 747 | 747 | */ |
| 748 | 748 | function base_inserer_copie($table, $rows, $desc_dest, $serveur_dest) { |
| 749 | 749 | |
| 750 | - // verifier le nombre d'insertion |
|
| 751 | - $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 752 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 753 | - $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 754 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 755 | - if ($nb - $nb1 < count($rows)) { |
|
| 756 | - spip_log( |
|
| 757 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 758 | - 'dump' . _LOG_INFO_IMPORTANTE |
|
| 759 | - ); |
|
| 760 | - foreach ($rows as $row) { |
|
| 761 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 762 | - $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 763 | - } |
|
| 764 | - // on reverifie le total |
|
| 765 | - $r = 0; |
|
| 766 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 767 | - if ($nb - $nb1 < count($rows)) { |
|
| 768 | - spip_log( |
|
| 769 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 770 | - 'dump' . _LOG_ERREUR |
|
| 771 | - ); |
|
| 772 | - $r = false; |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - return $r; |
|
| 750 | + // verifier le nombre d'insertion |
|
| 751 | + $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 752 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 753 | + $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 754 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 755 | + if ($nb - $nb1 < count($rows)) { |
|
| 756 | + spip_log( |
|
| 757 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 758 | + 'dump' . _LOG_INFO_IMPORTANTE |
|
| 759 | + ); |
|
| 760 | + foreach ($rows as $row) { |
|
| 761 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 762 | + $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 763 | + } |
|
| 764 | + // on reverifie le total |
|
| 765 | + $r = 0; |
|
| 766 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 767 | + if ($nb - $nb1 < count($rows)) { |
|
| 768 | + spip_log( |
|
| 769 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 770 | + 'dump' . _LOG_ERREUR |
|
| 771 | + ); |
|
| 772 | + $r = false; |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + return $r; |
|
| 777 | 777 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @return string |
| 38 | 38 | **/ |
| 39 | 39 | function base_dump_meta_name($rub) { |
| 40 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 40 | + return $meta = "status_dump_{$rub}_".abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
| 83 | 83 | $prefixe = $connexion['prefixe']; |
| 84 | 84 | |
| 85 | - $p = '/^' . $prefixe . '/'; |
|
| 85 | + $p = '/^'.$prefixe.'/'; |
|
| 86 | 86 | $res = $tables; |
| 87 | 87 | foreach (sql_alltable(null, $serveur) as $t) { |
| 88 | 88 | if (preg_match($p, (string) $t)) { |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 342 | 342 | |
| 343 | 343 | spip_log( |
| 344 | - 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . implode(', ', $tables), |
|
| 345 | - 'base.' . _LOG_INFO_IMPORTANTE |
|
| 344 | + 'Vider '.count($tables)." tables sur serveur '$serveur' : ".implode(', ', $tables), |
|
| 345 | + 'base.'._LOG_INFO_IMPORTANTE |
|
| 346 | 346 | ); |
| 347 | 347 | foreach ($tables as $table) { |
| 348 | 348 | // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
@@ -380,15 +380,15 @@ discard block |
||
| 380 | 380 | // s'asurer qu'on a pas deja fait la manip ! |
| 381 | 381 | if ($GLOBALS['visiteur_session']['id_auteur'] > 0 && sql_countsel('spip_auteurs', 'id_auteur>0')) { |
| 382 | 382 | spip_log( |
| 383 | - 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 384 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 383 | + 'Conserver copieur dans id_auteur='.$GLOBALS['visiteur_session']['id_auteur']." pour le serveur '$serveur'", |
|
| 384 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 385 | 385 | ); |
| 386 | 386 | sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
| 387 | 387 | if ($move) { |
| 388 | 388 | sql_updateq( |
| 389 | 389 | 'spip_auteurs', |
| 390 | 390 | ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
| 391 | - 'id_auteur=' . (int) $GLOBALS['visiteur_session']['id_auteur'], |
|
| 391 | + 'id_auteur='.(int) $GLOBALS['visiteur_session']['id_auteur'], |
|
| 392 | 392 | [], |
| 393 | 393 | $serveur |
| 394 | 394 | ); |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | $row = sql_fetsel( |
| 397 | 397 | '*', |
| 398 | 398 | 'spip_auteurs', |
| 399 | - 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 399 | + 'id_auteur='.$GLOBALS['visiteur_session']['id_auteur'], |
|
| 400 | 400 | '', |
| 401 | 401 | '', |
| 402 | 402 | '', |
@@ -424,17 +424,17 @@ discard block |
||
| 424 | 424 | // rien a faire si ce n'est pas le serveur principal ! |
| 425 | 425 | if ($serveur == '') { |
| 426 | 426 | if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
| 427 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 427 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 428 | 428 | sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
| 429 | 429 | } else { |
| 430 | 430 | spip_log( |
| 431 | 431 | "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
| 432 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 432 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 433 | 433 | ); |
| 434 | 434 | sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
| 435 | 435 | } |
| 436 | 436 | } else { |
| 437 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 437 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
@@ -468,19 +468,19 @@ discard block |
||
| 468 | 468 | } |
| 469 | 469 | } else { |
| 470 | 470 | sql_drop_table($table, '', $serveur_dest); |
| 471 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 471 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 472 | 472 | } |
| 473 | 473 | $desc_dest = false; |
| 474 | 474 | } |
| 475 | 475 | // si la table n'existe pas dans la destination, la creer a l'identique ! |
| 476 | 476 | if (!$desc_dest) { |
| 477 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 477 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 478 | 478 | include_spip('base/create'); |
| 479 | 479 | creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
| 480 | 480 | $desc_dest = sql_showtable($table, true, $serveur_dest); |
| 481 | 481 | } |
| 482 | 482 | if (!$desc_dest) { |
| 483 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 483 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'".var_export($desc, 1), 'dump.'._LOG_ERREUR); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | return $desc_dest; |
@@ -541,17 +541,17 @@ discard block |
||
| 541 | 541 | $data_pool = $options['data_pool'] ?? 50 * 1024; |
| 542 | 542 | |
| 543 | 543 | spip_log( |
| 544 | - 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 545 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 544 | + 'Copier '.count($tables)." tables de '$serveur_source' vers '$serveur_dest'", |
|
| 545 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 546 | 546 | ); |
| 547 | 547 | |
| 548 | 548 | if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
| 549 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 549 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 550 | 550 | |
| 551 | 551 | return true; // echec mais on a fini, donc true |
| 552 | 552 | } |
| 553 | 553 | if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
| 554 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 554 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 555 | 555 | |
| 556 | 556 | return true; // echec mais on a fini, donc true |
| 557 | 557 | } |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | ) { |
| 580 | 580 | spip_log( |
| 581 | 581 | "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
| 582 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 582 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 583 | 583 | ); |
| 584 | 584 | |
| 585 | 585 | return true; // echec mais on a fini, donc true |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | $tables = array_diff($tables, ['spip_meta']); |
| 599 | 599 | $tables[] = 'spip_meta'; |
| 600 | 600 | } |
| 601 | - spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 601 | + spip_log('Tables a copier :'.implode(', ', $tables), 'dump.'._LOG_INFO); |
|
| 602 | 602 | |
| 603 | 603 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 604 | 604 | |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | // mais si ca renvoie false c'est une erreur fatale => abandon |
| 663 | 663 | if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
| 664 | 664 | // forcer la sortie, charge a l'appelant de gerer l'echec |
| 665 | - spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 665 | + spip_log("Erreur fatale dans $inserer_copie table $table", 'dump'._LOG_ERREUR); |
|
| 666 | 666 | $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
| 667 | 667 | ecrire_fichier($status_file, serialize($status)); |
| 668 | 668 | |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | if ($n == $status['tables_copiees'][$table]) { |
| 678 | 678 | break; |
| 679 | 679 | } |
| 680 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 680 | + spip_log("recopie $table ".$status['tables_copiees'][$table], 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 681 | 681 | if ($callback_progression) { |
| 682 | 682 | $callback_progression($status['tables_copiees'][$table], 0, $table); |
| 683 | 683 | } |
@@ -688,30 +688,30 @@ discard block |
||
| 688 | 688 | } |
| 689 | 689 | if ($drop_source) { |
| 690 | 690 | sql_drop_table($table, '', $serveur_source); |
| 691 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 691 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 692 | 692 | } |
| 693 | 693 | $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
| 694 | 694 | ecrire_fichier($status_file, serialize($status)); |
| 695 | - spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 695 | + spip_log('tables_recopiees '.implode(',', array_keys($status['tables_copiees'])), 'dump.'._LOG_INFO); |
|
| 696 | 696 | if ($callback_progression) { |
| 697 | 697 | $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
| 698 | 698 | } |
| 699 | 699 | } else { |
| 700 | 700 | if ($status['tables_copiees'][$table] < 0) { |
| 701 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 701 | + spip_log("Table $table deja copiee : ".$status['tables_copiees'][$table], 'dump.'._LOG_INFO); |
|
| 702 | 702 | } |
| 703 | 703 | if ($callback_progression) { |
| 704 | 704 | $callback_progression( |
| 705 | 705 | 0, |
| 706 | 706 | $status['tables_copiees'][$table], |
| 707 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) && $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 707 | + "$table".((is_numeric($status['tables_copiees'][$table]) && $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 708 | 708 | ); |
| 709 | 709 | } |
| 710 | 710 | } |
| 711 | 711 | } else { |
| 712 | 712 | $status['errors'][] = "Impossible de lire la description de la table $table"; |
| 713 | 713 | ecrire_fichier($status_file, serialize($status)); |
| 714 | - spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 714 | + spip_log("Impossible de lire la description de la table $table", 'dump.'._LOG_ERREUR); |
|
| 715 | 715 | } |
| 716 | 716 | } |
| 717 | 717 | |
@@ -719,17 +719,17 @@ discard block |
||
| 719 | 719 | // abandonner |
| 720 | 720 | if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
| 721 | 721 | spip_log( |
| 722 | - 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 723 | - 'dump.' . _LOG_ERREUR |
|
| 722 | + 'Nombre de tables copiees incorrect : '.(is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0).'/'.count($tables), |
|
| 723 | + 'dump.'._LOG_ERREUR |
|
| 724 | 724 | ); |
| 725 | - $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 725 | + $status['errors'][] = 'Nombre de tables copiees incorrect : '.(is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0).'/'.count($tables); |
|
| 726 | 726 | ecrire_fichier($status_file, serialize($status)); |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
| 730 | 730 | $detruire_copieur_si_besoin($serveur_dest); |
| 731 | 731 | } else { |
| 732 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 732 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | // OK, copie complete |
@@ -754,8 +754,8 @@ discard block |
||
| 754 | 754 | $nb = sql_countsel($table, '', '', '', $serveur_dest); |
| 755 | 755 | if ($nb - $nb1 < count($rows)) { |
| 756 | 756 | spip_log( |
| 757 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 758 | - 'dump' . _LOG_INFO_IMPORTANTE |
|
| 757 | + 'base_inserer_copie : '.($nb - $nb1).' insertions au lieu de '.count($rows).'. On retente 1 par 1', |
|
| 758 | + 'dump'._LOG_INFO_IMPORTANTE |
|
| 759 | 759 | ); |
| 760 | 760 | foreach ($rows as $row) { |
| 761 | 761 | // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
@@ -766,8 +766,8 @@ discard block |
||
| 766 | 766 | $nb = sql_countsel($table, '', '', '', $serveur_dest); |
| 767 | 767 | if ($nb - $nb1 < count($rows)) { |
| 768 | 768 | spip_log( |
| 769 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 770 | - 'dump' . _LOG_ERREUR |
|
| 769 | + 'base_inserer_copie : '.($nb - $nb1).' insertions au lieu de '.count($rows).' apres insertion 1 par 1', |
|
| 770 | + 'dump'._LOG_ERREUR |
|
| 771 | 771 | ); |
| 772 | 772 | $r = false; |
| 773 | 773 | } |
@@ -16,17 +16,17 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_UPGRADE_TIME_OUT')) { |
| 23 | - /** |
|
| 24 | - * Durée en secondes pour relancer les scripts de mises à jour, x secondes |
|
| 25 | - * avant que la durée d'exécution du script provoque un timeout |
|
| 26 | - * |
|
| 27 | - * @var int |
|
| 28 | - **/ |
|
| 29 | - define('_UPGRADE_TIME_OUT', 20); |
|
| 23 | + /** |
|
| 24 | + * Durée en secondes pour relancer les scripts de mises à jour, x secondes |
|
| 25 | + * avant que la durée d'exécution du script provoque un timeout |
|
| 26 | + * |
|
| 27 | + * @var int |
|
| 28 | + **/ |
|
| 29 | + define('_UPGRADE_TIME_OUT', 20); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -49,40 +49,40 @@ discard block |
||
| 49 | 49 | * @return void |
| 50 | 50 | */ |
| 51 | 51 | function base_upgrade_dist($titre = '', $reprise = '') { |
| 52 | - if (!$titre) { |
|
| 53 | - return; |
|
| 54 | - } // anti-testeur automatique |
|
| 55 | - if ($GLOBALS['spip_version_base'] != $GLOBALS['meta']['version_installee']) { |
|
| 56 | - if (!is_numeric(_request('reinstall'))) { |
|
| 57 | - include_spip('base/create'); |
|
| 58 | - spip_log('recree les tables eventuellement disparues', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 59 | - creer_base(); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // quand on rentre par ici, c'est toujours une mise a jour de SPIP |
|
| 63 | - // lancement de l'upgrade SPIP |
|
| 64 | - $res = maj_base(); |
|
| 65 | - |
|
| 66 | - if ($res) { |
|
| 67 | - // on arrete tout ici ! |
|
| 68 | - exit; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - spip_log('Fin de mise a jour SQL. Debut m-a-j acces et config', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 72 | - |
|
| 73 | - // supprimer quelques fichiers temporaires qui peuvent se retrouver invalides |
|
| 74 | - @spip_unlink(_CACHE_RUBRIQUES); |
|
| 75 | - @spip_unlink(_CACHE_PIPELINES); |
|
| 76 | - @spip_unlink(_CACHE_PLUGINS_PATH); |
|
| 77 | - @spip_unlink(_CACHE_PLUGINS_OPT); |
|
| 78 | - @spip_unlink(_CACHE_PLUGINS_FCT); |
|
| 79 | - @spip_unlink(_CACHE_CHEMIN); |
|
| 80 | - @spip_unlink(_DIR_TMP . 'plugin_xml_cache.gz'); |
|
| 81 | - |
|
| 82 | - include_spip('inc/auth'); |
|
| 83 | - auth_synchroniser_distant(); |
|
| 84 | - $config = charger_fonction('config', 'inc'); |
|
| 85 | - $config(); |
|
| 52 | + if (!$titre) { |
|
| 53 | + return; |
|
| 54 | + } // anti-testeur automatique |
|
| 55 | + if ($GLOBALS['spip_version_base'] != $GLOBALS['meta']['version_installee']) { |
|
| 56 | + if (!is_numeric(_request('reinstall'))) { |
|
| 57 | + include_spip('base/create'); |
|
| 58 | + spip_log('recree les tables eventuellement disparues', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 59 | + creer_base(); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // quand on rentre par ici, c'est toujours une mise a jour de SPIP |
|
| 63 | + // lancement de l'upgrade SPIP |
|
| 64 | + $res = maj_base(); |
|
| 65 | + |
|
| 66 | + if ($res) { |
|
| 67 | + // on arrete tout ici ! |
|
| 68 | + exit; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + spip_log('Fin de mise a jour SQL. Debut m-a-j acces et config', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 72 | + |
|
| 73 | + // supprimer quelques fichiers temporaires qui peuvent se retrouver invalides |
|
| 74 | + @spip_unlink(_CACHE_RUBRIQUES); |
|
| 75 | + @spip_unlink(_CACHE_PIPELINES); |
|
| 76 | + @spip_unlink(_CACHE_PLUGINS_PATH); |
|
| 77 | + @spip_unlink(_CACHE_PLUGINS_OPT); |
|
| 78 | + @spip_unlink(_CACHE_PLUGINS_FCT); |
|
| 79 | + @spip_unlink(_CACHE_CHEMIN); |
|
| 80 | + @spip_unlink(_DIR_TMP . 'plugin_xml_cache.gz'); |
|
| 81 | + |
|
| 82 | + include_spip('inc/auth'); |
|
| 83 | + auth_synchroniser_distant(); |
|
| 84 | + $config = charger_fonction('config', 'inc'); |
|
| 85 | + $config(); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -113,51 +113,51 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | function maj_base($version_cible = 0, $redirect = '', $debut_page = true) { |
| 115 | 115 | |
| 116 | - $version_installee = $GLOBALS['meta']['version_installee'] ?? null; |
|
| 117 | - |
|
| 118 | - spip_log( |
|
| 119 | - "Version anterieure: $version_installee. Courante: " . $GLOBALS['spip_version_base'], |
|
| 120 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 121 | - ); |
|
| 122 | - if (!$version_installee || $GLOBALS['spip_version_base'] < $version_installee) { |
|
| 123 | - sql_replace( |
|
| 124 | - 'spip_meta', |
|
| 125 | - [ |
|
| 126 | - 'nom' => 'version_installee', |
|
| 127 | - 'valeur' => $GLOBALS['spip_version_base'], |
|
| 128 | - 'impt' => 'non' |
|
| 129 | - ] |
|
| 130 | - ); |
|
| 131 | - return false; |
|
| 132 | - } |
|
| 133 | - if (!upgrade_test()) { |
|
| 134 | - return true; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $cible = ($version_cible ?: $GLOBALS['spip_version_base']); |
|
| 138 | - |
|
| 139 | - if ($version_installee < 2021_01_01_00) { |
|
| 140 | - include_spip('maj/legacy/v21'); |
|
| 141 | - include_spip('maj/legacy/v30'); |
|
| 142 | - include_spip('maj/legacy/v31'); |
|
| 143 | - include_spip('maj/legacy/v32'); |
|
| 144 | - include_spip('maj/legacy/v40'); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - include_spip('maj/2021'); |
|
| 148 | - |
|
| 149 | - ksort($GLOBALS['maj']); |
|
| 150 | - $res = maj_while($version_installee, $cible, $GLOBALS['maj'], 'version_installee', 'meta', $redirect, $debut_page); |
|
| 151 | - if ($res) { |
|
| 152 | - if (!is_array($res)) { |
|
| 153 | - spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 154 | - } else { |
|
| 155 | - echo _T('avis_operation_echec') . ' ' . implode(' ', $res); |
|
| 156 | - echo install_fin_html(); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return $res; |
|
| 116 | + $version_installee = $GLOBALS['meta']['version_installee'] ?? null; |
|
| 117 | + |
|
| 118 | + spip_log( |
|
| 119 | + "Version anterieure: $version_installee. Courante: " . $GLOBALS['spip_version_base'], |
|
| 120 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 121 | + ); |
|
| 122 | + if (!$version_installee || $GLOBALS['spip_version_base'] < $version_installee) { |
|
| 123 | + sql_replace( |
|
| 124 | + 'spip_meta', |
|
| 125 | + [ |
|
| 126 | + 'nom' => 'version_installee', |
|
| 127 | + 'valeur' => $GLOBALS['spip_version_base'], |
|
| 128 | + 'impt' => 'non' |
|
| 129 | + ] |
|
| 130 | + ); |
|
| 131 | + return false; |
|
| 132 | + } |
|
| 133 | + if (!upgrade_test()) { |
|
| 134 | + return true; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $cible = ($version_cible ?: $GLOBALS['spip_version_base']); |
|
| 138 | + |
|
| 139 | + if ($version_installee < 2021_01_01_00) { |
|
| 140 | + include_spip('maj/legacy/v21'); |
|
| 141 | + include_spip('maj/legacy/v30'); |
|
| 142 | + include_spip('maj/legacy/v31'); |
|
| 143 | + include_spip('maj/legacy/v32'); |
|
| 144 | + include_spip('maj/legacy/v40'); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + include_spip('maj/2021'); |
|
| 148 | + |
|
| 149 | + ksort($GLOBALS['maj']); |
|
| 150 | + $res = maj_while($version_installee, $cible, $GLOBALS['maj'], 'version_installee', 'meta', $redirect, $debut_page); |
|
| 151 | + if ($res) { |
|
| 152 | + if (!is_array($res)) { |
|
| 153 | + spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 154 | + } else { |
|
| 155 | + echo _T('avis_operation_echec') . ' ' . implode(' ', $res); |
|
| 156 | + echo install_fin_html(); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return $res; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -199,53 +199,53 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | function maj_plugin($nom_meta_base_version, $version_cible, $maj, $table_meta = 'meta') { |
| 201 | 201 | |
| 202 | - if ($table_meta !== 'meta') { |
|
| 203 | - installer_table_meta($table_meta); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $current_version = null; |
|
| 207 | - |
|
| 208 | - if ( |
|
| 209 | - (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) |
|
| 210 | - || (!spip_version_compare($current_version = $GLOBALS[$table_meta][$nom_meta_base_version], $version_cible, '=')) |
|
| 211 | - ) { |
|
| 212 | - // $maj['create'] contient les directives propres a la premiere creation de base |
|
| 213 | - // c'est une operation derogatoire qui fait aboutir directement dans la version_cible |
|
| 214 | - if (isset($maj['create'])) { |
|
| 215 | - if (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) { |
|
| 216 | - // installation : on ne fait que l'operation create |
|
| 217 | - $maj = ['init' => $maj['create']]; |
|
| 218 | - // et on lui ajoute un appel a inc/config |
|
| 219 | - // pour creer les metas par defaut |
|
| 220 | - $config = charger_fonction('config', 'inc'); |
|
| 221 | - $maj[$version_cible] = [[$config]]; |
|
| 222 | - } |
|
| 223 | - // dans tous les cas enlever cet index du tableau |
|
| 224 | - unset($maj['create']); |
|
| 225 | - } |
|
| 226 | - // si init, deja dans le bon ordre |
|
| 227 | - if (!isset($maj['init'])) { |
|
| 228 | - include_spip('inc/plugin'); // pour spip_version_compare |
|
| 229 | - uksort($maj, 'spip_version_compare'); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // la redirection se fait par defaut sur la page d'administration des plugins |
|
| 233 | - // sauf lorsque nous sommes sur l'installation de SPIP |
|
| 234 | - // ou define _REDIRECT_MAJ_PLUGIN |
|
| 235 | - $redirect = (defined('_REDIRECT_MAJ_PLUGIN') ? _REDIRECT_MAJ_PLUGIN : generer_url_ecrire('admin_plugin')); |
|
| 236 | - if (defined('_ECRIRE_INSTALL')) { |
|
| 237 | - $redirect = parametre_url(generer_url_ecrire('install'), 'etape', _request('etape')); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - $res = maj_while($current_version, $version_cible, $maj, $nom_meta_base_version, $table_meta, $redirect); |
|
| 241 | - if ($res) { |
|
| 242 | - if (!is_array($res)) { |
|
| 243 | - spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 244 | - } else { |
|
| 245 | - echo '<p>' . _T('avis_operation_echec') . ' ' . implode(' ', $res) . '</p>'; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - } |
|
| 202 | + if ($table_meta !== 'meta') { |
|
| 203 | + installer_table_meta($table_meta); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $current_version = null; |
|
| 207 | + |
|
| 208 | + if ( |
|
| 209 | + (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) |
|
| 210 | + || (!spip_version_compare($current_version = $GLOBALS[$table_meta][$nom_meta_base_version], $version_cible, '=')) |
|
| 211 | + ) { |
|
| 212 | + // $maj['create'] contient les directives propres a la premiere creation de base |
|
| 213 | + // c'est une operation derogatoire qui fait aboutir directement dans la version_cible |
|
| 214 | + if (isset($maj['create'])) { |
|
| 215 | + if (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) { |
|
| 216 | + // installation : on ne fait que l'operation create |
|
| 217 | + $maj = ['init' => $maj['create']]; |
|
| 218 | + // et on lui ajoute un appel a inc/config |
|
| 219 | + // pour creer les metas par defaut |
|
| 220 | + $config = charger_fonction('config', 'inc'); |
|
| 221 | + $maj[$version_cible] = [[$config]]; |
|
| 222 | + } |
|
| 223 | + // dans tous les cas enlever cet index du tableau |
|
| 224 | + unset($maj['create']); |
|
| 225 | + } |
|
| 226 | + // si init, deja dans le bon ordre |
|
| 227 | + if (!isset($maj['init'])) { |
|
| 228 | + include_spip('inc/plugin'); // pour spip_version_compare |
|
| 229 | + uksort($maj, 'spip_version_compare'); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // la redirection se fait par defaut sur la page d'administration des plugins |
|
| 233 | + // sauf lorsque nous sommes sur l'installation de SPIP |
|
| 234 | + // ou define _REDIRECT_MAJ_PLUGIN |
|
| 235 | + $redirect = (defined('_REDIRECT_MAJ_PLUGIN') ? _REDIRECT_MAJ_PLUGIN : generer_url_ecrire('admin_plugin')); |
|
| 236 | + if (defined('_ECRIRE_INSTALL')) { |
|
| 237 | + $redirect = parametre_url(generer_url_ecrire('install'), 'etape', _request('etape')); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + $res = maj_while($current_version, $version_cible, $maj, $nom_meta_base_version, $table_meta, $redirect); |
|
| 241 | + if ($res) { |
|
| 242 | + if (!is_array($res)) { |
|
| 243 | + spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 244 | + } else { |
|
| 245 | + echo '<p>' . _T('avis_operation_echec') . ' ' . implode(' ', $res) . '</p>'; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -262,17 +262,17 @@ discard block |
||
| 262 | 262 | * @return void |
| 263 | 263 | */ |
| 264 | 264 | function relance_maj($meta, $table, $redirect = '') { |
| 265 | - include_spip('inc/headers'); |
|
| 266 | - if (!$redirect) { |
|
| 267 | - // recuperer la valeur installee en cours |
|
| 268 | - // on la tronque numeriquement, elle ne sert pas reellement |
|
| 269 | - // sauf pour verifier que ce n'est pas oui ou non |
|
| 270 | - // sinon is_numeric va echouer sur un numero de version 1.2.3 |
|
| 271 | - $installee = (int) $GLOBALS[$table][$meta]; |
|
| 272 | - $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 273 | - } |
|
| 274 | - echo redirige_formulaire($redirect); |
|
| 275 | - exit(); |
|
| 265 | + include_spip('inc/headers'); |
|
| 266 | + if (!$redirect) { |
|
| 267 | + // recuperer la valeur installee en cours |
|
| 268 | + // on la tronque numeriquement, elle ne sert pas reellement |
|
| 269 | + // sauf pour verifier que ce n'est pas oui ou non |
|
| 270 | + // sinon is_numeric va echouer sur un numero de version 1.2.3 |
|
| 271 | + $installee = (int) $GLOBALS[$table][$meta]; |
|
| 272 | + $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 273 | + } |
|
| 274 | + echo redirige_formulaire($redirect); |
|
| 275 | + exit(); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -285,29 +285,29 @@ discard block |
||
| 285 | 285 | * @return void |
| 286 | 286 | */ |
| 287 | 287 | function maj_debut_page($installee, $meta, $table) { |
| 288 | - static $done = false; |
|
| 289 | - if ($done) { |
|
| 290 | - return; |
|
| 291 | - } |
|
| 292 | - include_spip('inc/minipres'); |
|
| 293 | - include_spip('inc/filtres'); |
|
| 294 | - if (function_exists('ini_set')) { |
|
| 295 | - @ini_set('zlib.output_compression', '0'); // pour permettre l'affichage au fur et a mesure |
|
| 296 | - } |
|
| 297 | - $timeout = _UPGRADE_TIME_OUT * 2; |
|
| 298 | - $titre = _T('titre_page_upgrade'); |
|
| 299 | - $balise_img = charger_filtre('balise_img'); |
|
| 300 | - $titre .= $balise_img(chemin_image('loader.svg'), '', 'loader'); |
|
| 301 | - echo(install_debut_html($titre)); |
|
| 302 | - // script de rechargement auto sur timeout |
|
| 303 | - $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 304 | - echo http_script("window.setTimeout('location.href=\"" . $redirect . "\";'," . ($timeout * 1000) . ')'); |
|
| 305 | - echo "<div style='text-align: left'>\n"; |
|
| 306 | - if (ob_get_level()) { |
|
| 307 | - ob_flush(); |
|
| 308 | - } |
|
| 309 | - flush(); |
|
| 310 | - $done = true; |
|
| 288 | + static $done = false; |
|
| 289 | + if ($done) { |
|
| 290 | + return; |
|
| 291 | + } |
|
| 292 | + include_spip('inc/minipres'); |
|
| 293 | + include_spip('inc/filtres'); |
|
| 294 | + if (function_exists('ini_set')) { |
|
| 295 | + @ini_set('zlib.output_compression', '0'); // pour permettre l'affichage au fur et a mesure |
|
| 296 | + } |
|
| 297 | + $timeout = _UPGRADE_TIME_OUT * 2; |
|
| 298 | + $titre = _T('titre_page_upgrade'); |
|
| 299 | + $balise_img = charger_filtre('balise_img'); |
|
| 300 | + $titre .= $balise_img(chemin_image('loader.svg'), '', 'loader'); |
|
| 301 | + echo(install_debut_html($titre)); |
|
| 302 | + // script de rechargement auto sur timeout |
|
| 303 | + $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 304 | + echo http_script("window.setTimeout('location.href=\"" . $redirect . "\";'," . ($timeout * 1000) . ')'); |
|
| 305 | + echo "<div style='text-align: left'>\n"; |
|
| 306 | + if (ob_get_level()) { |
|
| 307 | + ob_flush(); |
|
| 308 | + } |
|
| 309 | + flush(); |
|
| 310 | + $done = true; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -351,63 +351,63 @@ discard block |
||
| 351 | 351 | * - tableau vide sinon. |
| 352 | 352 | */ |
| 353 | 353 | function maj_while($installee, $cible, $maj, $meta = '', $table = 'meta', $redirect = '', $debut_page = false) { |
| 354 | - # inclusions pour que les procedures d'upgrade disposent des fonctions de base |
|
| 355 | - include_spip('base/create'); |
|
| 356 | - include_spip('base/abstract_sql'); |
|
| 357 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 358 | - include_spip('inc/plugin'); // pour spip_version_compare |
|
| 359 | - $n = 0; |
|
| 360 | - $time = time(); |
|
| 361 | - |
|
| 362 | - if (!defined('_TIME_OUT')) { |
|
| 363 | - /** |
|
| 364 | - * Définir le timeout qui peut-être utilisé dans les fonctions |
|
| 365 | - * de mises à jour qui durent trop longtemps |
|
| 366 | - * |
|
| 367 | - * À utiliser tel que : `if (time() >= _TIME_OUT)` |
|
| 368 | - * |
|
| 369 | - * @var int |
|
| 370 | - */ |
|
| 371 | - define('_TIME_OUT', $time + _UPGRADE_TIME_OUT); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - foreach ($maj as $v => $operations) { |
|
| 375 | - // si une maj pour cette version |
|
| 376 | - if ( |
|
| 377 | - $v == 'init' |
|
| 378 | - || spip_version_compare($v, $installee, '>') && spip_version_compare($v, $cible, '<=') |
|
| 379 | - ) { |
|
| 380 | - if ($debut_page) { |
|
| 381 | - maj_debut_page($v, $meta, $table); |
|
| 382 | - } |
|
| 383 | - echo "MAJ $v"; |
|
| 384 | - $etape = serie_alter($v, $operations, $meta, $table, $redirect); |
|
| 385 | - $trouver_table(''); // vider le cache des descriptions de table |
|
| 386 | - # echec sur une etape en cours ? |
|
| 387 | - # on sort |
|
| 388 | - if ($etape) { |
|
| 389 | - return [$v, $etape]; |
|
| 390 | - } |
|
| 391 | - $n = time() - $time; |
|
| 392 | - spip_log("$table $meta: $v en $n secondes", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 393 | - if ($meta) { |
|
| 394 | - ecrire_meta($meta, $installee = $v, 'oui', $table); |
|
| 395 | - } |
|
| 396 | - echo (_IS_CLI ? "\n" : '<br />'); |
|
| 397 | - } |
|
| 398 | - if (time() >= _TIME_OUT) { |
|
| 399 | - relance_maj($meta, $table, $redirect); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - $trouver_table(''); // vider le cache des descriptions de table |
|
| 403 | - // indispensable pour les chgt de versions qui n'ecrivent pas en base |
|
| 404 | - // tant pis pour la redondance eventuelle avec ci-dessus |
|
| 405 | - if ($meta) { |
|
| 406 | - ecrire_meta($meta, $cible, 'oui', $table); |
|
| 407 | - } |
|
| 408 | - spip_log("MAJ terminee. $meta: $installee", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 409 | - |
|
| 410 | - return []; |
|
| 354 | + # inclusions pour que les procedures d'upgrade disposent des fonctions de base |
|
| 355 | + include_spip('base/create'); |
|
| 356 | + include_spip('base/abstract_sql'); |
|
| 357 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 358 | + include_spip('inc/plugin'); // pour spip_version_compare |
|
| 359 | + $n = 0; |
|
| 360 | + $time = time(); |
|
| 361 | + |
|
| 362 | + if (!defined('_TIME_OUT')) { |
|
| 363 | + /** |
|
| 364 | + * Définir le timeout qui peut-être utilisé dans les fonctions |
|
| 365 | + * de mises à jour qui durent trop longtemps |
|
| 366 | + * |
|
| 367 | + * À utiliser tel que : `if (time() >= _TIME_OUT)` |
|
| 368 | + * |
|
| 369 | + * @var int |
|
| 370 | + */ |
|
| 371 | + define('_TIME_OUT', $time + _UPGRADE_TIME_OUT); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + foreach ($maj as $v => $operations) { |
|
| 375 | + // si une maj pour cette version |
|
| 376 | + if ( |
|
| 377 | + $v == 'init' |
|
| 378 | + || spip_version_compare($v, $installee, '>') && spip_version_compare($v, $cible, '<=') |
|
| 379 | + ) { |
|
| 380 | + if ($debut_page) { |
|
| 381 | + maj_debut_page($v, $meta, $table); |
|
| 382 | + } |
|
| 383 | + echo "MAJ $v"; |
|
| 384 | + $etape = serie_alter($v, $operations, $meta, $table, $redirect); |
|
| 385 | + $trouver_table(''); // vider le cache des descriptions de table |
|
| 386 | + # echec sur une etape en cours ? |
|
| 387 | + # on sort |
|
| 388 | + if ($etape) { |
|
| 389 | + return [$v, $etape]; |
|
| 390 | + } |
|
| 391 | + $n = time() - $time; |
|
| 392 | + spip_log("$table $meta: $v en $n secondes", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 393 | + if ($meta) { |
|
| 394 | + ecrire_meta($meta, $installee = $v, 'oui', $table); |
|
| 395 | + } |
|
| 396 | + echo (_IS_CLI ? "\n" : '<br />'); |
|
| 397 | + } |
|
| 398 | + if (time() >= _TIME_OUT) { |
|
| 399 | + relance_maj($meta, $table, $redirect); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + $trouver_table(''); // vider le cache des descriptions de table |
|
| 403 | + // indispensable pour les chgt de versions qui n'ecrivent pas en base |
|
| 404 | + // tant pis pour la redondance eventuelle avec ci-dessus |
|
| 405 | + if ($meta) { |
|
| 406 | + ecrire_meta($meta, $cible, 'oui', $table); |
|
| 407 | + } |
|
| 408 | + spip_log("MAJ terminee. $meta: $installee", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 409 | + |
|
| 410 | + return []; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -430,53 +430,53 @@ discard block |
||
| 430 | 430 | * @return int |
| 431 | 431 | */ |
| 432 | 432 | function serie_alter($serie, $q = [], $meta = '', $table = 'meta', $redirect = '') { |
| 433 | - $meta2 = $meta . '_maj_' . $serie; |
|
| 434 | - $etape = 0; |
|
| 435 | - if (isset($GLOBALS[$table][$meta2])) { |
|
| 436 | - $etape = (int) $GLOBALS[$table][$meta2]; |
|
| 437 | - } |
|
| 438 | - foreach ($q as $i => $r) { |
|
| 439 | - if ($i >= $etape) { |
|
| 440 | - $msg = "maj $table $meta2 etape $i"; |
|
| 441 | - if ( |
|
| 442 | - is_array($r) |
|
| 443 | - && function_exists($f = array_shift($r)) |
|
| 444 | - ) { |
|
| 445 | - // note: $r (arguments de la fonction $f) peut avoir des données tabulaires |
|
| 446 | - spip_log("$msg: $f " . @implode(',', $r), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 447 | - // pour les fonctions atomiques sql_xx |
|
| 448 | - // on enregistre le meta avant de lancer la fonction, |
|
| 449 | - // de maniere a eviter de boucler sur timeout |
|
| 450 | - // mais pour les fonctions complexes, |
|
| 451 | - // il faut les rejouer jusqu'a achevement. |
|
| 452 | - // C'est a elle d'assurer qu'elles progressent a chaque rappel |
|
| 453 | - if (str_starts_with($f, 'sql_')) { |
|
| 454 | - ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 455 | - } |
|
| 456 | - echo (_IS_CLI ? '.' : " <span title='$i'>.</span>"); |
|
| 457 | - $f(...$r); |
|
| 458 | - // si temps imparti depasse, on relance sans ecrire en meta |
|
| 459 | - // car on est peut etre sorti sur timeout si c'est une fonction longue |
|
| 460 | - if (time() >= _TIME_OUT) { |
|
| 461 | - relance_maj($meta, $table, $redirect); |
|
| 462 | - } |
|
| 463 | - ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 464 | - spip_log("$meta2: ok", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 465 | - } else { |
|
| 466 | - if (!is_array($r)) { |
|
| 467 | - spip_log("maj $i format incorrect", 'maj.' . _LOG_ERREUR); |
|
| 468 | - } else { |
|
| 469 | - spip_log("maj $i fonction $f non definie", 'maj.' . _LOG_ERREUR); |
|
| 470 | - } |
|
| 471 | - // en cas d'erreur serieuse, on s'arrete |
|
| 472 | - // mais on permet de passer par dessus en rechargeant la page. |
|
| 473 | - return $i + 1; |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - effacer_meta($meta2, $table); |
|
| 478 | - |
|
| 479 | - return 0; |
|
| 433 | + $meta2 = $meta . '_maj_' . $serie; |
|
| 434 | + $etape = 0; |
|
| 435 | + if (isset($GLOBALS[$table][$meta2])) { |
|
| 436 | + $etape = (int) $GLOBALS[$table][$meta2]; |
|
| 437 | + } |
|
| 438 | + foreach ($q as $i => $r) { |
|
| 439 | + if ($i >= $etape) { |
|
| 440 | + $msg = "maj $table $meta2 etape $i"; |
|
| 441 | + if ( |
|
| 442 | + is_array($r) |
|
| 443 | + && function_exists($f = array_shift($r)) |
|
| 444 | + ) { |
|
| 445 | + // note: $r (arguments de la fonction $f) peut avoir des données tabulaires |
|
| 446 | + spip_log("$msg: $f " . @implode(',', $r), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 447 | + // pour les fonctions atomiques sql_xx |
|
| 448 | + // on enregistre le meta avant de lancer la fonction, |
|
| 449 | + // de maniere a eviter de boucler sur timeout |
|
| 450 | + // mais pour les fonctions complexes, |
|
| 451 | + // il faut les rejouer jusqu'a achevement. |
|
| 452 | + // C'est a elle d'assurer qu'elles progressent a chaque rappel |
|
| 453 | + if (str_starts_with($f, 'sql_')) { |
|
| 454 | + ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 455 | + } |
|
| 456 | + echo (_IS_CLI ? '.' : " <span title='$i'>.</span>"); |
|
| 457 | + $f(...$r); |
|
| 458 | + // si temps imparti depasse, on relance sans ecrire en meta |
|
| 459 | + // car on est peut etre sorti sur timeout si c'est une fonction longue |
|
| 460 | + if (time() >= _TIME_OUT) { |
|
| 461 | + relance_maj($meta, $table, $redirect); |
|
| 462 | + } |
|
| 463 | + ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 464 | + spip_log("$meta2: ok", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 465 | + } else { |
|
| 466 | + if (!is_array($r)) { |
|
| 467 | + spip_log("maj $i format incorrect", 'maj.' . _LOG_ERREUR); |
|
| 468 | + } else { |
|
| 469 | + spip_log("maj $i fonction $f non definie", 'maj.' . _LOG_ERREUR); |
|
| 470 | + } |
|
| 471 | + // en cas d'erreur serieuse, on s'arrete |
|
| 472 | + // mais on permet de passer par dessus en rechargeant la page. |
|
| 473 | + return $i + 1; |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + effacer_meta($meta2, $table); |
|
| 478 | + |
|
| 479 | + return 0; |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | /** |
@@ -485,16 +485,16 @@ discard block |
||
| 485 | 485 | * @return bool True si possible. |
| 486 | 486 | **/ |
| 487 | 487 | function upgrade_test() { |
| 488 | - sql_drop_table('spip_test', true); |
|
| 489 | - sql_create('spip_test', ['a' => 'int']); |
|
| 490 | - sql_alter('TABLE spip_test ADD b INT'); |
|
| 491 | - sql_insertq('spip_test', ['b' => 1], ['field' => ['b' => 'int']]); |
|
| 492 | - $result = sql_select('b', 'spip_test'); |
|
| 493 | - // ne pas garder le resultat de la requete sinon sqlite3 |
|
| 494 | - // ne peut pas supprimer la table spip_test lors du sql_alter qui suit |
|
| 495 | - // car cette table serait alors 'verouillee' |
|
| 496 | - $result = (bool) $result; |
|
| 497 | - sql_alter('TABLE spip_test DROP b'); |
|
| 498 | - |
|
| 499 | - return $result; |
|
| 488 | + sql_drop_table('spip_test', true); |
|
| 489 | + sql_create('spip_test', ['a' => 'int']); |
|
| 490 | + sql_alter('TABLE spip_test ADD b INT'); |
|
| 491 | + sql_insertq('spip_test', ['b' => 1], ['field' => ['b' => 'int']]); |
|
| 492 | + $result = sql_select('b', 'spip_test'); |
|
| 493 | + // ne pas garder le resultat de la requete sinon sqlite3 |
|
| 494 | + // ne peut pas supprimer la table spip_test lors du sql_alter qui suit |
|
| 495 | + // car cette table serait alors 'verouillee' |
|
| 496 | + $result = (bool) $result; |
|
| 497 | + sql_alter('TABLE spip_test DROP b'); |
|
| 498 | + |
|
| 499 | + return $result; |
|
| 500 | 500 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | if ($GLOBALS['spip_version_base'] != $GLOBALS['meta']['version_installee']) { |
| 56 | 56 | if (!is_numeric(_request('reinstall'))) { |
| 57 | 57 | include_spip('base/create'); |
| 58 | - spip_log('recree les tables eventuellement disparues', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 58 | + spip_log('recree les tables eventuellement disparues', 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 59 | 59 | creer_base(); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | exit; |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | - spip_log('Fin de mise a jour SQL. Debut m-a-j acces et config', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 71 | + spip_log('Fin de mise a jour SQL. Debut m-a-j acces et config', 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 72 | 72 | |
| 73 | 73 | // supprimer quelques fichiers temporaires qui peuvent se retrouver invalides |
| 74 | 74 | @spip_unlink(_CACHE_RUBRIQUES); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | @spip_unlink(_CACHE_PLUGINS_OPT); |
| 78 | 78 | @spip_unlink(_CACHE_PLUGINS_FCT); |
| 79 | 79 | @spip_unlink(_CACHE_CHEMIN); |
| 80 | - @spip_unlink(_DIR_TMP . 'plugin_xml_cache.gz'); |
|
| 80 | + @spip_unlink(_DIR_TMP.'plugin_xml_cache.gz'); |
|
| 81 | 81 | |
| 82 | 82 | include_spip('inc/auth'); |
| 83 | 83 | auth_synchroniser_distant(); |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | $version_installee = $GLOBALS['meta']['version_installee'] ?? null; |
| 117 | 117 | |
| 118 | 118 | spip_log( |
| 119 | - "Version anterieure: $version_installee. Courante: " . $GLOBALS['spip_version_base'], |
|
| 120 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 119 | + "Version anterieure: $version_installee. Courante: ".$GLOBALS['spip_version_base'], |
|
| 120 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 121 | 121 | ); |
| 122 | 122 | if (!$version_installee || $GLOBALS['spip_version_base'] < $version_installee) { |
| 123 | 123 | sql_replace( |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | $res = maj_while($version_installee, $cible, $GLOBALS['maj'], 'version_installee', 'meta', $redirect, $debut_page); |
| 151 | 151 | if ($res) { |
| 152 | 152 | if (!is_array($res)) { |
| 153 | - spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 153 | + spip_log("Pb d'acces SQL a la mise a jour", 'maj.'._LOG_ERREUR); |
|
| 154 | 154 | } else { |
| 155 | - echo _T('avis_operation_echec') . ' ' . implode(' ', $res); |
|
| 155 | + echo _T('avis_operation_echec').' '.implode(' ', $res); |
|
| 156 | 156 | echo install_fin_html(); |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | $res = maj_while($current_version, $version_cible, $maj, $nom_meta_base_version, $table_meta, $redirect); |
| 241 | 241 | if ($res) { |
| 242 | 242 | if (!is_array($res)) { |
| 243 | - spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 243 | + spip_log("Pb d'acces SQL a la mise a jour", 'maj.'._LOG_ERREUR); |
|
| 244 | 244 | } else { |
| 245 | - echo '<p>' . _T('avis_operation_echec') . ' ' . implode(' ', $res) . '</p>'; |
|
| 245 | + echo '<p>'._T('avis_operation_echec').' '.implode(' ', $res).'</p>'; |
|
| 246 | 246 | } |
| 247 | 247 | } |
| 248 | 248 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | echo(install_debut_html($titre)); |
| 302 | 302 | // script de rechargement auto sur timeout |
| 303 | 303 | $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
| 304 | - echo http_script("window.setTimeout('location.href=\"" . $redirect . "\";'," . ($timeout * 1000) . ')'); |
|
| 304 | + echo http_script("window.setTimeout('location.href=\"".$redirect."\";',".($timeout * 1000).')'); |
|
| 305 | 305 | echo "<div style='text-align: left'>\n"; |
| 306 | 306 | if (ob_get_level()) { |
| 307 | 307 | ob_flush(); |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | return [$v, $etape]; |
| 390 | 390 | } |
| 391 | 391 | $n = time() - $time; |
| 392 | - spip_log("$table $meta: $v en $n secondes", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 392 | + spip_log("$table $meta: $v en $n secondes", 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 393 | 393 | if ($meta) { |
| 394 | 394 | ecrire_meta($meta, $installee = $v, 'oui', $table); |
| 395 | 395 | } |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | if ($meta) { |
| 406 | 406 | ecrire_meta($meta, $cible, 'oui', $table); |
| 407 | 407 | } |
| 408 | - spip_log("MAJ terminee. $meta: $installee", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 408 | + spip_log("MAJ terminee. $meta: $installee", 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 409 | 409 | |
| 410 | 410 | return []; |
| 411 | 411 | } |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | * @return int |
| 431 | 431 | */ |
| 432 | 432 | function serie_alter($serie, $q = [], $meta = '', $table = 'meta', $redirect = '') { |
| 433 | - $meta2 = $meta . '_maj_' . $serie; |
|
| 433 | + $meta2 = $meta.'_maj_'.$serie; |
|
| 434 | 434 | $etape = 0; |
| 435 | 435 | if (isset($GLOBALS[$table][$meta2])) { |
| 436 | 436 | $etape = (int) $GLOBALS[$table][$meta2]; |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | && function_exists($f = array_shift($r)) |
| 444 | 444 | ) { |
| 445 | 445 | // note: $r (arguments de la fonction $f) peut avoir des données tabulaires |
| 446 | - spip_log("$msg: $f " . @implode(',', $r), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 446 | + spip_log("$msg: $f ".@implode(',', $r), 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 447 | 447 | // pour les fonctions atomiques sql_xx |
| 448 | 448 | // on enregistre le meta avant de lancer la fonction, |
| 449 | 449 | // de maniere a eviter de boucler sur timeout |
@@ -461,12 +461,12 @@ discard block |
||
| 461 | 461 | relance_maj($meta, $table, $redirect); |
| 462 | 462 | } |
| 463 | 463 | ecrire_meta($meta2, $i + 1, 'non', $table); |
| 464 | - spip_log("$meta2: ok", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 464 | + spip_log("$meta2: ok", 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 465 | 465 | } else { |
| 466 | 466 | if (!is_array($r)) { |
| 467 | - spip_log("maj $i format incorrect", 'maj.' . _LOG_ERREUR); |
|
| 467 | + spip_log("maj $i format incorrect", 'maj.'._LOG_ERREUR); |
|
| 468 | 468 | } else { |
| 469 | - spip_log("maj $i fonction $f non definie", 'maj.' . _LOG_ERREUR); |
|
| 469 | + spip_log("maj $i fonction $f non definie", 'maj.'._LOG_ERREUR); |
|
| 470 | 470 | } |
| 471 | 471 | // en cas d'erreur serieuse, on s'arrete |
| 472 | 472 | // mais on permet de passer par dessus en rechargeant la page. |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Installation |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/acces'); |
@@ -32,18 +32,18 @@ discard block |
||
| 32 | 32 | * @return bool |
| 33 | 33 | */ |
| 34 | 34 | function base_determine_autoinc($table, $desc = []) { |
| 35 | - if (($t = lister_tables_principales()) && isset($t[$table])) { |
|
| 36 | - $autoinc = true; |
|
| 37 | - } elseif (($t = lister_tables_auxiliaires()) && isset($t[$table])) { |
|
| 38 | - $autoinc = false; |
|
| 39 | - } else { |
|
| 40 | - // essayer de faire au mieux ! |
|
| 41 | - $autoinc = (isset($desc['key']['PRIMARY KEY']) |
|
| 42 | - && !str_contains((string) $desc['key']['PRIMARY KEY'], ',') |
|
| 43 | - && !str_contains((string) $desc['field'][$desc['key']['PRIMARY KEY']], 'default')); |
|
| 44 | - } |
|
| 35 | + if (($t = lister_tables_principales()) && isset($t[$table])) { |
|
| 36 | + $autoinc = true; |
|
| 37 | + } elseif (($t = lister_tables_auxiliaires()) && isset($t[$table])) { |
|
| 38 | + $autoinc = false; |
|
| 39 | + } else { |
|
| 40 | + // essayer de faire au mieux ! |
|
| 41 | + $autoinc = (isset($desc['key']['PRIMARY KEY']) |
|
| 42 | + && !str_contains((string) $desc['key']['PRIMARY KEY'], ',') |
|
| 43 | + && !str_contains((string) $desc['field'][$desc['key']['PRIMARY KEY']], 'default')); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - return $autoinc; |
|
| 46 | + return $autoinc; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -60,58 +60,58 @@ discard block |
||
| 60 | 60 | * @return void |
| 61 | 61 | */ |
| 62 | 62 | function creer_ou_upgrader_table($table, $desc, $autoinc, $upgrade = false, $serveur = '') { |
| 63 | - #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 64 | - $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 65 | - #if (!$sql_desc) $sql_desc = false; |
|
| 66 | - #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 67 | - if (!$sql_desc) { |
|
| 68 | - if ($autoinc === 'auto') { |
|
| 69 | - $autoinc = base_determine_autoinc($table, $desc); |
|
| 70 | - } |
|
| 71 | - #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 72 | - if (isset($desc['field']) && isset($desc['key'])) { |
|
| 73 | - sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 74 | - } |
|
| 75 | - // verifier la bonne installation de la table (php-fpm es-tu la ?) |
|
| 76 | - $sql_desc = sql_showtable($table, true, $serveur); |
|
| 77 | - #if (!$sql_desc) $sql_desc = false; |
|
| 78 | - #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 79 | - if (!$sql_desc) { |
|
| 80 | - // on retente avec un sleep ? |
|
| 81 | - sleep(1); |
|
| 82 | - sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 83 | - $sql_desc = sql_showtable($table, true, $serveur); |
|
| 84 | - #if (!$sql_desc) $sql_desc = false; |
|
| 85 | - #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 86 | - if (!$sql_desc) { |
|
| 87 | - spip_log("Echec creation table $table", 'maj' . _LOG_CRITIQUE); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } else { |
|
| 91 | - #spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 92 | - // ajouter les champs manquants |
|
| 93 | - // on ne supprime jamais les champs, car c'est dangereux |
|
| 94 | - // c'est toujours a faire manuellement |
|
| 95 | - $last = ''; |
|
| 96 | - if (isset($desc['field'])) { |
|
| 97 | - foreach ($desc['field'] as $field => $type) { |
|
| 98 | - if (!isset($sql_desc['field'][$field])) { |
|
| 99 | - sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ''), $serveur); |
|
| 100 | - } |
|
| 101 | - $last = $field; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - if (isset($desc['key'])) { |
|
| 105 | - foreach ($desc['key'] as $key => $type) { |
|
| 106 | - // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
|
| 107 | - // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
|
| 108 | - if (!isset($sql_desc['key'][$key]) && !isset($sql_desc['key']["$key $type"])) { |
|
| 109 | - sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 110 | - } |
|
| 111 | - $last = $field; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 63 | + #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 64 | + $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 65 | + #if (!$sql_desc) $sql_desc = false; |
|
| 66 | + #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 67 | + if (!$sql_desc) { |
|
| 68 | + if ($autoinc === 'auto') { |
|
| 69 | + $autoinc = base_determine_autoinc($table, $desc); |
|
| 70 | + } |
|
| 71 | + #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 72 | + if (isset($desc['field']) && isset($desc['key'])) { |
|
| 73 | + sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 74 | + } |
|
| 75 | + // verifier la bonne installation de la table (php-fpm es-tu la ?) |
|
| 76 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 77 | + #if (!$sql_desc) $sql_desc = false; |
|
| 78 | + #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 79 | + if (!$sql_desc) { |
|
| 80 | + // on retente avec un sleep ? |
|
| 81 | + sleep(1); |
|
| 82 | + sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 83 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 84 | + #if (!$sql_desc) $sql_desc = false; |
|
| 85 | + #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 86 | + if (!$sql_desc) { |
|
| 87 | + spip_log("Echec creation table $table", 'maj' . _LOG_CRITIQUE); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } else { |
|
| 91 | + #spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 92 | + // ajouter les champs manquants |
|
| 93 | + // on ne supprime jamais les champs, car c'est dangereux |
|
| 94 | + // c'est toujours a faire manuellement |
|
| 95 | + $last = ''; |
|
| 96 | + if (isset($desc['field'])) { |
|
| 97 | + foreach ($desc['field'] as $field => $type) { |
|
| 98 | + if (!isset($sql_desc['field'][$field])) { |
|
| 99 | + sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ''), $serveur); |
|
| 100 | + } |
|
| 101 | + $last = $field; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + if (isset($desc['key'])) { |
|
| 105 | + foreach ($desc['key'] as $key => $type) { |
|
| 106 | + // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
|
| 107 | + // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
|
| 108 | + if (!isset($sql_desc['key'][$key]) && !isset($sql_desc['key']["$key $type"])) { |
|
| 109 | + sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 110 | + } |
|
| 111 | + $last = $field; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -133,26 +133,26 @@ discard block |
||
| 133 | 133 | * @return void |
| 134 | 134 | */ |
| 135 | 135 | function alterer_base($tables_inc, $tables_noinc, $up = false, $serveur = '') { |
| 136 | - if ($up === false) { |
|
| 137 | - $old = false; |
|
| 138 | - $up = []; |
|
| 139 | - } else { |
|
| 140 | - $old = true; |
|
| 141 | - if (!is_array($up)) { |
|
| 142 | - $up = [$up]; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - foreach ($tables_inc as $k => $v) { |
|
| 146 | - if (!$old || in_array($k, $up)) { |
|
| 147 | - creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 148 | - } |
|
| 149 | - } |
|
| 136 | + if ($up === false) { |
|
| 137 | + $old = false; |
|
| 138 | + $up = []; |
|
| 139 | + } else { |
|
| 140 | + $old = true; |
|
| 141 | + if (!is_array($up)) { |
|
| 142 | + $up = [$up]; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + foreach ($tables_inc as $k => $v) { |
|
| 146 | + if (!$old || in_array($k, $up)) { |
|
| 147 | + creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - foreach ($tables_noinc as $k => $v) { |
|
| 152 | - if (!$old || in_array($k, $up)) { |
|
| 153 | - creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 154 | - } |
|
| 155 | - } |
|
| 151 | + foreach ($tables_noinc as $k => $v) { |
|
| 152 | + if (!$old || in_array($k, $up)) { |
|
| 153 | + creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -172,16 +172,16 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | function creer_base($serveur = '') { |
| 174 | 174 | |
| 175 | - // Note: les mises a jour reexecutent ce code pour s'assurer |
|
| 176 | - // de la conformite de la base |
|
| 177 | - // pas de panique sur "already exists" et "duplicate entry" donc. |
|
| 175 | + // Note: les mises a jour reexecutent ce code pour s'assurer |
|
| 176 | + // de la conformite de la base |
|
| 177 | + // pas de panique sur "already exists" et "duplicate entry" donc. |
|
| 178 | 178 | |
| 179 | - alterer_base( |
|
| 180 | - lister_tables_principales(), |
|
| 181 | - lister_tables_auxiliaires(), |
|
| 182 | - false, |
|
| 183 | - $serveur |
|
| 184 | - ); |
|
| 179 | + alterer_base( |
|
| 180 | + lister_tables_principales(), |
|
| 181 | + lister_tables_auxiliaires(), |
|
| 182 | + false, |
|
| 183 | + $serveur |
|
| 184 | + ); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -201,10 +201,10 @@ discard block |
||
| 201 | 201 | * @return void |
| 202 | 202 | */ |
| 203 | 203 | function maj_tables($upgrade_tables = [], $serveur = '') { |
| 204 | - alterer_base( |
|
| 205 | - lister_tables_principales(), |
|
| 206 | - lister_tables_auxiliaires(), |
|
| 207 | - $upgrade_tables, |
|
| 208 | - $serveur |
|
| 209 | - ); |
|
| 204 | + alterer_base( |
|
| 205 | + lister_tables_principales(), |
|
| 206 | + lister_tables_auxiliaires(), |
|
| 207 | + $upgrade_tables, |
|
| 208 | + $serveur |
|
| 209 | + ); |
|
| 210 | 210 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\SQL\Tables |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | include_spip('base/objets'); |
| 21 | 21 | |
@@ -67,150 +67,150 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | **/ |
| 69 | 69 | function base_trouver_table_dist($nom, $serveur = '', $table_spip = true, array $options = []) { |
| 70 | - $desc_cache = null; |
|
| 71 | - static $nom_cache_desc_sql = []; |
|
| 72 | - |
|
| 73 | - if ( |
|
| 74 | - !spip_connect($serveur) |
|
| 75 | - || !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 76 | - ) { |
|
| 77 | - return null; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $options += [ |
|
| 81 | - // si false, baissera le niveau de log si une table demandée n’existe pas |
|
| 82 | - 'log_missing' => true, |
|
| 83 | - ]; |
|
| 84 | - |
|
| 85 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 86 | - $objets_sql = lister_tables_objets_sql('::md5'); |
|
| 87 | - |
|
| 88 | - // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 89 | - // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 90 | - // de connexion, et tout risque d'ambiguite |
|
| 91 | - if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 92 | - $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 93 | - _DIR_CACHE . 'sql_desc_' |
|
| 94 | - . ($serveur ? "{$serveur}_" : '') |
|
| 95 | - . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 96 | - . '.txt'; |
|
| 97 | - // nouveau nom de cache = nouvelle version en memoire |
|
| 98 | - unset($connexion['tables']); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 102 | - if (!$nom) { |
|
| 103 | - spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 104 | - $connexion['tables'] = []; |
|
| 105 | - |
|
| 106 | - return null; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $nom_sql = $nom; |
|
| 110 | - $nom_sql = preg_match('/\.(.*)$/', $nom, $s) ? $s[1] : $nom; |
|
| 111 | - |
|
| 112 | - $fdesc = $desc = ''; |
|
| 113 | - $connexion = &$GLOBALS['connexions'][$serveur ?: 0]; |
|
| 114 | - |
|
| 115 | - // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 116 | - if ( |
|
| 117 | - $connexion['spip_connect_version'] |
|
| 118 | - && $table_spip |
|
| 119 | - && isset($GLOBALS['table_des_tables'][$nom]) |
|
| 120 | - ) { |
|
| 121 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 122 | - $nom_sql = 'spip_' . $nom; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - // si c'est la premiere table qu'on cherche |
|
| 126 | - // et si on est pas explicitement en recalcul |
|
| 127 | - // on essaye de recharger le cache des decriptions de ce serveur |
|
| 128 | - // dans le fichier cache |
|
| 129 | - if ( |
|
| 130 | - !isset($connexion['tables'][$nom_sql]) |
|
| 131 | - && defined('_VAR_MODE') |
|
| 132 | - && _VAR_MODE !== 'recalcul' |
|
| 133 | - && (!isset($connexion['tables']) || !$connexion['tables']) |
|
| 134 | - && lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 135 | - && ($desc_cache = unserialize($desc_cache)) |
|
| 136 | - ) { |
|
| 137 | - $connexion['tables'] = $desc_cache; |
|
| 138 | - } |
|
| 139 | - if ($table_spip && !isset($connexion['tables'][$nom_sql])) { |
|
| 140 | - if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 141 | - $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 142 | - } |
|
| 143 | - // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 144 | - // si c'est une table principale, |
|
| 145 | - // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 146 | - elseif ($nom_sql == $nom && isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 147 | - $nom_sql = 'spip_' . $nom; |
|
| 148 | - $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 149 | - } elseif ( |
|
| 150 | - isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 151 | - || isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 152 | - ) { |
|
| 153 | - $nom_sql = $n; |
|
| 154 | - $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 155 | - } # table locale a cote de SPIP, comme non SPIP: |
|
| 156 | - } |
|
| 157 | - if (!isset($connexion['tables'][$nom_sql])) { |
|
| 158 | - // La *vraie* base a la priorite |
|
| 159 | - $exists = sql_table_exists($nom_sql, $table_spip, $serveur); |
|
| 160 | - if ( |
|
| 161 | - !$exists |
|
| 162 | - || !($desc = sql_showtable($nom_sql, $table_spip, $serveur)) |
|
| 163 | - || !$desc['field'] |
|
| 164 | - ) { |
|
| 165 | - if (!$fdesc) { |
|
| 166 | - $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
|
| 167 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 168 | - |
|
| 169 | - return null; |
|
| 170 | - } |
|
| 171 | - // on ne sait pas lire la structure de la table : |
|
| 172 | - // on retombe sur la description donnee dans les fichiers spip |
|
| 173 | - $desc = $fdesc; |
|
| 174 | - $desc['exist'] = false; |
|
| 175 | - } else { |
|
| 176 | - $desc['exist'] = true; |
|
| 177 | - // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 178 | - // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 179 | - if (! $desc['key']) { |
|
| 180 | - spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 181 | - unset($desc['key']); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 186 | - $desc['connexion'] = $serveur; |
|
| 187 | - |
|
| 188 | - // charger les infos declarees pour cette table |
|
| 189 | - // en lui passant les infos connues |
|
| 190 | - // $desc est prioritaire pour la description de la table |
|
| 191 | - $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 192 | - // s'assurer qu'on a toujours un 'key' |
|
| 193 | - if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 194 | - $desc['key'] = $fdesc['key']; |
|
| 195 | - } |
|
| 196 | - if (! isset($desc['key'])) { |
|
| 197 | - $desc['key'] = []; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 201 | - $connexion['tables'][$nom_sql] = $desc; |
|
| 202 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 203 | - // une nouvelle table a ete decrite |
|
| 204 | - // mettons donc a jour le cache des descriptions de ce serveur |
|
| 205 | - if (is_writable(_DIR_CACHE)) { |
|
| 206 | - ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 207 | - } |
|
| 208 | - } else { |
|
| 209 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // toujours retourner $nom dans id_table |
|
| 213 | - $res['id_table'] = $nom; |
|
| 214 | - |
|
| 215 | - return $res; |
|
| 70 | + $desc_cache = null; |
|
| 71 | + static $nom_cache_desc_sql = []; |
|
| 72 | + |
|
| 73 | + if ( |
|
| 74 | + !spip_connect($serveur) |
|
| 75 | + || !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 76 | + ) { |
|
| 77 | + return null; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $options += [ |
|
| 81 | + // si false, baissera le niveau de log si une table demandée n’existe pas |
|
| 82 | + 'log_missing' => true, |
|
| 83 | + ]; |
|
| 84 | + |
|
| 85 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 86 | + $objets_sql = lister_tables_objets_sql('::md5'); |
|
| 87 | + |
|
| 88 | + // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 89 | + // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 90 | + // de connexion, et tout risque d'ambiguite |
|
| 91 | + if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 92 | + $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 93 | + _DIR_CACHE . 'sql_desc_' |
|
| 94 | + . ($serveur ? "{$serveur}_" : '') |
|
| 95 | + . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 96 | + . '.txt'; |
|
| 97 | + // nouveau nom de cache = nouvelle version en memoire |
|
| 98 | + unset($connexion['tables']); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 102 | + if (!$nom) { |
|
| 103 | + spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 104 | + $connexion['tables'] = []; |
|
| 105 | + |
|
| 106 | + return null; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $nom_sql = $nom; |
|
| 110 | + $nom_sql = preg_match('/\.(.*)$/', $nom, $s) ? $s[1] : $nom; |
|
| 111 | + |
|
| 112 | + $fdesc = $desc = ''; |
|
| 113 | + $connexion = &$GLOBALS['connexions'][$serveur ?: 0]; |
|
| 114 | + |
|
| 115 | + // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 116 | + if ( |
|
| 117 | + $connexion['spip_connect_version'] |
|
| 118 | + && $table_spip |
|
| 119 | + && isset($GLOBALS['table_des_tables'][$nom]) |
|
| 120 | + ) { |
|
| 121 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 122 | + $nom_sql = 'spip_' . $nom; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + // si c'est la premiere table qu'on cherche |
|
| 126 | + // et si on est pas explicitement en recalcul |
|
| 127 | + // on essaye de recharger le cache des decriptions de ce serveur |
|
| 128 | + // dans le fichier cache |
|
| 129 | + if ( |
|
| 130 | + !isset($connexion['tables'][$nom_sql]) |
|
| 131 | + && defined('_VAR_MODE') |
|
| 132 | + && _VAR_MODE !== 'recalcul' |
|
| 133 | + && (!isset($connexion['tables']) || !$connexion['tables']) |
|
| 134 | + && lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 135 | + && ($desc_cache = unserialize($desc_cache)) |
|
| 136 | + ) { |
|
| 137 | + $connexion['tables'] = $desc_cache; |
|
| 138 | + } |
|
| 139 | + if ($table_spip && !isset($connexion['tables'][$nom_sql])) { |
|
| 140 | + if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 141 | + $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 142 | + } |
|
| 143 | + // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 144 | + // si c'est une table principale, |
|
| 145 | + // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 146 | + elseif ($nom_sql == $nom && isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 147 | + $nom_sql = 'spip_' . $nom; |
|
| 148 | + $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 149 | + } elseif ( |
|
| 150 | + isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 151 | + || isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 152 | + ) { |
|
| 153 | + $nom_sql = $n; |
|
| 154 | + $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 155 | + } # table locale a cote de SPIP, comme non SPIP: |
|
| 156 | + } |
|
| 157 | + if (!isset($connexion['tables'][$nom_sql])) { |
|
| 158 | + // La *vraie* base a la priorite |
|
| 159 | + $exists = sql_table_exists($nom_sql, $table_spip, $serveur); |
|
| 160 | + if ( |
|
| 161 | + !$exists |
|
| 162 | + || !($desc = sql_showtable($nom_sql, $table_spip, $serveur)) |
|
| 163 | + || !$desc['field'] |
|
| 164 | + ) { |
|
| 165 | + if (!$fdesc) { |
|
| 166 | + $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
|
| 167 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 168 | + |
|
| 169 | + return null; |
|
| 170 | + } |
|
| 171 | + // on ne sait pas lire la structure de la table : |
|
| 172 | + // on retombe sur la description donnee dans les fichiers spip |
|
| 173 | + $desc = $fdesc; |
|
| 174 | + $desc['exist'] = false; |
|
| 175 | + } else { |
|
| 176 | + $desc['exist'] = true; |
|
| 177 | + // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 178 | + // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 179 | + if (! $desc['key']) { |
|
| 180 | + spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 181 | + unset($desc['key']); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 186 | + $desc['connexion'] = $serveur; |
|
| 187 | + |
|
| 188 | + // charger les infos declarees pour cette table |
|
| 189 | + // en lui passant les infos connues |
|
| 190 | + // $desc est prioritaire pour la description de la table |
|
| 191 | + $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 192 | + // s'assurer qu'on a toujours un 'key' |
|
| 193 | + if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 194 | + $desc['key'] = $fdesc['key']; |
|
| 195 | + } |
|
| 196 | + if (! isset($desc['key'])) { |
|
| 197 | + $desc['key'] = []; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 201 | + $connexion['tables'][$nom_sql] = $desc; |
|
| 202 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 203 | + // une nouvelle table a ete decrite |
|
| 204 | + // mettons donc a jour le cache des descriptions de ce serveur |
|
| 205 | + if (is_writable(_DIR_CACHE)) { |
|
| 206 | + ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 207 | + } |
|
| 208 | + } else { |
|
| 209 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // toujours retourner $nom dans id_table |
|
| 213 | + $res['id_table'] = $nom; |
|
| 214 | + |
|
| 215 | + return $res; |
|
| 216 | 216 | } |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | // de connexion, et tout risque d'ambiguite |
| 91 | 91 | if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
| 92 | 92 | $nom_cache_desc_sql[$serveur][$objets_sql] = |
| 93 | - _DIR_CACHE . 'sql_desc_' |
|
| 93 | + _DIR_CACHE.'sql_desc_' |
|
| 94 | 94 | . ($serveur ? "{$serveur}_" : '') |
| 95 | - . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 95 | + . substr(md5($connexion['db'].':'.$connexion['prefixe'].":$objets_sql"), 0, 8) |
|
| 96 | 96 | . '.txt'; |
| 97 | 97 | // nouveau nom de cache = nouvelle version en memoire |
| 98 | 98 | unset($connexion['tables']); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | && isset($GLOBALS['table_des_tables'][$nom]) |
| 120 | 120 | ) { |
| 121 | 121 | $nom = $GLOBALS['table_des_tables'][$nom]; |
| 122 | - $nom_sql = 'spip_' . $nom; |
|
| 122 | + $nom_sql = 'spip_'.$nom; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // si c'est la premiere table qu'on cherche |
@@ -143,12 +143,12 @@ discard block |
||
| 143 | 143 | // meme si pas d'abreviation declaree, trouver la table spip_$nom |
| 144 | 144 | // si c'est une table principale, |
| 145 | 145 | // puisqu'on le fait aussi pour les tables auxiliaires |
| 146 | - elseif ($nom_sql == $nom && isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 147 | - $nom_sql = 'spip_' . $nom; |
|
| 146 | + elseif ($nom_sql == $nom && isset($GLOBALS['tables_principales']['spip_'.$nom])) { |
|
| 147 | + $nom_sql = 'spip_'.$nom; |
|
| 148 | 148 | $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
| 149 | 149 | } elseif ( |
| 150 | 150 | isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
| 151 | - || isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 151 | + || isset($GLOBALS['tables_auxiliaires'][$n = 'spip_'.$nom]) |
|
| 152 | 152 | ) { |
| 153 | 153 | $nom_sql = $n; |
| 154 | 154 | $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | ) { |
| 165 | 165 | if (!$fdesc) { |
| 166 | 166 | $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
| 167 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 167 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base'.$log_level); |
|
| 168 | 168 | |
| 169 | 169 | return null; |
| 170 | 170 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $desc['exist'] = true; |
| 177 | 177 | // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
| 178 | 178 | // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
| 179 | - if (! $desc['key']) { |
|
| 179 | + if (!$desc['key']) { |
|
| 180 | 180 | spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
| 181 | 181 | unset($desc['key']); |
| 182 | 182 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | if (!isset($desc['key']) && !empty($fdesc['key'])) { |
| 194 | 194 | $desc['key'] = $fdesc['key']; |
| 195 | 195 | } |
| 196 | - if (! isset($desc['key'])) { |
|
| 196 | + if (!isset($desc['key'])) { |
|
| 197 | 197 | $desc['key'] = []; |
| 198 | 198 | } |
| 199 | 199 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -22,317 +22,317 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | class ValidateurXML |
| 24 | 24 | { |
| 25 | - public function validerElement($phraseur, $name, $attrs) { |
|
| 26 | - if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 27 | - if ($p = strpos((string) $name, ':')) { |
|
| 28 | - $name = substr((string) $name, $p + 1); |
|
| 29 | - $p = isset($this->dtc->elements[$name]); |
|
| 30 | - } |
|
| 31 | - if (!$p) { |
|
| 32 | - coordonnees_erreur($this, " <b>$name</b> : " |
|
| 33 | - . _T('zxml_inconnu_balise')); |
|
| 34 | - |
|
| 35 | - return; |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - // controler les filles illegitimes, ca suffit |
|
| 39 | - $depth = $this->depth; |
|
| 40 | - $ouvrant = $this->ouvrant; |
|
| 41 | - #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 42 | - if (isset($ouvrant[$depth]) && preg_match('/^\s*(\w+)/', (string) $ouvrant[$depth], $r)) { |
|
| 43 | - $pere = $r[1]; |
|
| 44 | - #spip_log("pere $pere"); |
|
| 45 | - if (isset($this->dtc->elements[$pere])) { |
|
| 46 | - $fils = $this->dtc->elements[$pere]; |
|
| 47 | - #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 48 | - if (!($p = @in_array($name, $fils)) && ($p = strpos((string) $name, ':'))) { |
|
| 49 | - $p = substr((string) $name, $p + 1); |
|
| 50 | - $p = @in_array($p, $fils); |
|
| 51 | - } |
|
| 52 | - if (!$p) { |
|
| 53 | - $bons_peres = @implode('</b>, <b>', $this->dtc->peres[$name]); |
|
| 54 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 55 | - . _T('zxml_non_fils') |
|
| 56 | - . ' <b>' |
|
| 57 | - . $pere |
|
| 58 | - . '</b>' |
|
| 59 | - . ($bons_peres ? '<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>' : '')); |
|
| 60 | - } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 61 | - $frat = substr((string) $depth, 2); |
|
| 62 | - if (!isset($this->fratrie[$frat])) { |
|
| 63 | - $this->fratrie[$frat] = ''; |
|
| 64 | - } |
|
| 65 | - $this->fratrie[$frat] .= "$name "; |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - // Init de la suite des balises a memoriser si regle difficile |
|
| 70 | - if ($this->dtc->regles[$name] && $this->dtc->regles[$name][0] == '/') { |
|
| 71 | - $this->fratrie[$depth] = ''; |
|
| 72 | - } |
|
| 73 | - if (isset($this->dtc->attributs[$name])) { |
|
| 74 | - foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 75 | - if ($v[1] == '#REQUIRED' && !isset($attrs[$n])) { |
|
| 76 | - coordonnees_erreur($this, " <b>$n</b>" |
|
| 77 | - . ' : ' |
|
| 78 | - . _T('zxml_obligatoire_attribut') |
|
| 79 | - . " <b>$name</b>"); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 86 | - // Si la balise est inconnue, eviter d'insister |
|
| 87 | - if (!isset($this->dtc->attributs[$bal])) { |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $a = $this->dtc->attributs[$bal]; |
|
| 92 | - if (!isset($a[$name])) { |
|
| 93 | - $bons = implode(', ', array_keys($a)); |
|
| 94 | - if ($bons) { |
|
| 95 | - $bons = " title=' " . |
|
| 96 | - _T('zxml_connus_attributs') . |
|
| 97 | - ' : ' . |
|
| 98 | - $bons . |
|
| 99 | - "'"; |
|
| 100 | - } |
|
| 101 | - $bons .= " style='font-weight: bold'"; |
|
| 102 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 103 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 104 | - . " <a$bons>$bal</a> (" |
|
| 105 | - . _T('zxml_survoler') |
|
| 106 | - . ')'); |
|
| 107 | - } else { |
|
| 108 | - $type = $a[$name][0]; |
|
| 109 | - if (!preg_match('/^\w+$/', (string) $type)) { |
|
| 110 | - $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 111 | - } else { |
|
| 112 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 113 | - $this->$f($phraseur, $name, $val, $bal); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - # else spip_log("$type type d'attribut inconnu"); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 121 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 125 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 129 | - if (isset($this->ids[$val])) { |
|
| 130 | - [$l, $c] = $this->ids[$val]; |
|
| 131 | - coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 132 | - . _T('zxml_valeur_attribut') |
|
| 133 | - . " <b>$name</b> " |
|
| 134 | - . _T('zxml_de') |
|
| 135 | - . " <b>$bal</b> " |
|
| 136 | - . _T('zxml_vu') |
|
| 137 | - . " (L$l,C$c)"); |
|
| 138 | - } else { |
|
| 139 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 140 | - $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 145 | - $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 149 | - $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 153 | - if (!preg_match($motif, (string) $val)) { |
|
| 154 | - coordonnees_erreur($this, "<b>$val</b> " |
|
| 155 | - . _T('zxml_valeur_attribut') |
|
| 156 | - . " <b>$name</b> " |
|
| 157 | - . _T('zxml_de') |
|
| 158 | - . " <b>$bal</b> " |
|
| 159 | - . _T('zxml_non_conforme') |
|
| 160 | - . '</p><p>' |
|
| 161 | - . '<b>' . $motif . '</b>'); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - public function valider_idref($nom, $ligne, $col) { |
|
| 166 | - if (!isset($this->ids[$nom])) { |
|
| 167 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - public function valider_passe2() { |
|
| 172 | - if (!$this->err) { |
|
| 173 | - foreach ($this->idrefs as $idref) { |
|
| 174 | - [$nom, $ligne, $col] = $idref; |
|
| 175 | - $this->valider_idref($nom, $ligne, $col); |
|
| 176 | - } |
|
| 177 | - foreach ($this->idrefss as $idref) { |
|
| 178 | - [$noms, $ligne, $col] = $idref; |
|
| 179 | - foreach (preg_split('/\s+/', (string) $noms) as $nom) { |
|
| 180 | - $this->valider_idref($nom, $ligne, $col); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 187 | - if ($this->dtc->elements) { |
|
| 188 | - $this->validerElement($phraseur, $name, $attrs); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if ($f = $this->process['debut']) { |
|
| 192 | - $f($this, $name, $attrs); |
|
| 193 | - } |
|
| 194 | - $depth = $this->depth; |
|
| 195 | - $this->debuts[$depth] = strlen((string) $this->res); |
|
| 196 | - foreach ($attrs as $k => $v) { |
|
| 197 | - $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - public function finElement($phraseur, $name) { |
|
| 202 | - $depth = $this->depth; |
|
| 203 | - $contenu = $this->contenu; |
|
| 204 | - |
|
| 205 | - $n = strlen((string) $this->res); |
|
| 206 | - $c = strlen(trim((string) $contenu[$depth])); |
|
| 207 | - $k = $this->debuts[$depth]; |
|
| 208 | - |
|
| 209 | - $regle = $this->dtc->regles[$name] ?? false; |
|
| 210 | - $vide = ($regle == 'EMPTY'); |
|
| 211 | - // controler que les balises devant etre vides le sont |
|
| 212 | - if ($vide) { |
|
| 213 | - if ($n != $k + $c) { |
|
| 214 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 215 | - } |
|
| 216 | - // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 217 | - } elseif ($regle && $regle != '*') { |
|
| 218 | - if ($regle == '+') { |
|
| 219 | - // iteration de disjonction non vide: 1 balise au - |
|
| 220 | - if ($n == $k) { |
|
| 221 | - coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 222 | - . _T('zxml_vide_balise')); |
|
| 223 | - } |
|
| 224 | - } else { |
|
| 225 | - $f = $this->fratrie[substr((string) $depth, 2)] ?? null; |
|
| 226 | - if (is_null($f) || !preg_match($regle, (string) $f)) { |
|
| 227 | - coordonnees_erreur( |
|
| 228 | - $this, |
|
| 229 | - " <p>\n<b>$name</b> " |
|
| 230 | - . _T('zxml_succession_fils_incorrecte') |
|
| 231 | - . ' : <b>' |
|
| 232 | - . $f |
|
| 233 | - . '</b>' |
|
| 234 | - ); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - if ($f = $this->process['fin']) { |
|
| 239 | - $f($this, $name, $vide); |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - public function textElement($phraseur, $data) { |
|
| 244 | - if (trim((string) $data)) { |
|
| 245 | - $d = $this->depth; |
|
| 246 | - $d = $this->ouvrant[$d]; |
|
| 247 | - preg_match('/^\s*(\S+)/', (string) $d, $m); |
|
| 248 | - if (isset($this->dtc->pcdata[$m[1]]) && $this->dtc->pcdata[$m[1]]) { |
|
| 249 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 250 | - . _T('zxml_nonvide_balise')); // message a affiner |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - if ($f = $this->process['text']) { |
|
| 254 | - $f($this, $data); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - public function piElement($phraseur, $target, $data) { |
|
| 259 | - if ($f = $this->process['pi']) { |
|
| 260 | - $f($this, $target, $data); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // Denonciation des entitees XML inconnues |
|
| 265 | - // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 266 | - // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 267 | - // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 268 | - // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 269 | - // le source de la page laisse legitimement supposer. |
|
| 270 | - |
|
| 271 | - public function defaultElement($phraseur, $data) { |
|
| 272 | - if ( |
|
| 273 | - !preg_match('/^<!--/', (string) $data) |
|
| 274 | - && preg_match_all('/&([^;]*)?/', (string) $data, $r, PREG_SET_ORDER) |
|
| 275 | - ) { |
|
| 276 | - foreach ($r as $m) { |
|
| 277 | - [$t, $e] = $m; |
|
| 278 | - if (!isset($this->dtc->entites[$e])) { |
|
| 279 | - coordonnees_erreur($this, " <b>$e</b> " |
|
| 280 | - . _T('zxml_inconnu_entite') |
|
| 281 | - . ' '); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - if (isset($this->process['default']) && ($f = $this->process['default'])) { |
|
| 286 | - $f($this, $data); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - public function phraserTout($phraseur, $data) { |
|
| 291 | - xml_parsestring($this, $data); |
|
| 292 | - |
|
| 293 | - if (!$this->dtc || preg_match(',^' . _MESSAGE_DOCTYPE . ',', (string) $data)) { |
|
| 294 | - $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 295 | - } else { |
|
| 296 | - $this->valider_passe2(); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Constructeur |
|
| 302 | - * |
|
| 303 | - * @param array $process ? |
|
| 304 | - **/ |
|
| 305 | - public function __construct($process = []) { |
|
| 306 | - if (is_array($process)) { |
|
| 307 | - $this->process = $process; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - public $ids = []; |
|
| 312 | - public $idrefs = []; |
|
| 313 | - public $idrefss = []; |
|
| 314 | - public $debuts = []; |
|
| 315 | - public $fratrie = []; |
|
| 316 | - |
|
| 317 | - public $dtc = null; |
|
| 318 | - public $sax = null; |
|
| 319 | - public $depth = ''; |
|
| 320 | - public $entete = ''; |
|
| 321 | - public $page = ''; |
|
| 322 | - public $res = ''; |
|
| 323 | - public array $err = []; |
|
| 324 | - public array $contenu = []; |
|
| 325 | - public array $versions = []; |
|
| 326 | - |
|
| 327 | - public array $ouvrant = []; |
|
| 328 | - public array $reperes = []; |
|
| 329 | - public array $process = [ |
|
| 330 | - 'debut' => 'xml_debutElement', |
|
| 331 | - 'fin' => 'xml_finElement', |
|
| 332 | - 'text' => 'xml_textElement', |
|
| 333 | - 'pi' => 'xml_piElement', |
|
| 334 | - 'default' => 'xml_defaultElement' |
|
| 335 | - ]; |
|
| 25 | + public function validerElement($phraseur, $name, $attrs) { |
|
| 26 | + if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 27 | + if ($p = strpos((string) $name, ':')) { |
|
| 28 | + $name = substr((string) $name, $p + 1); |
|
| 29 | + $p = isset($this->dtc->elements[$name]); |
|
| 30 | + } |
|
| 31 | + if (!$p) { |
|
| 32 | + coordonnees_erreur($this, " <b>$name</b> : " |
|
| 33 | + . _T('zxml_inconnu_balise')); |
|
| 34 | + |
|
| 35 | + return; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + // controler les filles illegitimes, ca suffit |
|
| 39 | + $depth = $this->depth; |
|
| 40 | + $ouvrant = $this->ouvrant; |
|
| 41 | + #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 42 | + if (isset($ouvrant[$depth]) && preg_match('/^\s*(\w+)/', (string) $ouvrant[$depth], $r)) { |
|
| 43 | + $pere = $r[1]; |
|
| 44 | + #spip_log("pere $pere"); |
|
| 45 | + if (isset($this->dtc->elements[$pere])) { |
|
| 46 | + $fils = $this->dtc->elements[$pere]; |
|
| 47 | + #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 48 | + if (!($p = @in_array($name, $fils)) && ($p = strpos((string) $name, ':'))) { |
|
| 49 | + $p = substr((string) $name, $p + 1); |
|
| 50 | + $p = @in_array($p, $fils); |
|
| 51 | + } |
|
| 52 | + if (!$p) { |
|
| 53 | + $bons_peres = @implode('</b>, <b>', $this->dtc->peres[$name]); |
|
| 54 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 55 | + . _T('zxml_non_fils') |
|
| 56 | + . ' <b>' |
|
| 57 | + . $pere |
|
| 58 | + . '</b>' |
|
| 59 | + . ($bons_peres ? '<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>' : '')); |
|
| 60 | + } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 61 | + $frat = substr((string) $depth, 2); |
|
| 62 | + if (!isset($this->fratrie[$frat])) { |
|
| 63 | + $this->fratrie[$frat] = ''; |
|
| 64 | + } |
|
| 65 | + $this->fratrie[$frat] .= "$name "; |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + // Init de la suite des balises a memoriser si regle difficile |
|
| 70 | + if ($this->dtc->regles[$name] && $this->dtc->regles[$name][0] == '/') { |
|
| 71 | + $this->fratrie[$depth] = ''; |
|
| 72 | + } |
|
| 73 | + if (isset($this->dtc->attributs[$name])) { |
|
| 74 | + foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 75 | + if ($v[1] == '#REQUIRED' && !isset($attrs[$n])) { |
|
| 76 | + coordonnees_erreur($this, " <b>$n</b>" |
|
| 77 | + . ' : ' |
|
| 78 | + . _T('zxml_obligatoire_attribut') |
|
| 79 | + . " <b>$name</b>"); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 86 | + // Si la balise est inconnue, eviter d'insister |
|
| 87 | + if (!isset($this->dtc->attributs[$bal])) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $a = $this->dtc->attributs[$bal]; |
|
| 92 | + if (!isset($a[$name])) { |
|
| 93 | + $bons = implode(', ', array_keys($a)); |
|
| 94 | + if ($bons) { |
|
| 95 | + $bons = " title=' " . |
|
| 96 | + _T('zxml_connus_attributs') . |
|
| 97 | + ' : ' . |
|
| 98 | + $bons . |
|
| 99 | + "'"; |
|
| 100 | + } |
|
| 101 | + $bons .= " style='font-weight: bold'"; |
|
| 102 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 103 | + . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 104 | + . " <a$bons>$bal</a> (" |
|
| 105 | + . _T('zxml_survoler') |
|
| 106 | + . ')'); |
|
| 107 | + } else { |
|
| 108 | + $type = $a[$name][0]; |
|
| 109 | + if (!preg_match('/^\w+$/', (string) $type)) { |
|
| 110 | + $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 111 | + } else { |
|
| 112 | + if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 113 | + $this->$f($phraseur, $name, $val, $bal); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + # else spip_log("$type type d'attribut inconnu"); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 121 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 125 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 129 | + if (isset($this->ids[$val])) { |
|
| 130 | + [$l, $c] = $this->ids[$val]; |
|
| 131 | + coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 132 | + . _T('zxml_valeur_attribut') |
|
| 133 | + . " <b>$name</b> " |
|
| 134 | + . _T('zxml_de') |
|
| 135 | + . " <b>$bal</b> " |
|
| 136 | + . _T('zxml_vu') |
|
| 137 | + . " (L$l,C$c)"); |
|
| 138 | + } else { |
|
| 139 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 140 | + $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 145 | + $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 149 | + $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 153 | + if (!preg_match($motif, (string) $val)) { |
|
| 154 | + coordonnees_erreur($this, "<b>$val</b> " |
|
| 155 | + . _T('zxml_valeur_attribut') |
|
| 156 | + . " <b>$name</b> " |
|
| 157 | + . _T('zxml_de') |
|
| 158 | + . " <b>$bal</b> " |
|
| 159 | + . _T('zxml_non_conforme') |
|
| 160 | + . '</p><p>' |
|
| 161 | + . '<b>' . $motif . '</b>'); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + public function valider_idref($nom, $ligne, $col) { |
|
| 166 | + if (!isset($this->ids[$nom])) { |
|
| 167 | + $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + public function valider_passe2() { |
|
| 172 | + if (!$this->err) { |
|
| 173 | + foreach ($this->idrefs as $idref) { |
|
| 174 | + [$nom, $ligne, $col] = $idref; |
|
| 175 | + $this->valider_idref($nom, $ligne, $col); |
|
| 176 | + } |
|
| 177 | + foreach ($this->idrefss as $idref) { |
|
| 178 | + [$noms, $ligne, $col] = $idref; |
|
| 179 | + foreach (preg_split('/\s+/', (string) $noms) as $nom) { |
|
| 180 | + $this->valider_idref($nom, $ligne, $col); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 187 | + if ($this->dtc->elements) { |
|
| 188 | + $this->validerElement($phraseur, $name, $attrs); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if ($f = $this->process['debut']) { |
|
| 192 | + $f($this, $name, $attrs); |
|
| 193 | + } |
|
| 194 | + $depth = $this->depth; |
|
| 195 | + $this->debuts[$depth] = strlen((string) $this->res); |
|
| 196 | + foreach ($attrs as $k => $v) { |
|
| 197 | + $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + public function finElement($phraseur, $name) { |
|
| 202 | + $depth = $this->depth; |
|
| 203 | + $contenu = $this->contenu; |
|
| 204 | + |
|
| 205 | + $n = strlen((string) $this->res); |
|
| 206 | + $c = strlen(trim((string) $contenu[$depth])); |
|
| 207 | + $k = $this->debuts[$depth]; |
|
| 208 | + |
|
| 209 | + $regle = $this->dtc->regles[$name] ?? false; |
|
| 210 | + $vide = ($regle == 'EMPTY'); |
|
| 211 | + // controler que les balises devant etre vides le sont |
|
| 212 | + if ($vide) { |
|
| 213 | + if ($n != $k + $c) { |
|
| 214 | + coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 215 | + } |
|
| 216 | + // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 217 | + } elseif ($regle && $regle != '*') { |
|
| 218 | + if ($regle == '+') { |
|
| 219 | + // iteration de disjonction non vide: 1 balise au - |
|
| 220 | + if ($n == $k) { |
|
| 221 | + coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 222 | + . _T('zxml_vide_balise')); |
|
| 223 | + } |
|
| 224 | + } else { |
|
| 225 | + $f = $this->fratrie[substr((string) $depth, 2)] ?? null; |
|
| 226 | + if (is_null($f) || !preg_match($regle, (string) $f)) { |
|
| 227 | + coordonnees_erreur( |
|
| 228 | + $this, |
|
| 229 | + " <p>\n<b>$name</b> " |
|
| 230 | + . _T('zxml_succession_fils_incorrecte') |
|
| 231 | + . ' : <b>' |
|
| 232 | + . $f |
|
| 233 | + . '</b>' |
|
| 234 | + ); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + if ($f = $this->process['fin']) { |
|
| 239 | + $f($this, $name, $vide); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + public function textElement($phraseur, $data) { |
|
| 244 | + if (trim((string) $data)) { |
|
| 245 | + $d = $this->depth; |
|
| 246 | + $d = $this->ouvrant[$d]; |
|
| 247 | + preg_match('/^\s*(\S+)/', (string) $d, $m); |
|
| 248 | + if (isset($this->dtc->pcdata[$m[1]]) && $this->dtc->pcdata[$m[1]]) { |
|
| 249 | + coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 250 | + . _T('zxml_nonvide_balise')); // message a affiner |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + if ($f = $this->process['text']) { |
|
| 254 | + $f($this, $data); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + public function piElement($phraseur, $target, $data) { |
|
| 259 | + if ($f = $this->process['pi']) { |
|
| 260 | + $f($this, $target, $data); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // Denonciation des entitees XML inconnues |
|
| 265 | + // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 266 | + // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 267 | + // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 268 | + // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 269 | + // le source de la page laisse legitimement supposer. |
|
| 270 | + |
|
| 271 | + public function defaultElement($phraseur, $data) { |
|
| 272 | + if ( |
|
| 273 | + !preg_match('/^<!--/', (string) $data) |
|
| 274 | + && preg_match_all('/&([^;]*)?/', (string) $data, $r, PREG_SET_ORDER) |
|
| 275 | + ) { |
|
| 276 | + foreach ($r as $m) { |
|
| 277 | + [$t, $e] = $m; |
|
| 278 | + if (!isset($this->dtc->entites[$e])) { |
|
| 279 | + coordonnees_erreur($this, " <b>$e</b> " |
|
| 280 | + . _T('zxml_inconnu_entite') |
|
| 281 | + . ' '); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + if (isset($this->process['default']) && ($f = $this->process['default'])) { |
|
| 286 | + $f($this, $data); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + public function phraserTout($phraseur, $data) { |
|
| 291 | + xml_parsestring($this, $data); |
|
| 292 | + |
|
| 293 | + if (!$this->dtc || preg_match(',^' . _MESSAGE_DOCTYPE . ',', (string) $data)) { |
|
| 294 | + $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 295 | + } else { |
|
| 296 | + $this->valider_passe2(); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Constructeur |
|
| 302 | + * |
|
| 303 | + * @param array $process ? |
|
| 304 | + **/ |
|
| 305 | + public function __construct($process = []) { |
|
| 306 | + if (is_array($process)) { |
|
| 307 | + $this->process = $process; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + public $ids = []; |
|
| 312 | + public $idrefs = []; |
|
| 313 | + public $idrefss = []; |
|
| 314 | + public $debuts = []; |
|
| 315 | + public $fratrie = []; |
|
| 316 | + |
|
| 317 | + public $dtc = null; |
|
| 318 | + public $sax = null; |
|
| 319 | + public $depth = ''; |
|
| 320 | + public $entete = ''; |
|
| 321 | + public $page = ''; |
|
| 322 | + public $res = ''; |
|
| 323 | + public array $err = []; |
|
| 324 | + public array $contenu = []; |
|
| 325 | + public array $versions = []; |
|
| 326 | + |
|
| 327 | + public array $ouvrant = []; |
|
| 328 | + public array $reperes = []; |
|
| 329 | + public array $process = [ |
|
| 330 | + 'debut' => 'xml_debutElement', |
|
| 331 | + 'fin' => 'xml_finElement', |
|
| 332 | + 'text' => 'xml_textElement', |
|
| 333 | + 'pi' => 'xml_piElement', |
|
| 334 | + 'default' => 'xml_defaultElement' |
|
| 335 | + ]; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | * |
| 343 | 343 | **/ |
| 344 | 344 | function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) { |
| 345 | - $f = new ValidateurXML($process); |
|
| 346 | - $sax = charger_fonction('sax', 'xml'); |
|
| 345 | + $f = new ValidateurXML($process); |
|
| 346 | + $sax = charger_fonction('sax', 'xml'); |
|
| 347 | 347 | |
| 348 | - return $sax($page, $apply, $f, $doctype, $charset); |
|
| 348 | + return $sax($page, $apply, $f, $doctype, $charset); |
|
| 349 | 349 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | . ' <b>' |
| 57 | 57 | . $pere |
| 58 | 58 | . '</b>' |
| 59 | - . ($bons_peres ? '<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>' : '')); |
|
| 59 | + . ($bons_peres ? '<p style="font-size: 80%"> '._T('zxml_mais_de').' <b>'.$bons_peres.'</b></p>' : '')); |
|
| 60 | 60 | } elseif ($this->dtc->regles[$pere][0] == '/') { |
| 61 | 61 | $frat = substr((string) $depth, 2); |
| 62 | 62 | if (!isset($this->fratrie[$frat])) { |
@@ -92,15 +92,15 @@ discard block |
||
| 92 | 92 | if (!isset($a[$name])) { |
| 93 | 93 | $bons = implode(', ', array_keys($a)); |
| 94 | 94 | if ($bons) { |
| 95 | - $bons = " title=' " . |
|
| 96 | - _T('zxml_connus_attributs') . |
|
| 97 | - ' : ' . |
|
| 98 | - $bons . |
|
| 95 | + $bons = " title=' ". |
|
| 96 | + _T('zxml_connus_attributs'). |
|
| 97 | + ' : '. |
|
| 98 | + $bons. |
|
| 99 | 99 | "'"; |
| 100 | 100 | } |
| 101 | 101 | $bons .= " style='font-weight: bold'"; |
| 102 | 102 | coordonnees_erreur($this, " <b>$name</b> " |
| 103 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 103 | + . _T('zxml_inconnu_attribut').' '._T('zxml_de') |
|
| 104 | 104 | . " <a$bons>$bal</a> (" |
| 105 | 105 | . _T('zxml_survoler') |
| 106 | 106 | . ')'); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | if (!preg_match('/^\w+$/', (string) $type)) { |
| 110 | 110 | $this->valider_motif($phraseur, $name, $val, $bal, $type); |
| 111 | 111 | } else { |
| 112 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 112 | + if (method_exists($this, $f = 'validerAttribut_'.$type)) { |
|
| 113 | 113 | $this->$f($phraseur, $name, $val, $bal); |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -158,13 +158,13 @@ discard block |
||
| 158 | 158 | . " <b>$bal</b> " |
| 159 | 159 | . _T('zxml_non_conforme') |
| 160 | 160 | . '</p><p>' |
| 161 | - . '<b>' . $motif . '</b>'); |
|
| 161 | + . '<b>'.$motif.'</b>'); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | public function valider_idref($nom, $ligne, $col) { |
| 166 | 166 | if (!isset($this->ids[$nom])) { |
| 167 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 167 | + $this->err[] = [" <p><b>$nom</b> "._T('zxml_inconnu_id'), $ligne, $col]; |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | // controler que les balises devant etre vides le sont |
| 212 | 212 | if ($vide) { |
| 213 | 213 | if ($n != $k + $c) { |
| 214 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 214 | + coordonnees_erreur($this, " <p><b>$name</b> "._T('zxml_nonvide_balise')); |
|
| 215 | 215 | } |
| 216 | 216 | // pour les regles PCDATA ou iteration de disjonction, tout est fait |
| 217 | 217 | } elseif ($regle && $regle != '*') { |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $d = $this->ouvrant[$d]; |
| 247 | 247 | preg_match('/^\s*(\S+)/', (string) $d, $m); |
| 248 | 248 | if (isset($this->dtc->pcdata[$m[1]]) && $this->dtc->pcdata[$m[1]]) { |
| 249 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 249 | + coordonnees_erreur($this, ' <p><b>'.$m[1].'</b> ' |
|
| 250 | 250 | . _T('zxml_nonvide_balise')); // message a affiner |
| 251 | 251 | } |
| 252 | 252 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | public function phraserTout($phraseur, $data) { |
| 291 | 291 | xml_parsestring($this, $data); |
| 292 | 292 | |
| 293 | - if (!$this->dtc || preg_match(',^' . _MESSAGE_DOCTYPE . ',', (string) $data)) { |
|
| 293 | + if (!$this->dtc || preg_match(',^'._MESSAGE_DOCTYPE.',', (string) $data)) { |
|
| 294 | 294 | $this->err[] = ['DOCTYPE ?', 0, 0]; |
| 295 | 295 | } else { |
| 296 | 296 | $this->valider_passe2(); |