- Fix Elasticsearch

- Traitement des XML
- Gestion du flux Arcadia
- Changement interface
This commit is contained in:
Vincent BRIDIER 2019-09-17 16:32:40 +02:00
parent 0056111538
commit ae264bdc96
12 changed files with 475 additions and 218 deletions

View file

@ -13,7 +13,7 @@ use App\Models\Dossier;
class ImportMedia extends Command
{
use MediaTools;
use MediaTools;
/**
* The name and signature of the console command.
@ -44,203 +44,224 @@ class ImportMedia extends Command
*
* @return mixed
*/
public function handle()
{
$this->info('Démarrage du traitement');
$files = Storage::disk('arcadia')->files();
public function handle()
{
$this->info('Démarrage du traitement');
$files = File::glob(storage_path('export_arcadia') . "/DAM_MEDIA_VISUEL_*.*");
$this->line("-> Import du fichier DAM_MEDIA_VISUEL");
// ---- Traitement de l'import des XML Visuel
foreach ($files as $filename) {
$path = explode("/", $filename);
$filename = $path[count($path) - 1];
// ---- Récupération du contenu
$oneFile = Storage::disk('arcadia')->get($filename);
$fileContent = simplexml_load_string($oneFile);
// ---- traitement du fichier
$bar = $this->output->createProgressBar(count($fileContent->MEDIA_VISUEL)-1);
$bar->start();
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->codeTypeMedia != "") {
$record->typemedia_id = $row->codeTypeMedia;
} else {
$record->typemedia_id = 1;
}
if ($row->codeTypeVue != "") {
$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_etendu');
// 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', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
$mediaFile = "/images/" . $record->arcadia_id . "." . $record->extension;
$fileExists = Storage::disk('arcadia')->exists($mediaFile);
if ($fileExists) {
// déplacement du média et renommage du fichier
$file = Storage::disk('arcadia')->get($mediaFile);
$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);
$this->line("-> Import du fichier DAM_MEDIA_VISUEL");
// ---- Traitement de l'import des XML Visuel
foreach ($files as $filename) {
// calcul de la taille du média
$record->taille = $this->formatBytes($this->get_file_size($full_path_dest));
if($filename == ".gitignore") continue;
} else {
// on applique une image par défaut
$record->extension = "jpg";
Storage::disk('local')->copy("images/default.jpg", $destinationPath . $record->uid . '.' . $record->extension);
// ---- Récupération du contenu
$oneFile = Storage::disk('arcadia')->get($filename);
$fileContent = simplexml_load_string($oneFile);
// ---- traitement du fichier
if (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->codeTypeMedia != ""){
$record->typemedia_id = $row->codeTypeMedia;
}else{
$record->typemedia_id = 1;
}
if($row->codeTypeVue != ""){
$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_etendu');
// 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', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
// calcul de la taille du média
$record->taille = $this->formatBytes($this->get_file_size("public/" . $destinationPath . $record->uid . '.' . $record->extension));
}
$mediaFile = "/images/".$record->arcadia_id.".".$record->extension;
$fileExists = Storage::disk('arcadia')->exists($mediaFile);
if($fileExists){
// déplacement du média et renommage du fichier
$file = Storage::disk('arcadia')->get($mediaFile);
$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);
$record->save();
// calcul de la taille du média
$record->taille = $this->formatBytes($this->get_file_size($full_path_dest));
// ---- 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);
} else {
$this->line("DAM_MEDIA_VISUEL : le media n°" . $row->code . " existe déjà en base");
}
$bar->advance();
}
$bar->finish();
}else{
// on applique une image par défaut
$record->extension = "jpg";
Storage::disk('local')->copy("images/default.jpg", $destinationPath.$record->uid. '.' .$record->extension);
// ---- Suppression du fichier
//Storage::disk('arcadia')->delete($filename);
// calcul de la taille du média
$record->taille = $this->formatBytes($this->get_file_size("public/".$destinationPath.$record->uid. '.' .$record->extension));
}
}
$record->save();
// ---- Traitement de l'association media <-> article
$files = File::glob(storage_path('export_arcadia') . "/DAM_ASSO_ARTICLE_*.*");
$this->line("-> Import du fichier DAM_ASSO_ARTICLE");
foreach ($files as $filename) {
$path = explode("/", $filename);
$filename = $path[count($path) - 1];
// ---- 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);
}else{
$this->line("DAM_MEDIA_VISUEL : le media n°".$row->code. " existe déjà en base");
}
}
// ---- Récupération du contenu
$oneFile = Storage::disk('arcadia')->get($filename);
$fileContent = simplexml_load_string($oneFile);
// ---- Suppression du fichier
//Storage::disk('arcadia')->delete($filename);
// ---- traitement du fichier
$bar = $this->output->createProgressBar(count($fileContent->mediaassoarticle)-1);
$bar->start();
foreach ($fileContent->mediaassoarticle as $row) {
$record = Media::where('arcadia_id', $row->codeVisuel)->first();
if ($record) {
$article = Article::where('noArt', $row->noArt)->first();
if ($article) {
// attache l'article au média
$record->articles()->syncWithoutDetaching($article->id);
// recherche un dossier lié à la marque de l'article
$marque_id = $article->codMarq;
$dossier = Dossier::whereHas("marques", function ($query) use ($marque_id) {
$query->where("codMarq", $marque_id);
})->first();
}
}
if ($dossier) {
// attache le dossier marque au Média
$record->dossier_id = $dossier->id;
$record->save();
$this->line("Liason media n°" . $row->codeVisuel . " à la marque n°" . $article->libMarq);
} else {
$marque = Marque::where('codMarq', '=', $marque_id)->first();
// On cree le dossier
$dossier = new Dossier();
$dossier->libelle = $marque->libMarq;
$dossier->sujet_id = 1;
$dossier->system = 0;
$dossier->marques()->syncWithoutDetaching($marque_id);
$dossier->save();
$record->dossier_id = $dossier->id;
$record->save();
$this->line("Liason media n°" . $row->codeVisuel . " à la marque n°" . $article->libMarq);
//$this->line("pas de liaison de marque : le media n°".$row->codeVisuel. " ne peut être lié à l'article n°".$row->noArt);
}
} else {
$this->line("DAM_ASSO_ARTICLE : le media n°" . $row->codeVisuel . " ne peut être lié à l'article n°" . $row->noArt);
}
} else {
$this->line("DAM_ASSO_ARTICLE : le media n°" . $row->codeVisuel . " n'existe pas");
}
$bar->advance();
}
$bar->finish();
// ---- Suppression du fichier
//Storage::disk('arcadia')->delete($filename);
}
// ---- Traitement de l'association media <-> article
$this->line("-> Import du fichier DAM_ASSO_ARTICLE");
foreach ($files as $filename) {
if($filename == ".gitignore") continue;
// ---- Traitement de l'association media <-> marque
$files = File::glob(storage_path('export_arcadia') . "/DAM_ASSO_MARQUE_*.*");
$this->line("-> Import du fichier DAM_ASSO_MARQUE");
foreach ($files as $filename) {
$path = explode("/", $filename);
$filename = $path[count($path) - 1];
// ---- Récupération du contenu
$oneFile = Storage::disk('arcadia')->get($filename);
$fileContent = simplexml_load_string($oneFile);
// ---- Récupération du contenu
$oneFile = Storage::disk('arcadia')->get($filename);
$fileContent = simplexml_load_string($oneFile);
// ---- traitement du fichier
if (substr($filename, 0, 16) == "DAM_ASSO_ARTICLE") {
foreach ($fileContent->mediaassoarticle as $row) {
$record = Media::where('arcadia_id', $row->codeVisuel)->first();
if($record){
$article = Article::where('noArt', $row->noArt)->first();
if($article){
// attache l'article au média
$record->articles()->syncWithoutDetaching ($article->id);
// recherche un dossier lié à la marque de l'article
$marque_id = $article->codMarq;
$dossier = Dossier::whereHas("marques", function($query) use ($marque_id){
$query->where("codMarq", $marque_id);
})->first();
// ---- traitement du fichier
$bar = $this->output->createProgressBar(count($fileContent->mediaassomarque)-1);
$bar->start();
foreach ($fileContent->mediaassomarque as $row) {
$record = Media::where('arcadia_id', $row->codeVisuel)->first();
if ($record) {
// attache la marque au média
$record->marques()->attach($row->codMarq);
} else {
$this->line("DAM_ASSO_MARQUE : le media n°" . $row->codeVisuel . " n'existe pas");
}
$bar->advance();
}
$bar->finish();
if($dossier){
// attache le dossier marque au Média
$record->dossier_id = $dossier->id;
$record->save();
$this->line("Liason media n°".$row->codeVisuel. " à la marque n°".$article->libMarq);
}else{
$this->line("pas de liaison de marque : le media n°".$row->codeVisuel. " ne peut être lié à l'article n°".$row->noArt);
}
}else{
$this->line("DAM_ASSO_ARTICLE : le media n°".$row->codeVisuel. " ne peut être lié à l'article n°".$row->noArt);
}
}else{
$this->line("DAM_ASSO_ARTICLE : le media n°".$row->codeVisuel. " n'existe pas");
}
}
// ---- Suppression du fichier
//Storage::disk('arcadia')->delete($filename);
}
// ---- Suppression du fichier
//Storage::disk('arcadia')->delete($filename);
}
}
// TODO : Import de l'association des sociétés
// ---- Traitement de l'association media <-> marque
$this->line("-> Import du fichier DAM_ASSO_MARQUE");
foreach ($files as $filename) {
if($filename == ".gitignore") continue;
// ---- Récupération du contenu
$oneFile = Storage::disk('arcadia')->get($filename);
$fileContent = simplexml_load_string($oneFile);
// ---- traitement du fichier
if (substr($filename, 0, 15) == "DAM_ASSO_MARQUE") {
foreach ($fileContent->mediaassomarque as $row) {
$record = Media::where('arcadia_id', $row->codeVisuel)->first();
if($record){
// attache la marque au média
$record->marques()->attach($row->codMarq);
}else{
$this->line("DAM_ASSO_MARQUE : le media n°".$row->codeVisuel. " n'existe pas");
}
}
// ---- Suppression du fichier
//Storage::disk('arcadia')->delete($filename);
}
}
// TODO : Import de l'association des sociétés
$this->line("");
$this->info('Fin du traitement');
}
$this->line("");
$this->info('Fin du traitement');
}
}

