diff --git a/languages/sqlite-integration-ja.mo b/languages/sqlite-integration-ja.mo index f7a9b8a..372e7f2 100644 Binary files a/languages/sqlite-integration-ja.mo and b/languages/sqlite-integration-ja.mo differ diff --git a/languages/sqlite-integration-ja.po b/languages/sqlite-integration-ja.po index 1467a58..5e96c70 100644 --- a/languages/sqlite-integration-ja.po +++ b/languages/sqlite-integration-ja.po @@ -1227,3 +1227,113 @@ msgid "" "continue." msgstr "" "この内容を保存してもよろしいですか?\\n\\nやめるなら[キャンセル]を、続けるなら[OK]をクリック。" + +#: database_maintenance.php:314 +msgid "Can't create backup file." +msgstr "バックアップファイルを作れません。" + +#: database_maintenance.php:334 +msgid "Failed: " +msgstr "失敗: " + +#: database_maintenance.php:395 +msgid "Maintenance" +msgstr "メンテナンス" + +#: database_maintenance.php:399 +msgid "Database Maintenace" +msgstr "データベース・メンテナンス" + +#: database_maintenance.php:400 +msgid "Important Notice" +msgstr "重要なお知らせ" + +#: database_maintenance.php:402 +msgid "" +"When you installed WordPress 3.5.x with SQLite Integration and upgraded to " +"3.6, your database might not function as expected." +msgstr "" +"WordPress 3.5.x を SQLite Integrationを使ってインストールし、3.6 にアップグレードした場合、" +"データベースが意図したとおりに動作しないかもしれません。" + +#: database_maintenance.php:403 +msgid "" +"This page provide you the database sanity check utility and the restore " +"utility." +msgstr "" +"このページでは、データベースが正常かどうかをチェックするユーティリティと、回復ユーティリティを提供します。" + +#: database_maintenance.php:406 +msgid "" +"Click \"Sanity Check\" button first, and see if you need to fix database or " +"not. If needed, click \"Fix Database\" button. Afterward you may go to " +"Miscellaneous page and optimize database (this is not required)." +msgstr "" +"「正常チェック」ボタンを最初にクリックして、データベースが修復を必要とするかどうかを見てください。必要なら、" +"「修復」ボタンをクリックしてください。「いろいろ」ページに移動して、最適化をすることもできます(必須ではありません)。" + +#: database_maintenance.php:409 +msgid "" +"Fix Database procedure will create a database backup file each time the " +"button clicked. The backup file is named with \"maintenance-backup\", so you " +"can remove it if you don't need it. Please go to Miscellaneous page and " +"check if there is one." +msgstr "" +"データベースの修復は、ボタンがクリックされるたびにバックアップファイルを作成します。ファイル名には、" +"\"maintenance-backup\"とついていますので、必要なければ削除してかまいません。" +"「いろいろ」ページに移動して、バックアップファイルが作成されているかどうかご覧ください。" + +#: database_maintenance.php:412 +msgid "" +"If you installed WordPress 3.6 (not upgraded), you don't have to restore the " +"database." +msgstr "" +"アップグレードではなくて、WordPress 3.6 を最初からインストールした場合は、データベースの修復は" +"必要ありません。" + +#: database_maintenance.php:421 +msgid "Sanity Check" +msgstr "正常チェック" + +#: database_maintenance.php:421 +msgid "" +"Are you sure to check the database? This will take some time.\\n\\nClick " +"[Cancel] to stop, [OK] to continue." +msgstr "" +"データベースのチェックをします。この操作は少し時間がかかるかもしれません。\\n\\nやめるなら[キャンセル]を、" +"続けるなら[OK]をクリックしてください。" + +#: database_maintenance.php:422 +msgid "Fix database" +msgstr "修復" + +#: database_maintenance.php:422 +msgid "" +"Are you sure to do fix the database? This will take some time.\\n\\nClick " +"[Cancel] to stop, [OK] to continue." +msgstr "" +"データベースの修復をします。この操作は少し時間がかかるかもしれません。\\n\\nやめるなら[キャンセル]を、" +"続けるなら[OK]をクリックしてください。" + +#: database_maintenance.php:436 database_maintenance.php:446 +msgid "Results" +msgstr "結果" + +#: database_maintenance.php:447 +msgid "Your database restoration is successfully finished!" +msgstr "データベースの修復が成功しました。" + +#: database_maintenance.php:463 database_maintenance.php:474 +msgid "Checked Results" +msgstr "チェックの結果" + +#: database_maintenance.php:468 +msgid " needs restoring." +msgstr "修復が必要です。" + +#: database_maintenance.php:475 +msgid "Your database is OK. You don't have to restore it." +msgstr "あなたのデータベースは正常です。修復の必要はありません。" + +msgid "You can check your database and fix it if needed." +msgstr "データベースのチェックと修復をすることができます。" diff --git a/pdoengine.class.php b/pdoengine.class.php index a794ab0..a7ef23c 100644 --- a/pdoengine.class.php +++ b/pdoengine.class.php @@ -648,7 +648,12 @@ class PDOEngine extends PDO { $engine = $this->prepare_engine($this->query_type); $reason = 0; $message = ''; + $re_query = ''; $rewritten_query = $engine->rewrite_query($query, $this->query_type); + if (is_array($rewritten_query) && array_key_exists('recursion', $rewritten_query)) { + $re_query = $rewritten_query['recursion']; + unset($rewritten_query['recursion']); + } try { $this->beginTransaction(); if (is_array($rewritten_query)) { @@ -674,6 +679,9 @@ class PDOEngine extends PDO { $this->rollBack(); } } + if ($re_query != '') { + $this->query($re_query); + } if ($reason > 0) { $err_message = sprintf(__("Problem in executing alter query. Error was: %s", 'sqlite-integration'), $message); $this->set_error(__LINE__, __FUNCTION__, $err_message); diff --git a/query_alter.class.php b/query_alter.class.php index 1d52765..38d5d44 100644 --- a/query_alter.class.php +++ b/query_alter.class.php @@ -9,49 +9,65 @@ class AlterQuery { public $_query = null; public function rewrite_query($query, $query_type) { - $tokens = array(); if (stripos($query, $query_type) === false) { return false; } $query = str_replace('`', '', $query); if (preg_match('/^\\s*(ALTER\\s*TABLE)\\s*(\\w+)?\\s*/ims', $query, $match)) { + $tmp_query = array(); + $tokens = array(); + $re_command = ''; $command = str_ireplace($match[0], '', $query); $tmp_tokens['query_type'] = trim($match[1]); $tmp_tokens['table_name'] = trim($match[2]); - $command_array = $this->split_multiple($command); - foreach ($command_array as $single_command) { - $command_tokens = $this->command_tokenizer($single_command); - if (!empty($command_tokens)) { - $tokens[] = array_merge($tmp_tokens, $command_tokens); - } else { - $this->_query = 'SELECT 1=1'; - } +// $command_array = $this->split_multiple($command); + $command_array = explode(',', $command); + + $single_command = array_shift($command_array); + if (!empty($command_array)) { + $re_command = 'ALTER TABLE ' . $tmp_tokens['table_name'] . ' '; + $re_command .= implode(',', $command_array); + } + $command_tokens = $this->command_tokenizer($single_command); + if (!empty($command_tokens)) { + $tokens = array_merge($tmp_tokens, $command_tokens); + } else { + $this->_query = 'SELECT 1=1'; + return $this->_query; } - foreach ($tokens as $token) { - $command_name = $token['command']; - switch ($command_name) { - case 'add column': case 'rename to': case 'add index': case 'drop index': - $this->_query = $this->handle_single_command($token); - break; - case 'add primary key': - $this->_query = $this->handle_add_primary_key($token); - break; - case 'drop primary key': - $this->_query = $this->handle_drop_primary_key($token); - break; - case 'modify column': - $this->_query = $this->handle_modify_command($token); - break; - case 'change column': - $this->_query = $this->handle_change_command($token); - break; - case 'alter column': - $this->_query = $this->handle_alter_command($token); - break; - default: - break; +// foreach ($tokens as $token) { + $command_name = strtolower($tokens['command']); + switch ($command_name) { + case 'add column': case 'rename to': case 'add index': case 'drop index': + $tmp_query = $this->handle_single_command($tokens); + break; + case 'add primary key': + $tmp_query = $this->handle_add_primary_key($tokens); + break; + case 'drop primary key': + $tmp_query = $this->handle_drop_primary_key($tokens); + break; + case 'modify column': + $tmp_query = $this->handle_modify_command($tokens); + break; + case 'change column': + $tmp_query = $this->handle_change_command($tokens); + break; + case 'alter column': + $tmp_query = $this->handle_alter_command($tokens); + break; + default: + break; } - } +// } + if (!is_array($tmp_query)) { + $this->_query[] = $tmp_query; + } else { + $this->_query = $tmp_query; + } + if ($re_command != '') { + $this->_query = array_merge($this->_query, array('recursion' => $re_command)); + } } else { $this->_query = 'SELECT 1=1'; } @@ -60,29 +76,29 @@ class AlterQuery { private function command_tokenizer($command) { $tokens = array(); - if (preg_match('/^(ADD|DROP|RENAME|MODIFY|CHANGE|ALTER)\\s*(\\w+)?\\s*(\\w+)?\\s*/ims', $command, $match)) { + if (preg_match('/^(ADD|DROP|RENAME|MODIFY|CHANGE|ALTER)\\s*(\\w+)?\\s*(\\w+(\(.+\)|))?\\s*/ims', $command, $match)) { $the_rest = str_ireplace($match[0], '', $command); - $match_1 = strtolower(trim($match[1])); - $match_2 = strtolower(trim($match[2])); - $match_3 = isset($match[3]) ? strtolower(trim($match[3])) : ''; - switch ($match_1) { + $match_1 = trim($match[1]); + $match_2 = trim($match[2]); + $match_3 = isset($match[3]) ? trim($match[3]) : ''; + switch (strtolower($match_1)) { case 'add': - if (in_array($match_2, array('fulltext', 'constraint', 'foreign'))) { + if (in_array(strtolower($match_2), array('fulltext', 'constraint', 'foreign'))) { break; - } elseif ($match_2 == 'column') { + } elseif (stripos('column', $match_2) !== false) { $tokens['command'] = $match_1.' '.$match_2; $tokens['column_name'] = $match_3; $tokens['column_def'] = trim($the_rest); - } elseif ($match_2 == 'primary') { + } elseif (stripos('primary', $match_2) !== false) { $tokens['command'] = $match_1.' '.$match_2.' '.$match_3; $tokens['column_name'] = $the_rest; - } elseif ($match_2 == 'unique') { + } elseif (stripos('unique', $match_2) !== false) { list($index_name, $col_name) = preg_split('/[\(\)]/s', trim($the_rest), -1, PREG_SPLIT_DELIM_CAPTURE); $tokens['unique'] = true; $tokens['command'] = $match_1.' '.$match_3; $tokens['index_name'] = trim($index_name); $tokens['column_name'] = '('.trim($col_name).')'; - } elseif (in_array($match_2, array('index', 'key'))) { + } elseif (in_array(strtolower($match_2), array('index', 'key'))) { $tokens['command'] = $match_1.' '.$match_2; if ($match_3 == '') { $tokens['index_name'] = str_replace(array('(', ')'), '', $the_rest); @@ -91,82 +107,94 @@ class AlterQuery { } $tokens['column_name'] = trim($the_rest); } else { - $tokens['command'] = $match_1.' column'; + $tokens['command'] = $match_1.' COLUMN'; $tokens['column_name'] = $match_2; $tokens['column_def'] = $match_3.' '.$the_rest; } break; case 'drop': - if ($match_2 == 'column') { + if (stripos('column', $match_2) !== false) { $tokens['command'] = $match_1.' '.$match_2; $tokens['column_name'] = trim($match_3); - } elseif ($match_2 == 'primary') { + } elseif (stripos('primary', $match_2) !== false) { $tokens['command'] = $match_1.' '.$match_2.' '.$match_3; - } elseif (in_array($match_2, array('index', 'key'))) { + } elseif (in_array(strtolower($match_2), array('index', 'key'))) { $tokens['command'] = $match_1.' '.$match_2; $tokens['index_name'] = $match_3; - } elseif ($match_2 == 'primary') { + } elseif (stripos('primary', $match_2) !== false) { $tokens['command'] = $match_1.' '.$match_2.' '.$match_3; } else { - $tokens['command'] = $match_1.' column'; + $tokens['command'] = $match_1.' COLUMN'; $tokens['column_name'] = $match_2; } break; case 'rename': - if ($match_2 == 'to') { + if (stripos('to', $match_2) !== false) { $tokens['command'] = $match_1.' '.$match_2; $tokens['column_name'] = $match_3; } else { - $tokens['command'] = $match_1.' to'; + $tokens['command'] = $match_1.' TO'; $tokens['column_name'] = $match_2; } break; case 'modify': - if ($match_2 == 'column') { + if (stripos('column', $match_2) !== false) { $tokens['command'] = $match_1.' '.$match_2; $tokens['column_name'] = $match_3; $tokens['column_def'] = trim($the_rest); } else { - $tokens['command'] = $match_1.' column'; + $tokens['command'] = $match_1.' COLUMN'; $tokens['column_name'] = $match_2; $tokens['column_def'] = $match_3.' '.trim($the_rest); } break; case 'change': - if ($match_2 == 'column') { + $the_rest = trim($the_rest); + if (stripos('column', $match_2) !== false) { $tokens['command'] = $match_1.' '.$match_2; $tokens['old_column'] = $match_3; - list($new_col, $col_def) = explode(' ', trim($the_rest), 2); - $tokens['new_column'] = $new_col; - $tokens['column_def'] = trim($col_def); - } else { - $tokens['command'] = $match_1.' column'; - $tokens['old_column'] = $match_2; - $tokens['new_column'] = $match_3; - $tokens['column_def'] = trim($the_rest); - } - break; - case 'alter': - if ($match_2 == 'column') { - $tokens['command'] = $match_1.' '.$match_2; - $tokens['column_name'] = $match_3; - list($set_or_drop) = explode(' ', $the_rest); - if (strtolower($set_or_drop) == 'set') { - $tokens['default_command'] = 'set default'; - $default_value = str_ireplace('set default', '', $the_rest); - $tokens['default_value'] = trim($default_value); + list($new_col) = explode(' ', $the_rest); + $tmp_col = preg_replace('/\(.+?\)/im', '', $new_col); + if (array_key_exists(strtolower($tmp_col), $this->array_types)) { + $tokens['column_def'] = $the_rest; } else { - $tokens['default_command'] = 'drop default'; + $tokens['new_column'] = $new_col; + $col_def = str_replace($new_col, '', $the_rest); + $tokens['column_def'] = trim($col_def); } } else { $tokens['command'] = $match_1.' column'; + $tokens['old_column'] = $match_2; + $tmp_col = preg_replace('/\(.+?\)/im', '', $match_3); + if (array_key_exists(strtolower($tmp_col), $this->array_types)) { + $tokens['column_def'] = $match_3 . ' ' . $the_rest; + } else { + $tokens['new_column'] = $match_3; + $tokens['column_def'] = $the_rest; + } + } + break; + case 'alter': + if (stripos('column', $match_2) !== false) { + $tokens['command'] = $match_1.' '.$match_2; + $tokens['column_name'] = $match_3; + list($set_or_drop) = explode(' ', $the_rest); + if (stripos('set', $set_or_drop) !== false) { + $tokens['default_command'] = 'SET DEFAULT'; + $default_value = str_ireplace('set default', '', $the_rest); + $tokens['default_value'] = trim($default_value); + } else { + $tokens['default_command'] = 'DROP DEFAULT'; + } + } else { + $tokens['command'] = $match_1.' COLUMN'; $tokens['column_name'] = $match_2; - if (strtolower($match_3) == 'set') { - $tokens['default_command'] = 'set default'; + if (stripos('set', $match_3) !== false) { + $tokens['default_command'] = 'SET DEFAULT'; $default_value = str_ireplace('default', '', $the_rest); $tokens['default_value'] = trim($default_value); } else { - $tokens['default_command'] = 'drop default'; + $tokens['default_command'] = 'DROP DEFAULT'; } } break; @@ -301,14 +329,14 @@ class AlterQuery { $create_query = array_shift($index_queries); if (stripos($create_query, $tokenized_query['column_name']) === false) { return 'SELECT 1=1'; - } elseif (preg_match("/{$tokenized_query['column_name']}\\s*{$tokenized_query['column_def']}\\s*[,)]/i", $create_query)) { + } elseif (preg_match("/{$tokenized_query['column_name']}\\s*{$column_def}\\s*[,)]/i", $create_query)) { return 'SELECT 1=1'; } $create_query = preg_replace("/{$tokenized_query['table_name']}/i", $temp_table, $create_query); if (preg_match("/\\b{$tokenized_query['column_name']}\\s*.*(?=,)/ims", $create_query)) { - $create_query = preg_replace("/\\b{$tokenized_query['column_name']}\\s*.*(?=,)/ims", "{$tokenized_query['column_name']} {$tokenized_query['column_def']}", $create_query); + $create_query = preg_replace("/\\b{$tokenized_query['column_name']}\\s*.*(?=,)/ims", "{$tokenized_query['column_name']} {$column_def}", $create_query); } elseif (preg_match("/\\b{$tokenized_query['column_name']}\\s*.*(?=\))/ims", $create_query)) { - $create_query = preg_replace("/\\b{$tokenized_query['column_name']}\\s*.*(?=\))/ims", "{$tokenized_query['column_name']} {$tokenized_query['column_def']}", $create_query); + $create_query = preg_replace("/\\b{$tokenized_query['column_name']}\\s*.*(?=\))/ims", "{$tokenized_query['column_name']} {$column_def}", $create_query); } $query[] = $create_query; $query[] = "INSERT INTO $temp_table SELECT * FROM {$tokenized_query['table_name']}"; @@ -326,11 +354,16 @@ class AlterQuery { $new_fields = ''; $tokenized_query = $queries; $temp_table = 'temp_'.$tokenized_query['table_name']; - $column_def = $this->convert_field_types($tokenized_query['new_column'], $tokenized_query['column_def']); + if (isset($tokenized_query['new_column'])) { + $column_name = $tokenized_query['new_column']; + } else { + $column_name = $tokenized_query['old_column']; + } + $column_def = $this->convert_field_types($column_name, $tokenized_query['column_def']); $_wpdb = new PDODB(); $col_obj = $_wpdb->get_results("SHOW COLUMNS FROM {$tokenized_query['table_name']}"); foreach ($col_obj as $col) { - if ($col->Field == $tokenized_query['old_column']) $col_check = true; + if (stripos($col->Field, $tokenized_query['old_column']) !== false) $col_check = true; $old_fields .= $col->Field . ','; } if ($col_check == false) { @@ -338,7 +371,7 @@ class AlterQuery { return 'SELECT 1=1'; } $old_fields = rtrim($old_fields, ','); - $new_fields = str_replace($tokenized_query['old_column'], $tokenized_query['new_column'], $old_fields); + $new_fields = str_ireplace($tokenized_query['old_column'], $column_name, $old_fields); $query_obj = $_wpdb->get_results("SELECT sql FROM sqlite_master WHERE tbl_name='{$tokenized_query['table_name']}'"); $_wpdb = null; for ($i = 0; $i < count($query_obj); $i++) { @@ -347,16 +380,16 @@ class AlterQuery { $create_query = array_shift($index_queries); $create_query = preg_replace("/{$tokenized_query['table_name']}/i", $temp_table, $create_query); if (preg_match("/\\b{$tokenized_query['old_column']}\\s*(.+?)(?=,)/ims", $create_query, $match)) { - if ($column_def == trim($match[1])) { + if (stripos(trim($match[1]), $column_def) !== false) { return 'SELECT 1=1'; } else { - $create_query = preg_replace("/\\b{$tokenized_query['old_column']}\\s*.*?(?=,)/ims", "{$tokenized_query['new_column']} {$column_def}", $create_query); + $create_query = preg_replace("/\\b{$tokenized_query['old_column']}\\s*.+?(?=,)/ims", "{$column_name} {$column_def}", $create_query, 1); } } elseif (preg_match("/\\b{$tokenized_query['old_column']}\\s*(.+?)(?=\))/ims", $create_query, $match)) { - if ($column_def == trim($match[1])) { + if (stripos(trim($match[1]), $column_def) !== false) { return 'SELECT 1=1'; } else { - $create_query = preg_replace("/\\b{$tokenized_query['old_column']}\\s*.*?(?=\))/ims", "{$tokenized_query['new_column']} {$column_def}", $create_query); + $create_query = preg_replace("/\\b{$tokenized_query['old_column']}\\s*.*(?=\))/ims", "{$column_name} {$column_def}", $create_query, 1); } } $query[] = $create_query; @@ -372,11 +405,11 @@ class AlterQuery { private function handle_alter_command($queries) { $tokenized_query = $queries; $temp_table = 'temp_'.$tokenized_query['table_name']; - if (stripos($tokenized_query['default_command'], 'set') !== false) { + if (isset($tokenized_query['default_value'])) { $def_value = $this->convert_field_types($tokenized_query['column_name'], $tokenized_query['default_value']); $def_value = 'DEFAULT '.$def_value; } else { - $def_value = ''; + $def_value = null; } $_wpdb = new PDODB(); $query_obj = $_wpdb->get_results("SELECT sql FROM sqlite_master WHERE tbl_name='{$tokenized_query['table_name']}'"); @@ -388,12 +421,34 @@ class AlterQuery { if (stripos($create_query, $tokenized_query['column_name']) === false) { return 'SELECT 1=1'; } - if (preg_match("/\\s*({$tokenized_query['column_name']}\\s*.*?)\\s*(DEFAULT\\s*.*|)[,)]/im", $create_query, $match)) { - $col_def = trim($match[1]); - $old_default = trim($match[2]); - $create_query = preg_replace("/($col_def)\\s*$old_default/im", "\\1 $def_value", $create_query); + if (preg_match("/\\s*({$tokenized_query['column_name']})\\s*(.*)?(DEFAULT\\s*.*)[,)]/im", $create_query, $match)) { + $col_name = trim($match[1]); + $col_def = trim($match[2]); + $col_def_esc = str_replace(array('(', ')'), array('\(', '\)'), $col_def); + $checked_col_def = $this->convert_field_types($col_name, $col_def); + $old_default = trim($match[3]); + $pattern = "/$col_name\\s*$col_def_esc\\s*$old_default/im"; + if (is_null($def_value)) { + $replacement = $col_name . ' ' . $checked_col_def; + } else { + $replacement = $col_name . ' ' . $checked_col_def . ' ' . $def_value; + } + $create_query = preg_replace($pattern, $replacement, $create_query); $create_query = str_ireplace($tokenized_query['table_name'], $temp_table, $create_query); - } else { + } elseif (preg_match("/\\s*({$tokenized_query['column_name']})\\s*(.*)?[,)]/im", $create_query, $match)) { + $col_name = trim($match[1]); + $col_def = trim($match[2]); + $col_def_esc = str_replace(array('(', ')'), array('\(', '\)'), $col_def); + $checked_col_def = $this->convert_field_types($col_name, $col_def); + $pattern = "/$col_name\\s*$col_def_esc/im"; + if (is_null($def_value)) { + $replacement = $col_name . ' ' . $checked_col_def; + } else { + $replacement = $col_name . ' ' . $checked_col_def . ' ' . $def_value; + } + $create_query = preg_replace($pattern, $replacement, $create_query); + $create_query = str_ireplace($tokenized_query['table_name'], $temp_table, $create_query); + } else { return 'SELECT 1=1'; } $query[] = $create_query; @@ -412,28 +467,10 @@ class AlterQuery { * @return string */ private function convert_field_types($col_name, $col_def){ - $array_types = array( - 'bit' => 'INTEGER', 'bool' => 'INTEGER', - 'boolean' => 'INTEGER', 'tinyint' => 'INTEGER', - 'smallint' => 'INTEGER', 'mediumint' => 'INTEGER', - 'bigint' => 'INTEGER', 'integer' => 'INTEGER', - 'int' => 'INTEGER', 'float' => 'REAL', - 'double' => 'REAL', 'decimal' => 'REAL', - 'dec' => 'REAL', 'numeric' => 'REAL', - 'fixed' => 'REAL', 'datetime' => 'TEXT', - 'date' => 'TEXT', 'timestamp' => 'TEXT', - 'time' => 'TEXT', 'year' => 'TEXT', - 'varchar' => 'TEXT', 'char' => 'TEXT', - 'varbinary' => 'BLOB', 'binary' => 'BLOB', - 'tinyblob' => 'BLOB', 'mediumblob' => 'BLOB', - 'longblob' => 'BLOB', 'blob' => 'BLOB', - 'tinytext' => 'TEXT', 'mediumtext' => 'TEXT', - 'longtext' => 'TEXT', 'text' => 'TEXT' - ); $array_curtime = array('current_timestamp', 'current_time', 'current_date'); $array_reptime = array("'0000-00-00 00:00:00'", "'0000-00-00 00:00:00'", "'0000-00-00'"); $def_string = str_replace('`', '', $col_def); - foreach ($array_types as $o=>$r){ + foreach ($this->array_types as $o=>$r){ $pattern = "/\\b$o\\s*(\([^\)]*\)*)?\\s*/ims"; if (preg_match($pattern, $def_string)) { $def_string = preg_replace($pattern, "$r ", $def_string); @@ -451,5 +488,24 @@ class AlterQuery { } return $def_string; } + + private $array_types = array( + 'bit' => 'INTEGER', 'bool' => 'INTEGER', + 'boolean' => 'INTEGER', 'tinyint' => 'INTEGER', + 'smallint' => 'INTEGER', 'mediumint' => 'INTEGER', + 'bigint' => 'INTEGER', 'integer' => 'INTEGER', + 'int' => 'INTEGER', 'float' => 'REAL', + 'double' => 'REAL', 'decimal' => 'REAL', + 'dec' => 'REAL', 'numeric' => 'REAL', + 'fixed' => 'REAL', 'datetime' => 'TEXT', + 'date' => 'TEXT', 'timestamp' => 'TEXT', + 'time' => 'TEXT', 'year' => 'TEXT', + 'varchar' => 'TEXT', 'char' => 'TEXT', + 'varbinary' => 'BLOB', 'binary' => 'BLOB', + 'tinyblob' => 'BLOB', 'mediumblob' => 'BLOB', + 'longblob' => 'BLOB', 'blob' => 'BLOB', + 'tinytext' => 'TEXT', 'mediumtext' => 'TEXT', + 'longtext' => 'TEXT', 'text' => 'TEXT' + ); } ?> \ No newline at end of file diff --git a/readme-ja.txt b/readme-ja.txt index 51bc8ba..ba2bdf4 100644 --- a/readme-ja.txt +++ b/readme-ja.txt @@ -7,7 +7,7 @@ Author: Kojima Toshiyasu Author URI: http://dogwood.skr.jp/ Requires at least: 3.3 Tested up to: 3.6 -Stable tag: 1.3 +Stable tag: 1.4 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -30,6 +30,12 @@ WordPressはMySQLと話していると思っていて、背後で何が起こっ SQLite Integrationは[PDO for WordPress](http://wordpress.org/extend/plugins/pdo-for-wordpress)プラグインの後継です。後者は残念なことに、もうメンテナンスされていないようです。SQLite IntegrationはPDO for WordPressの基本的なアイディアと構造を借りて、より多くの機能とユーティリティを追加しました。 += 重要なお知らせ = + +このプラグインを使ってWordPress 3.5.x をインストールし、3.6にアップグレードした場合、データベースが意図したとおりに動作していないかもしれません。これに該当する場合は、プラグインを最新版にアップグレードして、管理画面のメンテナンスページに移動し、修復が必要かどうかをチェックしてください。必要なら、そのページで提供しているユーティリティを使って修復をすることができます。 + +WordPress 3.6 をインストールした場合や、3.5.x を使っている場合は、これに該当しませんので、修復は必要ありません。 + = Features = SQLite Integrationは普通の「プラグイン」ではありません。WordPressをインストールするときに使います。そのため、少し準備が必要です。インストールのセクションを参照してください。[SQLite Integration Page](http://dogwood.skr.jp/wordpress/sqlite-integration/)をご覧になると、もっと詳しい説明を読むことができます。 @@ -167,9 +173,10 @@ SQLite Integrationのアップグレードに失敗するようなら、FTPを == Changelog == -= 1.3.1 () = += 1.4 (2013-09-12) = +* アップグレードしたWordPressで期待通り動作しないのを修正するために、データベース管理ユーティリティを追加しました。 * SHOW INDEXクエリにWHERE句がある場合の処理を変更しました。 -* ALTER TABLE ALTER COLUMNクエリのバグを修正しました。 +* ALTER TABLEクエリのバグを修正しました。 = 1.3 (2013-09-04) = * データベースファイルのスナップショットをzipアーカイブとしてバックアップするユーティリティを追加しました。 diff --git a/readme.txt b/readme.txt index da1bb2b..3ec24c9 100644 --- a/readme.txt +++ b/readme.txt @@ -7,7 +7,7 @@ Author: Kojima Toshiyasu Author URI: http://dogwood.skr.jp/ Requires at least: 3.3 Tested up to: 3.6 -Stable tag: 1.3 +Stable tag: 1.4 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -30,6 +30,12 @@ WordPress thinks she talks with MySQL and doesn't know what has happened in the SQLite Integration is a successor to [PDO for WordPress](http://wordpress.org/extend/plugins/pdo-for-wordpress) plugin, which unfortunately enough, doesn't seem to be maintained any more. SQLite Integration uses the basic idea and structures of that plugin and adds some more features or some utilities. += Important Notice = + +When your installed WordPress 3.5.x with this plugin and upgraded to 3.6, your database might not work as expected. If this is your case, please upgrade this plugin to the newest version (1.4) and visit the maintenance page in the admin dashboard, where you can check if you need to fix your database, and you can do fixing job with the utility. + +When you installed WordPress 3.6 with this plugin or your WordPress is 3.5.x, you don't have to fix your database. + = Features = SQLite Integration is not an ordinary 'plugin'. It is used to install WordPress itself. You need to do some preparations. Please read the install section. And see more detailed instruction in the [SQLite Integration Page](http://dogwood.skr.jp/wordpress/sqlite-integration). @@ -158,9 +164,10 @@ When auto upgrading of SQLite Integration fails, please try manual upgrade via F == Changelog == -= 1.3.1 () = += 1.4 (2013-09-12) = +* Added the database maintenance utility for fixing the database mulfunction of the upgraded WordPress installation. * Changed the manipulation of SHOW INDEX query with WHERE clause. -* Fixed the bug of the manipulation of ALTER TABLE ALTER COLUMN query. +* Fixed the bug of the manipulation of ALTER TABLE query. = 1.3 (2013-09-04) = * Added the backup utility that creates the zipped archive of the current snapshot of the database file. diff --git a/sqlite-integration.php b/sqlite-integration.php index 80d0914..050f881 100644 --- a/sqlite-integration.php +++ b/sqlite-integration.php @@ -4,7 +4,7 @@ Plugin Name: SQLite Integration Plugin URI: http://dogwood.skr.jp/wordpress/sqlite-integration/ Description: SQLite Integration is the plugin that enables WordPress to use SQLite. If you don't have MySQL and want to build a WordPress website, it's for you. Author: Kojima Toshiyasu -Version: 1.3 +Version: 1.4 Author URI: http://dogwood.skr.jp Text Domain: sqlite-integration Domain Path: /languages @@ -59,6 +59,10 @@ if (!class_exists('PatchUtils')) { require_once SQLiteFilePath . '/utilities/patch.php'; $patch_utils = new PatchUtils(); } +if (!class_exists('DatabaseMaintenance')) { + require_once SQLiteFilePath . '/utilities/database_maintenance.php'; + $maintenance = new DatabaseMaintenance(); +} /** * This class is for WordPress Administration Panel @@ -153,13 +157,14 @@ class SQLiteIntegration { * users. */ function add_pages() { - global $utils, $doc, $patch_utils; + global $utils, $doc, $patch_utils, $maintenance; if (function_exists('add_options_page')) { $welcome_page = add_options_page(__('SQLite Integration'), __('SQLite Integration'), 'manage_options', 'sqlite-integration', array($utils, 'welcome')); $util_page = add_submenu_page(null, 'System Info', 'System Info', 'manage_options', 'sys-info', array($utils, 'show_utils')); $edit_db = add_submenu_page(null, 'Setting File', 'Setting File', 'manage_options', 'setting-file', array($utils, 'edit_db_file')); $doc_page = add_submenu_page(null, 'Documentation', 'Documentation', 'manage_options', 'doc', array($doc, 'show_doc')); $patch_page = add_submenu_page(null, 'Patch Utility', 'Patch Utility', 'manage_options', 'patch', array($patch_utils, 'show_patch_page')); + $maintenance_page = add_submenu_page(null, 'DB Maintenance', 'DB Maintenance', 'manage_options', 'maintenance', array($maintenance, 'show_maintenance_page')); add_action('admin_print_styles-'.$welcome_page, array($this, 'add_style_sheet')); add_action('admin_print_styles-'.$util_page, array($this, 'add_style_sheet')); add_action('admin_print_styles-'.$edit_db, array($this, 'add_style_sheet')); @@ -169,6 +174,7 @@ class SQLiteIntegration { add_action('admin_print_scripts-'.$doc_page, array($this, 'add_sqlite_script')); add_action('admin_print_scripts-'.$patch_page, array($this, 'add_sqlite_script')); add_action('admin_print_scripts-'.$edit_db, array($this, 'add_sqlite_script')); + add_action('admin_print_styles-'.$maintenance_page, array($this, 'add_style_sheet')); } } @@ -177,13 +183,14 @@ class SQLiteIntegration { * So, capability is set to manage_network_options. */ function add_network_pages() { - global $utils, $doc, $patch_utils; + global $utils, $doc, $patch_utils, $maintenance; if (function_exists('add_options_page')) { $welcome_page = add_submenu_page('settings.php', __('SQLite Integration'), __('SQLite Integration'), 'manage_network_options', 'sqlite-integration', array($utils, 'welcome')); $util_page = add_submenu_page(null, 'System Info', 'System Info', 'manage_network_options', 'sys-info', array($utils, 'show_utils')); $edit_db = add_submenu_page(null, 'Setting File', 'Setting File', 'manage_network_options', 'setting-file', array($utils, 'edit_db_file')); $doc_page = add_submenu_page(null, 'Documentation', 'Documentation', 'manage_network_options', 'doc', array($doc, 'show_doc')); $patch_page = add_submenu_page(null, 'Patch Utility', 'Patch Utility', 'manage_network_options', 'patch', array($patch_utils, 'show_patch_page')); + $maintenance_page = add_submenu_page(null, 'DB Maintenance', 'DB Maintenance', 'manage_network_options', 'maintenance', array($maintenance, 'show_maintenance_page')); add_action('admin_print_styles-'.$welcome_page, array($this, 'add_style_sheet')); add_action('admin_print_styles-'.$util_page, array($this, 'add_style_sheet')); add_action('admin_print_styles-'.$edit_db, array($this, 'add_style_sheet')); @@ -193,6 +200,7 @@ class SQLiteIntegration { add_action('admin_print_scripts-'.$doc_page, array($this, 'add_sqlite_script')); add_action('admin_print_scripts-'.$patch_page, array($this, 'add_sqlite_script')); add_action('admin_print_scripts-'.$edit_db, array($this, 'add_sqlite_script')); + add_action('admin_print_styles-'.$maintenance_page, array($this, 'add_style_sheet')); } } diff --git a/utilities/database_maintenance.php b/utilities/database_maintenance.php new file mode 100644 index 0000000..e86c34c --- /dev/null +++ b/utilities/database_maintenance.php @@ -0,0 +1,484 @@ +prefix.'commentmeta' => array( + 'comment_id' => '\'0\'', + 'meta_key' => 'NULL' + ), + $wpdb->prefix.'comments' => array( + 'comment_post_ID' => '\'0\'', + 'comment_author_email' => '\'\'', + 'comment_author_url' => '\'\'', + 'comment_author_IP' => '\'\'', + 'comment_date' => '\'0000-00-00 00:00:00\'', + 'comment_date_gmt' => '\'0000-00-00 00:00:00\'', + 'comment_karma' => '\'0\'', + 'comment_approved' => '\'1\'', + 'comment_agent' => '\'\'', + 'comment_type' => '\'\'', + 'comment_type' => '\'\'', + 'comment_parent' => '\'0\'', + 'user_id' => '\'0\'' + ), + $wpdb->prefix.'links' => array( + 'link_url' => '\'\'', + 'link_name' => '\'\'', + 'link_image' => '\'\'', + 'link_target' => '\'\'', + 'link_description' => '\'\'', + 'link_visible' => '\'Y\'', + 'link_owner' => '\'1\'', + 'link_rating' => '\'0\'', + 'link_updated' => '\'0000-00-00 00:00:00\'', + 'link_rel' => '\'\'', + 'link_rss' => '\'\'' + ), + $wpdb->prefix.'options' => array( + 'option_name' => '\'\'', + 'autoload' => '\'yes\'' + ), + $wpdb->prefix.'postmeta' => array( + 'post_id' => '\'0\'', + 'meta_key' => 'NULL' + ), + $wpdb->prefix.'posts' => array( + 'post_author' => '\'0\'', + 'post_date' => '\'0000-00-00 00:00:00\'', + 'post_date_gmt' => '\'0000-00-00 00:00:00\'', + 'post_status' => '\'publish\'', + 'comment_status' => '\'open\'', + 'ping_status' => '\'open\'', + 'post_password' => '\'\'', + 'post_name' => '\'\'', + 'post_modified' => '\'0000-00-00 00:00:00\'', + 'post_modified_gmt' => '\'0000-00-00 00:00:00\'', + 'post_parent' => '\'0\'', + 'guid' => '\'\'', + 'menu_order' => '\'0\'', + 'post_type' => '\'post\'', + 'post_mime_type' => '\'\'', + 'comment_count' => '\'0\'' + ), + $wpdb->prefix.'term_relationships' => array( + 'term_order' => '0' + ), + $wpdb->prefix.'term_taxonomy' => array( + 'taxonomy' => '\'\'', + 'parent' => '0', + 'count' => '0' + ), + $wpdb->prefix.'terms' => array( + 'name' => '\'\'', + 'slug' => '\'\'', + 'term_group' => '0' + ), + $wpdb->prefix.'users' => array( + 'user_login' => '\'\'', + 'user_pass' => '\'\'', + 'user_nicename' => '\'\'', + 'user_email' => '\'\'', + 'user_url' => '\'\'', + 'user_registered' => '\'0000-00-00 00:00:00\'', + 'user_activation_key' => '\'\'', + 'user_status' => '\'0\'', + 'display_name' => '\'\'', + // for network install + 'user_login' => '\'\'', + 'spam' => '\'0\'', + 'deleted' => '\'0\'' + ), + $wpdb->prefix.'usermeta' => array( + 'user_id' => '\'0\'', + 'meta_key' => 'NULL', + ), + // for network install + $wpdb->prefix.'blog_versions' => array( + 'blog_id' => '\'0\'', + 'db_version' => '\'\'', + 'last_updated' => '\'0000-00-00 00:00:00\'' + ), + $wpdb->prefix.'blogs' => array( + 'site_id' => '\'0\'', + 'domain' => '\'\'', + 'path' => '\'\'', + 'registered' => '\'0000-00-00 00:00:00\'', + 'last_updated' => '\'0000-00-00 00:00:00\'', + 'public' => '\'1\'', + 'mature' => '\'0\'', + 'spam' => '\'0\'', + 'deleted' => '\'0\'', + 'lang_id' => '\'0\'' + ), + $wpdb->prefix.'registration_log' => array( + 'email' => '\'\'', + 'IP' => '\'\'', + 'blog_id' => '\'0\'', + 'date_registered' => '\'0000-00-00 00:00:00\'' + ), + $wpdb->prefix.'signups' => array( + 'domain' => '\'\'', + 'path' => '\'\'', + 'user_login' => '\'\'', + 'user_email' => '\'\'', + 'registered' => '\'0000-00-00 00:00:00\'', + 'activated' => '\'0000-00-00 00:00:00\'', + 'active' => '\'0\'', + 'activation_key' => '\'\'', + ), + $wpdb->prefix.'site' => array( + 'domain' => '\'\'', + 'path' => '\'\'' + ), + $wpdb->prefix.'sitemeta' => array( + 'site_id' => '\'0\'', + 'meta_key' => 'NULL', + ) + ); + $tables = $wpdb->tables('all'); + foreach ($tables as $table) { + $col_infos = $wpdb->get_results("SHOW COLUMNS FROM $table"); + foreach ($col_infos as $col) { + if (array_key_exists($col->Field, $columns_to_check[$table]) && $col->Default != $columns_to_check[$table][$col->Field]) { + $results_table[$table] = 'damaged'; + break; + } + } + } + if (empty($results_table)) { + return true; + } else { + return $results_table; + } + } + private function do_fix_database() { + global $wpdb, $wp_version, $utils; + $global_schema_to_change = array( + $wpdb->prefix.'commentmeta' => array( + "comment_id bigint(20) unsigned NOT NULL default '0'", + "meta_key varchar(255) default NULL", + "meta_value longtext" + ), + $wpdb->prefix.'comments' => array( + "comment_post_ID bigint(20) unsigned NOT NULL default '0'", + "comment_author_email varchar(100) NOT NULL default ''", + "comment_author_url varchar(200) NOT NULL default ''", + "comment_author_IP varchar(100) NOT NULL default ''", + "comment_date datetime NOT NULL default '0000-00-00 00:00:00'", + "comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00'", + "comment_karma int(11) NOT NULL default '0'", + "comment_approved varchar(20) NOT NULL default '1'", + "comment_agent varchar(255) NOT NULL default ''", + "comment_type varchar(20) NOT NULL default ''", + "comment_parent bigint(20) unsigned NOT NULL default '0'", + "user_id bigint(20) unsigned NOT NULL default '0'" + ), + $wpdb->prefix.'links' => array( + "link_url varchar(255) NOT NULL default ''", + "link_name varchar(255) NOT NULL default ''", + "link_image varchar(255) NOT NULL default ''", + "link_target varchar(25) NOT NULL default ''", + "link_description varchar(255) NOT NULL default ''", + "link_visible varchar(20) NOT NULL default 'Y'", + "link_owner bigint(20) unsigned NOT NULL default '1'", + "link_rating int(11) NOT NULL default '0'", + "link_updated datetime NOT NULL default '0000-00-00 00:00:00'", + "link_rel varchar(255) NOT NULL default ''", + "link_notes mediumtext NOT NULL", + "link_rss varchar(255) NOT NULL default ''" + ), + $wpdb->prefix.'options' => array( + "option_name varchar(64) NOT NULL default ''", + "option_value longtext NOT NULL", + "autoload varchar(20) NOT NULL default 'yes'" + ), + $wpdb->prefix.'postmeta' => array( + "post_id bigint(20) unsigned NOT NULL default '0'", + "meta_key varchar(255) default NULL", + "meta_value longtext" + ), + $wpdb->prefix.'posts' => array( + "post_author bigint(20) unsigned NOT NULL default '0'", + "post_date datetime NOT NULL default '0000-00-00 00:00:00'", + "post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00'", + "post_status varchar(20) NOT NULL default 'publish'", + "comment_status varchar(20) NOT NULL default 'open'", + "ping_status varchar(20) NOT NULL default 'open'", + "post_password varchar(20) NOT NULL default ''", + "post_name varchar(200) NOT NULL default ''", + "post_modified datetime NOT NULL default '0000-00-00 00:00:00'", + "post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00'", + "post_content_filtered longtext NOT NULL", + "post_parent bigint(20) unsigned NOT NULL default '0'", + "guid varchar(255) NOT NULL default ''", + "menu_order int(11) NOT NULL default '0'", + "post_type varchar(20) NOT NULL default 'post'", + "post_mime_type varchar(100) NOT NULL default ''", + "comment_count bigint(20) NOT NULL default '0'" + ), + $wpdb->prefix.'term_relationships' => array( + "term_order int(11) NOT NULL default 0" + ), + $wpdb->prefix.'term_taxonomy' => array( + "taxonomy varchar(32) NOT NULL default ''", + "description longtext NOT NULL", + "parent bigint(20) unsigned NOT NULL default 0", + "count bigint(20) NOT NULL default 0" + ), + $wpdb->prefix.'terms' => array( + "name varchar(200) NOT NULL default ''", + "slug varchar(200) NOT NULL default ''", + "term_group bigint(10) NOT NULL default 0" + ), + $wpdb->prefix.'users' => array( + "user_login varchar(60) NOT NULL default ''", + "user_pass varchar(64) NOT NULL default ''", + "user_nicename varchar(50) NOT NULL default ''", + "user_email varchar(100) NOT NULL default ''", + "user_url varchar(100) NOT NULL default ''", + "user_registered datetime NOT NULL default '0000-00-00 00:00:00'", + "user_activation_key varchar(60) NOT NULL default ''", + "user_status int(11) NOT NULL default '0'", + "display_name varchar(250) NOT NULL default ''" + ), + $wpdb->prefix.'usermeta' => array( + "user_id bigint(20) unsigned NOT NULL default '0'", + "meta_key varchar(255) default NULL", + "meta_value longtext" + ) + ); + + $network_schema_to_change = array( + $wpdb->prefix.'blog_versions' => array( + "blog_id bigint(20) NOT NULL default '0'", + "db_version varchar(20) NOT NULL default ''", + "last_updated datetime NOT NULL default '0000-00-00 00:00:00'" + ), + $wpdb->prefix.'blogs' => array( + "site_id bigint(20) NOT NULL default '0'", + "domain varchar(200) NOT NULL default ''", + "path varchar(100) NOT NULL default ''", + "registered datetime NOT NULL default '0000-00-00 00:00:00'", + "last_updated datetime NOT NULL default '0000-00-00 00:00:00'", + "public tinyint(2) NOT NULL default '1'", + "mature tinyint(2) NOT NULL default '0'", + "spam tinyint(2) NOT NULL default '0'", + "deleted tinyint(2) NOT NULL default '0'", + "lang_id int(11) NOT NULL default '0'" + ), + $wpdb->prefix.'registration_log' => array( + "email varchar(255) NOT NULL default ''", + "IP varchar(30) NOT NULL default ''", + "blog_id bigint(20) NOT NULL default '0'", + "date_registered datetime NOT NULL default '0000-00-00 00:00:00'" + ), + $wpdb->prefix.'signups' => array( + "domain varchar(200) NOT NULL default ''", + "path varchar(100) NOT NULL default ''", + "title longtext NOT NULL", + "user_login varchar(60) NOT NULL default ''", + "user_email varchar(100) NOT NULL default ''", + "registered datetime NOT NULL default '0000-00-00 00:00:00'", + "activated datetime NOT NULL default '0000-00-00 00:00:00'", + "active tinyint(1) NOT NULL default '0'", + "activation_key varchar(50) NOT NULL default ''", + "meta longtext" + ), + $wpdb->prefix.'site' => array( + "domain varchar(200) NOT NULL default ''", + "path varchar(100) NOT NULL default ''" + ), + $wpdb->prefix.'sitemeta' => array( + "site_id bigint(20) NOT NULL default '0'", + "meta_key varchar(255) default NULL", + "meta_value longtext" + ), + $wpdb->prefix.'users' => array( + "user_login varchar(60) NOT NULL default ''", + "spam tinyint(2) NOT NULL default '0'", + "deleted tinyint(2) NOT NULL default '0'" + ) + ); + if (version_compare($wp_version, '3.6', '<')) return false; + $results = $this->sanity_check(); + $return_val = array(); + $queries = array(); + if ($results !== true) { + if (!$this->maintenance_backup()) { + $message = __('Can\'t create backup file.', $domain); + echo $message; + return false; + } + $tables = array_keys($results); + foreach ($tables as $table) { + if (key_exists($table, $global_schema_to_change)) { + $queries = $global_schema_to_change[$table]; + } + if (key_exists($table, $network_schema_to_change)) { + if (!empty($queries)) { + $queries = array_merge($queries, $network_schema_to_change[$table]); + } else { + $queries = $network_schema_to_change[$table]; + } + } + foreach ($queries as $query) { + $sql = 'ALTER TABLE' . ' ' . $table . ' ' . 'CHANGE COLUMN' . ' ' . $query; + $res = $wpdb->query($sql); + if ($res === false) { + $return_val[] = __('Failed: ', $domain) . $query; + } + } + } + } else { + return true; + } + if (empty($return_val)) { + return true; + } else { + return $return_val; + } + } + + private function maintenance_backup() { + $result = array(); + $database_file = FQDB; + $db_name = basename(FQDB); + if (!file_exists($database_file)) { + return false; + } + $today = date("Ymd-His"); + if (!extension_loaded('zip')) { + $backup_file = $database_file . '.' . $today . '.maintenance-backup'; + if (copy($database_file, $backup_file)) { + $result = true; + } else { + $result = false; + } + } else { + $backup_file = $database_file . '.' . $today . '.maintenance-backup.zip'; + $zip = new ZipArchive(); + $res = $zip->open($backup_file, ZipArchive::CREATE | ZipArchive::OVERWRITE); + if ($res === true) { + $zip->addFile($database_file, $db_name); + $result = true; + } else { + $result = false; + } + $zip->close(); + } + return $result; + } + + function show_maintenance_page() { + global $utils; + $domain = $utils->text_domain; + if (is_multisite() && !current_user_can('manage_network_options')) { + die(__('You are not allowed to access this page!', $domain)); + } elseif (!current_user_can('manage_options')) { + die(__('You are not allowed to access this page!', $domain)); + } + + + if (isset($_GET['page']) && $_GET['page'] == 'maintenance') : ?> + +
+

