PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/concrete/core/controllers/single_pages/dashboard/system/backup_restore/update.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 156 lines | 130 code | 22 blank | 4 comment | 34 complexity | 0263ef2940f00b891dff6cc72ab968ea MD5 | raw file
  1. <?php
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. Loader::library('update');
  4. Loader::library('archive');
  5. class UpdateArchive extends Archive {
  6. public function __construct() {
  7. parent::__construct();
  8. $this->targetDirectory = DIR_APP_UPDATES;
  9. }
  10. public function install($file) {
  11. parent::install($file, true);
  12. }
  13. }
  14. if (!ini_get('safe_mode')) {
  15. @set_time_limit(0);
  16. ini_set('max_execution_time', 0);
  17. }
  18. class Concrete5_Controller_Dashboard_System_BackupRestore_Update extends DashboardBaseController {
  19. function view() {
  20. $upd = new Update();
  21. $updates = $upd->getLocalAvailableUpdates();
  22. $remote = $upd->getApplicationUpdateInformation();
  23. $this->set('updates', $updates);
  24. if (MULTI_SITE == 0) {
  25. $this->set('showDownloadBox', true);
  26. } else {
  27. $this->set('showDownloadBox', false);
  28. }
  29. if (is_object($remote) && version_compare($remote->version, APP_VERSION, '>')) {
  30. // loop through local updates
  31. $downloadableUpgradeAvailable = true;
  32. foreach($updates as $upd) {
  33. if ($upd->getUpdateVersion() == $remote->version) {
  34. // we have a LOCAL version ready to install that is the same, so we abort
  35. $downloadableUpgradeAvailable = false;
  36. $this->set('showDownloadBox', false);
  37. break;
  38. }
  39. }
  40. $this->set('downloadableUpgradeAvailable', $downloadableUpgradeAvailable);
  41. $this->set('update', $remote);
  42. } else {
  43. $this->set('downloadableUpgradeAvailable', false);
  44. }
  45. }
  46. public function check_for_updates() {
  47. Config::clear('APP_VERSION_LATEST', false);
  48. Update::getLatestAvailableVersionNumber();
  49. $this->redirect('/dashboard/system/backup_restore/update');
  50. }
  51. public function on_start() {
  52. $this->error = Loader::helper('validation/error');
  53. $cnt = Loader::controller('/upgrade');
  54. $cnt->secCheck();
  55. }
  56. public function on_before_render() {
  57. $this->set('error', $this->error);
  58. }
  59. public function download_update() {
  60. if (MULTI_SITE == 1) {
  61. return false;
  62. }
  63. $vt = Loader::helper('validation/token');
  64. if (!$vt->validate('download_update')) {
  65. $this->error->add($vt->getErrorMessage());
  66. }
  67. if (!is_dir(DIR_APP_UPDATES)) {
  68. $this->error->add(t('The directory %s does not exist.', DIR_APP_UPDATES));
  69. } else if (!is_writable(DIR_APP_UPDATES)) {
  70. $this->error->add(t('The directory %s must be writable by the web server.', DIR_APP_UPDATES));
  71. }
  72. if (!$this->error->has()) {
  73. $remote = Update::getApplicationUpdateInformation();
  74. if (is_object($remote)) {
  75. // try to download
  76. Loader::library("marketplace");
  77. $r = Marketplace::downloadRemoteFile($remote->url);
  78. if (empty($r) || $r == Package::E_PACKAGE_DOWNLOAD) {
  79. $response = array(Package::E_PACKAGE_DOWNLOAD);
  80. } else if ($r == Package::E_PACKAGE_SAVE) {
  81. $response = array($r);
  82. }
  83. if (isset($response)) {
  84. $errors = Package::mapError($response);
  85. foreach($errors as $e) {
  86. $this->error->add($e);
  87. }
  88. }
  89. if (!$this->error->has()) {
  90. // the file exists in the right spot
  91. Loader::library('archive');
  92. $ar = new UpdateArchive();
  93. try {
  94. $ar->install($r);
  95. } catch(Exception $e) {
  96. $this->error->add($e->getMessage());
  97. }
  98. }
  99. } else {
  100. $this->error->add(t('Unable to retrieve software from update server.'));
  101. }
  102. }
  103. $this->view();
  104. }
  105. public function do_update() {
  106. $updateVersion = $this->post('updateVersion');
  107. if (!$updateVersion) {
  108. $this->error->add(t('Invalid version'));
  109. } else {
  110. $upd = ApplicationUpdate::getByVersionNumber($updateVersion);
  111. }
  112. if (!is_object($upd)) {
  113. $this->error->add(t('Invalid version'));
  114. } else {
  115. if (version_compare($upd->getUpdateVersion(), APP_VERSION, '<=')) {
  116. $this->error->add(t('You may only apply updates with a greater version number than the version you are currently running.'));
  117. }
  118. }
  119. if (!$this->error->has()) {
  120. $resp = $upd->apply();
  121. if ($resp !== true) {
  122. switch($resp) {
  123. case ApplicationUpdate::E_UPDATE_WRITE_CONFIG:
  124. $this->error->add(t('Unable to write to config/site.php. You must make config/site.php writable in order to upgrade in this manner.'));
  125. break;
  126. }
  127. } else {
  128. header('Location: ' . BASE_URL . REL_DIR_FILES_TOOLS_REQUIRED . '/upgrade?source=dashboard_update');
  129. exit;
  130. }
  131. }
  132. $this->view();
  133. }
  134. }