mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-08-31 03:53:15 +08:00
Fixed: CodeFactor issues
This commit is contained in:
parent
47c0856c25
commit
b0d1792844
1 changed files with 43 additions and 54 deletions
|
@ -41,8 +41,6 @@ class MainWP_Clone_Install {
|
|||
* @return bool
|
||||
*/
|
||||
public function checkZipConsole() {
|
||||
// todo: implement
|
||||
// return function_exists('system');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -50,7 +48,6 @@ class MainWP_Clone_Install {
|
|||
return function_exists( 'unzip_file' );
|
||||
}
|
||||
|
||||
|
||||
public function removeConfigFile() {
|
||||
if ( ! $this->file || ! file_exists( $this->file ) ) {
|
||||
return false;
|
||||
|
@ -59,7 +56,7 @@ class MainWP_Clone_Install {
|
|||
if ( null !== $this->archiver ) {
|
||||
|
||||
} elseif ( $this->checkZipConsole() ) {
|
||||
// todo: implement
|
||||
// skip.
|
||||
} elseif ( $this->checkZipSupport() ) {
|
||||
$zip = new ZipArchive();
|
||||
$zipRes = $zip->open( $this->file );
|
||||
|
@ -73,7 +70,6 @@ class MainWP_Clone_Install {
|
|||
|
||||
return false;
|
||||
} else {
|
||||
// use pclzip
|
||||
$zip = new PclZip( $this->file );
|
||||
$list = $zip->delete( PCLZIP_OPT_BY_NAME, 'wp-config.php' );
|
||||
$list2 = $zip->delete( PCLZIP_OPT_BY_NAME, 'clone' );
|
||||
|
@ -115,7 +111,7 @@ class MainWP_Clone_Install {
|
|||
|
||||
return $this->archiver->file_exists( $file );
|
||||
} elseif ( $this->checkZipConsole() ) {
|
||||
// todo: implement
|
||||
// skip.
|
||||
} elseif ( $this->checkZipSupport() ) {
|
||||
$zip = new ZipArchive();
|
||||
$zipRes = $zip->open( $this->file );
|
||||
|
@ -139,7 +135,7 @@ class MainWP_Clone_Install {
|
|||
if ( false === $configContents ) {
|
||||
throw new Exception( __( 'Cant read configuration file from the backup.', 'mainwp-child' ) );
|
||||
}
|
||||
$this->config = maybe_unserialize( base64_decode( $configContents ) );
|
||||
$this->config = maybe_unserialize( base64_decode( $configContents ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
|
||||
|
||||
if ( isset( $this->config['plugins'] ) ) {
|
||||
MainWP_Helper::update_option( 'mainwp_temp_clone_plugins', $this->config['plugins'] );
|
||||
|
@ -188,7 +184,7 @@ class MainWP_Clone_Install {
|
|||
}
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
|
||||
// ok!
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,11 +201,11 @@ class MainWP_Clone_Install {
|
|||
/** @var $wpdb wpdb */
|
||||
global $wpdb;
|
||||
|
||||
$var = $wpdb->get_var( $wpdb->prepare( 'SELECT option_value FROM ' . $this->config['prefix'] . 'options WHERE option_name = %s', $name) );
|
||||
$var = $wpdb->get_var( $wpdb->prepare( 'SELECT option_value FROM ' . $this->config['prefix'] . 'options WHERE option_name = %s', $name ) );
|
||||
if ( null === $var ) {
|
||||
$wpdb->query( $wpdb->prepare( 'INSERT INTO ' . $this->config['prefix'] . 'options (`option_name`, `option_value`) VALUES (%s, "' . MainWP_Child_DB::real_escape_string( maybe_serialize( $value ) ) . '")', $name) );
|
||||
$wpdb->query( $wpdb->prepare( 'INSERT INTO ' . $this->config['prefix'] . 'options (`option_name`, `option_value`) VALUES (%s, "' . MainWP_Child_DB::real_escape_string( maybe_serialize( $value ) ) . '")', $name ) );
|
||||
} else {
|
||||
$wpdb->query( $wpdb->prepare( 'UPDATE ' . $this->config['prefix'] . 'options SET option_value = "' . MainWP_Child_DB::real_escape_string( maybe_serialize( $value ) ) . '" WHERE option_name = %s', $name) );
|
||||
$wpdb->query( $wpdb->prepare( 'UPDATE ' . $this->config['prefix'] . 'options SET option_value = "' . MainWP_Child_DB::real_escape_string( maybe_serialize( $value ) ) . '" WHERE option_name = %s', $name ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +216,7 @@ class MainWP_Clone_Install {
|
|||
$table_prefix = $this->config['prefix'];
|
||||
$home = get_option( 'home' );
|
||||
$site_url = get_option( 'siteurl' );
|
||||
// Install database
|
||||
// Install database!
|
||||
define( 'WP_INSTALLING', true );
|
||||
define( 'WP_DEBUG', false );
|
||||
$query = '';
|
||||
|
@ -269,15 +265,14 @@ class MainWP_Clone_Install {
|
|||
$tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N );
|
||||
|
||||
foreach ( $tables_db as $curr_table ) {
|
||||
// fix for more table prefix in one database
|
||||
if ( ( strpos( $curr_table[0], $wpdb->prefix ) !== false ) || ( strpos( $curr_table[0], $table_prefix ) !== false ) ) {
|
||||
// fix for more table prefix in one database.
|
||||
if ( ( false !== strpos( $curr_table[0], $wpdb->prefix ) ) || ( false !== strpos( $curr_table[0], $table_prefix ) ) ) {
|
||||
$tables[] = $curr_table[0];
|
||||
}
|
||||
}
|
||||
// Replace importance data first so if other replace failed, the website still work
|
||||
// Replace importance data first so if other replace failed, the website still work.
|
||||
$wpdb->query( $wpdb->prepare( 'UPDATE ' . $table_prefix . 'options SET option_value = %s WHERE option_name = "siteurl"', $site_url ) );
|
||||
$wpdb->query( $wpdb->prepare( 'UPDATE ' . $table_prefix . 'options SET option_value = %s WHERE option_name = "home"', $home ) );
|
||||
// Replace others
|
||||
$this->icit_srdb_replacer( $wpdb->dbh, $this->config['home'], $home, $tables );
|
||||
$this->icit_srdb_replacer( $wpdb->dbh, $this->config['siteurl'], $site_url, $tables );
|
||||
|
||||
|
@ -287,10 +282,14 @@ class MainWP_Clone_Install {
|
|||
}
|
||||
|
||||
protected function recalculateSerializedLengths( $pObject ) {
|
||||
return preg_replace_callback( '|s:(\d+):"(.*?)";|', array(
|
||||
$this,
|
||||
'recalculateSerializedLengths_callback',
|
||||
), $pObject );
|
||||
return preg_replace_callback(
|
||||
'|s:(\d+):"(.*?)";|',
|
||||
array(
|
||||
$this,
|
||||
'recalculateSerializedLengths_callback',
|
||||
),
|
||||
$pObject
|
||||
);
|
||||
}
|
||||
|
||||
protected function recalculateSerializedLengths_callback( $matches ) {
|
||||
|
@ -309,8 +308,8 @@ class MainWP_Clone_Install {
|
|||
*
|
||||
* @return bool False if not serialized and true if it was.
|
||||
*/
|
||||
function is_serialized( $data ) {
|
||||
// if it isn't a string, it isn't serialized
|
||||
public function is_serialized( $data ) {
|
||||
// if it isn't a string, it isn't serialized.
|
||||
if ( ! is_string( $data ) ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -373,14 +372,11 @@ class MainWP_Clone_Install {
|
|||
return $content;
|
||||
} else {
|
||||
if ( $this->checkZipConsole() ) {
|
||||
// todo: implement
|
||||
} elseif ( $this->checkZipSupport() ) {
|
||||
$zip = new ZipArchive();
|
||||
$zipRes = $zip->open( $this->file );
|
||||
if ( $zipRes ) {
|
||||
$content = $zip->getFromName( 'clone/config.txt' );
|
||||
// $zip->deleteName('clone/config.txt');
|
||||
// $zip->deleteName('clone/');
|
||||
$zip->close();
|
||||
|
||||
return $content;
|
||||
|
@ -388,10 +384,8 @@ class MainWP_Clone_Install {
|
|||
|
||||
return false;
|
||||
} else {
|
||||
// use pclzip
|
||||
$zip = new PclZip( $this->file );
|
||||
$content = $zip->extract( PCLZIP_OPT_BY_NAME, 'clone/config.txt',
|
||||
PCLZIP_OPT_EXTRACT_AS_STRING );
|
||||
$content = $zip->extract( PCLZIP_OPT_BY_NAME, 'clone/config.txt', PCLZIP_OPT_EXTRACT_AS_STRING );
|
||||
if ( ! is_array( $content ) || ! isset( $content[0]['content'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -417,7 +411,6 @@ class MainWP_Clone_Install {
|
|||
if ( ! $this->archiver->isOpen() ) {
|
||||
$this->archiver->read( $this->file );
|
||||
}
|
||||
|
||||
return $this->archiver->extractTo( ABSPATH );
|
||||
} elseif ( ( filesize( $this->file ) >= 50000000 ) && $this->checkWPZip() ) {
|
||||
return $this->extractWPZipBackup();
|
||||
|
@ -471,7 +464,7 @@ class MainWP_Clone_Install {
|
|||
if ( 0 === $zip->extract( PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( $zip->error_code !== PCLZIP_ERR_NO_ERROR ) {
|
||||
if ( PCLZIP_ERR_NO_ERROR !== $zip->error_code ) {
|
||||
throw new Exception( $zip->errorInfo( true ) );
|
||||
}
|
||||
|
||||
|
@ -484,8 +477,6 @@ class MainWP_Clone_Install {
|
|||
* @return bool
|
||||
*/
|
||||
public function extractZipConsoleBackup() {
|
||||
// todo implement
|
||||
// system('zip');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -515,7 +506,7 @@ class MainWP_Clone_Install {
|
|||
return preg_replace( '/(\$' . $varname . ' *= *[\'"])(.*?)([\'"] *;)/is', '${1}' . $value . '${3}', $content );
|
||||
}
|
||||
|
||||
function recurse_chmod( $mypath, $arg ) {
|
||||
public function recurse_chmod( $mypath, $arg ) {
|
||||
$d = opendir( $mypath );
|
||||
while ( ( $file = readdir( $d ) ) !== false ) {
|
||||
if ( '.' !== $file && '..' !== $file ) {
|
||||
|
@ -543,7 +534,7 @@ class MainWP_Clone_Install {
|
|||
*
|
||||
* @return array Collection of information gathered during the run.
|
||||
*/
|
||||
function icit_srdb_replacer( $connection, $search = '', $replace = '', $tables = array() ) {
|
||||
public function icit_srdb_replacer( $connection, $search = '', $replace = '', $tables = array() ) {
|
||||
global $guid, $exclude_cols;
|
||||
|
||||
$report = array(
|
||||
|
@ -561,14 +552,14 @@ class MainWP_Clone_Install {
|
|||
|
||||
$columns = array();
|
||||
|
||||
// Get a list of columns in this table
|
||||
// Get a list of columns in this table.
|
||||
$fields = MainWP_Child_DB::_query( 'DESCRIBE ' . $table, $connection );
|
||||
while ( $column = MainWP_Child_DB::fetch_array( $fields ) ) {
|
||||
$columns[ $column['Field'] ] = 'PRI' === $column['Key'] ? true : false;
|
||||
}
|
||||
|
||||
// Count the number of rows we have in the table if large we'll split into blocks, This is a mod from Simon Wheatley
|
||||
$row_count = MainWP_Child_DB::_query( 'SELECT COUNT(*) as count FROM ' . $table, $connection ); // to fix bug
|
||||
// Count the number of rows we have in the table if large we'll split into blocks, This is a mod from Simon Wheatley.
|
||||
$row_count = MainWP_Child_DB::_query( 'SELECT COUNT(*) as count FROM ' . $table, $connection );
|
||||
$rows_result = MainWP_Child_DB::fetch_array( $row_count );
|
||||
$row_count = $rows_result['count'];
|
||||
if ( 0 === $row_count ) {
|
||||
|
@ -581,7 +572,7 @@ class MainWP_Clone_Install {
|
|||
$current_row = 0;
|
||||
$start = $page * $page_size;
|
||||
$end = $start + $page_size;
|
||||
// Grab the content of the table
|
||||
// Grab the content of the table.
|
||||
$data = MainWP_Child_DB::_query( sprintf( 'SELECT * FROM %s LIMIT %d, %d', $table, $start, $end ), $connection );
|
||||
if ( ! $data ) {
|
||||
$report['errors'][] = MainWP_Child_DB::error();
|
||||
|
@ -589,7 +580,7 @@ class MainWP_Clone_Install {
|
|||
|
||||
while ( $row = MainWP_Child_DB::fetch_array( $data ) ) {
|
||||
|
||||
$report['rows'] ++; // Increment the row counter
|
||||
$report['rows'] ++; // Increment the row counter.
|
||||
$current_row ++;
|
||||
|
||||
$update_sql = array();
|
||||
|
@ -601,10 +592,11 @@ class MainWP_Clone_Install {
|
|||
continue;
|
||||
}
|
||||
|
||||
$edited_data = $data_to_fix = $row[ $column ];
|
||||
$edited_data = $row[ $column ];
|
||||
$data_to_fix = $edited_data;
|
||||
// Run a search replace on the data that'll respect the serialisation.
|
||||
$edited_data = $this->recursive_unserialize_replace( $search, $replace, $data_to_fix );
|
||||
// Something was changed
|
||||
// Something was changed.
|
||||
if ( $edited_data !== $data_to_fix ) {
|
||||
$report['change'] ++;
|
||||
$update_sql[] = $column . ' = "' . MainWP_Child_DB::real_escape_string( $edited_data ) . '"';
|
||||
|
@ -647,21 +639,18 @@ class MainWP_Clone_Install {
|
|||
*
|
||||
* @return array The original array with all elements replaced as needed.
|
||||
*/
|
||||
public function recursive_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) {
|
||||
|
||||
/* Fixed serialize issue */
|
||||
function recursive_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) {
|
||||
|
||||
// some unseriliased data cannot be re-serialised eg. SimpleXMLElements
|
||||
// some unseriliased data cannot be re-serialised eg. SimpleXMLElements.
|
||||
try {
|
||||
|
||||
if ( is_string( $data ) && is_serialized( $data ) && ! is_serialized_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) {
|
||||
$unserialized = @unserialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.
|
||||
if ( is_string( $data ) && is_serialized( $data ) && ! is_serialized_string( $data ) && false !== $unserialized ) {
|
||||
$data = $this->recursive_unserialize_replace( $from, $to, $unserialized, true );
|
||||
} elseif ( is_array( $data ) ) {
|
||||
$_tmp = array();
|
||||
foreach ( $data as $key => $value ) {
|
||||
$_tmp[ $key ] = $this->recursive_unserialize_replace( $from, $to, $value, false );
|
||||
}
|
||||
|
||||
$data = $_tmp;
|
||||
unset( $_tmp );
|
||||
} elseif ( is_object( $data ) ) {
|
||||
|
@ -673,11 +662,11 @@ class MainWP_Clone_Install {
|
|||
|
||||
$data = $_tmp;
|
||||
unset( $_tmp );
|
||||
} elseif ( is_serialized_string($data) && is_serialized($data) ) {
|
||||
// TODO: apply solution like phpmyadmin project have!
|
||||
if ( ( $data = @unserialize( $data ) ) !== false ) {
|
||||
} elseif ( is_serialized_string( $data ) && is_serialized( $data ) ) {
|
||||
$data = @unserialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.
|
||||
if ( false !== $data ) {
|
||||
$data = str_replace( $from, $to, $data );
|
||||
$data = serialize( $data );
|
||||
$data = serialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.
|
||||
}
|
||||
} else {
|
||||
if ( is_string( $data ) ) {
|
||||
|
@ -686,10 +675,10 @@ class MainWP_Clone_Install {
|
|||
}
|
||||
|
||||
if ( $serialised ) {
|
||||
return serialize( $data );
|
||||
return serialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.
|
||||
}
|
||||
} catch ( Exception $error ) {
|
||||
|
||||
// ok!
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue