Fixed: CodeFactor issues

This commit is contained in:
Bogdan Rapaić 2020-04-17 19:30:50 +02:00 committed by GitHub
parent b0aea12aab
commit 15c17d71c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,5 @@
<?php
/*
*
/**
* Credits
*
* Plugin-Name: WP Staging
@ -12,16 +10,14 @@
*
* The code is used for the MainWP Staging Extension
* Extension URL: https://mainwp.com/extension/staging/
*
*/
*/
class MainWP_Child_Staging {
public static $instance = null;
public $is_plugin_installed = false;
static function Instance() {
public static function Instance() {
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Staging();
}
@ -30,7 +26,7 @@ class MainWP_Child_Staging {
public function __construct() {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'wp-staging/wp-staging.php' ) && defined('WPSTG_PLUGIN_DIR') ) {
if ( is_plugin_active( 'wp-staging/wp-staging.php' ) && defined( 'WPSTG_PLUGIN_DIR' ) ) {
$this->is_plugin_installed = true;
} elseif ( is_plugin_active( 'wp-staging-pro/wp-staging-pro.php' ) ) {
$this->is_plugin_installed = true;
@ -45,7 +41,7 @@ class MainWP_Child_Staging {
public function init() {
if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' ) {
if ( 'Y' !== get_option( 'mainwp_wp_staging_ext_enabled' ) ) {
return;
}
@ -53,7 +49,7 @@ class MainWP_Child_Staging {
return;
}
if ( get_option( 'mainwp_wp_staging_hide_plugin' ) === 'hide' ) {
if ( 'hide' === get_option( 'mainwp_wp_staging_hide_plugin' ) ) {
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
@ -66,97 +62,98 @@ class MainWP_Child_Staging {
try {
$information['syncWPStaging'] = $this->get_sync_data();
} catch ( Exception $e ) {
// do not exit
// ok!
}
}
return $information;
}
// ok
public function get_sync_data() {
return $this->get_overview();
}
public function action() {
if ( ! $this->is_plugin_installed ) {
MainWP_Helper::write( array( 'error' => 'Please install WP Staging plugin on child website' ) );
MainWP_Helper::write( array( 'error' => __( 'Please install WP Staging plugin on child website', 'mainwp-child' ) ) );
}
if ( ! class_exists( 'WPStaging\WPStaging' ) ) {
require_once WPSTG_PLUGIN_DIR . 'apps/Core/WPStaging.php';
}
\WPStaging\WPStaging::getInstance();
$information = array();
if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' ) {
\WPStaging\WPStaging::getInstance();
$information = array();
if ( 'Y' !== get_option( 'mainwp_wp_staging_ext_enabled' ) ) {
MainWP_Helper::update_option( 'mainwp_wp_staging_ext_enabled', 'Y', 'yes' );
}
if ( isset( $_POST['mwp_action'] ) ) {
switch ( $_POST['mwp_action'] ) {
case 'set_showhide':
$information = $this->set_showhide();
$information = $this->set_showhide();
break;
case 'save_settings':
$information = $this->save_settings();
$information = $this->save_settings();
break;
case 'get_overview':
$information = $this->get_overview();
$information = $this->get_overview();
break;
case 'get_scan':
$information = $this->get_scan();
$information = $this->get_scan();
break;
case 'check_disk_space':
$information = $this->ajaxCheckFreeSpace();
$information = $this->ajaxCheckFreeSpace();
break;
case 'check_clone':
$information = $this->ajaxCheckCloneName();
$information = $this->ajaxCheckCloneName();
break;
case 'start_clone':
$information = $this->ajaxStartClone();
$information = $this->ajaxStartClone();
break;
case 'clone_database':
$information = $this->ajaxCloneDatabase();
$information = $this->ajaxCloneDatabase();
break;
case 'prepare_directories':
$information = $this->ajaxPrepareDirectories();
$information = $this->ajaxPrepareDirectories();
break;
case 'copy_files':
$information = $this->ajaxCopyFiles();
$information = $this->ajaxCopyFiles();
break;
case 'replace_data':
$information = $this->ajaxReplaceData();
$information = $this->ajaxReplaceData();
break;
case 'clone_finish':
$information = $this->ajaxFinish();
$information = $this->ajaxFinish();
break;
case 'delete_confirmation':
$information = $this->ajaxDeleteConfirmation();
$information = $this->ajaxDeleteConfirmation();
break;
case 'delete_clone':
$information = $this->ajaxDeleteClone();
$information = $this->ajaxDeleteClone();
break;
case 'cancel_clone':
$information = $this->ajaxCancelClone();
$information = $this->ajaxCancelClone();
break;
case 'staging_update':
$information = $this->ajaxUpdateProcess();
$information = $this->ajaxUpdateProcess();
break;
case 'cancel_update':
$information = $this->ajaxCancelUpdate();
$information = $this->ajaxCancelUpdate();
break;
}
}
MainWP_Helper::write( $information );
}
function set_showhide() {
public function set_showhide() {
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
MainWP_Helper::update_option( 'mainwp_wp_staging_hide_plugin', $hide, 'yes' );
$information['result'] = 'SUCCESS';
return $information;
}
function save_settings() {
public function save_settings() {
$settings = $_POST['settings'];
$filters = array(
'queryLimit',
@ -167,21 +164,19 @@ class MainWP_Child_Staging {
'disableAdminLogin',
'querySRLimit',
'maxFileSize',
// 'wpSubDirectory', // removed
'debugMode',
'unInstallOnDelete',
'checkDirectorySize',
'optimizer',
// 'loginSlug' // removed
);
$save_fields = array();
foreach ( $filters as $field ) {
if ( isset($settings[ $field ]) ) {
if ( isset( $settings[ $field ] ) ) {
$save_fields[ $field ] = $settings[ $field ];
}
}
update_option('wpstg_settings', $save_fields );
update_option( 'wpstg_settings', $save_fields );
return array( 'result' => 'success' );
}
@ -193,15 +188,13 @@ class MainWP_Child_Staging {
}
public function get_scan() {
// Scan
$scan = new WPStaging\Backend\Modules\Jobs\Scan();
$scan->start();
// Get Options
$options = $scan->getOptions();
$return = array(
'options' => serialize($options),
'options' => serialize( $options ),
'directoryListing' => $scan->directoryListing(),
'prefix' => WPStaging\WPStaging::getTablePrefix(),
);
@ -214,7 +207,6 @@ class MainWP_Child_Staging {
$cloneNameLength = strlen( $cloneName );
$clones = get_option( 'wpstg_existing_clones_beta', array() );
// Check clone name length
if ( $cloneNameLength < 1 || $cloneNameLength > 16 ) {
echo array(
'status' => 'failed',
@ -232,7 +224,7 @@ class MainWP_Child_Staging {
public function ajaxStartClone() {
$this->url = ''; // to fix warning
$this->url = '';
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
if ( ! $cloning->save() ) {
@ -246,7 +238,6 @@ class MainWP_Child_Staging {
}
public function ajaxCloneDatabase() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
@ -256,7 +247,6 @@ class MainWP_Child_Staging {
* Ajax Prepare Directories (get listing of files)
*/
public function ajaxPrepareDirectories() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
@ -266,7 +256,6 @@ class MainWP_Child_Staging {
* Ajax Clone Files
*/
public function ajaxCopyFiles() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
@ -284,11 +273,10 @@ class MainWP_Child_Staging {
* Ajax Finish
*/
public function ajaxFinish() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
$this->url = ''; // to fix warning
$this->url = '';
$return = $cloning->start();
$return->blogInfoName = get_bloginfo('name');
$return->blogInfoName = get_bloginfo( 'name' );
return $return;
}
@ -297,7 +285,6 @@ class MainWP_Child_Staging {
* Ajax Delete Confirmation
*/
public function ajaxDeleteConfirmation() {
$delete = new WPStaging\Backend\Modules\Jobs\Delete();
$delete->setData();
$clone = $delete->getClone();
@ -305,6 +292,7 @@ class MainWP_Child_Staging {
'clone' => $clone,
'deleteTables' => $delete->getTables(),
);
return $result;
}
@ -312,8 +300,8 @@ class MainWP_Child_Staging {
* Delete clone
*/
public function ajaxDeleteClone() {
$delete = new WPStaging\Backend\Modules\Jobs\Delete();
return $delete->start();
}
@ -322,16 +310,17 @@ class MainWP_Child_Staging {
*/
public function ajaxCancelClone() {
$cancel = new WPStaging\Backend\Modules\Jobs\Cancel();
return $cancel->start();
}
public function ajaxCancelUpdate() {
$cancel = new WPStaging\Backend\Modules\Jobs\CancelUpdate();
return $cancel->start();
}
public function ajaxUpdateProcess() {
$cloning = new WPStaging\Backend\Modules\Jobs\Updating();
if ( ! $cloning->save() ) {
@ -348,7 +337,6 @@ class MainWP_Child_Staging {
return $this->hasFreeDiskSpace();
}
// from wp-staging plugin
public function hasFreeDiskSpace() {
if ( ! function_exists( 'disk_free_space' ) ) {
return null;
@ -357,19 +345,18 @@ class MainWP_Child_Staging {
if ( false === $freeSpace ) {
$data = array(
'freespace' => false,
'usedspace' => $this->formatSize($this->getDirectorySizeInclSubdirs(ABSPATH)),
'usedspace' => $this->formatSize( $this->getDirectorySizeInclSubdirs( ABSPATH ) ),
);
return $data;
}
$data = array(
'freespace' => $this->formatSize($freeSpace),
'usedspace' => $this->formatSize($this->getDirectorySizeInclSubdirs(ABSPATH)),
'freespace' => $this->formatSize( $freeSpace ),
'usedspace' => $this->formatSize( $this->getDirectorySizeInclSubdirs( ABSPATH ) ),
);
return $data;
}
// from wp-staging plugin
function getDirectorySizeInclSubdirs( $dir ) {
public function getDirectorySizeInclSubdirs( $dir ) {
$size = 0;
foreach ( glob( rtrim( $dir, '/' ) . '/*', GLOB_NOSORT ) as $each ) {
$size += is_file( $each ) ? filesize( $each ) : $this->getDirectorySizeInclSubdirs( $each );
@ -377,7 +364,6 @@ class MainWP_Child_Staging {
return $size;
}
// from wp-staging plugin
public function formatSize( $bytes, $precision = 2 ) {
if ( (float) $bytes < 1 ) {
return '';
@ -386,10 +372,10 @@ class MainWP_Child_Staging {
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
$bytes = (float) $bytes;
$base = log($bytes) / log(1000); // 1024 would be for MiB KiB etc
$pow = pow(1000, $base - floor($base)); // Same rule for 1000
$base = log( $bytes ) / log( 1000 );
$pow = pow( 1000, $base - floor( $base ) );
return round($pow, $precision) . ' ' . $units[ (int) floor($base) ];
return round( $pow, $precision ) . ' ' . $units[ (int) floor( $base ) ];
}
@ -413,12 +399,13 @@ class MainWP_Child_Staging {
}
}
function hide_update_notice( $slugs ) {
public function hide_update_notice( $slugs ) {
$slugs[] = 'wp-staging/wp-staging.php';
return $slugs;
}
function remove_update_nag( $value ) {
public function remove_update_nag( $value ) {
if ( isset( $_POST['mainwpsignature'] ) ) {
return $value;
}
@ -438,4 +425,3 @@ class MainWP_Child_Staging {
return $value;
}
}