Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 2415 → Rev 3569

/trunk/scripts/modules/maintenance/Maintenance.php
135,18 → 135,24
// Régénère le champ "mots_cles_texte" pour toutes les images ayant des mots clés mais ayant ce champ
// vide, suite à une erreur
protected function regenererMotsClesTexteImages($tout = false) {
$req = "SELECT id_image FROM cel_images WHERE ".
"id_image IN (SELECT id_element_lie FROM cel_mots_cles_images_liaison)";
if(!$tout) {
$req .= " AND (mots_cles_texte IS NULL OR mots_cles_texte='')";
$requete = 'SELECT id_image '.
'FROM cel_images '.
'WHERE id_image IN (SELECT id_element_lie FROM cel_mots_cles_images_liaison) ';
if (!$tout) {
$requete .= "AND (mots_cles_texte IS NULL OR mots_cles_texte = '') ";
}
$res = $this->bdd->recupererTous($req);
echo count($res) . " images trouvées\n";
foreach ($res as $image) {
$req = "UPDATE cel_images SET mots_cles_texte = (SELECT GROUP_CONCAT(mot_cle) FROM cel_arbre_mots_cles_images cm "
. "INNER JOIN cel_mots_cles_images_liaison cml ON cml.id_mot_cle = cm.id_mot_cle AND cml.id_element_lie = '" . $image['id_image'] . "') "
. "WHERE id_image = '" . $image['id_image'] . "'";
$this->bdd->requeter($req);
$resultats = $this->bdd->recupererTous($requete);
echo count($resultats)." images trouvées\n";
foreach ($resultats as $image) {
$requete = 'UPDATE cel_images '.
'SET mots_cles_texte = ('.
' SELECT GROUP_CONCAT(mot_cle) '.
' FROM cel_arbre_mots_cles_images AS cm '.
' INNER JOIN cel_mots_cles_images_liaison AS cml '.
" ON (cml.id_mot_cle = cm.id_mot_cle AND cml.id_element_lie = '" . $image['id_image'] . "') ".
') '.
"WHERE id_image = '" . $image['id_image'] . "'";
$this->bdd->requeter($requete);
}
}
 
153,17 → 159,18
// Régénère le champ "mots_cles_texte" pour toutes les observations ayant des mots clés mais ayant ce champ
// vide, suite à une erreur
protected function regenererMotsClesTexteObs($tout = false) {
$req = "SELECT id_observation FROM cel_obs WHERE ".
"id_observation IN (SELECT id_element_lie FROM cel_mots_cles_obs_liaison)";
if(!$tout) {
$req .= " AND (mots_cles_texte IS NULL OR mots_cles_texte='')";
$requete = 'SELECT id_observation '.
'FROM cel_obs '.
'WHERE id_observation IN (SELECT id_element_lie FROM cel_mots_cles_obs_liaison) ';
if (!$tout) {
$requete .= "AND (mots_cles_texte IS NULL OR mots_cles_texte = '')";
}
$res = $this->bdd->recupererTous($req);
echo count($res) . " observations trouvées\n";
foreach ($res as $image) {
$req = "UPDATE cel_obs SET mots_cles_texte = (SELECT GROUP_CONCAT(mot_cle) FROM cel_arbre_mots_cles_obs cm "
. "INNER JOIN cel_mots_cles_obs_liaison cml ON cml.id_mot_cle = cm.id_mot_cle AND cml.id_element_lie = '" . $image['id_observation'] . "') "
. "WHERE id_observation = '" . $image['id_observation'] . "'";
$resultats = $this->bdd->recupererTous($requete);
echo count($resultats) . " observations trouvées\n";
foreach ($resultats as $image) {
$req = "UPDATE cel_obs SET mots_cles_texte = (SELECT GROUP_CONCAT(mot_cle) FROM cel_arbre_mots_cles_obs cm ".
"INNER JOIN cel_mots_cles_obs_liaison cml ON cml.id_mot_cle = cm.id_mot_cle AND cml.id_element_lie = '" . $image['id_observation'] . "') ".
"WHERE id_observation = '" . $image['id_observation'] . "'";
$this->bdd->requeter($req);
}
}
235,7 → 242,7
// Toutes les liaisons obs-motscles avec l'id utilisateur issu de la table cel obs car
// dans la table de liaison il est souvent vide
$requete_liaisons = "SELECT com.id_observation, com.id_mot_cle_obs, co.ce_utilisateur ".
"FROM `cel_obs_mots_cles` com INNER JOIN cel_obs co ON co.id_observation = com.id_observation ";
"FROM `cel_obs_mots_cles` com INNER JOIN cel_obs co ON co.id_observation = com.id_observation ";
 
$liaisons = $this->bdd->recupererTous($requete_liaisons);
$nb_liaisons_originales = count($liaisons);
286,9 → 293,9
$nouvel_id_mot_cle = $nouveau_mots_cles_fmt[$id_utilisateur_liaison][$texte_ancien_mot_cle]['id_mot_cle'];
 
$valeurs_a_inserer[] = array(
'id_element_lie' => $liaison['id_observation'],
'id_mot_cle' => $nouvel_id_mot_cle,
'ancienne_liaison' => $liaison
'id_element_lie' => $liaison['id_observation'],
'id_mot_cle' => $nouvel_id_mot_cle,
'ancienne_liaison' => $liaison
);
$ids_obs[] = $liaison['id_observation'];
} else {
315,13 → 322,12
$tranches = array_chunk($valeurs_a_inserer, 800);
 
foreach($tranches as $tranche) {
$requete_insertion = "INSERT IGNORE INTO cel_mots_cles_obs_liaison (id_element_lie, id_mot_cle) ".
"VALUES ";
$requete = "INSERT IGNORE INTO cel_mots_cles_obs_liaison (id_element_lie, id_mot_cle) VALUES ";
foreach($tranche as $l) {
$requete_insertion .= "('".$l['id_element_lie']."', '".$l['id_mot_cle']."'),";
$requete .= "('".$l['id_element_lie']."', '".$l['id_mot_cle']."'), ";
}
$requete_insertion = rtrim($requete_insertion, ',');
$insertion = $this->bdd->requeter($requete_insertion);
$requete = rtrim($requete, ',');
$insertion = $this->bdd->requeter($requete);
$this->afficherAvancement("Liaisons insérées (par paquet de 800) ", 1);
}
echo "\n";
378,9 → 384,9
$nouvel_id_mot_cle = $nouveau_mots_cles_fmt[$id_utilisateur_liaison][$texte_ancien_mot_cle]['id_mot_cle'];
 
$valeurs_a_inserer[] = array(
'id_element_lie' => $liaison['id_image'],
'id_mot_cle' => $nouvel_id_mot_cle,
'ancienne_liaison' => $liaison
'id_element_lie' => $liaison['id_image'],
'id_mot_cle' => $nouvel_id_mot_cle,
'ancienne_liaison' => $liaison
);
$ids_imgs[] = $liaison['id_image'];
} else {
406,13 → 412,13
$tranches = array_chunk($valeurs_a_inserer, 800);
 
foreach($tranches as $tranche) {
$requete_insertion = "INSERT IGNORE INTO cel_mots_cles_images_liaison (id_element_lie, id_mot_cle) ".
"VALUES ";
$requete = "INSERT IGNORE INTO cel_mots_cles_images_liaison (id_element_lie, id_mot_cle) ".
"VALUES ";
foreach($tranche as $l) {
$requete_insertion .= "('".$l['id_element_lie']."', '".$l['id_mot_cle']."'),";
$requete .= "('".$l['id_element_lie']."', '".$l['id_mot_cle']."'),";
}
$requete_insertion = rtrim($requete_insertion, ',');
$insertion = $this->bdd->requeter($requete_insertion);
$requete = rtrim($requete, ',');
$insertion = $this->bdd->requeter($requete);
$this->afficherAvancement("Liaisons insérées (par paquet de 800) ", 1);
}
echo "\n";
420,15 → 426,18
 
private function reparerLiaisonsObsParMotsClesTexte($mot_cle_texte_recherche) {
$ancienne_table_obs = Config::get('table_obs_recup');
$requete_anciens_mots_cles_texte = "SELECT ce_utilisateur, id_observation, mots_cles_texte ".
"FROM ".$ancienne_table_obs." WHERE mots_cles_texte LIKE '%".$mot_cle_texte_recherche."%'";
$obs_a_mot_cle = $this->bdd->recupererTous($requete_anciens_mots_cles_texte);
$requete = "SELECT ce_utilisateur, id_observation, mots_cles_texte ".
"FROM $ancienne_table_obs ".
"WHERE mots_cles_texte LIKE '%$mot_cle_texte_recherche%' ";
$obs_a_mot_cle = $this->bdd->recupererTous($requete);
 
$requete_nouveaux_mots_cle = "SELECT * FROM cel_arbre_mots_cles_obs ".
"WHERE id_utilisateur IN ".
"(SELECT id_utilisateur FROM ".$ancienne_table_obs." ".
"WHERE mots_cles_texte LIKE '%".$mot_cle_texte_recherche."%')";
$nouveaux_mots_cles = $this->bdd->recupererTous($requete_nouveaux_mots_cle);
$requete = 'SELECT * '.
'FROM cel_arbre_mots_cles_obs '.
'WHERE id_utilisateur IN ( '.
' SELECT id_utilisateur '.
"FROM $ancienne_table_obs ".
" WHERE mots_cles_texte LIKE '%$mot_cle_texte_recherche%') ";
$nouveaux_mots_cles = $this->bdd->recupererTous($requete);
 
$mots_cles_indexes = array();
foreach($nouveaux_mots_cles as $mot_cle) {
543,9 → 552,10
if ($mode == "images" || $mode == "obs") {
$table .= $mode;
}
$q1 = "SELECT id_mot_cle, chemin, mot_cle, (LOCATE(mot_cle, chemin) != 0) as valide FROM `$table`"
. " WHERE id_utilisateur = '$idUtilisateur'"
. " ORDER BY chemin ASC, valide DESC;";
$q1 = 'SELECT id_mot_cle, chemin, mot_cle, (LOCATE(mot_cle, chemin) != 0) AS valide '.
"FROM `$table` ".
"WHERE id_utilisateur = '$idUtilisateur' ".
"ORDER BY chemin ASC, valide DESC ";
$r1 = $this->bdd->requeter($q1);
 
$idsMotsCles = array();
618,8 → 628,8
echo "Fin de la réduction des mots clés $mode \n";
}
 
private function supprimerMajuscules($table, $colonne, $util=null) {
$requete = "UPDATE ".$table." SET ".$colonne." = LOWER(".$colonne.")";
private function supprimerMajuscules($table, $colonne, $util = null) {
$requete = "UPDATE $table SET $colonne = LOWER($colonne)";
if ($util !== null) {
$requete .= " WHERE id_utilisateur = $util";
}
626,8 → 636,7
$this->bdd->requeter($requete);
}
 
private function supprimerAccents($table, $colonne, $util=null) {
 
private function supprimerAccents($table, $colonne, $util = null) {
$requetes = array(
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Š','S')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'š','s')",
700,7 → 709,7
 
foreach($requetes as $requete) {
if ($util !== null) {
$requete .= " WHERE id_utilisateur = $util";
$requete .= " WHERE id_utilisateur = $util ";
}
$this->bdd->requeter($requete);
}