Bookable
2 years ago
Booking
1 year ago
Cache
5 years ago
Coupon
3 years ago
CustomField
2 years ago
Gallery
5 years ago
Location
4 years ago
Notification
1 year ago
Payment
1 year ago
Tax
2 years ago
User
1 year ago
AbstractDatabaseTable.php
5 years ago
AbstractDatabaseTable.php
82 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @copyright © TMS-Plugins. All rights reserved. |
| 4 | * @licence See LICENCE.md for license details. |
| 5 | */ |
| 6 | |
| 7 | namespace AmeliaBooking\Infrastructure\WP\InstallActions\DB; |
| 8 | |
| 9 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 10 | |
| 11 | /** |
| 12 | * Class AbstractDatabaseTable |
| 13 | * |
| 14 | * @package AmeliaBooking\Infrastructure\WP\InstallActions\DB |
| 15 | */ |
| 16 | class AbstractDatabaseTable |
| 17 | { |
| 18 | const TABLE = ''; |
| 19 | |
| 20 | /** |
| 21 | * @return string |
| 22 | * @throws InvalidArgumentException |
| 23 | */ |
| 24 | public static function getTableName() |
| 25 | { |
| 26 | if (!static::TABLE) { |
| 27 | throw new InvalidArgumentException('Table name is not provided'); |
| 28 | } |
| 29 | |
| 30 | global $wpdb; |
| 31 | return $wpdb->prefix . 'amelia_' . static::TABLE; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Create new table in the database |
| 36 | */ |
| 37 | public static function init() |
| 38 | { |
| 39 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 40 | dbDelta(static::buildTable()); |
| 41 | |
| 42 | global $wpdb; |
| 43 | |
| 44 | foreach (static::alterTable() as $command) { |
| 45 | $wpdb->query($command); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Delete table table from the database |
| 51 | * |
| 52 | * @throws InvalidArgumentException |
| 53 | */ |
| 54 | public static function delete() |
| 55 | { |
| 56 | global $wpdb; |
| 57 | |
| 58 | $table = self::getTableName(); |
| 59 | |
| 60 | $sql = "DROP TABLE IF EXISTS {$table};"; |
| 61 | $wpdb->query($sql); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @return boolean |
| 66 | */ |
| 67 | public static function isValidTablePrefix() |
| 68 | { |
| 69 | global $wpdb; |
| 70 | |
| 71 | return strlen($wpdb->prefix) <= 16; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @return array |
| 76 | */ |
| 77 | public static function alterTable() |
| 78 | { |
| 79 | return []; |
| 80 | } |
| 81 | } |
| 82 |