You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UpdateChecker.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\UpdateNotification;
  24. use OC\Updater\VersionCheck;
  25. class UpdateChecker {
  26. /** @var VersionCheck */
  27. private $updater;
  28. /**
  29. * @param VersionCheck $updater
  30. */
  31. public function __construct(VersionCheck $updater) {
  32. $this->updater = $updater;
  33. }
  34. /**
  35. * @return array
  36. */
  37. public function getUpdateState() {
  38. $data = $this->updater->check();
  39. $result = [];
  40. if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
  41. $result['updateAvailable'] = true;
  42. $result['updateVersion'] = $data['versionstring'];
  43. $result['updaterEnabled'] = $data['autoupdater'] === '1';
  44. if(substr($data['web'], 0, 8) === 'https://') {
  45. $result['updateLink'] = $data['web'];
  46. }
  47. if(substr($data['url'], 0, 8) === 'https://') {
  48. $result['downloadLink'] = $data['url'];
  49. }
  50. return $result;
  51. }
  52. return [];
  53. }
  54. /**
  55. * @param array $data
  56. */
  57. public function getJavaScript(array $data) {
  58. $data['array']['oc_updateState'] = json_encode([
  59. 'updateAvailable' => true,
  60. 'updateVersion' => $this->getUpdateState()['updateVersion'],
  61. 'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '',
  62. ]);
  63. }
  64. }