Skip to content

Commit

Permalink
Deploying version 2.6.10
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedTheGeek committed Feb 8, 2024
1 parent 988f4c0 commit f0bd63f
Show file tree
Hide file tree
Showing 150 changed files with 3,138 additions and 2,023 deletions.
6 changes: 3 additions & 3 deletions class/Common/Filesystem/RecursiveScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private function get_resume_position($abs_path)
private function get_scandir_manifest()
{
$file_data = $this->filesystem->get_contents($this->get_scandir_manifest_filename());
return unserialize($file_data);
return json_decode($file_data, true);
}

/**
Expand All @@ -430,9 +430,9 @@ private function get_scandir_manifest()
private function save_manifest()
{
$manifest_filename = $this->get_scandir_manifest_filename();
$result = $this->filesystem->put_contents($manifest_filename, serialize($this->manifest));
$result = $this->filesystem->put_contents($manifest_filename, json_encode($this->manifest));

if (!$result) {
if ( ! $result) {
$this->transfer_utils->catch_general_error('Could not create scandir manifest.');
}
}
Expand Down
24 changes: 0 additions & 24 deletions class/Common/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,30 +170,6 @@ function array_to_multipart($data)
return $result;
}

/**
* Convert file data, including contents, into a serialized array
*
* @param $file
*
* @return bool|string
*/
function file_to_serialized($file)
{
if (false == file_exists($file)) {
return false;
}

$filetype = wp_check_filetype($file);
$contents = file_get_contents($file);

$file_details = [
'name' => basename($file),
'file_type' => $filetype['type'],
'contents' => $contents,
];

return serialize($file_details);
}

