Skip to content

Commit f0bd63f

Browse files
committed
Deploying version 2.6.10
1 parent 988f4c0 commit f0bd63f

File tree

150 files changed

+3138
-2023
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+3138
-2023
lines changed

class/Common/Filesystem/RecursiveScanner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ private function get_resume_position($abs_path)
421421
private function get_scandir_manifest()
422422
{
423423
$file_data = $this->filesystem->get_contents($this->get_scandir_manifest_filename());
424-
return unserialize($file_data);
424+
return json_decode($file_data, true);
425425
}
426426

427427
/**
@@ -430,9 +430,9 @@ private function get_scandir_manifest()
430430
private function save_manifest()
431431
{
432432
$manifest_filename = $this->get_scandir_manifest_filename();
433-
$result = $this->filesystem->put_contents($manifest_filename, serialize($this->manifest));
433+
$result = $this->filesystem->put_contents($manifest_filename, json_encode($this->manifest));
434434

435-
if (!$result) {
435+
if ( ! $result) {
436436
$this->transfer_utils->catch_general_error('Could not create scandir manifest.');
437437
}
438438
}

class/Common/Http/Http.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -170,30 +170,6 @@ function array_to_multipart($data)
170170
return $result;
171171
}
172172

173-
/**
174-
* Convert file data, including contents, into a serialized array
175-
*
176-
* @param $file
177-
*
178-
* @return bool|string
179-
*/
180-
function file_to_serialized($file)
181-
{
182-
if (false == file_exists($file)) {
183-
return false;
184-
}
185-
186-
$filetype = wp_check_filetype($file);
187-
$contents = file_get_contents($file);
188-
189-
$file_details = [
190-
'name' => basename($file),
191-
'file_type' => $filetype['type'],
192-
'contents' => $contents,
193-
];
194-
195-
return serialize($file_details);
196-
}
197173

