diff --git a/src/Assets/Asset.php b/src/Assets/Asset.php index 8fab3951..6404c507 100644 --- a/src/Assets/Asset.php +++ b/src/Assets/Asset.php @@ -129,7 +129,7 @@ public function writeMeta($meta) { $meta['data'] = Arr::removeNullValues($meta['data']); - self::makeModelFromContract($this, $meta); + self::makeModelFromContract($this, $meta)?->save(); Blink::put('eloquent-asset-meta-exists-'.$this->id(), true); } @@ -166,8 +166,6 @@ public static function makeModelFromContract(AssetContract $source, $meta = []) $model->updated_at = $meta['last_modified']; } - $model->save(); - return $model; } diff --git a/src/Assets/AssetContainer.php b/src/Assets/AssetContainer.php index ec1ecf8a..43bcfbf5 100644 --- a/src/Assets/AssetContainer.php +++ b/src/Assets/AssetContainer.php @@ -60,23 +60,7 @@ public function fillFromModel(Model $model) public function toModel() { - $class = app('statamic.eloquent.assets.container_model'); - - return $class::firstOrNew(['handle' => $this->handle()])->fill([ - 'title' => $this->title(), - 'disk' => $this->diskHandle() ?? config('filesystems.default'), - 'settings' => [ - 'allow_uploads' => $this->allowUploads(), - 'allow_downloading' => $this->allowDownloading(), - 'allow_moving' => $this->allowMoving(), - 'allow_renaming' => $this->allowRenaming(), - 'create_folders' => $this->createFolders(), - 'search_index' => $this->searchIndex(), - 'source_preset' => $this->sourcePreset, - 'warm_presets' => $this->warmPresets, - 'validation_rules' => $this->validationRules(), - ], - ]); + return self::makeModelFromContract($this); } public static function makeModelFromContract(AssetContainerContract $source) @@ -103,8 +87,6 @@ public static function makeModelFromContract(AssetContainerContract $source) $model->updated_at = $source->fileLastModified(); } - $model->save(); - return $model; } diff --git a/src/Commands/ImportAssets.php b/src/Commands/ImportAssets.php index dba8ae54..50d44183 100644 --- a/src/Commands/ImportAssets.php +++ b/src/Commands/ImportAssets.php @@ -70,7 +70,7 @@ private function importAssetContainers(): void } $this->withProgressBar(AssetContainerFacade::all(), function ($container) { - AssetContainer::makeModelFromContract($container); + AssetContainer::makeModelFromContract($container)?->save(); }); $this->components->info('Assets containers imported sucessfully'); @@ -83,7 +83,7 @@ private function importAssets(): void } $this->withProgressBar(AssetFacade::all(), function ($asset) { - EloquentAsset::makeModelFromContract($asset); + EloquentAsset::makeModelFromContract($asset)?->save(); }); $this->components->info('Assets imported sucessfully');