uninstallapp.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. \OC_JSON::checkAdminUser();
  26. \OC_JSON::callCheck();
  27. $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
  28. if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
  29. $l = \OC::$server->getL10N('core');
  30. OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
  31. exit();
  32. }
  33. if (!array_key_exists('appid', $_POST)) {
  34. OC_JSON::error();
  35. exit;
  36. }
  37. $appId = (string)$_POST['appid'];
  38. $appId = OC_App::cleanAppId($appId);
  39. // FIXME: move to controller
  40. /** @var \OC\Installer $installer */
  41. $installer = \OC::$server->query(\OC\Installer::class);
  42. $result = $installer->removeApp($app);
  43. if($result !== false) {
  44. // FIXME: Clear the cache - move that into some sane helper method
  45. \OC::$server->getMemCacheFactory()->createDistributed('settings')->remove('listApps-0');
  46. \OC::$server->getMemCacheFactory()->createDistributed('settings')->remove('listApps-1');
  47. OC_JSON::success(array('data' => array('appid' => $appId)));
  48. } else {
  49. $l = \OC::$server->getL10N('settings');
  50. OC_JSON::error(array('data' => array( 'message' => $l->t("Couldn't remove app.") )));
  51. }