+

+

+ + +

+

+ +

+

+ +

+

+ +

+ +
+ + + +
+
+ do_fix_database(); + if ($fix_results !== true) { + $title = '

'. __('Results', $domain) . '

'; + echo '
'; + echo $title; + echo ''; + echo '
'; + } else { + $title = '

'. __('Results', $domain) . '

'; + $message = __('Your database restoration is successfully finished!', $domain); + echo '
'; + echo $title; + echo '

'.$message.'

'; + echo '
'; + } + } + if (isset($_POST['sanity-check'])) { + check_admin_referer('sqliteintegration-database-manip-stats'); + if (is_multisite() && !current_user_can('manage_network_options')) { + die(__('You are not allowed to do this operation!', $domain)); + } elseif (!current_user_can('manage_options')) { + die(__('You are not allowed to do this operation!', $domain)); + } + $check_results = $this->sanity_check(); + if ($check_results !== true) { + $title = '

'. __('Checked Results', $domain) . '

'; + echo '
'; + echo $title; + echo ''; + echo '
'; + } else { + $title = '

'. __('Checked Results', $domain) . '

'; + $message = __('Your database is OK. You don\'t have to restore it.', $domain); + echo '
'; + echo $title; + echo '

'.$message.'

'; + echo '
'; + } + } + } +} +?> \ No newline at end of file diff --git a/utilities/documentation.php b/utilities/documentation.php index 04188f4..44895be 100644 --- a/utilities/documentation.php +++ b/utilities/documentation.php @@ -24,6 +24,7 @@ class SQLiteIntegrationDocument { +
diff --git a/utilities/patch.php b/utilities/patch.php index ed1a7f2..4b8e2f7 100644 --- a/utilities/patch.php +++ b/utilities/patch.php @@ -222,6 +222,7 @@ class PatchUtils { +
diff --git a/utilities/utility.php b/utilities/utility.php index acd0deb..f2b8295 100644 --- a/utilities/utility.php +++ b/utilities/utility.php @@ -439,6 +439,10 @@ class SQLiteIntegrationUtils { + + + +
@@ -463,6 +467,7 @@ class SQLiteIntegrationUtils { +
@@ -717,6 +722,7 @@ class SQLiteIntegrationUtils { +