| @@ -12,9 +12,8 @@ | ||
| 12 | 12 | use Packetery\Core; |
| 13 | 13 | use Packetery\Core\Log\ILogger; |
| 14 | 14 | use Packetery\Core\Log\Record; |
| 15 | 15 | use Packetery\Module\Carrier\EntityRepository; |
| 16 | -use Packetery\Module\Options\OptionNames; | |
| 17 | 16 | use Packetery\Module\Options\OptionsProvider; |
| 18 | 17 | use Packetery\Module\Upgrade\Version_1_4_2; |
| 19 | 18 | |
| 20 | 19 | /** |
| @@ -130,14 +129,17 @@ | ||
| 130 | 129 | * |
| 131 | 130 | * @return void |
| 132 | 131 | */ |
| 133 | 132 | public function check(): void { |
| 134 | - $oldVersion = get_option( OptionNames::VERSION ); | |
| 133 | + $oldVersion = get_option( 'packetery_version' ); | |
| 135 | 134 | if ( $oldVersion === Plugin::VERSION ) { |
| 136 | 135 | return; |
| 137 | 136 | } |
| 138 | 137 | |
| 139 | - $this->runCreateTables(); | |
| 138 | + $this->createLogTable(); | |
| 139 | + $this->createCarrierTable(); | |
| 140 | + $this->createOrderTable(); | |
| 141 | + $this->createCustomsDeclarationTables(); | |
| 140 | 142 | |
| 141 | 143 | // If no previous version detected, no upgrade will be run. |
| 142 | 144 | if ( $oldVersion !== null && $oldVersion !== false ) { |
| 143 | 145 | if ( version_compare( $oldVersion, '1.2.0', '<' ) ) { |
| @@ -191,9 +193,9 @@ | ||
| 191 | 193 | |
| 192 | 194 | if ( version_compare( $oldVersion, '1.7.0', '<' ) ) { |
| 193 | 195 | $orderStatusAutoChange = $this->optionsProvider->isOrderStatusAutoChangeEnabled(); |
| 194 | 196 | $autoOrderStatus = $this->optionsProvider->getAutoOrderStatus(); |
| 195 | - $syncSettings = $this->optionsProvider->getOptionsByName( OptionNames::PACKETERY_SYNC ); | |
| 197 | + $syncSettings = $this->optionsProvider->getOptionsByName( OptionsProvider::OPTION_NAME_PACKETERY_SYNC ); | |
| 196 | 198 | if ( $orderStatusAutoChange ) { |
| 197 | 199 | $syncSettings['allow_order_status_change'] = true; |
| 198 | 200 | } |
| 199 | 201 | if ( $autoOrderStatus !== null ) { |
| @@ -201,51 +203,36 @@ | ||
| 201 | 203 | Core\Entity\PacketStatus::RECEIVED_DATA => $autoOrderStatus, |
| 202 | 204 | ]; |
| 203 | 205 | } |
| 204 | 206 | |
| 205 | - update_option( OptionNames::PACKETERY_SYNC, $syncSettings ); | |
| 207 | + update_option( OptionsProvider::OPTION_NAME_PACKETERY_SYNC, $syncSettings ); | |
| 206 | 208 | } |
| 207 | 209 | |
| 208 | 210 | if ( version_compare( $oldVersion, '1.7.1', '<' ) ) { |
| 209 | - $syncSettings = $this->optionsProvider->getOptionsByName( OptionNames::PACKETERY_SYNC ); | |
| 211 | + $syncSettings = $this->optionsProvider->getOptionsByName( OptionsProvider::OPTION_NAME_PACKETERY_SYNC ); | |
| 210 | 212 | if ( |
| 211 | 213 | isset( $syncSettings['order_status_change_packet_statuses'][ Core\Entity\PacketStatus::RECEIVED_DATA ] ) && |
| 212 | 214 | $syncSettings['order_status_change_packet_statuses'][ Core\Entity\PacketStatus::RECEIVED_DATA ] === '' |
| 213 | 215 | ) { |
| 214 | 216 | unset( $syncSettings['order_status_change_packet_statuses'][ Core\Entity\PacketStatus::RECEIVED_DATA ] ); |
| 215 | - update_option( OptionNames::PACKETERY_SYNC, $syncSettings ); | |
| 217 | + update_option( OptionsProvider::OPTION_NAME_PACKETERY_SYNC, $syncSettings ); | |
| 216 | 218 | } |
| 217 | 219 | } |
| 218 | 220 | |
| 219 | 221 | if ( version_compare( $oldVersion, '1.8.0', '<' ) ) { |
| 220 | - $generalSettings = $this->optionsProvider->getOptionsByName( OptionNames::PACKETERY ); | |
| 222 | + $generalSettings = $this->optionsProvider->getOptionsByName( OptionsProvider::OPTION_NAME_PACKETERY ); | |
| 221 | 223 | if ( isset( $generalSettings['cod_payment_method'] ) ) { |
| 222 | 224 | $generalSettings['cod_payment_methods'] = [ $generalSettings['cod_payment_method'] ]; |
| 223 | 225 | unset( $generalSettings['cod_payment_method'] ); |
| 224 | 226 | } |
| 225 | 227 | |
| 226 | - update_option( OptionNames::PACKETERY, $generalSettings ); | |
| 228 | + update_option( OptionsProvider::OPTION_NAME_PACKETERY, $generalSettings ); | |
| 227 | 229 | } |
| 228 | - | |
| 229 | - if ( version_compare( $oldVersion, '2.1.0', '<' ) ) { | |
| 230 | - add_option( OptionNames::PACKETERY_TUTORIAL_ORDER_DETAIL_EDIT_PACKET, 0 ); | |
| 231 | - add_option( OptionNames::PACKETERY_TUTORIAL_ORDER_GRID_EDIT_PACKET, 0 ); | |
| 232 | - } | |
| 233 | - } else { | |
| 234 | - add_option( OptionNames::PACKETERY_TUTORIAL_ORDER_DETAIL_EDIT_PACKET, 1 ); | |
| 235 | - add_option( OptionNames::PACKETERY_TUTORIAL_ORDER_GRID_EDIT_PACKET, 1 ); | |
| 236 | 230 | } |
| 237 | 231 | |
| 238 | - update_option( OptionNames::VERSION, Plugin::VERSION ); | |
| 232 | + update_option( 'packetery_version', Plugin::VERSION ); | |
| 239 | 233 | } |
| 240 | 234 | |
| 241 | - public function runCreateTables(): void { | |
| 242 | - $this->createLogTable(); | |
| 243 | - $this->createCarrierTable(); | |
| 244 | - $this->createOrderTable(); | |
| 245 | - $this->createCustomsDeclarationTables(); | |
| 246 | - } | |
| 247 | - | |
| 248 | 235 | /** |
| 249 | 236 | * Migrates WP order metadata. |
| 250 | 237 | * |
| 251 | 238 | * @return void |
| @@ -311,9 +298,8 @@ | ||
| 311 | 298 | if ( $this->getMetaAsNullableString( $order, self::META_POINT_ID ) !== null ) { |
| 312 | 299 | $orderEntity->setPickupPoint( |
| 313 | 300 | new Core\Entity\PickupPoint( |
| 314 | 301 | $this->getMetaAsNullableString( $order, self::META_POINT_ID ), |
| 315 | - null, | |
| 316 | 302 | $this->getMetaAsNullableString( $order, self::META_POINT_NAME ), |
| 317 | 303 | $this->getMetaAsNullableString( $order, self::META_POINT_CITY ), |
| 318 | 304 | $this->getMetaAsNullableString( $order, self::META_POINT_ZIP ), |
| 319 | 305 | $this->getMetaAsNullableString( $order, self::META_POINT_STREET ), |
| @@ -335,9 +321,8 @@ | ||
| 335 | 321 | $orderEntity->setDeliveryAddress( $validatedAddress ); |
| 336 | 322 | } |
| 337 | 323 | |
| 338 | 324 | $this->orderRepository->save( $orderEntity ); |
| 339 | - // Ignore errors. Save the metadata even if the previous call fails. | |
| 340 | 325 | $order->save_meta_data(); |
| 341 | 326 | } |
| 342 | 327 | } |
| 343 | 328 | |