-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathUpdateAssetReferencesToUseModelKeys.php
51 lines (42 loc) · 1.43 KB
/
UpdateAssetReferencesToUseModelKeys.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Statamic\Eloquent\Commands;
use Illuminate\Console\Command;
use Statamic\Assets\AssetReferenceUpdater;
use Statamic\Console\RunsInPlease;
use Statamic\Contracts\Assets\AssetContainer;
use Statamic\Facades;
class UpdateAssetReferencesToUseModelKeys extends Command
{
use RunsInPlease;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'statamic:eloquent:update-asset-references-to-use-model-keys {--container=all}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update container::path references to container::asset_model_key';
/**
* Execute the console command.
*/
public function handle()
{
Facades\AssetContainer::all()
->reject(fn ($container) => $this->option('container') != 'all' && $this->option('container') != $container->handle())
->each(fn ($container) => $this->processContainer($container));
$this->info('Complete');
}
private function processContainer(AssetContainer $container)
{
$this->info("Container: {$container->handle()}");
$container->queryAssets()->get()->each(function ($item) use ($container) {
return AssetReferenceUpdater::item($item)
->filterByContainer($container)
->updateReferences($item->path(), $item->id());
});
}
}