|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 6 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | + */ |
| 8 | + |
| 9 | +namespace OCA\User_LDAP\Migration; |
| 10 | + |
| 11 | +use OCP\IAppConfig; |
| 12 | +use OCP\IDBConnection; |
| 13 | +use OCP\Migration\IOutput; |
| 14 | +use OCP\Migration\IRepairStep; |
| 15 | + |
| 16 | +class RearrangeMarkRemnantsAsDisabled implements IRepairStep { |
| 17 | + public function __construct( |
| 18 | + protected IAppConfig $appConfig, |
| 19 | + protected IDBConnection $dbc, |
| 20 | + ) { |
| 21 | + |
| 22 | + } |
| 23 | + public function getName(): string { |
| 24 | + return 'Rearrange the configuration of ldap_mark_remnants_as_disabled'; |
| 25 | + } |
| 26 | + |
| 27 | + public function run(IOutput $output): void { |
| 28 | + $allKeys = $this->appConfig->getKeys('user_ldap'); |
| 29 | + |
| 30 | + if (in_array('backend_mark_remnants_as_disabled', $allKeys, true)) { |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + // if it was enabled for at least one configuration, use it as global configuration |
| 35 | + $filteredKeys = array_filter($allKeys, static function (string $key): bool { |
| 36 | + return str_ends_with($key, 'ldap_mark_remnants_as_disabled'); |
| 37 | + }); |
| 38 | + $newValue = false; |
| 39 | + foreach ($filteredKeys as $filteredKey) { |
| 40 | + $newValue = $newValue || $this->appConfig->getValueBool('user_ldap', $filteredKey); |
| 41 | + } |
| 42 | + |
| 43 | + // set the new value |
| 44 | + $this->appConfig->setValueBool('user_ldap', 'backend_mark_remnants_as_disabled', $newValue); |
| 45 | + if ($newValue) { |
| 46 | + $output->info('The option "Disable missing users from LDAP" is activated.'); |
| 47 | + } |
| 48 | + |
| 49 | + // clean up now that the new value is saved |
| 50 | + foreach ($filteredKeys as $filteredKey) { |
| 51 | + $this->appConfig->deleteKey('user_ldap', $filteredKey); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments