Changeset 1984:0b0cb9cd7da7 for plugins/maintenance
- Timestamp:
- 09/21/13 23:52:08 (12 years ago)
- Branch:
- default
- Location:
- plugins/maintenance
- Files:
-
- 1 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/maintenance/_admin.php
r1969 r1984 23 23 // Admin behaviors 24 24 $core->addBehavior('dcMaintenanceRegister', array('dcMaintenanceAdmin', 'dcMaintenanceRegister')); 25 $core->addBehavior('adminPreferencesHeaders', array('dcMaintenanceAdmin', 'adminPreferencesHeaders'));26 25 $core->addBehavior('adminDashboardFavs', array('dcMaintenanceAdmin', 'adminDashboardFavs')); 27 26 $core->addBehavior('adminDashboardFavsIcon', array('dcMaintenanceAdmin', 'adminDashboardFavsIcon')); 28 27 $core->addBehavior('adminDashboardItems', array('dcMaintenanceAdmin', 'adminDashboardItems')); 29 $core->addBehavior('admin PreferencesForm', array('dcMaintenanceAdmin', 'adminPreferencesForm'));30 $core->addBehavior('admin BeforeUserOptionsUpdate', array('dcMaintenanceAdmin', 'adminBeforeUserOptionsUpdate'));28 $core->addBehavior('adminDashboardOptionsForm', array('dcMaintenanceAdmin', 'adminDashboardOptionsForm')); 29 $core->addBehavior('adminAfterDashboardOptionsUpdate', array('dcMaintenanceAdmin', 'adminAfterDashboardOptionsUpdate')); 31 30 32 31 /** … … 60 59 61 60 $tasks[] = 'dcMaintenanceCache'; 61 $tasks[] = 'dcMaintenanceIndexposts'; 62 $tasks[] = 'dcMaintenanceIndexcomments'; 62 63 $tasks[] = 'dcMaintenanceCountcomments'; 63 $tasks[] = 'dcMaintenanceIndexcomments';64 $tasks[] = 'dcMaintenanceIndexposts';65 64 $tasks[] = 'dcMaintenanceLogs'; 66 65 $tasks[] = 'dcMaintenanceVacuum'; 67 66 $tasks[] = 'dcMaintenanceZipmedia'; 68 67 $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');79 68 } 80 69 … … 122 111 // Check expired tasks 123 112 $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); 131 126 } 132 127 … … 145 140 146 141 $maintenance = new dcMaintenance($core); 147 $tasks = $maintenance->getExpired();148 if (empty($tasks)) {149 return null;150 }151 142 152 143 $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 } 161 165 162 166 $items[] = new ArrayObject(array( 163 167 '<div id="maintenance-expired">'. 164 168 '<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>'. 166 170 '<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>'. 168 172 '</div>' 169 173 )); … … 178 182 * @param $args <b>object</b> dcCore instance or record 179 183 */ 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'); 199 187 200 188 echo … … 202 190 '<h4>'.__('Maintenance').'</h4>'. 203 191 204 '<div class="two-boxes">'.205 206 192 '<p><label for="maintenance_dashboard_icon" class="classic">'. 207 193 form::checkbox('maintenance_dashboard_icon', 1, $core->auth->user_prefs->maintenance->dashboard_icon). … … 210 196 '<p><label for="maintenance_dashboard_item" class="classic">'. 211 197 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 244 200 '</div>'; 245 201 } … … 248 204 * User preferences update. 249 205 * 250 * @param $cur <b>cursor</b> Cursor of user options251 206 * @param $user_id <b>string</b> User ID 252 207 */ 253 public static function admin BeforeUserOptionsUpdate($cur,$user_id=null)208 public static function adminAfterDashboardOptionsUpdate($user_id=null) 254 209 { 255 210 global $core; 256 211 257 212 if (is_null($user_id)) { 258 return null;259 }260 261 $maintenance = new dcMaintenance($core);262 $tasks = $maintenance->getTasks();263 if (empty($tasks)) {264 213 return null; 265 214 } … … 268 217 $core->auth->user_prefs->maintenance->put('dashboard_icon', !empty($_POST['maintenance_dashboard_icon']), 'boolean'); 269 218 $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') => 5184000291 );292 219 } 293 220 } -
plugins/maintenance/inc/class.dc.maintenance.php
r1969 r1984 25 25 class dcMaintenance 26 26 { 27 p rivate$core;27 public $core; 28 28 private $tasks = array(); 29 29 private $tabs = array(); 30 30 private $groups = array(); 31 private $logs = null; 31 32 32 33 /** … … 44 45 $tabs = new ArrayObject(); 45 46 $groups = new ArrayObject(); 47 $logs = $this->getLogs(); 46 48 47 49 # --BEHAVIOR-- dcMaintenanceRegister … … 75 77 } 76 78 77 $this->tasks[$task] = new $task($this ->core, 'plugin.php?p=maintenance');79 $this->tasks[$task] = new $task($this, 'plugin.php?p=maintenance'); 78 80 } 79 81 … … 230 232 231 233 /** 232 * Get expired tasks. 233 * 234 * @return <b>array</b> Array of expired Task ID / date 235 */ 236 public function getExpired() 237 { 238 // Retrieve logs from this task 239 $rs = $this->core->log->getLogs(array( 240 'log_table' => 'maintenance', 241 'blog_id' => 'all' 242 )); 243 244 $logs = array(); 245 while ($rs->fetch()) { 246 // Check if task exists 247 if (($task = $this->getTask($rs->log_msg)) !== null) { 248 // Check if remider is used and tasks expired 249 if ($task->ts() && strtotime($rs->log_dt) + $task->ts() < time()) { 250 $logs[$rs->log_msg] = $rs->log_dt; 251 } 234 * Get logs 235 * 236 * Return array( 237 * task id => array( 238 * timestamp of last execution, 239 * logged on current blog or not 240 * ) 241 * ) 242 * 243 * @return <b>array</b> List of logged tasks 244 */ 245 public function getLogs() 246 { 247 if ($this->logs === null) { 248 $rs = $this->core->log->getLogs(array( 249 'log_table' => 'maintenance', 250 'blog_id' => 'all' 251 )); 252 253 $this->logs = array(); 254 while ($rs->fetch()) { 255 $this->logs[$rs->log_msg] = array( 256 'ts' => strtotime($rs->log_dt), 257 'blog' => $rs->blog_id == $this->core->blog->id 258 ); 252 259 } 253 260 } 254 return $logs; 261 262 return $this->logs; 255 263 } 256 264 } -
plugins/maintenance/inc/class.dc.maintenance.task.php
r1969 r1984 21 21 class dcMaintenanceTask 22 22 { 23 protected $maintenance; 23 24 protected $core; 24 25 protected $p_url; 25 26 protected $code; 26 protected $ts = 604800; // one week 27 protected $ts = 0; 28 protected $expired = 0; 27 29 protected $ajax = false; 30 protected $blog = false; 28 31 29 32 protected $id; … … 43 46 * use method init() to do it. 44 47 * 45 * @param core <b>dcCore</b> dcCore instance48 * @param maintenance <b>dcMaintenance</b> dcMaintenance instance 46 49 * @param p_url <b>string</b> Maintenance plugin url 47 50 */ 48 public function __construct($core, $p_url) 49 { 50 $this->core =& $core; 51 public function __construct($maintenance, $p_url) 52 { 53 $this->maintenance = $maintenance; 54 $this->core = $maintenance->core; 51 55 $this->init(); 52 56 … … 64 68 } 65 69 66 $ core->auth->user_prefs->addWorkspace('maintenance');67 $ts = $ core->auth->user_prefs->maintenance->get('ts_'.$this->id);68 70 $this->core->blog->settings->addNamespace('maintenance'); 71 $ts = $this->core->blog->settings->maintenance->get('ts_'.$this->id); 72 69 73 $this->ts = abs((integer) $ts); 70 74 } … … 99 103 { 100 104 return $this->ts === false ? false : abs((integer) $this->ts); 105 } 106 107 /** 108 * Get task expired. 109 * 110 * This return: 111 * - Timstamp of last update if it expired 112 * - False if it not expired or has no recall time 113 * - Null if it has never been executed 114 * 115 * @return <b>mixed</b> Last update 116 */ 117 public function expired() 118 { 119 if ($this->expired === 0) { 120 if (!$this->ts()) { 121 $this->expired = false; 122 } 123 else { 124 $this->expired = null; 125 $logs = array(); 126 foreach($this->maintenance->getLogs() as $id => $log) 127 { 128 if ($id != $this->id() || $this->blog && !$log['blog']) { 129 continue; 130 } 131 132 $this->expired = $log['ts'] + $this->ts() < time() ? $log['ts'] : false; 133 } 134 } 135 } 136 return $this->expired; 101 137 } 102 138 … … 251 287 protected function log() 252 288 { 253 $maintenance = new dcMaintenance($this->core); 254 $maintenance->setLog($this->id); 289 $this->maintenance->setLog($this->id); 255 290 } 256 291 } -
plugins/maintenance/inc/tasks/class.dc.maintenance.countcomments.php
r1925 r1984 18 18 protected function init() 19 19 { 20 $this->task = __(' Reset comments and ping counters');20 $this->task = __('Count again comments and trackbacks'); 21 21 $this->success = __('Comments and trackback counted.'); 22 $this->error = __('Failed to reset comments and ping counters.');22 $this->error = __('Failed to count comments and trackbacks.'); 23 23 } 24 24 -
plugins/maintenance/inc/tasks/class.dc.maintenance.indexcomments.php
r1959 r1984 23 23 $this->name = __('Search engine index'); 24 24 $this->task = __('Index all comments'); 25 $this->step_task = __(' next');25 $this->step_task = __('Next'); 26 26 $this->step = __('Indexing comment %d to %d.'); 27 27 $this->success = __('Comments index done.'); -
plugins/maintenance/inc/tasks/class.dc.maintenance.indexposts.php
r1959 r1984 23 23 $this->name = __('Search engine index'); 24 24 $this->task = __('Index all posts'); 25 $this->step_task = __(' next');25 $this->step_task = __('Next'); 26 26 $this->step = __('Indexing entry %d to %d.'); 27 27 $this->success = __('Entries index done.'); -
plugins/maintenance/inc/tasks/class.dc.maintenance.vacuum.php
r1925 r1984 18 18 protected function init() 19 19 { 20 $this->task = __(' Vacuumtables');20 $this->task = __('optimize tables'); 21 21 $this->success = __('Optimization successful.'); 22 $this->error = __('Failed to vacuumtables.');22 $this->error = __('Failed to optimize tables.'); 23 23 } 24 24 -
plugins/maintenance/inc/tasks/class.dc.maintenance.zipmedia.php
r1955 r1984 14 14 class dcMaintenanceZipmedia extends dcMaintenanceTask 15 15 { 16 protected $blog = true; 16 17 protected $tab = 'backup'; 17 18 protected $group = 'zipblog'; -
plugins/maintenance/inc/tasks/class.dc.maintenance.ziptheme.php
r1955 r1984 14 14 class dcMaintenanceZiptheme extends dcMaintenanceTask 15 15 { 16 protected $blog = true; 16 17 protected $tab = 'backup'; 17 18 protected $group = 'zipblog'; -
plugins/maintenance/index.php
r1969 r1984 17 17 18 18 $maintenance = new dcMaintenance($core); 19 $core->blog->settings->addNamespace('maintenance'); 19 20 20 21 // Set var 21 22 23 $msg = ''; 22 24 $headers = ''; 23 25 $p_url = 'plugin.php?p=maintenance'; … … 27 29 $code = empty($_POST['code']) ? null : (integer) $_POST['code']; 28 30 $tab = empty($_REQUEST['tab']) ? 'maintenance' : $_REQUEST['tab']; 31 32 // Save settings 33 34 if (!empty($_POST['settings'])) { 35 36 try { 37 $core->blog->settings->maintenance->put( 38 'plugin_message', 39 !empty($_POST['settings_plugin_message']), 40 'boolean', 41 'Display alert message of expired tasks on plugin page', 42 true, 43 true 44 ); 45 46 foreach($maintenance->getTasks() as $t) { 47 if (!empty($_POST['settings_recall_time']) && $_POST['settings_recall_time'] == 'seperate') { 48 $ts = empty($_POST['settings_ts_'.$t->id()]) ? 0 : $_POST['settings_ts_'.$t->id()]; 49 } 50 else { 51 $ts = $_POST['settings_recall_time']; 52 } 53 $core->blog->settings->maintenance->put( 54 'ts_'.$t->id(), 55 abs((integer) $ts), 56 'integer', 57 sprintf('Recall time for task %s', $t->id()), 58 true, 59 true 60 ); 61 } 62 63 http::redirect($p_url.'&done=1&tab='.$tab); 64 } 65 catch(Exception $e) { 66 $core->error->add($e->getMessage()); 67 } 68 } 29 69 30 70 // Get task object … … 58 98 } 59 99 60 // Get expired tasks 61 $core->auth->user_prefs->addWorkspace('maintenance'); 62 if ($core->auth->user_prefs->maintenance->plugin_message) { 63 $expired = $maintenance->getExpired(); 64 } 100 // Combos 101 102 $combo_ts = array( 103 __('Every week') => 1,//604800, 104 __('Every two weeks') => 1209600, 105 __('Every month') => 2592000, 106 __('Every two months') => 5184000 107 ); 108 109 $full_combo_ts = array_merge(array( 110 __('Use different periods for each task') => 'seperate'), 111 $combo_ts 112 ); 113 114 $task_combo_ts = array_merge(array( 115 __('Never') => 0), 116 $combo_ts 117 ); 65 118 66 119 // Display page … … 68 121 echo '<html><head> 69 122 <title>'.__('Maintenance').'</title>'. 70 dcPage::jsPageTabs($tab); 123 dcPage::jsPageTabs($tab). 124 dcPage::jsLoad('index.php?pf=maintenance/js/settings.js');; 71 125 72 126 if ($task && $task->ajax()) { … … 87 141 // Success message 88 142 89 $msg = $task && !empty($_GET['done']) ? dcPage::success($task->success(),true,true,false) : ''; 143 if (!empty($_GET['done']) && $tab == 'settings') { 144 $msg = dcPage::success(__('Settings successfully updated'), true, true, false); 145 } 146 elseif (!empty($_GET['done']) && $task) { 147 $msg = dcPage::success($task->success(), true, true, false); 148 } 90 149 91 150 if ($task && ($res = $task->step()) !== null) { … … 120 179 '</form>'. 121 180 '<p class="step-back">'. 122 '<a class="back" href="'.$p_url.' ">'.__('Back').'</a>'.181 '<a class="back" href="'.$p_url.'&tab='.$task->tab().'">'.__('Back').'</a>'. 123 182 '</p>'. 124 183 '</div>'; … … 156 215 html::escapeHTML($t->task()).'</label>'; 157 216 158 if (array_key_exists($t->id(), $expired)) { 159 $res_task .= 160 '<br /> <span class="warn">'.sprintf( 161 __('Last execution of this task was on %s.'), 162 dt::dt2str(__('%Y-%m-%d %H:%M'), $expired[$t->id()]) 163 ).' '. 164 __('You should execute it now.').'</span>'; 165 } 166 elseif ($t->ts()) { 167 $res_task .= 168 '<br /> <span class="warn">'. 169 __('This task has never been executed.').' '. 170 __('You should execute it now.').'</span>'; 217 // Expired task alert message 218 $ts = $t->expired(); 219 if ($core->blog->settings->maintenance->plugin_message && $ts !== false) { 220 if ($ts === null) { 221 $res_task .= 222 '<br /> <span class="warn">'. 223 __('This task has never been executed.').' '. 224 __('You should execute it now.').'</span>'; 225 } 226 else { 227 $res_task .= 228 '<br /> <span class="warn">'.sprintf( 229 __('Last execution of this task was on %s.'), 230 dt::str($core->blog->settings->system->date_format, $ts).' '. 231 dt::str($core->blog->settings->system->time_format, $ts) 232 ).' '. 233 __('You should execute it now.').'</span>'; 234 } 171 235 } 172 236 … … 192 256 form::hidden(array('tab'), $tab_id). 193 257 $core->formNonce().'</p>'. 194 '<p class="form-note info">'.__('This may take a very long time ').'.</p>'.258 '<p class="form-note info">'.__('This may take a very long time.').'.</p>'. 195 259 '</form>'. 196 260 '</div>'; … … 218 282 '</div>'; 219 283 } 284 285 // Settings 286 287 echo 288 '<div id="settings" class="multi-part" title="'.__('Settings').'">'. 289 '<h3>'.__('Settings').'</h3>'. 290 '<form action="'.$p_url.'" method="post">'. 291 292 '<p><label for="settings_plugin_message" class="classic">'. 293 form::checkbox('settings_plugin_message', 1, $core->blog->settings->maintenance->plugin_message). 294 __('Display alert messages on expired tasks').'</label></p>'. 295 296 '<p><label for="settings_recall_time">'.__('Recall time for all tasks:').'</label>'. 297 form::combo('settings_recall_time', $full_combo_ts, 'seperate', 'recall-for-all'). 298 '</p>'. 299 300 '<p>'.__('Recall time per task:').'</p>'; 301 302 foreach($maintenance->getTasks($core) as $t) 303 { 304 echo 305 '<div class="two-boxes">'. 306 307 '<p><label for="settings_ts_'.$t->id().'">'.$t->task().'</label>'. 308 form::combo('settings_ts_'.$t->id(), $task_combo_ts, $t->ts(), 'recall-per-task'). 309 '</p>'. 310 311 '</div>'; 312 } 313 314 echo 315 '<p><input type="submit" value="'.__('Save').'" /> '. 316 form::hidden(array('tab'), 'settings'). 317 form::hidden(array('settings'), 1). 318 $core->formNonce().'</p>'. 319 '</form>'. 320 '<p class="info">'.sprintf( 321 __('You can place list of expired tasks on your %s.'), 322 '<a href="preferences.php#user-favorites">'.__('Dashboard').'</a>' 323 ).'</a></p>'. 324 '</div>'; 220 325 } 221 326
Note: See TracChangeset
for help on using the changeset viewer.