• ResolvedPlugin Contributor therab

    (@therab)


    Hi, this is a patch of my quick-and-dirty (which means not thoroughly tested) update of the csv import and export routines.
    I added import and export for the book_id.
    Hope it finds its way into the next update.

    With best regards,
    keep up the good work,
    Rainer

    
    diff -Naur orig/gwolle-gb/admin/gb-page-export.php gwolle-gb/admin/gb-page-export.php
    --- orig/gwolle-gb/admin/gb-page-export.php	2018-01-18 12:17:32.000000000 +0100
    +++ gwolle-gb/admin/gb-page-export.php	2018-01-21 22:12:17.000000000 +0100
    @@ -169,6 +169,7 @@
     		// Output the column headings
     		fputcsv($output, array(
     				'id',
    +				'book_id',
     				'author_name',
     				'author_email',
     				'author_origin',
    @@ -189,6 +190,7 @@
     			$row = Array();
     
     			$row[] = $entry->get_id();
    +			$row[] = $entry->get_book_id();
     			$row[] = addslashes($entry->get_author_name());
     			$row[] = addslashes($entry->get_author_email());
     			$row[] = addslashes($entry->get_author_origin());
    diff -Naur orig/gwolle-gb/admin/gb-page-import.php gwolle-gb/admin/gb-page-import.php
    --- orig/gwolle-gb/admin/gb-page-import.php	2018-01-18 12:17:32.000000000 +0100
    +++ gwolle-gb/admin/gb-page-import.php	2018-01-21 22:29:24.000000000 +0100
    @@ -550,7 +550,23 @@
     										'istrash',
     										'admin_reply'
     									);
    -									if ( $data != $testrow_1_0 && $data != $testrow_1_4_1 && $data != $testrow_1_4_8 ) {
    +									$testrow_2_3_8 = array(
    +										'id',
    +										'book_id',
    +										'author_name',
    +										'author_email',
    +										'author_origin',
    +										'author_website',
    +										'author_ip',
    +										'author_host',
    +										'content',
    +										'datetime',
    +										'isspam',
    +										'ischecked',
    +										'istrash',
    +										'admin_reply'
    +									);
    +									if ( $data != $testrow_1_0 && $data != $testrow_1_4_1 && $data != $testrow_1_4_8 && $data != $testrow_2_3_8 ) {
     										gwolle_gb_add_message( '<p>' . esc_html__('It seems your CSV file is from an export that is not compatible with this version of Gwolle-GB.', 'gwolle-gb') . '</p>', true, false);
     										break;
     									}
    @@ -558,7 +574,7 @@
     									continue;
     								}
     
    -								if ( $num != 12 && $num != 13 ) {
    +								if ( $num != 12 && $num != 13 && $num != 14 ) {
     									gwolle_gb_add_message( '<p>' . esc_html__('Your data seems to be corrupt. Import failed.', 'gwolle-gb') . '</p>', true, false);
     									break;
     								}
    @@ -567,25 +583,26 @@
     								$entry = new gwolle_gb_entry();
     
     								/* Check if the date is a timestamp, else convert */
    -								if ( !is_numeric($data[8]) ) {
    -									$data[8] = strtotime($data[8]);
    +								if ( !is_numeric($data[9]) ) {
    +									$data[9] = strtotime($data[9]);
     								}
     
     								/* Set the data in the instance */
     								// $entry->set_id( $data[0] ); // id of entry
    -								$entry->set_author_name( $data[1] );
    -								$entry->set_author_email( $data[2] );
    -								$entry->set_author_origin( $data[3] );
    -								$entry->set_author_website( $data[4] );
    -								$entry->set_author_ip( $data[5] );
    -								$entry->set_author_host( $data[6] );
    -								$entry->set_content( $data[7] );
    -								$entry->set_datetime( $data[8] );
    -								$entry->set_isspam( $data[9] );
    -								$entry->set_ischecked( $data[10] );
    -								$entry->set_istrash( $data[11] );
    +								$entry->set_book_id( $data[1] );
    +								$entry->set_author_name( $data[2] );
    +								$entry->set_author_email( $data[3] );
    +								$entry->set_author_origin( $data[4] );
    +								$entry->set_author_website( $data[5] );
    +								$entry->set_author_ip( $data[6] );
    +								$entry->set_author_host( $data[7] );
    +								$entry->set_content( $data[8] );
    +								$entry->set_datetime( $data[9] );
    +								$entry->set_isspam( $data[10] );
    +								$entry->set_ischecked( $data[11] );
    +								$entry->set_istrash( $data[12] );
     								if ( isset( $data[12] ) ) {
    -									$entry->set_admin_reply( $data[12] ); // admin_reply is only since 1.4.8
    +									$entry->set_admin_reply( $data[13] ); // admin_reply is only since 1.4.8
     								}
     
     								/* Save the instance */
    diff -Naur orig/gwolle-gb/readme.txt gwolle-gb/readme.txt
    --- orig/gwolle-gb/readme.txt	2018-01-18 12:17:32.000000000 +0100
    +++ gwolle-gb/readme.txt	2018-01-21 22:22:21.000000000 +0100
    @@ -165,6 +165,7 @@
     	<?php
     	array(
     		'id',
    +		'book_id',
     		'author_name',
     		'author_email',
     		'author_origin',
    
    • This topic was modified 8 years, 4 months ago by therab.
    • This topic was modified 8 years, 4 months ago by therab.
    • This topic was modified 8 years, 4 months ago by therab.
    • This topic was modified 8 years, 4 months ago by therab.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Marcel Pol

    (@mpol)

    Thank you, this has now been added to 2.3.9.
    Only thing I changed was set the book_id to the last field, so it can be wrapped inside an if statement. For the rest it was fine.
    It was the first time I received a patch as good as this. Thank you and have a good weekend.

    Plugin Contributor therab

    (@therab)

    Thank you, too.
    It’s only worth patching if what’s already there is worth patching 🙂
    Keep up the good work!

    Rainer

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Patch for csv import and export: book_id’ is closed to new replies.