Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2094 mathias 1
<?php
2
class Maintenance extends Script {
3
 
4
	protected $bdd;
5
 
6
	public function __construct($script_nom, $parametres_cli) {
7
		parent::__construct($script_nom, $parametres_cli);
8
		$this->bdd = new Bdd();
9
	}
10
 
11
	public function executer() {
12
		$cmd = $this->getParametre('a');
13
		try {
14
			switch ($cmd) {
15
				case 'regenererMotsClesTexteObs' :
16
					$this->regenererMotsClesTexteObs();
17
					break;
18
				case 'regenererMotsClesTexteImages' :
19
					$this->regenererMotsClesTexteImages();
20
					break;
21
				default :
22
					$msg = "Erreur : la commande '$cmd' n'existe pas!\n".
23
						"Commandes existantes : regenererMotsClesTexteImages, regenererMotsClesTexteObs";
24
					throw new Exception($msg);
25
			}
26
		} catch (Exception $e) {
27
			$this->traiterErreur($e->getMessage());
28
		}
29
	}
30
 
31
	// Régénère le champ "mots_cles_texte" pour toutes les images ayant des mots clés mais ayant ce champ
32
	// vide, suite à une erreur
33
	protected function regenererMotsClesTexteImages() {
34
		$req = "SELECT id_image FROM cel_images WHERE (mots_cles_texte IS NULL OR mots_cles_texte='') "
35
			. "AND id_image IN (SELECT id_element_lie FROM cel_mots_cles_images_liaison)";
36
		$res = $this->bdd->recupererTous($req);
37
		echo count($res) . " images trouvées\n";
38
		foreach ($res as $image) {
39
			$req = "UPDATE cel_images SET mots_cles_texte = (SELECT GROUP_CONCAT(mot_cle) FROM cel_arbre_mots_cles_images cm "
40
				. "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'] . "') "
41
				. "WHERE id_image = '" . $image['id_image'] . "'";
42
			$this->bdd->requeter($req);
43
		}
44
	}
45
 
46
	// Régénère le champ "mots_cles_texte" pour toutes les observations ayant des mots clés mais ayant ce champ
47
	// vide, suite à une erreur
48
	protected function regenererMotsClesTexteObs() {
49
		$req = "SELECT id_observation FROM cel_obs WHERE (mots_cles_texte IS NULL OR mots_cles_texte='') "
50
			. "AND id_observation IN (SELECT id_element_lie FROM cel_mots_cles_obs_liaison)";
51
		$res = $this->bdd->recupererTous($req);
52
		echo count($res) . " observations trouvées\n";
53
		foreach ($res as $image) {
54
			$req = "UPDATE cel_obs SET mots_cles_texte = (SELECT GROUP_CONCAT(mot_cle) FROM cel_arbre_mots_cles_obs cm "
55
			. "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'] . "') "
56
				. "WHERE id_observation = '" . $image['id_observation'] . "'";
57
			$this->bdd->requeter($req);
58
		}
59
	}
60
}
61
?>