Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public function compare_register_prod() {
error_log( 'start Import' );
//$truncat = $wpdb->query( 'DELETE FROM ' . $table . ' WHERE `platform` LIKE "Awin"' );
$partners = $this->awin['partner'];
$partners = explode( ',', $partners );
$secondes = apply_filters( 'compare_time_limit', 600 );
set_time_limit( $secondes );
$awin = get_option( 'awin' );
$customer_id = $awin['customer_id'];
foreach ( $partners as $key => $value ) {
$event = 'start partner ' . $value;
error_log( $event );
error_log( memory_get_usage() );
$this->queue_register->push_to_queue(
array(
'key' => $key,
'value' => $value,
'customer_id' => $customer_id,
)
);
$this->queue_register->save();
$this->queue_register->dispatch();
$path = null;
$upload = null;
$partner_details = null;
error_log( memory_get_usage() );
$event = 'stop partner ' . $value;
error_log( $event );
}
$event = 'import complete';
error_log( $event );
}
protected function task( $item ) {
global $wpdb;
$table = $wpdb->prefix . 'compare';
$value = $item['value'];
$customer_id = $item['customer_id'];
$xml = new XMLReader();
$awin = new Awin();
$partner_details = $awin->compare_get_awin_partners( $value );
foreach ( $partner_details as $partner_detail ) {
$partner_details = $partner_detail;
}
$path = wp_upload_dir();
$upload = $path['path'] . '/awin/xml/' . $customer_id . '-' . $value . '.gz';
$xml->open( 'compress.zlib://' . $upload );
$xml->read();
while ( $xml->read() && 'prod' !== $xml->name ) {
;
}
while ( 'prod' === $xml->name ) {
$element = new SimpleXMLElement( $xml->readOuterXML() );
$prod = array(
'price' => strval( $element->price->buynow ),
'title' => $element->text->name ? strval( $element->text->name ) : '',
'description' => strval( $element->text->desc ),
'img' => strval( $element->uri->mImage ),
'url' => strval( $element->uri->awTrack ),
'partner_name' => $partner_details,
'productid' => strval( $xml->getAttribute( 'id' ) ),
'ean' => strval( $element->ean ),
'platform' => 'Awin',
'partner_code' => $value,
);
$insert = $wpdb->insert( $table, $prod );
$xml->next( 'prod' );
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment