[0] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @package Dotclear |
---|
| 4 | * @subpackage Backend |
---|
| 5 | * |
---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 7 | * @copyright GPL-2.0-only |
---|
| 8 | */ |
---|
[0] | 9 | |
---|
[3730] | 10 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; |
---|
[0] | 11 | |
---|
| 12 | if (!defined('DC_BACKUP_PATH')) { |
---|
[3730] | 13 | define('DC_BACKUP_PATH', DC_ROOT); |
---|
[0] | 14 | } |
---|
| 15 | |
---|
| 16 | dcPage::checkSuper(); |
---|
| 17 | |
---|
| 18 | if (!is_readable(DC_DIGESTS)) { |
---|
[3730] | 19 | dcPage::open(__('Dotclear update')); |
---|
| 20 | echo '<h2>Access denied</h2>'; |
---|
| 21 | dcPage::close(); |
---|
| 22 | exit; |
---|
[0] | 23 | } |
---|
| 24 | |
---|
[3730] | 25 | $updater = new dcUpdate(DC_UPDATE_URL, 'dotclear', DC_UPDATE_VERSION, DC_TPL_CACHE . '/versions'); |
---|
| 26 | $new_v = $updater->check(DC_VERSION, !empty($_GET['nocache'])); |
---|
| 27 | $zip_file = $new_v ? DC_BACKUP_PATH . '/' . basename($updater->getFileURL()) : ''; |
---|
[166] | 28 | $version_info = $new_v ? $updater->getInfoURL() : ''; |
---|
[0] | 29 | |
---|
| 30 | # Hide "update me" message |
---|
| 31 | if (!empty($_GET['hide_msg'])) { |
---|
[3730] | 32 | $updater->setNotify(false); |
---|
| 33 | http::redirect('index.php'); |
---|
[0] | 34 | } |
---|
| 35 | |
---|
| 36 | $p_url = 'update.php'; |
---|
| 37 | |
---|
| 38 | $step = isset($_GET['step']) ? $_GET['step'] : ''; |
---|
[3874] | 39 | $step = in_array($step, ['check', 'download', 'backup', 'unzip']) ? $step : ''; |
---|
[0] | 40 | |
---|
[941] | 41 | $default_tab = !empty($_GET['tab']) ? html::escapeHTML($_GET['tab']) : 'update'; |
---|
| 42 | if (!empty($_POST['backup_file'])) { |
---|
[3730] | 43 | $default_tab = 'files'; |
---|
[941] | 44 | } |
---|
| 45 | |
---|
[3874] | 46 | $archives = []; |
---|
[0] | 47 | foreach (files::scanDir(DC_BACKUP_PATH) as $v) { |
---|
[3730] | 48 | if (preg_match('/backup-([0-9A-Za-z\.-]+).zip/', $v)) { |
---|
| 49 | $archives[] = $v; |
---|
| 50 | } |
---|
[0] | 51 | } |
---|
[941] | 52 | if (!empty($archives)) { |
---|
[3730] | 53 | usort($archives, "version_compare"); |
---|
[941] | 54 | } else { |
---|
[3730] | 55 | $default_tab = 'update'; |
---|
[941] | 56 | } |
---|
[0] | 57 | |
---|
| 58 | # Revert or delete backup file |
---|
[3730] | 59 | if (!empty($_POST['backup_file']) && in_array($_POST['backup_file'], $archives)) { |
---|
| 60 | $b_file = $_POST['backup_file']; |
---|
[2503] | 61 | |
---|
[3730] | 62 | try |
---|
| 63 | { |
---|
| 64 | if (!empty($_POST['b_del'])) { |
---|
| 65 | if (!@unlink(DC_BACKUP_PATH . '/' . $b_file)) { |
---|
| 66 | throw new Exception(sprintf(__('Unable to delete file %s'), html::escapeHTML($b_file))); |
---|
| 67 | } |
---|
| 68 | http::redirect($p_url . '?tab=files'); |
---|
| 69 | } |
---|
[2503] | 70 | |
---|
[3730] | 71 | if (!empty($_POST['b_revert'])) { |
---|
| 72 | $zip = new fileUnzip(DC_BACKUP_PATH . '/' . $b_file); |
---|
| 73 | $zip->unzipAll(DC_BACKUP_PATH . '/'); |
---|
| 74 | @unlink(DC_BACKUP_PATH . '/' . $b_file); |
---|
| 75 | http::redirect($p_url . '?tab=files'); |
---|
| 76 | } |
---|
| 77 | } catch (Exception $e) { |
---|
| 78 | $core->error->add($e->getMessage()); |
---|
| 79 | } |
---|
[0] | 80 | } |
---|
| 81 | |
---|
| 82 | # Upgrade process |
---|
[3730] | 83 | if ($new_v && $step) { |
---|
| 84 | try |
---|
| 85 | { |
---|
| 86 | $updater->setForcedFiles('inc/digests'); |
---|
[2503] | 87 | |
---|
[3730] | 88 | switch ($step) { |
---|
| 89 | case 'check': |
---|
| 90 | $updater->checkIntegrity(DC_ROOT . '/inc/digests', DC_ROOT); |
---|
| 91 | http::redirect($p_url . '?step=download'); |
---|
| 92 | break; |
---|
| 93 | case 'download': |
---|
| 94 | $updater->download($zip_file); |
---|
| 95 | if (!$updater->checkDownload($zip_file)) { |
---|
| 96 | throw new Exception( |
---|
| 97 | sprintf(__('Downloaded Dotclear archive seems to be corrupted. ' . |
---|
| 98 | 'Try <a %s>download it</a> again.'), 'href="' . $p_url . '?step=download"') . |
---|
| 99 | ' ' . |
---|
| 100 | __('If this problem persists try to ' . |
---|
| 101 | '<a href="http://dotclear.org/download">update manually</a>.') |
---|
| 102 | ); |
---|
| 103 | } |
---|
| 104 | http::redirect($p_url . '?step=backup'); |
---|
| 105 | break; |
---|
| 106 | case 'backup': |
---|
| 107 | $updater->backup( |
---|
| 108 | $zip_file, 'dotclear/inc/digests', |
---|
| 109 | DC_ROOT, DC_ROOT . '/inc/digests', |
---|
| 110 | DC_BACKUP_PATH . '/backup-' . DC_VERSION . '.zip' |
---|
| 111 | ); |
---|
| 112 | http::redirect($p_url . '?step=unzip'); |
---|
| 113 | break; |
---|
| 114 | case 'unzip': |
---|
| 115 | $updater->performUpgrade( |
---|
| 116 | $zip_file, 'dotclear/inc/digests', 'dotclear', |
---|
| 117 | DC_ROOT, DC_ROOT . '/inc/digests' |
---|
| 118 | ); |
---|
| 119 | break; |
---|
| 120 | } |
---|
| 121 | } catch (Exception $e) { |
---|
| 122 | $msg = $e->getMessage(); |
---|
[2503] | 123 | |
---|
[3730] | 124 | if ($e->getCode() == dcUpdate::ERR_FILES_CHANGED) { |
---|
| 125 | $msg = |
---|
| 126 | __('The following files of your Dotclear installation ' . |
---|
| 127 | 'have been modified so we won\'t try to update your installation. ' . |
---|
| 128 | 'Please try to <a href="http://dotclear.org/download">update manually</a>.'); |
---|
| 129 | } elseif ($e->getCode() == dcUpdate::ERR_FILES_UNREADABLE) { |
---|
| 130 | $msg = |
---|
| 131 | sprintf(__('The following files of your Dotclear installation are not readable. ' . |
---|
| 132 | 'Please fix this or try to make a backup file named %s manually.'), |
---|
| 133 | '<strong>backup-' . DC_VERSION . '.zip</strong>'); |
---|
| 134 | } elseif ($e->getCode() == dcUpdate::ERR_FILES_UNWRITALBE) { |
---|
| 135 | $msg = |
---|
| 136 | __('The following files of your Dotclear installation cannot be written. ' . |
---|
| 137 | 'Please fix this or try to <a href="http://dotclear.org/download">update manually</a>.'); |
---|
| 138 | } |
---|
[2503] | 139 | |
---|
[3730] | 140 | if (isset($e->bad_files)) { |
---|
| 141 | $msg .= |
---|
| 142 | '<ul><li><strong>' . |
---|
| 143 | implode('</strong></li><li><strong>', $e->bad_files) . |
---|
| 144 | '</strong></li></ul>'; |
---|
| 145 | } |
---|
[2503] | 146 | |
---|
[3730] | 147 | $core->error->add($msg); |
---|
[2503] | 148 | |
---|
[3730] | 149 | $core->callBehavior('adminDCUpdateException', $e); |
---|
| 150 | } |
---|
[0] | 151 | } |
---|
| 152 | |
---|
| 153 | /* DISPLAY Main page |
---|
| 154 | -------------------------------------------------------- */ |
---|
[941] | 155 | dcPage::open(__('Dotclear update'), |
---|
[3730] | 156 | (!$step ? |
---|
| 157 | dcPage::jsPageTabs($default_tab) . |
---|
| 158 | dcPage::jsLoad('js/_update.js') |
---|
| 159 | : ''), |
---|
| 160 | dcPage::breadcrumb( |
---|
[3874] | 161 | [ |
---|
[3730] | 162 | __('System') => '', |
---|
| 163 | __('Dotclear update') => '' |
---|
[3874] | 164 | ]) |
---|
[941] | 165 | ); |
---|
[0] | 166 | |
---|
| 167 | if (!$core->error->flag()) { |
---|
[3730] | 168 | if (!empty($_GET['nocache'])) { |
---|
| 169 | dcPage::success(__('Manual checking of update done successfully.')); |
---|
| 170 | } |
---|
[0] | 171 | } |
---|
| 172 | |
---|
[3730] | 173 | if (!$step) { |
---|
| 174 | echo '<div class="multi-part" id="update" title="' . __('Dotclear update') . '">'; |
---|
| 175 | if (empty($new_v)) { |
---|
| 176 | echo '<p><strong>' . __('No newer Dotclear version available.') . '</strong></p>' . |
---|
| 177 | '<form action="' . $p_url . '" method="get">' . |
---|
| 178 | '<p><input type="hidden" name="nocache" value="1" />' . |
---|
| 179 | '<input type="submit" value="' . __('Force checking update Dotclear') . '" /></p>' . |
---|
| 180 | '</form>'; |
---|
| 181 | } else { |
---|
| 182 | echo |
---|
| 183 | '<p class="static-msg">' . sprintf(__('Dotclear %s is available.'), $new_v) . |
---|
| 184 | ($version_info ? ' <a href="' . $version_info . '" class="outgoing" title="' . __('Information about this version') . '">(' . |
---|
[3771] | 185 | __('Information about this version') . ') <img src="images/outgoing-link.svg" alt=""/></a>' : '') . |
---|
[3730] | 186 | '</p>'; |
---|
| 187 | if (version_compare(phpversion(), $updater->getPHPVersion()) < 0) { |
---|
| 188 | echo |
---|
| 189 | '<p class="warning-msg">' . sprintf(__('PHP version is %s (%s or earlier needed).'), phpversion(), $updater->getPHPVersion()) . '</p>'; |
---|
| 190 | } else { |
---|
| 191 | echo |
---|
| 192 | '<p>' . __('To upgrade your Dotclear installation simply click on the following button. ' . |
---|
| 193 | 'A backup file of your current installation will be created in your root directory.') . '</p>' . |
---|
| 194 | '<form action="' . $p_url . '" method="get">' . |
---|
| 195 | '<p><input type="hidden" name="step" value="check" />' . |
---|
| 196 | '<input type="submit" value="' . __('Update Dotclear') . '" /></p>' . |
---|
| 197 | '</form>'; |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | echo '</div>'; |
---|
[2503] | 201 | |
---|
[3730] | 202 | if (!empty($archives)) { |
---|
| 203 | echo '<div class="multi-part" id="files" title="' . __('Manage backup files') . '">'; |
---|
[941] | 204 | |
---|
[3730] | 205 | echo |
---|
| 206 | '<h3>' . __('Update backup files') . '</h3>' . |
---|
| 207 | '<p>' . __('The following files are backups of previously updates. ' . |
---|
| 208 | 'You can revert your previous installation or delete theses files.') . '</p>'; |
---|
[2503] | 209 | |
---|
[3730] | 210 | echo '<form action="' . $p_url . '" method="post">'; |
---|
| 211 | foreach ($archives as $v) { |
---|
| 212 | echo |
---|
[3874] | 213 | '<p><label class="classic">' . form::radio(['backup_file'], html::escapeHTML($v)) . ' ' . |
---|
[3730] | 214 | html::escapeHTML($v) . '</label></p>'; |
---|
| 215 | } |
---|
[2503] | 216 | |
---|
[3730] | 217 | echo |
---|
| 218 | '<p><strong>' . __('Please note that reverting your Dotclear version may have some ' . |
---|
| 219 | 'unwanted side-effects. Consider reverting only if you experience strong issues with this new version.') . '</strong> ' . |
---|
| 220 | sprintf(__('You should not revert to version prior to last one (%s).'), end($archives)) . |
---|
| 221 | '</p>' . |
---|
| 222 | '<p><input type="submit" class="delete" name="b_del" value="' . __('Delete selected file') . '" /> ' . |
---|
| 223 | '<input type="submit" name="b_revert" value="' . __('Revert to selected file') . '" />' . |
---|
| 224 | $core->formNonce() . '</p>' . |
---|
| 225 | '</form>'; |
---|
[941] | 226 | |
---|
[3730] | 227 | echo '</div>'; |
---|
| 228 | } |
---|
| 229 | } elseif ($step == 'unzip' && !$core->error->flag()) { |
---|
| 230 | echo |
---|
| 231 | '<p class="message">' . |
---|
| 232 | __("Congratulations, you're one click away from the end of the update.") . |
---|
| 233 | ' <strong><a href="index.php?logout=1">' . __('Finish the update.') . '</a></strong>' . |
---|
| 234 | '</p>'; |
---|
[0] | 235 | } |
---|
| 236 | |
---|
[2314] | 237 | dcPage::helpBlock('core_update'); |
---|
[0] | 238 | dcPage::close(); |
---|