@@ -30,6 +30,7 @@ class CloudinaryScanService
3030 private const UPDATED = 'updated ' ;
3131 private const DELETED = 'deleted ' ;
3232 private const TOTAL = 'total ' ;
33+ private const FAILED = 'failed ' ;
3334 private const FOLDER_DELETED = 'folder_deleted ' ;
3435
3536 /**
@@ -55,6 +56,7 @@ class CloudinaryScanService
5556 self ::UPDATED => 0 ,
5657 self ::DELETED => 0 ,
5758 self ::TOTAL => 0 ,
59+ self ::FAILED => 0 ,
5860
5961 self ::FOLDER_DELETED => 0 ,
6062 ];
@@ -143,34 +145,42 @@ public function scan(): array
143145
144146 if (is_array ($ response ['resources ' ])) {
145147 foreach ($ response ['resources ' ] as $ resource ) {
146-
147148 $ fileIdentifier = $ this ->getCloudinaryPathService ()->computeFileIdentifier ($ resource );
148- if ($ this ->io ) {
149- $ this ->io ->writeln ($ fileIdentifier );
150- }
149+ try {
150+ if ($ this ->io ) {
151+ $ this ->io ->writeln ($ fileIdentifier );
152+ }
151153
152- // Save mirrored file
153- $ result = $ this ->getCloudinaryResourceService ()->save ($ resource );
154+ // Save mirrored file
155+ $ result = $ this ->getCloudinaryResourceService ()->save ($ resource );
154156
155- // Find if the file exists in sys_file already
156- if (!$ this ->fileExistsInStorage ($ fileIdentifier )) {
157+ // Find if the file exists in sys_file already
158+ if (!$ this ->fileExistsInStorage ($ fileIdentifier )) {
157159
158- if ($ this ->io ) {
159- $ this ->io ->writeln ('Indexing new file: ' . $ fileIdentifier );
160- $ this ->io ->writeln ('' );
161- }
160+ if ($ this ->io ) {
161+ $ this ->io ->writeln ('Indexing new file: ' . $ fileIdentifier );
162+ $ this ->io ->writeln ('' );
163+ }
162164
163- // This will trigger a file indexation
164- $ this ->storage ->getFile ($ fileIdentifier );
165- }
165+ // This will trigger a file indexation
166+ $ this ->storage ->getFile ($ fileIdentifier );
167+ }
166168
167- // For the stats, we collect the number of files touched
168- $ key = key ($ result );
169- $ this ->statistics [$ key ] += $ result [$ key ];
169+ // For the stats, we collect the number of files touched
170+ $ key = key ($ result );
171+ $ this ->statistics [$ key ] += $ result [$ key ];
170172
171- // In any case we can add a file to the counter.
172- // Later we can verify the total corresponds to the "created" + "updated" + "deleted" files
173- $ this ->statistics [self ::TOTAL ]++;
173+ // In any case we can add a file to the counter.
174+ // Later we can verify the total corresponds to the "created" + "updated" + "deleted" files
175+ $ this ->statistics [self ::TOTAL ]++;
176+ }
177+ catch (\Exception $ e ) {
178+ $ this ->statistics [self ::FAILED ]++;
179+ if ($ this ->io ) {
180+ $ this ->io ->warning (sprintf ('Error could not process "%s" ' , $ fileIdentifier ));
181+ }
182+ // ignore
183+ }
174184 }
175185 }
176186 } while (!empty ($ response ) && isset ($ response ['next_cursor ' ]));
0 commit comments