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