updateapp.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christopher Schäpers <kondou@ts.unde.re>
  6. * @author Frank Karlitschek <frank@karlitschek.de>
  7. * @author Georg Ehrke <georg@owncloud.com>
  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. OCP\JSON::checkAdminUser();
  28. OCP\JSON::callCheck();
  29. if (!array_key_exists('appid', $_POST)) {
  30. OCP\JSON::error(array(
  31. 'message' => 'No AppId given!'
  32. ));
  33. return;
  34. }
  35. $appId = (string)$_POST['appid'];
  36. if (!is_numeric($appId)) {
  37. $appId = \OC::$server->getAppConfig()->getValue($appId, 'ocsid', null);
  38. if ($appId === null) {
  39. OCP\JSON::error(array(
  40. 'message' => 'No OCS-ID found for app!'
  41. ));
  42. exit;
  43. }
  44. }
  45. $appId = OC_App::cleanAppId($appId);
  46. $config = \OC::$server->getConfig();
  47. $config->setSystemValue('maintenance', true);
  48. try {
  49. $result = \OC\Installer::updateAppByOCSId($appId);
  50. $config->setSystemValue('maintenance', false);
  51. } catch(Exception $ex) {
  52. $config->setSystemValue('maintenance', false);
  53. OC_JSON::error(array("data" => array( "message" => $ex->getMessage() )));
  54. return;
  55. }
  56. if($result !== false) {
  57. OC_JSON::success(array('data' => array('appid' => $appId)));
  58. } else {
  59. $l = \OC::$server->getL10N('settings');
  60. OC_JSON::error(array("data" => array( "message" => $l->t("Couldn't update app.") )));
  61. }