Subversion Repositories eFlore/Applications.cel

Rev

Rev 2095 | Rev 2104 | Go to most recent revision | Details | Compare with Previous | 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;
2095 mathias 21
				case 'viderMotsClesTexteImagesSansMotsCles' :
22
					$this->viderMotsClesTexteImagesSansMotsCles();
23
					break;
24
				case 'viderMotsClesTexteObsSansMotsCles' :
25
					$this->viderMotsClesTexteObsSansMotsCles();
26
					break;
2094 mathias 27
				default :
28
					$msg = "Erreur : la commande '$cmd' n'existe pas!\n".
29
						"Commandes existantes : regenererMotsClesTexteImages, regenererMotsClesTexteObs";
30
					throw new Exception($msg);
31
			}
32
		} catch (Exception $e) {
33
			$this->traiterErreur($e->getMessage());
34
		}
35
	}
36
 
37
	// Régénère le champ "mots_cles_texte" pour toutes les images ayant des mots clés mais ayant ce champ
38
	// vide, suite à une erreur
39
	protected function regenererMotsClesTexteImages() {
40
		$req = "SELECT id_image FROM cel_images WHERE (mots_cles_texte IS NULL OR mots_cles_texte='') "
41
			. "AND id_image IN (SELECT id_element_lie FROM cel_mots_cles_images_liaison)";
42
		$res = $this->bdd->recupererTous($req);
43
		echo count($res) . " images trouvées\n";
44
		foreach ($res as $image) {
45
			$req = "UPDATE cel_images SET mots_cles_texte = (SELECT GROUP_CONCAT(mot_cle) FROM cel_arbre_mots_cles_images cm "
46
				. "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'] . "') "
47
				. "WHERE id_image = '" . $image['id_image'] . "'";
48
			$this->bdd->requeter($req);
49
		}
50
	}
51
 
52
	// Régénère le champ "mots_cles_texte" pour toutes les observations ayant des mots clés mais ayant ce champ
53
	// vide, suite à une erreur
54
	protected function regenererMotsClesTexteObs() {
55
		$req = "SELECT id_observation FROM cel_obs WHERE (mots_cles_texte IS NULL OR mots_cles_texte='') "
56
			. "AND id_observation IN (SELECT id_element_lie FROM cel_mots_cles_obs_liaison)";
57
		$res = $this->bdd->recupererTous($req);
58
		echo count($res) . " observations trouvées\n";
59
		foreach ($res as $image) {
60
			$req = "UPDATE cel_obs SET mots_cles_texte = (SELECT GROUP_CONCAT(mot_cle) FROM cel_arbre_mots_cles_obs cm "
61
			. "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'] . "') "
62
				. "WHERE id_observation = '" . $image['id_observation'] . "'";
63
			$this->bdd->requeter($req);
64
		}
65
	}
2095 mathias 66
 
67
	// Vide le champ "mots_cles_texte" pour toutes les images n'ayant aucun mot clé
68
	protected function viderMotsClesTexteImagesSansMotsCles() {
69
		$req = "UPDATE cel_images SET mots_cles_texte = NULL WHERE id_image NOT IN (SELECT id_element_lie FROM cel_mots_cles_images_liaison)";
70
		$res = $this->bdd->requeter($req);
71
		echo "$res images mises à jour\n";
72
	}
73
 
74
	// Vide le champ "mots_cles_texte" pour toutes les obs n'ayant aucun mot clé
75
	protected function viderMotsClesTexteObsSansMotsCles() {
76
		$req = "UPDATE cel_obs SET mots_cles_texte = NULL WHERE id_observation NOT IN (SELECT id_element_lie FROM cel_mots_cles_obs_liaison)";
77
		$res = $this->bdd->requeter($req);
78
		echo "$res observations mises à jour\n";
79
	}
2094 mathias 80
}
81
?>