VariantOptionValues.php
101 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Database\Tables; |
| 4 | |
| 5 | use SureCart\Database\Table; |
| 6 | |
| 7 | /** |
| 8 | * The integrations table class. |
| 9 | */ |
| 10 | class VariantOptionValues { |
| 11 | /** |
| 12 | * Holds the table instance. |
| 13 | * |
| 14 | * @var \SureCart\Database\Table |
| 15 | */ |
| 16 | protected $table; |
| 17 | |
| 18 | /** |
| 19 | * Version number for the table. |
| 20 | * Change this to update the table. |
| 21 | * |
| 22 | * @var integer |
| 23 | */ |
| 24 | protected $version = 2; |
| 25 | |
| 26 | /** |
| 27 | * Table name. |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | protected $name = 'surecart_variant_option_values'; |
| 32 | |
| 33 | /** |
| 34 | * Get the table dependency. |
| 35 | * |
| 36 | * @param \SureCart\Database\Table $table The table dependency. |
| 37 | */ |
| 38 | public function __construct( Table $table ) { |
| 39 | $this->table = $table; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get the table name. |
| 44 | * |
| 45 | * @return string |
| 46 | */ |
| 47 | public function getName() { |
| 48 | global $wpdb; |
| 49 | return $wpdb->prefix . $this->name; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Add relationships custom table |
| 54 | * This allows for simple, efficient queries |
| 55 | * |
| 56 | * @return mixed |
| 57 | */ |
| 58 | public function install() { |
| 59 | return $this->table->create( |
| 60 | $this->name, |
| 61 | ' |
| 62 | id bigint(20) unsigned NOT NULL auto_increment, |
| 63 | value varchar(155) NOT NULL, |
| 64 | name varchar(155) NOT NULL, |
| 65 | post_id bigint(20) unsigned NOT NULL, |
| 66 | product_id varchar(155) NOT NULL, |
| 67 | account_id varchar(155) NOT NULL, |
| 68 | created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(), |
| 69 | updated_at TIMESTAMP NULL, |
| 70 | PRIMARY KEY (id), |
| 71 | KEY value (value), |
| 72 | KEY name (name), |
| 73 | KEY post_id (post_id), |
| 74 | KEY product_id (product_id), |
| 75 | KEY account_id (account_id), |
| 76 | KEY created_at (created_at), |
| 77 | KEY updated_at (updated_at) |
| 78 | ', |
| 79 | $this->version |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Uninstall tables |
| 85 | * |
| 86 | * @return boolean |
| 87 | */ |
| 88 | public function uninstall() { |
| 89 | return $this->table->drop( $this->getName() ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Does the table exist? |
| 94 | * |
| 95 | * @return boolean |
| 96 | */ |
| 97 | public function exists() { |
| 98 | return $this->table->exists( $this->name ); |
| 99 | } |
| 100 | } |
| 101 |