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