| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Description of MigrateService |
| 5 |
* |
| 6 |
* @author Ali2Woo Team |
| 7 |
* |
| 8 |
* @autoload: a2wl_admin_init |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace AliNext_Lite;; |
| 12 |
|
| 13 |
use Throwable; |
| 14 |
|
| 15 |
class MigrateService |
| 16 |
{ |
| 17 |
private ProductShippingDataRepository $ProductShippingDataRepository; |
| 18 |
private BackgroundProcessFactory $BackgroundProcessFactory; |
| 19 |
|
| 20 |
public function __construct( |
| 21 |
ProductShippingDataRepository $ProductShippingDataRepository, |
| 22 |
BackgroundProcessFactory $BackgroundProcessFactory, |
| 23 |
) { |
| 24 |
$this->ProductShippingDataRepository = $ProductShippingDataRepository; |
| 25 |
$this->BackgroundProcessFactory = $BackgroundProcessFactory; |
| 26 |
|
| 27 |
$this->migrate(); |
| 28 |
} |
| 29 |
|
| 30 |
public function migrate(): void |
| 31 |
{ |
| 32 |
// delete_option('a2wl_db_version'); |
| 33 |
$cur_version = get_option('a2wl_db_version', ''); |
| 34 |
if (version_compare($cur_version, "3.0.8", '<')) { |
| 35 |
$this->migrate_to_308(); |
| 36 |
} |
| 37 |
|
| 38 |
if (version_compare($cur_version, "3.5.2", '<')) { |
| 39 |
$this->migrate_to_352(); |
| 40 |
} |
| 41 |
|
| 42 |
if (version_compare($cur_version, "3.5.4", '<')) { |
| 43 |
$this->migrate_to_354(); |
| 44 |
} |
| 45 |
|
| 46 |
if (version_compare($cur_version, "3.5.9", '<')) { |
| 47 |
$this->migrate_to_359(); |
| 48 |
} |
| 49 |
|
| 50 |
if (version_compare($cur_version, "3.6.3", '<')) { |
| 51 |
$this->migrate_to_363(); |
| 52 |
} |
| 53 |
|
| 54 |
if (version_compare($cur_version, "3.7.1", '<')) { |
| 55 |
$this->migrate_to_371(); |
| 56 |
} |
| 57 |
|
| 58 |
if (version_compare($cur_version, "3.7.3", '<')) { |
| 59 |
$this->migrate_to_373(); |
| 60 |
} |
| 61 |
|
| 62 |
if (version_compare($cur_version, A2WL()->version, '<')) { |
| 63 |
update_option('a2wl_db_version', A2WL()->version, 'no'); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
private function migrate_to_308(): void |
| 68 |
{ |
| 69 |
a2wl_error_log('migrate to 3.0.8'); |
| 70 |
if (class_exists('AliNext_Lite\ProductShippingMeta')) { |
| 71 |
ProductShippingMeta::clear_in_all_product(); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
private function migrate_to_352(): void |
| 76 |
{ |
| 77 |
a2wl_error_log('migrate to 3.5.2'); |
| 78 |
$this->ProductShippingDataRepository->clear(); |
| 79 |
} |
| 80 |
|
| 81 |
private function migrate_to_354(): void |
| 82 |
{ |
| 83 |
a2wl_error_log('migrate to 3.5.4'); |
| 84 |
$this->ProductShippingDataRepository->clear(); |
| 85 |
} |
| 86 |
|
| 87 |
public function migrate_to_359(): void |
| 88 |
{ |
| 89 |
a2wl_error_log('migrate 3.5.9'); |
| 90 |
$cap = Capability::pluginAccess(); |
| 91 |
$allowManager = false; |
| 92 |
|
| 93 |
if (A2WL()->isAnPlugin()) { |
| 94 |
$allowManager = get_setting(Settings::SETTING_ALLOW_SHOP_MANAGER); |
| 95 |
} |
| 96 |
|
| 97 |
foreach (PageGuardHelper::getAllRoles() as $roleKey) { |
| 98 |
$role = get_role($roleKey); |
| 99 |
if (!$role) { |
| 100 |
continue; |
| 101 |
} |
| 102 |
|
| 103 |
if ($roleKey === PageGuardHelper::ROLE_ADMIN || $allowManager) { |
| 104 |
$role->add_cap($cap); |
| 105 |
} else { |
| 106 |
$role->remove_cap($cap); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
public function migrate_to_363(): void |
| 112 |
{ |
| 113 |
a2wl_error_log('migrate 3.6.3'); |
| 114 |
set_setting(Settings::SETTING_DELIVERY_INFO_DISPLAY_MODE, 'default'); |
| 115 |
} |
| 116 |
|
| 117 |
private function migrate_to_371(): void |
| 118 |
{ |
| 119 |
a2wl_error_log('migrate to 3.7.1'); |
| 120 |
|
| 121 |
$activationDate = get_option(Settings::SETTING_PLUGIN_ACTIVATION_DATE); |
| 122 |
if (!$activationDate) { |
| 123 |
update_option(Settings::SETTING_PLUGIN_ACTIVATION_DATE, time()); |
| 124 |
} |
| 125 |
|
| 126 |
set_setting(Settings::SETTING_TIP_OF_DAY, TipOfDay::getDefaultData()); |
| 127 |
settings()->commit(); |
| 128 |
} |
| 129 |
|
| 130 |
public function migrate_to_373(): void |
| 131 |
{ |
| 132 |
a2wl_error_log('migrate to 3.7.3: dispatch AliExpress image URL domain migration'); |
| 133 |
|
| 134 |
try { |
| 135 |
/** @var MigrateAlicdnUrlProcess $process */ |
| 136 |
$process = $this->BackgroundProcessFactory->createProcessByCode( |
| 137 |
MigrateAlicdnUrlProcess::ACTION_CODE |
| 138 |
); |
| 139 |
$process->pushToQueue()->save()->dispatch(); |
| 140 |
} catch (Throwable $e) { |
| 141 |
a2wl_error_log('[AlicdnUrlMigrate] Failed to dispatch migration job: ' . $e->getMessage()); |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|