/**
* Check for download
Expand Down
38 changes: 3 additions & 35 deletions class/Common/Http/RemotePost.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ public function handle_remote_post_responses($response, $url, $scope, $expecting
return $this->handle_empty_response_body($response, $url, $scope);
}

$decoded_body = false;
if (is_serialized($response['body'])) {
$decoded_body = Util::unserialize($response['body']);
} elseif (Util::is_json($response['body'])) {
if (Util::is_json($response['body'])) {
$decoded_body = json_decode($response['body'], true);
} else {
$decoded_body =
Expand Down Expand Up @@ -227,31 +224,6 @@ public function handle_remote_post_responses($response, $url, $scope, $expecting
}
}

// if ($expecting_serial && false === is_serialized($response['body'])) {
// if (0 === strpos($url, 'https://') && 'ajax_verify_connection_to_remote_site' == $scope) {
// return true;
// }
// $this->error_log->setError(__('There was a problem with the AJAX request, we were expecting a serialized response, instead we received:<br />', 'wp-migrate-db') . esc_html($response['body']));
// $this->error_log->log_error($this->error_log->getError(), $response);
//
// return false;
//
// } elseif ($expecting_serial && ('ajax_verify_connection_to_remote_site' == $scope || 'ajax_copy_licence_to_remote_site' == $scope)) {
//
// $unserialized_response = Util::unserialize($response['body'], __METHOD__);
//
// if (false !== $unserialized_response && isset($unserialized_response['error']) && '1' == $unserialized_response['error'] && 0 === strpos($url, 'https://')) {
//
// if (stristr($unserialized_response['message'], 'Invalid content verification signature')) {
//
// //Check if remote address returned is the same as what was requested. Apache sometimes returns a random HTTPS site.
// if (false === strpos($unserialized_response['message'], sprintf('Remote URL: %s', $state_data['url']))) {
// return true;
// }
// }
// }
// }

return true;
}

Expand Down Expand Up @@ -452,15 +424,11 @@ public function verify_remote_post_response($response)
return $result;
}

if (Util::is_json($response)) {
return json_decode($response, true);
}

if (is_wp_error($response)) {
return $this->end_ajax($response);
}

if (!is_serialized(trim($response))) {
if ( ! Util::is_json($response)) {
$return = array('wpmdb_error' => 1, 'body' => $response);
$error_msg = 'Failed as the response is not serialized string (#115mf)';
$this->error_log->log_error($error_msg, $response);
Expand All @@ -469,7 +437,7 @@ public function verify_remote_post_response($response)
return $result;
}

$response = unserialize(trim($response));
$response = json_decode($response, true);

if (isset($response['wpmdb_error'])) {
$this->error_log->log_error($response['wpmdb_error'], $response);
Expand Down
30 changes: 24 additions & 6 deletions class/Common/Http/Scramble.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace DeliciousBrains\WPMDB\Common\Http;

use DeliciousBrains\WPMDB\Common\Util\Util;

class Scramble
{

Expand All @@ -19,7 +21,7 @@ function scramble($input)
}

if (!\is_string($input) && !\is_bool($input)) {
$input = serialize($input);
$input = json_encode($input);
}

return 'WPMDB-SCRAMBLED' . str_replace(array('/', '\\'), array('%#047%', '%#092%'), str_rot13($input));
Expand All @@ -28,22 +30,38 @@ function scramble($input)
/**
* Unscramble string.
*
* @param mixed $input String to be unscrambled.
* @param mixed $input String to be unscrambled.
* @param bool $doing_json Are we already processing some JSON?
*
* @return mixed
*/
function unscramble($input)
function unscramble($input, $doing_json = false)
{
if (!empty($input) && is_string($input)) {
if (0 === strpos($input, 'WPMDB-SCRAMBLED')) {
if ( ! empty($input) && is_string($input) && (false !== strpos($input, 'WPMDB-SCRAMBLED') || $doing_json)) {
// We know we have scrambled data, but was it JSON encoded afterwards?
if (Util::is_json($input)) {
$input = json_decode($input, true);
if (is_array($input)) {
foreach ($input as $key => $val) {
$input[$key] = $this->unscramble($val, true);
}
} else {
$input = $this->unscramble($input, true);
}

// Re-encode just once when finished doing JSON.
if ( ! $doing_json) {
$input = json_encode($input);
}
} elseif (0 === strpos($input, 'WPMDB-SCRAMBLED')) {
// If the string begins with WPMDB-SCRAMBED we can unscramble.
// As the scrambled string could be multiple segments of scrambling (from stow) we remove indicators in one go.
$input = str_replace(array('WPMDB-SCRAMBLED', '%#047%', '%#092%'), array('', '/', '\\'), $input);
$input = str_rot13($input);
} elseif (false !== strpos($input, 'WPMDB-SCRAMBLED')) {
// Starts with non-scrambled data (error), but with scrambled string following.
$pos = strpos($input, 'WPMDB-SCRAMBLED');
$input = substr($input, 0, $pos) . $this->unscramble(substr($input, $pos));
$input = substr($input, 0, $pos) . $this->unscramble(substr($input, $pos), $doing_json);
}
}

Expand Down
4 changes: 4 additions & 0 deletions class/Common/MF/MediaFilesLocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ public function ajax_mf_transfer_files()
$count = apply_filters('wpmdbmf_file_batch_size', 1000);
$data = $this->queue_manager->list_jobs($count);

if (is_wp_error($data)) {
return $this->http->end_ajax($data);
}

$processed = $this->transfer_util->process_file_data($data);

if (empty($data)) {
Expand Down
2 changes: 1 addition & 1 deletion class/Common/Migration/FinalizeMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function ajax_finalize_migration()
)
);
$data['form_data'] = base64_encode($data['form_data']);
$data['site_details'] = base64_encode(serialize($data['site_details']));
$data['site_details'] = base64_encode(json_encode($data['site_details']));

$data['action'] = 'wpmdb_remote_finalize_migration';
$data['intent'] = 'pull';
Expand Down
2 changes: 1 addition & 1 deletion class/Common/Migration/InitiateMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected function initiatePushOrPull(
'action' => 'wpmdb_remote_initiate_migration',
'intent' => $state_data['intent'],
'form_data' => base64_encode( $state_data['form_data'] ),
'site_details' => base64_encode( serialize( $this->migration_helper->getMergedSiteDetails($state_data) ) ),
'site_details' => base64_encode( json_encode( $this->migration_helper->getMergedSiteDetails($state_data) ) ),
];

$data['sig'] = $this->http_helper->create_signature($data, $state_data['key']);
Expand Down
16 changes: 10 additions & 6 deletions class/Common/Migration/MigrationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function ajax_migrate_table()
'current_row' => 'numeric',
'form_data' => 'json',
'last_table' => 'positive_int',
'primary_keys' => 'serialized',
'primary_keys' => 'json',
'gzip' => 'int',
'nonce' => 'key',
'bottleneck' => 'positive_int',
Expand All @@ -228,6 +228,9 @@ function ajax_migrate_table()
if (!Util::is_json($_POST['form_data'])) {
$_POST['form_data'] = stripslashes($_POST['form_data']);
}
if (!Util::is_json($_POST['primary_keys'])) {
$_POST['primary_keys'] = stripslashes($_POST['primary_keys']);
}

$state_data = Persistence::setPostData($key_rules, __METHOD__);

Expand All @@ -252,9 +255,10 @@ function ajax_migrate_table()
$return = $this->handle_table_backup();
}

$decoded = json_decode($return, true);

return $this->http->end_ajax(maybe_unserialize($return));
if (Util::is_json($return)) {
$return = json_decode($return, true);
}
return $this->http->end_ajax($return);
}

