Dotclear

source: admin/update.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 8.7 KB checked in by franck <carnet.franck.paul@…>, 6 years ago (diff)

short notation for array (array() → [])

Line 
1<?php
2/**
3 * @package Dotclear
4 * @subpackage Backend
5 *
6 * @copyright Olivier Meunier & Association Dotclear
7 * @copyright GPL-2.0-only
8 */
9
10require dirname(__FILE__) . '/../inc/admin/prepend.php';
11
12if (!defined('DC_BACKUP_PATH')) {
13    define('DC_BACKUP_PATH', DC_ROOT);
14}
15
16dcPage::checkSuper();
17
18if (!is_readable(DC_DIGESTS)) {
19    dcPage::open(__('Dotclear update'));
20    echo '<h2>Access denied</h2>';
21    dcPage::close();
22    exit;
23}
24
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()) : '';
28$version_info = $new_v ? $updater->getInfoURL() : '';
29
30# Hide "update me" message
31if (!empty($_GET['hide_msg'])) {
32    $updater->setNotify(false);
33    http::redirect('index.php');
34}
35
36$p_url = 'update.php';
37
38$step = isset($_GET['step']) ? $_GET['step'] : '';
39$step = in_array($step, ['check', 'download', 'backup', 'unzip']) ? $step : '';
40
41$default_tab = !empty($_GET['tab']) ? html::escapeHTML($_GET['tab']) : 'update';
42if (!empty($_POST['backup_file'])) {
43    $default_tab = 'files';
44}
45
46$archives = [];
47foreach (files::scanDir(DC_BACKUP_PATH) as $v) {
48    if (preg_match('/backup-([0-9A-Za-z\.-]+).zip/', $v)) {
49        $archives[] = $v;
50    }
51}
52if (!empty($archives)) {
53    usort($archives, "version_compare");
54} else {
55    $default_tab = 'update';
56}
57
58# Revert or delete backup file
59if (!empty($_POST['backup_file']) && in_array($_POST['backup_file'], $archives)) {
60    $b_file = $_POST['backup_file'];
61
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        }
70
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    }
80}
81
82# Upgrade process
83if ($new_v && $step) {
84    try
85    {
86        $updater->setForcedFiles('inc/digests');
87
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();
123
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        }
139
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        }
146
147        $core->error->add($msg);
148
149        $core->callBehavior('adminDCUpdateException', $e);
150    }
151}
152
153/* DISPLAY Main page
154-------------------------------------------------------- */
155dcPage::open(__('Dotclear update'),
156    (!$step ?
157        dcPage::jsPageTabs($default_tab) .
158        dcPage::jsLoad('js/_update.js')
159        : ''),
160    dcPage::breadcrumb(
161        [
162            __('System')          => '',
163            __('Dotclear update') => ''
164        ])
165);
166
167if (!$core->error->flag()) {
168    if (!empty($_GET['nocache'])) {
169        dcPage::success(__('Manual checking of update done successfully.'));
170    }
171}
172
173if (!$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') . '">(' .
185            __('Information about this version') . ')&nbsp;<img src="images/outgoing-link.svg" alt=""/></a>' : '') .
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>';
201
202    if (!empty($archives)) {
203        echo '<div class="multi-part" id="files" title="' . __('Manage backup files') . '">';
204
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>';
209
210        echo '<form action="' . $p_url . '" method="post">';
211        foreach ($archives as $v) {
212            echo
213            '<p><label class="classic">' . form::radio(['backup_file'], html::escapeHTML($v)) . ' ' .
214            html::escapeHTML($v) . '</label></p>';
215        }
216
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>';
226
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>';
235}
236
237dcPage::helpBlock('core_update');
238dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map