-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdates.php
131 lines (113 loc) · 2.62 KB
/
updates.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
124
125
126
127
128
129
130
131
<?php
/*
* This file is part of the Icybee package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Icybee\Modules\Sites;
use ICanBoogie\Updater\Update;
use ICanBoogie\Updater\AssertionFailed;
/**
* - Rename table `site_sites` as `sites`.
*
* @module users
*/
class Update20120101 extends Update
{
public function update_table_sites()
{
$db = $this->app->db;
if (!$db->table_exists('site_sites'))
{
throw new AssertionFailed('assert_table_exists', 'site_sites');
}
if ($db->table_exists('sites'))
{
throw new AssertionFailed('assert_not_table_exists', 'sites');
}
$db("RENAME TABLE `site_sites` TO `sites`");
}
}
/**
* - Renames the `modified` columns as `updated_at`.
*
* @module sites
*/
class Update20131208 extends Update
{
public function update_column_updated_at()
{
$this->module->model
->assert_has_column('modified')
->rename_column('modified', 'updated_at');
}
public function update_column_created_at()
{
$this->module->model
->assert_not_has_column('created_at')
->create_column('created_at');
}
public function update_remove_column_model()
{
$this->module->model
->assert_has_column('model')
->remove_column('model');
}
public function update_column_status()
{
$this->module->model
->assert_has_column('status')
->assert_not_column_has_size('status', 6)
->alter_column('status');
}
/**
* We now use HTTP codes for the site status.
*/
public function update_status()
{
$model = $this->module->model->target;
$count = $model->where('status < 200')->count;
if (!$count)
{
throw new AssertionFailed(__FUNCTION__, [ "status < 200" ]);
}
$model('UPDATE {self} SET `status` = ? WHERE `status` = 1', [ Site::STATUS_OK ]);
$model('UPDATE {self} SET `status` = ? WHERE `status` = 0', [ Site::STATUS_UNAUTHORIZED ]);
}
}
/**
* - Renames column `siteid` as `site_id`.
*
* @module sites
*/
class Update20150908 extends Update
{
/**
* Renames column `siteid` as `site_id`, also revokes `cached_sites`.
*/
public function update_column_site_id()
{
$this->module->model
->assert_has_column('siteid')
->rename_column('siteid', 'site_id');
unset($this->app->vars['cached_sites']);
}
}
/**
* - Creates column `prefer_secure`.
*
* @module sites
*/
class Update20151226 extends Update
{
public function update_create_column_prefer_secure()
{
$this->module->model
->assert_not_has_column('prefer_secure')
->create_column('prefer_secure');
unset($this->app->vars['cached_sites']);
}
}