Dotclear

source: plugins/maintenance/inc/class.dc.maintenance.task.php @ 2566:9bf417837888

Revision 2566:9bf417837888, 5.9 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Add some people in CREDITS, remove trailing spaces and tabs.

RevLine 
[1925]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_RC_PATH')) { return; }
13
14/**
15@ingroup PLUGIN_MAINTENANCE
16@nosubgrouping
17@brief Maintenance plugin task class.
18
19Every task of maintenance must extend this class.
20*/
21class dcMaintenanceTask
22{
[1984]23     protected $maintenance;
[1925]24     protected $core;
25     protected $p_url;
26     protected $code;
[1984]27     protected $ts = 0;
28     protected $expired = 0;
[1959]29     protected $ajax = false;
[1984]30     protected $blog = false;
[1989]31     protected $perm = null;
[1925]32
33     protected $id;
34     protected $name;
[2044]35     protected $description;
[1955]36     protected $tab = 'maintenance';
[1925]37     protected $group = 'other';
38
39     protected $task;
40     protected $step;
41     protected $error;
42     protected $success;
43
44     /**
45      * Constructor.
46      *
47      * If your task required something on construct,
48      * use method init() to do it.
49      *
[1984]50      * @param maintenance    <b>dcMaintenance</b>     dcMaintenance instance
[1925]51      * @param p_url     <b>string</b>  Maintenance plugin url
52      */
[2044]53     public function __construct($maintenance)
[1925]54     {
[1984]55          $this->maintenance = $maintenance;
56          $this->core = $maintenance->core;
[1925]57          $this->init();
[2491]58          $this->id = null;
[1925]59
[1989]60          if ($this->perm() === null && !$this->core->auth->isSuperAdmin()
61          || !$this->core->auth->check($this->perm(), $this->core->blog->id)) {
62               return null;
63          }
64
[2044]65          $this->p_url = $maintenance->p_url;
[1925]66          $this->id = get_class($this);
67
68          if (!$this->name) {
69               $this->name = get_class($this);
70          }
71          if (!$this->error) {
72               $this->error = __('Failed to execute task.');
73          }
74          if (!$this->success) {
75               $this->success = __('Task successfully executed.');
76          }
[1969]77
[1984]78          $this->core->blog->settings->addNamespace('maintenance');
79          $ts = $this->core->blog->settings->maintenance->get('ts_'.$this->id);
80
[1969]81          $this->ts = abs((integer) $ts);
[1989]82
83          return true;
[1925]84     }
85
86     /**
87      * Initialize task object.
88      *
89      * Better to set translated messages here than
90      * to rewrite constructor.
91      */
92     protected function init()
93     {
94          return null;
95     }
96
97     /**
[1989]98      * Get task permission.
99      *
[2566]100      * Return user permission required to run this task
[1989]101      * or null for super admin.
102      *
103      * @return <b>mixed</b> Permission.
104      */
105     public function perm()
106     {
107          return $this->perm;
108     }
109
110     /**
111      * Get task scope.
112      *.
113      * Is task limited to current blog.
114      *
115      * @return <b>boolean</b> Limit to blog
116      */
117     public function blog()
118     {
119          return $this->blog;
120     }
121
122     /**
[1925]123      * Set $code for task having multiple steps.
124      *
125      * @param code <b>integer</b> Code used for task execution
126      */
127     public function code($code)
128     {
129          $this->code = (integer) $code;
130     }
131
132     /**
[1940]133      * Get timestamp between maintenances.
134      *
135      * @return     <b>intetger</b>     Timestamp
136      */
137     public function ts()
138     {
[1969]139          return $this->ts === false ? false : abs((integer) $this->ts);
[1940]140     }
141
142     /**
[1984]143      * Get task expired.
144      *
145      * This return:
146      * - Timstamp of last update if it expired
147      * - False if it not expired or has no recall time
148      * - Null if it has never been executed
149      *
150      * @return     <b>mixed</b>   Last update
151      */
152     public function expired()
153     {
154          if ($this->expired === 0) {
155               if (!$this->ts()) {
156                    $this->expired = false;
157               }
158               else {
159                    $this->expired = null;
160                    $logs = array();
161                    foreach($this->maintenance->getLogs() as $id => $log)
162                    {
163                         if ($id != $this->id() || $this->blog && !$log['blog']) {
164                              continue;
165                         }
166
167                         $this->expired = $log['ts'] + $this->ts() < time() ? $log['ts'] : false;
168                    }
169               }
170          }
171          return $this->expired;
172     }
173
174     /**
[1925]175      * Get task ID.
176      *
177      * @return     <b>string</b>  Task ID (class name)
178      */
179     public function id()
180     {
181          return $this->id;
182     }
183
184     /**
185      * Get task name.
186      *
187      * @return     <b>string</b>  Task name
188      */
189     public function name()
190     {
191          return $this->name;
192     }
193
194     /**
[2044]195      * Get task description.
196      *
197      * @return     <b>string</b>  Description
198      */
199     public function description()
200     {
201          return $this->description;
202     }
203
204     /**
[1955]205      * Get task tab.
206      *
207      * @return     <b>mixed</b>   Task tab ID or null
208      */
209     public function tab()
210     {
211          return $this->tab;
212     }
213
214     /**
[1925]215      * Get task group.
216      *
[2566]217      * If task required a full tab,
[1925]218      * this must be returned null.
[2566]219      *
[1925]220      * @return     <b>mixed</b>   Task group ID or null
221      */
222     public function group()
223     {
224          return $this->group;
225     }
226
227     /**
[1959]228      * Use ajax
229      *
[2566]230      * Is task use maintenance ajax script
[1959]231      * for steps process.
232      *
233      * @return     <b>boolean</b> Use ajax
234      */
235     public function ajax()
236     {
237          return (boolean) $this->ajax;
238     }
239
240     /**
[1925]241      * Get task message.
242      *
243      * This message is used on form button.
244      *
245      * @return     <b>string</b>  Message
246      */
247     public function task()
248     {
249          return $this->task;
250     }
251
252     /**
253      * Get step message.
254      *
255      * This message is displayed during task step execution.
256      *
257      * @return     <b>mixed</b>   Message or null
258      */
259     public function step()
260     {
261          return $this->step;
262     }
263
264     /**
265      * Get success message.
266      *
267      * This message is displayed when task is accomplished.
268      *
269      * @return     <b>mixed</b>   Message or null
270      */
271     public function success()
272     {
273          return $this->success;
274     }
275
276     /**
277      * Get error message.
278      *
279      * This message is displayed on error.
280      *
281      * @return     <b>mixed</b>   Message or null
282      */
283     public function error()
284     {
285          return $this->error;
286     }
287
288     /**
289      * Get header.
290      *
291      * Headers required on maintenance page.
292      *
293      * @return     <b>mixed</b>   Message or null
294      */
295     public function header()
296     {
297          return null;
298     }
299
300     /**
301      * Get content.
302      *
303      * Content for full tab task.
304      *
305      * @return     <b>string</b>  Tab's content
306      */
307     public function content()
308     {
309          return null;
310     }
311
312     /**
313      * Execute task.
314      *
315      * @return     <b>mixed</b>   :
316      *   - FALSE on error,
317      *   - TRUE if task is finished
318      *   - INTEGER if task required a next step
319      */
320     public function execute()
321     {
322          return null;
323     }
[1955]324
325     /**
326      * Log task execution.
327      *
[2566]328      * Sometimes we need to log task execution
[1955]329      * direct from task itself.
330      *
331      */
332     protected function log()
333     {
[1984]334          $this->maintenance->setLog($this->id);
[1955]335     }
[2044]336
337     public function help()
338     {
339          return null;
340     }
[1925]341}
Note: See TracBrowser for help on using the repository browser.

Sites map