Dotclear

source: plugins/maintenance/index.php @ 1969:d2ef655d3195

Revision 1969:d2ef655d3195, 5.1 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Revamp plugin maintenance, step 4, add user prefs (without translation), wait for boss, 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$core->auth->user_prefs->addWorkspace('maintenance');
62if ($core->auth->user_prefs->maintenance->plugin_message) {
63     $expired = $maintenance->getExpired();
64}
65
66// Display page
67
68echo '<html><head>
69<title>'.__('Maintenance').'</title>'.
70dcPage::jsPageTabs($tab);
71
72if ($task && $task->ajax()) {
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
89$msg = $task && !empty($_GET['done']) ? dcPage::success($task->success(),true,true,false) : '';
90
91if ($task && ($res = $task->step()) !== null) {
92
93     // Page title
94
95     echo dcPage::breadcrumb(
96          array(
97               __('Plugins') => '',
98               '<a href="'.$p_url.'">'.__('Maintenance').'</a>' => '',
99               '<span class="page-title">'.html::escapeHTML($task->name()).'</span>' => ''
100          )
101     );
102
103     echo $msg;
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     echo $msg;
138
139     // Simple task (with only a button to start it)
140
141     foreach($maintenance->getTabs() as $tab_id => $tab_name)
142     {
143          $res_group = '';
144          foreach($maintenance->getGroups($core) as $group_id => $group_name)
145          {
146               $res_task = '';
147               foreach($maintenance->getTasks($core) as $t)
148               {
149                    if ($t->group() != $group_id || $t->tab() != $tab_id) {
150                         continue;
151                    }
152
153                    $res_task .= 
154                    '<p>'.form::radio(array('task', $t->id()), $t->id()).' '.
155                    '<label class="classic" for="'.$t->id().'">'.
156                    html::escapeHTML($t->task()).'</label>';
157
158                    if (array_key_exists($t->id(), $expired)) {
159                         $res_task .= 
160                         '<br /> <span class="warn">'.sprintf(
161                              __('Last execution of this task was on %s.'),
162                              dt::dt2str(__('%Y-%m-%d %H:%M'), $expired[$t->id()])
163                         ).' '.
164                         __('You should execute it now.').'</span>';
165                    }
166                    elseif ($t->ts()) {
167                         $res_task .= 
168                         '<br /> <span class="warn">'.
169                         __('This task has never been executed.').' '.
170                         __('You should execute it now.').'</span>';
171                    }
172
173                    $res_task .= '</p>';
174               }
175
176               if (!empty($res_task)) {
177                    $res_group .= 
178                    '<div class="fieldset">'.
179                    '<h4 id="'.$group_id.'">'.$group_name.'</h4>'.
180                    $res_task.
181                    '</div>';
182               }
183          }
184
185          if (!empty($res_group)) {
186               echo 
187               '<div id="'.$tab_id.'" class="multi-part" title="'.$tab_name.'">'.
188               '<h3>'.$tab_name.'</h3>'.
189               '<form action="'.$p_url.'" method="post">'.
190               $res_group.
191               '<p><input type="submit" value="'.__('Execute task').'" /> '.
192               form::hidden(array('tab'), $tab_id).
193               $core->formNonce().'</p>'.
194               '<p class="form-note info">'.__('This may take a very long time').'.</p>'.
195               '</form>'.
196               '</div>';
197          }
198     }
199
200     // Advanced tasks (that required a tab)
201
202     foreach($maintenance->getTasks($core) as $t)
203     {
204          if ($t->group() !== null) {
205               continue;
206          }
207
208          echo 
209          '<div id="'.$t->id().'" class="multi-part" title="'.$t->name().'">'.
210          '<h3>'.$t->name().'</h3>'.
211          '<form action="'.$p_url.'" method="post">'.
212          $t->content().
213          '<p><input type="submit" value="'.__('Execute task').'" /> '.
214          form::hidden(array('task'), $t->id()).
215          form::hidden(array('tab'), $t->id()).
216          $core->formNonce().'</p>'.
217          '</form>'.
218          '</div>';
219     }
220}
221
222dcPage::helpBlock('maintenance');
223
224echo '</body></html>';
Note: See TracBrowser for help on using the repository browser.

Sites map