Skip to content

Commit

Permalink
Merge pull request #222 from yangyao/update-migrate
Browse files Browse the repository at this point in the history
Update tracking migrate cron
  • Loading branch information
yangyao authored May 7, 2024
2 parents 22314e6 + d4ee9f9 commit a31606f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
4 changes: 2 additions & 2 deletions aftership-woocommerce-tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: AfterShip Tracking - All-In-One WooCommerce Order Tracking (Free plan available)
* Plugin URI: http://aftership.com/
* Description: Track orders in one place. shipment tracking, automated notifications, order lookup, branded tracking page, delivery day prediction
* Version: 1.17.13
* Version: 1.17.14
* Author: AfterShip
* Author URI: http://aftership.com
*
Expand All @@ -20,7 +20,7 @@

require_once( 'woo-includes/woo-functions.php' );

define( 'AFTERSHIP_VERSION', '1.17.13' );
define( 'AFTERSHIP_VERSION', '1.17.14' );
define( 'AFTERSHIP_PATH', dirname( __FILE__ ) );
define( 'AFTERSHIP_ASSETS_URL', plugins_url() . '/' . basename( AFTERSHIP_PATH ) );
define( 'AFTERSHIP_SCRIPT_TAGS', 'aftership_script_tags' );
Expand Down
49 changes: 38 additions & 11 deletions includes/class-shipment-tracking-migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,66 @@
*/
class AfterShip_ShipmentTracking_Migrator {

/**
* Get the interval.
*
* @return bool
*/
public static function get_interval() {
$options = get_option( 'aftership_option_name' );
if ( ! $options ) {
return 0;
}
$interval = isset( $options['shipment_tracking_migrate_interval'] ) ? $options['shipment_tracking_migrate_interval'] : -1;
if ( ! $interval || $interval <= 0 ) {
return 0;
}
return $interval;
}

/**
* Check if the migration is enabled.
*
* @return bool
*/
public static function is_enabled() {
if ( ! self::get_interval() ) {
return false;
}
return true;
}

/**
* Setup.
*/
public static function load() {
add_action( 'init', array( __CLASS__, 'init' ) );
if ( ! self::is_enabled() ) {
return;
}
add_action( 'init', array( __CLASS__, 'schedule' ) );
add_action( 'aftership_migrate_from_shipment_tracking', array( __CLASS__, 'migrate_from_shipment_tracking' ) );
}

/**
* Schedule events and hook appropriate actions.
*/
public static function init() {
public static function schedule() {
$queue = WC()->queue();
$next = $queue->get_next( 'aftership_migrate_from_shipment_tracking' );
if ( ! $next ) {
$queue->schedule_recurring( time(), DAY_IN_SECONDS, 'aftership_migrate_from_shipment_tracking' );
}

add_action( 'aftership_migrate_from_shipment_tracking', array( __CLASS__, 'migrate_from_shipment_tracking' ) );
}

/**
* Migrate tracking number from shipment tracking.
*/
public static function migrate_from_shipment_tracking() {
$options = get_option( 'aftership_option_name' );
if ( ! $options ) {
return;
}
$interval = isset( $options['shipment_tracking_migrate_interval'] ) ? $options['shipment_tracking_migrate_interval'] : -1;
if ( ! $interval || $interval <= 0 ) {
if ( ! self::is_enabled() ) {
return;
}
$orders = wc_get_orders(
$interval = self::get_interval();
$orders = wc_get_orders(
array(
'date_created' => gmdate( 'Y-m-d', time() - $interval ) . '...' . gmdate( 'Y-m-d' ),
'limit' => -1,
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: aftership
Donate link: https://www.aftership.com/
Tags: woocommerce shipping,woocommerce tracking,shipment tracking,order tracking, woocommerce,track order,dhl,ups,usps,fedex,shipping,tracking,order
Requires at least: 2.9
Tested up to: 6.3
Stable tag: 1.17.13
Tested up to: 6.5
Stable tag: 1.17.14
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -141,6 +141,9 @@ Tailor a dynamic branded tracking page. Upload promotional banner, logo, and fav

== Changelog ==

= 1.17.14 =
* Fix known issue

= 1.17.13 =
* Update courier list

Expand Down

0 comments on commit a31606f

Please sign in to comment.