ldc-dam/app/Jobs/Arcadia/XmlArcadiaMediasIn.php
Jérémy Munsch 9767e62c72
Update NPM deps and webpack.mix.js
composer require ldc/web-status-checker-laravel remove Old static status checker

Fix ImportMedia

WIP commands OK

many fixes

Fix and try to optimize folder component

Fix front icons + actions based on icons

Favico

front fix alert

Fix Media upload on depot

fix folder component buttons

Full front fix with perf due tu vuejs

Download medias

Navigate within medias superfix

Move media + loader

isLocked boolean and remove media fix

Folder scroll fix

arcadia link color red

Fix panier show external

Tons of fixes back as front

REwrited all
2022-07-22 17:00:48 +02:00

117 lines
3.5 KiB
PHP

<?php
namespace App\Jobs\Arcadia;
use App\Exceptions\AbortXmlImportException;
use App\Models\ArcadiaLink;
use App\Models\Media;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class XmlArcadiaMediasIn extends XmlJobs
{
/**
* The xsd file path used to validate files
*
* @var string|null
*/
protected $xsdSchemaPath = 'resources/documents/arcadia/incoming_medias.xsd';
/**
* Disk name from config/filesystems.php
*
* @var string
*/
protected $disk = 'arcadia_link_r';
/**
* The columns to take from the XML subcolumns can be added with a dot
*
* @var array
*/
protected $takeColumns = [
'code_DAM' => 'id',
'codeArcadia' => 'arcadia_id',
'version' => 'version'
];
/**
* The columns allowed to be null
*
* @var array
*/
protected $nullableFields = [];
/**
* Fields that are unique
*
* @var array
*/
protected $uniqueKeyField = [
'id'
];
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
$this->parseData('MEDIA_VISUEL', Media::class, function (\SimpleXMLElement $xmlData, array &$line) {
// * After XML parse Callback.
// * Unlock media
$line['isLocked'] = false;
}, function (array $uniqueColumnsKey, $line) {
// * DO the DB save yourself callback
try {
/** @var \App\Models\Media $media */
$media = Media::withTrashed()->where($uniqueColumnsKey)->firstOrFail();
$media->arcadia_id = $line['arcadia_id'];
$media->version = $line['version'];
$media->isLocked = false;
$media->saveOrFail();
} catch (ModelNotFoundException $e) {
$e = new AbortXmlImportException(
sprintf('La fiche media \'%s\' ne peut être trouvé', \json_encode($uniqueColumnsKey)),
0,
$e
);
throw $e;
}//end try
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
}, function (\SimpleXMLElement $xmlData, array &$line) {
// * After DB save Callback.
$media = null;
try {
/** @var \App\Models\Media $media */
$media = Media::withTrashed()->findOrFail($line['id']);
} catch (ModelNotFoundException $e) {
$e = new AbortXmlImportException(
\sprintf('La fiche media \'%s\' ne peut être trouvé', $line['id']),
0,
$e
);
throw $e;
}
try {
// * Suppression dans la supervision Arcadia Link
/** @var \App\Models\ArcadiaLink|null */
$arcadiaLink = ArcadiaLink::where('media_id', $media->id)->first();
if ($arcadiaLink) {
$arcadiaLink->deleteOrFail();
}
// * Save into elastic if media is not soft deleted, remove otherwise.
!$media->trashed() ? $media->addToElasticSearch() : $media->removeFromElasticSearch();
} catch (\RuntimeException $e) {
throw new AbortXmlImportException($e->getMessage());
} //end try
});
}
}