source: extensions/SmartAlbums/maintain.inc.php @ 27266

Last change on this file since 27266 was 27266, checked in by mistic100, 10 years ago

allow to choose the sort order when using limit filter

File size: 4.1 KB
Line 
1<?php
2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
3
4class 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) ENGINE=MyISAM DEFAULT CHARSET=utf8
68;');
69
70    // new column on image category table
71    $result = pwg_query('SHOW COLUMNS FROM `' . IMAGE_CATEGORY_TABLE . '` LIKE "smart";');
72    if (!pwg_db_num_rows($result))
73    {
74      pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM(\'true\', \'false\') NOT NULL DEFAULT \'false\';');
75    }
76
77    // new column on category filters table (2.1.1)
78    $result = pwg_query('SHOW COLUMNS FROM `' . $this->table . '` LIKE "updated";');
79    if (!pwg_db_num_rows($result))
80    {
81      pwg_query('ALTER TABLE `' . $this->table . '` ADD `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00"');
82    }
83
84    // remove column on category table, moved to category filters table (2.1.1)
85    $result = pwg_query('SHOW COLUMNS FROM `' . CATEGORIES_TABLE . '` LIKE "smart_update";');
86    if (pwg_db_num_rows($result))
87    {
88      pwg_query('UPDATE `' . $this->table . '` AS f SET updated = ( SELECT smart_update FROM `' . CATEGORIES_TABLE . '` AS c WHERE c.id = f.category_id );');
89      pwg_query('ALTER TABLE `' . CATEGORIES_TABLE . '` DROP `smart_update`;');
90    }
91
92    // date filters renamed in 2.0
93    $query = '
94SELECT category_id
95  FROM `' . $this->table . '`
96  WHERE
97    type = "date" AND
98    cond IN ("the","before","after","the_crea","before_crea","after_crea")
99;';
100
101    if (pwg_db_num_rows(pwg_query($query)))
102    {
103      $name_changes = array(
104        'the' => 'the_post',
105        'before' => 'before_post',
106        'after' => 'after_post',
107        'the_crea' => 'the_taken',
108        'before_crea' => 'before_taken',
109        'after_crea' => 'after_taken',
110        );
111      foreach ($name_changes as $old => $new)
112      {
113        pwg_query('UPDATE `' . $this->table . '` SET cond = "' . $new . '" WHERE type = "date" AND cond = "' . $old . '";');
114      }
115    }
116   
117    // limit filter extended in 2.2.1
118    pwg_query('UPDATE `' . $this->table . '` SET cond = "" WHERE type = "limit" AND cond = "limit";');
119    pwg_query('ALTER TABLE `' . $this->table . '` CHANGE `cond` `cond` VARCHAR(32) NULL ;');
120
121    $this->installed = true;
122  }
123
124  function activate($plugin_version, &$errors=array())
125  {
126    if (!$this->installed)
127    {
128      $this->install($plugin_version, $errors);
129    }
130  }
131
132  function deactivate()
133  {
134  }
135
136  function uninstall()
137  {
138    conf_delete_param('SmartAlbums');
139
140    pwg_query('DROP TABLE `' . $this->table . '`;');
141
142    pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;');
143  }
144}
Note: See TracBrowser for help on using the repository browser.