Skip to content

Commit

Permalink
Merge pull request #86 from BeAPI/ver/6.2.0
Browse files Browse the repository at this point in the history
Release 6.2.0
  • Loading branch information
petitphp authored Aug 21, 2023
2 parents d7a807a + 7fdd145 commit 13d6fc5
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .plugin-data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "6.1.20",
"version": "6.2.0",
"slug": "shopping-feed"
}
16 changes: 9 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

* Contributors: ShoppingFeed, BeAPI
* Tags: shoppingfeed, marketplace, woocommerce, woocommerce shoppingfeed, create woocommerce products shoppingfeed, products feed, generate shoppingfeed, amazon, Jet, Walmart, many marketplace, import orders
* Stable tag: 6.1.20
* Version: 6.1.20
* Stable tag: 6.2.0
* Version: 6.2.0
* Requires PHP: 7.1
* Requires at least: 5.7
* Tested up to: 6.2
Expand All @@ -15,6 +15,8 @@
> Version 6.0.0 is a major version, there are several changes and improvements which affect the architecture of the plugin. You will have to re-configure the plugin, all the previous settings will be lost
## Changelog
* 6.2.0
* Rework feed generation process to better handle shop with large amount of products.
* 6.1.20
* Fix an issue with migration process failing to be scheduled with new version of Woocommerce.
* Update plugin requirements
Expand Down Expand Up @@ -135,12 +137,12 @@ WordPress connection Controller Plugin for ShoppingFeed - Sell on Amazon, Ebay,
## Requirements

### Server :
- PHP version 5.6 or above
- PHP version 7.1 or above
- PHP cURL extension is activated

### WordPress :
- Core version 5.2 or above
- WooCommerce version 3.8 or above
- Core version 5.7 or above
- WooCommerce version 5.1 or above

