Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions inc/duplication/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static function should_copy_table($table, $table_base_name, $from_site_id
* @param int $from_site_id Source site ID.
* @param int $to_site_id Target site ID.
*/
return (bool) apply_filters('mucd_should_copy_table', $copy, $table, $table_base_name, $from_site_id, $to_site_id);
return (bool) apply_filters('wu_mucd_should_copy_table', $copy, $table, $table_base_name, $from_site_id, $to_site_id);
}

/**
Expand Down Expand Up @@ -248,7 +248,7 @@ public static function is_runtime_table($table_base_name) {
*
* @param array $runtime_tables Runtime-only table base names.
*/
$runtime_tables = (array) apply_filters('mucd_runtime_tables_to_ignore', $runtime_tables);
$runtime_tables = (array) apply_filters('wu_mucd_runtime_tables_to_ignore', $runtime_tables);

return in_array($table_base_name, $runtime_tables, true);
}
Expand All @@ -274,7 +274,7 @@ private static function should_skip_empty_table($table, $table_base_name, $from_
return false;
}

return 0 === self::get_table_row_count($table);
return ! self::table_has_rows($table);
}

/**
Expand All @@ -297,7 +297,7 @@ private static function skip_empty_tables($from_site_id, $to_site_id) {
* @param int $from_site_id Source site ID.
* @param int $to_site_id Target site ID.
*/
return (bool) apply_filters('mucd_skip_empty_tables', true, $from_site_id, $to_site_id);
return (bool) apply_filters('wu_mucd_skip_empty_tables', true, $from_site_id, $to_site_id);
}

/**
Expand Down Expand Up @@ -330,24 +330,30 @@ private static function is_required_table($table_base_name) {
*
* @param array $required_tables Required table base names.
*/
$required_tables = (array) apply_filters('mucd_required_tables_to_copy', $required_tables);
$required_tables = (array) apply_filters('wu_mucd_required_tables_to_copy', $required_tables);

return in_array($table_base_name, $required_tables, true);
}

