oci_migrate set picture as nullable
This commit is contained in:
parent
39fc13dfe2
commit
e6796029ec
1 changed files with 18 additions and 18 deletions
|
|
@ -334,26 +334,25 @@ return new class extends Migration
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @var \App\Models\Product $product */
|
||||
$product = Product::query()->where('id', $row->{$index})->firstOrNew();
|
||||
$product->id = $row->NUM_VEILLE_PROD;
|
||||
|
||||
// * DOCS
|
||||
$disk = $this->getMigrationStorage('Produit/' . strval($row->{$index}));
|
||||
$files = collect($disk->files())->mapWithKeys(function ($file) use ($disk, $product) {
|
||||
$files = $disk ? collect($disk->files())->mapWithKeys(function (string $file) use ($disk, $product) {
|
||||
$filePath = FileStorageHelper::storeFile($product, new \SplFileInfo($disk->path($file)));
|
||||
return [pathinfo($filePath, PATHINFO_BASENAME) => $filePath];
|
||||
});
|
||||
}) : null;
|
||||
|
||||
$picture = $files->getOrPut('ref.jpg', FileStorageHelper::storeFile(
|
||||
$product,
|
||||
new \SplFileInfo(app_path(
|
||||
'../database/factories/assets/product/default-picture-1200x900.png'
|
||||
))
|
||||
));
|
||||
$files->pull('ref.jpg');
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
$pictureKey = $files ? $files->map(fn (string $filePath, string $fileName) => $fileName)
|
||||
->first(fn ($fileName) => preg_match('/ref-[0-9a-z]*.jpg/', $fileName) !== false) : null;
|
||||
$picture = $files ? $files->get($pictureKey) : null;
|
||||
if ($files) {
|
||||
$files->pull($pictureKey);
|
||||
$files = $files->values();
|
||||
}
|
||||
|
||||
$fill = [
|
||||
'brand_id' => $brand->id,
|
||||
|
|
@ -377,7 +376,7 @@ return new class extends Migration
|
|||
'specified_claim' => $claim,
|
||||
'tasters_number' => $row->NB_DEGUST,
|
||||
'origins' => $originList,
|
||||
'docs' => $files->all(),
|
||||
'docs' => $files,
|
||||
'picture_alt' => "Image de {$row->NOM}",
|
||||
'picture_title' => "Image de {$row->NOM}",
|
||||
'picture' => $picture,
|
||||
|
|
@ -509,25 +508,26 @@ return new class extends Migration
|
|||
* Get migration disk
|
||||
*
|
||||
* @param string|null $path Get a specific path.
|
||||
* @return \Illuminate\Filesystem\FilesystemAdapter
|
||||
* @return \Illuminate\Filesystem\FilesystemAdapter|null
|
||||
* @throws \Error If veille folder is missing.
|
||||
*/
|
||||
private function getMigrationStorage(string $path = '')
|
||||
private function getMigrationStorage(string $path = ''): \Illuminate\Filesystem\FilesystemAdapter|null
|
||||
{
|
||||
$storagePath = storage_path('app/migration');
|
||||
$path = "/Veille/{$path}";
|
||||
|
||||
if (!File::exists("{$storagePath}{$path}")) {
|
||||
throw new \Error("Missing storage path {$storagePath}{$path}");
|
||||
return null;
|
||||
}
|
||||
$diskName = 'migration' . Str::of("{$storagePath}{$path}")->slug();
|
||||
|
||||
config()->set('filesystems.disks.migration', [
|
||||
config()->set("filesystems.disks.{$diskName}", [
|
||||
'driver' => 'local',
|
||||
'root' => "{$storagePath}{$path}",
|
||||
'throw' => true,
|
||||
'throw' => false,
|
||||
]);
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter */
|
||||
$disk = Storage::disk('migration');
|
||||
$disk = Storage::disk($diskName);
|
||||
|
||||
|
||||
return $disk;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue