source: extensions/UserCollections/include/install.inc.php @ 25674

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

fixc empty share key field after addition
fix javascript errors

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