tagging version 1.4.2

git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/tags/1.4.2@799985 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
kjmtsh 2013-11-06 19:25:11 +00:00
parent e17d3a382a
commit a377521ad3
24 changed files with 2195 additions and 975 deletions

9
db.php
View File

@ -5,12 +5,11 @@
* wordpress/wp-content/db.php
*
* @package SQLite Integration
* @version 1.1
* @author Kojima Toshiyasu, Justin Adie
*
*/
function pdo_log_erro($message, $data = null) {
function pdo_log_error($message, $data = null) {
if (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin') !== false) {
$admin_dir = '';
@ -38,15 +37,15 @@ HTML
}
if (version_compare( PHP_VERSION, '5.2.4', '<')) {
pdo_log_erro(__('PHP version on this server is too old.'), sprinf(__("Your server is running PHP version %d but this version of WordPress requires at least 5.2.4"), phpversion()));
pdo_log_error('PHP version on this server is too old.', sprinf("Your server is running PHP version %d but this version of WordPress requires at least 5.2.4", phpversion()));
}
if (!extension_loaded('pdo')) {
pdo_log_erro(__('PHP PDO Extension is not loaded.'), __('Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress.'));
pdo_log_error('PHP PDO Extension is not loaded.', 'Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress.');
}
if (!extension_loaded('pdo_sqlite')) {
pdo_log_erro(__('PDO Driver for SQLite is missing.'), __('Your PHP installtion appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.'));
pdo_log_error('PDO Driver for SQLite is missing.', 'Your PHP installtion appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.');
}
/**

View File

@ -1,7 +1,6 @@
<?php
/**
* @package SQLite Integration
* @version 1.1
* @author Kojima Toshiyasu, Justin Adie
*
*/
@ -57,7 +56,8 @@ class PDOSQLiteUDFS {
'inet_ntoa' => 'inet_ntoa',
'inet_aton' => 'inet_aton',
'datediff' => 'datediff',
'locate' => 'locate'
'locate' => 'locate',
'version' => 'version'
);
public function month($field){
@ -385,5 +385,12 @@ class PDOSQLiteUDFS {
}
}
}
/**
*
*/
public function version() {
global $required_mysql_version;
return $required_mysql_version;
}
}
?>

View File

@ -1,7 +1,6 @@
<?php
/**
* @package SQLite Integration
* @version 1.1
* @author Kojima Toshiyasu, Justin Adie
*
*/
@ -58,7 +57,8 @@ class PDOSQLiteUDFS {
'inet_ntoa' => 'inet_ntoa',
'inet_aton' => 'inet_aton',
'datediff' => 'datediff',
'locate' => 'locate'
'locate' => 'locate',
'version' => 'version'
);
public function month($field){
@ -359,5 +359,12 @@ class PDOSQLiteUDFS {
}
}
}
/**
*
*/
public function version() {
global $required_mysql_version;
return $required_mysql_version;
}
}
?>

View File

@ -1,13 +1,12 @@
<?php
/**
* @package SQLite Integration
* @version 1.1
* @author Kojima Toshiyasu, Justin Adie
*
*/
/**
* This function overrides wp_install() in wp-admin/upgrade.php
* This function overrides wp_install() in wp-admin/includes/upgrade.php
*/
function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') {
if (!empty($deprecated))
@ -57,7 +56,16 @@ function wp_install($blog_title, $user_name, $user_email, $public, $deprecated =
wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.')));
wp_cache_flush();
if (isset($_SERVER['SERVER_SOFTWARE']) && stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false || isset($_SERVER['SERVER_SIGNATURE']) && stripos($_SERVER['SERVER_SIGNATURE'], 'apache') !== false) {
;// Your server is Apache. Nothing to do more.
} else {
$server_message = sprintf('Your webserver doesn\'t seem to be Apache. So the database directory access restriction by the .htaccess file may not function. We strongly recommend that you should restrict the access to the directory %s in some other way.', FQDBDIR);
echo '<div style="position: absolute; margin-top: 250px; width: 700px; border: .5px dashed rgb(0, 0, 0);"><p style="margin: 10px;">';
echo $server_message;
echo '</p></div>';
}
return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
}
?>

View File

