291 lines
9.6 KiB
PHP
291 lines
9.6 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\File;
|
|
use App\Article;
|
|
use App\Marque;
|
|
use App\Sujet;
|
|
use App\Typemedia;
|
|
use App\Typevue;
|
|
use App\Site;
|
|
use App\Variante;
|
|
use App\Media;
|
|
use App\Http\Traits\MediaTools;
|
|
|
|
class ImportArcadiaFiles extends Command
|
|
{
|
|
use MediaTools;
|
|
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'arcadia:import';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Import des fichiers xml Arcadia';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->info('Démarrage du traitement');
|
|
$files = Storage::disk('arcadia')->files();
|
|
$bar = $this->output->createProgressBar(count($files)-1);
|
|
$bar->start();
|
|
|
|
// ---- Pour chaque fichier
|
|
foreach ($files as $filename) {
|
|
|
|
if($filename == ".gitignore") continue;
|
|
|
|
// ---- Récupération du contenu
|
|
$files = Storage::disk('arcadia')->get($filename);
|
|
$fileContent = simplexml_load_string($files);
|
|
|
|
// ---- traitement du fichier
|
|
if(substr($filename, 0, 11) == "DAM_ARTICLE"){
|
|
foreach ($fileContent->dam as $row) {
|
|
$record = Article::where('noArt', $row->noArt)->first();
|
|
if($record){ // Update record
|
|
$record->libCcial = $row->libCcial;
|
|
$record->codMarq = $row->codMarq;
|
|
$record->libMarq = $row->libMarq;
|
|
$record->codFamVte = $row->codFamVte;
|
|
$record->libFamVte = $row->libFamVte;
|
|
$record->codGencodAdm = $row->codGencodAdm;
|
|
$record->codGencodSymb = $row->codGencodSymb;
|
|
$record->codGencodPds = $row->codGencodPds;
|
|
$record->save();
|
|
}else{ // Insert new record
|
|
$record = new Article();
|
|
$record->noArt = $row->noArt;
|
|
$record->libCcial = $row->libCcial;
|
|
$record->codMarq = $row->codMarq;
|
|
$record->libMarq = $row->libMarq;
|
|
$record->codFamVte = $row->codFamVte;
|
|
$record->libFamVte = $row->libFamVte;
|
|
$record->codGencodAdm = $row->codGencodAdm;
|
|
$record->codGencodSymb = $row->codGencodSymb;
|
|
$record->codGencodPds = $row->codGencodPds;
|
|
$record->save();
|
|
}
|
|
}
|
|
}elseif (substr($filename, 0, 10) == "DAM_MARQUE") {
|
|
foreach ($fileContent->dam as $row) {
|
|
$record = Marque::where('codMarq', $row->codMarq)->first();
|
|
if($record){ // Update record
|
|
$record->libMarq = $row->libMarq;
|
|
$record->save();
|
|
}else{ // Insert new record
|
|
$record = new Marque();
|
|
$record->codMarq = $row->codMarq;
|
|
$record->libMarq = $row->libMarq;
|
|
$record->save();
|
|
}
|
|
}
|
|
}elseif (substr($filename, 0, 15) == "DAM_MEDIA_SUJET") {
|
|
foreach ($fileContent->mediaSujet as $row) {
|
|
$record = Sujet::where('codeSujet', $row->code)->first();
|
|
if($record){ // Update record
|
|
$record->libelle = $row->libelle;
|
|
$record->save();
|
|
}else{ // Insert new record
|
|
$record = new Sujet();
|
|
$record->codeSujet = $row->code;
|
|
$record->libelle = $row->libelle;
|
|
$record->save();
|
|
}
|
|
}
|
|
}elseif (substr($filename, 0, 20) == "DAM_MEDIA_TYPE_MEDIA") {
|
|
foreach ($fileContent->mediatypemedia as $row) {
|
|
$record = Typemedia::where('codeTypemedia', $row->code)->first();
|
|
if($record){ // Update record
|
|
$record->libelle = $row->libelle;
|
|
$record->save();
|
|
}else{ // Insert new record
|
|
$record = new Typemedia();
|
|
$record->codeTypemedia = $row->code;
|
|
$record->libelle = $row->libelle;
|
|
$record->save();
|
|
}
|
|
}
|
|
}elseif (substr($filename, 0, 17) == "DAM_MEDIA_TYPEVUE") {
|
|
foreach ($fileContent->mediatypesvue as $row) {
|
|
$record = Typevue::where('codeTypevue', $row->code)->first();
|
|
if($record){ // Update record
|
|
$record->libelle = $row->libelle;
|
|
$record->sujet_id = $row->sujet_id->mediasujet->code;
|
|
$record->save();
|
|
}else{ // Insert new record
|
|
$record = new Typevue();
|
|
$record->codeTypevue = $row->code;
|
|
$record->libelle = $row->libelle;
|
|
$record->sujet_id = $row->sujet_id->mediasujet->code;
|
|
$record->save();
|
|
}
|
|
}
|
|
}elseif (substr($filename, 0, 18) == "DAM_MEDIA_VARIANTE") {
|
|
foreach ($fileContent->mediavariante as $row) {
|
|
$record = Variante::where('codeVariante', $row->code)->first();
|
|
if($record){ // Update record
|
|
$record->libelle = $row->libelle;
|
|
$record->sujet_id = $row->sujet_id->children()[0]->code;
|
|
$record->typevue_id = $row->CodeTypeVue->mediatypesvue->code;
|
|
$record->save();
|
|
}else{ // Insert new record
|
|
$record = new Variante();
|
|
$record->codeVariante = $row->code;
|
|
$record->libelle = $row->libelle;
|
|
$record->sujet_id = $row->sujet_id->children()[0]->code;
|
|
$record->typevue_id = $row->CodeTypeVue->mediatypesvue->code;
|
|
$record->save();
|
|
}
|
|
}
|
|
}elseif (substr($filename, 0, 20) == "DAM_SITE_PROD_GROUPE") {
|
|
foreach ($fileContent->SITE_PROD_GRP as $row) {
|
|
$record = Site::where('id', $row->code)->first();
|
|
if($record){ // Update record
|
|
$record->libelle = $row->libelle;
|
|
$record->save();
|
|
}else{ // Insert new record
|
|
$record = new Site();
|
|
$record->id = $row->code;
|
|
$record->libelle = $row->libelle;
|
|
$record->save();
|
|
}
|
|
}
|
|
}elseif (substr($filename, 0, 16) == "DAM_MEDIA_VISUEL") {
|
|
foreach ($fileContent->MEDIA_VISUEL as $row) {
|
|
$record = Media::where('arcadia_id', $row->code)->first();
|
|
if(!$record){ // Insert new record
|
|
$record = new Media();
|
|
$record->arcadia_id = $row->code;
|
|
if($row->extension != ""){
|
|
$record->extension = $row->extension->typeFichier->libExtension;
|
|
}
|
|
|
|
$record->libelle = $row->libelle;
|
|
$record->largeur = $row->nbPxLargeur;
|
|
$record->largeur_mm = $row->largeurMm;
|
|
$record->hauteur = $row->nbPxHauteur;
|
|
$record->hauteur_mm = $row->hauteurMm;
|
|
$record->resolution = $row->pppLargeur;
|
|
if($row->version != ""){
|
|
$record->version = $row->version;
|
|
}else{
|
|
$record->version = 1;
|
|
}
|
|
|
|
if($row->typemedia_id != ""){
|
|
$record->typemedia_id = $row->codeTypeMedia;
|
|
}else{
|
|
$record->typemedia_id = 1;
|
|
}
|
|
if($row->typevue_id != ""){
|
|
$record->typevue_id = $row->codeTypeVue;
|
|
}
|
|
$record->commentaire = $row->commentaire;
|
|
$record->sujet_id = $row->codeSujet;
|
|
if($row->langue != ""){
|
|
$record->langue_id = $row->langue;
|
|
}
|
|
if($row->copyright != ""){
|
|
$record->copyright_id = $row->copyright;
|
|
}
|
|
if($row->codeVariante != ""){
|
|
$record->variante_id = $row->codeVariante;
|
|
}
|
|
if($row->dateCreation != ""){
|
|
$row->dateCreation = substr($row->dateCreation, 0, 10);
|
|
$date = explode("/", $row->dateCreation);
|
|
$record->created_at = $date[2].'-'.$date[1].'-'.$date[0];
|
|
}
|
|
if($row->dateModification != ""){
|
|
$row->dateModification = substr($row->dateModification, 0, 10);
|
|
$date = explode("/", $row->dateModification);
|
|
$record->updated_at = $date[2].'-'.$date[1].'-'.$date[0];
|
|
}
|
|
if($row->datePublication != ""){
|
|
$row->datePublication = substr($row->datePublication, 0, 10);
|
|
$date = explode("/", $row->datePublication);
|
|
$record->published_at = $date[2].'-'.$date[1].'-'.$date[0];
|
|
}
|
|
$record->statut = config('services.statut.public_etendue');
|
|
|
|
// TODO lien avec les sites, marques et articles
|
|
|
|
|
|
$mediaFile = "/images/".$record->arcadia_id.".".$record->extension;
|
|
$fileExists = Storage::disk('arcadia')->exists($mediaFile);
|
|
if($fileExists){
|
|
$file = Storage::disk('arcadia')->get($mediaFile);
|
|
|
|
// Affectation d'un dossier et d'un uid
|
|
$destinationPath = $this->get_mediaFolder()."/";
|
|
$record->folder = $destinationPath;
|
|
$record->uid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
|
// 32 bits for "time_low"
|
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
|
// 16 bits for "time_mid"
|
|
mt_rand(0, 0xffff),
|
|
// 16 bits for "time_hi_and_version",
|
|
// four most significant bits holds version number 4
|
|
mt_rand(0, 0x0fff) | 0x4000,
|
|
// 16 bits, 8 bits for "clk_seq_hi_res",
|
|
// 8 bits for "clk_seq_low",
|
|
// two most significant bits holds zero and one for variant DCE1.1
|
|
mt_rand(0, 0x3fff) | 0x8000,
|
|
// 48 bits for "node"
|
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
|
);
|
|
|
|
// déplacement du média et renommage du fichier
|
|
$full_path_source = Storage::disk('arcadia')->getDriver()->getAdapter()->applyPathPrefix($mediaFile);
|
|
$full_path_dest = Storage::disk('local')->getDriver()->getAdapter()->applyPathPrefix($destinationPath.$record->uid. '.' .$record->extension);
|
|
File::move($full_path_source, $full_path_dest);
|
|
|
|
// calcul de la taille du média et durée
|
|
$record->taille = $this->formatBytes($this->get_file_size($full_path_dest));
|
|
$record->save();
|
|
|
|
// ---- Creation des vignettes de base
|
|
$this->create_sys_thumb($record);
|
|
// ---- Creation des vignettes en lien avec le sujet du média
|
|
$this->create_thumb($record);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// ---- Suppression du fichier
|
|
Storage::disk('arcadia')->delete($filename);
|
|
$bar->advance();
|
|
}
|
|
|
|
$bar->finish();
|
|
$this->line("");
|
|
$this->info('Fin du traitement');
|
|
}
|
|
}
|