Skip to content

Commit

Permalink
Improve formatting fpr #82
Browse files Browse the repository at this point in the history
  • Loading branch information
bueltge committed Jun 15, 2017
1 parent dd9bed4 commit ce9cd0a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
18 changes: 9 additions & 9 deletions inc/Database/Exporter.php
Expand Up @@ -312,12 +312,12 @@ public function backup_table( $search = '', $replace = '', $table, $new_table_pr
$page_size = $this->page_size;
$pages = ceil( $row_count / $page_size );
//Prepare CSV data
if($csv != null) {
$csv_lines = explode("\n", $csv);
$csv_head = str_getcsv("search,replace");
if ( $csv !== null ) {
$csv_lines = explode("\n", $csv );
$csv_head = str_getcsv( 'search,replace' );
$csv_array = array();
foreach ($csv_lines as $line) {
$csv_array[] = array_combine($csv_head, str_getcsv($line));
foreach ( $csv_lines as $line ) {
$csv_array[] = array_combine( $csv_head, str_getcsv( $line ) );
}
}
for ( $page = 0; $page < $pages; $page ++ ) {
Expand Down Expand Up @@ -347,15 +347,15 @@ public function backup_table( $search = '', $replace = '', $table, $new_table_pr
//skip replace if no search pattern
//check if we need to replace something
//skip primary_key
if ( $search !== '' && $column !== $primary_key && $column !== "guid") {
if ( $search !== '' && $column !== $primary_key && $column !== 'guid' ) {

$edited_data = $this->replace->recursive_unserialize_replace(
$search, $replace,
$value
);
if($csv != null) {
foreach($csv_array as $entry) {
$edited_data = $this->recursive_unserialize_replace( $entry['search'], $entry['replace'], $edited_data );
if ( $csv !== null ) {
foreach( $csv_array as $entry ) {
$edited_data = $this->replace->recursive_unserialize_replace( $entry['search'], $entry['replace'], $edited_data );
}
}
// Something was changed
Expand Down
23 changes: 12 additions & 11 deletions inc/Database/Replace.php
Expand Up @@ -73,13 +73,14 @@ public function __construct( Manager $dbm, Service\MaxExecutionTime $max_executi
* @param string $search What we want to replace
* @param string $replace What we want to replace it with.
* @param string $tables The name of the table we want to look at.
* @param null $csv
*
* @return array|\WP_Error Collection of information gathered during the run.
* @return array|\WP_Error Collection of information gathered during the run.
*/

public function run_search_replace( $search, $replace, $tables, $csv = null) {
public function run_search_replace( $search, $replace, $tables, $csv = null ) {

if ( $search === $replace && $search != '' ){
if ( $search === $replace && $search !== '' ){
return new \WP_Error( 'error', __( "Search and replace pattern can't be the same!" ) );
}

Expand Down Expand Up @@ -127,7 +128,7 @@ public function replace_values( $search = '', $replace = '', $table, $csv = null
);

// check we have a search string, bail if not
if ( empty( $search ) && empty($csv) ) {
if ( empty( $search ) && empty( $csv ) ) {
$table_report[ 'errors' ][] = 'Search string is empty';

return $table_report;
Expand Down Expand Up @@ -155,12 +156,12 @@ public function replace_values( $search = '', $replace = '', $table, $csv = null
$page_size = $this->page_size;
$pages = ceil( $row_count / $page_size );
//Prepare CSV data
if($csv != null) {
if ( $csv !== null ) {
$csv_lines = explode("\n", $csv);
$csv_head = str_getcsv("search,replace");
$csv_head = str_getcsv( 'search,replace' );
$csv_array = array();
foreach ($csv_lines as $line) {
$csv_array[] = array_combine($csv_head, str_getcsv($line));
foreach ( $csv_lines as $line ) {
$csv_array[] = array_combine($csv_head, str_getcsv( $line ) );
}
}
for ( $page = 0; $page < $pages; $page ++ ) {
Expand All @@ -184,7 +185,7 @@ public function replace_values( $search = '', $replace = '', $table, $csv = null

foreach ( $columns as $column ) {
//Skip the GUID column per Wordpress Codex
if($column == "guid") {
if ( $column === "guid" ) {
continue;
}
$data_to_fix = $row[ $column ];
Expand All @@ -204,8 +205,8 @@ public function replace_values( $search = '', $replace = '', $table, $csv = null
// Run a search replace on the data that'll respect the serialisation.
$edited_data = $this->recursive_unserialize_replace( $search, $replace, $data_to_fix );
// Run a search replace by CSV parameters if CSV input present
if($csv != null) {
foreach($csv_array as $entry) {
if ( $csv !== null ) {
foreach( $csv_array as $entry ) {
$edited_data = $this->recursive_unserialize_replace( $entry['search'], $entry['replace'], $edited_data );
}
}
Expand Down
2 changes: 1 addition & 1 deletion inc/Page/SearchReplace.php
Expand Up @@ -291,7 +291,7 @@ private function get_replace_value() {
}

/**
* shows the csv value in template
* Shows the csv value in template.
*/
private function get_csv_value() {

Expand Down

0 comments on commit ce9cd0a

Please sign in to comment.