Dotclear

source: plugins/maintenance/inc/class.dc.maintenance.task.php @ 1969:d2ef655d3195

Revision 1969:d2ef655d3195, 4.3 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_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{
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          $core->auth->user_prefs->addWorkspace('maintenance');
67          $ts = $core->auth->user_prefs->maintenance->get('ts_'.$this->id);
68         
69          $this->ts = abs((integer) $ts);
70     }
71
72     /**
73      * Initialize task object.
74      *
75      * Better to set translated messages here than
76      * to rewrite constructor.
77      */
78     protected function init()
79     {
80          return null;
81     }
82
83     /**
84      * Set $code for task having multiple steps.
85      *
86      * @param code <b>integer</b> Code used for task execution
87      */
88     public function code($code)
89     {
90          $this->code = (integer) $code;
91     }
92
93     /**
94      * Get timestamp between maintenances.
95      *
96      * @return     <b>intetger</b>     Timestamp
97      */
98     public function ts()
99     {
100          return $this->ts === false ? false : abs((integer) $this->ts);
101     }
102
103     /**
104      * Get task ID.
105      *
106      * @return     <b>string</b>  Task ID (class name)
107      */
108     public function id()
109     {
110          return $this->id;
111     }
112
113     /**
114      * Get task name.
115      *
116      * @return     <b>string</b>  Task name
117      */
118     public function name()
119     {
120          return $this->name;
121     }
122
123     /**
124      * Get task tab.
125      *
126      * @return     <b>mixed</b>   Task tab ID or null
127      */
128     public function tab()
129     {
130          return $this->tab;
131     }
132
133     /**
134      * Get task group.
135      *
136      * If task required a full tab,
137      * this must be returned null.
138      *
139      * @return     <b>mixed</b>   Task group ID or null
140      */
141     public function group()
142     {
143          return $this->group;
144     }
145
146     /**
147      * Use ajax
148      *
149      * Is task use maintenance ajax script
150      * for steps process.
151      *
152      * @return     <b>boolean</b> Use ajax
153      */
154     public function ajax()
155     {
156          return (boolean) $this->ajax;
157     }
158
159     /**
160      * Get task message.
161      *
162      * This message is used on form button.
163      *
164      * @return     <b>string</b>  Message
165      */
166     public function task()
167     {
168          return $this->task;
169     }
170
171     /**
172      * Get step message.
173      *
174      * This message is displayed during task step execution.
175      *
176      * @return     <b>mixed</b>   Message or null
177      */
178     public function step()
179     {
180          return $this->step;
181     }
182
183     /**
184      * Get success message.
185      *
186      * This message is displayed when task is accomplished.
187      *
188      * @return     <b>mixed</b>   Message or null
189      */
190     public function success()
191     {
192          return $this->success;
193     }
194
195     /**
196      * Get error message.
197      *
198      * This message is displayed on error.
199      *
200      * @return     <b>mixed</b>   Message or null
201      */
202     public function error()
203     {
204          return $this->error;
205     }
206
207     /**
208      * Get header.
209      *
210      * Headers required on maintenance page.
211      *
212      * @return     <b>mixed</b>   Message or null
213      */
214     public function header()
215     {
216          return null;
217     }
218
219     /**
220      * Get content.
221      *
222      * Content for full tab task.
223      *
224      * @return     <b>string</b>  Tab's content
225      */
226     public function content()
227     {
228          return null;
229     }
230
231     /**
232      * Execute task.
233      *
234      * @return     <b>mixed</b>   :
235      *   - FALSE on error,
236      *   - TRUE if task is finished
237      *   - INTEGER if task required a next step
238      */
239     public function execute()
240     {
241          return null;
242     }
243
244     /**
245      * Log task execution.
246      *
247      * Sometimes we need to log task execution
248      * direct from task itself.
249      *
250      */
251     protected function log()
252     {
253          $maintenance = new dcMaintenance($this->core);
254          $maintenance->setLog($this->id);
255     }
256}
Note: See TracBrowser for help on using the repository browser.

Sites map