getNewServerConfigPrefix.php 1.1 KB

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