PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | src/Packetery/Module/Order/Repository.php +22 -48 trunk2.0.9 View file →
@@ -17,14 +17,11 @@
17 17 use Packetery\Core\Entity\PickupPoint;
18 18 use Packetery\Module\Carrier;
19 19 use Packetery\Module\Carrier\PacketaPickupPointsConfig;
20 20 use Packetery\Module\CustomsDeclaration;
21 -use Packetery\Module\Exception\DeleteErrorException;
22 21 use Packetery\Module\Exception\InvalidCarrierException;
23 -use Packetery\Module\Framework\WcAdapter;
24 22 use Packetery\Module\ModuleHelper;
25 23 use Packetery\Module\Shipping\ShippingProvider;
26 -use Packetery\Module\WcLogger;
27 24 use Packetery\Module\WpdbAdapter;
28 25 use WC_Order;
29 26 use WP_Post;
30 27
@@ -77,13 +74,8 @@
77 74 */
78 75 private $customsDeclarationRepository;
79 76
80 77 /**
81 - * @var WcAdapter
82 - */
83 - private $wcAdapter;
84 -
85 - /**
86 78 * Repository constructor.
87 79 *
88 80 * @param WpdbAdapter $wpdbAdapter WpdbAdapter.
89 81 * @param Builder $orderFactory Order factory.
@@ -97,10 +89,9 @@
97 89 Builder $orderFactory,
98 90 CoreHelper $coreHelper,
99 91 PacketaPickupPointsConfig $pickupPointsConfig,
100 92 Carrier\EntityRepository $carrierRepository,
101 - CustomsDeclaration\Repository $customsDeclarationRepository,
102 - WcAdapter $wcAdapter
93 + CustomsDeclaration\Repository $customsDeclarationRepository
103 94 ) {
104 95 $this->wpdbAdapter = $wpdbAdapter;
105 96 $this->builder = $orderFactory;
106 97 $this->coreHelper = $coreHelper;
@@ -106,9 +97,8 @@
106 97 $this->coreHelper = $coreHelper;
107 98 $this->pickupPointsConfig = $pickupPointsConfig;
108 99 $this->carrierRepository = $carrierRepository;
109 100 $this->customsDeclarationRepository = $customsDeclarationRepository;
110 - $this->wcAdapter = $wcAdapter;
111 101 }
112 102
113 103 /**
114 104 * Applies custom order status filter.
@@ -206,12 +196,10 @@
206 196 `is_exported` tinyint(1) NOT NULL,
207 197 `packet_id` varchar(15) NULL,
208 198 `packet_claim_id` varchar(15) NULL,
209 199 `packet_claim_password` varchar(10) NULL,
210 - `consign_password` varchar(10) NULL,
211 200 `is_label_printed` tinyint(1) NOT NULL,
212 201 `point_id` varchar(50) NULL,
213 - `point_place` varchar(100) NULL,
214 202 `point_name` varchar(150) NULL,
215 203 `point_url` varchar(255) NULL,
216 204 `point_street` varchar(120) NULL,
217 205 `point_zip` varchar(10) NULL,
@@ -238,8 +226,15 @@
238 226 return $this->wpdbAdapter->dbDelta( $createTableQuery, $this->wpdbAdapter->packeteryOrder );
239 227 }
240 228
241 229 /**
230 + * Drop table used to store orders.
231 + */
232 + public function drop(): void {
233 + $this->wpdbAdapter->query( 'DROP TABLE IF EXISTS `' . $this->wpdbAdapter->packeteryOrder . '`' );
234 + }
235 +
236 + /**
242 237 * @throws InvalidCarrierException InvalidCarrierException.
243 238 */
244 239 public function getById( int $id ): ?Order {
245 240 $wcOrder = $this->getWcOrderById( $id );
@@ -376,9 +371,8 @@
376 371 'is_exported' => (int) $order->isExported(),
377 372 'packet_id' => $order->getPacketId(),
378 373 'packet_claim_id' => $order->getPacketClaimId(),
379 374 'packet_claim_password' => $order->getPacketClaimPassword(),
380 - 'consign_password' => $order->getConsignPassword(),
381 375 'packet_status' => $order->getPacketStatus(),
382 376 'stored_until' => $this->coreHelper->getStringFromDateTime( $order->getStoredUntil(), CoreHelper::DATEPICKER_FORMAT ),
383 377 'is_label_printed' => (int) $order->isLabelPrinted(),
384 378 'carrier_number' => $order->getCarrierNumber(),
@@ -384,9 +378,8 @@
384 378 'carrier_number' => $order->getCarrierNumber(),
385 379 'weight' => $order->getWeight(),
386 380 'car_delivery_id' => $order->getCarDeliveryId(),
387 381 'point_id' => $point->getId(),
388 - 'point_place' => $point->getPlace(),
389 382 'point_name' => $point->getName(),
390 383 'point_url' => $point->getUrl(),
391 384 'point_street' => $point->getStreet(),
392 385 'point_zip' => $point->getZip(),
@@ -411,12 +404,12 @@
411 404 * Saves order.
412 405 *
413 406 * @param Order $order Order.
414 407 *
415 - * @return int|false The number of rows updated, or false on error.
408 + * @return void
416 409 */
417 - public function save( Order $order ) {
418 - return $this->saveData( $this->orderToDbArray( $order ) );
410 + public function save( Order $order ): void {
411 + $this->saveData( $this->orderToDbArray( $order ) );
419 412 }
420 413
421 414 /**
422 415 * Saves order data.
@@ -422,14 +415,13 @@
422 415 * Saves order data.
423 416 *
424 417 * @param array<string, int|string|null|DateTimeImmutable> $orderData Order data.
425 418 *
426 - * @return int|false The number of rows updated, or false on error.
419 + * @return void
427 420 */
428 - public function saveData( array $orderData ) {
421 + public function saveData( array $orderData ): void {
429 422 $this->onBeforeDataInsertion( $orderData );
430 -
431 - return $this->wpdbAdapter->insertReplaceHelper( $this->wpdbAdapter->packeteryOrder, $orderData, null, 'REPLACE' );
423 + $this->wpdbAdapter->insertReplaceHelper( $this->wpdbAdapter->packeteryOrder, $orderData, null, 'REPLACE' );
432 424 }
433 425
434 426 /**
435 427 * Calls logic before order data replace/insert.
@@ -450,9 +442,9 @@
450 442 if ( ( $pointId !== null && $pointId !== '' ) || ! $isLoggingActive || ! $this->pickupPointsConfig->isInternalPickupPointCarrier( $carrierId ) ) {
451 443 return;
452 444 }
453 445
454 - $wcLogger = $this->wcAdapter->getLogger();
446 + $wcLogger = wc_get_logger();
455 447 $dataToLog = [
456 448 'order' => $orderData,
457 449 'trace' => array_map(
458 450 static function ( array $item ): array {
@@ -695,42 +687,24 @@
695 687 * Deletes order data including customs declaration and its items from custom tables.
696 688 *
697 689 * @param int $orderId Order id.
698 690 *
699 - * @return bool true on success, false in case of db failure.
691 + * @return void
700 692 */
701 - public function delete( int $orderId ): bool {
702 - try {
703 - $this->customsDeclarationRepository->delete( (string) $orderId );
704 - $this->wpdbAdapter->delete( $this->wpdbAdapter->packeteryOrder, [ 'id' => $orderId ], '%d' );
705 -
706 - return true;
707 - } catch ( DeleteErrorException $e ) {
708 - return false;
709 - }
693 + public function delete( int $orderId ): void {
694 + $this->customsDeclarationRepository->delete( (string) $orderId );
695 + $this->wpdbAdapter->delete( $this->wpdbAdapter->packeteryOrder, [ 'id' => $orderId ], '%d' );
710 696 }
711 697
712 698 /**
713 699 * Fires after post deletion.
714 700 *
715 - * @param int|mixed $postId Post id.
716 - * @param WP_Post|mixed $post Post object.
701 + * @param int $postId Post id.
702 + * @param WP_Post $post Post object.
717 703 *
718 704 * @return void
719 705 */
720 - public function deletedPostHook( $postId, $post ): void {
721 - if ( ! is_int( $postId ) ) {
722 - WcLogger::logArgumentTypeError( __METHOD__, 'postId', 'int', $postId );
723 -
724 - return;
725 - }
726 -
727 - if ( ! $post instanceof WP_Post ) {
728 - WcLogger::logArgumentTypeError( __METHOD__, 'post', WP_Post::class, $post );
729 -
730 - return;
731 - }
732 -
706 + public function deletedPostHook( int $postId, WP_Post $post ): void {
733 707 // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
734 708 if ( $post->post_type === 'shop_order' ) {
735 709 $this->delete( $postId );
736 710 }