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 | |
---|
28 | protected $id; |
---|
29 | protected $name; |
---|
30 | protected $group = 'other'; |
---|
31 | |
---|
32 | protected $task; |
---|
33 | protected $step; |
---|
34 | protected $error; |
---|
35 | protected $success; |
---|
36 | |
---|
37 | /** |
---|
38 | * Constructor. |
---|
39 | * |
---|
40 | * If your task required something on construct, |
---|
41 | * use method init() to do it. |
---|
42 | * |
---|
43 | * @param core <b>dcCore</b> dcCore instance |
---|
44 | * @param p_url <b>string</b> Maintenance plugin url |
---|
45 | */ |
---|
46 | public function __construct($core, $p_url) |
---|
47 | { |
---|
48 | $this->core =& $core; |
---|
49 | $this->init(); |
---|
50 | |
---|
51 | $this->p_url = $p_url; |
---|
52 | $this->id = get_class($this); |
---|
53 | |
---|
54 | if (!$this->name) { |
---|
55 | $this->name = get_class($this); |
---|
56 | } |
---|
57 | if (!$this->error) { |
---|
58 | $this->error = __('Failed to execute task.'); |
---|
59 | } |
---|
60 | if (!$this->success) { |
---|
61 | $this->success = __('Task successfully executed.'); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Initialize task object. |
---|
67 | * |
---|
68 | * Better to set translated messages here than |
---|
69 | * to rewrite constructor. |
---|
70 | */ |
---|
71 | protected function init() |
---|
72 | { |
---|
73 | return null; |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | * Set $code for task having multiple steps. |
---|
78 | * |
---|
79 | * @param code <b>integer</b> Code used for task execution |
---|
80 | */ |
---|
81 | public function code($code) |
---|
82 | { |
---|
83 | $this->code = (integer) $code; |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * Get timestamp between maintenances. |
---|
88 | * |
---|
89 | * @return <b>intetger</b> Timestamp |
---|
90 | */ |
---|
91 | public function ts() |
---|
92 | { |
---|
93 | return abs((integer) $this->ts); |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | * Get task ID. |
---|
98 | * |
---|
99 | * @return <b>string</b> Task ID (class name) |
---|
100 | */ |
---|
101 | public function id() |
---|
102 | { |
---|
103 | return $this->id; |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * Get task name. |
---|
108 | * |
---|
109 | * @return <b>string</b> Task name |
---|
110 | */ |
---|
111 | public function name() |
---|
112 | { |
---|
113 | return $this->name; |
---|
114 | } |
---|
115 | |
---|
116 | /** |
---|
117 | * Get task group. |
---|
118 | * |
---|
119 | * If task required a full tab, |
---|
120 | * this must be returned null. |
---|
121 | * |
---|
122 | * @return <b>mixed</b> Task group ID or null |
---|
123 | */ |
---|
124 | public function group() |
---|
125 | { |
---|
126 | return $this->group; |
---|
127 | } |
---|
128 | |
---|
129 | /** |
---|
130 | * Get task message. |
---|
131 | * |
---|
132 | * This message is used on form button. |
---|
133 | * |
---|
134 | * @return <b>string</b> Message |
---|
135 | */ |
---|
136 | public function task() |
---|
137 | { |
---|
138 | return $this->task; |
---|
139 | } |
---|
140 | |
---|
141 | /** |
---|
142 | * Get step message. |
---|
143 | * |
---|
144 | * This message is displayed during task step execution. |
---|
145 | * |
---|
146 | * @return <b>mixed</b> Message or null |
---|
147 | */ |
---|
148 | public function step() |
---|
149 | { |
---|
150 | return $this->step; |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * Get success message. |
---|
155 | * |
---|
156 | * This message is displayed when task is accomplished. |
---|
157 | * |
---|
158 | * @return <b>mixed</b> Message or null |
---|
159 | */ |
---|
160 | public function success() |
---|
161 | { |
---|
162 | return $this->success; |
---|
163 | } |
---|
164 | |
---|
165 | /** |
---|
166 | * Get error message. |
---|
167 | * |
---|
168 | * This message is displayed on error. |
---|
169 | * |
---|
170 | * @return <b>mixed</b> Message or null |
---|
171 | */ |
---|
172 | public function error() |
---|
173 | { |
---|
174 | return $this->error; |
---|
175 | } |
---|
176 | |
---|
177 | /** |
---|
178 | * Get header. |
---|
179 | * |
---|
180 | * Headers required on maintenance page. |
---|
181 | * |
---|
182 | * @return <b>mixed</b> Message or null |
---|
183 | */ |
---|
184 | public function header() |
---|
185 | { |
---|
186 | return null; |
---|
187 | } |
---|
188 | |
---|
189 | /** |
---|
190 | * Get content. |
---|
191 | * |
---|
192 | * Content for full tab task. |
---|
193 | * |
---|
194 | * @return <b>string</b> Tab's content |
---|
195 | */ |
---|
196 | public function content() |
---|
197 | { |
---|
198 | return null; |
---|
199 | } |
---|
200 | |
---|
201 | /** |
---|
202 | * Execute task. |
---|
203 | * |
---|
204 | * @return <b>mixed</b> : |
---|
205 | * - FALSE on error, |
---|
206 | * - TRUE if task is finished |
---|
207 | * - INTEGER if task required a next step |
---|
208 | */ |
---|
209 | public function execute() |
---|
210 | { |
---|
211 | return null; |
---|
212 | } |
---|
213 | } |
---|