| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Services; |
| 4 |
|
| 5 |
use SyncBasalam\Config\Endpoints; |
| 6 |
use SyncBasalam\Logger\Logger; |
| 7 |
use SyncBasalam\Services\ApiServiceManager; |
| 8 |
|
| 9 |
defined('ABSPATH') || exit; |
| 10 |
|
| 11 |
class FetchVersionDetail |
| 12 |
{ |
| 13 |
private $apiService; |
| 14 |
private $version; |
| 15 |
|
| 16 |
public function __construct($version) |
| 17 |
{ |
| 18 |
$this->apiService = syncBasalamContainer()->get(ApiServiceManager::class); |
| 19 |
$this->version = $version; |
| 20 |
} |
| 21 |
|
| 22 |
public function Fetch() |
| 23 |
{ |
| 24 |
$url = Endpoints::HAMSALAM_VERSION_DETAIL . '?site_url=' . get_site_url() . '¤t_version=' . $this->version; |
| 25 |
try { |
| 26 |
$response = $this->apiService->get($url); |
| 27 |
return $response; |
| 28 |
} catch (\Throwable $e) { |
| 29 |
Logger::error('خطا در دریافت اطلاعات نسخه: ' . $e->getMessage()); |
| 30 |
return null; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
public function checkForceUpdate() |
| 35 |
{ |
| 36 |
try { |
| 37 |
$response = $this->Fetch(); |
| 38 |
|
| 39 |
if (!is_array($response) || !isset($response['body'])) return false; |
| 40 |
|
| 41 |
$data = json_decode($response['body'], true); |
| 42 |
|
| 43 |
if (json_last_error() !== JSON_ERROR_NONE || !is_array($data) || !array_key_exists('force_update', $data)) { |
| 44 |
return false; |
| 45 |
} |
| 46 |
|
| 47 |
if (!empty($data['force_update'])) { |
| 48 |
update_option('sync_basalam_force_update', true); |
| 49 |
return true; |
| 50 |
} |
| 51 |
|
| 52 |
delete_option('sync_basalam_force_update'); |
| 53 |
return false; |
| 54 |
} catch (\Throwable $e) { |
| 55 |
Logger::error('خطا در بررسی force update: ' . $e->getMessage()); |
| 56 |
return false; |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|