PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.18
ووسلام – همگام سازی ووکامرس و باسلام v1.10.18
1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 1.8.7 1.8.4 All 51 releases
sync-basalam / includes / Services / FetchVersionDetail.php

FetchVersionDetail.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.18, at includes/Services/FetchVersionDetail.php

70 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Services;
4
5 use SyncBasalam\Config\Endpoints;
6 use SyncBasalam\Logger\Logger;
7 use SyncBasalam\Services\ApiServiceManager;
8 use SyncBasalam\Services\ForceUpdateGate;
9
10 defined('ABSPATH') || exit;
11
12 class FetchVersionDetail
13 {
14 private $apiService;
15 private $version;
16
17 public function __construct($version)
18 {
19 $this->apiService = syncBasalamContainer()->get(ApiServiceManager::class);
20 $this->version = $version;
21 }
22
23 public function Fetch()
24 {
25 $url = Endpoints::HAMSALAM_VERSION_DETAIL . '?site_url=' . get_site_url() . '&current_version=' . $this->version;
26 try {
27 $response = $this->apiService->get($url);
28 return $response;
29 } catch (\Throwable $e) {
30 Logger::error('خطا در دریافت اطلاعات نسخه: ' . $e->getMessage());
31 return null;
32 }
33 }
34
35 public function checkForceUpdate()
36 {
37 if (wp_get_environment_type() === 'local') {
38 delete_option('sync_basalam_force_update');
39 return false;
40 }
41
42 try {
43 $response = $this->Fetch();
44
45 if (!is_array($response) || !isset($response['body'])) return false;
46
47 $data = json_decode($response['body'], true);
48
49 if (json_last_error() !== JSON_ERROR_NONE || !is_array($data) || !array_key_exists('force_update', $data)) {
50 return false;
51 }
52
53 if (ForceUpdateGate::shouldHonorRemoteFlag(
54 $data['force_update'],
55 $this->version,
56 isset($data['latest_version']) ? (string) $data['latest_version'] : null
57 )) {
58 update_option('sync_basalam_force_update', true);
59 return true;
60 }
61
62 delete_option('sync_basalam_force_update');
63 return false;
64 } catch (\Throwable $e) {
65 Logger::error('خطا در بررسی force update: ' . $e->getMessage());
66 return false;
67 }
68 }
69 }
70