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 ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | /** |
---|
15 | @ingroup PLUGIN_MAINTENANCE |
---|
16 | @nosubgrouping |
---|
17 | @brief Maintenance plugin task class. |
---|
18 | |
---|
19 | Every task of maintenance must extend this class. |
---|
20 | */ |
---|
21 | class dcMaintenanceTask |
---|
22 | { |
---|
23 | protected $core; |
---|
24 | protected $p_url; |
---|
25 | protected $code; |
---|
26 | protected $ts = 604800; // one week |
---|
27 | protected $ajax = false; |
---|
28 | |
---|
29 | protected $id; |
---|
30 | protected $name; |
---|
31 | protected $tab = 'maintenance'; |
---|
32 | protected $group = 'other'; |
---|
33 | |
---|
34 | protected $task; |
---|
35 | protected $step; |
---|
36 | protected $error; |
---|
37 | protected $success; |
---|
38 | |
---|
39 | /** |
---|
40 | * Constructor. |
---|
41 | * |
---|
42 | * If your task required something on construct, |
---|
43 | * use method init() to do it. |
---|
44 | * |
---|
45 | * @param core <b>dcCore</b> dcCore instance |
---|
46 | * @param p_url <b>string</b> Maintenance plugin url |
---|
47 | */ |
---|
48 | public function __construct($core, $p_url) |
---|
49 | { |
---|
50 | $this->core =& $core; |
---|
51 | $this->init(); |
---|
52 | |
---|
53 | $this->p_url = $p_url; |
---|
54 | $this->id = get_class($this); |
---|
55 | |
---|
56 | if (!$this->name) { |
---|
57 | $this->name = get_class($this); |
---|
58 | } |
---|
59 | if (!$this->error) { |
---|
60 | $this->error = __('Failed to execute task.'); |
---|
61 | } |
---|
62 | if (!$this->success) { |
---|
63 | $this->success = __('Task successfully executed.'); |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * Initialize task object. |
---|
69 | * |
---|
70 | * Better to set translated messages here than |
---|
71 | * to rewrite constructor. |
---|
72 | */ |
---|
73 | protected function init() |
---|
74 | { |
---|
75 | return null; |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * Set $code for task having multiple steps. |
---|
80 | * |
---|
81 | * @param code <b>integer</b> Code used for task execution |
---|
82 | */ |
---|
83 | public function code($code) |
---|
84 | { |
---|
85 | $this->code = (integer) $code; |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * Get timestamp between maintenances. |
---|
90 | * |
---|
91 | * @return <b>intetger</b> Timestamp |
---|
92 | */ |
---|
93 | public function ts() |
---|
94 | { |
---|
95 | return abs((integer) $this->ts); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * Get task ID. |
---|
100 | * |
---|
101 | * @return <b>string</b> Task ID (class name) |
---|
102 | */ |
---|
103 | public function id() |
---|
104 | { |
---|
105 | return $this->id; |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * Get task name. |
---|
110 | * |
---|
111 | * @return <b>string</b> Task name |
---|
112 | */ |
---|
113 | public function name() |
---|
114 | { |
---|
115 | return $this->name; |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * Get task tab. |
---|
120 | * |
---|
121 | * @return <b>mixed</b> Task tab ID or null |
---|
122 | */ |
---|
123 | public function tab() |
---|
124 | { |
---|
125 | return $this->tab; |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * Get task group. |
---|
130 | * |
---|
131 | * If task required a full tab, |
---|
132 | * this must be returned null. |
---|
133 | * |
---|
134 | * @return <b>mixed</b> Task group ID or null |
---|
135 | */ |
---|
136 | public function group() |
---|
137 | { |
---|
138 | return $this->group; |
---|
139 | } |
---|
140 | |
---|
141 | /** |
---|
142 | * Use ajax |
---|
143 | * |
---|
144 | * Is task use maintenance ajax script |
---|
145 | * for steps process. |
---|
146 | * |
---|
147 | * @return <b>boolean</b> Use ajax |
---|
148 | */ |
---|
149 | public function ajax() |
---|
150 | { |
---|
151 | return (boolean) $this->ajax; |
---|
152 | } |
---|
153 | |
---|
154 | /** |
---|
155 | * Get task message. |
---|
156 | * |
---|
157 | * This message is used on form button. |
---|
158 | * |
---|
159 | * @return <b>string</b> Message |
---|
160 | */ |
---|
161 | public function task() |
---|
162 | { |
---|
163 | return $this->task; |
---|
164 | } |
---|
165 | |
---|
166 | /** |
---|
167 | * Get step message. |
---|
168 | * |
---|
169 | * This message is displayed during task step execution. |
---|
170 | * |
---|
171 | * @return <b>mixed</b> Message or null |
---|
172 | */ |
---|
173 | public function step() |
---|
174 | { |
---|
175 | return $this->step; |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | * Get success message. |
---|
180 | * |
---|
181 | * This message is displayed when task is accomplished. |
---|
182 | * |
---|
183 | * @return <b>mixed</b> Message or null |
---|
184 | */ |
---|
185 | public function success() |
---|
186 | { |
---|
187 | return $this->success; |
---|
188 | } |
---|
189 | |
---|
190 | /** |
---|
191 | * Get error message. |
---|
192 | * |
---|
193 | * This message is displayed on error. |
---|
194 | * |
---|
195 | * @return <b>mixed</b> Message or null |
---|
196 | */ |
---|
197 | public function error() |
---|
198 | { |
---|
199 | return $this->error; |
---|
200 | } |
---|
201 | |
---|
202 | /** |
---|
203 | * Get header. |
---|
204 | * |
---|
205 | * Headers required on maintenance page. |
---|
206 | * |
---|
207 | * @return <b>mixed</b> Message or null |
---|
208 | */ |
---|
209 | public function header() |
---|
210 | { |
---|
211 | return null; |
---|
212 | } |
---|
213 | |
---|
214 | /** |
---|
215 | * Get content. |
---|
216 | * |
---|
217 | * Content for full tab task. |
---|
218 | * |
---|
219 | * @return <b>string</b> Tab's content |
---|
220 | */ |
---|
221 | public function content() |
---|
222 | { |
---|
223 | return null; |
---|
224 | } |
---|
225 | |
---|
226 | /** |
---|
227 | * Execute task. |
---|
228 | * |
---|
229 | * @return <b>mixed</b> : |
---|
230 | * - FALSE on error, |
---|
231 | * - TRUE if task is finished |
---|
232 | * - INTEGER if task required a next step |
---|
233 | */ |
---|
234 | public function execute() |
---|
235 | { |
---|
236 | return null; |
---|
237 | } |
---|
238 | |
---|
239 | /** |
---|
240 | * Log task execution. |
---|
241 | * |
---|
242 | * Sometimes we need to log task execution |
---|
243 | * direct from task itself. |
---|
244 | * |
---|
245 | */ |
---|
246 | protected function log() |
---|
247 | { |
---|
248 | $maintenance = new dcMaintenance($this->core); |
---|
249 | $maintenance->setLog($this->id); |
---|
250 | } |
---|
251 | } |
---|