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