198174
/**
199175
* Check for download

class/Common/Http/RemotePost.php

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ public function handle_remote_post_responses($response, $url, $scope, $expecting
178178
return $this->handle_empty_response_body($response, $url, $scope);
179179
}
180180

181-
$decoded_body = false;
182-
if (is_serialized($response['body'])) {
183-
$decoded_body = Util::unserialize($response['body']);
184-
} elseif (Util::is_json($response['body'])) {
181+
if (Util::is_json($response['body'])) {
185182
$decoded_body = json_decode($response['body'], true);
186183
} else {
187184
$decoded_body =
@@ -227,31 +224,6 @@ public function handle_remote_post_responses($response, $url, $scope, $expecting
227224
}
228225
}
229226

230-
// if ($expecting_serial && false === is_serialized($response['body'])) {
231-
// if (0 === strpos($url, 'https://') && 'ajax_verify_connection_to_remote_site' == $scope) {
232-
// return true;
233-
// }
234-
// $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']));
235-
// $this->error_log->log_error($this->error_log->getError(), $response);
236-
//
237-
// return false;
238-
//
239-
// } elseif ($expecting_serial && ('ajax_verify_connection_to_remote_site' == $scope || 'ajax_copy_licence_to_remote_site' == $scope)) {
240-
//
241-
// $unserialized_response = Util::unserialize($response['body'], __METHOD__);
242-
//
243-
// if (false !== $unserialized_response && isset($unserialized_response['error']) && '1' == $unserialized_response['error'] && 0 === strpos($url, 'https://')) {
244-
//
245-
// if (stristr($unserialized_response['message'], 'Invalid content verification signature')) {
246-
//
247-
// //Check if remote address returned is the same as what was requested. Apache sometimes returns a random HTTPS site.
248-
// if (false === strpos($unserialized_response['message'], sprintf('Remote URL: %s', $state_data['url']))) {
249-
// return true;
250-
// }
251-
// }
252-
// }
253-
// }
254-
255227
return true;
256228
}
257229

@@ -452,15 +424,11 @@ public function verify_remote_post_response($response)
452424
return $result;
453425
}
454426

455-
if (Util::is_json($response)) {
456-
return json_decode($response, true);
457-
}
458-
459427
if (is_wp_error($response)) {
460428
return $this->end_ajax($response);
461429
}
462430

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

472-
$response = unserialize(trim($response));
440+
$response = json_decode($response, true);
473441

474442
if (isset($response['wpmdb_error'])) {
475443
$this->error_log->log_error($response['wpmdb_error'], $response);

class/Common/Http/Scramble.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace DeliciousBrains\WPMDB\Common\Http;
44

5+
use DeliciousBrains\WPMDB\Common\Util\Util;
6+
57
class Scramble
68
{
79

@@ -19,7 +21,7 @@ function scramble($input)
1921
}
2022

2123
if (!\is_string($input) && !\is_bool($input)) {
22-
$input = serialize($input);
24+
$input = json_encode($input);
2325
}
2426

2527
return 'WPMDB-SCRAMBLED' . str_replace(array('/', '\\'), array('%#047%', '%#092%'), str_rot13($input));
@@ -28,22 +30,38 @@ function scramble($input)
2830
/**
2931
* Unscramble string.
3032
*
31-
* @param mixed $input String to be unscrambled.
33+
* @param mixed $input String to be unscrambled.
34+
* @param bool $doing_json Are we already processing some JSON?
3235
*
3336
* @return mixed
3437
*/
35-
function unscramble($input)
38+
function unscramble($input, $doing_json = false)
3639
{
37-
if (!empty($input) && is_string($input)) {
38-
if (0 === strpos($input, 'WPMDB-SCRAMBLED')) {
40+
if ( ! empty($input) && is_string($input) && (false !== strpos($input, 'WPMDB-SCRAMBLED') || $doing_json)) {
41+
// We know we have scrambled data, but was it JSON encoded afterwards?
42+
if (Util::is_json($input)) {
43+
$input = json_decode($input, true);
44+
if (is_array($input)) {
45+
foreach ($input as $key => $val) {
46+
$input[$key] = $this->unscramble($val, true);
47+
}
48+
} else {
49+
$input = $this->unscramble($input, true);
50+
}
51+
52+
// Re-encode just once when finished doing JSON.
53+
if ( ! $doing_json) {
54+
$input = json_encode($input);
55+
}
56+
} elseif (0 === strpos($input, 'WPMDB-SCRAMBLED')) {
3957
// If the string begins with WPMDB-SCRAMBED we can unscramble.
4058
// As the scrambled string could be multiple segments of scrambling (from stow) we remove indicators in one go.
4159
$input = str_replace(array('WPMDB-SCRAMBLED', '%#047%', '%#092%'), array('', '/', '\\'), $input);
4260
$input = str_rot13($input);
4361
} elseif (false !== strpos($input, 'WPMDB-SCRAMBLED')) {
4462
// Starts with non-scrambled data (error), but with scrambled string following.
4563
$pos = strpos($input, 'WPMDB-SCRAMBLED');
46-
$input = substr($input, 0, $pos) . $this->unscramble(substr($input, $pos));
64+
$input = substr($input, 0, $pos) . $this->unscramble(substr($input, $pos), $doing_json);
4765
}
4866
}
4967

class/Common/MF/MediaFilesLocal.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ public function ajax_mf_transfer_files()
261261
$count = apply_filters('wpmdbmf_file_batch_size', 1000);
262262
$data = $this->queue_manager->list_jobs($count);
263263

264+
if (is_wp_error($data)) {
265+
return $this->http->end_ajax($data);
266+
}
267+
264268
$processed = $this->transfer_util->process_file_data($data);
265269

266270
if (empty($data)) {

class/Common/Migration/FinalizeMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function ajax_finalize_migration()
132132
)
133133
);
134134
$data['form_data'] = base64_encode($data['form_data']);
135-
$data['site_details'] = base64_encode(serialize($data['site_details']));
135+
$data['site_details'] = base64_encode(json_encode($data['site_details']));
136136

137137
$data['action'] = 'wpmdb_remote_finalize_migration';
138138
$data['intent'] = 'pull';

class/Common/Migration/InitiateMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected function initiatePushOrPull(
212212
'action' => 'wpmdb_remote_initiate_migration',
213213
'intent' => $state_data['intent'],
214214
'form_data' => base64_encode( $state_data['form_data'] ),
215-
'site_details' => base64_encode( serialize( $this->migration_helper->getMergedSiteDetails($state_data) ) ),
215+
'site_details' => base64_encode( json_encode( $this->migration_helper->getMergedSiteDetails($state_data) ) ),
216216
];
217217

218218
$data['sig'] = $this->http_helper->create_signature($data, $state_data['key']);

class/Common/Migration/MigrationManager.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function ajax_migrate_table()
215215
'current_row' => 'numeric',
216216
'form_data' => 'json',
217217
'last_table' => 'positive_int',
218-
'primary_keys' => 'serialized',
218+
'primary_keys' => 'json',
219219
'gzip' => 'int',
220220
'nonce' => 'key',
221221
'bottleneck' => 'positive_int',
@@ -228,6 +228,9 @@ function ajax_migrate_table()
228228
if (!Util::is_json($_POST['form_data'])) {
229229
$_POST['form_data'] = stripslashes($_POST['form_data']);
230230
}
231+
if (!Util::is_json($_POST['primary_keys'])) {
232+
$_POST['primary_keys'] = stripslashes($_POST['primary_keys']);
233+
}
231234

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

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

255-
$decoded = json_decode($return, true);
256-
257-
return $this->http->end_ajax(maybe_unserialize($return));
258+
if (Util::is_json($return)) {
259+
$return = json_decode($return, true);
260+
}
261+
return $this->http->end_ajax($return);
258262
}
259263

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

337341
$sig_data = $data;
338342
unset($sig_data['find_replace_pairs'], $sig_data['form_data'], $sig_data['source_prefix'], $sig_data['destination_prefix']);
339-
$data['find_replace_pairs'] = base64_encode(serialize($data['find_replace_pairs']));
343+
$data['find_replace_pairs'] = base64_encode(json_encode($data['find_replace_pairs']));
340344
$data['form_data'] = base64_encode($data['form_data']);
341345
$data['primary_keys'] = base64_encode($data['primary_keys']);
342346
$data['source_prefix'] = base64_encode($data['source_prefix']);
@@ -345,7 +349,7 @@ function ajax_migrate_table()
345349
$data['sig'] = $this->http_helper->create_signature($sig_data, $state_data['key']);
346350

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

class/Common/Queue/Connection.php

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,37 @@
33
namespace DeliciousBrains\WPMDB\Common\Queue;
44

55

6+
use WP_Error;
7+
use wpdb;
8+
69
class Connection extends Connections\DatabaseConnection {
710

8-
public function __construct( $wpdb = null, $prefix = null ) {
9-
if ( null === $wpdb ) {
10-
$wpdb = $GLOBALS['wpdb'];
11-
}
12-
if ( null === $prefix ) {
13-
$prefix = $GLOBALS['wpmdbpro']->get( 'temp_prefix' );
14-
}
11+
/**
12+
* DatabaseQueue constructor.
13+
*
14+
* @param wpdb $wpdb WP database object, default global object.
15+
* @param array $allowed_job_classes Job classes that may be handled, default any Job subclass.
16+
* @param string $prefix Table prefix, default temp_prefix.
17+
*/
18+
public function __construct(wpdb $wpdb = null, $allowed_job_classes = [], $prefix = null)
19+
{
20+
if (null === $wpdb) {
21+
$wpdb = $GLOBALS['wpdb'];
22+
}
23+
if (null === $prefix) {
24+
$prefix = $GLOBALS['wpmdbpro']->get('temp_prefix');
25+
}
1526

16-
$this->database = $wpdb;
17-
$this->jobs_table = $prefix . 'queue_jobs';
18-
$this->failures_table = $prefix . 'queue_failures';
19-
}
27+
// We should be able to call parent to set database
28+
// and allowed_job_classes, but unit test setup is broken
29+
// and throws a wobbly in Mockery. Yay, mocks. 😞
30+
// parent::__construct($wpdb, $allowed_job_classes);
31+
$this->database = $wpdb;
32+
$this->allowed_job_classes = $allowed_job_classes;
33+
34+
$this->jobs_table = $prefix . 'queue_jobs';
35+
$this->failures_table = $prefix . 'queue_failures';
36+
}
2037

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

4663
$jobs = [];
4764
foreach ( $results as $raw_job ) {
48-
$jobs[ $raw_job->id ] = $this->vitalize_job( $raw_job );
65+
$job = $this->vitalize_job($raw_job);
66+
67+
if ($job && is_a($job, Job::class)) {
68+
$jobs[$raw_job->id] = $job;
69+
} else {
70+
return new WP_Error(
71+
'invalid-queue-job',
72+
__('An invalid item was found in the queue of files to be transferred.', 'wp-migrate-db')
73+
);
74+
}
4975
}
5076

5177
return $jobs;

class/Common/Queue/Connections/ConnectionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function delete( $job );
3636
*
3737
* @param Job $job
3838
*/
39-
public function release( $job );
39+
public function release( Job $job );
4040

4141
/**
4242
* Push a job onto the failure queue.

0 commit comments

Comments
 (0)