| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Cron functions |
| 5 |
* |
| 6 |
* @link https://makecommerce.net/ |
| 7 |
* @since 3.0.0 |
| 8 |
* |
| 9 |
* @package Makecommerce |
| 10 |
* @subpackage Makecommerce/includes |
| 11 |
*/ |
| 12 |
|
| 13 |
namespace MakeCommerce; |
| 14 |
|
| 15 |
/** |
| 16 |
* Fired by cron |
| 17 |
* |
| 18 |
* This class defines all code necessary for plugins cron functions. |
| 19 |
* |
| 20 |
* @since 3.0.0 |
| 21 |
* @package Makecommerce |
| 22 |
* @subpackage Makecommerce/includes |
| 23 |
* @author Maksekeskus AS <support@maksekeskus.ee> |
| 24 |
*/ |
| 25 |
class Cron { |
| 26 |
|
| 27 |
/** |
| 28 |
* Initialize cron |
| 29 |
* |
| 30 |
* @since 3.0.0 |
| 31 |
*/ |
| 32 |
public function __construct() { |
| 33 |
|
| 34 |
// Assign schedule if not set, update compatible no need to reactivate, format('U') php 5.2 compatible |
| 35 |
// Assigns task at 23.59.59 by local time, task runs if time has passed and somebody navigates the site |
| 36 |
if ( !wp_next_scheduled( 'mc_banklinks_update_cron' ) ) { |
| 37 |
|
| 38 |
$date = new \DateTime(); |
| 39 |
$date->setTime( rand( 0, 23 ), rand( 0, 59 ), 00 ); |
| 40 |
$timestamp = intval( $date->format( 'U' ) ); |
| 41 |
|
| 42 |
wp_schedule_event( $timestamp, 'twicedaily', 'mc_banklinks_update_cron' ); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Define query variables. |
| 48 |
* |
| 49 |
* @since 3.0.0 |
| 50 |
*/ |
| 51 |
public function query_vars( $vars ) { |
| 52 |
|
| 53 |
$vars[] = 'mk-action'; |
| 54 |
$vars[] = 'mk-shop-id'; |
| 55 |
$vars[] = 'mk-test-shop-id'; |
| 56 |
|
| 57 |
return $vars; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Update banklinks if all conditions are met |
| 62 |
* |
| 63 |
* @since 3.0.0 |
| 64 |
*/ |
| 65 |
public function parse_update_vars( $wp ) { |
| 66 |
|
| 67 |
if ( |
| 68 |
array_key_exists('mk-action', $wp->query_vars) && |
| 69 |
$wp->query_vars['mk-action'] == 'mk-update' && |
| 70 |
( |
| 71 |
array_key_exists('mk-shop-id', $wp->query_vars) || |
| 72 |
array_key_exists('mk-test-shop-id', $wp->query_vars) |
| 73 |
) |
| 74 |
) { |
| 75 |
|
| 76 |
if ( |
| 77 |
( |
| 78 |
strlen($wp->query_vars['mk-shop-id']) && |
| 79 |
$wp->query_vars['mk-shop-id'] == get_option('mk_shop_id', false) |
| 80 |
) || |
| 81 |
( |
| 82 |
strlen($wp->query_vars['mk-test-shop-id']) && |
| 83 |
$wp->query_vars['mk-test-shop-id'] == get_option('mk_test_shop_id', false) |
| 84 |
) |
| 85 |
) { |
| 86 |
|
| 87 |
Payment::update_banklinks(); |
| 88 |
exit(); |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Updates banklinks via cron |
| 95 |
* |
| 96 |
* @since 3.0.0 |
| 97 |
*/ |
| 98 |
public function update_banklinks() { |
| 99 |
|
| 100 |
Payment::update_banklinks(); |
| 101 |
} |
| 102 |
} |
| 103 |
|