source: extensions/community/maintain.class.php @ 30676

Last change on this file since 30676 was 29970, checked in by plg, 10 years ago

compatibility with Piwigo 2.7

For now, we keep uploadify (Flash) on Community because it is more compatible
with old browsers like IE8/IE9. Once the new HTML5 upload form will be more
mature, we will replace uploadify on Community too.

File size: 5.5 KB
Line 
1<?php
2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
3
4class community_maintain extends PluginMaintain
5{
6  private $installed = false;
7
8  function __construct($plugin_id)
9  {
10    parent::__construct($plugin_id);
11  }
12
13  function install($plugin_version, &$errors=array())
14  {
15    global $conf, $prefixeTable;
16   
17    $query = '
18CREATE TABLE IF NOT EXISTS '.$prefixeTable.'community_permissions (
19  id int(11) NOT NULL AUTO_INCREMENT,
20  type varchar(255) NOT NULL,
21  group_id smallint(5) unsigned DEFAULT NULL,
22  user_id mediumint(8) unsigned DEFAULT NULL,
23  category_id smallint(5) unsigned DEFAULT NULL,
24  user_album enum(\'true\',\'false\') NOT NULL DEFAULT \'false\',
25  recursive enum(\'true\',\'false\') NOT NULL DEFAULT \'true\',
26  create_subcategories enum(\'true\',\'false\') NOT NULL DEFAULT \'false\',
27  moderated enum(\'true\',\'false\') NOT NULL DEFAULT \'true\',
28  nb_photos int DEFAULT NULL,
29  storage int DEFAULT NULL,
30  PRIMARY KEY (id)
31) ENGINE=MyISAM DEFAULT CHARSET=utf8
32;';
33    pwg_query($query);
34
35    $query = '
36CREATE TABLE IF NOT EXISTS '.$prefixeTable.'community_pendings (
37  image_id mediumint(8) unsigned NOT NULL,
38  state varchar(255) NOT NULL,
39  added_on datetime NOT NULL,
40  validated_by mediumint(8) unsigned DEFAULT NULL
41) ENGINE=MyISAM DEFAULT CHARSET=utf8
42;';
43    pwg_query($query);
44
45    // column community_permissions.nb_photos added for version 2.5.d
46    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'community_permissions` LIKE "nb_photos";');
47    if (!pwg_db_num_rows($result))
48    {     
49      pwg_query('ALTER TABLE `'.$prefixeTable .'community_permissions` ADD `nb_photos` INT DEFAULT NULL;');
50    }
51 
52    // column community_permissions.storage added for version 2.5.d
53    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'community_permissions` LIKE "storage";');
54    if (!pwg_db_num_rows($result))
55    {     
56      pwg_query('ALTER TABLE `'.$prefixeTable .'community_permissions` ADD `storage` INT DEFAULT NULL;');
57    }
58
59    // column community_permissions.user_album added for version 2.5.d
60    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'community_permissions` LIKE "user_album";');
61    if (!pwg_db_num_rows($result))
62    {     
63      pwg_query('ALTER TABLE `'.$prefixeTable .'community_permissions` ADD `user_album` enum(\'true\',\'false\') NOT NULL DEFAULT \'false\' after `category_id`;');
64    }
65
66    // column categories.community_user added for version 2.5.d
67    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'categories` LIKE "community_user";');
68    if (!pwg_db_num_rows($result))
69    {     
70      pwg_query('ALTER TABLE `'.$prefixeTable .'categories` ADD `community_user` mediumint unsigned DEFAULT NULL;');
71    }
72
73    // Piwigo 2.7 enlarges user ids, from smallint to mediumint
74    $to_enlarge_ids = array(
75      $prefixeTable.'community_permissions.user_id',
76      $prefixeTable.'community_pendings.validated_by',
77      $prefixeTable.'categories.community_user',
78      );
79
80    foreach ($to_enlarge_ids as $to_enlarge_id)
81    {
82      list($table, $column) = explode('.', $to_enlarge_id);
83
84      $row = pwg_db_fetch_assoc(pwg_query('SHOW COLUMNS FROM `'.$table.'` LIKE "'.$column.'";'));
85      if ($row['Type'] != 'mediumint')
86      {
87        $query = 'ALTER TABLE '.$table.' CHANGE '.$column.' '.$column.' MEDIUMINT UNSIGNED DEFAULT NULL;';
88        pwg_query($query);
89      }
90    }
91
92    if (!isset($conf['community']))
93    {
94      $community_default_config = array(
95        'user_albums' => false,
96        );
97     
98      conf_update_param('community', $community_default_config, true);
99    }
100   
101    $this->installed = true;
102  }
103
104  function activate($plugin_version, &$errors=array())
105  {
106    global $prefixeTable;
107   
108    if (!$this->installed)
109    {
110      $this->install($plugin_version, $errors);
111    }
112   
113    $query = '
114SELECT
115    COUNT(*)
116  FROM '.$prefixeTable.'community_permissions
117;';
118    list($counter) = pwg_db_fetch_row(pwg_query($query));
119    if (0 == $counter)
120    {
121      // is there a "Community" album?
122      $query = '
123SELECT
124    id
125  FROM '.CATEGORIES_TABLE.'
126  WHERE name = \'Community\'
127;';
128      $result = pwg_query($query);
129      while ($row = pwg_db_fetch_assoc($result))
130      {
131        $category_id = $row['id'];
132        break;
133      }
134
135      if (!isset($category_id))
136      {
137        // create an album "Community"
138        include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
139        $category_info = create_virtual_category('Community');
140        $category_id = $category_info['id'];
141      }
142
143      single_insert(
144        $prefixeTable.'community_permissions',
145        array(
146          'type' => 'any_registered_user',
147          'category_id' => $category_id,
148          'recursive' => 'true',
149          'create_subcategories' => 'true',
150          'moderated' => 'true',
151          )
152        );
153    }
154
155    include_once(dirname(__FILE__).'/include/functions_community.inc.php');
156    community_update_cache_key();
157  }
158
159  function update($old_version, $new_version, &$errors=array())
160  {
161    $this->install($new_version, $errors);
162  }
163 
164  function deactivate()
165  {
166  }
167
168  function uninstall()
169  {
170    global $prefixeTable;
171 
172    $query = 'DROP TABLE '.$prefixeTable.'community_permissions;';
173    pwg_query($query);
174   
175    $query = 'DROP TABLE '.$prefixeTable.'community_pendings;';
176    pwg_query($query);
177   
178    $query = 'ALTER TABLE '.$prefixeTable.'categories drop column community_user;';
179    pwg_query($query);
180   
181    // delete configuration
182    pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN ("community", "community_cache_key");');
183  }
184}
185?>
Note: See TracBrowser for help on using the repository browser.