Dotclear

Changeset 1940:0fb7e85337bf


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

Revamp plugin maintenance, step 2, add task reminder, addresses #999

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • locales/en/plugins.po

    r1925 r1940  
    958958msgstr "" 
    959959 
     960msgid "one task to update" 
     961msgstr "" 
     962 
     963#, php-format 
     964msgid "%s tasks to update" 
     965msgstr "" 
     966 
     967msgid "Show maintenance tasks to update." 
     968msgstr "" 
     969 
     970#, php-format 
     971msgid "Last execution of this task was on %s. You should execute it again." 
     972msgstr "" 
     973 
    960974msgid "Failed to empty templates cache directory." 
    961975msgstr "" 
  • locales/fr/plugins.po

    r1925 r1940  
    11191119msgstr "Impossible d'exécuter la tâche." 
    11201120 
     1121msgid "One task to update" 
     1122msgid_plural "%s tasks to update" 
     1123msgstr[] "Une tâche à mettre à jour" 
     1124msgstr[] "%s tâches à mettre à jour" 
     1125 
     1126msgid "Show maintenance tasks to update." 
     1127msgstr "Afficher les tâches de maintenance à mettre à jour." 
     1128 
     1129#, php-format 
     1130msgid "Last execution of this task was on %s. You should execute it again." 
     1131msgstr "La dernière exécution de cette tâches était le %s. Vous devriez l'exécuter à nouveau." 
     1132 
    11211133msgid "Failed to empty templates cache directory." 
    11221134msgstr "Impossible de vider le répertoire de cache des « templates »." 
  • plugins/maintenance/_admin.php

    r1925 r1940  
    2424$core->addBehavior('dcMaintenanceRegister', array('dcMaintenanceAdmin', 'register')); 
    2525$core->addBehavior('adminDashboardFavs', array('dcMaintenanceAdmin', 'favs')); 
     26$core->addBehavior('adminDashboardFavsIcon', array('dcMaintenanceAdmin', 'favsicon')); 
     27$core->addBehavior('adminPreferencesForm',   array('dcMaintenanceAdmin',   'prefform')); 
     28$core->addBehavior('adminBeforeUserOptionsUpdate',     array('dcMaintenanceAdmin',   'userupd')); 
    2629 
    2730/** 
     
    3538{ 
    3639     /** 
    37       * Register default tasks 
     40      * Register default tasks. 
    3841      * 
    3942      * @param $core     <b>dcCore</b>  dcCore instance 
     
    5760 
    5861     /** 
    59       * Dashboard favs 
     62      * Dashboard favs. 
    6063      * 
    6164      * @param $core     <b>dcCore</b>  dcCore instance 
     
    7477     } 
    7578 
    76      /** @todo Rminder*/ 
     79     /** 
     80      * Dashboard favs icon. 
     81      * 
     82      * This updates maintenance fav icon text  
     83      * if there are tasks required maintenance. 
     84      * 
     85      * @param $core     <b>dcCore</b>  dcCore instance 
     86      * @param $name     <b>string</b>  Current fav name 
     87      * @param $icon     <b>arrayObject</b>  Current fav attributes 
     88      */ 
     89     public static function favsicon($core, $name, $icon) 
     90     { 
     91          // Check icon 
     92          if ($name !== 'maintenance') { 
     93               return null; 
     94          } 
     95 
     96          // Check user option 
     97          $user_options = $core->auth->getOptions(); 
     98          if (empty($user_options['user_maintenance_expired'])) { 
     99               return null; 
     100          } 
     101 
     102          // Check expired tasks 
     103          $maintenance = new dcMaintenance($core); 
     104          $expired = $maintenance->getExpired(); 
     105          $expired = count($expired); 
     106          if (!$expired) { 
     107               return null; 
     108          } 
     109 
     110          $icon[0] .= '<br />'.sprintf(__('One task to update', '%s tasks to update', $expired), $expired); 
     111     } 
     112 
     113     /** 
     114      * User preferences form. 
     115      * 
     116      * This add options for superadmin user  
     117      * to show or not expired taks. 
     118      * 
     119      * @param $args     <b>object</b>  dcCore instance or record 
     120      */ 
     121     public static function prefform($args) 
     122     { 
     123          $opts = array(); 
     124          if ($args instanceof dcCore) { 
     125               $opts = $args->auth->getOptions(); 
     126               $core = $args; 
     127          } 
     128          elseif ($args instanceof record) { 
     129               $opts = $args->options(); 
     130               $core = $args->core; 
     131          } 
     132 
     133          echo  
     134          '<p><label for="user_maintenance_expired" class="classic">'. 
     135          form::checkbox('user_maintenance_expired', 1, !empty($opts['user_maintenance_expired'])).' '. 
     136          __('Show maintenance tasks to update.').'</label></p>'; 
     137     } 
     138 
     139     /** 
     140      * User preferences update. 
     141      * 
     142      * @param $cur <b>cursor</b>  Cursor of user options 
     143      * @param $user_id  <b>string</b>  User ID 
     144      */ 
     145     public static function userupd($cur, $user_id=null) 
     146     { 
     147          if (!is_null($user_id)) { 
     148               $cur->user_options['user_maintenance_expired'] = !empty($_POST['user_maintenance_expired']); 
     149          } 
     150     } 
    77151} 
  • plugins/maintenance/inc/class.dc.maintenance.php

    r1925 r1940  
    137137          return $res; 
    138138     } 
     139 
     140     /** 
     141      * Set log for a task. 
     142      * 
     143      * @param id   <b>string</b>  Task ID 
     144      */ 
     145     public function setLog($id) 
     146     { 
     147          // Check if taks exists 
     148          if (!$this->getTask($id)) { 
     149               return null; 
     150          } 
     151 
     152          // Get logs from this task 
     153          $rs = $this->core->con->select ( 
     154               'SELECT log_id '. 
     155               'FROM '.$this->core->prefix.'log '. 
     156               "WHERE log_msg = '".$this->core->con->escape($id)."' ". 
     157               "AND log_table = 'maintenance' " 
     158          ); 
     159 
     160          $logs = array(); 
     161          while ($rs->fetch()) { 
     162               $logs[] = $rs->log_id; 
     163          } 
     164 
     165          // Delete old logs 
     166          if (!empty($logs)) { 
     167               $this->core->log->delLogs($logs); 
     168          } 
     169 
     170          // Add new log 
     171          $cur = $this->core->con->openCursor($this->core->prefix.'log'); 
     172 
     173          $cur->log_msg = $id; 
     174          $cur->log_table = 'maintenance'; 
     175          $cur->user_id = $this->core->auth->userID(); 
     176 
     177          $this->core->log->addLog($cur); 
     178     } 
     179 
     180     /** 
     181      * Delete all maintenance logs. 
     182      */ 
     183     public function delLogs() 
     184     { 
     185          // Retrieve logs from this task 
     186          $rs = $this->core->log->getLogs(array( 
     187               'log_table' => 'maintenance', 
     188               'blog_id' => 'all' 
     189          )); 
     190 
     191          $logs = array(); 
     192          while ($rs->fetch()) { 
     193               $logs[] = $rs->log_id; 
     194          } 
     195 
     196          // Delete old logs 
     197          if (!empty($logs)) { 
     198               $this->core->log->delLogs($logs); 
     199          } 
     200     } 
     201 
     202     /** 
     203      * Get expired task. 
     204      * 
     205      * @return     <b>array</b>   Array of expired Task ID / date 
     206      */ 
     207     public function getExpired() 
     208     { 
     209          // Retrieve logs from this task 
     210          $rs = $this->core->log->getLogs(array( 
     211               'log_table' => 'maintenance', 
     212               'blog_id' => 'all' 
     213          )); 
     214 
     215          $logs = array(); 
     216          while ($rs->fetch()) { 
     217               // Check if task exists 
     218               if (($task = $this->getTask($rs->log_msg)) !== null) { 
     219                    // Check if tasks expired 
     220                    if (strtotime($rs->log_dt) + $task->ts() < time()) { 
     221                         $logs[$rs->log_msg] = $rs->log_dt; 
     222                    } 
     223               } 
     224          } 
     225          return $logs; 
     226     } 
    139227} 
  • plugins/maintenance/inc/class.dc.maintenance.task.php

    r1925 r1940  
    2424     protected $p_url; 
    2525     protected $code; 
     26     protected $ts = 604800; // one week 
    2627 
    2728     protected $id; 
     
    3334     protected $error; 
    3435     protected $success; 
    35      protected $reminder; 
    3636 
    3737     /** 
     
    8585 
    8686     /** 
     87      * Get timestamp between maintenances. 
     88      * 
     89      * @return     <b>intetger</b>     Timestamp 
     90      */ 
     91     public function ts() 
     92     { 
     93          return abs((integer) $this->ts); 
     94     } 
     95 
     96     /** 
    8797      * Get task ID. 
    8898      * 
     
    165175     } 
    166176 
    167      /** @todo */ 
    168      public function reminder() 
    169      { 
    170           return null; 
    171      } 
    172  
    173177     /** 
    174178      * Get header. 
  • plugins/maintenance/index.php

    r1925 r1940  
    2323$p_url = 'plugin.php?p=maintenance'; 
    2424$task = null; 
     25$expired = array(); 
    2526 
    2627$code = empty($_POST['code']) ? null : (integer) $_POST['code']; 
     
    4849          } 
    4950          if (true === $code) { 
     51               $maintenance->setLog($task->id()); 
    5052               http::redirect($p_url.'&task='.$task->id().'&done=1&tab='.$tab); 
    5153          } 
     
    5456          $core->error->add($e->getMessage()); 
    5557     } 
     58} 
     59 
     60// Get expired tasks 
     61$user_options = $core->auth->getOptions(); 
     62if (!empty($user_options['user_maintenance_expired'])) { 
     63     $expired = $maintenance->getExpired(); 
    5664} 
    5765 
     
    144152 
    145153               $res .=   
    146                '<p>'.form::radio(array('task', $t->id()),$t->id()).' '. 
     154               '<p>'.form::radio(array('task', $t->id()), $t->id()).' '. 
    147155               '<label class="classic" for="'.$t->id().'">'. 
    148                html::escapeHTML($t->task()).'</label></p>'; 
     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>'; 
     164               } 
     165 
     166               $res .= '</p>'; 
    149167          } 
    150168 
Note: See TracChangeset for help on using the changeset viewer.

Sites map