Dotclear

source: plugins/maintenance/inc/class.dc.maintenance.task.php @ 1925:567a4a03e5df

Revision 1925:567a4a03e5df, 3.4 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Revamp plugin maintenance, step 1, rewrite code to open it, addresses #999

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{
23     protected $core;
24     protected $p_url;
25     protected $code;
26
27     protected $id;
28     protected $name;
29     protected $group = 'other';
30
31     protected $task;
32     protected $step;
33     protected $error;
34     protected $success;
35     protected $reminder;
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 task ID.
88      *
89      * @return     <b>string</b>  Task ID (class name)
90      */
91     public function id()
92     {
93          return $this->id;
94     }
95
96     /**
97      * Get task name.
98      *
99      * @return     <b>string</b>  Task name
100      */
101     public function name()
102     {
103          return $this->name;
104     }
105
106     /**
107      * Get task group.
108      *
109      * If task required a full tab,
110      * this must be returned null.
111      *
112      * @return     <b>mixed</b>   Task group ID or null
113      */
114     public function group()
115     {
116          return $this->group;
117     }
118
119     /**
120      * Get task message.
121      *
122      * This message is used on form button.
123      *
124      * @return     <b>string</b>  Message
125      */
126     public function task()
127     {
128          return $this->task;
129     }
130
131     /**
132      * Get step message.
133      *
134      * This message is displayed during task step execution.
135      *
136      * @return     <b>mixed</b>   Message or null
137      */
138     public function step()
139     {
140          return $this->step;
141     }
142
143     /**
144      * Get success message.
145      *
146      * This message is displayed when task is accomplished.
147      *
148      * @return     <b>mixed</b>   Message or null
149      */
150     public function success()
151     {
152          return $this->success;
153     }
154
155     /**
156      * Get error message.
157      *
158      * This message is displayed on error.
159      *
160      * @return     <b>mixed</b>   Message or null
161      */
162     public function error()
163     {
164          return $this->error;
165     }
166
167     /** @todo */
168     public function reminder()
169     {
170          return null;
171     }
172
173     /**
174      * Get header.
175      *
176      * Headers required on maintenance page.
177      *
178      * @return     <b>mixed</b>   Message or null
179      */
180     public function header()
181     {
182          return null;
183     }
184
185     /**
186      * Get content.
187      *
188      * Content for full tab task.
189      *
190      * @return     <b>string</b>  Tab's content
191      */
192     public function content()
193     {
194          return null;
195     }
196
197     /**
198      * Execute task.
199      *
200      * @return     <b>mixed</b>   :
201      *   - FALSE on error,
202      *   - TRUE if task is finished
203      *   - INTEGER if task required a next step
204      */
205     public function execute()
206     {
207          return null;
208     }
209}
Note: See TracBrowser for help on using the repository browser.

Sites map