Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 2413 → Rev 2414

/trunk/scripts/modules/generation_images/GenerationImages.php
New file
0,0 → 1,75
<?php
// declare(encoding='UTF-8');
/**
* Génère des miniatures.
*
* Utilisation :
* - Pour ? : <code>/opt/lamp/bin/php cli.php generation_images -a genererMinaturesEnAttente</code>
* - Pour ? : <code>/opt/lamp/bin/php cli.php generation_images -a genererMinaturesEnAttente</code>
*
* @category CEL
* @package Scripts
* @subpackage Génération Images
* @author Mathias CHOUET <mathias@tela-botanica.org>
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
*/
class GenerationImages extends Script {
 
protected $bdd;
protected $parametres_autorises = array(
'-id' => array(false, '1', 'Identifiants des images à traiter (séparés par des virgules')
);
 
public function __construct($script_nom, $parametres_cli) {
parent::__construct($script_nom, $parametres_cli);
$this->bdd = new Bdd();
}
 
public function executer() {
$cmd = $this->getParametre('a');
switch($cmd) {
case 'genererMinaturesEnAttente';
$this->genererMiniaturesEnAttente();
break;
case 'genererMinaturesPourId';
$this->genererMinaturesPourId();
break;
default :
$msg = "Erreur : la commande '$cmd' n'existe pas!\n";
throw new Exception($msg);
}
}
 
private function genererMinaturesPourId() {
$id = $this->getParametre('id');
$ids = explode(',',$id);
if ($id == null) {
echo "le paramètre id doit être un ensemble de nombres séparés par des virgules";
} else {
include_once dirname(__FILE__).'/bibliotheque/ImageRecreation.php';
$createur_images = new ImageRecreation();
foreach ($ids as $id_image) {
$createur_images->regenererMiniaturesPourId(array($id_image));
}
}
}
 
private function genererMiniaturesEnAttente() {
$req = "SELECT id_image FROM cel_images WHERE ".
"date_creation >= DATE_SUB(NOW(), INTERVAL 15 MINUTE)";
$images_attente = $this->bdd->recupererTous($req);
 
if (!empty($images_attente)) {
// iterer sur config pour formats
include_once dirname(__FILE__).'/bibliotheque/ImageRecreation.php';
$createur_images = new ImageRecreation();
foreach ($images_attente as $image) {
$createur_images->regenererMiniaturesPourId(array($image['id_image']));
}
}
}
}