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

Last change on this file since 21668 was 21668, checked in by mistic100, 11 years ago

bad order of SQL commands

File size: 3.1 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      'update_on_date' => true,
14      'update_timeout' => 3,
15      'show_list_messages' => true,
16      'smart_is_forbidden' => false,
17      'last_update' => 0,
18      ));
19   
20    conf_update_param('SmartAlbums', $smart_default_config);
21    $conf['SmartAlbums'] = $smart_default_config;
22  }
23  else
24  {
25    $new_conf = unserialize($conf['SmartAlbums']);
26    // new param in 2.0.2
27    if (!isset($new_conf['smart_is_forbidden']))
28    {
29      $new_conf['smart_is_forbidden'] = true;
30    }
31    // new params in 2.1.0
32    if (!isset($new_conf['update_on_date']))
33    {
34      $new_conf['update_on_date'] = true;
35      $new_conf['update_timeout'] = 3;
36      $new_conf['last_update'] = 0;
37    }
38    conf_update_param('SmartAlbums', serialize($new_conf));
39    $conf['SmartAlbums'] = serialize($new_conf);
40  }
41 
42  // new table
43        pwg_query(
44'CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'category_filters` (
45  `category_id` smallint(5) unsigned NOT NULL,
46  `type` varchar(16) NOT NULL,
47  `cond` varchar(16) NULL,
48  `value` text NULL,
49  `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00"
50) ENGINE=MyISAM DEFAULT CHARSET=utf8
51;');
52 
53  // new column on image category table
54  $result = pwg_query('SHOW COLUMNS FROM `' . IMAGE_CATEGORY_TABLE . '` LIKE "smart";');
55  if (!pwg_db_num_rows($result))
56  {     
57    pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM(\'true\', \'false\') NOT NULL DEFAULT \'false\';');
58  }
59 
60  // new column on category filters table
61  $result = pwg_query('SHOW COLUMNS FROM `' . $prefixeTable . 'category_filters` LIKE "updated";');
62  if (!pwg_db_num_rows($result))
63  {     
64    pwg_query('ALTER TABLE `' . $prefixeTable . 'category_filters` ADD `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00"');
65  }
66 
67  // remove column on category table, moved to category filters table
68  $result = pwg_query('SHOW COLUMNS FROM `' . CATEGORIES_TABLE . '` LIKE "smart_update";');
69  if (pwg_db_num_rows($result))
70  {
71    pwg_query('UPDATE `' . $prefixeTable . 'category_filters` AS f SET updated = ( SELECT smart_update FROM `' . CATEGORIES_TABLE . '` AS c WHERE c.id = f.category_id );');
72    pwg_query('ALTER TABLE `' . CATEGORIES_TABLE . '` DROP `smart_update`;');
73  }
74 
75  // date filters renamed in 2.0
76  $query = '
77SELECT category_id
78  FROM `' . $prefixeTable . 'category_filters`
79  WHERE
80    type = "date" AND
81    cond IN ("the","before","after","the_crea","before_crea","after_crea")
82;';
83
84  if (pwg_db_num_rows(pwg_query($query)))
85  {
86    $name_changes = array(
87      'the' => 'the_post',
88      'before' => 'before_post',
89      'after' => 'after_post',
90      'the_crea' => 'the_taken',
91      'before_crea' => 'before_taken',
92      'after_crea' => 'after_taken',
93      );
94    foreach ($name_changes as $old => $new)
95    {
96      pwg_query('UPDATE `' . $prefixeTable . 'category_filters` SET cond = "'.$new.'" WHERE type = "date" AND cond = "'.$old.'";');
97    }
98  }
99}
100
101?>
Note: See TracBrowser for help on using the repository browser.