|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Queryr\EntityStore; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\DBALException; |
|
6
|
|
|
use Doctrine\DBAL\Schema\AbstractSchemaManager; |
|
7
|
|
|
use Doctrine\DBAL\Schema\Table; |
|
8
|
|
|
use Doctrine\DBAL\Types\Type; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @licence GNU GPL v2+ |
|
12
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
13
|
|
|
*/ |
|
14
|
|
|
class EntityStoreInstaller { |
|
15
|
|
|
|
|
16
|
|
|
private $schemaManager; |
|
17
|
|
|
private $config; |
|
18
|
|
|
|
|
19
|
2 |
|
public function __construct( AbstractSchemaManager $schemaManager, EntityStoreConfig $config ) { |
|
20
|
2 |
|
$this->schemaManager = $schemaManager; |
|
21
|
2 |
|
$this->config = $config; |
|
22
|
2 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @throws DBALException |
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function install() { |
|
28
|
2 |
|
$this->schemaManager->createTable( $this->newItemTable() ); |
|
29
|
2 |
|
$this->schemaManager->createTable( $this->newPropertyTable() ); |
|
30
|
2 |
|
} |
|
31
|
|
|
|
|
32
|
2 |
|
private function newItemTable() { |
|
33
|
2 |
|
$table = new Table( $this->config->getItemTableName() ); |
|
34
|
|
|
|
|
35
|
2 |
|
$table->addColumn( 'item_id', Type::BIGINT ); |
|
36
|
2 |
|
$table->addColumn( 'item_type', Type::BIGINT, [ 'notnull' => false ] ); |
|
37
|
2 |
|
$table->addColumn( 'page_title', Type::STRING, [ 'length' => 255 ] ); |
|
38
|
2 |
|
$table->addColumn( 'revision_id', Type::BIGINT ); |
|
39
|
2 |
|
$table->addColumn( 'revision_time', Type::STRING, [ 'length' => 25 ] ); |
|
40
|
2 |
|
$table->addColumn( 'item_json', Type::BLOB ); |
|
41
|
2 |
|
$table->addColumn( 'item_label_en', Type::STRING, [ 'length' => 255, 'notnull' => false ] ); |
|
42
|
2 |
|
$table->addColumn( 'wp_title_en', Type::STRING, [ 'length' => 255, 'notnull' => false ] ); |
|
43
|
|
|
|
|
44
|
2 |
|
$table->addIndex( [ 'item_id' ] ); |
|
45
|
2 |
|
$table->addIndex( [ 'item_type' ] ); |
|
46
|
2 |
|
$table->addIndex( [ 'page_title' ] ); |
|
47
|
2 |
|
$table->addIndex( [ 'revision_id' ] ); |
|
48
|
2 |
|
$table->addIndex( [ 'revision_time' ] ); |
|
49
|
2 |
|
$table->addIndex( [ 'wp_title_en' ] ); |
|
50
|
|
|
|
|
51
|
2 |
|
return $table; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
2 |
|
private function newPropertyTable() { |
|
55
|
2 |
|
$table = new Table( $this->config->getPropertyTableName() ); |
|
56
|
|
|
|
|
57
|
2 |
|
$table->addColumn( 'property_id', Type::BIGINT ); |
|
58
|
2 |
|
$table->addColumn( 'property_json', Type::BLOB ); |
|
59
|
2 |
|
$table->addColumn( 'page_title', Type::STRING, [ 'length' => 255 ] ); |
|
60
|
2 |
|
$table->addColumn( 'revision_id', Type::BIGINT ); |
|
61
|
2 |
|
$table->addColumn( 'revision_time', Type::STRING, [ 'length' => 25 ] ); |
|
62
|
2 |
|
$table->addColumn( 'property_type', Type::STRING, [ 'length' => 30 ] ); |
|
63
|
|
|
|
|
64
|
2 |
|
$table->addIndex( [ 'property_id' ] ); |
|
65
|
2 |
|
$table->addIndex( [ 'page_title' ] ); |
|
66
|
2 |
|
$table->addIndex( [ 'revision_id' ] ); |
|
67
|
2 |
|
$table->addIndex( [ 'revision_time' ] ); |
|
68
|
2 |
|
$table->addIndex( [ 'property_type' ] ); |
|
69
|
|
|
|
|
70
|
2 |
|
return $table; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
public function uninstall() { |
|
74
|
1 |
|
$this->schemaManager->dropTable( $this->config->getItemTableName() ); |
|
75
|
1 |
|
$this->schemaManager->dropTable( $this->config->getPropertyTableName() ); |
|
76
|
1 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
} |