UpdateChecker.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. if(substr($data['web'], 0, 8) === 'https://') {
  44. $result['updateLink'] = $data['web'];
  45. }
  46. return $result;
  47. }
  48. return [];
  49. }
  50. /**
  51. * @param array $data
  52. */
  53. public function getJavaScript(array $data) {
  54. $data['array']['oc_updateState'] = json_encode([
  55. 'updateAvailable' => true,
  56. 'updateVersion' => $this->getUpdateState()['updateVersion'],
  57. 'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '',
  58. ]);
  59. }
  60. }