2119 |
aurelien |
1 |
<?php
|
|
|
2 |
class Generationimages extends Script {
|
|
|
3 |
|
|
|
4 |
protected $bdd;
|
|
|
5 |
protected $parametres_autorises = array(
|
|
|
6 |
'-id' => array(false, '1', 'Identifiants des images à traiter (séparés par des virgules')
|
|
|
7 |
);
|
|
|
8 |
|
|
|
9 |
public function __construct($script_nom, $parametres_cli) {
|
|
|
10 |
parent::__construct($script_nom, $parametres_cli);
|
|
|
11 |
$this->bdd = new Bdd();
|
|
|
12 |
}
|
|
|
13 |
|
|
|
14 |
public function executer() {
|
|
|
15 |
$cmd = $this->getParametre('a');
|
|
|
16 |
switch($cmd) {
|
|
|
17 |
case 'genererMinaturesEnAttente';
|
|
|
18 |
$this->genererMiniaturesEnAttente();
|
|
|
19 |
break;
|
|
|
20 |
case 'genererMinaturesPourId';
|
|
|
21 |
$this->genererMinaturesPourId();
|
|
|
22 |
break;
|
|
|
23 |
default :
|
|
|
24 |
$msg = "Erreur : la commande '$cmd' n'existe pas!\n";
|
|
|
25 |
throw new Exception($msg);
|
|
|
26 |
}
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
private function genererMinaturesPourId() {
|
|
|
30 |
$id = $this->getParametre('id');
|
|
|
31 |
$ids = explode(',',$id);
|
|
|
32 |
if($id == null) {
|
|
|
33 |
echo "le paramètre id doit être un ensemble de nombres séparés par des virgules";
|
|
|
34 |
} else {
|
|
|
35 |
include('ImageRecreation.php');
|
|
|
36 |
$createur_images = new ImageRecreation();
|
|
|
37 |
foreach($ids as $id_image) {
|
|
|
38 |
$createur_images->regenererMiniaturesPourId(array($id_image));
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
private function genererMiniaturesEnAttente() {
|
|
|
44 |
$req = "SELECT id_image FROM cel_images WHERE ".
|
|
|
45 |
"date_creation >= DATE_SUB(NOW(), INTERVAL 15 MINUTE)";
|
|
|
46 |
$images_attente = $this->bdd->recupererTous($req);
|
|
|
47 |
|
|
|
48 |
if(!empty($images_attente)) {
|
|
|
49 |
// iterer sur config pour formats
|
|
|
50 |
include('ImageRecreation.php');
|
|
|
51 |
$createur_images = new ImageRecreation();
|
|
|
52 |
foreach($images_attente as $image) {
|
|
|
53 |
$createur_images->regenererMiniaturesPourId(array($image['id_image']));
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
?>
|