forked from pagekit/extension-blog
-
Notifications
You must be signed in to change notification settings - Fork 2
/
scripts.php
123 lines (104 loc) · 5.91 KB
/
scripts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
return [
'install' => function ($app) {
$util = $app['db']->getUtility();
if ($util->tableExists('@blog_post') === false) {
$util->createTable('@blog_post', function ($table) {
$table->addColumn('id', 'integer', ['unsigned' => true, 'length' => 10, 'autoincrement' => true]);
$table->addColumn('user_id', 'integer', ['unsigned' => true, 'length' => 10, 'default' => 0]);
$table->addColumn('category_id', 'integer', ['unsigned' => true, 'length' => 10]);
$table->addColumn('slug', 'string', ['length' => 255]);
$table->addColumn('title', 'string', ['length' => 255]);
$table->addColumn('status', 'smallint');
$table->addColumn('date', 'datetime', ['notnull' => false]);
$table->addColumn('modified', 'datetime');
$table->addColumn('content', 'text');
$table->addColumn('excerpt', 'text');
$table->addColumn('comment_status', 'boolean', ['default' => false]);
$table->addColumn('comment_count', 'integer', ['default' => 0]);
$table->addColumn('data', 'json_array', ['notnull' => false]);
$table->addColumn('roles', 'simple_array', ['notnull' => false]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['slug'], '@BLOG_POST_SLUG');
$table->addIndex(['title'], '@BLOG_POST_TITLE');
$table->addIndex(['user_id'], '@BLOG_POST_USER_ID');
$table->addIndex(['category_id'], '@BLOG_POST_CATEGORY_ID');
$table->addIndex(['date'], '@BLOG_POST_DATE');
$table->addColumn('tag1', 'string', ['length' => 100, 'notnull' => false]);
$table->addColumn('tag2', 'string', ['length' => 100, 'notnull' => false]);
$table->addColumn('tag3', 'string', ['length' => 100, 'notnull' => false]);
$table->addColumn('tag4', 'string', ['length' => 100, 'notnull' => false]);
$table->addColumn('tag5', 'string', ['length' => 100, 'notnull' => false]);
$table->addColumn('tag6', 'string', ['length' => 100, 'notnull' => false]);
$table->addColumn('tag7', 'string', ['length' => 100, 'notnull' => false]);
$table->addColumn('tag8', 'string', ['length' => 100, 'notnull' => false]);
$table->addColumn('tag9', 'string', ['length' => 100, 'notnull' => false]);
$table->addColumn('tag10', 'string', ['length' => 100, 'notnull' => false]);
});
}
if ($util->tableExists('@blog_comment') === false) {
$util->createTable('@blog_comment', function ($table) {
$table->addColumn('id', 'integer', ['unsigned' => true, 'length' => 10, 'autoincrement' => true]);
$table->addColumn('parent_id', 'integer', ['unsigned' => true, 'length' => 10]);
$table->addColumn('post_id', 'integer', ['unsigned' => true, 'length' => 10]);
$table->addColumn('user_id', 'string', ['length' => 255]);
$table->addColumn('author', 'string', ['length' => 255]);
$table->addColumn('email', 'string', ['length' => 255]);
$table->addColumn('url', 'string', ['length' => 255, 'notnull' => false]);
$table->addColumn('ip', 'string', ['length' => 255]);
$table->addColumn('created', 'datetime');
$table->addColumn('content', 'text');
$table->addColumn('status', 'smallint');
$table->setPrimaryKey(['id']);
$table->addIndex(['author'], '@BLOG_COMMENT_AUTHOR');
$table->addIndex(['created'], '@BLOG_COMMENT_CREATED');
$table->addIndex(['status'], '@BLOG_COMMENT_STATUS');
$table->addIndex(['post_id'], '@BLOG_COMMENT_POST_ID');
$table->addIndex(['post_id', 'status'], '@BLOG_COMMENT_POST_ID_STATUS');
});
}
if ($util->tableExists('@blog_category') === false) {
$util->createTable('@blog_category', function ($table) {
$table->addColumn('id', 'integer', ['unsigned' => true, 'length' => 10, 'autoincrement' => true]);
$table->addColumn('title', 'string', ['length' => 255]);
$table->addColumn('slug', 'string', ['length' => 255]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['slug'], '@BLOG_POST_CATEGORY_SLUG');
});
}
},
'uninstall' => function ($app) {
$util = $app['db']->getUtility();
if ($util->tableExists('@blog_post')) {
$util->dropTable('@blog_post');
}
if ($util->tableExists('@blog_comment')) {
$util->dropTable('@blog_comment');
}
if ($util->tableExists('@blog_category')) {
$util->dropTable('@blog_category');
}
},
'updates' => [
'0.11.2' => function ($app) {
$db = $app['db'];
$util = $db->getUtility();
foreach (['@blog_post', '@blog_comment', '@blog_category'] as $name) {
$table = $util->getTable($name);
foreach ($table->getIndexes() as $name => $index) {
if ($name !== 'primary') {
$table->renameIndex($index->getName(), $app['db']->getPrefix() . $index->getName());
}
}
if ($app['db']->getDatabasePlatform()->getName() === 'sqlite') {
foreach ($table->getColumns() as $column) {
if (in_array($column->getType()->getName(), ['string', 'text'])) {
$column->setOptions(['customSchemaOptions' => ['collation' => 'NOCASE']]);
}
}
}
}
$util->migrate();
}
]
];