1
0

getNewServerConfigPrefix.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. use OCA\User_LDAP\Configuration;
  3. use OCA\User_LDAP\Helper;
  4. /**
  5. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  6. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  7. * SPDX-License-Identifier: AGPL-3.0-only
  8. */
  9. // Check user and app status
  10. \OC_JSON::checkAdminUser();
  11. \OC_JSON::checkAppEnabled('user_ldap');
  12. \OC_JSON::callCheck();
  13. $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
  14. $serverConnections = $helper->getServerConfigurationPrefixes();
  15. sort($serverConnections);
  16. $lk = array_pop($serverConnections);
  17. $ln = (int)str_replace('s', '', $lk);
  18. $nk = 's' . str_pad((string)($ln + 1), 2, '0', STR_PAD_LEFT);
  19. $resultData = ['configPrefix' => $nk];
  20. $newConfig = new Configuration($nk, false);
  21. if (isset($_POST['copyConfig'])) {
  22. $originalConfig = new Configuration($_POST['copyConfig']);
  23. $newConfig->setConfiguration($originalConfig->getConfiguration());
  24. } else {
  25. $configuration = new Configuration($nk, false);
  26. $newConfig->setConfiguration($configuration->getDefaults());
  27. $resultData['defaults'] = $configuration->getDefaults();
  28. }
  29. $newConfig->saveConfiguration();
  30. \OC_JSON::success($resultData);