Dotclear


Ignore:
Timestamp:
09/19/13 01:08:39 (12 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
default
Children:
1956:d272c079e6e5, 1964:bfde9296c3c5
Message:

Revamp plugin maintenance, step 3, add backup tasks, dynamic tabs and plugin importExport, addresses #999

Location:
plugins/maintenance
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • plugins/maintenance/_admin.php

    r1940 r1955  
    4343      * @param $tasks    <b>arrayObject</b>  Array of tasks to register 
    4444      * @param $groups   <b>arrayObject</b>  Array of groups to register 
     45      * @param $tabs     <b>arrayObject</b>  Array of tabs to register 
    4546      */ 
    46       public static function register($core, $tasks, $groups) 
     47      public static function register($core, $tasks, $groups, $tabs) 
    4748     { 
     49          $tabs['maintenance'] = __('Servicing'); 
     50          $tabs['backup'] = __('Backup'); 
     51 
    4852          $groups['optimize'] = __('Optimize'); 
    4953          $groups['index'] = __('Count and index'); 
    5054          $groups['purge'] = __('Purge'); 
    5155          $groups['other'] = __('Other'); 
     56          $groups['zipblog'] = __('Compressed file for current blog'); 
     57          $groups['zipfull'] = __('Compressed file for all blogs'); 
    5258 
    5359          $tasks[] = 'dcMaintenanceCache'; 
     
    5763          $tasks[] = 'dcMaintenanceLogs'; 
    5864          $tasks[] = 'dcMaintenanceVacuum'; 
     65          $tasks[] = 'dcMaintenanceZipmedia'; 
     66          $tasks[] = 'dcMaintenanceZiptheme'; 
    5967     } 
    6068 
  • plugins/maintenance/_prepend.php

    r1925 r1955  
    2424$__autoload['dcMaintenanceLogs'] = dirname(__FILE__).'/inc/tasks/class.dc.maintenance.logs.php'; 
    2525$__autoload['dcMaintenanceVacuum'] = dirname(__FILE__).'/inc/tasks/class.dc.maintenance.vacuum.php'; 
     26$__autoload['dcMaintenanceZipmedia'] = dirname(__FILE__).'/inc/tasks/class.dc.maintenance.zipmedia.php'; 
     27$__autoload['dcMaintenanceZiptheme'] = dirname(__FILE__).'/inc/tasks/class.dc.maintenance.ziptheme.php'; 
    2628 
    2729$this->core->rest->addFunction('dcMaintenanceStep', array('dcMaintenanceRest', 'step')); 
  • plugins/maintenance/inc/class.dc.maintenance.php

    r1940 r1955  
    2727     private $core; 
    2828     private $tasks = array(); 
     29     private $tabs = array(); 
    2930     private $groups = array(); 
    3031 
     
    4142 
    4243          $tasks = new ArrayObject(); 
     44          $tabs = new ArrayObject(); 
    4345          $groups = new ArrayObject(); 
    4446 
    4547          # --BEHAVIOR-- dcMaintenanceRegister 
    46           $core->callBehavior('dcMaintenanceRegister', $core, $tasks, $groups); 
    47  
    48           $this->init($tasks, $groups); 
     48          $core->callBehavior('dcMaintenanceRegister', $core, $tasks, $groups, $tabs); 
     49 
     50          $this->init($tasks, $groups, $tabs); 
    4951     } 
    5052 
     
    5456      * @param tasks     <b>arrayObject</b>  Array of task to register 
    5557      * @param groups    <b>arrayObject</b>  Array of groups to add 
    56       */ 
    57      public function init($tasks, $groups) 
     58      * @param tabs <b>arrayObject</b>  Array of tabs to add 
     59      */ 
     60     public function init($tasks, $groups, $tabs) 
    5861     { 
    5962          $this->tasks = $this->groups = array(); 
     
    7982               $this->groups[(string) $id] = (string) $name; 
    8083          } 
     84 
     85          foreach($tabs as $id => $name) 
     86          { 
     87               $this->tabs[(string) $id] = (string) $name; 
     88          } 
     89     } 
     90 
     91     /** 
     92      * Get a tab name. 
     93      * 
     94      * @param id   <b>string</b> Tab ID 
     95      * @return     <b>mixed</b> tab name or null if not exists 
     96      */ 
     97     public function getTab($id) 
     98     { 
     99          return array_key_exists($id, $this->tabs) ? $this->tabs[$id] : null; 
     100     } 
     101 
     102     /** 
     103      * Get tabs. 
     104      * 
     105      * @return     <b>array</b> Array of tabs ID and name 
     106      */ 
     107     public function getTabs() 
     108     { 
     109          return $this->tabs; 
    81110     } 
    82111 
  • plugins/maintenance/inc/class.dc.maintenance.task.php

    r1940 r1955  
    2828     protected $id; 
    2929     protected $name; 
     30     protected $tab = 'maintenance'; 
    3031     protected $group = 'other'; 
    3132 
     
    115116 
    116117     /** 
     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     /** 
    117128      * Get task group. 
    118129      * 
     
    211222          return null; 
    212223     } 
     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     } 
    213237} 
  • plugins/maintenance/index.php

    r1940 r1955  
    7070dcPage::jsPageTabs($tab); 
    7171 
    72 if ($task) { 
     72if (0){//$task) { 
    7373     echo  
    7474     '<script type="text/javascript">'."\n". 
     
    137137     // Simple task (with only a button to start it) 
    138138 
    139      echo  
    140      '<div id="maintenance" class="multi-part" title="'.__('Maintenance').'">'. 
    141      '<h3>'.__('Maintenance').'</h3>'. 
    142      '<form action="'.$p_url.'" method="post">'; 
    143  
    144      foreach($maintenance->getGroups($core) as $g_id => $g_name) 
     139     foreach($maintenance->getTabs() as $tab_id => $tab_name) 
    145140     { 
    146           $res = ''; 
    147           foreach($maintenance->getTasks($core) as $t) 
     141          $res_group = ''; 
     142          foreach($maintenance->getGroups($core) as $group_id => $group_name) 
    148143          { 
    149                if ($t->group() != $g_id) { 
    150                     continue; 
     144               $res_task = ''; 
     145               foreach($maintenance->getTasks($core) as $t) 
     146               { 
     147                    if ($t->group() != $group_id || $t->tab() != $tab_id) { 
     148                         continue; 
     149                    } 
     150 
     151                    $res_task .=   
     152                    '<p>'.form::radio(array('task', $t->id()), $t->id()).' '. 
     153                    '<label class="classic" for="'.$t->id().'">'. 
     154                    html::escapeHTML($t->task()).'</label>'; 
     155 
     156                    if (array_key_exists($t->id(), $expired)) { 
     157                         $res_task .=  
     158                         ' <span class="clear form-note warn">'.sprintf( 
     159                              __('Last execution of this task was on %s. You should execute it again.'), 
     160                              dt::dt2str(__('%Y-%m-%d %H:%M'), $expired[$t->id()]) 
     161                         ).'</span>'; 
     162                    } 
     163 
     164                    $res_task .= '</p>'; 
    151165               } 
    152166 
    153                $res .=   
    154                '<p>'.form::radio(array('task', $t->id()), $t->id()).' '. 
    155                '<label class="classic" for="'.$t->id().'">'. 
    156                html::escapeHTML($t->task()).'</label>'; 
    157  
    158                if (array_key_exists($t->id(), $expired)) { 
    159                     $res .=  
    160                     ' <span class="clear form-note warn">'.sprintf( 
    161                          __('Last execution of this task was on %s. You should execute it again.'), 
    162                          dt::dt2str(__('%Y-%m-%d %H:%M'), $expired[$t->id()]) 
    163                     ).'</span>'; 
     167               if (!empty($res_task)) { 
     168                    $res_group .=  
     169                    '<div class="fieldset">'. 
     170                    '<h4 id="'.$group_id.'">'.$group_name.'</h4>'. 
     171                    $res_task. 
     172                    '</div>'; 
    164173               } 
    165  
    166                $res .= '</p>'; 
    167           } 
    168  
    169           if (!empty($res)) { 
    170                echo '<div class="fieldset"><h4 id="'.$g_id.'">'.$g_name.'</h4>'.$res.'</div>'; 
    171           } 
    172      } 
    173  
    174      echo  
    175      '<p><input type="submit" value="'.__('Execute task').'" /> '. 
    176      form::hidden(array('tab'), 'maintenance'). 
    177      $core->formNonce().'</p>'. 
    178      '<p class="form-note info">'.__('This may take a very long time').'.</p>'. 
    179      '</form>'. 
    180      '</div>'; 
     174          } 
     175 
     176          if (!empty($res_group)) { 
     177               echo  
     178               '<div id="'.$tab_id.'" class="multi-part" title="'.$tab_name.'">'. 
     179               '<h3>'.$tab_name.'</h3>'. 
     180               '<form action="'.$p_url.'" method="post">'. 
     181               $res_group. 
     182               '<p><input type="submit" value="'.__('Execute task').'" /> '. 
     183               form::hidden(array('tab'), $tab_id). 
     184               $core->formNonce().'</p>'. 
     185               '<p class="form-note info">'.__('This may take a very long time').'.</p>'. 
     186               '</form>'. 
     187               '</div>'; 
     188          } 
     189     } 
    181190 
    182191     // Advanced tasks (that required a tab) 
Note: See TracChangeset for help on using the changeset viewer.

Sites map