44
55/**
66 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7- * SPDX-License-Identifier: AGPL-3.0-or- later
7+ * SPDX-License-Identifier: AGPL-3.0-later
88 */
9-
109namespace OCA \DAV \Migration ;
1110
12- use Closure ;
1311use OCA \DAV \AppInfo \Application ;
1412use OCP \AppFramework \Services \IAppConfig ;
1513use OCP \IGroupManager ;
1614use OCP \IUserManager ;
1715use OCP \Migration \IOutput ;
18- use OCP \Migration \SimpleMigrationStep ;
16+ use OCP \Migration \IRepairStep ;
1917use OCP \Notification \IManager ;
20- use Psr \ Log \ LoggerInterface ;
18+ use OCP \ ServerVersion ;
2119
22- class Version1032Date20250701000000 extends SimpleMigrationStep {
20+ class DisableSystemAddressBook implements IRepairStep {
2321
2422 public function __construct (
23+ private readonly ServerVersion $ serverVersion ,
2524 private readonly IAppConfig $ appConfig ,
2625 private readonly IUserManager $ userManager ,
2726 private readonly IGroupManager $ groupManager ,
2827 private readonly IManager $ notificationManager ,
29- private readonly LoggerInterface $ logger ,
3028 ) {
3129 }
3230
33- public function postSchemaChange (IOutput $ output , Closure $ schemaClosure , array $ options ) {
31+ /**
32+ * @inheritdoc
33+ */
34+ public function getName () {
35+ return 'Disable system address book ' ;
36+ }
37+
38+ /**
39+ * @inheritdoc
40+ */
41+ public function run (IOutput $ output ) {
42+ $ output ->info ("Running repair step to disable system address book " );
43+ if ($ this ->serverVersion ->getMajorVersion () !== 32 ) {
44+ $ output ->info ("Skipping repair step system address book this only applies to Nextcloud 32 " );
45+ return ;
46+ }
3447 // If the system address book is not exposed there is nothing to do
3548 if ($ this ->appConfig ->getAppValueBool ('system_addressbook_exposed ' , true ) === false ) {
49+ $ output ->info ("Skipping repair step system address book is already disabled " );
3650 return ;
3751 }
3852 // We use count seen because getting a user count from the backend can be very slow
3953 $ limit = $ this ->appConfig ->getAppValueInt ('system_addressbook_limit ' , 5000 );
4054 if ($ this ->userManager ->countSeenUsers () <= $ limit ) {
55+ $ output ->info ("Skipping repair step system address book has less then the threshold $ limit of contacts no need to disable " );
4156 return ;
4257 }
4358 $ this ->appConfig ->setAppValueBool ('system_addressbook_exposed ' , false );
44- $ this -> logger -> warning (' System address book disabled because user limit reached ' );
59+ $ output -> warning (" System address book disabled because it has more then the threshold of $ limit contacts this can be re-enabled later " );
4560 // Notify all admin users about the system address book being disabled
4661 foreach ($ this ->groupManager ->get ('admin ' )->getUsers () as $ user ) {
4762 $ notification = $ this ->notificationManager ->createNotification ();
@@ -52,5 +67,4 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
5267 $ this ->notificationManager ->notify ($ notification );
5368 }
5469 }
55-
5670}
0 commit comments