• Resolved jochl

    (@jochl)


    Hi WP-ALL-IMPORT,

    First of all, thank you for answering all these questions on this forum. It really helped out with a few other features I needed.

    However I’m stuck myself now and could not find an answer. I have an export that creates an xml file with the latest orders (hourly) that need processing elsewhere. It works but it keeps creating xml files even when there are no orders to export. So it creates an empty xml file which is unwanted.

    I started on a function myself but the syntax is probably not right.
    Hopefully you can correct it, I would be ever grateful.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter jochl

    (@jochl)

    	add_action( 'pmxe_before_export', 'wp_all_export_before_export', 10, 1 );
    	function wp_all_export_before_export( $export_id )
    	{
    		// Unless you want this to execute for every export you should check the id here:
    		if($export_id == 2){
    			$export = new PMXI_Export_Record(); 
    			$export->getById($export_id);	 
    			if ( !$export->isEmpty() && $export->count < 1 ) {
    				echo 'Import skipped because of empty file / < 100 records';  
    				// stop import processing 
    				die(); 			 
    			}	 
    			
    		}
    	}
    Thread Starter jochl

    (@jochl)

    Created something along these lines but it does not work – probably need to set the log aswell but I’m kind of stuck.

    Thread Starter jochl

    (@jochl)

    add_action( 'pmxe_before_export', 'wp_all_export_before_export', 10, 1 );
     function wp_all_export_before_export( $export_id )
        {
            if ($export_id == 2) {
                $exportRecord = new PMXE_Export_Record();
                $exportRecord->getById($export_id);
                if ( $exportRecord->count == 0){
                    $exportRecord->set(array(
                        'triggered'   => 0,
                        'processing'  => 0,
                        'executing'   => 0,
                        'canceled'    => 1,
                        'canceled_on' => date('Y-m-d H:i:s')
                    ))->update();	
                    die();
                } 
            }
        }

    I feel like this should work – but it does not. Triggered via Cron.

    Plugin Author WP All Import

    (@wpallimport)

    Hey @jochl

    I can see that we’ve answered your question in our ticket system. For anyone else reading this, here’s an example snippet that shows how to delete an empty export file after the export completes: https://gist.github.com/KittenCodes/dd4882c92f2c8b0421bd5849cad629ac

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

The topic ‘Empty XML files’ is closed to new replies.