## Installation
Sign up for free on ShoppingFeed : https://shopping-feed.com/
Expand Down Expand Up @@ -255,12 +257,12 @@ function your_custom_tracking_url_function() {
```

### Extra Fields
If you want to add add extra fields to your XML Feed, you can use the following snippet
If you want to add an extra fields to your XML Feed, you can use the following snippet
```php
add_filter( 'shopping_feed_extra_fields', 'your_custom_fields_function', 10, 2 );

/** @return array */
function your_custom_tracking_url_function($fields, $wc_product) {
function your_custom_fields_function($fields, $wc_product) {
$fields[] = array('name'=>'my_field', 'value'=>'my_value');
return $fields;
}
Expand Down
16 changes: 9 additions & 7 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## ShoppingFeed
Contributors: ShoppingFeed, BeAPI
Tags: shoppingfeed, marketplace, woocommerce, woocommerce shoppingfeed, create woocommerce products shoppingfeed, products feed, generate shoppingfeed, amazon, Jet, Walmart, many marketplace, import orders
Stable tag: 6.1.20
Version: 6.1.20
Stable tag: 6.2.0
Version: 6.2.0
Requires PHP: 7.1
Requires at least: 5.7
Tested up to: 6.2
Expand All @@ -13,6 +13,8 @@ WC tested up to: 7.7
Version 6.0.0 is a major version, there are several changes and improvements which affect the architecture of the plugin. You will have to re-configure the plugin, all the previous settings will be lost

== Changelog ==
* 6.2.0
* Rework feed generation process to better handle shop with large amount of products.
* 6.1.20
* Fix an issue with migration process failing to be scheduled with new version of Woocommerce.
* Update plugin requirements
Expand Down Expand Up @@ -133,13 +135,13 @@ WordPress connection Controller Plugin for ShoppingFeed - Sell on Amazon, Ebay,
## Requirements

### Server :
- PHP version 5.6 or above
- PHP version 7.1 or above
- PHP cURL extension is activated

### WordPress :

- Core version 5.2 or above
- WooCommerce version 3.8 or above
- Core version 5.7 or above
- WooCommerce version 5.1 or above

## Installation

Expand Down Expand Up @@ -259,13 +261,13 @@ function your_custom_tracking_url_function() {
`

### Extra Fields
If you want to add add extra fields to your XML Feed, you can use the following snippet
If you want to add an extra fields to your XML Feed, you can use the following snippet

`
add_filter( 'shopping_feed_extra_fields', 'your_custom_fields_function', 10, 2 );

/** @return array */
function your_custom_tracking_url_function($fields, $wc_product) {
function your_custom_fields_function($fields, $wc_product) {
$fields[] = array('name'=>'my_field', 'value'=>'my_value');
return $fields;
}
Expand Down
4 changes: 2 additions & 2 deletions shoppingfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://www.shopping-feed.com/
* Text Domain: shopping-feed
* Domain Path: /languages
* Version: 6.1.20
* Version: 6.2.0
* Requires at least: 5.7
* Requires PHP: 7.1
* WC requires at least: 5.1.0
Expand All @@ -26,7 +26,7 @@
require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload.php';
}

define( 'SF_VERSION', '6.1.20' );
define( 'SF_VERSION', '6.2.0' );
define( 'SF_DB_VERSION_SLUG', 'SF_DB_VERSION' );
define( 'SF_DB_VERSION', '1.0.0' );
define( 'SF_UPGRADE_RUNNING', 'SF_UPGRADE_RUNNING' );
Expand Down
19 changes: 17 additions & 2 deletions src/Admin/WoocommerceActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct() {
'generate_feed_part',
],
10,
2
3
);

//Combine feed's parts
Expand All @@ -80,7 +80,22 @@ public function __construct() {
add_action(
'sf_generate_feed_action',
function () {
Generator::get_instance()->generate();
if ( ShoppingFeedHelper::is_process_running( 'sf_feed_generation_process' ) ) {
ShoppingFeedHelper::get_logger()->warning(
sprintf(
__( 'Feed generation already running', 'shopping-feed' )
),
array(
'source' => 'shopping-feed',
)
);

return true;
}

AsyncGenerator::get_instance()->launch();

return true;
}
);

Expand Down
106 changes: 64 additions & 42 deletions src/Feed/AsyncGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ShoppingFeed\Feed\ProductGenerator;
use ShoppingFeed\ShoppingFeedWC\Products\Products;
use ShoppingFeed\ShoppingFeedWC\ShoppingFeed;
use ShoppingFeed\ShoppingFeedWC\ShoppingFeedHelper;

class AsyncGenerator extends Generator {
Expand All @@ -12,69 +13,74 @@ class AsyncGenerator extends Generator {
* Launch the feed generation process
*/
public function launch() {
$part_size = ShoppingFeedHelper::get_sf_part_size();
// Ensure all necessary directories have been created.
ShoppingFeed::add_sf_directory();

$products = Products::get_instance()->get_products();
$total_products = count( $products );
$total_pages = 1;
if ( $part_size < $total_products ) {
$total_pages = (int) round( $total_products / $part_size );
}
// Clean directory containing feed parts generated by the async generator.
// This is to avoid reusing old parts that could remain if a previous execution of the generator failed.
$this->clean_feed_parts_directory();

$option = array(
'total_pages' => $total_pages,
$part_size = ShoppingFeedHelper::get_sf_part_size();
as_schedule_single_action(
time() + 5,
'sf_feed_generation_part',
array(
1,
$part_size,
),
'sf_feed_generation_process'
);

update_option( 'sf_feed_generation_process', $option );
for ( $page = 1; $page <= $total_pages; $page ++ ) {
as_schedule_single_action(
false,
'sf_feed_generation_part',
array(
$page,
$part_size,
),
'sf_feed_generation_process'
);
}
}

/**
* Generate feed part
*
* @param $page
* @param $post_per_page
* @param int $page
* @param int $post_per_page
*
* @return bool|\WP_Error
*/
public function generate_feed_part( $page, $post_per_page ) {
$args = array(
'page' => $page,
'limit' => $post_per_page,
'page' => $page,
'limit' => $post_per_page,
'return' => 'ids',
);
$products = Products::get_instance()->get_products( $args );
$path = sprintf( '%s/%s', ShoppingFeedHelper::get_feed_parts_directory(), 'part_' . $page );

$products_list = Products::get_instance()->format_products( $products );
// If the query doesn't return any products, schedule the combine action and stop the current action.
if ( empty( $products ) ) {
as_schedule_single_action(
time() + 5,
'sf_feed_generation_combine_feed_parts',
array(),
'sf_feed_generation_process'
);

return true;
}

// Process products returned by the query and reschedule the action for the next page.
$path = sprintf( '%s/%s', ShoppingFeedHelper::get_feed_parts_directory(), 'part_' . $page );
$products_list = Products::get_instance()->format_products( $products );
try {
$this->generator = new ProductGenerator();
$this->generator->setPlatform( $page, $page );
$this->generator->setPlatform( (string) $page, (string) $page );
$this->generator->setUri( sprintf( 'file://%s.xml', $path ) );
$this->set_filters();
$this->set_mappers();
$this->generator->write( $products_list );

$option = get_option( 'sf_feed_generation_process' );
$option['currentPage'] = $page;
update_option( 'sf_feed_generation_process', $option );

if ( ! empty( $option['currentPage'] ) && $option['currentPage'] === $option['total_pages'] ) {
as_schedule_single_action(
false,
'sf_feed_generation_combine_feed_parts',
array(),
'sf_feed_generation_process'
);
}
$page ++;
as_schedule_single_action(
time() + 5,
'sf_feed_generation_part',
array(
$page,
$post_per_page,
),
'sf_feed_generation_process'
);
} catch ( \Exception $exception ) {
return new \WP_Error( 'shopping_feed_generation_error', $exception->getMessage() );
}
Expand Down Expand Up @@ -139,7 +145,8 @@ public function combine_feed_parts() {
wp_delete_file( $dir . '/products_tmp.xml' );

$skelton = simplexml_load_string( ShoppingFeedHelper::get_feed_skeleton() );
$this->simplexml_import_xml( $skelton->metadata, $products, $before = true );
$this->simplexml_import_xml( $skelton->metadata, $products, true );
$skelton->metadata->platform = sprintf( 'WooCommerce:%s', ShoppingFeedHelper::get_wc_version() );
$skelton->metadata->startedAt = $last_started_at;
$skelton->metadata->finishedAt = $last_finished_at;
$skelton->metadata->invalid = $xml_invalid;
Expand Down Expand Up @@ -195,4 +202,19 @@ public function simplexml_import_xml( \SimpleXMLElement $parent, $xml, $before =
return (bool) $node->appendChild( $fragment );
// @codingStandardsIgnoreEnd
}

/**
* Remove all XML files in the feed parts directory.
*
* @return void
*/
public function clean_feed_parts_directory() {
$dir_parts = ShoppingFeedHelper::get_feed_parts_directory();
$files = glob( $dir_parts . '/' . '*.xml' ); // @codingStandardsIgnoreLine.
if ( is_array( $files ) && ! empty( $files ) ) {
foreach ( $files as $file ) {
wp_delete_file( $file );
}
}
}
}
4 changes: 2 additions & 2 deletions src/Feed/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Generator {
*/
const SF_FEED_LAST_GENERATION_DATE = 'SF_FEED_LAST_GENERATION';
/**
* @var Generator
* @var static
*/
private static $instance;
/** @var Platform */
Expand Down Expand Up @@ -218,7 +218,7 @@ function (
/**
* Get the singleton instance.
*
* @return Generator
* @return static
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/ShoppingFeedHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public static function get_sf_part_size() {
return 200;
}

return $part_size;
return (int) $part_size;
}

/**
Expand Down Expand Up @@ -709,7 +709,7 @@ public static function get_running_process( $group ) {
return $action_scheduler->query_actions(
array(
'group' => $group,
'status' => $action_scheduler::STATUS_PENDING,
'status' => [ \ActionScheduler_Store::STATUS_PENDING, \ActionScheduler_Store::STATUS_RUNNING ],
)
);
}
Expand Down

0 comments on commit 13d6fc5

Please sign in to comment.