Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

UpdateChecker.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  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. namespace OCA\UpdateNotification;
  26. use OC\Updater\ChangesCheck;
  27. use OC\Updater\VersionCheck;
  28. class UpdateChecker {
  29. /** @var VersionCheck */
  30. private $updater;
  31. /** @var ChangesCheck */
  32. private $changesCheck;
  33. /**
  34. * @param VersionCheck $updater
  35. */
  36. public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) {
  37. $this->updater = $updater;
  38. $this->changesCheck = $changesCheck;
  39. }
  40. /**
  41. * @return array
  42. */
  43. public function getUpdateState(): array {
  44. $data = $this->updater->check();
  45. $result = [];
  46. if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
  47. $result['updateAvailable'] = true;
  48. $result['updateVersion'] = $data['version'];
  49. $result['updateVersionString'] = $data['versionstring'];
  50. $result['updaterEnabled'] = $data['autoupdater'] === '1';
  51. $result['versionIsEol'] = $data['eol'] === '1';
  52. if (strpos($data['web'], 'https://') === 0) {
  53. $result['updateLink'] = $data['web'];
  54. }
  55. if (strpos($data['url'], 'https://') === 0) {
  56. $result['downloadLink'] = $data['url'];
  57. }
  58. if (strpos($data['changes'], 'https://') === 0) {
  59. try {
  60. $result['changes'] = $this->changesCheck->check($data['changes'], $data['version']);
  61. } catch (\Exception $e) {
  62. // no info, not a problem
  63. }
  64. }
  65. return $result;
  66. }
  67. return [];
  68. }
  69. /**
  70. * @param array $data
  71. */
  72. public function populateJavaScriptVariables(array $data) {
  73. $data['array']['oc_updateState'] = json_encode([
  74. 'updateAvailable' => true,
  75. 'updateVersion' => $this->getUpdateState()['updateVersionString'],
  76. 'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
  77. ]);
  78. }
  79. }