Dotclear

source: plugins/maintenance/inc/class.dc.maintenance.task.php @ 1955:b0bef03695c0

Revision 1955:b0bef03695c0, 3.9 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

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

Sites map