55namespace CraftCms \Cms \Console \Commands \Utils ;
66
77use Craft ;
8- use craft \elements \Asset ;
98use craft \errors \InvalidElementException ;
109use craft \helpers \FileHelper ;
1110use CraftCms \Cms \Config \GeneralConfig ;
1211use CraftCms \Cms \Console \CraftCommand ;
12+ use CraftCms \Cms \Element \Elements \Asset ;
13+ use Exception ;
1314use Illuminate \Console \Command ;
1415use Illuminate \Support \Facades \DB ;
1516use Throwable ;
16- use yii \db \Expression ;
1717
1818use function Laravel \Prompts \confirm ;
1919
@@ -42,15 +42,15 @@ public function handle(GeneralConfig $generalConfig): int
4242
4343 match (DB ::connection ()->getDriverName ()) {
4444 // h/t https://stackoverflow.com/a/11741314/1688568
45- 'mysql ' => $ query ->andWhere ( new Expression ( ' [[ filename]] <> CONVERT([[ filename]] USING ASCII) ') ),
45+ 'mysql ' => $ query ->whereRaw ( ' filename <> CONVERT(filename USING ASCII) ' ),
4646 // h/t https://dba.stackexchange.com/a/167571/205387
47- 'pgsql ' => $ query ->andWhere ( new Expression ( " [[ filename]] ~ '[^[:ascii:]]' ") ),
48- default => throw new \ Exception ('Invalid driver name: ' .DB ::connection ()->getDriverName ().'. ' )
47+ 'pgsql ' => $ query ->whereRaw ( " filename ~ '[^[:ascii:]]' " ),
48+ default => throw new Exception ('Invalid driver name: ' .DB ::connection ()->getDriverName ().'. ' )
4949 };
5050
51- /** @var Asset[] $assets */
52- $ assets = $ query ->all ();
53- $ total = count ( $ assets );
51+ /** @var \Illuminate\Support\Collection< Asset> $assets */
52+ $ assets = $ query ->get ();
53+ $ total = $ assets-> count ( );
5454
5555 if ($ total === 0 ) {
5656 $ this ->components ->success ('No assets found with non-ASCII filenames. ' );
@@ -60,10 +60,9 @@ public function handle(GeneralConfig $generalConfig): int
6060
6161 $ this ->components ->info ("$ total assets found with non-ASCII filenames: " );
6262
63- $ this ->components ->bulletList (array_map (
63+ $ this ->components ->bulletList ($ assets -> map (
6464 fn (Asset $ asset ) => $ asset ->getFilename (),
65- $ assets ,
66- ));
65+ )->all ());
6766
6867 if (! confirm ('Ready to rename these filenames as ASCII? ' )) {
6968 return self ::SUCCESS ;
0 commit comments