Dotclear


Ignore:
Timestamp:
09/23/13 20:34:42 (12 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
default
Message:

Revamp plugin maintenance, final setp (perhaps still some typo), addresses #1484, fixes #1208, fixes #999

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/maintenance/inc/class.dc.maintenance.php

    r1989 r2044  
    2626{ 
    2727     public $core; 
     28     public $p_url = 'plugin.php?p=maintenance'; 
     29 
    2830     private $tasks = array(); 
    2931     private $tabs = array(); 
     
    3436      * Constructor. 
    3537      * 
    36       * Here you register tasks and groups for tasks. 
    37       * 
    3838      * @param core <b>dcCore</b>  dcCore instance 
    3939      */ 
     
    4141     { 
    4242          $this->core = $core; 
    43  
    44           $tasks = new ArrayObject(); 
    45           $tabs = new ArrayObject(); 
    46           $groups = new ArrayObject(); 
    4743          $logs = $this->getLogs(); 
    48  
    49           # --BEHAVIOR-- dcMaintenanceRegister 
    50           $core->callBehavior('dcMaintenanceRegister', $core, $tasks, $groups, $tabs); 
    51  
    52           $this->init($tasks, $groups, $tabs); 
    53      } 
    54  
    55      /** 
    56       * Initialize list of groups and tasks. 
    57       * 
    58       * @param tasks     <b>arrayObject</b>  Array of task to register 
    59       * @param groups    <b>arrayObject</b>  Array of groups to add 
    60       * @param tabs <b>arrayObject</b>  Array of tabs to add 
    61       */ 
    62      public function init($tasks, $groups, $tabs) 
    63      { 
    64           $this->tasks = $this->groups = array(); 
    65  
    66           foreach($tasks as $task) 
    67           { 
    68                if (!class_exists($task)) { 
    69                     continue; 
    70                } 
    71  
    72                $r = new ReflectionClass($task); 
    73                $p = $r->getParentClass(); 
    74  
    75                if (!$p || $p->name != 'dcMaintenanceTask') { 
    76                     continue; 
    77                } 
    78  
    79                if (($t = new $task($this, 'plugin.php?p=maintenance')) === null 
    80                || $t->perm() === null && !$this->core->auth->isSuperAdmin() 
    81                || !$this->core->auth->check($t->perm(), $this->core->blog->id)) { 
    82                     continue; 
    83                } 
    84  
    85                $this->tasks[$task] = $t; 
    86           } 
    87  
    88           foreach($groups as $id => $name) 
    89           { 
    90                $this->groups[(string) $id] = (string) $name; 
    91           } 
    92  
    93           foreach($tabs as $id => $name) 
    94           { 
    95                $this->tabs[(string) $id] = (string) $name; 
    96           } 
    97      } 
    98  
    99      /** 
    100       * Get a tab name. 
     44          $this->init(); 
     45     } 
     46 
     47     /** 
     48      * Initialize list of tabs and groups and tasks. 
     49      * 
     50      * To register a tab or group or task,  
     51      * use behavior dcMaintenanceInit then a method of 
     52      * dcMaintenance like addTab('myTab', ...). 
     53      */ 
     54     protected function init() 
     55     { 
     56          # --BEHAVIOR-- dcMaintenanceInit 
     57          $this->core->callBehavior('dcMaintenanceInit', $this); 
     58     } 
     59 
     60     /// @name Tab methods 
     61     //@{ 
     62     /** 
     63      * Add a tab. 
     64      * 
     65      * @param id        <b>string<b> Tab ID 
     66      * @param name <b>string<b> Tab name 
     67      * @param options   <b>string<b> Options 
     68      * @return <b>dcMaintenance</b>    Self 
     69      */ 
     70     public function addTab($id, $name, $options=array()) 
     71     { 
     72          $this->tabs[$id] = new dcMaintenanceDescriptor($id, $name, $options); 
     73 
     74          return $this; 
     75     } 
     76 
     77     /** 
     78      * Get a tab. 
    10179      * 
    10280      * @param id   <b>string</b> Tab ID 
    103       * @return     <b>mixed</b> tab name or null if not exists 
     81      * @return     <b>object</b> dcMaintenanceDescriptor of a tab 
    10482      */ 
    10583     public function getTab($id) 
     
    11795          return $this->tabs; 
    11896     } 
    119  
    120      /** 
    121       * Get a group name. 
     97     //@} 
     98 
     99 
     100     /// @name Group methods 
     101     //@{ 
     102     /** 
     103      * Add a group. 
     104      * 
     105      * @param id        <b>string<b> Group ID 
     106      * @param name <b>string<b> Group name 
     107      * @param options   <b>string<b> Options 
     108      * @return <b>dcMaintenance</b>    Self 
     109      */ 
     110     public function addGroup($id, $name, $options=array()) 
     111     { 
     112          $this->groups[$id] = new dcMaintenanceDescriptor($id, $name, $options); 
     113 
     114          return $this; 
     115     } 
     116 
     117     /** 
     118      * Get a group. 
    122119      * 
    123120      * @param id   <b>string</b> Group ID 
    124       * @return     <b>mixed</b> Group name or null if not exists 
     121      * @return     <b>object</b> dcMaintenanceDescriptor of a group 
    125122      */ 
    126123     public function getGroup($id) 
     
    132129      * Get groups. 
    133130      * 
    134       * @return     <b>array</b> Array of groups ID and name 
     131      * @return     <b>array</b> Array of groups ID and descriptor 
    135132      */ 
    136133     public function getGroups() 
    137134     { 
    138135          return $this->groups; 
     136     } 
     137     //@} 
     138 
     139 
     140     /// @name Task methods 
     141     //@{ 
     142     /** 
     143      * Add a task. 
     144      * 
     145      * @param task <b>mixed<b> Class name or object 
     146      * @return     <b>boolean</b> True if it is added 
     147      * @return <b>dcMaintenance</b>    Self 
     148      */ 
     149     public function addTask($task) 
     150     { 
     151          if (class_exists($task) && is_subclass_of($task, 'dcMaintenanceTask')) { 
     152               $this->tasks[$task] = new $task($this); 
     153          } 
     154 
     155          return $this; 
    139156     } 
    140157 
     
    174191          return $res; 
    175192     } 
    176  
     193     //@} 
     194 
     195 
     196     /// @name Log methods 
     197     //@{ 
    177198     /** 
    178199      * Set log for a task. 
     
    268289          return $this->logs; 
    269290     } 
     291     //@} 
    270292} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map