enableapp.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christopher Schäpers <kondou@ts.unde.re>
  7. * @author Kamil Domanski <kdomanski@kdemail.net>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. use OCP\ILogger;
  28. OC_JSON::checkAdminUser();
  29. \OC_JSON::callCheck();
  30. $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
  31. if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
  32. $l = \OC::$server->getL10N('core');
  33. OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
  34. exit();
  35. }
  36. $groups = isset($_POST['groups']) ? (array)$_POST['groups'] : [];
  37. $appIds = isset($_POST['appIds']) ? (array)$_POST['appIds'] : [];
  38. try {
  39. $updateRequired = false;
  40. foreach($appIds as $appId) {
  41. $app = new OC_App();
  42. $appId = OC_App::cleanAppId($appId);
  43. $app->enable($appId, $groups);
  44. if(\OC_App::shouldUpgrade($appId)) {
  45. $updateRequired = true;
  46. }
  47. }
  48. OC_JSON::success(['data' => ['update_required' => $updateRequired]]);
  49. } catch (Exception $e) {
  50. \OC::$server->getLogger()->logException($e, [
  51. 'level' => ILogger::DEBUG,
  52. 'app' => 'core',
  53. ]);
  54. OC_JSON::error(array("data" => array("message" => $e->getMessage()) ));
  55. }