|
| 1 | +<?php |
| 2 | +namespace Screenfeed\AutoWPDB\Tests\Fixtures\src\Table; |
| 3 | + |
| 4 | +use Screenfeed\AutoWPDB\TableDefinition\AbstractTableDefinition; |
| 5 | + |
| 6 | +/** |
| 7 | + * Class that defines our custom table. |
| 8 | + * |
| 9 | + * @since 0.3 |
| 10 | + */ |
| 11 | +class CustomTable extends AbstractTableDefinition { |
| 12 | + protected $table_version; |
| 13 | + protected $schema; |
| 14 | + protected $short_name; |
| 15 | + protected $table_is_global; |
| 16 | + |
| 17 | + protected $default_table_version = 102; |
| 18 | + protected $default_schema = " |
| 19 | + file_id bigint(20) unsigned NOT NULL auto_increment, |
| 20 | + file_date datetime NOT NULL default '0000-00-00 00:00:00', |
| 21 | + path varchar(191) NOT NULL default '', |
| 22 | + mime_type varchar(100) NOT NULL default '', |
| 23 | + modified tinyint(1) unsigned NOT NULL default 0, |
| 24 | + width smallint(2) unsigned NOT NULL default 0, |
| 25 | + height smallint(2) unsigned NOT NULL default 0, |
| 26 | + file_size int(4) unsigned NOT NULL default 0, |
| 27 | + status varchar(20) default NULL, |
| 28 | + error varchar(255) default NULL, |
| 29 | + data longtext default NULL, |
| 30 | + PRIMARY KEY (file_id), |
| 31 | + UNIQUE KEY path (path), |
| 32 | + KEY status (status), |
| 33 | + KEY modified (modified)"; |
| 34 | + protected $default_short_name = 'foobar'; |
| 35 | + protected $default_table_is_global = true; |
| 36 | + |
| 37 | + public function get_table_version(): int { |
| 38 | + if ( ! isset( $this->table_version ) ) { |
| 39 | + $this->table_version = $this->default_table_version; |
| 40 | + } |
| 41 | + return $this->table_version; |
| 42 | + } |
| 43 | + |
| 44 | + public function get_table_short_name(): string { |
| 45 | + if ( ! isset( $this->short_name ) ) { |
| 46 | + $this->short_name = $this->default_short_name; |
| 47 | + } |
| 48 | + return $this->short_name; |
| 49 | + } |
| 50 | + |
| 51 | + public function is_table_global(): bool { |
| 52 | + if ( ! isset( $this->table_is_global ) ) { |
| 53 | + $this->table_is_global = $this->default_table_is_global; |
| 54 | + } |
| 55 | + return $this->table_is_global; |
| 56 | + } |
| 57 | + |
| 58 | + public function get_primary_key(): string { |
| 59 | + return 'file_id'; |
| 60 | + } |
| 61 | + |
| 62 | + public function get_column_placeholders(): array { |
| 63 | + return [ |
| 64 | + 'file_id' => '%d', |
| 65 | + 'file_date' => '%s', |
| 66 | + 'path' => '%s', |
| 67 | + 'mime_type' => '%s', |
| 68 | + 'modified' => '%d', |
| 69 | + 'width' => '%d', |
| 70 | + 'height' => '%d', |
| 71 | + 'file_size' => '%d', |
| 72 | + 'status' => '%s', |
| 73 | + 'error' => '%s', |
| 74 | + 'data' => '%s', |
| 75 | + ]; |
| 76 | + } |
| 77 | + |
| 78 | + public function get_column_defaults(): array { |
| 79 | + return [ |
| 80 | + 'file_id' => 0, |
| 81 | + 'file_date' => '0000-00-00 00:00:00', |
| 82 | + 'path' => '', |
| 83 | + 'mime_type' => '', |
| 84 | + 'modified' => 0, |
| 85 | + 'width' => 0, |
| 86 | + 'height' => 0, |
| 87 | + 'file_size' => 0, |
| 88 | + 'status' => null, |
| 89 | + 'error' => null, |
| 90 | + 'data' => [], |
| 91 | + ]; |
| 92 | + } |
| 93 | + |
| 94 | + public function get_table_schema(): string { |
| 95 | + if ( ! isset( $this->schema ) ) { |
| 96 | + $this->schema = $this->default_schema; |
| 97 | + } |
| 98 | + return $this->schema; |
| 99 | + } |
| 100 | + |
| 101 | + /** ----------------------------------------------------------------------------------------- */ |
| 102 | + /** SETTERS ================================================================================= */ |
| 103 | + /** ----------------------------------------------------------------------------------------- */ |
| 104 | + |
| 105 | + public function set_table_version( $table_version ) { |
| 106 | + $this->table_version = $table_version; |
| 107 | + } |
| 108 | + |
| 109 | + public function set_table_short_name( $short_name ) { |
| 110 | + $this->short_name = $short_name; |
| 111 | + } |
| 112 | + |
| 113 | + public function set_table_schema( $schema ) { |
| 114 | + $this->schema = $schema; |
| 115 | + } |
| 116 | + |
| 117 | + public function set_table_is_global( $table_is_global ) { |
| 118 | + $this->table_is_global = $table_is_global; |
| 119 | + } |
| 120 | +} |
0 commit comments