woocommerce
/
src
/
Internal
/
DataStores
/
StockNotifications
/
StockNotificationsMetaDataStore.php
StockNotificationsMetaDataStore.php
66 lines
| 1 | <?php |
| 2 | /** |
| 3 | * StockNotificationsMetaDataStore class file. |
| 4 | */ |
| 5 | |
| 6 | declare( strict_types = 1 ); |
| 7 | |
| 8 | namespace Automattic\WooCommerce\Internal\DataStores\StockNotifications; |
| 9 | |
| 10 | use Automattic\WooCommerce\Internal\DataStores\CustomMetaDataStore; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | /** |
| 15 | * Mimics a WP metadata (i.e. add_metadata(), get_metadata() and friends) implementation using a custom table. |
| 16 | */ |
| 17 | class StockNotificationsMetaDataStore extends CustomMetaDataStore { |
| 18 | |
| 19 | /** |
| 20 | * Returns the name of the table used for storage. |
| 21 | * |
| 22 | * @return string |
| 23 | */ |
| 24 | public function get_table_name() { |
| 25 | global $wpdb; |
| 26 | return $wpdb->prefix . 'wc_stock_notificationmeta'; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Returns the name of the field/column used for identifiying metadata entries. |
| 31 | * |
| 32 | * @return string |
| 33 | */ |
| 34 | protected function get_meta_id_field() { |
| 35 | return 'id'; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Returns the name of the field/column used for associating meta with objects. |
| 40 | * |
| 41 | * @return string |
| 42 | */ |
| 43 | protected function get_object_id_field() { |
| 44 | return 'notification_id'; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Delete by notification ID. |
| 49 | * |
| 50 | * @param int $notification_id The notification ID. |
| 51 | * @return bool True if the metadata were deleted, false otherwise. |
| 52 | */ |
| 53 | public function delete_by_notification_id( $notification_id ) { |
| 54 | global $wpdb; |
| 55 | |
| 56 | $table = $this->get_table_name(); |
| 57 | $result = $wpdb->delete( |
| 58 | $table, |
| 59 | array( 'notification_id' => $notification_id ), |
| 60 | array( '%d' ) |
| 61 | ); |
| 62 | |
| 63 | return false === $result ? false : true; |
| 64 | } |
| 65 | } |
| 66 |