| 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of Dotclear 2. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
|---|
| 7 | # Licensed under the GPL version 2.0 license. |
|---|
| 8 | # See LICENSE file or |
|---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|---|
| 10 | # |
|---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
|---|
| 12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
|---|
| 13 | |
|---|
| 14 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : null; |
|---|
| 15 | $start = !empty($_GET['start']) ? abs((integer) $_GET['start']) : 0; |
|---|
| 16 | |
|---|
| 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 | } |
|---|
| 28 | } |
|---|
| 29 | http::redirect($p_url.'&vacuum=1'); |
|---|
| 30 | } |
|---|
| 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) { |
|---|
| 60 | $core->error->add($e->getMessage()); |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | ?> |
|---|
| 65 | <html> |
|---|
| 66 | <head> |
|---|
| 67 | <title><?php echo __('Maintenance'); ?></title> |
|---|
| 68 | </head> |
|---|
| 69 | |
|---|
| 70 | <body> |
|---|
| 71 | <?php |
|---|
| 72 | echo dcPage::breadcrumb( |
|---|
| 73 | array( |
|---|
| 74 | __('Plugins') => '', |
|---|
| 75 | '<span class="page-title">'.__('Maintenance').'</span>' => '' |
|---|
| 76 | )); |
|---|
| 77 | ?> |
|---|
| 78 | |
|---|
| 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.')); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 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 | echo |
|---|
| 104 | '<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 | else |
|---|
| 112 | { |
|---|
| 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 | echo |
|---|
| 128 | '<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 | else |
|---|
| 136 | { |
|---|
| 137 | dcPage::message(__('Comments index done.')); |
|---|
| 138 | echo '<p><a class="back" href="'.$p_url.'">'.__('Back').'</a></p>'; |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | else |
|---|
| 142 | { |
|---|
| 143 | echo |
|---|
| 144 | '<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 | echo |
|---|
| 154 | '<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 | echo |
|---|
| 164 | '<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 | echo |
|---|
| 175 | '<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 | echo |
|---|
| 185 | '<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 | dcPage::helpBlock('maintenance'); |
|---|
| 195 | ?> |
|---|
| 196 | |
|---|
| 197 | </body> |
|---|
| 198 | </html> |
|---|