diff --git a/src/Assets/Asset.php b/src/Assets/Asset.php index f820b780c9..f0ec427002 100644 --- a/src/Assets/Asset.php +++ b/src/Assets/Asset.php @@ -67,10 +67,15 @@ class Asset implements Arrayable, ArrayAccess, AssetContract, Augmentable, Conta } protected $container; + protected $path; + protected $meta; + protected $withEvents = true; + protected $shouldHydrate = true; + protected $removedData = []; public function syncOriginal() @@ -745,11 +750,7 @@ public function containerHandle() */ public function rename($filename, $unique = false) { - if ($unique) { - return $this->moveUnique($this->folder(), $filename); - } - - return $this->move($this->folder(), $filename); + return $this->move($this->folder(), $filename, $unique); } /** @@ -757,11 +758,13 @@ public function rename($filename, $unique = false) * * @param string $folder The folder relative to the container. * @param string|null $filename The new filename, if renaming. + * @param bool $unique Whether to ensure the filename is unique. * @return $this */ - public function move($folder, $filename = null) + public function move($folder, $filename = null, $unique = false) { $filename = Uploader::getSafeFilename($filename ?: $this->filename()); + $filename = $unique ? $this->ensureUniqueFilename($folder, $filename) : $filename; $oldPath = $this->path(); $oldMetaPath = $this->metaPath(); $newPath = Str::removeLeft(Path::tidy($folder.'/'.$filename.'.'.pathinfo($oldPath, PATHINFO_EXTENSION)), '/'); @@ -780,21 +783,6 @@ public function move($folder, $filename = null) return $this; } - /** - * Move the asset to a different location with a unique filename. - * - * @param string $folder The folder relative to the container. - * @param string|null $filename The new filename, if renaming. - * @return $this - */ - public function moveUnique($folder, $filename = null) - { - $filename = Uploader::getSafeFilename($filename ?: $this->filename()); - $filename = $this->ensureUniqueFilename($folder, $filename); - - return $this->move($folder, $filename); - } - public function moveQuietly($folder, $filename = null) { $this->withEvents = false; diff --git a/tests/Assets/AssetTest.php b/tests/Assets/AssetTest.php index 29c1cc6064..1b3a7249b1 100644 --- a/tests/Assets/AssetTest.php +++ b/tests/Assets/AssetTest.php @@ -50,7 +50,7 @@ class AssetTest extends TestCase private $container; - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -939,7 +939,7 @@ public function it_saves_quietly() } #[Test] - public function when_saving_quietly_the_cached_assets_withEvents_flag_will_be_set_back_to_true() + public function when_saving_quietly_the_cached_assets_with_events_flag_will_be_set_back_to_true() { Event::fake(); Storage::fake('test'); @@ -1261,7 +1261,7 @@ public function it_doesnt_lowercase_moved_files_when_configured() } #[Test] - public function it_can_be_moved_uniquely_to_another_folder_when_conflict_exists() + public function it_can_be_moved_to_another_folder_with_a_unique_filename_when_conflict_exists() { Storage::fake('local'); $disk = Storage::disk('local'); @@ -1274,7 +1274,7 @@ public function it_can_be_moved_uniquely_to_another_folder_when_conflict_exists( $asset = $container->makeAsset('old/asset.txt')->data(['foo' => 'bar']); $asset->save(); - $return = $asset->moveUnique('new'); + $return = $asset->move('new', null, true); $this->assertEquals($asset, $return); $disk->assertMissing('old/asset.txt'); @@ -1283,7 +1283,7 @@ public function it_can_be_moved_uniquely_to_another_folder_when_conflict_exists( } #[Test] - public function it_can_be_moved_uniquely_to_another_folder_without_renaming_when_no_conflict() + public function it_can_be_moved_to_another_folder_with_a_unique_filename_without_renaming_when_no_conflict() { Storage::fake('local'); $disk = Storage::disk('local'); @@ -1294,7 +1294,7 @@ public function it_can_be_moved_uniquely_to_another_folder_without_renaming_when $asset = $container->makeAsset('old/asset.txt')->data(['foo' => 'bar']); $asset->save(); - $return = $asset->moveUnique('new'); + $return = $asset->move('new', null, true); $this->assertEquals($asset, $return); $disk->assertMissing('old/asset.txt'); @@ -2479,6 +2479,7 @@ public function augment($value) $relationshipFieldtype = new class extends Fieldtype { protected static $handle = 'relationship'; + protected $relationship = true; public function augment($values)