2023-05-09 13:17:39 -04:00
< ? php
declare ( strict_types = 1 );
/**
2024-05-27 11:39:07 -04:00
* SPDX - FileCopyrightText : 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2023-05-09 13:17:39 -04:00
*/
namespace OCA\DAV\Migration ;
use Closure ;
use OCA\DAV\CardDAV\SyncService ;
use OCP\DB\ISchemaWrapper ;
2023-08-17 04:19:10 -04:00
use OCP\IConfig ;
use OCP\IUserManager ;
2023-05-09 13:17:39 -04:00
use OCP\Migration\IOutput ;
use OCP\Migration\SimpleMigrationStep ;
use Psr\Log\LoggerInterface ;
2023-06-26 04:52:07 -04:00
use Throwable ;
2023-05-09 13:17:39 -04:00
class Version1027Date20230504122946 extends SimpleMigrationStep {
2023-08-17 04:19:10 -04:00
public function __construct (
private SyncService $syncService ,
private LoggerInterface $logger ,
private IUserManager $userManager ,
private IConfig $config ,
) {
}
2023-05-09 13:17:39 -04:00
/**
* @ param IOutput $output
* @ param Closure () : ISchemaWrapper $schemaClosure
* @ param array $options
*/
public function postSchemaChange ( IOutput $output , Closure $schemaClosure , array $options ) : void {
2025-01-14 06:38:02 -05:00
if ( $this -> userManager -> countSeenUsers () > 100 || $this -> userManager -> countUsersTotal ( 100 ) >= 100 ) {
2023-08-17 04:19:10 -04:00
$this -> config -> setAppValue ( 'dav' , 'needs_system_address_book_sync' , 'yes' );
$output -> info ( 'Could not sync system address books during update - too many user records have been found. Please call occ dav:sync-system-addressbook manually.' );
return ;
}
2023-06-26 04:52:07 -04:00
try {
$this -> syncService -> syncInstance ();
2023-08-17 04:19:10 -04:00
$this -> config -> setAppValue ( 'dav' , 'needs_system_address_book_sync' , 'no' );
2023-06-26 04:52:07 -04:00
} catch ( Throwable $e ) {
2023-08-17 04:19:10 -04:00
$this -> config -> setAppValue ( 'dav' , 'needs_system_address_book_sync' , 'yes' );
2023-06-26 04:52:07 -04:00
$this -> logger -> error ( 'Could not sync system address books during update' , [
'exception' => $e ,
]);
$output -> warning ( 'System address book sync failed. See logs for details' );
}
2023-05-09 13:17:39 -04:00
}
}