source: extensions/UserCollections/maintain.inc.php @ 25715

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

very big update for Piwigo 2.6

File size: 3.5 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4class UserCollections_maintain extends PluginMaintain
5{
6  private $installed = false;
7
8  function install($plugin_version, &$errors=array())
9  {
10    global $conf, $prefixeTable;
11
12    if (empty($conf['user_collections']))
13    {
14      $conf['user_collections'] = serialize(array(
15        'allow_mails' => true,
16        'allow_public' => true,
17        ));
18
19      conf_update_param('user_collections', $conf['user_collections']);
20    }
21
22    // create tables
23    $query = '
24CREATE TABLE IF NOT EXISTS `'.$prefixeTable.'collections` (
25  `id` mediumint(8) NOT NULL AUTO_INCREMENT,
26  `user_id` smallint(5) DEFAULT NULL,
27  `name` varchar(255) NOT NULL,
28  `date_creation` datetime NOT NULL,
29  `comment` text NULL,
30  `nb_images` mediumint(8) NOT NULL DEFAULT 0,
31  PRIMARY KEY (`id`)
32) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
33;';
34    pwg_query($query);
35
36    $query = '
37CREATE TABLE IF NOT EXISTS `'.$prefixeTable.'collection_images` (
38  `col_id` mediumint(8) NOT NULL,
39  `image_id` mediumint(8) NOT NULL,
40  `add_date` datetime NULL,
41  UNIQUE KEY `UNIQUE` (`col_id`,`image_id`)
42) ENGINE=MyISAM DEFAULT CHARSET=utf8
43;';
44    pwg_query($query);
45
46    $query = '
47CREATE TABLE IF NOT EXISTS `'.$prefixeTable.'collection_shares` (
48  `id` mediumint(8) NOT NULL AUTO_INCREMENT,
49  `col_id` mediumint(8) NOT NULL,
50  `share_key` varchar(64) NOT NULL,
51  `params` text NULL,
52  `add_date` datetime NOT NULL,
53  PRIMARY KEY (`id`),
54  UNIQUE KEY `share_key` (`share_key`)
55) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
56;';
57    pwg_query($query);
58
59
60    // version 2.0.0
61    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'collection_images` LIKE "add_date";');
62    if (!pwg_db_num_rows($result))
63    {
64      pwg_query('ALTER TABLE `'.$prefixeTable.'collection_images` ADD `add_date` datetime NULL;');
65    }
66
67    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'collections` LIKE "comment";');
68    if (!pwg_db_num_rows($result))
69    {
70      pwg_query('ALTER TABLE `'.$prefixeTable.'collections` ADD `comment` text NULL;');
71      pwg_query('ALTER TABLE `'.$prefixeTable.'collections` DROP `active`;');
72    }
73
74    // version 2.1.0
75    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'collections` LIKE "public";');
76    if (pwg_db_num_rows($result))
77    {
78      $now = date('Y-m-d H:i:s');
79
80      $query = '
81SELECT id, public_id
82  FROM `'.$prefixeTable.'collections`
83  WHERE public = 1
84;';
85      $result = pwg_query($query);
86
87      $inserts = array();
88      while ($row = pwg_db_fetch_assoc($result))
89      {
90        $inserts[] = array(
91          'col_id' => $row['id'],
92          'share_key' => $row['public_id'],
93          'params' => serialize(array('password'=>'','deadline'=>'')),
94          'add_date' => $now,
95          );
96      }
97
98      mass_inserts($prefixeTable.'collection_shares',
99        array('col_id','share_key','params','add_date'),
100        $inserts
101        );
102
103      pwg_query('ALTER TABLE `'.$prefixeTable.'collections` DROP `public`, DROP `public_id`;');
104    }
105  }
106
107  function activate($plugin_version, &$errors=array())
108  {
109    if (!$this->installed)
110    {
111      $this->install($plugin_version, $errors);
112    }
113  }
114
115  function deactivate(){}
116
117  function uninstall()
118  {
119    global $prefixeTable;
120
121    conf_delete_param('user_collections');
122
123    pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'collections`;');
124    pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'collection_images`;');
125    pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'collection_shares`;');
126  }
127}
Note: See TracBrowser for help on using the repository browser.