Blame | Last modification | View Log | RSS feed
<?php
class Maintenance extends Script {
protected $bdd;
public function __construct($script_nom, $parametres_cli) {
parent::__construct($script_nom, $parametres_cli);
$this->bdd = new Bdd();
}
public function executer() {
$cmd = $this->getParametre('a');
try {
switch ($cmd) {
case 'regenererMotsClesTexteObs' :
$this->regenererMotsClesTexteObs();
break;
case 'regenererMotsClesTexteImages' :
$this->regenererMotsClesTexteImages();
break;
default :
$msg = "Erreur : la commande '$cmd' n'existe pas!\n".
"Commandes existantes : regenererMotsClesTexteImages, regenererMotsClesTexteObs";
throw new Exception($msg);
}
} catch (Exception $e) {
$this->traiterErreur($e->getMessage());
}
}
// 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() {
$req = "SELECT id_image FROM cel_images WHERE (mots_cles_texte IS NULL OR mots_cles_texte='') "
. "AND id_image IN (SELECT id_element_lie FROM cel_mots_cles_images_liaison)";
$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);
}
}
// 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() {
$req = "SELECT id_observation FROM cel_obs WHERE (mots_cles_texte IS NULL OR mots_cles_texte='') "
. "AND id_observation IN (SELECT id_element_lie FROM cel_mots_cles_obs_liaison)";
$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'] . "'";
$this->bdd->requeter($req);
}
}
}
?>