updateapp.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @author Christopher Schäpers <kondou@ts.unde.re>
  4. * @author Frank Karlitschek <frank@owncloud.org>
  5. * @author Georg Ehrke <georg@owncloud.com>
  6. * @author Lukas Reschke <lukas@owncloud.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <icewind@owncloud.com>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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. }