1 | <?php |
---|
2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | class SmartAlbums_maintain extends PluginMaintain |
---|
5 | { |
---|
6 | private $installed = false; |
---|
7 | |
---|
8 | private $default_conf = array( |
---|
9 | 'update_on_upload' => false, |
---|
10 | 'update_on_date' => true, |
---|
11 | 'update_timeout' => 3, |
---|
12 | 'show_list_messages' => true, |
---|
13 | 'smart_is_forbidden' => false, |
---|
14 | 'last_update' => 0, |
---|
15 | ); |
---|
16 | |
---|
17 | private $table; |
---|
18 | |
---|
19 | function __construct($plugin_id) |
---|
20 | { |
---|
21 | global $prefixeTable; |
---|
22 | |
---|
23 | parent::__construct($plugin_id); |
---|
24 | |
---|
25 | $this->table = $prefixeTable . 'category_filters'; |
---|
26 | } |
---|
27 | |
---|
28 | function install($plugin_version, &$errors=array()) |
---|
29 | { |
---|
30 | global $conf, $prefixeTable; |
---|
31 | |
---|
32 | if (empty($conf['SmartAlbums'])) |
---|
33 | { |
---|
34 | $conf['SmartAlbums'] = serialize($this->default_conf); |
---|
35 | conf_update_param('SmartAlbums', $conf['SmartAlbums']); |
---|
36 | } |
---|
37 | else |
---|
38 | { |
---|
39 | $new_conf = is_string($conf['SmartAlbums']) ? unserialize($conf['SmartAlbums']) : $conf['SmartAlbums']; |
---|
40 | |
---|
41 | // new param in 2.0.2 |
---|
42 | if (!isset($new_conf['smart_is_forbidden'])) |
---|
43 | { |
---|
44 | $new_conf['smart_is_forbidden'] = true; |
---|
45 | } |
---|
46 | |
---|
47 | // new params in 2.1.0 |
---|
48 | if (!isset($new_conf['update_on_date'])) |
---|
49 | { |
---|
50 | $new_conf['update_on_date'] = true; |
---|
51 | $new_conf['update_timeout'] = 3; |
---|
52 | $new_conf['last_update'] = 0; |
---|
53 | } |
---|
54 | |
---|
55 | $conf['SmartAlbums'] = serialize($new_conf); |
---|
56 | conf_update_param('SmartAlbums', $conf['SmartAlbums']); |
---|
57 | } |
---|
58 | |
---|
59 | // new table |
---|
60 | pwg_query( |
---|
61 | 'CREATE TABLE IF NOT EXISTS `' . $this->table . '` ( |
---|
62 | `category_id` smallint(5) unsigned NOT NULL, |
---|
63 | `type` varchar(16) NOT NULL, |
---|
64 | `cond` varchar(32) NULL, |
---|
65 | `value` text NULL, |
---|
66 | `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00", |
---|
67 | KEY `category_id` (`category_id`) |
---|
68 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
---|
69 | ;'); |
---|
70 | |
---|
71 | // new column on image category table |
---|
72 | $result = pwg_query('SHOW COLUMNS FROM `' . IMAGE_CATEGORY_TABLE . '` LIKE "smart";'); |
---|
73 | if (!pwg_db_num_rows($result)) |
---|
74 | { |
---|
75 | pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM(\'true\', \'false\') NOT NULL DEFAULT \'false\';'); |
---|
76 | } |
---|
77 | |
---|
78 | // new column on category filters table (2.1.1) |
---|
79 | $result = pwg_query('SHOW COLUMNS FROM `' . $this->table . '` LIKE "updated";'); |
---|
80 | if (!pwg_db_num_rows($result)) |
---|
81 | { |
---|
82 | pwg_query('ALTER TABLE `' . $this->table . '` ADD `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00"'); |
---|
83 | } |
---|
84 | |
---|
85 | // remove column on category table, moved to category filters table (2.1.1) |
---|
86 | $result = pwg_query('SHOW COLUMNS FROM `' . CATEGORIES_TABLE . '` LIKE "smart_update";'); |
---|
87 | if (pwg_db_num_rows($result)) |
---|
88 | { |
---|
89 | pwg_query('UPDATE `' . $this->table . '` AS f SET updated = ( SELECT smart_update FROM `' . CATEGORIES_TABLE . '` AS c WHERE c.id = f.category_id );'); |
---|
90 | pwg_query('ALTER TABLE `' . CATEGORIES_TABLE . '` DROP `smart_update`;'); |
---|
91 | } |
---|
92 | |
---|
93 | // date filters renamed in 2.0 |
---|
94 | $query = ' |
---|
95 | SELECT category_id |
---|
96 | FROM `' . $this->table . '` |
---|
97 | WHERE |
---|
98 | type = "date" AND |
---|
99 | cond IN ("the","before","after","the_crea","before_crea","after_crea") |
---|
100 | ;'; |
---|
101 | |
---|
102 | if (pwg_db_num_rows(pwg_query($query))) |
---|
103 | { |
---|
104 | $name_changes = array( |
---|
105 | 'the' => 'the_post', |
---|
106 | 'before' => 'before_post', |
---|
107 | 'after' => 'after_post', |
---|
108 | 'the_crea' => 'the_taken', |
---|
109 | 'before_crea' => 'before_taken', |
---|
110 | 'after_crea' => 'after_taken', |
---|
111 | ); |
---|
112 | foreach ($name_changes as $old => $new) |
---|
113 | { |
---|
114 | pwg_query('UPDATE `' . $this->table . '` SET cond = "' . $new . '" WHERE type = "date" AND cond = "' . $old . '";'); |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | // limit filter extended in 2.2.1 |
---|
119 | pwg_query('UPDATE `' . $this->table . '` SET cond = "" WHERE type = "limit" AND cond = "limit";'); |
---|
120 | pwg_query('ALTER TABLE `' . $this->table . '` CHANGE `cond` `cond` VARCHAR(32) NULL ;'); |
---|
121 | |
---|
122 | // add recursive marker for album filter (2.2.2) |
---|
123 | $result = pwg_query('SELECT COUNT(*) FROM `' . $this->table . '` WHERE type="album" AND (value NOT LIKE "true,%" OR value NOT LIKE "false,%");'); |
---|
124 | list($count) = pwg_db_fetch_row($result); |
---|
125 | if ($count>0) |
---|
126 | { |
---|
127 | pwg_query('UPDATE `' . $this->table . '` SET value = CONCAT("false,", value) WHERE type="album";'); |
---|
128 | } |
---|
129 | |
---|
130 | $this->installed = true; |
---|
131 | } |
---|
132 | |
---|
133 | function activate($plugin_version, &$errors=array()) |
---|
134 | { |
---|
135 | if (!$this->installed) |
---|
136 | { |
---|
137 | $this->install($plugin_version, $errors); |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | function deactivate() |
---|
142 | { |
---|
143 | } |
---|
144 | |
---|
145 | function uninstall() |
---|
146 | { |
---|
147 | conf_delete_param('SmartAlbums'); |
---|
148 | |
---|
149 | pwg_query('DROP TABLE `' . $this->table . '`;'); |
---|
150 | |
---|
151 | pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;'); |
---|
152 | } |
---|
153 | } |
---|