| @@ -8,10 +8,9 @@ | ||
| 8 | 8 | declare( strict_types=1 ); |
| 9 | 9 | |
| 10 | 10 | namespace Packetery\Module; |
| 11 | 11 | |
| 12 | -use Packetery\Module\Exception\DeleteErrorException; | |
| 13 | -use Packetery\Module\Framework\WcAdapter; | |
| 12 | +use WC_Logger; | |
| 14 | 13 | |
| 15 | 14 | /** |
| 16 | 15 | * Class WpdbAdapter |
| 17 | 16 | * |
| @@ -89,20 +88,14 @@ | ||
| 89 | 88 | */ |
| 90 | 89 | private $wpdb; |
| 91 | 90 | |
| 92 | 91 | /** |
| 93 | - * @var WcAdapter | |
| 94 | - */ | |
| 95 | - private $wcAdapter; | |
| 96 | - | |
| 97 | - /** | |
| 98 | 92 | * Constructor. |
| 99 | 93 | * |
| 100 | 94 | * @param \wpdb $wpdb Wpdb. |
| 101 | 95 | */ |
| 102 | - public function __construct( \wpdb $wpdb, WcAdapter $wcAdapter ) { | |
| 103 | - $this->wpdb = $wpdb; | |
| 104 | - $this->wcAdapter = $wcAdapter; | |
| 96 | + public function __construct( \wpdb $wpdb ) { | |
| 97 | + $this->wpdb = $wpdb; | |
| 105 | 98 | } |
| 106 | 99 | |
| 107 | 100 | /** |
| 108 | 101 | * @param string $query SQL query. |
| @@ -183,17 +176,14 @@ | ||
| 183 | 176 | * @param string $table Table name. |
| 184 | 177 | * @param array<string, int|string> $where A named array of WHERE clauses (in column => value pairs). |
| 185 | 178 | * @param string|null $whereFormat Optional. An array of formats to be mapped to each of the values in $where. |
| 186 | 179 | * |
| 187 | - * @return int The number of rows deleted, throws DeleteErrorException on error. | |
| 188 | - * @throws DeleteErrorException | |
| 180 | + * @return int|false The number of rows updated, or false on error. | |
| 189 | 181 | */ |
| 190 | - public function delete( string $table, array $where, ?string $whereFormat = null ): int { | |
| 182 | + public function delete( string $table, array $where, ?string $whereFormat = null ) { | |
| 191 | 183 | $result = $this->wpdb->delete( $table, $where, $whereFormat ); |
| 192 | 184 | if ( $result === false ) { |
| 193 | 185 | $this->handleError(); |
| 194 | - | |
| 195 | - throw new DeleteErrorException( "Could not delete from table `{$table}`." ); | |
| 196 | 186 | } |
| 197 | 187 | |
| 198 | 188 | return $result; |
| 199 | 189 | } |
| @@ -302,9 +292,15 @@ | ||
| 302 | 292 | * |
| 303 | 293 | * @return void |
| 304 | 294 | */ |
| 305 | 295 | private function logError( string $errorMessage ): void { |
| 306 | - $wcLogger = $this->wcAdapter->getLogger(); | |
| 296 | + /** | |
| 297 | + * WC logger. | |
| 298 | + * | |
| 299 | + * @var WC_Logger $wcLogger | |
| 300 | + */ | |
| 301 | + $wcLogger = wc_get_logger(); | |
| 302 | + | |
| 307 | 303 | $wcLogger->error( sprintf( 'wpdb: %s', $errorMessage ), [ 'source' => 'packeta' ] ); |
| 308 | 304 | } |
| 309 | 305 | |
| 310 | 306 | /** |
| @@ -398,9 +394,14 @@ | ||
| 398 | 394 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 399 | 395 | $result1 = dbDelta( $createTableQuery ); |
| 400 | 396 | $result2 = dbDelta( $createTableQuery ); |
| 401 | 397 | |
| 402 | - $wcLogger = $this->wcAdapter->getLogger(); | |
| 398 | + /** | |
| 399 | + * WC logger. | |
| 400 | + * | |
| 401 | + * @var WC_Logger $wcLogger | |
| 402 | + */ | |
| 403 | + $wcLogger = wc_get_logger(); | |
| 403 | 404 | foreach ( $result1 as $tableOrColumn => $message ) { |
| 404 | 405 | $wcLogger->info( sprintf( 'dbDelta: %s => %s', $tableOrColumn, $message ), [ 'source' => 'packeta' ] ); |
| 405 | 406 | } |
| 406 | 407 | |
| @@ -472,10 +473,6 @@ | ||
| 472 | 473 | * @return string |
| 473 | 474 | */ |
| 474 | 475 | public function escLike( string $text ): string { |
| 475 | 476 | return $this->wpdb->esc_like( $text ); |
| 476 | - } | |
| 477 | - | |
| 478 | - public function dbServerInfo(): string { | |
| 479 | - return $this->wpdb->db_server_info(); | |
| 480 | 477 | } |
| 481 | 478 | } |