From ac2380e5fb7da22c2417b4c2db8f39f245cf7622 Mon Sep 17 00:00:00 2001 From: Arnaud Hours Date: Thu, 18 Sep 2025 14:49:33 +0200 Subject: [PATCH] feat(fast-orders): add minutes param --- includes/class-lengow-cron.php | 12 ++++++----- includes/class-lengow-import.php | 34 ++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/includes/class-lengow-cron.php b/includes/class-lengow-cron.php index 320cb64b..1069bdf3 100644 --- a/includes/class-lengow-cron.php +++ b/includes/class-lengow-cron.php @@ -128,6 +128,9 @@ public function launch() { if ( isset( $_GET[ Lengow_Import::PARAM_DAYS ] ) ) { $params[ Lengow_Import::PARAM_DAYS ] = (float) sanitize_text_field( $_GET[ Lengow_Import::PARAM_DAYS ] ); } + if ( isset( $_GET[ Lengow_Import::PARAM_MINUTES ] ) ) { + $params[ Lengow_Import::PARAM_MINUTES ] = (float) sanitize_text_field( $_GET[ Lengow_Import::PARAM_MINUTES ] ); + } if ( isset( $_GET[ Lengow_Import::PARAM_CREATED_FROM ] ) ) { $params[ Lengow_Import::PARAM_CREATED_FROM ] = (string) sanitize_text_field( $_GET[ Lengow_Import::PARAM_CREATED_FROM ] ); } @@ -156,6 +159,10 @@ public function launch() { } $import = new Lengow_Import( $params ); $import->exec(); + + if ( isset( $params[ Lengow_Import::PARAM_LOG_OUTPUT ] ) ) { + echo $import->getLogsDisplay(); + } } // sync actions between Lengow and WooCommerce. if ( ! $sync || Lengow_Sync::SYNC_ACTION === $sync ) { @@ -183,11 +190,6 @@ public function launch() { if ( $sync && ! in_array( $sync, Lengow_Sync::$sync_actions, true ) ) { wp_die( 'Action: ' . $sync . ' is not a valid action', '', array( 'response' => 400 ) ); } - - if ( isset( $params[ Lengow_Import::PARAM_LOG_OUTPUT ] ) ) { - echo( esc_html( $import->getLogsDisplay() ) ); - exit; - } } } } diff --git a/includes/class-lengow-import.php b/includes/class-lengow-import.php index 43b5e0c0..03045ffc 100755 --- a/includes/class-lengow-import.php +++ b/includes/class-lengow-import.php @@ -38,6 +38,7 @@ class Lengow_Import { const PARAM_MARKETPLACE_NAME = 'marketplace_name'; const PARAM_DELIVERY_ADDRESS_ID = 'delivery_address_id'; const PARAM_DAYS = 'days'; + const PARAM_MINUTES = 'minutes'; const PARAM_CREATED_FROM = 'created_from'; const PARAM_CREATED_TO = 'created_to'; const PARAM_ORDER_LENGOW_ID = 'order_lengow_id'; @@ -288,19 +289,21 @@ public function __construct( $params = array() ) { // set the time interval. $this->set_interval_time( isset( $params[ self::PARAM_DAYS ] ) ? (float) $params[ self::PARAM_DAYS ] : null, - isset( $params[ self::PARAM_CREATED_FROM ] ) ? $params[ self::PARAM_CREATED_FROM ] : null, - isset( $params[ self::PARAM_CREATED_TO ] ) ? $params[ self::PARAM_CREATED_TO ] : null + isset( $params[ self::PARAM_MINUTES ] ) ? (float) $params[ self::PARAM_MINUTES ] : null, + $params[ self::PARAM_CREATED_FROM ] ?? null, + $params[ self::PARAM_CREATED_TO ] ?? null ); - $this->limit = isset( $params[ self::PARAM_LIMIT ] ) ? $params[ self::PARAM_LIMIT ] : 0; + $this->limit = $params[ self::PARAM_LIMIT ] ?? 0; } - Lengow_Main::log( - Lengow_Log::CODE_IMPORT, - Lengow_Main::set_log_message( - 'log.import.init_params', - array( 'init_params' => wp_json_encode( $params ) ) - ), - $this->log_output - ); + + Lengow_Main::log( + Lengow_Log::CODE_IMPORT, + Lengow_Main::set_log_message( + 'log.import.init_params', + array( 'init_params' => wp_json_encode( $params ) ) + ), + $this->log_output + ); } /** @@ -410,10 +413,11 @@ public static function rest_time_to_import() { * Set interval time for order synchronisation. * * @param integer|null $days Import period + * @param integer|null $minutes Import period in minutes * @param string|null $created_from Import of orders since * @param string|null $created_to Import of orders until */ - private function set_interval_time( $days = null, $created_from = null, $created_to = null ) { + private function set_interval_time( $days = null, $minutes = null, $created_from = null, $created_to = null ) { if ( $created_from && $created_to ) { // retrieval of orders created from ... until ... $created_from_timestamp = strtotime( get_gmt_from_date( $created_from ) ); @@ -431,7 +435,11 @@ private function set_interval_time( $days = null, $created_from = null, $created return; } - if ( $days ) { + + if ( $minutes ) { + $interval_time = floor($minutes * 60); + $interval_time = $interval_time > self::MAX_INTERVAL_TIME ? self::MAX_INTERVAL_TIME : $interval_time; + } elseif ( $days ) { $interval_time = floor($days * self::MIN_INTERVAL_TIME); $interval_time = $interval_time > self::MAX_INTERVAL_TIME ? self::MAX_INTERVAL_TIME : $interval_time; } else {