Subversion Repositories eFlore/Applications.cel

Rev

Rev 2414 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2414 Rev 2436
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Génère des miniatures.
4
 * Génère des miniatures.
5
 *
5
 *
6
 * Utilisation :
6
 * Utilisation :
7
 * - Pour ? : <code>/opt/lamp/bin/php cli.php generation_images -a genererMinaturesEnAttente</code>
7
 * - Pour ? : <code>/opt/lamp/bin/php cli.php generation_images -a genererMinaturesEnAttente</code>
8
 * - Pour ? : <code>/opt/lamp/bin/php cli.php generation_images -a genererMinaturesEnAttente</code>
8
 * - Pour ? : <code>/opt/lamp/bin/php cli.php generation_images -a genererMinaturesEnAttente</code>
9
 *
9
 *
10
 * @category   CEL
10
 * @category   CEL
11
 * @package    Scripts
11
 * @package    Scripts
12
 * @subpackage Génération Images
12
 * @subpackage Génération Images
13
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
13
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
14
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
14
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
15
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
15
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
16
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
16
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
17
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
17
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
18
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
18
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
19
 */
19
 */
20
class GenerationImages extends Script {
20
class GenerationImages extends Script {
21
 
21
 
22
	protected $bdd;
22
	protected $bdd;
23
	protected $parametres_autorises = array(
23
	protected $parametres_autorises = array(
24
			'-id' => array(false, '1', 'Identifiants des images à traiter (séparés par des virgules')
24
			'-id' => array(false, '1', 'Identifiants des images à traiter (séparés par des virgules')
25
		);
25
		);
26
 
26
 
27
	public function __construct($script_nom, $parametres_cli) {
27
	public function __construct($script_nom, $parametres_cli) {
28
		parent::__construct($script_nom, $parametres_cli);
28
		parent::__construct($script_nom, $parametres_cli);
29
		$this->bdd = new Bdd();
29
		$this->bdd = new Bdd();
30
	}
30
	}
31
 
31
 
32
	public function executer() {
32
	public function executer() {
33
		$cmd = $this->getParametre('a');
33
		$cmd = $this->getParametre('a');
34
		switch($cmd) {
34
		switch($cmd) {
35
			case 'genererMinaturesEnAttente';
35
			case 'genererMinaturesEnAttente';
36
				$this->genererMiniaturesEnAttente();
36
				$this->genererMiniaturesEnAttente();
37
				break;
37
				break;
38
			case 'genererMinaturesPourId';
38
			case 'genererMinaturesPourId';
39
				$this->genererMinaturesPourId();
39
				$this->genererMinaturesPourId();
40
				break;
40
				break;
41
			default :
41
			default :
42
				$msg = "Erreur : la commande '$cmd' n'existe pas!\n";
42
				$msg = "Erreur : la commande '$cmd' n'existe pas!\n";
43
				throw new Exception($msg);
43
				throw new Exception($msg);
44
		}
44
		}
45
	}
45
	}
46
 
46
 
47
	private function genererMinaturesPourId() {
47
	private function genererMinaturesPourId() {
48
		$id = $this->getParametre('id');
48
		$id = $this->getParametre('id');
49
		$ids = explode(',',$id);
49
		$ids = explode(',',$id);
50
		if ($id == null) {
50
		if ($id == null) {
51
			echo "le paramètre id doit être un ensemble de nombres séparés par des virgules";
51
			echo "le paramètre id doit être un ensemble de nombres séparés par des virgules";
52
		} else {
52
		} else {
53
			include_once dirname(__FILE__).'/bibliotheque/ImageRecreation.php';
53
			include_once dirname(__FILE__).'/bibliotheque/ImageRecreation.php';
54
			$createur_images = new ImageRecreation();
54
			$createur_images = new ImageRecreation();
55
			foreach ($ids as $id_image) {
55
			foreach ($ids as $id_image) {
56
				$createur_images->regenererMiniaturesPourId(array($id_image));
56
				$createur_images->regenererMiniaturesPourId(array($id_image));
57
			}
57
			}
58
		}
58
		}
59
	}
59
	}
60
 
60
 
61
	private function genererMiniaturesEnAttente() {
61
	private function genererMiniaturesEnAttente() {
62
		$req = "SELECT id_image FROM cel_images WHERE ".
62
		$requete = 'SELECT id_image '.
-
 
63
			'FROM cel_images '.
63
			"date_creation >= DATE_SUB(NOW(), INTERVAL 15 MINUTE)";
64
			'WHERE date_creation >= DATE_SUB(NOW(), INTERVAL 15 MINUTE)';
64
		$images_attente = $this->bdd->recupererTous($req);
65
		$images_attente = $this->bdd->recupererTous($requete);
65
 
66
 
66
		if (!empty($images_attente)) {
67
		if (!empty($images_attente)) {
67
			// iterer sur config pour formats
68
			// iterer sur config pour formats
68
			include_once dirname(__FILE__).'/bibliotheque/ImageRecreation.php';
69
			include_once dirname(__FILE__).'/bibliotheque/ImageRecreation.php';
69
			$createur_images = new ImageRecreation();
70
			$createur_images = new ImageRecreation();
70
			foreach ($images_attente as $image) {
71
			foreach ($images_attente as $image) {
71
				$createur_images->regenererMiniaturesPourId(array($image['id_image']));
72
				$createur_images->regenererMiniaturesPourId(array($image['id_image']));
72
			}
73
			}
73
		}
74
		}
74
	}
75
	}
75
}
76
}