mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-09-01 03:58:07 +08:00
Fixed: CodeFactor issues
This commit is contained in:
parent
6558bc714f
commit
d469d4c1f0
1 changed files with 90 additions and 103 deletions
|
@ -43,7 +43,7 @@ class MainWP_Backup {
|
||||||
$pid = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid';
|
$pid = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify if another backup is running, if so, return an error
|
// Verify if another backup is running, if so, return an error.
|
||||||
$files = glob( $backupdir . '*.pid' );
|
$files = glob( $backupdir . '*.pid' );
|
||||||
foreach ( $files as $file ) {
|
foreach ( $files as $file ) {
|
||||||
if ( basename( $file ) == basename( $pid ) ) {
|
if ( basename( $file ) == basename( $pid ) ) {
|
||||||
|
@ -86,11 +86,11 @@ class MainWP_Backup {
|
||||||
|
|
||||||
$this->timeout = 20 * 60 * 60;
|
$this->timeout = 20 * 60 * 60;
|
||||||
$mem = '512M';
|
$mem = '512M';
|
||||||
// @codingStandardsIgnoreStart
|
// phpcs:disable
|
||||||
@ini_set( 'memory_limit', $mem );
|
@ini_set( 'memory_limit', $mem );
|
||||||
@set_time_limit( $this->timeout );
|
@set_time_limit( $this->timeout );
|
||||||
@ini_set( 'max_execution_time', $this->timeout );
|
@ini_set( 'max_execution_time', $this->timeout );
|
||||||
// @codingStandardsIgnoreEnd
|
// phpcs:enable
|
||||||
|
|
||||||
if ( null !== $this->archiver ) {
|
if ( null !== $this->archiver ) {
|
||||||
$success = $this->archiver->createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append );
|
$success = $this->archiver->createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append );
|
||||||
|
@ -112,11 +112,11 @@ class MainWP_Backup {
|
||||||
public function zipFile( $files, $archive ) {
|
public function zipFile( $files, $archive ) {
|
||||||
$this->timeout = 20 * 60 * 60;
|
$this->timeout = 20 * 60 * 60;
|
||||||
$mem = '512M';
|
$mem = '512M';
|
||||||
// @codingStandardsIgnoreStart
|
// phpcs:disable
|
||||||
@ini_set( 'memory_limit', $mem );
|
@ini_set( 'memory_limit', $mem );
|
||||||
@set_time_limit( $this->timeout );
|
@set_time_limit( $this->timeout );
|
||||||
@ini_set( 'max_execution_time', $this->timeout );
|
@ini_set( 'max_execution_time', $this->timeout );
|
||||||
// @codingStandardsIgnoreEnd
|
// phpcs:enable
|
||||||
|
|
||||||
if ( ! is_array( $files ) ) {
|
if ( ! is_array( $files ) ) {
|
||||||
$files = array( $files );
|
$files = array( $files );
|
||||||
|
@ -135,7 +135,7 @@ class MainWP_Backup {
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _zipFile( $files, $archive ) {
|
public function _zipFile( $files, $archive ) {
|
||||||
$this->zip = new ZipArchive();
|
$this->zip = new ZipArchive();
|
||||||
$this->zipArchiveFileCount = 0;
|
$this->zipArchiveFileCount = 0;
|
||||||
$this->zipArchiveSizeCount = 0;
|
$this->zipArchiveSizeCount = 0;
|
||||||
|
@ -152,18 +152,19 @@ class MainWP_Backup {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _zipFileConsole( $files, $archive ) {
|
public function _zipFileConsole( $files, $archive ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function _zipFilePcl( $files, $archive ) {
|
public function _zipFilePcl( $files, $archive ) {
|
||||||
// Zip this backup folder..
|
// Zip this backup folder.
|
||||||
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
||||||
$this->zip = new PclZip( $archive );
|
$this->zip = new PclZip( $archive );
|
||||||
|
|
||||||
$error = false;
|
$error = false;
|
||||||
foreach ( $files as $file ) {
|
foreach ( $files as $file ) {
|
||||||
if ( 0 === ( $rslt = $this->zip->add( $file, PCLZIP_OPT_REMOVE_PATH, dirname( $file ) ) ) ) {
|
$rslt = $this->zip->add( $file, PCLZIP_OPT_REMOVE_PATH, dirname( $file ) );
|
||||||
|
if ( 0 === $rslt ) {
|
||||||
$error = true;
|
$error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,45 +275,49 @@ class MainWP_Backup {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$plugins = array();
|
$plugins = array();
|
||||||
$dir = WP_CONTENT_DIR . '/plugins/';
|
$dir = WP_CONTENT_DIR . '/plugins/';
|
||||||
// @codingStandardsIgnoreStart
|
// phpcs:disable
|
||||||
$fh = @opendir( $dir );
|
$fh = @opendir( $dir );
|
||||||
while ( $entry = @readdir( $fh ) ) {
|
while ( $entry = @readdir( $fh ) ) {
|
||||||
if ( ! @is_dir( $dir . $entry ) ) {
|
if ( ! @is_dir( $dir . $entry ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( ( $entry == '.' ) || ( $entry == '..' ) ) {
|
if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$plugins[] = $entry;
|
$plugins[] = $entry;
|
||||||
}
|
}
|
||||||
@closedir( $fh );
|
@closedir( $fh );
|
||||||
// @codingStandardsIgnoreEnd
|
// phpcs:enable
|
||||||
|
|
||||||
$themes = array();
|
$themes = array();
|
||||||
$dir = WP_CONTENT_DIR . '/themes/';
|
$dir = WP_CONTENT_DIR . '/themes/';
|
||||||
// @codingStandardsIgnoreStart
|
// phpcs:disable
|
||||||
$fh = @opendir( $dir );
|
$fh = @opendir( $dir );
|
||||||
while ( $entry = @readdir( $fh ) ) {
|
while ( $entry = @readdir( $fh ) ) {
|
||||||
if ( ! @is_dir( $dir . $entry ) ) {
|
if ( ! @is_dir( $dir . $entry ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( ( $entry == '.' ) || ( $entry == '..' ) ) {
|
if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$themes[] = $entry;
|
$themes[] = $entry;
|
||||||
}
|
}
|
||||||
@closedir( $fh );
|
@closedir( $fh );
|
||||||
// @codingStandardsIgnoreEnd
|
// phpcs:enable
|
||||||
|
|
||||||
$string = base64_encode( serialize( array(
|
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
|
||||||
'siteurl' => get_option( 'siteurl' ),
|
serialize(
|
||||||
'home' => get_option( 'home' ),
|
array(
|
||||||
'abspath' => ABSPATH,
|
'siteurl' => get_option( 'siteurl' ),
|
||||||
'prefix' => $wpdb->prefix,
|
'home' => get_option( 'home' ),
|
||||||
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
|
'abspath' => ABSPATH,
|
||||||
'plugins' => $plugins,
|
'prefix' => $wpdb->prefix,
|
||||||
'themes' => $themes,
|
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
|
||||||
) ) );
|
'plugins' => $plugins,
|
||||||
|
'themes' => $themes,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$this->addFileFromStringToZip( 'clone/config.txt', $string );
|
$this->addFileFromStringToZip( 'clone/config.txt', $string );
|
||||||
}
|
}
|
||||||
|
@ -382,7 +387,8 @@ class MainWP_Backup {
|
||||||
$db_files = $this->createBackupDB( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' );
|
$db_files = $this->createBackupDB( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' );
|
||||||
$error = false;
|
$error = false;
|
||||||
foreach ( $db_files as $db_file ) {
|
foreach ( $db_files as $db_file ) {
|
||||||
if ( 0 === ( $rslt = $this->zip->add( $db_file, PCLZIP_OPT_REMOVE_PATH, dirname( $db_file ), PCLZIP_OPT_ADD_PATH, basename( WP_CONTENT_DIR ) ) ) ) {
|
$rslt = $this->zip->add( $db_file, PCLZIP_OPT_REMOVE_PATH, dirname( $db_file ), PCLZIP_OPT_ADD_PATH, basename( WP_CONTENT_DIR ) );
|
||||||
|
if ( 0 === $rslt ) {
|
||||||
$error = true;
|
$error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -399,7 +405,8 @@ class MainWP_Backup {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} elseif ( is_file( $node ) ) {
|
} elseif ( is_file( $node ) ) {
|
||||||
if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) {
|
$rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH );
|
||||||
|
if ( 0 === $rslt ) {
|
||||||
$error = true;
|
$error = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -410,21 +417,23 @@ class MainWP_Backup {
|
||||||
|
|
||||||
if ( $addConfig ) {
|
if ( $addConfig ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$string = base64_encode( serialize( array(
|
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
|
||||||
'siteurl' => get_option( 'siteurl' ),
|
serialize(
|
||||||
'home' => get_option( 'home' ),
|
array(
|
||||||
'abspath' => ABSPATH,
|
'siteurl' => get_option( 'siteurl' ),
|
||||||
'prefix' => $wpdb->prefix,
|
'home' => get_option( 'home' ),
|
||||||
'lang' => WPLANG,
|
'abspath' => ABSPATH,
|
||||||
) ) );
|
'prefix' => $wpdb->prefix,
|
||||||
|
'lang' => WPLANG,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$this->addFileFromStringToPCLZip( 'clone/config.txt', $string, $filepath );
|
$this->addFileFromStringToPCLZip( 'clone/config.txt', $string, $filepath );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $error ) {
|
if ( $error ) {
|
||||||
// @codingStandardsIgnoreStart
|
@unlink( $filepath ); // phpcs:ignore
|
||||||
@unlink( $filepath );
|
|
||||||
// @codingStandardsIgnoreEnd
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -432,7 +441,7 @@ class MainWP_Backup {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function copy_dir( $nodes, $excludes, $backupfolder, $excludenonwp, $root ) {
|
public function copy_dir( $nodes, $excludes, $backupfolder, $excludenonwp, $root ) {
|
||||||
if ( ! is_array( $nodes ) ) {
|
if ( ! is_array( $nodes ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -447,9 +456,7 @@ class MainWP_Backup {
|
||||||
if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
|
if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
|
||||||
if ( is_dir( $node ) ) {
|
if ( is_dir( $node ) ) {
|
||||||
if ( ! file_exists( str_replace( ABSPATH, $backupfolder, $node ) ) ) {
|
if ( ! file_exists( str_replace( ABSPATH, $backupfolder, $node ) ) ) {
|
||||||
// @codingStandardsIgnoreStart
|
@mkdir( str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore
|
||||||
@mkdir( str_replace( ABSPATH, $backupfolder, $node ) );
|
|
||||||
// @codingStandardsIgnoreEnd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' );
|
$newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' );
|
||||||
|
@ -460,25 +467,22 @@ class MainWP_Backup {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @codingStandardsIgnoreStart
|
@copy( $node, str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore
|
||||||
@copy( $node, str_replace( ABSPATH, $backupfolder, $node ) );
|
|
||||||
// @codingStandardsIgnoreEnd
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) {
|
public function createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) {
|
||||||
// Create backup folder
|
// Create backup folder.
|
||||||
$backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR;
|
$backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR;
|
||||||
// @codingStandardsIgnoreStart
|
|
||||||
@mkdir( $backupFolder );
|
|
||||||
// @codingStandardsIgnoreEnd
|
|
||||||
|
|
||||||
// Create DB backup
|
@mkdir( $backupFolder ); // phpcs:ignore
|
||||||
|
|
||||||
|
// Create DB backup.
|
||||||
$db_files = $this->createBackupDB( $backupFolder . 'dbBackup' );
|
$db_files = $this->createBackupDB( $backupFolder . 'dbBackup' );
|
||||||
|
|
||||||
// Copy installation to backup folder
|
// Copy installation to backup folder.
|
||||||
$nodes = glob( ABSPATH . '*' );
|
$nodes = glob( ABSPATH . '*' );
|
||||||
if ( ! $includeCoreFiles ) {
|
if ( ! $includeCoreFiles ) {
|
||||||
$coreFiles = array(
|
$coreFiles = array(
|
||||||
|
@ -520,33 +524,35 @@ class MainWP_Backup {
|
||||||
unset( $coreFiles );
|
unset( $coreFiles );
|
||||||
}
|
}
|
||||||
$this->copy_dir( $nodes, $excludes, $backupFolder, $excludenonwp, true );
|
$this->copy_dir( $nodes, $excludes, $backupFolder, $excludenonwp, true );
|
||||||
// to fix bug wrong folder
|
|
||||||
// @codingStandardsIgnoreStart
|
|
||||||
|
|
||||||
foreach ( $db_files as $db_file ) {
|
foreach ( $db_files as $db_file ) {
|
||||||
@copy( $db_file, $backupFolder . basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) );
|
@copy( $db_file, $backupFolder . basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); // phpcs:ignore
|
||||||
@unlink( $db_file );
|
@unlink( $db_file ); // phpcs:ignore
|
||||||
}
|
}
|
||||||
// @codingStandardsIgnoreEnd
|
|
||||||
unset( $nodes );
|
unset( $nodes );
|
||||||
|
|
||||||
// Zip this backup folder..
|
// Zip this backup folder.
|
||||||
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
||||||
$this->zip = new PclZip( $filepath );
|
$this->zip = new PclZip( $filepath );
|
||||||
$this->zip->create( $backupFolder, PCLZIP_OPT_REMOVE_PATH, $backupFolder );
|
$this->zip->create( $backupFolder, PCLZIP_OPT_REMOVE_PATH, $backupFolder );
|
||||||
if ( $addConfig ) {
|
if ( $addConfig ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$string = base64_encode( serialize( array(
|
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
|
||||||
'siteurl' => get_option( 'siteurl' ),
|
serialize(
|
||||||
'home' => get_option( 'home' ),
|
array(
|
||||||
'abspath' => ABSPATH,
|
'siteurl' => get_option( 'siteurl' ),
|
||||||
'prefix' => $wpdb->prefix,
|
'home' => get_option( 'home' ),
|
||||||
'lang' => WPLANG,
|
'abspath' => ABSPATH,
|
||||||
) ) );
|
'prefix' => $wpdb->prefix,
|
||||||
|
'lang' => WPLANG,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$this->addFileFromStringToPCLZip( 'clone/config.txt', $string, $filepath );
|
$this->addFileFromStringToPCLZip( 'clone/config.txt', $string, $filepath );
|
||||||
}
|
}
|
||||||
// Remove backup folder
|
// Remove backup folder.
|
||||||
MainWP_Helper::delete_dir( $backupFolder );
|
MainWP_Helper::delete_dir( $backupFolder );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -600,7 +606,8 @@ class MainWP_Backup {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} elseif ( is_file( $node ) ) {
|
} elseif ( is_file( $node ) ) {
|
||||||
if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) {
|
$rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH );
|
||||||
|
if ( 0 === $rslt ) {
|
||||||
$error = true;
|
$error = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -611,7 +618,7 @@ class MainWP_Backup {
|
||||||
return ! $error;
|
return ! $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFileFromStringToZip( $file, $string ) {
|
public function addFileFromStringToZip( $file, $string ) {
|
||||||
return $this->zip->addFromString( $file, $string );
|
return $this->zip->addFromString( $file, $string );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,9 +628,12 @@ class MainWP_Backup {
|
||||||
$tmpfilename = dirname( $filepath ) . '/' . basename( $file );
|
$tmpfilename = dirname( $filepath ) . '/' . basename( $file );
|
||||||
if ( false !== file_put_contents( $tmpfilename, $string ) ) {
|
if ( false !== file_put_contents( $tmpfilename, $string ) ) {
|
||||||
$this->zip->delete( PCLZIP_OPT_BY_NAME, $file );
|
$this->zip->delete( PCLZIP_OPT_BY_NAME, $file );
|
||||||
$add = $this->zip->add( $tmpfilename,
|
$add = $this->zip->add(
|
||||||
PCLZIP_OPT_REMOVE_PATH, dirname( $filepath ),
|
$tmpfilename,
|
||||||
PCLZIP_OPT_ADD_PATH, $localpath
|
PCLZIP_OPT_REMOVE_PATH,
|
||||||
|
dirname( $filepath ),
|
||||||
|
PCLZIP_OPT_ADD_PATH,
|
||||||
|
$localpath
|
||||||
);
|
);
|
||||||
unlink( $tmpfilename );
|
unlink( $tmpfilename );
|
||||||
if ( ! empty( $add ) ) {
|
if ( ! empty( $add ) ) {
|
||||||
|
@ -637,11 +647,9 @@ class MainWP_Backup {
|
||||||
protected $gcCnt = 0;
|
protected $gcCnt = 0;
|
||||||
protected $testContent;
|
protected $testContent;
|
||||||
|
|
||||||
function addFileToZip( $path, $zipEntryName ) {
|
public function addFileToZip( $path, $zipEntryName ) {
|
||||||
if ( time() - $this->lastRun > 20 ) {
|
if ( time() - $this->lastRun > 20 ) {
|
||||||
// @codingStandardsIgnoreStart
|
@set_time_limit( $this->timeout ); // phpcs:ignore
|
||||||
@set_time_limit( $this->timeout );
|
|
||||||
// @codingStandardsIgnoreEnd
|
|
||||||
$this->lastRun = time();
|
$this->lastRun = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,18 +657,9 @@ class MainWP_Backup {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this would fail with status ZIPARCHIVE::ER_OPEN
|
|
||||||
// after certain number of files is added since
|
|
||||||
// ZipArchive internally stores the file descriptors of all the
|
|
||||||
// added files and only on close writes the contents to the ZIP file
|
|
||||||
// see: http://bugs.php.net/bug.php?id=40494
|
|
||||||
// and: http://pecl.php.net/bugs/bug.php?id=9443
|
|
||||||
// return $zip->addFile( $path, $zipEntryName );
|
|
||||||
|
|
||||||
$this->zipArchiveSizeCount += filesize( $path );
|
$this->zipArchiveSizeCount += filesize( $path );
|
||||||
$this->gcCnt ++;
|
$this->gcCnt ++;
|
||||||
|
|
||||||
// 5 mb limit!
|
|
||||||
if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) {
|
if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) {
|
||||||
$this->zipArchiveFileCount ++;
|
$this->zipArchiveFileCount ++;
|
||||||
$added = $this->zip->addFile( $path, $zipEntryName );
|
$added = $this->zip->addFile( $path, $zipEntryName );
|
||||||
|
@ -675,30 +674,25 @@ class MainWP_Backup {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->gcCnt > 20 ) {
|
if ( $this->gcCnt > 20 ) {
|
||||||
// @codingStandardsIgnoreStart
|
|
||||||
if ( function_exists( 'gc_enable' ) ) {
|
if ( function_exists( 'gc_enable' ) ) {
|
||||||
@gc_enable();
|
@gc_enable(); // phpcs:ignore
|
||||||
}
|
}
|
||||||
if ( function_exists( 'gc_collect_cycles' ) ) {
|
if ( function_exists( 'gc_collect_cycles' ) ) {
|
||||||
@gc_collect_cycles();
|
@gc_collect_cycles(); // phpcs:ignore
|
||||||
}
|
}
|
||||||
// @codingStandardsIgnoreEnd
|
|
||||||
$this->gcCnt = 0;
|
$this->gcCnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Over limits?
|
if ( ( ( $this->file_descriptors > 0 ) && ( $this->zipArchiveFileCount > $this->file_descriptors ) ) ) {
|
||||||
if ( ( ( $this->file_descriptors > 0 ) && ( $this->zipArchiveFileCount > $this->file_descriptors ) ) ) { // || $this->zipArchiveSizeCount >= (31457280 * 2))
|
|
||||||
$this->zip->close();
|
$this->zip->close();
|
||||||
$this->zip = null;
|
$this->zip = null;
|
||||||
unset( $this->zip );
|
unset( $this->zip );
|
||||||
// @codingStandardsIgnoreStart
|
|
||||||
if ( function_exists( 'gc_enable' ) ) {
|
if ( function_exists( 'gc_enable' ) ) {
|
||||||
@gc_enable();
|
@gc_enable(); // phpcs:ignore
|
||||||
}
|
}
|
||||||
if ( function_exists( 'gc_collect_cycles' ) ) {
|
if ( function_exists( 'gc_collect_cycles' ) ) {
|
||||||
@gc_collect_cycles();
|
@gc_collect_cycles(); // phpcs:ignore
|
||||||
}
|
}
|
||||||
// @codingStandardsIgnoreEnd
|
|
||||||
$this->zip = new ZipArchive();
|
$this->zip = new ZipArchive();
|
||||||
$this->zip->open( $this->zipArchiveFileName );
|
$this->zip->open( $this->zipArchiveFileName );
|
||||||
$this->zipArchiveFileCount = 0;
|
$this->zipArchiveFileCount = 0;
|
||||||
|
@ -714,18 +708,15 @@ class MainWP_Backup {
|
||||||
|
|
||||||
public function createBackupDB( $filepath_prefix, $archiveExt = false, &$archiver = null ) {
|
public function createBackupDB( $filepath_prefix, $archiveExt = false, &$archiver = null ) {
|
||||||
$timeout = 20 * 60 * 60;
|
$timeout = 20 * 60 * 60;
|
||||||
// @codingStandardsIgnoreStart
|
@set_time_limit( $timeout ); // phpcs:ignore
|
||||||
@set_time_limit( $timeout );
|
@ini_set( 'max_execution_time', $timeout ); // phpcs:ignore
|
||||||
@ini_set( 'max_execution_time', $timeout );
|
|
||||||
$mem = '512M';
|
$mem = '512M';
|
||||||
@ini_set( 'memory_limit', $mem );
|
@ini_set( 'memory_limit', $mem ); // phpcs:ignore
|
||||||
// @codingStandardsIgnoreEnd
|
|
||||||
|
|
||||||
/** @var $wpdb wpdb */
|
/** @var $wpdb wpdb */
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$db_files = array();
|
$db_files = array();
|
||||||
// Get all the tables
|
|
||||||
$tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N );
|
$tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N );
|
||||||
foreach ( $tables_db as $curr_table ) {
|
foreach ( $tables_db as $curr_table ) {
|
||||||
if ( null !== $archiver ) {
|
if ( null !== $archiver ) {
|
||||||
|
@ -739,17 +730,13 @@ class MainWP_Backup {
|
||||||
if ( file_exists( $currentfile ) ) {
|
if ( file_exists( $currentfile ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$fh = fopen( $currentfile . '.tmp', 'w' ); // or error;
|
$fh = fopen( $currentfile . '.tmp', 'w' );
|
||||||
|
|
||||||
fwrite( $fh, "\n\n" . 'DROP TABLE IF EXISTS ' . $table . ';' );
|
fwrite( $fh, "\n\n" . 'DROP TABLE IF EXISTS ' . $table . ';' );
|
||||||
// todo fix this
|
|
||||||
// $table_create = $wpdb->get_row( $wpdb->prepare( 'SHOW CREATE TABLE %s', $table ), ARRAY_N );
|
|
||||||
$table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N );
|
$table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N );
|
||||||
fwrite( $fh, "\n" . $table_create[1] . ";\n\n" );
|
fwrite( $fh, "\n" . $table_create[1] . ";\n\n" );
|
||||||
|
|
||||||
// @codingStandardsIgnoreStart
|
$rows = @MainWP_Child_DB::_query( 'SELECT * FROM ' . $table, $wpdb->dbh ); // phpcs:ignore
|
||||||
$rows = @MainWP_Child_DB::_query( 'SELECT * FROM ' . $table, $wpdb->dbh );
|
|
||||||
// @codingStandardsIgnoreEnd
|
|
||||||
|
|
||||||
if ( $rows ) {
|
if ( $rows ) {
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue