Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions includes/class-lengow-cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
}
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;
}
}
}
}
34 changes: 21 additions & 13 deletions includes/class-lengow-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
);
}

/**
Expand Down Expand Up @@ -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 ) );
Expand All @@ -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 {
Expand Down