View file

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Http\Traits\ArcadiaLink;
use Elasticquent\ElasticquentTrait;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
@ -481,6 +482,16 @@ class MediaController extends Controller
$historique->description = "Média déplacé à la racine";
}
$media->save();
// Elasticsearch
$id = $media->id;
$media = Media::find($id);
$media->removeFromIndex();
$media->addToIndex();
// Lien Arcadia
ArcadiaLink::update($media);
$historique->save();
}
}
@ -511,7 +522,13 @@ class MediaController extends Controller
$historique->description = "Le média a été supprimé";
$historique->save();
// Elasticsearch
$media->removeFromIndex();
$media->delete();
// Lien Arcadia
ArcadiaLink::delete($media);
}
return json_encode($deletedMediasList);
@ -574,7 +591,6 @@ class MediaController extends Controller
{
Auth::user()->authorizeRoles([config('roles.const.ADMIN'), config('roles.const.REDACTEUR'), config('roles.const.CONTRIBUTEUR')]);
$user_id = Auth::user()->id;
$response = array();
$mediaUpdate = (object)$request->input('media');
$media = Media::where('id', $mediaUpdate->id)->first();
@ -651,9 +667,14 @@ class MediaController extends Controller
}
// ---- Index dans Elasticsearch
$id = $media->id;
$media = Media::find($id);
$media->removeFromIndex();
$media->addToIndex();
// Lien Arcadia
ArcadiaLink::update($media);
// ---- Historique des actions
$historique = new historique();
$historique->user_id = $user_id;
@ -664,7 +685,7 @@ class MediaController extends Controller
}
$response = true;
$response = array('status' => true, 'sujet_id' => $media->sujet_id);
return json_encode($response);
}
@ -698,6 +719,15 @@ class MediaController extends Controller
// ---- Sauvegarde de la nouvelle étiquette
$media->etiquette_id = $etiquette_id;
$media->save();
// ---- Index dans Elasticsearch
$id = $media->id;
$media = Media::find($id);
$media->removeFromIndex();
$media->addToIndex();
// Lien Arcadia
ArcadiaLink::update($media);
}
}
}
@ -752,6 +782,12 @@ class MediaController extends Controller
$media->taille = $this->formatBytes($this->get_file_size($mediaPath));
$media->save();
// ---- Index dans Elasticsearch
$id = $media->id;
$media = Media::find($id);
$media->removeFromIndex();
$media->addToIndex();
$historique = new historique();
$historique->user_id = Auth::user()->id;;
$historique->media_id = $media->id;
@ -764,6 +800,9 @@ class MediaController extends Controller
// ---- Creation des vignettes en lien avec le sujet du média
$this->create_thumb($media);
$response = $media;
// Lien Arcadia
ArcadiaLink::update($media);
}
return json_encode($response);
@ -778,28 +817,24 @@ class MediaController extends Controller
Auth::user()->authorizeRoles([config('roles.const.ADMIN')]);
$response = false;
$media_id = $request->input('media_id');
$arcadia_id = $request->input('arcadia_id');
$historique = new historique();
$historique->user_id = Auth::user()->id;
$historique->media_id = $media_id;
$historique->type = "Modification";
if ($arcadia_id == "" || $arcadia_id == 0) {
$arcadia_id = NULL;
$historique->description = "Suppression de la référence Arcadia";
} else {
$historique->description = "Ajout de la référence Arcadia " . $arcadia_id;
$media = Media::where('arcadia_id', $arcadia_id)->first();
if ($media) return json_encode($response);
}
$historique->description = "Ajout de la liaison Arcadia";
$media = Media::where('id', $media_id)->first();
if ($media) {
$media->arcadia_id = $arcadia_id;
$media->isLocked = 1;
$media->save();
// Lien Arcadia
ArcadiaLink::create($media);
// ---- Index dans Elasticsearch
$id = $media->id;
$media = Media::find($id);
$media->removeFromIndex();
$media->addToIndex();
@ -935,8 +970,13 @@ class MediaController extends Controller
$media->largeur_mm = "";
$media->hauteur_mm = "";
}
$media->isDefault = 1;
$media->save();
$id = $media->id;
$media = Media::find($id);
// ---- Index dans Elasticsearch
$media->addToIndex();
@ -960,7 +1000,6 @@ class MediaController extends Controller
$historique->description = "Média ajouté";
$historique->save();
return json_encode($response);
}
}

