| Line 1... |
Line 1... |
| 1 |
<?php
|
1 |
<?php
|
| - |
|
2 |
// declare(encoding='UTF-8');
|
| - |
|
3 |
/**
|
| - |
|
4 |
* Script de migration des Images de la version 1 de la base de données du CEL à la v2.
|
| 2 |
|
5 |
*
|
| - |
|
6 |
* @category php 5.2
|
| - |
|
7 |
* @package Cel/Scripts
|
| - |
|
8 |
* @author Aurélien PERONNET <aurelien@tela-botanica.org>
|
| - |
|
9 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
| - |
|
10 |
* @copyright Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
|
| - |
|
11 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
| - |
|
12 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
| - |
|
13 |
* @version $Id$
|
| - |
|
14 |
*/
|
| 3 |
class MigrationImages extends Cel {
|
15 |
class MigrationImages extends Cel {
|
| Line 4... |
Line -... |
| 4 |
|
- |
|
| 5 |
public static $bdd_cel_migration;
|
16 |
|
| 6 |
public static $bdd_utilisateurs;
|
- |
|
| 7 |
|
17 |
const dry_run = false;
|
| 8 |
const truncate = true; //Doit on vider les tables de destination ?
|
- |
|
| 9 |
|
18 |
const truncate = true; //Doit on vider les tables de destination ?
|
| 10 |
const separateur_champs_metadonnees = ';';
|
19 |
const separateur_champs_metadonnees = ';';
|
| Line -... |
Line 20... |
| - |
|
20 |
const separateur_valeurs_metadonnees = ':';
|
| - |
|
21 |
|
| 11 |
const separateur_valeurs_metadonnees = ':';
|
22 |
public static $bdd_cel_migration;
|
| - |
|
23 |
public static $bdd_utilisateurs;
|
| - |
|
24 |
private $cle_id_metadonnees = array();
|
| - |
|
25 |
private $tableau_utilisateurs = array();
|
| Line 12... |
Line 26... |
| 12 |
|
26 |
private $tableau_observations = array();
|
| 13 |
private $id_cle_metadonnees = array();
|
27 |
private $tableau_mots_cles = array();
|
| 14 |
|
28 |
|
| 15 |
/** Tableau associatif permettant de stocker l'avancement dans une boucle.
|
29 |
/** Tableau associatif permettant de stocker l'avancement dans une boucle.
|
| 16 |
* La clé est un md5 du message à afficher au démarrage de la boucle.
|
30 |
* La clé est un md5 du message à afficher au démarrage de la boucle.
|
| Line 17... |
Line -... |
| 17 |
* @var array
|
- |
|
| 18 |
*/
|
- |
|
| 19 |
private static $avancement = array();
|
- |
|
| 20 |
|
- |
|
| 21 |
const dry_run = false;
|
- |
|
| 22 |
|
- |
|
| 23 |
private $tableau_utilisateurs = array();
|
31 |
* @var array
|
| 24 |
private $tableau_observations = array();
|
32 |
*/
|
| 25 |
private $tableau_mots_cles = array();
|
33 |
private static $avancement = array();
|
| 26 |
|
34 |
|
| 27 |
private $tableau_nouveau_ancien = array(
|
35 |
private $tableau_nouveau_ancien = array(
|
| Line 34... |
Line 42... |
| 34 |
'hauteur' => 'ci_meta_height',
|
42 |
'hauteur' => 'ci_meta_height',
|
| 35 |
'largeur' => 'ci_meta_width',
|
43 |
'largeur' => 'ci_meta_width',
|
| 36 |
'appareil_fabriquant' => 'ci_meta_make',
|
44 |
'appareil_fabriquant' => 'ci_meta_make',
|
| 37 |
'appareil_modele' => 'ci_meta_model',
|
45 |
'appareil_modele' => 'ci_meta_model',
|
| 38 |
'date_prise_de_vue' => 'ci_meta_date_time',
|
46 |
'date_prise_de_vue' => 'ci_meta_date_time',
|
| 39 |
'note_qualite' => 'ci_note_image',
|
47 |
'note_qualite' => 'traiterNoteImage',
|
| 40 |
'mots_cles_texte' => 'traiterMotsClesTexte',
|
48 |
'mots_cles_texte' => 'ci_meta_mots_cles',
|
| 41 |
'commentaire' => 'ci_meta_comment',
|
49 |
'commentaire' => 'ci_meta_comment',
|
| 42 |
'nom_original' => 'ci_nom_original',
|
50 |
'nom_original' => 'ci_nom_original',
|
| 43 |
'md5' => 'ci_md5',
|
51 |
'md5' => 'ci_md5',
|
| 44 |
'meta_exif' => 'traiterExif',
|
52 |
'meta_exif' => 'traiterExif',
|
| 45 |
'meta_iptc' => 'traiterIptc',
|
53 |
'meta_iptc' => 'traiterIptc',
|
| Line 104... |
Line 112... |
| 104 |
private $champs_divers_non_gardes = array(
|
112 |
private $champs_divers_non_gardes = array(
|
| 105 |
'ci_publiable_eflore',
|
113 |
'ci_publiable_eflore',
|
| 106 |
'ci_meta_mots_cles'
|
114 |
'ci_meta_mots_cles'
|
| 107 |
);
|
115 |
);
|
| Line -... |
Line 564... |
| - |
|
564 |
);
|
| - |
|
565 |
|
| - |
|
566 |
private $ids_tags_iptc = array(
|
| - |
|
567 |
'1#000' => array('id' => '0', 'tag' => 'ApplicationRecordVersion', 'categorie' => 'EnvelopeRecord'),
|
| - |
|
568 |
'1#090' => array('id' => '90', 'tag' => 'CodedCharacterSet', 'categorie' => 'EnvelopeRecord'),
|
| - |
|
569 |
'2#003' => array('id' => '3', 'tag' => 'ObjectTypeReference', 'categorie' => 'ApplicationRecord'),
|
| - |
|
570 |
'2#004' => array('id' => '4', 'tag' => 'ObjectAttributeReference', 'categorie' => 'ApplicationRecord'),
|
| - |
|
571 |
'2#005' => array('id' => '5', 'tag' => 'ObjectName', 'categorie' => 'ApplicationRecord'),
|
| - |
|
572 |
'2#007' => array('id' => '7', 'tag' => 'EditStatus', 'categorie' => 'ApplicationRecord'),
|
| - |
|
573 |
'2#008' => array('id' => '8', 'tag' => 'EditorialUpdate', 'categorie' => 'ApplicationRecord'),
|
| - |
|
574 |
'2#010' => array('id' => '10', 'tag' => 'Urgency', 'categorie' => 'ApplicationRecord'),
|
| - |
|
575 |
'2#012' => array('id' => '12', 'tag' => 'SubjectReference', 'categorie' => 'ApplicationRecord'),
|
| - |
|
576 |
'Category' => array('id' => '15', 'tag' => 'Category', 'categorie' => 'ApplicationRecord'),
|
| - |
|
577 |
'2#015' => array('id' => '15', 'tag' => 'Category', 'categorie' => 'ApplicationRecord'),
|
| - |
|
578 |
'2#020' => array('id' => '20', 'tag' => 'SupplementalCategories', 'categorie' => 'ApplicationRecord'),
|
| - |
|
579 |
'2#022' => array('id' => '22', 'tag' => 'FixtureIdentifier', 'categorie' => 'ApplicationRecord'),
|
| - |
|
580 |
'MotsCles' => array('id' => '25', 'tag' => 'Keywords', 'categorie' => 'ApplicationRecord'),
|
| - |
|
581 |
'2#026' => array('id' => '26', 'tag' => 'ContentLocationCode', 'categorie' => 'ApplicationRecord'),
|
| - |
|
582 |
'2#027' => array('id' => '27', 'tag' => 'ContentLocationName', 'categorie' => 'ApplicationRecord'),
|
| - |
|
583 |
'2#030' => array('id' => '30', 'tag' => 'ReleaseDate', 'categorie' => 'ApplicationRecord'),
|
| - |
|
584 |
'2#035' => array('id' => '35', 'tag' => 'ReleaseTime', 'categorie' => 'ApplicationRecord'),
|
| - |
|
585 |
'2#037' => array('id' => '37', 'tag' => 'ExpirationDate', 'categorie' => 'ApplicationRecord'),
|
| - |
|
586 |
'2#038' => array('id' => '38', 'tag' => 'ExpirationTime', 'categorie' => 'ApplicationRecord'),
|
| - |
|
587 |
'2#040' => array('id' => '40', 'tag' => 'SpecialInstructions', 'categorie' => 'ApplicationRecord'),
|
| - |
|
588 |
'2#042' => array('id' => '42', 'tag' => 'ActionAdvised', 'categorie' => 'ApplicationRecord'),
|
| - |
|
589 |
'2#045' => array('id' => '45', 'tag' => 'ReferenceService', 'categorie' => 'ApplicationRecord'),
|
| - |
|
590 |
'2#047' => array('id' => '47', 'tag' => 'ReferenceDate', 'categorie' => 'ApplicationRecord'),
|
| - |
|
591 |
'2#050' => array('id' => '50', 'tag' => 'ReferenceNumber', 'categorie' => 'ApplicationRecord'),
|
| - |
|
592 |
'2#055' => array('id' => '55', 'tag' => 'DateCreated', 'categorie' => 'ApplicationRecord'),
|
| - |
|
593 |
'2#060' => array('id' => '60', 'tag' => 'TimeCreated', 'categorie' => 'ApplicationRecord'),
|
| - |
|
594 |
'2#062' => array('id' => '62', 'tag' => 'DigitalCreationDate', 'categorie' => 'ApplicationRecord'),
|
| - |
|
595 |
'2#063' => array('id' => '63', 'tag' => 'DigitalCreationTime', 'categorie' => 'ApplicationRecord'),
|
| - |
|
596 |
'2#065' => array('id' => '65', 'tag' => 'OriginatingProgram', 'categorie' => 'ApplicationRecord'),
|
| 131 |
}
|
597 |
'2#070' => array('id' => '70', 'tag' => 'ProgramVersion', 'categorie' => 'ApplicationRecord'),
|
| - |
|
598 |
'2#075' => array('id' => '75', 'tag' => 'ObjectCycle', 'categorie' => 'ApplicationRecord'),
|
| - |
|
599 |
'ByLine' => array('id' => '80', 'tag' => 'By-line', 'categorie' => 'ApplicationRecord'),
|
| - |
|
600 |
'ByLineTitle' => array('id' => '85', 'tag' => 'By-lineTitle', 'categorie' => 'ApplicationRecord'),
|
| - |
|
601 |
'City' => array('id' => '90', 'tag' => 'City', 'categorie' => 'ApplicationRecord'),
|
| - |
|
602 |
'SubLocation' => array('id' => '92', 'tag' => 'Sub-location', 'categorie' => 'ApplicationRecord'),
|
| - |
|
603 |
'ProvinceState' => array('id' => '95', 'tag' => 'Province-State', 'categorie' => 'ApplicationRecord'),
|
| - |
|
604 |
'CountryPrimaryLocationCode' => array('id' => '100', 'tag' => 'Country-PrimaryLocationCode', 'categorie' => 'ApplicationRecord'),
|
| - |
|
605 |
'CountryName' => array('id' => '101', 'tag' => 'Country-PrimaryLocationName', 'categorie' => 'ApplicationRecord'),
|
| - |
|
606 |
'2#103' => array('id' => '103', 'tag' => 'OriginalTransmissionReference', 'categorie' => 'ApplicationRecord'),
|
| - |
|
607 |
'Headline' => array('id' => '105', 'tag' => 'Headline', 'categorie' => 'ApplicationRecord'),
|
| - |
|
608 |
'Credit' => array('id' => '110', 'tag' => 'Credit', 'categorie' => 'ApplicationRecord'),
|
| - |
|
609 |
'2#115' => array('id' => '115', 'tag' => 'Source', 'categorie' => 'ApplicationRecord'),
|
| - |
|
610 |
'CopyrightNotice' => array('id' => '116', 'tag' => 'CopyrightNotice', 'categorie' => 'ApplicationRecord'),
|
| - |
|
611 |
'Contact' => array('id' => '118', 'tag' => 'Contact', 'categorie' => 'ApplicationRecord'),
|
| - |
|
612 |
'2#120' => array('id' => '120', 'tag' => 'Caption-Abstract', 'categorie' => 'ApplicationRecord'),
|
| - |
|
613 |
'2#121' => array('id' => '121', 'tag' => 'LocalCaption', 'categorie' => 'ApplicationRecord'),
|
| - |
|
614 |
'2#122' => array('id' => '122', 'tag' => 'Writer-Editor', 'categorie' => 'ApplicationRecord'),
|
| - |
|
615 |
'2#125' => array('id' => '125', 'tag' => 'RasterizedCaption', 'categorie' => 'ApplicationRecord'),
|
| - |
|
616 |
'2#130' => array('id' => '130', 'tag' => 'ImageType', 'categorie' => 'ApplicationRecord'),
|
| - |
|
617 |
'2#131' => array('id' => '131', 'tag' => 'ImageOrientation', 'categorie' => 'ApplicationRecord'),
|
| - |
|
618 |
'2#135' => array('id' => '135', 'tag' => 'LanguageIdentifier', 'categorie' => 'ApplicationRecord'),
|
| - |
|
619 |
'2#150' => array('id' => '150', 'tag' => 'AudioType', 'categorie' => 'ApplicationRecord'),
|
| - |
|
620 |
'2#151' => array('id' => '151', 'tag' => 'AudioSamplingRate', 'categorie' => 'ApplicationRecord'),
|
| - |
|
621 |
'2#152' => array('id' => '152', 'tag' => 'AudioSamplingResolution', 'categorie' => 'ApplicationRecord'),
|
| - |
|
622 |
'2#153' => array('id' => '153', 'tag' => 'AudioDuration', 'categorie' => 'ApplicationRecord'),
|
| - |
|
623 |
'2#154' => array('id' => '154', 'tag' => 'AudioOutcue', 'categorie' => 'ApplicationRecord'),
|
| - |
|
624 |
'2#184' => array('id' => '184', 'tag' => 'JobID', 'categorie' => 'ApplicationRecord'),
|
| - |
|
625 |
'2#185' => array('id' => '185', 'tag' => 'MasterDocumentID', 'categorie' => 'ApplicationRecord'),
|
| - |
|
626 |
'2#186' => array('id' => '186', 'tag' => 'ShortDocumentID', 'categorie' => 'ApplicationRecord'),
|
| - |
|
627 |
'2#187' => array('id' => '187', 'tag' => 'UniqueDocumentID', 'categorie' => 'ApplicationRecord'),
|
| - |
|
628 |
'2#188' => array('id' => '188', 'tag' => 'OwnerID', 'categorie' => 'ApplicationRecord'),
|
| - |
|
629 |
'2#200' => array('id' => '200', 'tag' => 'ObjectPreviewFileFormat', 'categorie' => 'ApplicationRecord'),
|
| 132 |
|
630 |
'2#201' => array('id' => '201', 'tag' => 'ObjectPreviewFileVersion', 'categorie' => 'ApplicationRecord'),
|
| - |
|
631 |
'2#202' => array('id' => '202', 'tag' => 'ObjectPreviewData', 'categorie' => 'ApplicationRecord'),
|
| - |
|
632 |
'2#221' => array('id' => '221', 'tag' => 'Prefs', 'categorie' => 'ApplicationRecord'),
|
| - |
|
633 |
'2#225' => array('id' => '225', 'tag' => 'ClassifyState', 'categorie' => 'ApplicationRecord'),
|
| - |
|
634 |
'2#228' => array('id' => '228', 'tag' => 'SimilarityIndex', 'categorie' => 'ApplicationRecord'),
|
| - |
|
635 |
'2#230' => array('id' => '230', 'tag' => 'DocumentNotes', 'categorie' => 'ApplicationRecord'),
|
| - |
|
636 |
'2#231' => array('id' => '231', 'tag' => 'DocumentHistory', 'categorie' => 'ApplicationRecord'),
|
| - |
|
637 |
'2#232' => array('id' => '232', 'tag' => 'ExifCameraInfo', 'categorie' => 'ApplicationRecord'),
|
| - |
|
638 |
'2#242' => array('id' => '242', 'tag' => 'Unknown242', 'categorie' => 'Unknown'),
|
| 133 |
echo str_repeat(chr(8), (strlen((string) $actuel) - $passage));
|
639 |
'2#254' => array('id' => '254', 'tag' => 'Unknown254', 'categorie' => 'Unknown'),
|
| 134 |
echo $actuel++;
|
- |
|
| Line 135... |
Line 640... |
| 135 |
}
|
640 |
'2#255' => array('id' => '255', 'tag' => 'CatalogSets', 'categorie' => 'ApplicationRecord')
|
| 136 |
}
|
641 |
);
|
| 137 |
|
642 |
|
| 138 |
/**
|
643 |
/**
|
| 139 |
* Méthode appelée avec une requête de type GET.
|
- |
|
| 140 |
*/
|
644 |
* Méthode appelée avec une requête de type GET.
|
| 141 |
public function getElement($params) {
|
645 |
*/
|
| 142 |
|
646 |
public function getElement($params) {
|
| 143 |
if(!isset($this->config['database_cel']['database_migration']) || $this->config['database_cel']['database_migration'] == '') {
|
647 |
if (!isset($this->config['database_cel']['database_migration']) || $this->config['database_cel']['database_migration'] == '') {
|
| 144 |
echo 'Attention la variable de configuration database_migration dans la section database_cel, contenant la base de données d\'arrivée, doit être remplie '."\n";
|
- |
|
| 145 |
exit;
|
648 |
echo 'Attention la variable de configuration database_migration dans la section database_cel, contenant la base de données d\'arrivée, doit être remplie '."\n";
|
| 146 |
}
|
649 |
exit;
|
| 147 |
|
650 |
}
|
| 148 |
if(!isset($this->config['database_ident']['database']) || $this->config['database_ident']['database'] == '') {
|
651 |
if (!isset($this->config['database_ident']['database']) || $this->config['database_ident']['database'] == '') {
|
| Line 149... |
Line 652... |
| 149 |
echo 'Attention la variable de configuration database dans la section database_ident, contenant la base de données utilisateurs, doit être remplie '."\n";
|
652 |
echo 'Attention la variable de configuration database dans la section database_ident, contenant la base de données utilisateurs, doit être remplie '."\n";
|
| 150 |
exit;
|
653 |
exit;
|
| Line 151... |
Line 654... |
| 151 |
}
|
654 |
}
|
| Line 152... |
Line 655... |
| 152 |
|
655 |
|
| 153 |
self::$bdd_cel_migration = $this->config['database_cel']['database_migration'];
|
656 |
self::$bdd_cel_migration = $this->config['database_cel']['database_migration'];
|
| 154 |
self::$bdd_utilisateurs = $this->config['database_ident']['database'];
|
657 |
self::$bdd_utilisateurs = $this->config['database_ident']['database'];
|
| 155 |
|
658 |
|
| Line 174... |
Line 677... |
| 174 |
|
677 |
|
| 175 |
echo "-------------------------------------------------------------------\n\n";
|
678 |
echo "-------------------------------------------------------------------\n\n";
|
| 176 |
echo " ETAPE 1. Paramétrage ... \n\n";
|
679 |
echo " ETAPE 1. Paramétrage ... \n\n";
|
| 177 |
echo "-------------------------------------------------------------------\n\n";
|
680 |
echo "-------------------------------------------------------------------\n\n";
|
| 178 |
$this->getUtilisateurs();
|
- |
|
| 179 |
$this->getMotsCles();
|
681 |
$this->getUtilisateurs();
|
| Line 180... |
Line 682... |
| 180 |
$this->getObservations();
|
682 |
$this->getObservations();
|
| 181 |
|
683 |
|
| 182 |
echo "-------------------------------------------------------------------\n\n";
|
684 |
echo "-------------------------------------------------------------------\n\n";
|
| 183 |
echo " ETAPE 2. Migration des images ... \n\n";
|
685 |
echo " ETAPE 2. Migration des images ... \n\n";
|
| - |
|
686 |
echo "-------------------------------------------------------------------\n\n";
|
| 184 |
echo "-------------------------------------------------------------------\n\n";
|
687 |
$this->migrerImages();
|
| Line 185... |
Line 688... |
| 185 |
$this->migrerImages();
|
688 |
$this->ordonnerImages();
|
| 186 |
echo "\n"."\n"."\n";
|
689 |
echo "\n"."\n"."\n";
|
| 187 |
|
690 |
|
| Line 194... |
Line 697... |
| 194 |
|
697 |
|
| 195 |
private function getUtilisateurs() {
|
698 |
private function getUtilisateurs() {
|
| 196 |
echo "\n-------------------------------------------------------------------\n";
|
699 |
echo "\n-------------------------------------------------------------------\n";
|
| Line 197... |
Line 700... |
| 197 |
echo "--SELECTION DES UTILISATEURS---------------------------------------\n\n";
|
700 |
echo "--SELECTION DES UTILISATEURS---------------------------------------\n\n";
|
| - |
|
701 |
|
| 198 |
|
702 |
$requete = 'SELECT U_ID as id, U_MAIL as mail, U_NAME as nom, U_SURNAME as prenom, U_PASSWD as pass '.
|
| Line 199... |
Line 703... |
| 199 |
$requete_selection_utilisateurs = 'SELECT U_ID as id, U_MAIL as mail, U_NAME as nom, U_SURNAME as prenom, U_PASSWD as pass FROM '.self::$bdd_utilisateurs.'.annuaire_tela';
|
703 |
'FROM '.self::$bdd_utilisateurs.'.annuaire_tela';
|
| 200 |
$tableau_utilisateurs = $this->executerRequete($requete_selection_utilisateurs);
|
704 |
$tableau_utilisateurs = $this->executerRequete($requete);
|
| 201 |
|
705 |
|
| Line 202... |
Line 706... |
| 202 |
foreach( $tableau_utilisateurs as &$utilisateur) {
|
706 |
foreach ($tableau_utilisateurs as &$utilisateur) {
|
| 203 |
$this->tableau_utilisateurs[$utilisateur['mail']] = $utilisateur;
|
707 |
$this->tableau_utilisateurs[$utilisateur['mail']] = $utilisateur;
|
| 204 |
}
|
708 |
}
|
| Line 205... |
Line -... |
| 205 |
|
- |
|
| 206 |
echo sizeof($this->tableau_utilisateurs)." utilisateurs sélectionnés";
|
- |
|
| 207 |
echo "\n-----------------------------------------------------------------OK\n";
|
- |
|
| 208 |
}
|
- |
|
| 209 |
|
- |
|
| 210 |
private function getMotsCles() {
|
- |
|
| 211 |
echo "\n-------------------------------------------------------------------\n";
|
- |
|
| 212 |
echo "--SELECTION DES MOTS-CLES -----------------------------------------\n\n";
|
- |
|
| 213 |
|
- |
|
| 214 |
$requete_selection_mots_cles = 'SELECT cmc_id_proprietaire as id_utilisateur, cmc_id_mot_cle_utilisateur as id_mot_cle, cmc_mot_cle as mot_cle FROM cel_mots_cles_obs';
|
- |
|
| 215 |
$tableau_mots_cles = $this->executerRequete($requete_selection_mots_cles);
|
- |
|
| 216 |
|
- |
|
| 217 |
foreach( $tableau_mots_cles as &$mot_cle) {
|
- |
|
| 218 |
$this->tableau_mots_cles[$mot_cle['id_utilisateur']][$mot_cle['id_mot_cle']] = $mot_cle;
|
- |
|
| 219 |
}
|
- |
|
| 220 |
|
- |
|
| 221 |
echo sizeof($this->tableau_mots_cles)." mots-clés sélectionnés";
|
709 |
|
| 222 |
echo "\n-----------------------------------------------------------------OK\n";
|
- |
|
| 223 |
|
710 |
echo sizeof($this->tableau_utilisateurs)." utilisateurs sélectionnés";
|
| 224 |
}
|
- |
|
| 225 |
|
711 |
echo "\n-----------------------------------------------------------------OK\n";
|
| 226 |
private function getObservations() {
|
712 |
}
|
| 227 |
|
713 |
|
| - |
|
714 |
private function getObservations() {
|
| Line 228... |
Line 715... |
| 228 |
$pas = 5000;
|
715 |
$pas = 5000;
|
| 229 |
|
716 |
$nObs = 'SELECT COUNT(*) AS nb FROM cel_inventory';
|
| 230 |
$nObs = "SELECT COUNT(*) AS nb FROM cel_inventory";
|
717 |
$resultatNbObs = $this->executerRequete($nObs);
|
| 231 |
$resultatNbObs = $this->executerRequete($nObs);
|
718 |
$nbObs = $resultatNbObs[0]['nb'];
|
| 232 |
$nbObs = $resultatNbObs[0]['nb'];
|
719 |
$maxLimite = $nbObs + $pas;
|
| 233 |
|
720 |
|
| 234 |
for ($i = 0; $i < 230000; $i += $pas ) {
|
- |
|
| 235 |
$requete_selection_observations = 'SELECT id, ordre, identifiant FROM cel_inventory LIMIT '.$i.", $pas";
|
721 |
for ($i = 0; $i < $maxLimite; $i += $pas ) {
|
| 236 |
$tableau_observations = $this->executerRequete($requete_selection_observations);
|
722 |
$requete_selection_observations = 'SELECT id, ordre, identifiant FROM cel_inventory LIMIT '.$i.", $pas";
|
| 237 |
foreach($tableau_observations as &$obs) {
|
- |
|
| 238 |
$this->tableau_observations[$obs['identifiant']][$obs['ordre']] = $obs['id'];
|
723 |
$tableau_observations = $this->executerRequete($requete_selection_observations);
|
| 239 |
}
|
724 |
foreach ($tableau_observations as &$obs) {
|
| Line 240... |
Line -... |
| 240 |
|
- |
|
| 241 |
$this->afficherAvancement('Selection des observations (par '.$pas.' )', $nbObs);
|
- |
|
| 242 |
}
|
- |
|
| 243 |
|
- |
|
| 244 |
echo "\n\n";
|
- |
|
| 245 |
}
|
- |
|
| 246 |
|
- |
|
| 247 |
public function executerRequeteSimple($requete) {
|
- |
|
| 248 |
// Fonction de commodité pour afficher les requetes au lieu de les executer
|
- |
|
| 249 |
if (self::dry_run) {
|
- |
|
| 250 |
echo str_replace('),','),'."\n", $requete)."\n";
|
725 |
$this->tableau_observations[$obs['identifiant']][$obs['ordre']] = $obs['id'];
|
| 251 |
return true;
|
- |
|
| 252 |
} else {
|
726 |
}
|
| 253 |
return parent::executerRequeteSimple($requete);
|
727 |
$this->afficherAvancement('Selection des observations (par '.$pas.' )');
|
| 254 |
}
|
- |
|
| Line 255... |
Line 728... |
| 255 |
}
|
728 |
}
|
| 256 |
|
729 |
echo "\n\n";
|
| 257 |
private function migrerImages() {
|
730 |
}
|
| 258 |
|
731 |
|
| - |
|
732 |
private function migrerImages() {
|
| Line 259... |
Line 733... |
| 259 |
$debut = 0;
|
733 |
$debut = 0;
|
| 260 |
$pas = 200;
|
734 |
$pas = 100;
|
| - |
|
735 |
|
| 261 |
$fin = 150000;
|
736 |
//Selectionner le nombre d'images
|
| Line 262... |
Line 737... |
| 262 |
|
737 |
$requeteNbImg = "SELECT COUNT(*) as nb FROM cel_images";
|
| 263 |
//Selectionner le nombre d'images
|
- |
|
| 264 |
$requeteNbImg = "SELECT COUNT(*) as nb FROM cel_images";
|
738 |
$resultatNbImg = $this->executerRequete($requeteNbImg);
|
| 265 |
$resultatNbImg = $this->executerRequete($requeteNbImg);
|
739 |
$fin = $resultatNbImg[0]['nb'];
|
| 266 |
$fin = $resultatNbImg[0]['nb'];
|
740 |
$maxLimite = $fin + $pas;
|
| 267 |
|
741 |
|
| 268 |
for ($i = $debut; $i <= $fin ; $i += $pas) {
|
- |
|
| 269 |
$requete_selection_images = 'SELECT * FROM cel_images '.
|
- |
|
| 270 |
'ORDER BY ci_id_image ASC LIMIT '.$i.','.$pas;
|
742 |
for ($i = $debut; $i <= $maxLimite ; $i += $pas) {
|
| Line 271... |
Line 743... |
| 271 |
|
743 |
$requete = 'SELECT * '.
|
| 272 |
$images = @$this->requeter($requete_selection_images);
|
- |
|
| 273 |
|
744 |
'FROM cel_images '.
|
| 274 |
$requete_insertion_images = 'INSERT INTO '.self::$bdd_cel_migration.'.cel_images (';
|
- |
|
| 275 |
foreach ($this->tableau_nouveau_ancien as $nouveau_champ => $ancien_champ) {
|
745 |
'ORDER BY ci_id_image ASC LIMIT '.$i.','.$pas;
|
| 276 |
$requete_insertion_images .= $nouveau_champ.',';
|
- |
|
| 277 |
}
|
746 |
|
| 278 |
$requete_insertion_images = rtrim($requete_insertion_images, ',');
|
- |
|
| 279 |
|
747 |
$images = @$this->requeter($requete);
|
| 280 |
$requete_insertion_images = $requete_insertion_images.') VALUES ';
|
748 |
$requete = 'INSERT INTO '.self::$bdd_cel_migration.'.cel_images (';
|
| 281 |
|
749 |
foreach ($this->tableau_nouveau_ancien as $nouveau_champ => $ancien_champ) {
|
| Line 282... |
Line 750... |
| 282 |
if (is_array($images)) {
|
750 |
$requete .= $nouveau_champ.',';
|
| 283 |
|
751 |
}
|
| Line 284... |
Line 752... |
| 284 |
$nb_images_a_traiter = count($images);
|
752 |
$requete = rtrim($requete, ',').') VALUES ';
|
| 285 |
|
753 |
|
| - |
|
754 |
if (is_array($images)) {
|
| 286 |
foreach($images as $image) {
|
755 |
$nb_images_a_traiter = count($images);
|
| 287 |
|
756 |
foreach ($images as $image) {
|
| 288 |
$nouvelle_image = $this->traiterLigneImage($image);
|
757 |
$nouvelle_image = $this->traiterLigneImage($image);
|
| 289 |
|
758 |
$nouvelle_image = array_map(array($this, 'protegerSiNonNull'), $nouvelle_image);
|
| Line 290... |
Line 759... |
| 290 |
$nouvelle_image = array_map(array($this,'proteger'),$nouvelle_image);
|
759 |
$requete .= '('.join(',', array_values($nouvelle_image)).'),';
|
| 291 |
$requete_insertion_images .= '('.join(',',array_values($nouvelle_image)).'),';
|
760 |
}
|
| 292 |
}
|
761 |
|
| 293 |
|
762 |
$requete = rtrim($requete, ',');
|
| 294 |
$requete_insertion_images = rtrim($requete_insertion_images, ',');
|
763 |
$migration_images = $this->executerRequeteSimple($requete);
|
| 295 |
$migration_images = $this->executer($requete_insertion_images);
|
764 |
|
| Line 296... |
Line -... |
| 296 |
|
- |
|
| 297 |
if (!$migration_images) {
|
- |
|
| 298 |
echo 'la migration des images '.$i.' à '.($i+$nb_images_a_traiter).' a échoué '."\n";
|
- |
|
| 299 |
} else {
|
- |
|
| 300 |
$this->afficherAvancement('Migration des images (par '.$pas.' )', $fin);
|
765 |
if (!$migration_images) {
|
| - |
|
766 |
echo 'la migration des images '.$i.' à '.($i + $nb_images_a_traiter).' a échoué '."\n";
|
| 301 |
}
|
767 |
file_put_contents('/home/jpm/requete.sql', $requete);
|
| 302 |
}
|
768 |
} else {
|
| 303 |
|
769 |
$this->afficherAvancement('Migration des images (par '.$pas.' )');
|
| 304 |
if(count($images) < $pas) {
|
- |
|
| 305 |
echo "\n---------------------------------------------------------------- OK\n\n";
|
- |
|
| 306 |
return;
|
770 |
}
|
| 307 |
}
|
- |
|
| 308 |
}
|
771 |
}
|
| 309 |
}
|
- |
|
| 310 |
|
- |
|
| 311 |
private function migrerLiaisonsObsImages() {
|
- |
|
| 312 |
$debut = 0;
|
772 |
|
| 313 |
$pas = 500;
|
- |
|
| 314 |
$fin = 50000;
|
- |
|
| 315 |
|
773 |
if (count($images) < $pas) {
|
| 316 |
$liaisons_obs_inexistantes = 0;
|
- |
|
| 317 |
|
774 |
echo "\n---------------------------------------------------------------- OK\n\n";
|
| 318 |
//Selectionner le nombre de liaisons
|
775 |
return;
|
| 319 |
$requeteNbImgObs = "SELECT COUNT(*) as nb FROM cel_obs_images";
|
776 |
}
|
| 320 |
$resultatNbImgObs = $this->executerRequete($requeteNbImgObs);
|
777 |
}
|
| 321 |
$fin = $resultatNbImgObs[0]['nb'];
|
778 |
}
|
| 322 |
|
- |
|
| 323 |
for ($i = $debut; $i <= $fin ; $i += $pas) {
|
779 |
|
| 324 |
|
780 |
/**
|
| 325 |
if($i > $fin) {
|
- |
|
| 326 |
$i = $fin;
|
- |
|
| 327 |
}
|
- |
|
| 328 |
|
- |
|
| 329 |
$requete_selection_liaisons = 'SELECT * FROM cel_obs_images LIMIT '.$i.','.$pas;
|
781 |
* Utiliser cette méthode dans une boucle pour afficher un message suivi du nombre de tour de boucle effectué.
|
| 330 |
$tableau_liaisons = $this->executerRequete($requete_selection_liaisons);
|
- |
|
| 331 |
|
- |
|
| 332 |
$requete_migration_liaison = 'INSERT INTO '.self::$bdd_cel_migration.'.cel_obs_images '.
|
- |
|
| 333 |
'(id_image, id_utilisateur, id_observation, date_liaison) '.
|
782 |
* Vous devrez vous même gérer le retour à la ligne à la sortie de la boucle.
|
| 334 |
'VALUES ';
|
783 |
*
|
| 335 |
|
- |
|
| 336 |
$sous_requete_insertion = '';
|
784 |
* @param string le message d'information.
|
| 337 |
|
785 |
* @param int le nombre de départ à afficher.
|
| 338 |
if(is_array($tableau_liaisons)) {
|
786 |
* @return void le message est affiché dans la console.
|
| 339 |
foreach($tableau_liaisons as &$liaison) {
|
787 |
*/
|
| 340 |
|
788 |
protected function afficherAvancement($message, $depart = 0) {
|
| 341 |
$mail_utilisateur = $liaison['coi_ce_utilisateur'];
|
789 |
if (! isset(self::$avancement[$message])) {
|
| 342 |
$utilisateur = $this->renvoyerIdPourMigration($mail_utilisateur);
|
790 |
self::$avancement[$message] = $depart;
|
| 343 |
|
791 |
echo "$message : ";
|
| 344 |
$id_obs = $liaison['coi_ce_observation'];
|
792 |
|
| 345 |
|
793 |
$actuel =& self::$avancement[$message];
|
| 346 |
if (isset($this->tableau_observations[$mail_utilisateur][$id_obs])) {
|
794 |
echo $actuel++;
|
| 347 |
$id_obs = $this->tableau_observations[$mail_utilisateur][$id_obs];
|
- |
|
| 348 |
|
795 |
} else {
|
| - |
|
796 |
$actuel =& self::$avancement[$message];
|
| 349 |
$sous_requete_insertion .= '('.$this->proteger($liaison['coi_ce_image']).','.
|
797 |
|
| 350 |
$this->proteger($utilisateur).','.
|
798 |
// Cas du passage de 99 (= 2 caractères) à 100 (= 3 caractères)
|
| 351 |
$this->proteger($id_obs).','.
|
799 |
$passage = 0;
|
| 352 |
$this->proteger($liaison['coi_date_liaison']).
|
800 |
if (strlen((string) ($actuel - 1)) < strlen((string) ($actuel))) {
|
| 353 |
'),';
|
801 |
$passage = 1;
|
| 354 |
} else {
|
802 |
}
|
| 355 |
// cas d'une observation inexistante, la liaison est ignorée
|
803 |
echo str_repeat(chr(8), (strlen((string) $actuel) - $passage));
|
| - |
|
804 |
echo $actuel++;
|
| 356 |
$liaisons_obs_inexistantes++;
|
805 |
}
|
| 357 |
}
|
- |
|
| 358 |
}
|
- |
|
| 359 |
|
- |
|
| 360 |
$sous_requete_insertion = rtrim($sous_requete_insertion,',');
|
- |
|
| 361 |
$requete_migration_liaison = $requete_migration_liaison.$sous_requete_insertion;
|
806 |
}
|
| Line 362... |
Line 807... |
| 362 |
|
807 |
|
| 363 |
$migration_liaison = $this->executerRequeteSimple($requete_migration_liaison);
|
- |
|
| 364 |
|
808 |
private function ordonnerImages() {
|
| Line 365... |
Line 809... |
| 365 |
if (!$migration_liaison) {
|
809 |
$requete = 'ALTER TABLE '.self::$bdd_cel_migration.'.cel_images ORDER BY id_image';
|
| 366 |
echo 'la migration des liaisons obs images de '.$i.' à '.($i+$pas).' a échoué ! '."\n<br />";
|
- |
|
| 367 |
} else {
|
810 |
$this->executerRequeteSimple($requete);
|
| 368 |
$this->afficherAvancement('Migration des liaisons obs images (par '.$pas.' )', $fin);
|
811 |
}
|
| 369 |
}
|
812 |
|
| 370 |
}
|
813 |
public function executerRequeteSimple($requete) {
|
| 371 |
}
|
814 |
// Fonction de commodité pour afficher les requetes au lieu de les executer
|
| 372 |
echo "\n\n";
|
815 |
if (self::dry_run) {
|
| 373 |
echo $liaisons_obs_inexistantes ? $liaisons_obs_inexistantes." liaisons image obs ont été ignorées car les obs sont absentes" : '' ;
|
816 |
echo str_replace('),','),'."\n", $requete)."\n";
|
| 374 |
echo "\n";
|
- |
|
| 375 |
echo "\n---------------------------------------------------------------- OK\n\n";
|
817 |
return true;
|
| 376 |
}
|
818 |
} else {
|
| 377 |
|
819 |
return parent::executerRequeteSimple($requete);
|
| 378 |
private function traiterLigneImage($image) {
|
820 |
}
|
| Line 379... |
Line 821... |
| 379 |
|
821 |
}
|
| 380 |
$nouvelle_image = array();
|
822 |
|
| Line 381... |
Line 823... |
| 381 |
|
823 |
private function traiterLigneImage($image) {
|
| 382 |
foreach ($this->tableau_nouveau_ancien as $nouveau_champ_image => $ancien_champ_image) {
|
- |
|
| 383 |
|
824 |
$nouvelle_image = array();
|
| 384 |
if ($this->estUnChampATraiter($ancien_champ_image)) {
|
825 |
|
| Line 385... |
Line 826... |
| 385 |
if (method_exists($this,$ancien_champ_image)) {
|
826 |
foreach ($this->tableau_nouveau_ancien as $nouveau_champ_image => $ancien_champ_image) {
|
| 386 |
$nouvelle_image[$nouveau_champ_image] = $this->$ancien_champ_image($image);
|
- |
|
| 387 |
} else {
|
- |
|
| 388 |
echo 'methode manquante : '.$ancien_champ_image."\n";
|
- |
|
| 389 |
$nouvelle_image[$nouveau_champ_image] = '';
|
- |
|
| 390 |
}
|
827 |
if ($this->estUnChampATraiter($ancien_champ_image)) {
|
| 391 |
|
- |
|
| 392 |
} else {
|
- |
|
| 393 |
$nouvelle_image[$nouveau_champ_image] = $image[$ancien_champ_image];
|
- |
|
| 394 |
}
|
828 |
if (method_exists($this,$ancien_champ_image)) {
|
| 395 |
}
|
829 |
$nouvelle_image[$nouveau_champ_image] = $this->$ancien_champ_image($image);
|
| 396 |
|
- |
|
| 397 |
return $nouvelle_image;
|
830 |
} else {
|
| 398 |
}
|
- |
|
| 399 |
|
- |
|
| 400 |
private function estUnChampATraiter($champ) {
|
- |
|
| 401 |
|
- |
|
| 402 |
return strpos($champ, 'traiter') !== false;
|
- |
|
| 403 |
}
|
- |
|
| 404 |
|
- |
|
| 405 |
private function traiterMotsClesTexte($ligne_image) {
|
- |
|
| 406 |
|
- |
|
| 407 |
$mail_image = $ligne_image['ci_ce_utilisateur'];
|
- |
|
| 408 |
$retour = $ligne_image['ci_meta_mots_cles'];
|
- |
|
| 409 |
|
- |
|
| 410 |
if (isset($this->tableau_mots_cles[$mail_image])) {
|
- |
|
| 411 |
|
- |
|
| 412 |
$mots_cles_tableau = $this->parserMotsCles($mail_image, $ligne_image['ci_meta_mots_cles'], ',');
|
- |
|
| 413 |
$retour = join(';',$mots_cles_tableau);
|
- |
|
| 414 |
$retour = ltrim($retour,';;') ;
|
- |
|
| 415 |
}
|
- |
|
| 416 |
|
- |
|
| 417 |
return $retour;
|
- |
|
| 418 |
}
|
- |
|
| 419 |
|
- |
|
| 420 |
private function parserMotsCles($utilisateur, $mot_cles, $separateur = ',') {
|
- |
|
| 421 |
|
- |
|
| 422 |
$tableau_mots_cles = explode($separateur,$mot_cles);
|
- |
|
| 423 |
$tableau_mots_cles_formates = array();
|
- |
|
| 424 |
|
- |
|
| 425 |
foreach($tableau_mots_cles as $mot_cle) {
|
- |
|
| 426 |
|
- |
|
| 427 |
$mot_cle = str_replace($separateur.$separateur,'',$mot_cle);
|
- |
|
| 428 |
$mot_cle = str_replace('null','',$mot_cle);
|
- |
|
| 429 |
|
- |
|
| 430 |
if ($this->estUnIdentifiantMotCle($mot_cle)) {
|
- |
|
| 431 |
|
- |
|
| 432 |
// certains mots clés mal formatés contiennent des virgules
|
- |
|
| 433 |
if (strpos($mot_cle,',') !== false) {
|
- |
|
| 434 |
$tab_mot_cle_mal_formate = explode(',',$mot_cle);
|
- |
|
| 435 |
|
- |
|
| 436 |
foreach ($tab_mot_cle_mal_formate as $mot_cle_mal_formate) {
|
- |
|
| 437 |
if ($this->estUnIdentifiantMotCle($mot_cle_mal_formate)) {
|
831 |
echo 'methode manquante : '.$ancien_champ_image."\n";
|
| Line 438... |
Line 832... |
| 438 |
$tableau_mots_cles_formates[$mot_cle_mal_formate] = $this->tableau_mots_cles[$utilisateur][$mot_cle_mal_formate]['mot_cle'];
|
832 |
$nouvelle_image[$nouveau_champ_image] = '';
|
| 439 |
}
|
- |
|
| 440 |
}
|
833 |
}
|
| 441 |
} else {
|
834 |
} else {
|
| Line 442... |
Line 835... |
| 442 |
// on met le mot clé dans sa propre case afin d'éviter
|
835 |
$nouvelle_image[$nouveau_champ_image] = $image[$ancien_champ_image];
|
| 443 |
// facilement les doublons provoqués par de mauvais formatages
|
836 |
}
|
| Line 444... |
Line 837... |
| 444 |
if(isset($this->tableau_mots_cles[$utilisateur][$mot_cle])) {
|
837 |
}
|
| - |
|
838 |
|
| - |
|
839 |
return $nouvelle_image;
|
| - |
|
840 |
}
|
| - |
|
841 |
|
| - |
|
842 |
private function estUnChampATraiter($champ) {
|
| - |
|
843 |
return strpos($champ, 'traiter') !== false;
|
| - |
|
844 |
}
|
| - |
|
845 |
|
| - |
|
846 |
private function protegerSiNonNull($valeur) {
|
| - |
|
847 |
if ($valeur != 'NULL') {
|
| - |
|
848 |
$valeur = $this->proteger($valeur);
|
| - |
|
849 |
}
|
| - |
|
850 |
return $valeur;
|
| - |
|
851 |
}
|
| - |
|
852 |
|
| - |
|
853 |
private function traiterIdentifiantUtilisateur($ligne_image) {
|
| - |
|
854 |
$mail_image = $ligne_image['ci_ce_utilisateur'];
|
| - |
|
855 |
$retour = $this->renvoyerIdPourMigration($mail_image);
|
| - |
|
856 |
|
| Line -... |
Line 857... |
| - |
|
857 |
return $retour;
|
| 445 |
$tableau_mots_cles_formates[$mot_cle] = $this->tableau_mots_cles[$utilisateur][$mot_cle]['mot_cle'];
|
858 |
}
|
| 446 |
}
|
859 |
|
| Line 447... |
Line 860... |
| 447 |
}
|
860 |
private function renvoyerIdPourMigration($utilisateur) {
|
| 448 |
|
861 |
// si tout les test suivant échouent, on garde l'utilisateur tel quel (cas de la chaine de session des utilisateur anonymes)
|
| 449 |
}
|
862 |
$retour = $utilisateur;
|
| 450 |
}
|
863 |
// si le mail correspond a un utilisateur de la bdd
|
| 451 |
|
864 |
if (isset($this->tableau_utilisateurs[$utilisateur])) {
|
| Line 452... |
Line 865... |
| 452 |
return $tableau_mots_cles_formates;
|
865 |
// on renvoie son id
|
| 453 |
}
|
866 |
$retour = $this->tableau_utilisateurs[$utilisateur]['id'];
|
| Line -... |
Line 867... |
| - |
|
867 |
} else {
|
| - |
|
868 |
// sinon si c'est un mail inconnu, on garde le md5
|
| 454 |
|
869 |
if($this->mailValide($utilisateur)) {
|
| - |
|
870 |
$retour = md5($utilisateur);
|
| - |
|
871 |
}
|
| - |
|
872 |
}
|
| - |
|
873 |
return $retour;
|
| Line -... |
Line 874... |
| - |
|
874 |
}
|
| 455 |
private function estUnIdentifiantMotCle($chaine) {
|
875 |
|
| 456 |
return trim($chaine) != '' && preg_match('/[0-9A-Z]+\.[0-9A-Z]+/i', $chaine) ;
|
876 |
public function mailValide($mail) {
|
| Line 457... |
Line 877... |
| 457 |
}
|
877 |
// vérification bidon mais ça suffit pour ici
|
| 458 |
|
878 |
return !(strpos('@',$mail) === false);
|
| 459 |
private function traiterIdentifiantUtilisateur($ligne_image) {
|
879 |
}
|
| 460 |
|
880 |
|
| 461 |
$mail_image = $ligne_image['ci_ce_utilisateur'];
|
881 |
private function traiterPrenomUtilisateur($ligne_image) {
|
| Line 462... |
Line 882... |
| 462 |
$retour = $this->renvoyerIdPourMigration($mail_image);
|
882 |
$mail_image = $ligne_image['ci_ce_utilisateur'];
|
| 463 |
|
883 |
$retour = $mail_image;
|
| Line 464... |
Line -... |
| 464 |
return $retour;
|
- |
|
| 465 |
}
|
- |
|
| 466 |
|
- |
|
| 467 |
private function traiterPrenomUtilisateur($ligne_image) {
|
- |
|
| 468 |
|
- |
|
| 469 |
$mail_image = $ligne_image['ci_ce_utilisateur'];
|
- |
|
| 470 |
$retour = $mail_image;
|
- |
|
| 471 |
|
- |
|
| 472 |
if (isset($this->tableau_utilisateurs[$mail_image])) {
|
- |
|
| 473 |
$retour = $this->tableau_utilisateurs[$mail_image]['prenom'];
|
- |
|
| 474 |
} else {
|
- |
|
| 475 |
$retour = '';
|
- |
|
| 476 |
}
|
- |
|
| 477 |
|
- |
|
| 478 |
return $retour;
|
- |
|
| 479 |
}
|
- |
|
| 480 |
|
- |
|
| 481 |
private function traiterNomUtilisateur($ligne_image) {
|
- |
|
| 482 |
|
- |
|
| 483 |
$mail_image = $ligne_image['ci_ce_utilisateur'];
|
- |
|
| 484 |
$retour = $mail_image;
|
- |
|
| 485 |
|
- |
|
| 486 |
if (isset($this->tableau_utilisateurs[$mail_image])) {
|
- |
|
| 487 |
$retour = $this->tableau_utilisateurs[$mail_image]['nom'];
|
- |
|
| 488 |
} else {
|
- |
|
| 489 |
$retour = '';
|
- |
|
| 490 |
}
|
- |
|
| 491 |
|
- |
|
| 492 |
return $retour;
|
- |
|
| 493 |
}
|
- |
|
| 494 |
|
- |
|
| 495 |
private function decoderTableauMetaDonnees($chaine) {
|
- |
|
| 496 |
|
- |
|
| 497 |
$tableau_valeurs_decodees = array();
|
- |
|
| 498 |
|
- |
|
| 499 |
if (trim($chaine) != '') {
|
- |
|
| 500 |
$tableau_meta = explode(self::separateur_champs_metadonnees,$chaine);
|
- |
|
| 501 |
foreach ($tableau_meta as &$chaine_meta) {
|
- |
|
| 502 |
|
- |
|
| 503 |
$cle_valeur = explode(self::separateur_valeurs_metadonnees, $chaine_meta);
|
- |
|
| 504 |
if (is_array($cle_valeur) && count($cle_valeur) == 2) {
|
- |
|
| 505 |
$cle = ltrim($cle_valeur[0],' ');
|
- |
|
| 506 |
$tableau_valeurs_decodees[$cle] = $cle_valeur[1];
|
884 |
|
| 507 |
}
|
- |
|
| 508 |
}
|
- |
|
| 509 |
}
|
- |
|
| 510 |
|
- |
|
| 511 |
return $tableau_valeurs_decodees;
|
- |
|
| 512 |
}
|
- |
|
| 513 |
|
- |
|
| 514 |
private function convertirTableauMetadonneesEnXml($tableau) {
|
- |
|
| 515 |
|
- |
|
| 516 |
$xml = '';
|
- |
|
| 517 |
|
- |
|
| 518 |
foreach($tableau as $cle => $valeur) {
|
- |
|
| 519 |
|
- |
|
| 520 |
$cle = str_replace('ci_meta_exif_','',$cle);
|
- |
|
| 521 |
$cle = str_replace('ci_meta_iptc_','',$cle);
|
- |
|
| 522 |
$cle = str_replace('ci_meta_','',$cle);
|
- |
|
| 523 |
$cle = str_replace('_',' ',$cle);
|
- |
|
| 524 |
$cle = str_replace(' ','',ucwords($cle));
|
- |
|
| 525 |
$valeur = str_replace("\0",'',$valeur);
|
- |
|
| 526 |
$id = isset($this->id_cle_metadonnees[$cle]) ? $this->id_cle_metadonnees[$cle] : $cle;
|
- |
|
| 527 |
$xml .= '<'.$cle.' id="'.$id.'">'.$valeur.'</'.$cle.'>'."\n";
|
- |
|
| 528 |
}
|
- |
|
| 529 |
|
- |
|
| 530 |
return $xml;
|
- |
|
| 531 |
}
|
- |
|
| 532 |
|
- |
|
| 533 |
private function peutUtiliserExifTool() {
|
- |
|
| 534 |
return file_exists('/usr/bin/exiftool') && is_executable('/usr/bin/exiftool');
|
- |
|
| 535 |
}
|
- |
|
| 536 |
|
- |
|
| 537 |
private function decoderMetadonnees($chemin_image) {
|
- |
|
| 538 |
|
- |
|
| 539 |
$res = '';
|
- |
|
| 540 |
|
- |
|
| 541 |
if($this->peutUtiliserExifTool()) {
|
- |
|
| 542 |
$res = $this->decoderMetadonneesExifTool($chemin_image);
|
- |
|
| 543 |
|
- |
|
| 544 |
$xml_meta = '<?xml version="1.0" encoding="UTF-8" ?>';
|
- |
|
| 545 |
$xml_meta .= '<exif>';
|
- |
|
| 546 |
|
- |
|
| 547 |
foreach($res['EXIF'] as $prop => $valeur) {
|
- |
|
| 548 |
$xml_meta .= ' <'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
|
- |
|
| 549 |
}
|
- |
|
| 550 |
$xml_meta .= '</exif>'."\n";
|
- |
|
| 551 |
|
- |
|
| 552 |
$xml_meta .= '<iptc>';
|
- |
|
| 553 |
foreach($res['IPTC'] as $prop => $valeur) {
|
- |
|
| 554 |
$xml_meta .= ' <'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
|
- |
|
| 555 |
}
|
- |
|
| 556 |
$xml_meta .= '</iptc>'."\n";
|
- |
|
| 557 |
|
- |
|
| 558 |
$xml_meta .= '<xmp>';
|
- |
|
| 559 |
foreach($res['XMP'] as $prop => $valeur) {
|
- |
|
| 560 |
$xml_meta .= ' <'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
|
- |
|
| 561 |
}
|
885 |
if (isset($this->tableau_utilisateurs[$mail_image])) {
|
| 562 |
$xml_meta .= '</xmp>'."\n";
|
886 |
$retour = self::formaterMotPremiereLettreChaqueMotEnMajuscule($this->tableau_utilisateurs[$mail_image]['prenom']);
|
| Line 563... |
Line 887... |
| 563 |
} else {
|
887 |
} else {
|
| 564 |
|
888 |
$retour = '';
|
| 565 |
}
|
- |
|
| 566 |
|
- |
|
| 567 |
return $xml_meta;
|
889 |
}
|
| 568 |
}
|
890 |
|
| 569 |
|
891 |
return $retour;
|
| 570 |
private function decoderMetadonneesExifTool($chemin_image) {
|
- |
|
| 571 |
$metadata = array();
|
- |
|
| 572 |
$res = exec('/usr/bin/exiftool -g -D '.$chemin_image, $metadata);
|
- |
|
| 573 |
|
- |
|
| 574 |
$metadata_decodees = array();
|
- |
|
| 575 |
|
- |
|
| 576 |
$categorie = '';
|
892 |
}
|
| 577 |
foreach($metadata as &$data) {
|
893 |
|
| Line 578... |
Line 894... |
| 578 |
if($this->estUnSeparateurCategorieExifTool($data)) {
|
894 |
public static function formaterMotPremiereLettreChaqueMotEnMajuscule($chaine, $encodage= 'UTF-8') {
|
| 579 |
$categorie = trim(str_replace('----','',$data));
|
- |
|
| 580 |
} else {
|
895 |
$chaine = str_replace('-', ' - ', $chaine);
|
| 581 |
$data_decodee = $this->parserValeurMetadonneeExifTool($data);
|
896 |
$chaine = mb_strtolower($chaine, $encodage);
|
| Line 582... |
Line -... |
| 582 |
$cle_metadonnee = str_replace(' ', '', $data_decodee['cle']);
|
- |
|
| 583 |
$metadata_decodees[$categorie][$cle_metadonnee] = $data_decodee;
|
897 |
$chaine = mb_convert_case($chaine, MB_CASE_TITLE, $encodage);
|
| 584 |
$this->id_cle_metadonnees[$cle_metadonnee] = $data_decodee['id'];
|
898 |
$chaine = str_replace(' - ', '-', $chaine);
|
| - |
|
899 |
return $chaine;
|
| 585 |
}
|
900 |
}
|
| 586 |
}
|
901 |
|
| 587 |
|
902 |
private function traiterNomUtilisateur($ligne_image) {
|
| 588 |
return $metadata_decodees;
|
903 |
$mail_image = $ligne_image['ci_ce_utilisateur'];
|
| Line 589... |
Line 904... |
| 589 |
}
|
904 |
$retour = $mail_image;
|
| 590 |
|
- |
|
| 591 |
private function estUnSeparateurCategorieExifTool($data) {
|
905 |
|
| 592 |
return preg_match('^---- (.)* ----^',$data);
|
906 |
if (isset($this->tableau_utilisateurs[$mail_image])) {
|
| 593 |
}
|
- |
|
| 594 |
|
- |
|
| 595 |
private function parserValeurMetadonneeExifTool($data) {
|
- |
|
| 596 |
$cle_valeur = explode(':',$data);
|
- |
|
| 597 |
|
- |
|
| Line -... |
Line 907... |
| - |
|
907 |
$retour = self::formaterMotEnMajuscule($this->tableau_utilisateurs[$mail_image]['nom']);
|
| - |
|
908 |
} else {
|
| - |
|
909 |
$retour = '';
|
| - |
|
910 |
}
|
| - |
|
911 |
|
| 598 |
$valeur = '';
|
912 |
return $retour;
|
| 599 |
if(count($cle_valeur) == 2) {
|
913 |
}
|
| Line 600... |
Line 914... |
| 600 |
$valeur = trim($cle_valeur[1]);
|
914 |
|
| 601 |
}
|
- |
|
| 602 |
|
- |
|
| 603 |
$id_cle = explode(' ',trim($cle_valeur[0]),2);
|
- |
|
| 604 |
|
- |
|
| 605 |
$id_cle[1] = str_replace(array('-','/'),'',$id_cle[1]);
|
- |
|
| 606 |
|
915 |
public static function formaterMotEnMajuscule($chaine, $encodage= 'UTF-8') {
|
| 607 |
$cle_id_valeur = array('cle' => $id_cle[1], 'id' => str_replace('-','',$id_cle[0]), 'valeur' => $valeur);
|
- |
|
| 608 |
return $cle_id_valeur;
|
- |
|
| 609 |
}
|
- |
|
| 610 |
|
- |
|
| 611 |
private function traiterExif($ligne_image) {
|
- |
|
| 612 |
|
- |
|
| 613 |
$metadonnees_autres = $this->decoderTableauMetaDonnees($ligne_image['ci_meta_exif_autres']);
|
- |
|
| 614 |
$metadonnees = array_intersect_key($ligne_image, array_flip($this->champs_exifs_non_gardes))+$metadonnees_autres;
|
916 |
return mb_convert_case($chaine, MB_CASE_UPPER, $encodage);
|
| 615 |
|
917 |
}
|
| Line 616... |
Line 918... |
| 616 |
$xml_meta = '<?xml version="1.0" encoding="UTF-8" ?>';
|
918 |
|
| 617 |
$xml_meta .= '<exif>';
|
- |
|
| 618 |
$xml_meta .= $this->convertirTableauMetadonneesEnXml($metadonnees);
|
- |
|
| 619 |
$xml_meta .= '</exif>';
|
- |
|
| 620 |
|
- |
|
| 621 |
return $xml_meta;
|
- |
|
| 622 |
}
|
- |
|
| 623 |
|
- |
|
| 624 |
private function traiterIptc($ligne_image) {
|
- |
|
| 625 |
|
- |
|
| 626 |
$metadonnees_autres = $this->decoderTableauMetaDonnees($ligne_image['ci_meta_iptc_autres']);
|
- |
|
| 627 |
$metadonnees = array_intersect_key($ligne_image, array_flip($this->champs_iptc_non_gardes))+$metadonnees_autres;
|
- |
|
| 628 |
|
- |
|
| 629 |
$xml_meta = '<?xml version="1.0" encoding="UTF-8" ?>';
|
919 |
private function traiterNoteImage($image) {
|
| 630 |
$xml_meta .= '<iptc>';
|
- |
|
| 631 |
$xml_meta .= $this->convertirTableauMetadonneesEnXml($metadonnees);
|
- |
|
| 632 |
$xml_meta .= '</iptc>';
|
- |
|
| 633 |
|
- |
|
| 634 |
return $xml_meta;
|
- |
|
| 635 |
}
|
- |
|
| 636 |
|
- |
|
| 637 |
private function traiterXmp($ligne_image) {
|
- |
|
| 638 |
|
- |
|
| 639 |
$chemin = $this->obtenirCheminImageOriginale($ligne_image['ci_id_image']);
|
- |
|
| 640 |
// TODO décommenté car pour le moment ça n'est pas necessaire, à éxécuter à part
|
- |
|
| 641 |
//$res = $this->decoderMetadonneesExifTool($chemin);
|
- |
|
| 642 |
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
|
- |
|
| 643 |
$xml .= '<xmp>';
|
- |
|
| 644 |
if (isset($res['XMP'])) {
|
- |
|
| 645 |
foreach ($res['XMP'] as $prop => $valeur) {
|
- |
|
| 646 |
$xml .= ' <'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
|
- |
|
| 647 |
}
|
- |
|
| 648 |
}
|
- |
|
| 649 |
$xml .= '</xmp>';
|
- |
|
| 650 |
|
- |
|
| 651 |
return $xml;
|
- |
|
| 652 |
}
|
- |
|
| 653 |
|
- |
|
| 654 |
private function traiterMakernote($ligne_image) {
|
- |
|
| 655 |
|
- |
|
| 656 |
$chemin = $this->obtenirCheminImageOriginale($ligne_image['ci_id_image']);
|
- |
|
| 657 |
//$res = $this->decoderMetadonneesExifTool($chemin);
|
- |
|
| 658 |
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
|
- |
|
| 659 |
$xml .= '<makernote>';
|
- |
|
| 660 |
if (isset($res['MAKERNOTE'])) {
|
- |
|
| 661 |
foreach ($res['MAKERNOTE'] as $prop => $valeur) {
|
- |
|
| 662 |
$xml .= ' <'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
|
- |
|
| 663 |
}
|
- |
|
| 664 |
}
|
- |
|
| 665 |
$xml .= '</makernote>';
|
- |
|
| 666 |
|
- |
|
| 667 |
return '';
|
- |
|
| 668 |
}
|
- |
|
| 669 |
|
- |
|
| 670 |
public function obtenirCheminImageOriginale($id_image) {
|
- |
|
| 671 |
$nom = $this->convertirIdBddVersNomFichier($id_image, 'O');
|
- |
|
| 672 |
$dossier = $this->obtenirDossierPourFormat($id_image,'O');
|
- |
|
| 673 |
|
- |
|
| 674 |
return $dossier.'/'.$nom;
|
- |
|
| 675 |
}
|
- |
|
| 676 |
|
- |
|
| 677 |
public function convertirIdBddVersNomFichier($id, $format, $extension = 'jpg') {
|
- |
|
| 678 |
// creation du format original
|
- |
|
| 679 |
$id_avec_zeros = sprintf('%09s', $id) ;
|
920 |
$retour = $image['ci_note_image'];
|
| 680 |
$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
|
921 |
if ($image['ci_note_image'] == '-1') {
|
| Line 1173... |
Line 1018... |
| 1173 |
'City' => '144',
|
1018 |
|
| 1174 |
'Sub-location' => '146',
|
1019 |
if (is_array($tableau_liaisons)) {
|