source: extensions/SmartAlbums/include/install.inc.php @ 17716

Last change on this file since 17716 was 17716, checked in by mistic100, 12 years ago

consolidate upgrade process

File size: 2.0 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4function smart_albums_install() 
5{
6  global $conf, $prefixeTable;
7 
8  // configuration
9  if (!isset($conf['SmartAlbums']))
10  {
11    $smart_default_config = serialize(array(
12      'update_on_upload' => false,
13      'show_list_messages' => true,
14      'smart_is_forbidden' => true,
15      ));
16   
17    conf_update_param('SmartAlbums', $smart_default_config);
18    $conf['SmartAlbums'] = $smart_default_config;
19  }
20  else
21  {
22    $new_conf = unserialize($conf['SmartAlbums']);
23    // new param in 2.0.2
24    if (!isset($new_conf['smart_is_forbidden']))
25    {
26      $new_conf['smart_is_forbidden'] = true;
27      conf_update_param('SmartAlbums', serialize($new_conf));
28      $conf['SmartAlbums'] = serialize($new_conf);
29    }
30  }
31 
32  // new table
33        pwg_query(
34'CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'category_filters` (
35  `category_id` smallint(5) unsigned NOT NULL,
36  `type` varchar(16) NOT NULL,
37  `cond` varchar(16) NULL,
38  `value` text
39) ENGINE=MyISAM DEFAULT CHARSET=utf8
40;');
41 
42  // new column on image category table
43  $result = pwg_query('SHOW COLUMNS FROM `' . IMAGE_CATEGORY_TABLE . '` LIKE "smart";');
44  if (!pwg_db_num_rows($result))
45  {     
46    pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM(\'true\', \'false\') NOT NULL DEFAULT \'false\';');
47  }
48 
49  // date filters renamed in 2.0
50  $query = '
51SELECT category_id
52  FROM `' . $prefixeTable . 'category_filters`
53  WHERE
54    type = "date" AND
55    cond IN ("the","before","after","the_crea","before_crea","after_crea")
56;';
57
58  if (pwg_db_num_rows(pwg_query($query)))
59  {
60    $name_changes = array(
61      'the' => 'the_post',
62      'before' => 'before_post',
63      'after' => 'after_post',
64      'the_crea' => 'the_taken',
65      'before_crea' => 'before_taken',
66      'after_crea' => 'after_taken',
67      );
68    foreach ($name_changes as $old => $new)
69    {
70      pwg_query('UPDATE `' . $prefixeTable . 'category_filters` SET cond = "'.$new.'" WHERE cond = "'.$old.'";');
71    }
72  }
73}
74
75?>
Note: See TracBrowser for help on using the repository browser.