@ -14,6 +14,9 @@ jQuery(document).ready(function($) {
} else if (document.getElementById("patch-files") != null) {
$table = $('#patch-files');
$headers = $table.find('thead th').slice(1);
} else if (document.getElementById("backup-files") != null) {
$table = $('#backup-files');
$headers = $table.find('thead th').slice(1);
}
$headers
.wrapInner('<a href="#"></a>')

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
<?php
/**
* @package SQLite Integration
* @version 1.1
* @author Kojima Toshiyasu, Justin Adie
*
*/
@ -46,6 +45,16 @@ class PDODB extends wpdb {
return true;
}
/**
* dummy out the MySQL function
* @see wpdb::set_charset()
*/
function set_charset($dbh, $charset = null, $collate = null) {
if ( ! isset( $charset ) )
$charset = $this->charset;
if ( ! isset( $collate ) )
$collate = $this->collate;
}
/**
* dummy out the MySQL function
* @see wpdb::select()
@ -62,10 +71,7 @@ class PDODB extends wpdb {
* @see wpdb::_real_escape()
*/
function _real_escape($string) {
if ($this->dbh && $this->real_escape)
return $this->dbh->quote($string);
else
return addslashes($string);
return addslashes($string);
}
/**
@ -77,7 +83,7 @@ class PDODB extends wpdb {
if (!$str) {
$err = $this->dbh->get_error_message() ? $this->dbh->get_error_message() : '';
$str = $err[2];
if (!empty($err)) $str = $err[2]; else $str = '';
}
$EZSQL_ERROR[] = array('query' => $this->last_query, 'error_str' => $str);

View File

@ -1,7 +1,6 @@
<?php
/**
* @package SQLite Integration
* @version 1.1
* @author Kojima Toshiyasu, Justin Adie
*
*/
@ -35,7 +34,7 @@ class PDOEngine extends PDO {
/**
* Constructor
* @param array $DatabaseParams
* @param
*/
function __construct() {
$this->init();
@ -80,8 +79,8 @@ class PDOEngine extends PDO {
if ($status == 5 || $status == 6) {
$locked = true;
} else {
$message = __("Database connection error!<br />", 'sqlite-integration');
$message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err->getMessage());
$message = 'Database connection error!<br />';
$message .= sprintf("Error message is: %s", $err->getMessage());
$this->set_error(__LINE__, __FUNCTION__, $message);
return false;
}
@ -96,8 +95,8 @@ class PDOEngine extends PDO {
try {
$this->pdo = new PDO($dsn, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch (PDOException $err) {
$message = __("Database connection error!<br />", 'sqlite-integration');
$message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err->getMessage());
$message = 'Database initialization error!<br />';
$message .= sprintf("Error message is: %s", $err->getMessage());
$this->set_error(__LINE__, __FUNCTION__, $message);
return false;
}
@ -113,16 +112,16 @@ class PDOEngine extends PDO {
global $wpdb;
$u = umask(0000);
if (!is_dir(FQDBDIR)) {
if (!@mkdir(FQDBDIR, 0777, true)) {
if (!@mkdir(FQDBDIR, 0707, true)) {
umask($u);
$message = __('Unable to create the required directory! Please check your server settings.', 'sqlite-integration');
$message = 'Unable to create the required directory! Please check your server settings.';
echo $message;
return false;
}
}
if (!is_writable(FQDBDIR)) {
umask($u);
$message = __('Unable to create a file in the directory! Please check your server settings.', 'sqlite-integration');
$message = 'Unable to create a file in the directory! Please check your server settings.';
echo $message;
return false;
}
@ -130,11 +129,11 @@ class PDOEngine extends PDO {
$fh = fopen(FQDBDIR . '.htaccess', "w");
if (!$fh) {
umask($u);
$message = __('Unable to create a file in the directory! Please check your server settings.', 'sqlite-integration');
$message = 'Unable to create a file in the directory! Please check your server settings.';
echo $message;
return false;
}
fwrite($fh, "DENY FROM ALL");
fwrite($fh, 'DENY FROM ALL');
fclose($fh);
}
umask($u);
@ -145,7 +144,7 @@ class PDOEngine extends PDO {
* executed once while installation process
*/
private function make_sqlite_tables() {
require_once PDODIR . "install.php";
require_once PDODIR . 'install.php';
}
public function query($query) {
@ -253,7 +252,7 @@ class PDOEngine extends PDO {
ob_start();
debug_print_backtrace();
$output .= "<pre>" . ob_get_contents() . "</pre>";
$output .= '<pre>' . ob_get_contents() . '</pre>';
ob_end_clean();
return $output;
@ -299,7 +298,7 @@ class PDOEngine extends PDO {
}
private function prepare_query(){
$this->queries[] = "Prepare:\t". $this->prepared_query;
$this->queries[] = 'Prepare: ' . $this->prepared_query;
$reason = 0;
$message = '';
$statement = null;
@ -313,7 +312,7 @@ class PDOEngine extends PDO {
} while (5 == $reason || 6 == $reason);
if ($reason > 0){
$err_message = sprintf(__("Problem preparing the PDO SQL Statement. Error was: %s", 'sqlite-integration'), $message);
$err_message = sprintf("Problem preparing the PDO SQL Statement. Error was: %s", $message);
$this->set_error(__LINE__, __FUNCTION__, $err_message);
}
return $statement;
@ -325,7 +324,7 @@ class PDOEngine extends PDO {
if (!is_object($statement))
return;
if (count($this->extracted_variables) > 0) {
$this->queries[] = "Executing: ". var_export($this->extracted_variables, true);
$this->queries[] = 'Executing: ' . var_export($this->extracted_variables, true);
do {
if ($this->query_type == 'update' || $this->query_type == 'replace') {
try {
@ -347,7 +346,7 @@ class PDOEngine extends PDO {
}
} while (5 == $reason || 6 == $reason);
} else {
$this->queries[] = "Executing: (no parameters)\t ";
$this->queries[] = 'Executing: (no parameters)';
do{
if ($this->query_type == 'update' || $this->query_type == 'replace') {
try {
@ -370,7 +369,7 @@ class PDOEngine extends PDO {
} while (5 == $reason || 6 == $reason);
}
if ($reason > 0) {
$err_message = sprintf(__("Error while executing query! Error message was: %s", 'sqlite-integration'), $message);
$err_message = sprintf("Error while executing query! Error message was: %s", $message);
$this->set_error(__LINE__, __FUNCTION__, $err_message);
return false;
} else {
@ -378,32 +377,34 @@ class PDOEngine extends PDO {
}
//generate the results that $wpdb will want to see
switch ($this->query_type) {
case "insert":
case "update":
case "replace":
case 'insert':
case 'update':
case 'replace':
$this->last_insert_id = $this->pdo->lastInsertId();
$this->affected_rows = $statement->rowCount();
$this->return_value = $this->affected_rows;
break;
case "select":
case "show":
case "showcolumns":
case "showindex":
case "describe":
case "desc":
case 'select':
case 'show':
case 'showcolumns':
case 'showindex':
case 'describe':
case 'desc':
case 'check':
case 'analyze':
// case "foundrows":
$this->num_rows = count($this->_results);
$this->return_value = $this->num_rows;
break;
case "delete":
case 'delete':
$this->affected_rows = $statement->rowCount();
$this->return_value = $this->affected_rows;
break;
case "alter":
case "drop":
case "create":
case "optimize":
case "truncate":
case 'alter':
case 'drop':
case 'create':
case 'optimize':
case 'truncate':
if ($this->is_error) {
$this->return_value = false;
} else {
@ -424,7 +425,7 @@ class PDOEngine extends PDO {
$_limit = $limit = ini_get('pcre.backtrack_limit');
do {
if ($limit > 10000000) {
$message = __("The query is too big to parse properly", 'sqlite-integration');
$message = 'The query is too big to parse properly';
$this->set_error(__LINE__, __FUNCTION__, $message);
break; //no point in continuing execution, would get into a loop
} else {
@ -436,7 +437,7 @@ class PDOEngine extends PDO {
//reset the pcre.backtrack_limist
ini_set('pcre.backtrack_limit', $_limit);
$this->queries[]= "With Placeholders: $query ";
$this->queries[]= 'With Placeholders: ' . $query;
$this->prepared_query = $query;
}
@ -469,7 +470,7 @@ class PDOEngine extends PDO {
* @return boolean|string
*/
private function determine_query_type($query) {
$result = preg_match('/^\\s*(EXPLAIN|PRAGMA|SELECT\\s*FOUND_ROWS|SELECT|INSERT|UPDATE|REPLACE|DELETE|ALTER|CREATE|DROP\\s*INDEX|DROP|SHOW\\s*\\w+\\s*\\w+\\s*|DESCRIBE|DESC|TRUNCATE|OPTIMIZE)/i', $query, $match);
$result = preg_match('/^\\s*(EXPLAIN|PRAGMA|SELECT\\s*FOUND_ROWS|SELECT|INSERT|UPDATE|REPLACE|DELETE|ALTER|CREATE|DROP\\s*INDEX|DROP|SHOW\\s*\\w+\\s*\\w+\\s*|DESCRIBE|DESC|TRUNCATE|OPTIMIZE|CHECK|ANALYZE)/i', $query, $match);
if (!$result) {
return false;
@ -505,7 +506,7 @@ class PDOEngine extends PDO {
private function execute_insert_query_new($query) {
$engine = $this->prepare_engine($this->query_type);
$this->rewritten_query = $engine->rewrite_query($query, $this->query_type);
$this->queries[] = "Rewritten: $this->rewritten_query";
$this->queries[] = 'Rewritten: ' . $this->rewritten_query;
$this->extract_variables();
$statement = $this->prepare_query();
$this->execute_query($statement);
@ -544,7 +545,7 @@ class PDOEngine extends PDO {
}
$query_string = $query_prefix . ' ' . $value . $suffix;
$this->rewritten_query = $engine->rewrite_query($query_string, $this->query_type);
$this->queries[] = "Rewritten: $this->rewritten_query";
$this->queries[] = 'Rewritten: ' . $this->rewritten_query;
$this->extracted_variables = array();
$this->extract_variables();
if ($first) {
@ -557,7 +558,7 @@ class PDOEngine extends PDO {
}
} else {
$this->rewritten_query = $engine->rewrite_query($query, $this->query_type);
$this->queries[] = "Rewritten: $this->rewritten_query";
$this->queries[] = 'Rewritten: ' . $this->rewritten_query;
$this->extract_variables();
$statement = $this->prepare_query();
$this->execute_query($statement);
@ -633,7 +634,7 @@ class PDOEngine extends PDO {
}
}
if ($reason > 0) {
$err_message = sprintf(__("Problem in creating table or index. Error was: %s", 'sqlite-integration'), $message);
$err_message = sprintf("Problem in creating table or index. Error was: %s", $message);
$this->set_error(__LINE__, __FUNCTION__, $err_message);
return false;
}
@ -649,7 +650,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)) {
@ -675,8 +681,11 @@ 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);
$err_message = sprintf("Problem in executing alter query. Error was: %s", $message);
$this->set_error(__LINE__, __FUNCTION__, $err_message);
return false;
}
@ -699,7 +708,11 @@ class PDOEngine extends PDO {
$value = str_replace("'", '', $match[1]);
$dummy_data['Variable_name'] = trim($value);
// this is set for Wordfence Security Plugin
if ($value == 'max_allowed_packet') $dummy_data['Value'] = 1047552;
if ($value == 'max_allowed_packet') {
$dummy_data['Value'] = 1047552;
} else {
$dummy_data['Value'] = '';
}
}
$_results[] = new ObjectArray($dummy_data);
$this->results = $_results;
@ -713,6 +726,8 @@ class PDOEngine extends PDO {
$this->convert_to_columns_object();
} elseif ('showindex' === $this->query_type){
$this->convert_to_index_object();
} elseif (in_array($this->query_type, array('check', 'analyze'))) {
$this->convert_result_check_or_analyze();
} else {
$this->results = $this->_results;
}
@ -774,6 +789,7 @@ class PDOEngine extends PDO {
}
/**
* rewrites the result of SHOW INDEX to the Object compatible with MySQL
* added the WHERE clause manipulation (ver 1.3.1)
*/
private function convert_to_index_object() {
$_results = array();
@ -840,10 +856,44 @@ class PDOEngine extends PDO {
$_columns['Comment'] = '';
$_results[] = new ObjectArray($_columns);
}
if (stripos($this->queries[0], 'WHERE') !== false) {
preg_match('/WHERE\\s*(.*)$/im', $this->queries[0], $match);
list($key, $value) = explode('=', $match[1]);
$key = trim($key);
$value = preg_replace("/[\';]/", '', $value);
$value = trim($value);
foreach ($_results as $result) {
if (stripos($value, $result->$key) !== false) {
unset($_results);
$_results[] = $result;
break;
}
}
}
}
$this->results = $_results;
}
private function convert_result_check_or_analyze() {
$results = array();
if ($this->query_type == 'check') {
$_columns = array(
'Table' => '',
'Op' => 'check',
'Msg_type' => 'status',
'Msg_text' => 'OK'
);
} else {
$_columns = array(
'Table' => '',
'Op' => 'analyze',
'Msg_type' => 'status',
'Msg_text' => 'Table is already up to date'
);
}
$_results[] = new ObjectArray($_columns);
$this->results = $_results;
}
/**
* function to get SQLite library version
* this is used for checking if SQLite can execute multiple rows insert

View File

@ -1,7 +1,6 @@
<?php
/**
* @package SQLite Integration
* @version 1.1
* @author Kojima Toshiyasu, Justin Adie
*/
@ -54,12 +53,15 @@ class PDOSQLiteDriver {
$this->_delete_index_hints();
$this->_rewrite_regexp();
$this->_rewrite_boolean();
$this->_fix_date_quoting();
$this->_rewrite_between();
break;
case 'insert':
$this->_strip_backticks();
$this->_execute_duplicate_key_update();
$this->_rewrite_insert_ignore();
$this->_rewrite_regexp();
$this->_fix_date_quoting();
break;
case 'update':
$this->_strip_backticks();
@ -68,6 +70,7 @@ class PDOSQLiteDriver {
$this->_rewrite_limit_usage();
$this->_rewrite_order_by_usage();
$this->_rewrite_regexp();
$this->_rewrite_between();
break;
case 'delete':
$this->_strip_backticks();
@ -85,7 +88,15 @@ class PDOSQLiteDriver {
case 'optimize':
$this->_rewrite_optimize();
break;
case 'pragma':
break;
default:
if (defined(WP_DEBUG) && WP_DEBUG) {
break;
} else {
$this->_return_true();
break;
}
}
return $this->_query;
}
@ -95,7 +106,7 @@ class PDOSQLiteDriver {
*/
private function _handle_show_query(){
$table_name = '';
$pattern = '/^\\s*SHOW\\s*TABLES\\s*(LIKE\\s*(.*))$/im';
$pattern = '/^\\s*SHOW\\s*TABLES\\s*.*?(LIKE\\s*(.*))$/im';
if (preg_match($pattern, $this->_query, $matches)) {
$table_name = str_replace(array("'", ';'), '', $matches[2]);
}
@ -285,25 +296,28 @@ class PDOSQLiteDriver {
* @return void
*/
private function _delete_index_hints(){
$pattern = '/use\s+index\s*\(.*?\)/i';
$pattern = '/\\s*(use|ignore|force)\\s+index\\s*\(.*?\)/i';
$this->_query = preg_replace($pattern, '', $this->_query);
}
/**
* Justin Adie says:
* method to fix inconsistent use of quoted, unquoted etc date values in query function
* this is ironic, given the above rewrite badlyformed dates method
* examples
* Fix the date string and quote. This is required for the calendar widget.
*
* where month(fieldname)=08 becomes month(fieldname)='8'
* where month(fieldname)='08' becomes month(fieldname)='8'
*
* I don't understand...
* I use preg_replace_callback instead of 'e' option because of security reason.
* cf. PHP manual (regular expression)
*
* @return void
*/
private function _fix_date_quoting(){
$pattern = '/(month|year|second|day|minute|hour|dayofmonth)\s*\((.*?)\)\s*=\s*["\']?(\d{1,4})[\'"]?\s*/ei';
$this->_query = preg_replace($pattern, "'\\1(\\2)=\'' . intval('\\3') . '\' ' ", $this->_query);
private function _fix_date_quoting() {
$pattern = '/(month|year|second|day|minute|hour|dayofmonth)\\s*\((.*?)\)\\s*=\\s*["\']?(\d{1,4})[\'"]?\\s*/im';
$this->_query = preg_replace_callback($pattern, array($this, '__fix_date_quoting'), $this->_query);
}
private function __fix_date_quoting($match) {
$fixed_val = "{$match[1]}({$match[2]})='" . intval($match[3]) . "' ";
return $fixed_val;
}
private function _rewrite_regexp(){
@ -341,28 +355,12 @@ class PDOSQLiteDriver {
/**
* method to execute SHOW INDEX query
* Moved the WHERE clause manipulation to pdoengin.class.php (ver 1.3.1)
*/
private function _handle_show_index() {
$_columns = array(// No, you'll get no meaningful information..
'Key_name' => 'name',
);
$pattern_0 = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?\\s*WHERE\\s*(.*)$/im';
$pattern_1 = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?/im';
if (preg_match($pattern_0, $this->_query, $match_0)) {
$table_name = str_replace("'", '', $match_0[1]);
list($key, $value) = explode('=', $match_0[2]);
$key = trim($key);
$value = preg_replace("/[\';]/", '', $value);
$value = trim($value);
if (array_key_exists($key, $_columns)) {
$key = $_columns[$key];
$where_clause = 'AND ' . $key . ' LIKE ' . "'" . $value . "%'";
} else {
$where_clause = '';
}
$this->_query = "SELECT * FROM sqlite_master WHERE tbl_name='$table_name' $where_clause";
} elseif (preg_match($pattern_1, $this->_query, $match_1)) {
$table_name = preg_replace("/[\';]/", '', $match_1[1]);
$pattern = '/^\\s*SHOW\\s*(?:INDEX|INDEXES|KEYS)\\s*FROM\\s*(\\w+)?/im';
if (preg_match($pattern, $this->_query, $match)) {
$table_name = preg_replace("/[\';]/", '', $match[1]);
$table_name = trim($table_name);
$this->_query = "SELECT * FROM sqlite_master WHERE tbl_name='$table_name'";
}
@ -408,7 +406,7 @@ class PDOSQLiteDriver {
return;
}
// data check
if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/im', $insert_data, $match_1)) {
if (preg_match('/^\((.*)\)\\s*VALUES\\s*\((.*)\)$/ims', $insert_data, $match_1)) {
$col_array = explode(',', $match_1[1]);
$ins_data_array = explode(',', $match_1[2]);
foreach ($col_array as $col) {
@ -498,15 +496,45 @@ class PDOSQLiteDriver {
$this->_query = $update_query;
}
}
} else {
// wordaround...
$pattern = '/ ON DUPLICATE KEY UPDATE.*$/im';
$replace_query = preg_replace($pattern, '', $this->_query);
$replace_query = str_ireplace('INSERT ', 'INSERT OR REPLACE ', $replace_query);
$this->_query = $replace_query;
}
// else {
// $pattern = '/ ON DUPLICATE KEY UPDATE.*$/im';
// $replace_query = preg_replace($pattern, '', $this->_query);
// $replace_query = str_ireplace('INSERT ', 'INSERT OR REPLACE ', $replace_query);
// $this->_query = $replace_query;
// }
}
private function _rewrite_between() {
$pattern = '/\\s*(\\w+)?\\s*BETWEEN\\s*([^\\s]*)?\\s*AND\\s*([^\\s]*)?\\s*/ims';
if (preg_match($pattern, $this->_query, $match)) {
$column_name = trim($match[1]);
$min_value = trim($match[2]);
$max_value = trim($match[3]);
$max_value = rtrim($max_value);
$tokens = preg_split("/(''|'|,|)/s", $this->_query, -1, PREG_SPLIT_DELIM_CAPTURE);
$literal = false;
$rewriting = false;
foreach ($tokens as $token) {
if (strpos($token, "'") !== false) {
if ($literal) {
$literal = false;
} else {
$literal = true;
}
} else {
if ($literal === false && stripos($token, 'between') !== false) {
$rewriting = true;
break;
}
}
}
if ($rewriting) {
$replacement = " $column_name >= '$min_value' AND $column_name <= '$max_value'";
$this->_query = str_ireplace($match[0], $replacement, $this->_query);
}
}
}
/**
* workaround function to avoid DELETE with JOIN
* wp-admin/includes/upgrade.php contains 'DELETE ... JOIN' statement.
@ -522,5 +550,11 @@ class PDOSQLiteDriver {
$this->_query = $rewritten;
}
}
/**
*
*/
private function _return_true() {
$this->_query = 'SELECT 1=1';
}
}
?>

View File

@ -3,56 +3,71 @@
* The class for manipulating ALTER query
* newly supports multiple variants
* @package SQLite Integration
* @version 1.1
* @author Kojima Toshiyasu
*/
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';
}
@ -61,110 +76,125 @@ 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;
$tokens['index_name'] = $match_3;
if ($match_3 == '') {
$tokens['index_name'] = str_replace(array('(', ')'), '', $the_rest);
} else {
$tokens['index_name'] = $match_3;
}
$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) = preg_split('/\s/s', trim($the_rest), -1, PREG_SPLIT_DELIM_CAPTURE);
$tokens['new_column'] = $new_col;
$col_def = str_ireplace($new_col, '', $the_rest);
$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 ($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 ($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;
@ -299,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']}";
@ -324,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) {
@ -336,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++) {
@ -345,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 ($tokenized_query['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']} {$tokenized_query['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 ($tokenized_query['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']} {$tokenized_query['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;
@ -370,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']}'");
@ -386,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;
@ -410,29 +467,11 @@ 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',
'int' => 'INTEGER', 'integer' => 'INTEGER',
'bigint' => 'INTEGER', 'float' => 'REAL',
'double' => 'REAL', 'decimal' => 'REAL',
'dec' => 'REAL', 'numeric' => 'REAL',
'fixed' => 'REAL', 'date' => 'TEXT',
'datetime' => 'TEXT', 'timestamp' => 'TEXT',
'time' => 'TEXT', 'year' => 'TEXT',
'char' => 'TEXT', 'varchar' => 'TEXT',
'binary' => 'INTEGER', 'varbinary' => 'BLOB',
'tinyblob' => 'BLOB', 'tinytext' => 'TEXT',
'blob' => 'BLOB', 'text' => 'TEXT',
'mediumblob' => 'BLOB', 'mediumtext' => 'TEXT',
'longblob' => 'BLOB', 'longtext' => '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){
$pattern = "/\\b" . $o . "\\s*(\([^\)]*\))?\\s*/imsx";
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);
break;
@ -449,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'
);
}
?>

View File

@ -1,7 +1,6 @@
<?php
/**
* @package SQLite Integration
* @version 1.1
* @author Kojima Toshiyasu, Justin Adie
*/
@ -31,8 +30,9 @@ class CreateQuery{
} else {
return $this->_query;
}
} elseif (preg_match('/^CREATE\\s*(TEMP|TEMPORARY|)\\s*TRIGGER\\s*/im', $this->_query)) {
return $this->_query;
}
$this->strip_backticks();
$this->get_table_name();
$this->rewrite_comments();
$this->rewrite_field_types();
@ -46,6 +46,7 @@ class CreateQuery{
$this->rewrite_set();
$this->rewrite_key();
$this->add_if_not_exists();
$this->strip_backticks();
return $this->post_process();
}
@ -86,8 +87,12 @@ class CreateQuery{
'longblob' => 'blob', 'longtext' => 'text'
);
foreach ($array_types as $o=>$r){
$pattern = '/\\b(?<!`)'.$o.'\\b\\s*(\([^\)]*\)*)?\\s*/imsx';
$this->_query = preg_replace($pattern, " $r ", $this->_query);
$pattern = "/\\b(?<!`)$o\\b\\s*(\([^\)]*\)*)?\\s*/ims";
if (preg_match("/^\\s*.*?\\s*\(.*?$o.*?\)/im", $this->_query)) {
;
} else {
$this->_query = preg_replace($pattern, " $r ", $this->_query);
}
}
}

View File

@ -6,8 +6,8 @@ Tags: database, SQLite, PDO
Author: Kojima Toshiyasu
Author URI: http://dogwood.skr.jp/
Requires at least: 3.3
Tested up to: 3.5.2
Stable tag: 1.1
Tested up to: 3.7.1
Stable tag: 1.4.2
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/)をご覧になると、もっと詳しい説明を読むことができます。
@ -44,7 +50,8 @@ SQLite Integrationは普通の「プラグイン」ではありません。WordP
下の方法でコンタクトを取ってください。
[Support Forum](http://wordpress.org/support/plugin/sqlite-integration)にポストする。
1. [Support Forum](http://wordpress.org/support/plugin/sqlite-integration)にポストする。
2. [SQLite Integration(ja)のページ](http://dogwood.skr.jp/wordpress/sqlite-integration-ja/)でメッセージを残す。
注意: WordPress.orgはMySQL以外のデータベースを正式にサポートしていません。だから、WordPress.orgからのサポートは得られません。フォーラムに投稿しても、回答を得ることはまずないでしょう。また、パッチをあてたプラグインを使う場合は、そのプラグインの作者からのサポートはないものと思ってください。自分でリスクを負う必要があります。
@ -158,18 +165,56 @@ wp-config.phpの準備が終わったら、次のステップに進みます。
* [Yet Another Related Posts](http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/)
* [Better Related Posts](http://wordpress.org/extend/plugins/better-related/)
たぶん、もっとあるでしょう。
たぶん、もっとあるでしょう。動作しないプラグインを見つけたら、お知らせいただけると助かります。
== Changelog ==
= 1.1 (2013-07-24) =
* DROP INDEX 単独のクエリが動作していなかったのを修正しました。
* shutdown_hook で descructor を実行していたのをやめました。
* LOCATE() 関数を使えるようにしました。
= 1.0 (2013-07-07) =
最初のリリース。
== Upgrade Notice ==
SQLite Integrationのアップグレードに失敗するようなら、FTPを使っての手動アップグレードを試してみてください。
== Changelog ==
= 1.4.2 (2013-11-06) =
* ダッシュボードに表示される情報についてのバグを修正しました。
* スクリーンショットを変更しました。
* WordPress 3.7.1 でのインストールテストを行いました。
= 1.4.1 (2013-09-27) =
* BETWEEN関数の書き換え方を修正しました。致命的なバグです。新規投稿に'between A and B'というフレーズが含まれていると、公開されず、投稿自体も消えます。
* MP6を使っているときに、管理画面のレイアウトが崩れるのを修正しました。
* 日本語が一部表示されないのを直しました。
* SELECT version()がダミーデータを返すようにしました。
* WP_DEBUGが有効の時に、WordPressのテーブルからカラム情報を読んで表示できるようにしました。
= 1.4 (2013-09-12) =
* アップグレードしたWordPressで期待通り動作しないのを修正するために、データベース管理ユーティリティを追加しました。
* SHOW INDEXクエリにWHERE句がある場合の処理を変更しました。
* ALTER TABLEクエリのバグを修正しました。
= 1.3 (2013-09-04) =
* データベースファイルのスナップショットをzipアーカイブとしてバックアップするユーティリティを追加しました。
* ダッシュボードのスタイルをMP6プラグインに合わせたものに変えました。
* 言語カタログが読み込まれていないときのエラーメッセージの出力方法を一部変更しました。
* query_create.class.phpの_rewrite_field_types()を変更しました。dbDelta()関数が意図したとおりに実行されます。
* BETWEENステートメントが使えるようになりました。
* クエリからインデックスヒントを全て削除して実行するようにしました。
* New StatPressプラグインが使えるように、ALTER TABLE CHANGE COLUMNの扱いを修正しました。
* いくつかの小さなバグを修正しました。
= 1.2.1 (2013-08-04) =
* wp-db.phpの変更にともなって、wpdb::real_escapeプロパティを削除しました。WordPress 3.6 との互換性を保つための変更です。
= 1.2 (2013-08-03) =
* カレンダー・ウィジェットでの不具合に対応するため、日付フォーマットとそのクオートを修正しました。
* Windows マシンでパッチファイルが削除できなかったのを修正しました。
* パッチファイルをアップロードするときに textdomain のエラーが出るのを修正しました。
* ON DUPLICATE KEY UPDATEをともなったクエリの処理を変更しました。
* readme.txt と readme-ja.txt の間違いを直しました。
= 1.1 (2013-07-24) =
* DROP INDEX 単独のクエリが動作していなかったのを修正しました。
* shutdown_hook で destruct() を実行していたのをやめました。
* LOCATE() 関数を使えるようにしました。
= 1.0 (2013-07-07) =
* 最初のリリース。

View File

@ -6,8 +6,8 @@ Tags: database, SQLite, PDO
Author: Kojima Toshiyasu
Author URI: http://dogwood.skr.jp/
Requires at least: 3.3
Tested up to: 3.5.2
Stable tag: 1.1
Tested up to: 3.7.1
Stable tag: 1.4.2
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -15,7 +15,7 @@ SQLite Integration is the plugin that enables WordPress to use SQLite. If you wa
== Description ==
This plugin enables WordPress to work with [SQLite](http://www.sqlite.org/). You don't have to prepare MySQL database server and its configuration. SQLite is a self-contained, serverless, transactional SQL database engine. It is not a full-featured database system like MySQL or PostgreSQL, but it best fits for low to medium traffic websites.
This plugin enables WordPress to work with [SQLite](http://www.sqlite.org/). You don't have to prepare MySQL database server or its configuration. SQLite is a self-contained, serverless, transactional SQL database engine. It is not a full-featured database system like MySQL or PostgreSQL, but it best fits for low to medium traffic websites.
SQLite Integration is a kind of wrapper program, which is placed between WordPress and SQLite database and works as a mediator. It works as follows:
@ -30,9 +30,15 @@ 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.2) 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).
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/).
Once you succeeded in installing WordPress, you can use it just like the others using MySQL. Optionally, you can activate this plugin in the installed plugins panel of the adimn dashboard, and you can see the useful information and instructions. It is not required but I recommend it.
@ -44,9 +50,10 @@ If you are using [PDO for WordPress](http://wordpress.org/extend/plugins/pdo-for
Please contact us with the methods below:
Post to [Support Forum](http://wordpress.org/support/plugin/sqlite-integration/).
1. Post to [Support Forum](http://wordpress.org/support/plugin/sqlite-integration/).
2. Visti the [SQLite Integration Page](http://dogwood.skr.jp/wordpress/sqlite-integration/) or [SQLite Integration(ja) Page](http://dogwood.skr.jp/wordpress/sqlite-integration-ja/) and leave a message.
Notes: WordPress.org doesn't officially support using any other database than MySQL. So there will be no supports from WordPress.org. Even if you post to the general Forum, you have few chances to get the answer. And if you use patched plugins, you will have be no support from the plugin authors, eithter.
Notes: WordPress.org doesn't officially support using any other database than MySQL. So there will be no supports from WordPress.org. Even if you post to the general Forum, you have few chances to get the answer. And if you use patched plugins, you will have no support from the plugin authors, eithter.
= Translation =
@ -58,9 +65,9 @@ This plugin is *not* like the other plugins. You can't install and activate it o
First of all, you've got to prepare WordPress installation. See [Installing Wordpress ](http://codex.wordpress.org/Installing_WordPress) section in the Codex.
After checking the prerequisites and unzipping the WordPress archive file, you must rename wp-contig-sample.php file to wp-config.php and do some editting as the [Codex page](http://codex.wordpress.org/Editing_wp-config.php) says. Please follow the instructions *except* the database settings.
After checking the prerequisites and unzipping the WordPress archive file, you must rename wp-contig-sample.php file to wp-config.php and do some editting as the [Codex page](http://codex.wordpress.org/Editing_wp-config.php) says. Please follow the Codex' instructions *except* the database settings.
When you finish, you can add optional settings. Follow the steps below:
When you finish, you can add optional settings. This is not required. If you don't need optional settings, you don't have to edit wp-config.php any more.
* If you want to put the SQLite database file to the directory different from the default setting (wp-content/database), you can add the line below (don't forget to add a trailing slash):
@ -150,18 +157,55 @@ These are other examples:
* [Yet Another Related Posts](http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/)
* [Better Related Posts](http://wordpress.org/extend/plugins/better-related/)
Probably there are more, I'm afraid.
== Changelog ==
= 1.1 (2013-07-24) =
* Fixed the manipulation of DROP INDEX query.
* Removed desctructor() from shutdown_hook.
* Enabled LOCATE() function in the query string.
= 1.0 (2013-07-07) =
First release version of the plugin.
Probably there are more, I'm afraid. If you find one, please let me know.
== Upgrade Notice ==
When auto upgrading of SQLite Integration fails, Please try manual upgrade via FTP.
When auto upgrading of SQLite Integration fails, please try manual upgrade via FTP.
== Changelog ==
= 1.4.2 (2013-11-06) =
* Fixed some minor bugs about the information in the dashboard.
* Changed the screenshot.
* Tested WordPress 3.7.1 installation.
= 1.4.1 (2013-09-27) =
* Fixed the rewriting process of BETWEEN function. This is a critical bug. When your newly created post contains 'between A and B' phrase, it is not published and disappears.
* Fixed the admin dashboard display when using MP6.
* Fixed the Japanese catalog.
* Added the procedure for returning the dummy data when using SELECT version().
* Added the procedure for displaying column informatin of WordPress tables when WP_DEBUG enabled.
= 1.4 (2013-09-12) =
* Added the database maintenance utility for fixing the database malfunction of the upgraded WordPress installation.
* Changed the manipulation of SHOW INDEX query with WHERE clause.
* 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.
* Changed the dashboard style to match MP6 plugin.
* Changed the way of putting out the error messages when language catalogs are not loaded.
* Modified the _rewrite_field_types() in query_create.class.php for the dbDelta() function to work properly.
* Added the support for BETWEEN statement.
* Changed the regular expression to remove all the index hints from the query string.
* Fixed the manipulation of ALTER TABLE CHANGE COLUMN query for NewStatPress plugin to work.
* Fixed minor bugs.
= 1.2.1 (2013-08-04) =
* Removed wpdb::real_escape property following the change of the wpdb.php file which makes the plugin compatible with Wordpress 3.6.
= 1.2 (2013-08-03) =
* Fixed the date string format and its quotation for calendar widget.
* Fixed the patch utility program for using on the Windows machine.
* Fixed the textdomain error in utilities/patch.php file when uploading the patch file.
* Changed the manipulation of the query with ON DUPLICATE KEY UPDATE.
* Fixed the typos in readme.txt and readme-ja.txt.
= 1.1 (2013-07-24) =
* Fixed the manipulation of DROP INDEX query.
* Removed destruct() from shutdown_hook.
* Enabled LOCATE() function in the query string.
= 1.0 (2013-07-07) =
* First release version of the plugin.

View File

@ -1,7 +1,6 @@
<?php
/**
* @package SQLite Integration
* @version 1.1
* @author Kojima Toshiyasu, Justin Adie
*/
@ -15,7 +14,7 @@ function make_db_sqlite() {
include_once ABSPATH . 'wp-admin/includes/schema.php';
$index_array = array();
ob_end_clean();
// ob_end_clean();
$table_schemas = wp_get_db_schema();
$queries = explode (";", $table_schemas);
$query_parser = new CreateQuery();
@ -23,8 +22,8 @@ function make_db_sqlite() {
$pdo = new PDO('sqlite:'.FQDB, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch (PDOException $err) {
$err_data = $err->errorInfo;
$message = __("Database connection error!<br />", 'sqlite-integration');
$message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err_data[2]);
$message = 'Database connection error!<br />';
$message .= sprintf("Error message is: %s", $err_data[2]);
echo $message;
return false;
}
@ -77,8 +76,8 @@ function make_db_sqlite() {
$pdo->commit();
} else {
$pdo->rollBack();
$message = sprintf(__("Error occured while creating tables or indexes...<br />Query was: %s<br />", 'sqlite-integration'), var_export($rewritten_query, true));
$message .= sprintf(__("Error message is: %s", 'sqlite-integration'), $err_data[2]);
$message = sprintf("Error occured while creating tables or indexes...<br />Query was: %s<br />", var_export($rewritten_query, true));
$message .= sprintf("Error message is: %s", $err_data[2]);
echo $message;
return false;
}

View File

@ -1,10 +1,10 @@
<?php
/*
Plugin Name: SQLite Integration
Plugin URI: http://wordpress.org/extend/plugins/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.1
Version: 1.4.1
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'));
@ -168,6 +173,8 @@ class SQLiteIntegration {
add_action('admin_print_scripts-'.$util_page, array($this, 'add_sqlite_script'));
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'));
}
}
@ -176,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'));
@ -191,6 +199,8 @@ class SQLiteIntegration {
add_action('admin_print_scripts-'.$util_page, array($this, 'add_sqlite_script'));
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'));
}
}

View File

@ -1,21 +1,8 @@
@CHARSET "UTF-8";
#sqlite-admin-wrap h2,
#sqlite-admin-side-wrap h2 {
background: rgb(73, 90, 88);
background: -moz-linear-gradient(bottom, rgba(73, 90, 88, 1), rgba(73, 90, 88, 0.5), rgba(73, 90, 88, 0));
background: -webkit-gradient(linear, bottom, top, from(rgba(73, 90, 88, 1)), color-stop(0.5, rgba(73, 90, 88, 0.5)), to(rgba(73, 90, 88, 0)));
background: linear-gradient(to top, rgba(73, 90, 88, 1), rgba(73, 90, 88, 0.2));
color: rgb(247, 254, 236);
-webkit-border-top-right-radius: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
text-shadow: -1px -1px 0 rgb(93, 69, 35),
1px -1px 0 rgb(93, 69, 35),
-1px 1px 0 rgb(93, 69, 35),
1px 1px 0 rgb(93, 69, 35);
background: rgb(34, 34, 34);
color: rgb(256, 256, 256);
padding-left: 5px;
}
.navigation {
@ -37,13 +24,8 @@
margin-right: 10px;
padding: 5px;
border: .5px solit #000;
-webkit-border-top-right-radius: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
box-shadow: 5px 5px 5px #eee;
background: rgb(51, 51, 51);
color: (256, 256, 256);
}
.menu-selected {
font-size: 20px;
@ -54,30 +36,18 @@
margin-right: 10px;
padding: 5px;
border: .5px solit #000;
-webkit-border-top-right-radius: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
box-shadow: 5px 5px 5px #eee;
background: rgb(73, 90, 88);
background: -moz-linear-gradient(bottom, rgba(73, 90, 88, 1), rgba(73, 90, 88, 0.5), rgba(73, 90, 88, 0));
background: -webkit-gradient(linear, bottom, top, from(rgba(73, 90, 88, 1)), color-stop(0.5, rgba(73, 90, 88, 0.5)), to(rgba(73, 90, 88, 0)));
background: linear-gradient(to top, rgba(73, 90, 88, 1), rgba(73, 90, 88, 0.2));
color: rgb(247, 254, 236);
text-shadow: -1px -1px 0 rgb(93, 69, 35),
1px -1px 0 rgb(93, 69, 35),
-1px 1px 0 rgb(93, 69, 35),
1px 1px 0 rgb(93, 69, 35);
background: rgb(46, 162, 204);
color: rgb(256, 256, 256);
}
.menu-item a {
text-decoration: none;
color: rgb(256, 256, 256);
}
#sqlite-admin-wrap {
color: #1d1d1d;
font-size: 10pt;
border: 1px solid #ddd;
background: rgb(256, 256, 256);
/* border-top: 0; */
-webkit-border-bottom-right-radius: 6px;
-webkit-border-bottom-left-radius: 6px;
@ -85,6 +55,12 @@
-moz-border-radius-bottomleft: 6px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;
-webkit-border-top-right-radius: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
display: block;
float: left;
min-height: 100px;
@ -99,6 +75,7 @@
color: #1d1d1d;
font-size: 10pt;
border: 1px solid #ddd;
background: rgb(256, 256, 256);
/* border-top: 0; */
-webkit-border-bottom-right-radius: 6px;
-webkit-border-bottom-left-radius: 6px;
@ -106,6 +83,12 @@
-moz-border-radius-bottomleft: 6px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;
-webkit-border-top-right-radius: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
display: block;
float: left;
min-height: 100px;
@ -122,7 +105,7 @@ p {
margin-left: 10px;
margin-right: 10px;
}
ul {
ul.in-body-list {
margin-left: 20px;
}
ol {

View File

@ -1,22 +1,9 @@
@CHARSET "UTF-8";
#sqlite-admin-wrap h2,
#sqlite-admin-side-wrap h2 {
background: rgb(73, 90, 88);
background: -moz-linear-gradient(bottom, rgba(73, 90, 88, 1), rgba(73, 90, 88, 0.5), rgba(73, 90, 88, 0));
background: -webkit-gradient(linear, bottom, top, from(rgba(73, 90, 88, 1)), color-stop(0.5, rgba(73, 90, 88, 0.5)), to(rgba(73, 90, 88, 0)));
background: linear-gradient(to top, rgba(73, 90, 88, 1), rgba(73, 90, 88, 0.2));
color: rgb(247, 254, 236);
-webkit-border-top-right-radius: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
text-shadow: -1px -1px 0 rgb(93, 69, 35),
1px -1px 0 rgb(93, 69, 35),
-1px 1px 0 rgb(93, 69, 35),
1px 1px 0 rgb(93, 69, 35);
padding-left: 5px;
background: rgb(34, 34, 34);
color: rgb(256, 256, 256);
padding-left: 5px;
}
h3 {
clear: both;
@ -40,13 +27,8 @@ h3 {
margin-right: 10px;
padding: 5px;
border: .5px solit #000;
-webkit-border-top-right-radius: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
box-shadow: 5px 5px 5px #eee;
background: rgb(51, 51, 51);
color: (256, 256, 256);
}
.menu-selected {
font-size: 20px;
@ -57,30 +39,18 @@ h3 {
margin-right: 10px;
padding: 5px;
border: .5px solit #000;
-webkit-border-top-right-radius: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
box-shadow: 5px 5px 5px #eee;
background: rgb(73, 90, 88);
background: -moz-linear-gradient(bottom, rgba(73, 90, 88, 1), rgba(73, 90, 88, 0.5), rgba(73, 90, 88, 0));
background: -webkit-gradient(linear, bottom, top, from(rgba(73, 90, 88, 1)), color-stop(0.5, rgba(73, 90, 88, 0.5)), to(rgba(73, 90, 88, 0)));
background: linear-gradient(to top, rgba(73, 90, 88, 1), rgba(73, 90, 88, 0.2));
color: rgb(247, 254, 236);
text-shadow: -1px -1px 0 rgb(93, 69, 35),
1px -1px 0 rgb(93, 69, 35),
-1px 1px 0 rgb(93, 69, 35),
1px 1px 0 rgb(93, 69, 35);
background: rgb(46, 162, 204);
color: rgb(256, 256, 256);
}
.menu-item a {
text-decoration: none;
color: rgb(256, 256, 256);
}
#sqlite-admin-wrap {
color: #1d1d1d;
font-size: 10pt;
border: 1px solid #ddd;
background: rgb(256, 256, 256);
/* border-top: 0; */
-webkit-border-bottom-right-radius: 6px;
-webkit-border-bottom-left-radius: 6px;
@ -88,11 +58,17 @@ h3 {
-moz-border-radius-bottomleft: 6px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;
-webkit-border-top-right-radius: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
display: block;
float: left;
min-height: 100%;
position: relative;
width: 60%;
width: 58%;
margin-top: 10px;
padding: 5px;
box-shadow: 5px 5px 5px #eee;
@ -102,6 +78,7 @@ h3 {
color: #1d1d1d;
font-size: 10pt;
border: 1px solid #ddd;
background: rgb(256, 256, 256);
/* border-top: 0; */
-webkit-border-bottom-right-radius: 6px;
-webkit-border-bottom-left-radius: 6px;
@ -109,6 +86,12 @@ h3 {
-moz-border-radius-bottomleft: 6px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;
-webkit-border-top-right-radius: 6px;
-webkit-border-top-left-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
display: block;
float: left;
min-height: 100%;
@ -125,14 +108,14 @@ p {
}
table#sys-info{
/* width: 600px; */
width: 450px;
width: 480px;
}
table#status {
width: 450px;
width: 480px;
}
table#sqlite-table {
/* width: 700px; */
width: 650px;
width: 100%;
}
th.tbl-name {
width: 200px;
@ -141,7 +124,7 @@ th.tbl_owner {
width: 105px;
}
th.tbl_index {
width: 350px;
width: 300px;
}
td.system {
color: rgb(153, 0, 0);
@ -150,12 +133,12 @@ td.user {
color: rgb(0, 0, 255);
}
td.menu-title {
width: 90px;
width: 95px;
}
table.statement {
width: 500px;
}
ul {
ul.in-body-list {
margin-left: 20px;
}
ol {
@ -176,7 +159,7 @@ tr.workaround {
tr.compatible {
}
th.active-plugins {
width: 100px;
width: 120px;
}
th.compatible {
width: 80px;
@ -189,7 +172,8 @@ input.button-primary {
.alt {
background: rgb(247, 254, 236);
}
table#patch-files .item {
table#patch-files .item,
table#backup-files .item {
width: 40px;
}
.alert {

View File

@ -0,0 +1,559 @@
<?php
/**
* database check and restoration
* This file is for temporary use and will be removed or changed in the future release.
*/
class DatabaseMaintenance {
private function sanity_check() {
global $wpdb;
$results_table = array();
$columns_to_check = array(
$wpdb->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_gmt' => '\'0000-00-00 00:00:00\'',
'comment_date' => '\'0000-00-00 00:00:00\'',
'comment_karma' => '\'0\'',
'comment_approved' => '\'1\'',
'comment_agent' => '\'\'',
'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_gmt' => '\'0000-00-00 00:00:00\'',
'post_date' => '\'0000-00-00 00:00:00\'',
'post_status' => '\'publish\'',
'comment_status' => '\'open\'',
'ping_status' => '\'open\'',
'post_password' => '\'\'',
'post_name' => '\'\'',
'post_modified_gmt' => '\'0000-00-00 00:00:00\'',
'post_modified' => '\'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
'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;
$return_val = array();
$queries = array();
$results = $this->sanity_check();
if ($results !== true) {
if (!$this->maintenance_backup()) {
$message = __('Can\'t create backup file.', $domain);
return $message;
}
$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 {
$message = __('Your database is OK. You don\'t have to restore it.', $domain);
return $message;
}
if (empty($return_val)) {
$message = __('Your database restoration is successfully finished!', $domain);
return $message;
} else {
return $return_val;
}
}
private function show_columns() {
global $wpdb, $utils;
$domain = $utils->text_domain;
$tables = $wpdb->tables('all');
if (!isset($_POST['table'])) {
$message = __('Table name is not selected.', $domain);
return $message;
} elseif (!in_array($_POST['table'], $tables)) {
$message = __('There\'s no such table.', $domain);
return $message;
} else {
$table_name = $_POST['table'];
$results = $wpdb->get_results("SHOW COLUMNS FROM $table_name");
return $results;
}
}
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, $wpdb;
$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') : ?>
<div class="navigation">
<ul class="navi-menu">
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=doc"><?php _e('Documentation', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain);?></a></li>
<li class="menu-selected"><?php _e('Maintenance', $domain);?></li>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">
<h2><?php _e('Database Maintenace', $domain);?></h2>
<h3><?php _e('Important Notice', $domain);?></h3>
<p>
<span style="color: red;"><?php _e('When you installed WordPress 3.5.x with SQLite Integration and upgraded to 3.6, your database might not function as expected.', $domain);?></span>
<?php _e('This page provide you the database sanity check utility and the restore utility.', $domain);?>
</p>
<p>
<?php _e('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).', $domain);?>
</p>
<p>
<?php _e('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.', $domain);?>
</p>
<p>
<?php _e('If you installed WordPress 3.6 (not upgraded), you don\'t have to restore the database.', $domain);?>
</p>
<form action="" method="post">
<?php
if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqliteintegration-database-manip-stats');
}
?>
<input type="submit" name="sanity-check" class="button-primary" value="<?php _e('Sanity Check', $domain);?>" onclick="return confirm('<?php _e('Are you sure to check the database? This will take some time.\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" />
<input type="submit" name="do-fix-database" class="button-primary" value="<?php _e('Fix database', $domain);?>" onclick="return confirm('<?php _e('Are you sure to do fix the database? This will take some time.\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" />
</form>
<?php if (defined('WP_DEBUG') && WP_DEBUG == true) : ?>
<h3><?php _e('Columns Information', $domain);?></h3>
<p>
<?php _e('Select a table name and click "Display Columns" button, and you\'ll see the column property of that table. This information is for debug use.', $domain);?>
</p>
<?php
$wp_tables = $wpdb->tables('all');
?>
<form action="" method="post">
<?php
if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqliteintegration-database-manip-stats');
}
?>
<label for="table"/><?php _e('Table Name: ', $domain);?></label>
<select name="table" id="table">
<?php foreach ($wp_tables as $table) :?>
<option value="<?php echo $table;?>"><?php echo $table;?></option>
<?php endforeach;?>
</select>
<input type="submit" name="show-columns" class="button-secondary" value="<?php _e('Display Columns', $domain);?>" onclick="return confirm('<?php _e('Display columns in the selected table.\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" />
</form>
<?php endif; ?>
</div>
<?php endif;
if (isset($_POST['do-fix-database'])) {
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));
}
$fix_results = $this->do_fix_database();
if (is_array($fix_results)) {
$title = '<h3>'. __('Results', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title;
echo '<ul>';
foreach ($fix_results as $result) {
echo '<li>' . $result . '</li>';
}
echo '</ul>';
echo '</div>';
} else {
$title = '<h3>'. __('Results', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title;
echo '<p>'.$fix_results.'</p>';
echo '</div>';
}
}
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 = '<h3>'. __('Checked Results', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title;
echo '<ul>';
foreach ($check_results as $table => $damaged) {
$message = __(' needs restoring.', $domain);
echo '<li><span class="em">' . $table . '</span>' . $message . '</li>';
}
echo '</ul>';
echo '</div>';
} else {
$title = '<h3>'. __('Checked Results', $domain) . '</h3>';
$message = __('Your database is OK. You don\'t have to restore it.', $domain);
echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title;
echo '<p>'.$message.'</p>';
echo '</div>';
}
}
if (isset($_POST['show-columns'])) {
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));
}
$results = $this->show_columns();
if (is_array($results)) {
$title = '<h3>'. sprintf(__('Columns In %s', $domain), $_POST['table']) . '</h3>';
$column_header = __('Column', $domain);
$type_header = __('Type', $domain);
$null_header = __('Null', $domain);
$default_header = __('Default', $domain);
echo '<div class="wrap" id="sqlite-admin-side-wrap" style="clear: both;">';
echo $title;
echo '<table class="widefat page fixed"><thead><tr><th>'. $column_header . '</th><th>'. $type_header . '</th><th>' . $null_header . '</th><th>' . $default_header . '</th></tr></thead>';
echo '<tbody>';
$counter = 0;
foreach ($results as $column) {
echo (($counter % 2) == 1) ? '<tr class="alt">' : '<tr>';
echo '<td>' . $column->Field . '</td>';
echo '<td>' . $column->Type . '</td>';
echo '<td>' . $column->Null . '</td>';
echo '<td>' . $column->Default . '</td>';
echo '</tr>';
$counter++;
}
echo '</tbody></table></div>';
} else {
$title = '<h3>'. __('Columns Info', $domain) . '</h3>';
echo '<div class="wrap" id="sqlite-admin-side-wrap">';
echo $title;
echo '<p>' . $results;
echo '</p></div>';
}
}
}
}
?>

View File

@ -1,8 +1,7 @@
<?php
/**
* @package SQLite Integration
* @version 1.1
* @author Toshiyasu Kojima
* @author Kojima Toshiyasu
*
*/
/**
@ -25,6 +24,7 @@ class SQLiteIntegrationDocument {
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain); ?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></li>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">
@ -38,7 +38,7 @@ class SQLiteIntegrationDocument {
<h3><?php _e('Features', $domain);?></h3>
<p>
<?php _e('This plugin is a successor to <a href="http://wordpress.org/extend/plugins/pdo-for-wordpress/">PDO for WordPress</a>, which enabled WordPress to use SQLite for its database. But PDO for WordPress doesn\'t seem to be maintained any more only to be outdated. SQLite Integration makes use of the basic ideas and framework of PDO for WordPress, adds some new features and updates it to be able to work with the newest version of WordPress(3.5.1 and 3.6 beta).', $domain); ?>
<?php _e('This plugin is a successor to <a href="http://wordpress.org/extend/plugins/pdo-for-wordpress/">PDO for WordPress</a>, which enabled WordPress to use SQLite for its database. But PDO for WordPress doesn\'t seem to be maintained any more only to be outdated. SQLite Integration makes use of the basic ideas and framework of PDO for WordPress, adds some new features and updates it to be able to work with the newest version of WordPress(3.7.1).', $domain); ?>
</p>
<p>
<?php _e('<a href="http://www.sqlite.org/">SQLite Web Page</a> says &mdash; SQLite is a &quot;software library that implements selfcontained, serverless, zero-configuration, transactional SQL database engine&quot;. It is &quot;a good choice for small to medium size websites&quot;. It\'s small and portable, and you don\'t need any database server system.', $domain); ?>
@ -86,7 +86,7 @@ class SQLiteIntegrationDocument {
<p>
<?php _e('SQLite Integration doesn\'t contain database maintenace functionality, because there are some other free or proprietary softwares that give you such functionalities. For example, these are among free softwares:', $domain);?>
</p>
<ul>
<ul class="in-body-list">
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/">SQLite Manager Mozilla Addon</a>(<?php _e('my recommendation', $domain);?>)</li>
<li><a href="http://www.sqlitemanager.org/">SQLiteManager</a>(<?php _e('unfortunately seems not to maintained...', $domain); ?>)</li>
</ul>

View File

@ -3,7 +3,7 @@
* This file contains PatchUtils class
*
* @package SQLite Integration
* @since 1.1
* @author Kojima Toshiyasu
*
*/
class PatchUtils {
@ -34,6 +34,8 @@ class PatchUtils {
* @return boolean|array
*/
private function apply_patches() {
global $utils;
$domain = $utils->text_domain;
$installed_plugins = array();
$file_names = array();
$output = array();
@ -103,6 +105,8 @@ class PatchUtils {
* @return boolean|array
*/
private function delete_patch_files() {
global $utils;
$domain = $utils->text_domain;
$file_names = array();
$rm_results = array();
if (isset($_POST['plugin_checked'])) {
@ -110,18 +114,16 @@ class PatchUtils {
} else {
return false;
}
$command = 'rm -f';
foreach ($file_names as $file) {
if (chdir(SQLitePatchDir)) {
exec("$command $file", $output, $retval);
} else {
$rm_results[$file] = __('Error!: patches directory is not accessible.', $domain);
}
if ($retval > 0) {
$rm_results[$file] = sprintf(__('Error! Messages: %s', $domain), $output);
} else {
$rm_results[$file] = sprintf(__('File %s is deleted.', $domain), $file);
}
if (chdir(SQLitePatchDir)) {
foreach ($file_names as $file) {
if (unlink($file)) {
$rm_results[$file] = sprintf(__('File %s is deleted.', $domain), $file);
} else {
$rm_results[$file] = sprintf(__('Error! File %s is not deleted.', $domain), $file);
}
}
} else {
$rm_results[$file] = __('Error!: patches directory is not accessible.', $domain);
}
return $rm_results;
}
@ -130,6 +132,8 @@ class PatchUtils {
* No return values.
*/
private function upload_file() {
global $utils;
$domain = $utils->text_domain;
if (!file_exists(SQLitePatchDir) || !is_dir(SQLitePatchDir)) {
mkdir(SQLitePatchDir, 0705, true);
}
@ -198,7 +202,7 @@ class PatchUtils {
}
echo '</div>';
} else {
$message = __('Error! Please remove files manually');
$message = __('Error! Please remove files manually', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
}
}
@ -218,6 +222,7 @@ class PatchUtils {
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=sys-info"><?php _e('System Info', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li>
<li class="menu-selected"><?php _e('Patch Utility', $domain);?></li>
<li class="menu-item"><a href="<?php echo $utils->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></li>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">

View File

@ -22,7 +22,14 @@
"compat":"Checked",
"class":"compatible"
},
{
"name":"Better Delete Revision",
"compat":"No",
"reason":"DELETE with JOIN/etc",
"class":"incompatible"
},
{
"name":"Better Related Posts",
"compat":"No",
@ -111,6 +118,14 @@
"class":"compatible"
},
{
"name":"FeedWordPress",
"compat":"Needs patch",
"patch_url":"http://dogwood.skr.jp/wordpress/plugins/",
"reason":"MySQL specific function",
"class":"workaround"
},
{
"name":"Google Analyticator",
"compat":"Checked",
@ -162,6 +177,34 @@
"class":"compatible"
},
{
"name":"Mathjax Latex",
"compat":"Checked",
"class":"compatible"
},
{
"name":"MP6",
"compat":"Checked",
"class":"compatible"
},
{
"name":"NewStatPress",
"compat":"Needs Patch",
"patch_url":"http://dogwood.skr.jp/wordpress/plugins/",
"reason":"MySQL specific data",
"class":"workaround"
},
{
"name":"NextGEN Gallery",
"compat":"Needs patch",
"patch_url":"http://dogwood.skr.jp/wordpress/plugins/",
"reason":"MySQL specific function",
"class":"workaround"
},
{
"name":"Optimize Database after Deleting Revisions",
"compat":"Probably No",
@ -175,6 +218,12 @@
"class":"compatible"
},
{
"name":"Redirection",
"compat":"Checked",
"class":"compatible"
},
{
"name":"Related Posts",
"compat":"Checked",
@ -237,12 +286,20 @@
{
"name":"Wordpress Popular Posts",
"compat":"Needs Patch",
"patch_url":"http://dogwood.skr.jp/wordpress/plugins/",
"reason":"MySQL specific query",
"class":"workaround"
},
{
"name":"WordPress Related Posts",
"compat":"Checked",
"class":"compatible"
},
{
"name":"WordPress Related Posts",
"name":"WP Emmet",
"compat":"Checked",
"class":"compatible"
},
@ -264,7 +321,13 @@
"compat":"Checked",
"class":"compatible"
},
{
"name":"WP-PostViews",
"compat":"Checked",
"class":"compatible"
},
{
"name":"WP-reCAPTCHA",
"compat":"Checked",

View File

@ -2,7 +2,7 @@
/**
*
* @package SQLite Integration
* @author kjm
* @author Kojima Toshiyasu
*
*/
class SQLiteIntegrationUtils {
@ -198,7 +198,7 @@ class SQLiteIntegrationUtils {
$db_file = FQDB;
if (file_exists($db_file)) {
$size = filesize($db_file);
clearstatcache(false, $db_file);
clearstatcache(true, $db_file);
return $this->convert_to_formatted_number($size);
}
}
@ -329,6 +329,79 @@ class SQLiteIntegrationUtils {
}
}
/**
* function to parse FQDBDIR and return backup database files
*/
private function get_backup_files() {
$db_name = basename(FQDB);
$names_to_exclude = array('.', '..', '.htaccess', 'debug.txt', '.ht.sqlite', $db_name);
$backup_files = array();
if (is_dir(FQDBDIR)) {
if ($dir_handle = opendir(FQDBDIR)) {
while (($file_name = readdir($dir_handle)) !== false) {
if (in_array($file_name, $names_to_exclude)) continue;
$backup_files[] = $file_name;
}
}
}
return $backup_files;
}
/**
* function to create backup file
*/
private function backup_db() {
$result = array();
$database_file = FQDB;
$db_name = basename(FQDB);
if (!file_exists($database_file)) {
return false;
}
$today = date("Ymd");
if (!extension_loaded('zip')) {
$backup_file = $database_file . '.' . $today . '.back';
if (copy($database_file, $backup_file)) {
$result['success'] = basename($backup_file) . __(' was created.', $domain);
} else {
$result['error'] = basename($backup_file) . __(' was not created.', $domain);
}
} else {
$backup_file = $database_file . '.' . $today . '.zip';
$zip = new ZipArchive();
$res = $zip->open($backup_file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
if ($res === true) {
$zip->addFile($database_file, $db_name);
$result['success'] = basename($backup_file) . __(' was created.', $domain);
} else {
$result['error'] = basename($backup_file) . __(' was not created.', $domain);
}
$zip->close();
}
return $result;
}
private function delete_backup_db() {
global $utils;
$domain = $utils->text_domain;
$file_names = array();
$results = array();
if (isset($_POST['backup_checked'])) {
$file_names = $_POST['backup_checked'];
} else {
return false;
}
if (chdir(FQDBDIR)) {
foreach ($file_names as $file) {
if (unlink($file)) {
$results[$file] = sprintf(__('File %s was deleted.', $domain), $file);
} else {
$results[$file] = sprintf(__('Error! File was not deleted.', $domain), $file);
}
}
}
return $results;
}
function welcome() {
$domain = $this->text_domain;
if (isset($_GET['page']) && $_GET['page'] == 'sqlite-integration') :?>
@ -366,6 +439,10 @@ class SQLiteIntegrationUtils {
<td><a href="<?php echo $this->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain)?></a></td>
<td><?php _e('You can upload patch files and apply them to the incompatible plugins.', $domain)?></td>
</tr>
<tr>
<td><a href="<?php echo $this->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></td>
<td><?php _e('You can check your database and fix it if needed.', $domain);?></td>
</tr>
</tbody>
</table>
</div>
@ -390,6 +467,7 @@ class SQLiteIntegrationUtils {
<li class="menu-selected"><?php _e('System Info', $domain);?></li>
<li class="menu-item"><a href="<?php echo $this->show_parent();?>?page=setting-file"><?php _e('Miscellaneous', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $this->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain);?></a></li>
<li class="menu-item"><a href="<?php echo $this->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></li>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">
@ -608,6 +686,35 @@ class SQLiteIntegrationUtils {
echo '<div id="message" class="updated fade">'.$messages.'</div>';
}
}
if (isset($_POST['backup_db'])) {
check_admin_referer('sqliteintegration-backup-manip-stats');
$results = $this->backup_db();
if ($results === false) {
$message = __('Couldn\'t find your database file.');
echo '<div id="message" class="updated fade">'.$message.'</div>';
} elseif (is_array($results) && array_key_exists('success', $results)) {
echo '<div id="message" class="updated fade">'.$results['success'].'</div>';
} else {
echo '<div id="message" class="update fade">'.$results['error'].'</div>';
}
}
if (isset($_POST['delete_backup_files'])) {
check_admin_referer('sqliteintegration-backup-manip-stats');
$results = $this->delete_backup_db();
if ($results === false) {
$message = __('Please select backup file(s).', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
} elseif (is_array($results) && count($results) > 0) {
echo '<div id="message" class="updated fade">';
foreach ($results as $key => $val) {
echo $val.'<br />';
}
echo '</div>';
} else {
$message = __('Error! Please remove file(s) manyally.', $domain);
echo '<div id="message" class="updated fade">'.$message.'</div>';
}
}
if (isset($_GET['page']) && $_GET['page'] == 'setting-file') :?>
<div class="navigation">
<ul class="navi-menu">
@ -615,6 +722,7 @@ class SQLiteIntegrationUtils {
<li class="menu-item"><a href="<?php echo $this->show_parent();?>?page=sys-info"><?php _e('System Info', $domain) ?></a></li>
<li class="menu-selected"><?php _e('Miscellaneous', $domain);?></li>
<li class="menu-item"><a href="<?php echo $this->show_parent();?>?page=patch"><?php _e('Patch Utility', $domain)?></a></li>
<li class="menu-item"><a href="<?php echo $this->show_parent();?>?page=maintenance"><?php _e('Maintenance', $domain);?></a></li>
</ul>
</div>
<div class="wrap" id="sqlite-admin-wrap">
@ -632,7 +740,43 @@ class SQLiteIntegrationUtils {
<input type="submit" name="sqlitewordpress_db_optimize" value="<?php _e('Optimize', $domain)?>" onclick="return confirm('<?php _e('Are you sure to optimize your database?\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" class="button-primary">
</p>
</form>
<h3><?php _e('SQLite Integration Error Log', $domain)?></h3>
<h3><?php _e('Create or Delete backup file(s)', $domain);?></h3>
<p>
<?php _e('Click the backup button below if you want to create a current snapshot of your database file. The backup file is named &lsquo;DB_FILE_NAME.yyyymmdd.zip&rsquo; if PHP zip extension is loaded or &lsquo;DB_FILE_NAME.yyyymmdd.back&rsquo; if not loaded, and is put in the same directory that the database is in.', $domain);?>
</p>
<p>
<?php _e('If you want to delete the file(s), check the file name and click the Delete button. You can check multiple files.', $domain);?>
</p>
<?php $backup_files = $this->get_backup_files();?>
<form action="" method="post" id="delete-backup-form">
<?php if (function_exists('wp_nonce_field')) {
wp_nonce_field('sqliteintegration-backup-manip-stats');
}
?>
<table class="widefat page fixed" id="backup-files">
<thead>
<tr>
<th class="item"><?php _e('Delete', $domain);?></th>
<th data-sort='{"key":"name"}'><?php _e('Backup Files', $domain);?></th>
</tr>
</thead>
<tbody>
<?php if (!empty($backup_files)) : ?>
<?php foreach ($backup_files as $file) : ?>
<tr data-table='{"name":"<?php echo $file;?>"}'>
<td><input type="checkbox" id="backup_check" name="backup_checked[]" value="<?php echo $file;?>"/></td>
<td><?php echo $file;?></td>
</tr>
<?php endforeach;?>
<?php endif;?>
</tbody>
</table>
<p>
<input type="submit" name="backup_db" class="button-primary" value="<?php _e('Backup', $domain);?>" onclick="return confirm('<?php _e('Are you sure to make a backup file?\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" />
<input type="submit" name="delete_backup_files" class="button-primary" value="<?php _e('Delete file', $domain);?>" onclick="return confirm('<?php _e('Are you sure to delete backup file(s)?\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" />
</p>
</form>
<h3><?php _e('SQLite Integration Error Log', $domain);?></h3>
<p>
<?php _e('This is the contents of SQLite Integration error log file(default: wp-content/database/debug.txt). If you want to clear this file, click the Clear Log button.', $domain)?>
</p>
@ -641,7 +785,7 @@ class SQLiteIntegrationUtils {
wp_nonce_field('sqlitewordpress-log-reset-stats');
}
?>
<textarea name="errorlog" id="errorlog" cols="85" rows="10">
<textarea name="errorlog" id="errorlog" cols="70" rows="10">
<?php $ret_val = $this->show_error_log();
if ($ret_val === false || empty($ret_val)) {
$message = __('No error messages are found', $domain);
@ -665,7 +809,7 @@ class SQLiteIntegrationUtils {
wp_nonce_field('sqlitewordpress-db-save-stats');
}
?>
<textarea name="dbfile" id="dbfile" cols="85" rows="30">
<textarea name="dbfile" id="dbfile" cols="70" rows="10">
<?php $this->show_db_php();?></textarea>
<p>
<input type="submit" name="sqlitewordpress_db_save" value="<?php _e('Save')?>" onclick="return confirm('<?php _e('Are you sure to save this file?\n\nClick [Cancel] to stop, [OK] to continue.', $domain);?>')" class="button-primary">