/**
* Count rows in a source table.
* Check whether a source table has rows.
*
* @since 2.5.1
*
* @param string $table Full source table name.
* @return int Source table row count.
* @return bool Whether the source table has rows.
*/
private static function get_table_row_count($table) {
private static function table_has_rows($table) {
global $wpdb;

$wpdb->last_error = '';
$has_rows = self::do_sql_query('SELECT 1 FROM `' . $table . '` LIMIT 1', 'var', false);

$count = self::do_sql_query('SELECT COUNT(*) FROM `' . $table . '`', 'var', false);
if ('' !== $wpdb->last_error) {
return true;
}

return (int) $count;
return null !== $has_rows;
}

/**
Expand Down
19 changes: 17 additions & 2 deletions tests/WP_Ultimo/Duplication/MUCD_Data_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@
* Test try_replace with serialized array data.
*/
public function test_try_replace_serialized_array() {
$data = serialize(['url' => 'https://example.com/old-site/page']);

Check warning on line 93 in tests/WP_Ultimo/Duplication/MUCD_Data_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

serialize() found. Serialized data has known vulnerability problems with Object Injection. JSON is generally a better approach for serializing data. See https://www.owasp.org/index.php/PHP_Object_Injection
$row = ['meta_value' => $data];

Check warning on line 94 in tests/WP_Ultimo/Duplication/MUCD_Data_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Detected usage of meta_value, possible slow query.

$result = \MUCD_Data::try_replace($row, 'meta_value', 'example.com/old-site', 'example.com/new-site');

$unserialized = unserialize($result);

Check warning on line 98 in tests/WP_Ultimo/Duplication/MUCD_Data_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

unserialize() found. Serialized data has known vulnerability problems with Object Injection. JSON is generally a better approach for serializing data. See https://www.owasp.org/index.php/PHP_Object_Injection
$this->assertEquals('https://example.com/new-site/page', $unserialized['url']);
}

Expand All @@ -103,17 +103,17 @@
* Test try_replace with nested serialized data.
*/
public function test_try_replace_nested_serialized_array() {
$data = serialize([

Check warning on line 106 in tests/WP_Ultimo/Duplication/MUCD_Data_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

serialize() found. Serialized data has known vulnerability problems with Object Injection. JSON is generally a better approach for serializing data. See https://www.owasp.org/index.php/PHP_Object_Injection
'settings' => [
'link' => 'https://example.com/old-site/about',
'icon' => 'fa-home',
],
'content' => 'Visit https://example.com/old-site for more',
]);
$row = ['meta_value' => $data];

Check warning on line 113 in tests/WP_Ultimo/Duplication/MUCD_Data_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Detected usage of meta_value, possible slow query.

$result = \MUCD_Data::try_replace($row, 'meta_value', 'example.com/old-site', 'example.com/new-site');
$unserialized = unserialize($result);

Check warning on line 116 in tests/WP_Ultimo/Duplication/MUCD_Data_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

unserialize() found. Serialized data has known vulnerability problems with Object Injection. JSON is generally a better approach for serializing data. See https://www.owasp.org/index.php/PHP_Object_Injection

$this->assertEquals('https://example.com/new-site/about', $unserialized['settings']['link']);
$this->assertEquals('Visit https://example.com/new-site for more', $unserialized['content']);
Expand All @@ -135,12 +135,12 @@
* Test try_replace with double-serialized data.
*/
public function test_try_replace_double_serialized() {
$data = serialize(serialize(['url' => 'https://example.com/old-site/page']));

Check warning on line 138 in tests/WP_Ultimo/Duplication/MUCD_Data_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

serialize() found. Serialized data has known vulnerability problems with Object Injection. JSON is generally a better approach for serializing data. See https://www.owasp.org/index.php/PHP_Object_Injection

Check warning on line 138 in tests/WP_Ultimo/Duplication/MUCD_Data_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

serialize() found. Serialized data has known vulnerability problems with Object Injection. JSON is generally a better approach for serializing data. See https://www.owasp.org/index.php/PHP_Object_Injection
$row = ['meta_value' => $data];

Check warning on line 139 in tests/WP_Ultimo/Duplication/MUCD_Data_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Detected usage of meta_value, possible slow query.

$result = \MUCD_Data::try_replace($row, 'meta_value', 'example.com/old-site', 'example.com/new-site');

$unserialized = unserialize(unserialize($result));

Check warning on line 143 in tests/WP_Ultimo/Duplication/MUCD_Data_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

unserialize() found. Serialized data has known vulnerability problems with Object Injection. JSON is generally a better approach for serializing data. See https://www.owasp.org/index.php/PHP_Object_Injection
$this->assertEquals('https://example.com/new-site/page', $unserialized['url']);
}

Expand Down Expand Up @@ -713,7 +713,7 @@
};

add_filter(
'mucd_should_copy_table',
'wu_mucd_should_copy_table',
$filter,
10,
3
Expand All @@ -724,10 +724,25 @@
\MUCD_Data::should_copy_table($table, 'actionscheduler_actions', get_current_blog_id(), 123)
);
} finally {
remove_filter('mucd_should_copy_table', $filter, 10);
remove_filter('wu_mucd_should_copy_table', $filter, 10);
}
}

/**
* Test empty-table checks fail open when the row probe errors.
*/
public function test_should_copy_table_keeps_optional_table_when_row_probe_errors() {
global $wpdb;

$table = $wpdb->get_blog_prefix() . 'wu_missing_optional_fixture';

$this->drop_table_selection_fixture($table);

$this->assertTrue(
\MUCD_Data::should_copy_table($table, 'wu_missing_optional_fixture', get_current_blog_id(), 123)
);
}

/**
* Create a temporary table used by table-selection tests.
*
Expand Down
Loading