Changeset 1925:567a4a03e5df for plugins
- Timestamp:
- 09/17/13 01:23:06 (12 years ago)
- Branch:
- default
- Location:
- plugins/maintenance
- Files:
-
- 11 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/maintenance/_admin.php
r1179 r1925 12 12 if (!defined('DC_CONTEXT_ADMIN')) { return; } 13 13 14 $_menu['Plugins']->addItem(__('Maintenance'),'plugin.php?p=maintenance','index.php?pf=maintenance/icon.png', 15 preg_match('/plugin.php\?p=maintenance(&.*)?$/',$_SERVER['REQUEST_URI']), 16 $core->auth->isSuperAdmin()); 14 // Sidebar menu 15 $_menu['Plugins']->addItem( 16 __('Maintenance'), 17 'plugin.php?p=maintenance', 18 'index.php?pf=maintenance/icon.png', 19 preg_match('/plugin.php\?p=maintenance(&.*)?$/', $_SERVER['REQUEST_URI']), 20 $core->auth->isSuperAdmin() 21 ); 17 22 18 $core->addBehavior('adminDashboardFavs','maintenanceDashboardFavs'); 23 // Admin behaviors 24 $core->addBehavior('dcMaintenanceRegister', array('dcMaintenanceAdmin', 'register')); 25 $core->addBehavior('adminDashboardFavs', array('dcMaintenanceAdmin', 'favs')); 19 26 20 function maintenanceDashboardFavs($core,$favs) 27 /** 28 @ingroup PLUGIN_MAINTENANCE 29 @nosubgrouping 30 @brief Maintenance plugin admin class. 31 32 Group of methods used on behaviors. 33 */ 34 class dcMaintenanceAdmin 21 35 { 22 $favs['maintenance'] = new ArrayObject(array('maintenance','Maintenance','plugin.php?p=maintenance', 23 'index.php?pf=maintenance/icon.png','index.php?pf=maintenance/icon-big.png', 24 null,null,null)); 36 /** 37 * Register default tasks 38 * 39 * @param $core <b>dcCore</b> dcCore instance 40 * @param $tasks <b>arrayObject</b> Array of tasks to register 41 * @param $groups <b>arrayObject</b> Array of groups to register 42 */ 43 public static function register($core, $tasks, $groups) 44 { 45 $groups['optimize'] = __('Optimize'); 46 $groups['index'] = __('Count and index'); 47 $groups['purge'] = __('Purge'); 48 $groups['other'] = __('Other'); 49 50 $tasks[] = 'dcMaintenanceCache'; 51 $tasks[] = 'dcMaintenanceCountcomments'; 52 $tasks[] = 'dcMaintenanceIndexcomments'; 53 $tasks[] = 'dcMaintenanceIndexposts'; 54 $tasks[] = 'dcMaintenanceLogs'; 55 $tasks[] = 'dcMaintenanceVacuum'; 56 } 57 58 /** 59 * Dashboard favs 60 * 61 * @param $core <b>dcCore</b> dcCore instance 62 * @param $favs <b>arrayObject</b> Array of favs 63 */ 64 public static function favs($core, $favs) 65 { 66 $favs['maintenance'] = new ArrayObject(array( 67 'maintenance', 68 'Maintenance', 69 'plugin.php?p=maintenance', 70 'index.php?pf=maintenance/icon.png', 71 'index.php?pf=maintenance/icon-big.png', 72 null,null,null 73 )); 74 } 75 76 /** @todo Rminder*/ 25 77 } 26 ?> -
plugins/maintenance/_define.php
r1179 r1925 14 14 $this->registerModule( 15 15 /* Name */ "Maintenance", 16 /* Description*/ "Maintain your database",17 /* Author */ "Olivier Meunier ",18 /* Version */ '1. 2'16 /* Description*/ "Maintain your installation", 17 /* Author */ "Olivier Meunier & Association Dotclear", 18 /* Version */ '1.3' 19 19 ); 20 ?> -
plugins/maintenance/index.php
r1760 r1925 12 12 if (!defined('DC_CONTEXT_ADMIN')) { return; } 13 13 14 $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : null; 15 $start = !empty($_GET['start']) ? abs((integer) $_GET['start']) : 0; 14 dcPage::checkSuper(); 16 15 17 if ($action == 'vacuum') 18 { 19 try 20 { 21 $schema = dbSchema::init($core->con); 22 $db_tables = $schema->getTables(); 23 24 foreach ($db_tables as $t) { 25 if (strpos($t,$core->prefix) === 0) { 26 $core->con->vacuum($t); 27 } 16 // main class 17 18 $maintenance = new dcMaintenance($core); 19 20 // Set var 21 22 $headers = ''; 23 $p_url = 'plugin.php?p=maintenance'; 24 $task = null; 25 26 $code = empty($_POST['code']) ? null : (integer) $_POST['code']; 27 $tab = empty($_REQUEST['tab']) ? 'maintenance' : $_REQUEST['tab']; 28 29 // Get task object 30 31 if (!empty($_REQUEST['task'])) { 32 $task = $maintenance->getTask($_REQUEST['task']); 33 34 if ($task === null) { 35 $core->error->add('Unknow task ID'); 36 } 37 38 $task->code($code); 39 } 40 41 // Execute task 42 43 if ($task && !empty($_POST['task']) && $task->id() == $_POST['task']) { 44 try { 45 $code = $task->execute(); 46 if (false === $code) { 47 throw new Exception($task->error()); 28 48 } 29 http::redirect($p_url.'&vacuum=1'); 49 if (true === $code) { 50 http::redirect($p_url.'&task='.$task->id().'&done=1&tab='.$tab); 51 } 30 52 } 31 catch (Exception $e) 32 { 33 $core->error->add($e->getMessage()); 34 } 35 } 36 elseif ($action == 'commentscount') 37 { 38 try { 39 $core->countAllComments(); 40 http::redirect($p_url.'&commentscount=1'); 41 } catch (Exception $e) { 42 $core->error->add($e->getMessage()); 43 } 44 } 45 elseif ($action == 'empty_cache') 46 { 47 try { 48 $core->emptyTemplatesCache(); 49 http::redirect($p_url.'&empty_cache=1'); 50 } catch (Exception $e) { 51 $core->error->add($e->getMessage()); 52 } 53 } 54 elseif ($action == 'log') 55 { 56 try { 57 $core->log->delLogs(null,true); 58 http::redirect($p_url.'&delete_logs=1'); 59 } catch (Exception $e) { 53 catch (Exception $e) { 60 54 $core->error->add($e->getMessage()); 61 55 } 62 56 } 63 57 64 ?> 65 <html> 66 <head> 67 <title><?php echo __('Maintenance'); ?></title> 58 // Display page 59 60 echo '<html><head> 61 <title>'.__('Maintenance').'</title>'. 62 dcPage::jsPageTabs($tab); 63 64 if ($task) { 65 echo 66 '<script type="text/javascript">'."\n". 67 "//<![CDATA\n". 68 dcPage::jsVar('dotclear.msg.wait', __('Please wait...')). 69 "//]]>\n". 70 '</script>'. 71 dcPage::jsLoad('index.php?pf=maintenance/js/dc.maintenance.js'); 72 } 73 74 echo 75 $maintenance->getHeaders().' 68 76 </head> 77 <body>'; 69 78 70 <body> 71 <?php 79 // Success message 80 81 if ($task && !empty($_GET['done'])) { 82 dcPage::success($task->success()); 83 } 84 85 if ($task && ($res = $task->step()) !== null) { 86 87 // Page title 88 89 echo dcPage::breadcrumb( 90 array( 91 __('Plugins') => '', 92 '<a href="'.$p_url.'">'.__('Maintenance').'</a>' => '', 93 '<span class="page-title">'.html::escapeHTML($task->name()).'</span>' => '' 94 ) 95 ); 96 97 // Intermediate task (task required several steps) 98 99 echo 100 '<div class="step-box" id="'.$task->id().'">'. 101 '<h3>'.html::escapeHTML($task->name()).'</h3>'. 102 '<form action="'.$p_url.'" method="post">'. 103 '<p class="step-msg">'. 104 $res. 105 '</p>'. 106 '<p class="step-submit">'. 107 '<input type="submit" value="'.$task->task().'" /> '. 108 form::hidden(array('task'), $task->id()). 109 form::hidden(array('code'), (integer) $code). 110 $core->formNonce(). 111 '</p>'. 112 '</form>'. 113 '<p class="step-back">'. 114 '<a class="back" href="'.$p_url.'">'.__('Back').'</a>'. 115 '</p>'. 116 '</div>'; 117 } 118 else { 119 120 // Page title 121 72 122 echo dcPage::breadcrumb( 73 123 array( 74 124 __('Plugins') => '', 75 125 '<span class="page-title">'.__('Maintenance').'</span>' => '' 76 ) );77 ?> 126 ) 127 ); 78 128 79 <?php 80 if (!empty($_GET['vacuum'])) { 81 dcPage::success(__('Optimization successful.')); 82 } 83 if (!empty($_GET['commentscount'])) { 84 dcPage::success(__('Comments and trackback counted.')); 85 } 86 if (!empty($_GET['empty_cache'])) { 87 dcPage::success(__('Templates cache directory emptied.')); 88 } 89 if (!empty($_GET['delete_logs'])) { 90 dcPage::success(__('Logs deleted.')); 129 // Simple task (with only a button to start it) 130 131 echo 132 '<div id="maintenance" class="multi-part" title="'.__('Maintenance').'">'. 133 '<h3>'.__('Maintenance').'</h3>'. 134 '<form action="'.$p_url.'" method="post">'; 135 136 foreach($maintenance->getGroups($core) as $g_id => $g_name) 137 { 138 $res = ''; 139 foreach($maintenance->getTasks($core) as $t) 140 { 141 if ($t->group() != $g_id) { 142 continue; 143 } 144 145 $res .= 146 '<p>'.form::radio(array('task', $t->id()),$t->id()).' '. 147 '<label class="classic" for="'.$t->id().'">'. 148 html::escapeHTML($t->task()).'</label></p>'; 149 } 150 151 if (!empty($res)) { 152 echo '<div class="fieldset"><h4 id="'.$g_id.'">'.$g_name.'</h4>'.$res.'</div>'; 153 } 154 } 155 156 echo 157 '<p><input type="submit" value="'.__('Execute task').'" /> '. 158 form::hidden(array('tab'), 'maintenance'). 159 $core->formNonce().'</p>'. 160 '<p class="form-note info">'.__('This may take a very long time').'.</p>'. 161 '</form>'. 162 '</div>'; 163 164 // Advanced tasks (that required a tab) 165 166 foreach($maintenance->getTasks($core) as $t) 167 { 168 if ($t->group() !== null) { 169 continue; 170 } 171 172 echo 173 '<div id="'.$t->id().'" class="multi-part" title="'.$t->name().'">'. 174 '<h3>'.$t->name().'</h3>'. 175 '<form action="'.$p_url.'" method="post">'. 176 $t->content(). 177 '<p><input type="submit" value="'.__('Execute task').'" /> '. 178 form::hidden(array('task'), $t->id()). 179 form::hidden(array('tab'), $t->id()). 180 $core->formNonce().'</p>'. 181 '</form>'. 182 '</div>'; 183 } 91 184 } 92 185 93 if ($action == 'index' && !empty($_GET['indexposts']))94 {95 $limit = 1000;96 echo '<p>'.sprintf(__('Indexing entry %d to %d.'),$start,$start+$limit).'</p>';97 98 $new_start = $core->indexAllPosts($start,$limit);99 100 if ($new_start)101 {102 $new_url = $p_url.'&action=index&indexposts=1&start='.$new_start;103 echo104 '<script type="text/javascript">'."\n".105 "//<![CDATA\n".106 "window.location = '".$new_url."'\n".107 "//]]>\n".108 '</script>'.109 '<noscript><p><a href="'.html::escapeURL($new_url).'">'.__('next').'</a></p></noscript>';110 }111 else112 {113 dcPage::message(__('Entries index done.'));114 echo '<p><a class="back" href="'.$p_url.'">'.__('Back').'</a></p>';115 }116 }117 elseif ($action == 'index' && !empty($_GET['indexcomments']))118 {119 $limit = 1000;120 echo '<p>'.sprintf(__('Indexing comment %d to %d.'),$start,$start+$limit).'</p>';121 122 $new_start = $core->indexAllComments($start,$limit);123 124 if ($new_start)125 {126 $new_url = $p_url.'&action=index&indexcomments=1&start='.$new_start;127 echo128 '<script type="text/javascript">'."\n".129 "//<![CDATA\n".130 "window.location = '".$new_url."'\n".131 "//]]>\n".132 '</script>'.133 '<noscript><p><a href="'.html::escapeURL($new_url).'">'.__('next').'</a></p></noscript>';134 }135 else136 {137 dcPage::message(__('Comments index done.'));138 echo '<p><a class="back" href="'.$p_url.'">'.__('Back').'</a></p>';139 }140 }141 else142 {143 echo144 '<div class="two-boxes">'.145 '<h3>'.__('Optimize database room').'</h3>'.146 '<form action="plugin.php" method="post">'.147 '<p><input type="submit" value="'.__('Vacuum tables').'" /> '.148 $core->formNonce().149 form::hidden(array('action'),'vacuum').150 form::hidden(array('p'),'maintenance').'</p>'.151 '</form></div>';152 153 echo154 '<div class="two-boxes">'.155 '<h3>'.__('Counters').'</h3>'.156 '<form action="plugin.php" method="post">'.157 '<p><input type="submit" value="'.__('Reset comments and ping counters').'" /> '.158 $core->formNonce().159 form::hidden(array('action'),'commentscount').160 form::hidden(array('p'),'maintenance').'</p>'.161 '</form></div>';162 163 echo164 '<div class="two-boxes">'.165 '<h3>'.__('Search engine index').'</h3>'.166 '<form action="plugin.php" method="get">'.167 '<p><input type="submit" name="indexposts" value="'.__('Index all posts').'" /> '.168 '<input type="submit" name="indexcomments" value="'.__('Index all comments').'" /> '.169 form::hidden(array('action'),'index').170 form::hidden(array('p'),'maintenance').'</p>'.171 '<p class="form-note info">'.__('This may take a very long time').'.</p>'.172 '</form></div>';173 174 echo175 '<div class="two-boxes">'.176 '<h3>'.__('Vacuum logs').'</h3>'.177 '<form action="plugin.php" method="post">'.178 '<p><input type="submit" value="'.__('Delete all logs').'" /> '.179 $core->formNonce().180 form::hidden(array('action'),'log').181 form::hidden(array('p'),'maintenance').'</p>'.182 '</form></div>';183 184 echo185 '<div class="two-boxes">'.186 '<h3>'.__('Empty templates cache directory').'</h3>'.187 '<form action="plugin.php" method="post">'.188 '<p><input type="submit" value="'.__('Empty directory').'" /> '.189 $core->formNonce().190 form::hidden(array('action'),'empty_cache').191 form::hidden(array('p'),'maintenance').'</p>'.192 '</form></div>';193 }194 186 dcPage::helpBlock('maintenance'); 195 ?>196 187 197 </body> 198 </html> 188 echo '</body></html>';
Note: See TracChangeset
for help on using the changeset viewer.