Dotclear

source: plugins/maintenance/index.php @ 1940:0fb7e85337bf

Revision 1940:0fb7e85337bf, 4.6 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Revamp plugin maintenance, step 2, add task reminder, 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 ($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     echo 
140     '<div id="maintenance" class="multi-part" title="'.__('Maintenance').'">'.
141     '<h3>'.__('Maintenance').'</h3>'.
142     '<form action="'.$p_url.'" method="post">';
143
144     foreach($maintenance->getGroups($core) as $g_id => $g_name)
145     {
146          $res = '';
147          foreach($maintenance->getTasks($core) as $t)
148          {
149               if ($t->group() != $g_id) {
150                    continue;
151               }
152
153               $res .= 
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 .= 
160                    ' <span class="clear form-note warn">'.sprintf(
161                         __('Last execution of this task was on %s. You should execute it again.'),
162                         dt::dt2str(__('%Y-%m-%d %H:%M'), $expired[$t->id()])
163                    ).'</span>';
164               }
165
166               $res .= '</p>';
167          }
168
169          if (!empty($res)) {
170               echo '<div class="fieldset"><h4 id="'.$g_id.'">'.$g_name.'</h4>'.$res.'</div>';
171          }
172     }
173
174     echo 
175     '<p><input type="submit" value="'.__('Execute task').'" /> '.
176     form::hidden(array('tab'), 'maintenance').
177     $core->formNonce().'</p>'.
178     '<p class="form-note info">'.__('This may take a very long time').'.</p>'.
179     '</form>'.
180     '</div>';
181
182     // Advanced tasks (that required a tab)
183
184     foreach($maintenance->getTasks($core) as $t)
185     {
186          if ($t->group() !== null) {
187               continue;
188          }
189
190          echo 
191          '<div id="'.$t->id().'" class="multi-part" title="'.$t->name().'">'.
192          '<h3>'.$t->name().'</h3>'.
193          '<form action="'.$p_url.'" method="post">'.
194          $t->content().
195          '<p><input type="submit" value="'.__('Execute task').'" /> '.
196          form::hidden(array('task'), $t->id()).
197          form::hidden(array('tab'), $t->id()).
198          $core->formNonce().'</p>'.
199          '</form>'.
200          '</div>';
201     }
202}
203
204dcPage::helpBlock('maintenance');
205
206echo '</body></html>';
Note: See TracBrowser for help on using the repository browser.

Sites map