← All changes
|
src/Controllers/Hooks/Order/class-order-controller.php
+31
-4
3.0.6
→
4.1.0
View file →
| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | namespace SeQura\WC\Controllers\Hooks\Order; |
| 10 | 10 | |
| 11 | 11 | use SeQura\Core\Infrastructure\Logger\LogContextData; |
| 12 | 12 | use SeQura\WC\Controllers\Controller; |
| 13 | -use SeQura\WC\Services\Interface_Logger_Service; | |
| 13 | +use SeQura\WC\Services\Log\Interface_Logger_Service; | |
| 14 | 14 | use SeQura\WC\Services\Order\Interface_Order_Service; |
| 15 | 15 | use Throwable; |
| 16 | 16 | use WC_Order; |
| 17 | 17 | |
| @@ -32,9 +32,9 @@ | ||
| 32 | 32 | */ |
| 33 | 33 | public function __construct( |
| 34 | 34 | Interface_Logger_Service $logger, |
| 35 | 35 | string $templates_path, |
| 36 | - Interface_Order_Service $order_service | |
| 36 | + Interface_Order_Service $order_service | |
| 37 | 37 | ) { |
| 38 | 38 | parent::__construct( $logger, $templates_path ); |
| 39 | 39 | $this->order_service = $order_service; |
| 40 | 40 | |
| @@ -98,9 +98,9 @@ | ||
| 98 | 98 | \set_transient( |
| 99 | 99 | $this->get_notices_transient( $order_id ), |
| 100 | 100 | array( |
| 101 | 101 | array( |
| 102 | - 'notice' => \__( 'An error occurred while updating the order data in seQura.', 'sequra' ), // TODO: improve message with link to simba. | |
| 102 | + 'notice' => __( 'An error occurred while updating the order data in seQura.', 'sequra' ), // TODO: improve message with link to simba. | |
| 103 | 103 | 'type' => 'error', |
| 104 | 104 | 'dismissible' => true, |
| 105 | 105 | ), |
| 106 | 106 | ), |
| @@ -128,9 +128,9 @@ | ||
| 128 | 128 | if ( ! \is_admin() || ! isset( $_GET['post'], $_GET['action'] ) || 'edit' !== $_GET['action'] ) { |
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - $order = wc_get_order( absint( $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification | |
| 132 | + $order = wc_get_order( \absint( $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification | |
| 133 | 133 | if ( ! $order instanceof WC_Order ) { |
| 134 | 134 | return; |
| 135 | 135 | } |
| 136 | 136 | |
| @@ -156,6 +156,33 @@ | ||
| 156 | 156 | $args = array( |
| 157 | 157 | 'sequra_link' => $this->order_service->get_link_to_sequra_back_office( $order ), |
| 158 | 158 | ); |
| 159 | 159 | \wc_get_template( 'admin/order_details.php', $args, '', $this->templates_path ); |
| 160 | + } | |
| 161 | + | |
| 162 | + /** | |
| 163 | + * Cleanup orders | |
| 164 | + * | |
| 165 | + * @return void | |
| 166 | + */ | |
| 167 | + public function cleanup_orders() { | |
| 168 | + $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ ); | |
| 169 | + $this->order_service->cleanup_orders(); | |
| 170 | + } | |
| 171 | + | |
| 172 | + /** | |
| 173 | + * Respond to the sequra_order_migration_add_indexes hook | |
| 174 | + * | |
| 175 | + * @param string $hook Hook name that triggered the action. | |
| 176 | + */ | |
| 177 | + public function migrate_orders_to_use_indexes( $hook ) { | |
| 178 | + $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ ); | |
| 179 | + | |
| 180 | + if ( $this->order_service->is_migration_complete() ) { | |
| 181 | + $this->logger->log_debug( 'Indexing process is done. Job will be unscheduled', __FUNCTION__, __CLASS__ ); | |
| 182 | + \wp_clear_scheduled_hook( $hook, array( $hook ) ); | |
| 183 | + return; | |
| 184 | + } | |
| 185 | + | |
| 186 | + $this->order_service->migrate_data(); | |
| 160 | 187 | } |
| 161 | 188 | } |