[10871] | 1 | <?php |
---|
[26442] | 2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
[10871] | 3 | |
---|
[26442] | 4 | class SmartAlbums_maintain extends PluginMaintain |
---|
[11376] | 5 | { |
---|
[26442] | 6 | private $installed = false; |
---|
[10871] | 7 | |
---|
[26442] | 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) |
---|
[11376] | 20 | { |
---|
[26442] | 21 | global $prefixeTable; |
---|
| 22 | |
---|
| 23 | parent::__construct($plugin_id); |
---|
| 24 | |
---|
| 25 | $this->table = $prefixeTable . 'category_filters'; |
---|
[11376] | 26 | } |
---|
| 27 | |
---|
[26442] | 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, |
---|
[27266] | 64 | `cond` varchar(32) NULL, |
---|
[26442] | 65 | `value` text NULL, |
---|
[27300] | 66 | `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00", |
---|
| 67 | KEY `category_id` (`category_id`) |
---|
[26442] | 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 | } |
---|
[27266] | 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 ;'); |
---|
[26442] | 121 | |
---|
| 122 | $this->installed = true; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | function activate($plugin_version, &$errors=array()) |
---|
| 126 | { |
---|
| 127 | if (!$this->installed) |
---|
| 128 | { |
---|
| 129 | $this->install($plugin_version, $errors); |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | function deactivate() |
---|
| 134 | { |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | function uninstall() |
---|
| 138 | { |
---|
| 139 | conf_delete_param('SmartAlbums'); |
---|
| 140 | |
---|
| 141 | pwg_query('DROP TABLE `' . $this->table . '`;'); |
---|
| 142 | |
---|
| 143 | pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;'); |
---|
| 144 | } |
---|
[10871] | 145 | } |
---|