View file

@ -1,6 +1,7 @@
<?php
namespace App\Http\Controllers;
use App\Http\Traits\ArcadiaLink;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\Request;
@ -115,6 +116,10 @@ class UploadController extends Controller {
$filepath = preg_quote($media->folder.$media->uid, '/');
$matchingFiles = preg_grep('/^'.$filepath.'/', $filesfF);
Storage::delete($matchingFiles);
$media->isDefault = 0;
$media->save();
}else{
// On déplace le fichier dans le répertoire des médias
Storage::move("uploads/".$filename, $destinationPath.$filename);
@ -200,6 +205,8 @@ class UploadController extends Controller {
break;
}
$id = $media->id;
$media = Media::find($id);
// ---- Index dans Elasticsearch
$media->addToIndex();

View file

@ -0,0 +1,164 @@
<?php
namespace App\Http\Traits;
use App\Models\Format;
use App\Scopes\SystemScope;
use DOMDocument;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
trait ArcadiaLink {
public static function create($media)
{
self::convert(self::getXML($media, "C"), $media);
}
public static function update($media)
{
if ($media->arcadia_id === NULL)
return;
self::convert(self::getXML($media, "M"), $media);
}
public static function delete($media)
{
if ($media->arcadia_id === NULL)
return;
$dom = new DOMDocument('1.0','UTF-8');
$dom->formatOutput = true;
$root = $dom->createElement('MEDIA_VISUEL');
$dom->appendChild($root);
$root->appendChild($dom->createElement('codeArcadia'))->appendChild($dom->createCDATASection( "$media->arcadia_id"));
$root->appendChild($dom->createElement('code_DAM'))->appendChild($dom->createCDATASection( "$media->id"));
$root->appendChild( $dom->createElement('TypeMouvement'))->appendChild($dom->createCDATASection( "S"));
$xml = $dom->saveXML();
self::convert($xml, $media);
}
public static function reactivate($media)
{
if ($media->arcadia_id === NULL)
return;
$dom = new DOMDocument('1.0','UTF-8');
$dom->formatOutput = true;
$root = $dom->createElement('MEDIA_VISUEL');
$dom->appendChild($root);
$root->appendChild($dom->createElement('codeArcadia'))->appendChild($dom->createCDATASection( "$media->arcadia_id"));
$root->appendChild($dom->createElement('code_DAM'))->appendChild($dom->createCDATASection( "$media->id"));
$root->appendChild( $dom->createElement('TypeMouvement'))->appendChild($dom->createCDATASection( "R"));
$xml = $dom->saveXML();
self::convert($xml, $media);
}
private static function convert($xml, $media)
{
$uid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
Storage::disk('arcadia_link_s')->put("$uid.xml", $xml);
self::compress($media->folder, $media->uid, $media->extension, $uid);
}
private static function compress($folder, $name, $extension, $uid)
{
try {
$a = new \PharData( storage_path('arcadia_link/send') ."/$uid.tmp");
// ADD FILES TO archive.tar FILE
$a->addFile(storage_path('arcadia_link/send') . "/$uid.xml", 'media.xml');
$a->addFile(public_path() . "/$folder$name.$extension", "$name.$extension");
// COMPRESS archive.tar FILE. COMPRESSED FILE WILL BE archive.tar.gz
$a->compress(\Phar::NONE);
// NOTE THAT BOTH FILES WILL EXISTS. SO IF YOU WANT YOU CAN UNLINK archive.tar
unset($a);
unlink(storage_path('arcadia_link/send') . "/$uid.tmp");
unlink(storage_path('arcadia_link/send') . "/$uid.xml");
} catch (Exception $e) {
//echo "Exception : " . $e;
// TODO : Envoi mail Log
Log::emergency("Erreur création .tar : $e (Traits/ArcadiaLink)");
}
}
private static function getXML($media, $mouvement)
{
$refKey = self::getRefKey($media);
$formats = self::getFormats();
$dom = new DOMDocument('1.0','UTF-8');
$dom->formatOutput = true;
$root = $dom->createElement('MEDIA_VISUEL');
$dom->appendChild($root);
$root->appendChild($dom->createElement('codeArcadia'))->appendChild($dom->createCDATASection( "$media->arcadia_id"));
$root->appendChild($dom->createElement('code_DAM'))->appendChild($dom->createCDATASection( "$media->id"));
$root->appendChild( $dom->createElement('TypeMouvement'))->appendChild($dom->createCDATASection( "$mouvement"));
$cleRef = $root->appendChild( $dom->createElement('cle_Referentiel'));
foreach ($refKey as $k) {
$cleRef->appendChild( $dom->createElement('id'))->appendChild($dom->createCDATASection( "$k->id"));
}
$root->appendChild( $dom->createElement('libExtension'))->appendChild($dom->createCDATASection( "$media->extension"));
$root->appendChild( $dom->createElement('nbPxLargeur'))->appendChild($dom->createCDATASection( "$media->largeur"));
$root->appendChild( $dom->createElement('largeurMm'))->appendChild($dom->createCDATASection( "$media->largeur_mm"));
$root->appendChild( $dom->createElement('nbPxHauteur'))->appendChild($dom->createCDATASection( "$media->hauteur"));
$root->appendChild( $dom->createElement('hauteurMm'))->appendChild($dom->createCDATASection( "$media->hauteur_mm"));
$root->appendChild( $dom->createElement('pppLargeur'))->appendChild($dom->createCDATASection( "$media->resolution"));
$root->appendChild( $dom->createElement('version'))->appendChild($dom->createCDATASection( "$media->version"));
$root->appendChild( $dom->createElement('codeTypeMedia'))->appendChild($dom->createCDATASection( "$media->typemedia_id"));
$root->appendChild( $dom->createElement('codeTypeVue'))->appendChild($dom->createCDATASection( "$media->typevue_id"));
$root->appendChild( $dom->createElement('commentaire'))->appendChild($dom->createCDATASection( "$media->commentaire"));
$root->appendChild( $dom->createElement('codeSujet'))->appendChild($dom->createCDATASection( "$media->sujet_id"));
$root->appendChild( $dom->createElement('langue'))->appendChild($dom->createCDATASection( "$media->langue_id"));
$root->appendChild( $dom->createElement('copyright'))->appendChild($dom->createCDATASection( "$media->copyright_id"));
$root->appendChild( $dom->createElement('codeVariante'))->appendChild($dom->createCDATASection( "$media->variante_id"));
$root->appendChild( $dom->createElement('dateCreation'))->appendChild($dom->createCDATASection( "$media->created_at"));
$root->appendChild( $dom->createElement('dateModification'))->appendChild($dom->createCDATASection( "$media->updated_at"));
$root->appendChild( $dom->createElement('datePublication'))->appendChild($dom->createCDATASection( "$media->published_at"));
$root->appendChild( $dom->createElement('libelle'))->appendChild($dom->createCDATASection( "$media->libelle"));
$root->appendChild( $dom->createElement('NomFichier'))->appendChild($dom->createCDATASection( "$media->uid.$media->extension"));
$mediaFormat = $root->appendChild( $dom->createElement('formats'));
foreach ($formats as $k) {
$format = $mediaFormat->appendChild( $dom->createElement('format'));
$format->appendChild( $dom->createElement('id'))->appendChild($dom->createCDATASection( $k['id']));
$format->appendChild( $dom->createElement('libelle'))->appendChild($dom->createCDATASection( $k['libelle']));
$format->appendChild( $dom->createElement('extension'))->appendChild($dom->createCDATASection("$media->extension"));
$format->appendChild( $dom->createElement('largeur'))->appendChild($dom->createCDATASection( $k['largeur']));
$format->appendChild( $dom->createElement('hauteur'))->appendChild($dom->createCDATASection( $k['hauteur']));
$format->appendChild( $dom->createElement('lien'))->appendChild($dom->createCDATASection(env('APP_URL') . "/$media->folder$media->uid" . "_" . $k['libelle'] . ".$media->extension"));
}
return $dom->saveXML();
}
private static function getRefKey($media)
{
switch ($media->sujet_id){
case 1:
return $media->articles()->get();
break;
case 2:
return $media->marques()->get();
break;
case 4:
return $media->societes()->get();
break;
default:
return [];
}
}
private static function getFormats()
{
return Format::withoutGlobalScope(SystemScope::class)->where('system', '=', '1')->get();
}
}

View file

@ -1,7 +1,6 @@
<?php
namespace App\Http\Traits;
use Elasticquent\ElasticquentTrait;
use Illuminate\Support\Facades\Storage;
trait ElasticTrait {

View file

@ -12,7 +12,7 @@ trait MediaTools {
$formats = $media->sujet->formats;
$mediaPath = public_path()."/".$media->folder.$media->uid.".".$media->extension;
$im = new \imagick($mediaPath);
$im = new \Imagick($mediaPath);
$im->setImageBackgroundColor('#ffffff');
$im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_REMOVE);
$im->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
@ -38,12 +38,13 @@ trait MediaTools {
$im->writeImage($fp);
}
$im->destroy();
unset($im);
}
public function create_sys_thumb($media) {
$mediaPath = public_path()."/".$media->folder.$media->uid.".".$media->extension;
$im = new \imagick();
$im = new \Imagick();
$im->readImage($mediaPath);
if(in_array($media->extension, array("pdf", "ai", "psd")) ){
@ -82,6 +83,7 @@ trait MediaTools {
$im->thumbnailImage(200, 200 , true);
$im->writeImage($fp);
$im->destroy();
unset($im);
}
public function get_mediaFolder() {

View file

@ -60,6 +60,15 @@ return [
'root' => storage_path('export_arcadia'),
],
'arcadia_link_s' => [
'driver' => 'local',
'root' => storage_path('arcadia_link/send'),
],
'arcadia_link_r' => [
'driver' => 'local',
'root' => storage_path('arcadia_link/receive'),
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),

49
resources/js/media.js vendored
View file

@ -713,7 +713,7 @@ $(document).ready(function() {
},
success: function(result){
// chargement des données
$(".tab_edit #arcadia_id").val(result.data.arcadia_id);
$(".tab_edit #arcadia_id").val(result.data.arcadia_id);
$(".tab_edit #libelle").val(result.data.libelle);
$(".tab_edit #sujetLibelle").val(result.data.sujet.libelle);
$(".tab_edit #typevues").val(result.data.typevue_id);
@ -786,11 +786,33 @@ $(document).ready(function() {
$(".tab_edit #hauteur_mm").val(result.data.hauteur_mm);
// Config de la fiche d'édition
if(result.data.sujet.sujet_arcadia == 0){
// Si le media n'est pas un sujet Arcadia ou si le media n'est pas une image on masque l'option Arcadia
// 1 = Photos et 5 = jpg
if(result.data.sujet.sujet_arcadia == 0 || result.data.isDefault == 1 || (result.data.typemedia_id != 1 && result.data.typemedia_id != 5)){
$(".tab_edit .arcadia_fields").hide();
}else{
$(".tab_edit .arcadia_fields").show();
}
// Si le media est lie a Arcadia ou si le media est en attente d'Arcadia
if (result.data.arcadia_id != null || result.data.isLocked == 1){
$(".btn-arcadia-link").hide();
$(".btn-arcadia-remove-link").show();
}else{
$(".btn-arcadia-link").show();
$(".btn-arcadia-remove-link").hide();
}
// Si le media est en attente d'Arcadia
if(result.data.isLocked == 1){
$(".btn-arcadia-remove-link").attr('disabled', true);
$(".btn_tab_edit_save").attr('disabled', true);
$(".is-locked").show();
}else{
$(".btn-arcadia-remove-link").attr('disabled', false);
$(".btn_tab_edit_save").attr('disabled', false);
$(".is-locked").hide();
}
$(".tab_edit .article_form, .tab_edit .marque_form, .tab_edit .societe_form").hide();
switch (result.data.sujet_id) {
case 1: // Visuel Article
@ -865,38 +887,24 @@ $(document).ready(function() {
// ---- Bouton Arcadia
$('.tab_edit .btn-arcadia-link').on('click', function(event){
event.preventDefault();
var arcadia_id = $("#arcadia_id").val();
arcadia_id = prompt("Indiquez le code Arcadia de ce média", arcadia_id);
// Si la saisie est vide on affiche le message d'erreur et on n'execute pas l'ajax
if (arcadia_id === "") {
$.fancybox.close();
$.fancyMessage({
title: "Lier un média à Arcadia",
message: "Le code Arcadia est vide.",
type: "error"
});
var result = confirm("Etes-vous sur de vouloir lancer le traitement ?");
if (result != true)
return;
}else if (arcadia_id === null) {
return;
}
$.ajax({
url: '/ajax/set-id-arcadia',
method: 'POST',
dataType : 'json',
data: {
arcadia_id: arcadia_id,
media_id : $(window).data('current_edit_media'),
},
success: function(result){
if(result == true){
$.fancybox.close();
$.fancyMessage({title : "Lier un média à Arcadia", message : "Le code Arcadia a bien été ajouté au média", type : "info"});
$("#arcadia_id").val(arcadia_id);
$.fancyMessage({title : "Lier un média à Arcadia", message : "La demande à été effectuée, votre média est temporairement bloqué.", type : "info"});
}else{
$.fancybox.close();
$.fancyMessage({title : "Lier un média à Arcadia", message : "Ce code a déjà été attribué à un autre média. Ajout impossible.", type : "error"});
$.fancyMessage({title : "Lier un média à Arcadia", message : "Une erreur est survenue. Traitement impossible.", type : "error"});
}
},
error: function(jqXHR, textStatus, errorThrown) {
@ -1164,6 +1172,7 @@ $(document).ready(function() {
},
success: function(result){
$.fancyMessage({title : "Sauvegarde d'un média", message : "Les données ont bien été enregistrées", type : "info"});
loadMedia(result.sujet_id);
},
error: function(jqXHR, textStatus, errorThrown) {
$.fancyMessage({title : "Sauvegarde d'un média", message : "Erreur lors de l'enregistrement. Merci d'actualiser la page.", type : "error"});

View file

@ -21,11 +21,12 @@
<h3>Informations générales</h3>
<form class="form_edit_media" action="#" method="post">
<div class="row arcadia_fields">
<label for="arcadia_id">Code Arcadia</label>
<label for="arcadia_id">Arcadia</label>
<input type="text" name="arcadia_id" id="arcadia_id" readonly>
<div class="">
<input type="number" value="" id="arcadia_id" name="arcadia_id" readonly >
@if (Auth::user()->hasRole(config('roles.const.ADMIN')))
<button class="btn btn-square ml-10 btn-arcadia-link" type="button" name="button"><i class="far fa-link"></i> Lien avec Arcadia</button>
<button class="btn btn-square ml-10 btn-arcadia-link" type="button" name="button"><i class="far fa-link"></i> Lier avec Arcadia</button>
<span class="is-locked" style="display: none;">En attente de liaison Arcadia</span>
@endif
</div>
</div>
@ -221,6 +222,9 @@
</div>
<div class="button_bar">
<a href="#" class="btn btn-black mr-10 btn_tab_edit_cancel">Fermer</a>
@if (Auth::user()->hasRole(config('roles.const.ADMIN')))
<button class="btn btn-red btn_tab_edit_delete" type="button" name="button">Supprimer</button>
@endif
@if (Auth::user()->hasRole([config('roles.const.CONTRIBUTEUR'), config('roles.const.ADMIN'), config('roles.const.REDACTEUR')]))
<button class="btn btn_tab_edit_save" type="button" name="button">Sauvegarder</button>
@endif

View file

@ -0,0 +1 @@
gitkeep

View file

@ -0,0 +1 @@
gitkeep

View file

@ -0,0 +1 @@
gitkeep