| 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_RC_PATH')) { return; } |
|---|
| 13 | |
|---|
| 14 | define('UTF8MB4_MAXLEN',191); |
|---|
| 15 | |
|---|
| 16 | class dcMaintenanceUtf8mb4 extends dcMaintenanceTask |
|---|
| 17 | { |
|---|
| 18 | protected $perm = null; // super admin only |
|---|
| 19 | protected $step_task; |
|---|
| 20 | protected $list; |
|---|
| 21 | |
|---|
| 22 | protected function init() |
|---|
| 23 | { |
|---|
| 24 | $this->name = __('UTF8-mb4 check'); |
|---|
| 25 | $this->task = __('UTF8-mb4 compatibility check'); |
|---|
| 26 | $this->step = __('Next: %s'); |
|---|
| 27 | $this->step_task = __('Next'); |
|---|
| 28 | $this->success = __('Check end'); |
|---|
| 29 | $this->error = __('Some data will not be fully importable in a UTF8-mb4 database. You need to reduce them before.'); |
|---|
| 30 | |
|---|
| 31 | $this->description = __('Check various data for compatibility with UTF8-mb4 (full UTF8 encoding storage) before exporting and importing them in a new UTF8-mb4 MySQL database.'); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | public function execute() |
|---|
| 35 | { |
|---|
| 36 | $this->code = $this->checkUtf8mb4($this->code); |
|---|
| 37 | return $this->code ?: true; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | public function task() |
|---|
| 41 | { |
|---|
| 42 | return $this->code ? $this->step_task : $this->task; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | public function step() |
|---|
| 46 | { |
|---|
| 47 | return $this->code ? '<p>'.$this->list.'</p>' : null; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | public function success() |
|---|
| 51 | { |
|---|
| 52 | return $this->code ? sprintf($this->step, $this->step_task) : $this->success; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | public function header() |
|---|
| 56 | { |
|---|
| 57 | return sprintf($this->step, $this->step_task); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | protected function checkUtf8mb4($code=null) |
|---|
| 61 | { |
|---|
| 62 | switch ($code) { |
|---|
| 63 | case null: |
|---|
| 64 | case 0: |
|---|
| 65 | # check posts |
|---|
| 66 | $this->list = __('All post URLs are importable in UTF8-mb4 database'); |
|---|
| 67 | |
|---|
| 68 | $rs = $this->core->con->select( |
|---|
| 69 | 'SELECT post_id, post_type, post_title, post_url, LENGTH(post_url) AS xlen FROM '.$this->core->prefix.'post '. |
|---|
| 70 | 'WHERE LENGTH(post_url) > '.UTF8MB4_MAXLEN.' ORDER BY post_id', true); |
|---|
| 71 | if (!$rs->isEmpty()) { |
|---|
| 72 | $this->list = |
|---|
| 73 | '<p class="step-msg">'. |
|---|
| 74 | sprintf(__('%s post URLs are longer than %d characters:'),$rs->count(),UTF8MB4_MAXLEN).'</p>'. |
|---|
| 75 | '<div class="table-outer">'. |
|---|
| 76 | '<table>'. |
|---|
| 77 | '<th class="first">'.__('Title').'</th>'. |
|---|
| 78 | '<th>'.__('URL Length').'</th>'; |
|---|
| 79 | while ($rs->fetch()) { |
|---|
| 80 | $this->list .= |
|---|
| 81 | '<tr class="line" id="p'.$rs->post_id.'">'. |
|---|
| 82 | '<td class="maximal" scope="row"><a href="'. |
|---|
| 83 | $this->core->getPostAdminURL($rs->post_type,$rs->post_id).'">'. |
|---|
| 84 | html::escapeHTML($rs->post_title).'</a></td>'. |
|---|
| 85 | '<td class="nowrap count">'.$rs->xlen.'</td>'. |
|---|
| 86 | '</tr>'; |
|---|
| 87 | } |
|---|
| 88 | $this->list .= |
|---|
| 89 | '</table>'. |
|---|
| 90 | '</div>'; |
|---|
| 91 | } |
|---|
| 92 | $code++; |
|---|
| 93 | break; |
|---|
| 94 | case 1: |
|---|
| 95 | # check pings |
|---|
| 96 | $this->list = __('All ping URLs are importable in UTF8-mb4 database'); |
|---|
| 97 | |
|---|
| 98 | $rs = $this->core->con->select( |
|---|
| 99 | 'SELECT post_id, ping_url, LENGTH(ping_url) AS xlen FROM '.$this->core->prefix.'ping '. |
|---|
| 100 | 'WHERE LENGTH(ping_url) > '.UTF8MB4_MAXLEN.' ORDER BY post_id', true); |
|---|
| 101 | if (!$rs->isEmpty()) { |
|---|
| 102 | $this->list = |
|---|
| 103 | '<p class="step-msg">'. |
|---|
| 104 | sprintf(__('%s ping URLs are longer than %d characters:'),$rs->count(),UTF8MB4_MAXLEN).'</p>'. |
|---|
| 105 | '<div class="table-outer">'. |
|---|
| 106 | '<table>'. |
|---|
| 107 | '<th class="first">'.__('Ping URL').'</th>'. |
|---|
| 108 | '<th>'.__('URL Length').'</th>'; |
|---|
| 109 | while ($rs->fetch()) { |
|---|
| 110 | $this->list .= |
|---|
| 111 | '<tr class="line" id="p'.$rs->post_id.'">'. |
|---|
| 112 | '<td class="maximal" scope="row"><a href="'. |
|---|
| 113 | $this->core->getPostAdminURL('post',$rs->post_id).'#trackbacks">'. |
|---|
| 114 | html::escapeHTML($rs->ping_url).'</a></td>'. |
|---|
| 115 | '<td class="nowrap count">'.$rs->xlen.'</td>'. |
|---|
| 116 | '</tr>'; |
|---|
| 117 | } |
|---|
| 118 | $this->list .= |
|---|
| 119 | '</table>'. |
|---|
| 120 | '</div>'; |
|---|
| 121 | } |
|---|
| 122 | $code++; |
|---|
| 123 | break; |
|---|
| 124 | case 2: |
|---|
| 125 | # check meta |
|---|
| 126 | $this->list = __('All meta IDs are importable in UTF8-mb4 database'); |
|---|
| 127 | |
|---|
| 128 | $rs = $this->core->con->select( |
|---|
| 129 | 'SELECT meta_id, meta_type, LENGTH(meta_id) AS xlen FROM '.$this->core->prefix.'meta '. |
|---|
| 130 | 'WHERE LENGTH(meta_id) > '.UTF8MB4_MAXLEN.' ORDER BY meta_id', true); |
|---|
| 131 | if (!$rs->isEmpty()) { |
|---|
| 132 | $this->list = |
|---|
| 133 | '<p class="step-msg">'. |
|---|
| 134 | sprintf(__('%s meta IDs are longer than %d characters:'),$rs->count(),UTF8MB4_MAXLEN).'</p>'. |
|---|
| 135 | '<div class="table-outer">'. |
|---|
| 136 | '<table>'. |
|---|
| 137 | '<th class="first">'.__('Meta ID').'</th>'. |
|---|
| 138 | '<th>'.__('Type').'</th>'. |
|---|
| 139 | '<th>'.__('Length').'</th>'; |
|---|
| 140 | while ($rs->fetch()) { |
|---|
| 141 | $this->list .= |
|---|
| 142 | '<tr class="line" id="m-'.$rs->meta_id.'">'. |
|---|
| 143 | '<td class="maximal" scope="row">'. |
|---|
| 144 | ($rs->meta_type == 'tag' ? |
|---|
| 145 | '<a href="'.$this->core->adminurl->get('admin.plugin.tags', |
|---|
| 146 | array('m' => 'tag_posts','tag' => $rs->meta_id)).'">' : ''). |
|---|
| 147 | html::escapeHTML($rs->meta_id).($rs->meta_type == 'tag' ? '</a>' : '').'</td>'. |
|---|
| 148 | '<td>'.$rs->meta_type.'</td>'. |
|---|
| 149 | '<td class="nowrap count">'.$rs->xlen.'</td>'. |
|---|
| 150 | '</tr>'; |
|---|
| 151 | } |
|---|
| 152 | $this->list .= |
|---|
| 153 | '</table>'. |
|---|
| 154 | '</div>'; |
|---|
| 155 | } |
|---|
| 156 | $code++; |
|---|
| 157 | break; |
|---|
| 158 | case 3: |
|---|
| 159 | # check categories |
|---|
| 160 | $this->list = __('All Category URLs are importable in UTF8-mb4 database'); |
|---|
| 161 | |
|---|
| 162 | $rs = $this->core->con->select( |
|---|
| 163 | 'SELECT cat_id, cat_title, cat_url, LENGTH(cat_url) AS xlen FROM '.$this->core->prefix.'category '. |
|---|
| 164 | 'WHERE LENGTH(cat_url) > '.UTF8MB4_MAXLEN.' ORDER BY cat_id', true); |
|---|
| 165 | if (!$rs->isEmpty()) { |
|---|
| 166 | $this->list = |
|---|
| 167 | '<p class="step-msg">'. |
|---|
| 168 | sprintf(__('%s category URLs are longer than %d characters:'),$rs->count(),UTF8MB4_MAXLEN).'</p>'. |
|---|
| 169 | '<div class="table-outer">'. |
|---|
| 170 | '<table>'. |
|---|
| 171 | '<th class="first">'.__('Title').'</th>'. |
|---|
| 172 | '<th>'.__('URL Length').'</th>'; |
|---|
| 173 | while ($rs->fetch()) { |
|---|
| 174 | $this->list .= |
|---|
| 175 | '<tr class="line" id="c-'.$rs->cat_id.'">'. |
|---|
| 176 | '<td class="maximal" scope="row">'. |
|---|
| 177 | '<a href="'.$this->core->adminurl->get('admin.category',array('id' => $rs->cat_id)).'">'. |
|---|
| 178 | html::escapeHTML($rs->cat_title).'</a></td>'. |
|---|
| 179 | '<td class="nowrap count">'.$rs->xlen.'</td>'. |
|---|
| 180 | '</tr>'; |
|---|
| 181 | } |
|---|
| 182 | $this->list .= |
|---|
| 183 | '</table>'. |
|---|
| 184 | '</div>'; |
|---|
| 185 | } |
|---|
| 186 | $code++; |
|---|
| 187 | break; |
|---|
| 188 | case 4: |
|---|
| 189 | # check prefs |
|---|
| 190 | $this->list = __('All User preferences are importable in UTF8-mb4 database'); |
|---|
| 191 | |
|---|
| 192 | $rs = $this->core->con->select( |
|---|
| 193 | 'SELECT pref_id, pref_ws, LENGTH(pref_id) AS xlen FROM '.$this->core->prefix.'pref '. |
|---|
| 194 | 'WHERE LENGTH(pref_id) > '.UTF8MB4_MAXLEN.' ORDER BY pref_ws,pref_id', true); |
|---|
| 195 | if (!$rs->isEmpty()) { |
|---|
| 196 | $this->list = |
|---|
| 197 | '<p class="step-msg">'. |
|---|
| 198 | sprintf(__('%s User preference IDs are longer than %d characters:'),$rs->count(),UTF8MB4_MAXLEN).'</p>'. |
|---|
| 199 | '<div class="table-outer">'. |
|---|
| 200 | '<table>'. |
|---|
| 201 | '<th class="first">'.__('Preference ID').'</th>'. |
|---|
| 202 | '<th>'.__('Workspace').'</th>'. |
|---|
| 203 | '<th>'.__('Length').'</th>'; |
|---|
| 204 | while ($rs->fetch()) { |
|---|
| 205 | $this->list .= |
|---|
| 206 | '<tr class="line" id="p-'.$rs->pref_id.'">'. |
|---|
| 207 | '<td class="maximal" scope="row">'.html::escapeHTML($rs->pref_id).'</td>'. |
|---|
| 208 | '<td>'.html::escapeHTML($rs->pref_ws).'</td>'. |
|---|
| 209 | '<td class="nowrap count">'.$rs->xlen.'</td>'. |
|---|
| 210 | '</tr>'; |
|---|
| 211 | } |
|---|
| 212 | $this->list .= |
|---|
| 213 | '</table>'. |
|---|
| 214 | '</div>'; |
|---|
| 215 | } |
|---|
| 216 | $code++; |
|---|
| 217 | break; |
|---|
| 218 | case 5: |
|---|
| 219 | # check settings |
|---|
| 220 | $this->list = __('All Blog settings are importable in UTF8-mb4 database'); |
|---|
| 221 | |
|---|
| 222 | $rs = $this->core->con->select( |
|---|
| 223 | 'SELECT setting_id, setting_ns, LENGTH(setting_id) AS xlen FROM '.$this->core->prefix.'setting '. |
|---|
| 224 | 'WHERE LENGTH(setting_id) > '.UTF8MB4_MAXLEN.' ORDER BY setting_ns,setting_id', true); |
|---|
| 225 | if (!$rs->isEmpty()) { |
|---|
| 226 | $this->list = |
|---|
| 227 | '<p class="step-msg">'. |
|---|
| 228 | sprintf(__('%s Blog setting IDs are longer than %d characters:'),$rs->count(),UTF8MB4_MAXLEN).'</p>'. |
|---|
| 229 | '<div class="table-outer">'. |
|---|
| 230 | '<table>'. |
|---|
| 231 | '<th class="first">'.__('Setting ID').'</th>'. |
|---|
| 232 | '<th>'.__('Namespace').'</th>'. |
|---|
| 233 | '<th>'.__('Length').'</th>'; |
|---|
| 234 | while ($rs->fetch()) { |
|---|
| 235 | $this->list .= |
|---|
| 236 | '<tr class="line" id="s-'.$rs->setting_id.'">'. |
|---|
| 237 | '<td class="maximal" scope="row">'.html::escapeHTML($rs->setting_id).'</td>'. |
|---|
| 238 | '<td>'.html::escapeHTML($rs->setting_ns).'</td>'. |
|---|
| 239 | '<td class="nowrap count">'.$rs->xlen.'</td>'. |
|---|
| 240 | '</tr>'; |
|---|
| 241 | } |
|---|
| 242 | $this->list .= |
|---|
| 243 | '</table>'. |
|---|
| 244 | '</div>'; |
|---|
| 245 | } |
|---|
| 246 | $code++; |
|---|
| 247 | break; |
|---|
| 248 | default: |
|---|
| 249 | # Ending check |
|---|
| 250 | $code = null; |
|---|
| 251 | break; |
|---|
| 252 | } |
|---|
| 253 | return $code; |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | } |
|---|