[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
| 6 | # Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear |
---|
| 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'); |
---|
| 29 | $new_v = $updater->check(DC_VERSION); |
---|
| 30 | $zip_file = $new_v ? DC_BACKUP_PATH.'/'.basename($updater->getFileURL()) : ''; |
---|
| 31 | |
---|
| 32 | # Hide "update me" message |
---|
| 33 | if (!empty($_GET['hide_msg'])) { |
---|
| 34 | $updater->setNotify(false); |
---|
| 35 | http::redirect('index.php'); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | $p_url = 'update.php'; |
---|
| 39 | |
---|
| 40 | $step = isset($_GET['step']) ? $_GET['step'] : ''; |
---|
| 41 | $step = in_array($step,array('check','download','backup','unzip')) ? $step : ''; |
---|
| 42 | |
---|
| 43 | $archives = array(); |
---|
| 44 | foreach (files::scanDir(DC_BACKUP_PATH) as $v) { |
---|
| 45 | if (preg_match('/backup-([0-9A-Za-z\.-]+).zip/',$v)) { |
---|
| 46 | $archives[] = $v; |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | # Revert or delete backup file |
---|
| 51 | if (!empty($_POST['backup_file']) && in_array($_POST['backup_file'],$archives)) |
---|
| 52 | { |
---|
| 53 | $b_file = $_POST['backup_file']; |
---|
| 54 | |
---|
| 55 | try |
---|
| 56 | { |
---|
| 57 | if (!empty($_POST['b_del'])) |
---|
| 58 | { |
---|
| 59 | if (!@unlink(DC_BACKUP_PATH.'/'.$b_file)) { |
---|
| 60 | throw new Exception(sprintf(__('Unable to delete file %s'),html::escapeHTML($b_file))); |
---|
| 61 | } |
---|
| 62 | http::redirect($p_url); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | if (!empty($_POST['b_revert'])) |
---|
| 66 | { |
---|
| 67 | $zip = new fileUnzip(DC_BACKUP_PATH.'/'.$b_file); |
---|
| 68 | $zip->unzipAll(DC_BACKUP_PATH.'/'); |
---|
| 69 | @unlink(DC_BACKUP_PATH.'/'.$b_file); |
---|
| 70 | http::redirect($p_url); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | catch (Exception $e) |
---|
| 74 | { |
---|
| 75 | $core->error->add($e->getMessage()); |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | # Upgrade process |
---|
| 80 | if ($new_v && $step) |
---|
| 81 | { |
---|
| 82 | try |
---|
| 83 | { |
---|
| 84 | $updater->setForcedFiles('inc/digests'); |
---|
| 85 | |
---|
| 86 | switch ($step) |
---|
| 87 | { |
---|
| 88 | case 'check': |
---|
| 89 | $updater->checkIntegrity(DC_ROOT.'/inc/digests',DC_ROOT); |
---|
| 90 | http::redirect($p_url.'?step=download'); |
---|
| 91 | break; |
---|
| 92 | case 'download': |
---|
| 93 | $updater->download($zip_file); |
---|
| 94 | if (!$updater->checkDownload($zip_file)) { |
---|
| 95 | throw new Exception( |
---|
| 96 | sprintf(__('Downloaded Dotclear archive seems to be corrupted. '. |
---|
| 97 | 'Try <a %s>download it</a> again.'),'href="'.$p_url.'?step=download"') |
---|
| 98 | ); |
---|
| 99 | } |
---|
| 100 | http::redirect($p_url.'?step=backup'); |
---|
| 101 | break; |
---|
| 102 | case 'backup': |
---|
| 103 | $updater->backup( |
---|
| 104 | $zip_file, 'dotclear/inc/digests', |
---|
| 105 | DC_ROOT, DC_ROOT.'/inc/digests', |
---|
| 106 | DC_BACKUP_PATH.'/backup-'.DC_VERSION.'.zip' |
---|
| 107 | ); |
---|
| 108 | http::redirect($p_url.'?step=unzip'); |
---|
| 109 | break; |
---|
| 110 | case 'unzip': |
---|
| 111 | $updater->performUpgrade( |
---|
| 112 | $zip_file, 'dotclear/inc/digests', 'dotclear', |
---|
| 113 | DC_ROOT, DC_ROOT.'/inc/digests' |
---|
| 114 | ); |
---|
| 115 | break; |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | catch (Exception $e) |
---|
| 119 | { |
---|
| 120 | $msg = $e->getMessage(); |
---|
| 121 | if ($e->getCode() == dcUpdate::ERR_FILES_CHANGED) |
---|
| 122 | { |
---|
| 123 | $msg = |
---|
| 124 | __('The following files of your Dotclear installation '. |
---|
| 125 | 'have been modified so we won\'t try to update your installation. '. |
---|
| 126 | 'Please try to <a href="http://dotclear.org/download">update manually</a>.'); |
---|
| 127 | } |
---|
| 128 | elseif ($e->getCode() == dcUpdate::ERR_FILES_UNREADABLE) |
---|
| 129 | { |
---|
| 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 | } |
---|
| 135 | elseif ($e->getCode() == dcUpdate::ERR_FILES_UNWRITALBE) |
---|
| 136 | { |
---|
| 137 | $msg = |
---|
| 138 | __('The following files of your Dotclear installation cannot be written. '. |
---|
| 139 | 'Please fix this or try to <a href="http://dotclear.org/download">update manually</a>.'); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | if (isset($e->bad_files)) { |
---|
| 143 | $msg .= |
---|
| 144 | '<ul><li><strong>'. |
---|
| 145 | implode('</strong></li><li><strong>',$e->bad_files). |
---|
| 146 | '</strong></li></ul>'; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | $core->error->add($msg); |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | /* DISPLAY Main page |
---|
| 154 | -------------------------------------------------------- */ |
---|
| 155 | dcPage::open(__('Dotclear update')); |
---|
| 156 | |
---|
| 157 | if (!$core->error->flag()) { |
---|
| 158 | echo '<h2>'.__('Dotclear update').'</h2>'; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | if (!$step) |
---|
| 162 | { |
---|
| 163 | if (empty($new_v)) |
---|
| 164 | { |
---|
| 165 | echo '<p><strong>'.__('No newer Dotclear version available.').'</strong></p>'; |
---|
| 166 | } |
---|
| 167 | else |
---|
| 168 | { |
---|
| 169 | echo |
---|
| 170 | '<p class="static-msg">'.sprintf(__('Dotclear %s is available.'),$new_v).'</p>'. |
---|
| 171 | |
---|
| 172 | '<p>'.__('To upgrade your Dotclear installation simply click on the following button. '. |
---|
| 173 | 'A backup file of your current installation will be created in your root directory.').'</p>'. |
---|
| 174 | '<form action="'.$p_url.'" method="get">'. |
---|
| 175 | '<p><input type="hidden" name="step" value="check" />'. |
---|
| 176 | '<input type="submit" value="'.__('Update Dotclear').'" /></p>'. |
---|
| 177 | '</form>'; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | if (!empty($archives)) |
---|
| 181 | { |
---|
| 182 | echo |
---|
| 183 | '<h3>'.__('Update backup files').'</h3>'. |
---|
| 184 | '<p>'.__('The following files are backups of previously updates. '. |
---|
| 185 | 'You can revert your previous installation or delete theses files.').'</p>'; |
---|
| 186 | |
---|
| 187 | echo '<form action="'.$p_url.'" method="post">'; |
---|
| 188 | |
---|
| 189 | foreach ($archives as $v) { |
---|
| 190 | echo |
---|
| 191 | '<p><label class="classic">'.form::radio(array('backup_file'),html::escapeHTML($v)).' '. |
---|
| 192 | html::escapeHTML($v).'</label></p>'; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | echo |
---|
| 196 | '<p><strong>'.__('Please note that reverting your Dotclear version may have some '. |
---|
| 197 | 'unwanted side-effects. Consider reverting only if you experience strong issues with this new version.').'</strong> '. |
---|
| 198 | sprintf(__('You should not revert to version prior to last one (%s).'),end($archives)). |
---|
| 199 | '</p>'. |
---|
| 200 | '<p><input type="submit" name="b_del" value="'.__('Delete selected file').'" /> '. |
---|
| 201 | '<input type="submit" name="b_revert" value="'.__('Revert to selected file').'" />'. |
---|
| 202 | $core->formNonce().'</p>'. |
---|
| 203 | '</form>'; |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | elseif ($step == 'unzip' && !$core->error->flag()) |
---|
| 207 | { |
---|
| 208 | echo |
---|
| 209 | '<p class="message">'. |
---|
| 210 | __("Congratulations, you're one click away from the end of the update."). |
---|
| 211 | ' <strong><a href="index.php?logout=1">'.__('Finish the update.').'</a></strong>'. |
---|
| 212 | '</p>'; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | dcPage::close(); |
---|
| 216 | ?> |
---|