Dotclear

source: plugins/maintenance/index.php @ 1955:b0bef03695c0

Revision 1955:b0bef03695c0, 4.9 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Revamp plugin maintenance, step 3, add backup tasks, dynamic tabs and plugin importExport, addresses #999

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 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 -----------------------------------------
12if (!defined('DC_CONTEXT_ADMIN')) { return; }
13
14dcPage::checkSuper();
15
16// main class
17
18$maintenance = new dcMaintenance($core);
19
20// Set var
21
22$headers = '';
23$p_url = 'plugin.php?p=maintenance';
24$task = null;
25$expired = array();
26
27$code = empty($_POST['code']) ? null : (integer) $_POST['code'];
28$tab = empty($_REQUEST['tab']) ? 'maintenance' : $_REQUEST['tab'];
29
30// Get task object
31
32if (!empty($_REQUEST['task'])) {
33     $task = $maintenance->getTask($_REQUEST['task']);
34
35     if ($task === null) {
36          $core->error->add('Unknow task ID');
37     }
38
39     $task->code($code);
40}
41
42// Execute task
43
44if ($task && !empty($_POST['task']) && $task->id() == $_POST['task']) {
45     try {
46          $code = $task->execute();
47          if (false === $code) {
48               throw new Exception($task->error());
49          }
50          if (true === $code) {
51               $maintenance->setLog($task->id());
52               http::redirect($p_url.'&task='.$task->id().'&done=1&tab='.$tab);
53          }
54     }
55     catch (Exception $e) {
56          $core->error->add($e->getMessage());
57     }
58}
59
60// Get expired tasks
61$user_options = $core->auth->getOptions();
62if (!empty($user_options['user_maintenance_expired'])) {
63     $expired = $maintenance->getExpired();
64}
65
66// Display page
67
68echo '<html><head>
69<title>'.__('Maintenance').'</title>'.
70dcPage::jsPageTabs($tab);
71
72if (0){//$task) {
73     echo 
74     '<script type="text/javascript">'."\n".
75     "//<![CDATA\n".
76     dcPage::jsVar('dotclear.msg.wait', __('Please wait...')).
77     "//]]>\n".
78     '</script>'.
79     dcPage::jsLoad('index.php?pf=maintenance/js/dc.maintenance.js');
80}
81
82echo 
83$maintenance->getHeaders().'
84</head>
85<body>';
86
87// Success message
88
89if ($task && !empty($_GET['done'])) {
90     dcPage::success($task->success());
91}
92
93if ($task && ($res = $task->step()) !== null) {
94
95     // Page title
96
97     echo dcPage::breadcrumb(
98          array(
99               __('Plugins') => '',
100               '<a href="'.$p_url.'">'.__('Maintenance').'</a>' => '',
101               '<span class="page-title">'.html::escapeHTML($task->name()).'</span>' => ''
102          )
103     );
104
105     // Intermediate task (task required several steps)
106
107     echo 
108     '<div class="step-box" id="'.$task->id().'">'.
109     '<h3>'.html::escapeHTML($task->name()).'</h3>'.
110     '<form action="'.$p_url.'" method="post">'.
111     '<p class="step-msg">'.
112          $res.
113     '</p>'.
114     '<p class="step-submit">'.
115          '<input type="submit" value="'.$task->task().'" /> '.
116          form::hidden(array('task'), $task->id()).
117          form::hidden(array('code'), (integer) $code).
118          $core->formNonce().
119     '</p>'.
120     '</form>'.
121     '<p class="step-back">'.
122          '<a class="back" href="'.$p_url.'">'.__('Back').'</a>'.
123     '</p>'.
124     '</div>';
125}
126else {
127
128     // Page title
129
130     echo dcPage::breadcrumb(
131          array(
132               __('Plugins') => '',
133               '<span class="page-title">'.__('Maintenance').'</span>' => ''
134          )
135     );
136
137     // Simple task (with only a button to start it)
138
139     foreach($maintenance->getTabs() as $tab_id => $tab_name)
140     {
141          $res_group = '';
142          foreach($maintenance->getGroups($core) as $group_id => $group_name)
143          {
144               $res_task = '';
145               foreach($maintenance->getTasks($core) as $t)
146               {
147                    if ($t->group() != $group_id || $t->tab() != $tab_id) {
148                         continue;
149                    }
150
151                    $res_task .= 
152                    '<p>'.form::radio(array('task', $t->id()), $t->id()).' '.
153                    '<label class="classic" for="'.$t->id().'">'.
154                    html::escapeHTML($t->task()).'</label>';
155
156                    if (array_key_exists($t->id(), $expired)) {
157                         $res_task .= 
158                         ' <span class="clear form-note warn">'.sprintf(
159                              __('Last execution of this task was on %s. You should execute it again.'),
160                              dt::dt2str(__('%Y-%m-%d %H:%M'), $expired[$t->id()])
161                         ).'</span>';
162                    }
163
164                    $res_task .= '</p>';
165               }
166
167               if (!empty($res_task)) {
168                    $res_group .= 
169                    '<div class="fieldset">'.
170                    '<h4 id="'.$group_id.'">'.$group_name.'</h4>'.
171                    $res_task.
172                    '</div>';
173               }
174          }
175
176          if (!empty($res_group)) {
177               echo 
178               '<div id="'.$tab_id.'" class="multi-part" title="'.$tab_name.'">'.
179               '<h3>'.$tab_name.'</h3>'.
180               '<form action="'.$p_url.'" method="post">'.
181               $res_group.
182               '<p><input type="submit" value="'.__('Execute task').'" /> '.
183               form::hidden(array('tab'), $tab_id).
184               $core->formNonce().'</p>'.
185               '<p class="form-note info">'.__('This may take a very long time').'.</p>'.
186               '</form>'.
187               '</div>';
188          }
189     }
190
191     // Advanced tasks (that required a tab)
192
193     foreach($maintenance->getTasks($core) as $t)
194     {
195          if ($t->group() !== null) {
196               continue;
197          }
198
199          echo 
200          '<div id="'.$t->id().'" class="multi-part" title="'.$t->name().'">'.
201          '<h3>'.$t->name().'</h3>'.
202          '<form action="'.$p_url.'" method="post">'.
203          $t->content().
204          '<p><input type="submit" value="'.__('Execute task').'" /> '.
205          form::hidden(array('task'), $t->id()).
206          form::hidden(array('tab'), $t->id()).
207          $core->formNonce().'</p>'.
208          '</form>'.
209          '</div>';
210     }
211}
212
213dcPage::helpBlock('maintenance');
214
215echo '</body></html>';
Note: See TracBrowser for help on using the repository browser.

Sites map