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