| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Description of TipOfDaySyncController |
| 5 |
* |
| 6 |
* @author Ali2Woo Team |
| 7 |
* |
| 8 |
* @autoload: a2wl_admin_init |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace AliNext_Lite;; |
| 12 |
|
| 13 |
class TipOfDaySyncController extends AbstractController |
| 14 |
{ |
| 15 |
private TipOfDaySyncService $TipOfDaySyncService; |
| 16 |
|
| 17 |
public const SYNC_PERIOD = 7200; |
| 18 |
|
| 19 |
public function __construct( |
| 20 |
TipOfDaySyncService $TipOfDaySyncService |
| 21 |
) { |
| 22 |
parent::__construct(); |
| 23 |
|
| 24 |
$this->TipOfDaySyncService = $TipOfDaySyncService; |
| 25 |
|
| 26 |
$last_update = intval(get_setting(Settings::SETTING_TIP_OF_DAY_LAST_SYNC)); |
| 27 |
|
| 28 |
if (!$last_update || $last_update < time()) { |
| 29 |
set_setting(Settings::SETTING_TIP_OF_DAY_LAST_SYNC, time() + self::SYNC_PERIOD); |
| 30 |
|
| 31 |
$request_url = RequestHelper::build_request('sync_tips_of_day'); |
| 32 |
|
| 33 |
$request = a2wl_remote_get($request_url); |
| 34 |
|
| 35 |
if (!is_wp_error($request) && intval($request['response']['code']) == 200) { |
| 36 |
$pluginData = json_decode($request['body'], true); |
| 37 |
|
| 38 |
if (is_array($pluginData)) { |
| 39 |
$this->TipOfDaySyncService->syncFromApiData($pluginData); |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|