Subversion Repositories eFlore/Applications.cel

Compare Revisions

No changes between revisions

Ignore whitespace Rev 2192 → Rev 2193

/branches/v2.2-faucille/scripts/modules/maintenance/Maintenance.php
5,7 → 5,7
protected $parametres_autorises = array(
'-mc' => array(false, '1', 'Mot clef à chercher pour régénérer les machins'),
'-doublon' => array(false, '1', "Id du mot clé qu'on veut réduire à un autre"),
'-util' => array(false, '1', "Id de l'utilisateur"),
'-util' => array(false, null, "Id de l'utilisateur"),
'-cible' => array(false, '1', "Id de l'autre mot clé")
);
 
57,9 → 57,18
break;
case 'reductionMotsClesImagesUtil' :
// ex: cli.php maintenance -a reductionMotsClesImagesUtil -util 6865
$idUtilisateur = $this->getParametre('util');
$idUtilisateur = $this->obtenirParametreIntObligatoirePourMethode('util');
$this->reductionMotsClesImagesUtilisateur($idUtilisateur);
break;
case 'reduireEtNormaliserMotsClesImagesUtil' :
// ex: cli.php maintenance -a reduireEtNormaliserMotsClesImages -util 6865
$idUtilisateur = $this->obtenirParametreIntObligatoirePourMethode('util');
$this->reduireEtNormaliserMotsClesImages($idUtilisateur);
break;
case 'reduireEtNormaliserMotsClesImages' :
// ex: cli.php maintenance -a reduireEtNormaliserMotsClesImages
$this->reduireEtNormaliserMotsClesImages();
break;
default :
$msg = "Erreur : la commande '$cmd' n'existe pas!\n".
"Commandes existantes : regenererMotsClesTexteImages, regenererMotsClesTexteObs";
69,6 → 78,15
$this->traiterErreur($e->getMessage());
}
}
private function obtenirParametreIntObligatoirePourMethode($param) {
$param_val = $this->getParametre($param);
if(!$param_val || !is_numeric($param_val)) {
$msg = "Erreur : le paramètre $param est obligatoire pour cette méthode et doit être un entier \n";
throw new Exception($msg);
}
return $param_val;
}
 
// 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
440,7 → 458,9
// Parcourt l'arbre des mots-cles images de l'utilisateur dont l'id est $idUtilisateur, et réduit tous ceux dont le chemin
// n'est pas unique
private function reductionMotsClesImagesUtilisateur($idUtilisateur) {
$q1 = "SELECT id_mot_cle, chemin FROM cel_arbre_mots_cles_images WHERE id_utilisateur = $idUtilisateur;";
$q1 = "SELECT id_mot_cle, chemin, mot_cle, (LOCATE(mot_cle, chemin) != 0) as valide FROM cel_arbre_mots_cles_images"
. " WHERE id_utilisateur = '$idUtilisateur'"
. " ORDER BY chemin ASC, valide DESC;";
$r1 = $this->bdd->requeter($q1);
 
$idsMotsCles = array();
468,5 → 488,126
}
echo "$aTraiter groupes ont été réduits" . PHP_EOL;
}
private function reduireEtNormaliserMotsClesImages($util=null) {
$this->reduireEtNormaliserMotsCles('cel_arbre_mots_cles_images', 'chemin', 'images', $util);
}
private function reduireEtNormaliserMotsCles($table, $colonne, $mode = "images", $util=null) {
echo "Suppression des accents dans la table $table, colonne $colonne ...";
$this->supprimerAccents($table, $colonne, $util);
echo "effectuée \n";
echo "Suppression des majuscules dans la table $table, colonne $colonne ...";
$this->supprimerMajuscules($table, $colonne, $util);
echo "effectuée \n";
echo "\n";
if ($util !== null) {
echo "Réduction de tous les mots clés $mode de l'utilisateur $util\n";
$this->reductionMotsClesImagesUtilisateur($util);
} else {
echo "Réduction de tous les mots clés $mode \n";
$req_utilisateurs = "SELECT DISTINCT id_utilisateur FROM ".$table;
$utilisateurs = $this->bdd->recupererTous($req_utilisateurs);
foreach($utilisateurs as $utilisateur) {
echo "Utilisateur en cours de traitement : ".$utilisateur['id_utilisateur']." \n";
if($mode == "images") {
$this->reductionMotsClesImagesUtilisateur($utilisateur['id_utilisateur']);
} else {
//TODO: créer cette fonction
// $this->reductionMotsClesObsUtilisateur($utilisateur['id_utilisateur']);
}
}
}
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.")";
if ($util !== null) {
$requete .= " WHERE id_utilisateur = $util";
}
$this->bdd->requeter($requete);
}
private function supprimerAccents($table, $colonne, $util=null) {
$requetes = array(
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Š','S')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'š','s')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ð','Dj')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ž','Z')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ž','z')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'À','A')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Á','A')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Â','A')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ã','A')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ä','A')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Å','A')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Æ','A')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ç','C')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'È','E')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'É','E')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ê','E')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ë','E')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ì','I')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Í','I')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Î','I')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ï','I')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ñ','N')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ò','O')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ó','O')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ô','O')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Õ','O')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ö','O')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ø','O')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ù','U')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ú','U')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Û','U')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ü','U')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Ý','Y')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'Þ','B')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ß','Ss')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'à','a')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'á','a')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'â','a')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ã','a')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ä','a')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'å','a')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'æ','a')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ç','c')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'è','e')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'é','e')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ê','e')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ë','e')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ì','i')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'í','i')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'î','i')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ï','i')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ð','o')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ñ','n')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ò','o')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ó','o')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ô','o')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'õ','o')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ö','o')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ø','o')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ù','u')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ú','u')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'û','u')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ý','y')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ý','y')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'þ','b')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ÿ','y')",
"UPDATE ".$table." SET ".$colonne." = REPLACE(".$colonne.",'ƒ','f')",
);
foreach($requetes as $requete) {
if ($util !== null) {
$requete .= " WHERE id_utilisateur = $util";
}
$this->bdd->requeter($requete);
}
}
}
?>
/branches/v2.2-faucille/scripts
Property changes:
Modified: svn:mergeinfo
Merged /trunk/scripts:r2191-2192
/branches/v2.2-faucille/.
Property changes:
Modified: svn:mergeinfo
Merged /trunk:r2191-2192