Dotclear


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

Revamp plugin maintenance, step 4 bis, better place for settings according to boss and some typo, addresses #999

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/maintenance/_admin.php

    r1969 r1984  
    2323// Admin behaviors 
    2424$core->addBehavior('dcMaintenanceRegister', array('dcMaintenanceAdmin', 'dcMaintenanceRegister')); 
    25 $core->addBehavior('adminPreferencesHeaders', array('dcMaintenanceAdmin', 'adminPreferencesHeaders')); 
    2625$core->addBehavior('adminDashboardFavs', array('dcMaintenanceAdmin', 'adminDashboardFavs')); 
    2726$core->addBehavior('adminDashboardFavsIcon', array('dcMaintenanceAdmin', 'adminDashboardFavsIcon')); 
    2827$core->addBehavior('adminDashboardItems', array('dcMaintenanceAdmin', 'adminDashboardItems')); 
    29 $core->addBehavior('adminPreferencesForm',   array('dcMaintenanceAdmin',   'adminPreferencesForm')); 
    30 $core->addBehavior('adminBeforeUserOptionsUpdate',     array('dcMaintenanceAdmin',   'adminBeforeUserOptionsUpdate')); 
     28$core->addBehavior('adminDashboardOptionsForm',   array('dcMaintenanceAdmin',   'adminDashboardOptionsForm')); 
     29$core->addBehavior('adminAfterDashboardOptionsUpdate', array('dcMaintenanceAdmin',   'adminAfterDashboardOptionsUpdate')); 
    3130 
    3231/** 
     
    6059 
    6160          $tasks[] = 'dcMaintenanceCache'; 
     61          $tasks[] = 'dcMaintenanceIndexposts'; 
     62          $tasks[] = 'dcMaintenanceIndexcomments'; 
    6263          $tasks[] = 'dcMaintenanceCountcomments'; 
    63           $tasks[] = 'dcMaintenanceIndexcomments'; 
    64           $tasks[] = 'dcMaintenanceIndexposts'; 
    6564          $tasks[] = 'dcMaintenanceLogs'; 
    6665          $tasks[] = 'dcMaintenanceVacuum'; 
    6766          $tasks[] = 'dcMaintenanceZipmedia'; 
    6867          $tasks[] = 'dcMaintenanceZiptheme'; 
    69      } 
    70  
    71      /** 
    72       * Dashboard headers. 
    73       * 
    74       * Add ajavascript to toggle tasks list. 
    75       */ 
    76      public static function adminPreferencesHeaders() 
    77      { 
    78           return dcPage::jsLoad('index.php?pf=maintenance/js/preferences.js'); 
    7968     } 
    8069 
     
    122111          // Check expired tasks 
    123112          $maintenance = new dcMaintenance($core); 
    124           $expired = $maintenance->getExpired(); 
    125           $expired = count($expired); 
    126           if (!$expired) { 
    127                return null; 
    128           } 
    129  
    130           $icon[0] .= '<br />'.sprintf(__('One task to update', '%s tasks to update', $expired), $expired); 
     113          $count = 0; 
     114          foreach($maintenance->getTasks() as $t) 
     115          { 
     116               if ($t->expired() !== false){ 
     117                    $count++; 
     118               } 
     119          } 
     120 
     121          if (!$count) { 
     122               return null; 
     123          } 
     124 
     125          $icon[0] .= '<br />'.sprintf(__('One task to execute', '%s tasks to execute', $count), $count); 
    131126     } 
    132127 
     
    145140 
    146141          $maintenance = new dcMaintenance($core); 
    147           $tasks = $maintenance->getExpired(); 
    148           if (empty($tasks)) { 
    149                return null; 
    150           } 
    151142 
    152143          $lines = array(); 
    153           foreach($tasks as $id => $ts) { 
    154                $lines[$ts] =  
    155                '<li title="'.sprintf(__('Last updated on %s'), 
    156                     dt::dt2str($core->blog->settings->system->date_format, $ts).' '. 
    157                     dt::dt2str($core->blog->settings->system->time_format, $ts) 
    158                ).'">'.$maintenance->getTask($id)->task().'</li>'; 
    159           } 
    160           ksort($lines); 
     144          foreach($maintenance->getTasks() as $t) 
     145          { 
     146               $ts = $t->expired(); 
     147               if ($ts === false){ 
     148                    continue; 
     149               } 
     150 
     151               $lines[] =  
     152               '<li title="'.($ts === null ? 
     153                    __('This task has never been executed.') 
     154                    : 
     155                    sprintf(__('Last execution of this task was on %s.'), 
     156                         dt::dt2str($core->blog->settings->system->date_format, $ts).' '. 
     157                         dt::dt2str($core->blog->settings->system->time_format, $ts) 
     158                    ) 
     159               ).'">'.$t->task().'</li>'; 
     160          } 
     161 
     162          if (empty($lines)) { 
     163               return null; 
     164          } 
    161165 
    162166          $items[] = new ArrayObject(array( 
    163167               '<div id="maintenance-expired">'. 
    164168               '<h3><img src="index.php?pf=maintenance/icon.png" alt="" /> '.__('Maintenance').'</h3>'. 
    165                '<p>'.sprintf(__('There is a task to update.', 'There are %s tasks to update.', count($tasks)), count($tasks)).'</p>'. 
     169               '<p class="warn">'.sprintf(__('There is a task to execute.', 'There are %s tasks to execute.', count($lines)), count($lines)).'</p>'. 
    166170               '<ul>'.implode('',$lines).'</ul>'. 
    167                '<p><a href="plugin.php?p=maintenance">'.__('Manage task').'</a></p>'. 
     171               '<p><a href="plugin.php?p=maintenance">'.__('Manage tasks').'</a></p>'. 
    168172               '</div>' 
    169173               )); 
     
    178182      * @param $args     <b>object</b>  dcCore instance or record 
    179183      */ 
    180      public static function adminPreferencesForm($core) 
    181      { 
    182           $core->auth->user_prefs->addWorkspace('maintenance'); 
    183           $maintenance = new dcMaintenance($core); 
    184  
    185           $tasks = $maintenance->getTasks(); 
    186           if (empty($tasks)) { 
    187                return null; 
    188           } 
    189  
    190           $full_combo_ts = array_merge(array( 
    191                __('Use different periods for each task') => 'seperate'),  
    192                self::comboTs() 
    193           ); 
    194  
    195           $task_combo_ts = array_merge(array( 
    196                __('Never') => 0),  
    197                self::comboTs() 
    198           ); 
     184     public static function adminDashboardOptionsForm($core) 
     185     { 
     186          $core->auth->user_prefs->addWorkspace('maintenance'); 
    199187 
    200188          echo 
     
    202190          '<h4>'.__('Maintenance').'</h4>'. 
    203191 
    204           '<div class="two-boxes">'. 
    205  
    206192          '<p><label for="maintenance_dashboard_icon" class="classic">'. 
    207193          form::checkbox('maintenance_dashboard_icon', 1, $core->auth->user_prefs->maintenance->dashboard_icon). 
     
    210196          '<p><label for="maintenance_dashboard_item" class="classic">'. 
    211197          form::checkbox('maintenance_dashboard_item', 1, $core->auth->user_prefs->maintenance->dashboard_item). 
    212           __('Display list of expired tasks on dashboard contents').'</label></p>'. 
    213  
    214           '<p><label for="maintenance_plugin_message" class="classic">'. 
    215           form::checkbox('maintenance_plugin_message', 1, $core->auth->user_prefs->maintenance->plugin_message). 
    216           __('Display alert message of expired tasks on plugin page').'</label></p>'. 
    217  
    218           '</div>'. 
    219  
    220           '<div class="two-boxes">'. 
    221  
    222           '<p><label for="maintenance_recall_time">'.__('Recall time for all tasks').'</label>'. 
    223           form::combo('maintenance_recall_time', $full_combo_ts, 'seperate', 'recall-for-all'). 
    224           '</p>'. 
    225  
    226           '</div>'. 
    227  
    228           '<div id="maintenance-recall-time">'. 
    229           '<h5>'.__('Recall time per task').'</h5>'; 
    230  
    231           foreach($tasks as $task) { 
    232                echo 
    233                '<div class="two-boxes">'. 
    234  
    235                '<p><label for="maintenance_ts_'.$task->id().'">'.$task->task().'</label>'. 
    236                form::combo('maintenance_ts_'.$task->id(), $task_combo_ts, $task->ts(), 'recall-per-task'). 
    237                '</p>'. 
    238  
    239                '</div>'; 
    240           } 
    241  
    242           echo  
    243           '</div>'. 
     198          __('Display list of expired tasks on dashboard items').'</label></p>'. 
     199 
    244200          '</div>'; 
    245201     } 
     
    248204      * User preferences update. 
    249205      * 
    250       * @param $cur <b>cursor</b>  Cursor of user options 
    251206      * @param $user_id  <b>string</b>  User ID 
    252207      */ 
    253      public static function adminBeforeUserOptionsUpdate($cur, $user_id=null) 
     208     public static function adminAfterDashboardOptionsUpdate($user_id=null) 
    254209     { 
    255210          global $core; 
    256211 
    257212          if (is_null($user_id)) { 
    258                return null; 
    259           } 
    260  
    261           $maintenance = new dcMaintenance($core); 
    262           $tasks = $maintenance->getTasks(); 
    263           if (empty($tasks)) { 
    264213               return null; 
    265214          } 
     
    268217          $core->auth->user_prefs->maintenance->put('dashboard_icon', !empty($_POST['maintenance_dashboard_icon']), 'boolean'); 
    269218          $core->auth->user_prefs->maintenance->put('dashboard_item', !empty($_POST['maintenance_dashboard_item']), 'boolean'); 
    270           $core->auth->user_prefs->maintenance->put('plugin_message', !empty($_POST['maintenance_plugin_message']), 'boolean'); 
    271  
    272           foreach($tasks as $task) { 
    273                if ($_POST['maintenance_recall_time'] == 'seperate') { 
    274                     $ts = empty($_POST['maintenance_ts_'.$task->id()]) ? 0 : $_POST['maintenance_ts_'.$task->id()]; 
    275                } 
    276                else { 
    277                     $ts = $_POST['maintenance_recall_time']; 
    278                } 
    279                $core->auth->user_prefs->maintenance->put('ts_'.$task->id(), abs((integer) $ts), 'integer'); 
    280           } 
    281      } 
    282  
    283      /* @ignore */ 
    284      public static function comboTs() 
    285      { 
    286           return array( 
    287                __('Every week')         => 604800, 
    288                __('Every two weeks')    => 1209600, 
    289                __('Every month')        => 2592000, 
    290                __('Every two months')   => 5184000 
    291           ); 
    292219     } 
    293220} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map