1515use OCP \Files \IRootFolder ;
1616use OCP \FilesMetadata \Exceptions \FilesMetadataNotFoundException ;
1717use OCP \FilesMetadata \IFilesMetadataManager ;
18- use OCP \IConfig ;
18+ use OCP \IAppConfig ;
1919use OCP \IUserManager ;
2020use Psr \Log \LoggerInterface ;
2121
2222class GenerateMetadataJob extends TimedJob {
2323 public function __construct (
2424 ITimeFactory $ time ,
25- private IConfig $ config ,
25+ private IAppConfig $ appConfig ,
2626 private IRootFolder $ rootFolder ,
2727 private IUserManager $ userManager ,
2828 private IFilesMetadataManager $ filesMetadataManager ,
@@ -36,8 +36,13 @@ public function __construct(
3636 }
3737
3838 protected function run (mixed $ argument ): void {
39+ if ($ this ->appConfig ->getValueBool ('core ' , 'metadataGenerationDone ' , false )) {
40+ return ;
41+ }
42+
43+ $ lastHandledUser = $ this ->appConfig ->getValueString ('core ' , 'metadataGenerationLastHandledUser ' , '' );
44+
3945 $ users = $ this ->userManager ->search ('' );
40- $ lastHandledUser = $ this ->config ->getAppValue ('core ' , 'metadataGenerationLastHandledUser ' , '' );
4146
4247 // we'll only start timer once we have found a valid user to handle
4348 // meaning NOW if we have not handled any user from a previous run
@@ -53,7 +58,7 @@ protected function run(mixed $argument): void {
5358 continue ;
5459 }
5560
56- $ this ->config -> setAppValue ('core ' , 'metadataGenerationLastHandledUser ' , $ userId );
61+ $ this ->appConfig -> setValueString ('core ' , 'metadataGenerationLastHandledUser ' , $ userId );
5762 $ this ->scanFilesForUser ($ user ->getUID ());
5863
5964 // Stop if execution time is more than one hour.
@@ -62,8 +67,8 @@ protected function run(mixed $argument): void {
6267 }
6368 }
6469
65- $ this ->jobList -> remove (GenerateMetadataJob::class );
66- $ this ->config -> deleteAppValue ('core ' , 'metadataGenerationLastHandledUser ' );
70+ $ this ->appConfig -> deleteKey ( ' core ' , ' metadataGenerationLastHandledUser ' );
71+ $ this ->appConfig -> setValueBool ('core ' , 'metadataGenerationDone ' , true );
6772 }
6873
6974 private function scanFilesForUser (string $ userId ): void {
0 commit comments