// Pull and push need to be handled differently for obvious reasons,
Expand Down Expand Up @@ -336,7 +340,7 @@ function ajax_migrate_table()

$sig_data = $data;
unset($sig_data['find_replace_pairs'], $sig_data['form_data'], $sig_data['source_prefix'], $sig_data['destination_prefix']);
$data['find_replace_pairs'] = base64_encode(serialize($data['find_replace_pairs']));
$data['find_replace_pairs'] = base64_encode(json_encode($data['find_replace_pairs']));
$data['form_data'] = base64_encode($data['form_data']);
$data['primary_keys'] = base64_encode($data['primary_keys']);
$data['source_prefix'] = base64_encode($data['source_prefix']);
Expand All @@ -345,7 +349,7 @@ function ajax_migrate_table()
$data['sig'] = $this->http_helper->create_signature($sig_data, $state_data['key']);

// Don't add to computed signature
$data['site_details'] = base64_encode(serialize($state_data['site_details']));
$data['site_details'] = base64_encode(json_encode($state_data['site_details']));
$ajax_url = $this->util->ajax_url();
$response = $this->remote_post->post($ajax_url, $data, __FUNCTION__);

Expand Down
52 changes: 39 additions & 13 deletions class/Common/Queue/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,37 @@
namespace DeliciousBrains\WPMDB\Common\Queue;


use WP_Error;
use wpdb;

class Connection extends Connections\DatabaseConnection {

public function __construct( $wpdb = null, $prefix = null ) {
if ( null === $wpdb ) {
$wpdb = $GLOBALS['wpdb'];
}
if ( null === $prefix ) {
$prefix = $GLOBALS['wpmdbpro']->get( 'temp_prefix' );
}
/**
* DatabaseQueue constructor.
*
* @param wpdb $wpdb WP database object, default global object.
* @param array $allowed_job_classes Job classes that may be handled, default any Job subclass.
* @param string $prefix Table prefix, default temp_prefix.
*/
public function __construct(wpdb $wpdb = null, $allowed_job_classes = [], $prefix = null)
{
if (null === $wpdb) {
$wpdb = $GLOBALS['wpdb'];
}
if (null === $prefix) {
$prefix = $GLOBALS['wpmdbpro']->get('temp_prefix');
}

$this->database = $wpdb;
$this->jobs_table = $prefix . 'queue_jobs';
$this->failures_table = $prefix . 'queue_failures';
}
// We should be able to call parent to set database
// and allowed_job_classes, but unit test setup is broken
// and throws a wobbly in Mockery. Yay, mocks. 😞
// parent::__construct($wpdb, $allowed_job_classes);
$this->database = $wpdb;
$this->allowed_job_classes = $allowed_job_classes;

$this->jobs_table = $prefix . 'queue_jobs';
$this->failures_table = $prefix . 'queue_failures';
}

/**
* Get list of jobs in queue
Expand All @@ -25,7 +42,7 @@ public function __construct( $wpdb = null, $prefix = null ) {
* @param int $offset
* @param bool $raw if true, method will return serialized instead of instantiated objects
*
* @return array
* @return array|WP_Error
*/
public function list_jobs( $limit, $offset, $raw = false ) {
$offset = null === $offset ? 0 : $offset;
Expand All @@ -45,7 +62,16 @@ public function list_jobs( $limit, $offset, $raw = false ) {

$jobs = [];
foreach ( $results as $raw_job ) {
$jobs[ $raw_job->id ] = $this->vitalize_job( $raw_job );
$job = $this->vitalize_job($raw_job);

if ($job && is_a($job, Job::class)) {
$jobs[$raw_job->id] = $job;
} else {
return new WP_Error(
'invalid-queue-job',
__('An invalid item was found in the queue of files to be transferred.', 'wp-migrate-db')
);
}
}

return $jobs;
Expand Down
2 changes: 1 addition & 1 deletion class/Common/Queue/Connections/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function delete( $job );
*
* @param Job $job
*/
public function release( $job );
public function release( Job $job );

/**
* Push a job onto the failure queue.
Expand Down
Loading

0 comments on commit f0bd63f

Please sign in to comment.