| 1 |
<?php |
<?php |
| 2 |
// $Id: og_collections.install,v 1.2.2.1 2008/03/17 23:55:33 sdboyer Exp $ |
// $Id: og_collections.install,v 1.2.2.2 2008/04/06 20:43:45 sdboyer Exp $ |
| 3 |
|
|
| 4 |
function og_collections_install() { |
function og_collections_install() { |
| 5 |
switch ($GLOBALS['db_type']) { |
switch ($GLOBALS['db_type']) { |
| 22 |
CREATE TABLE {og_collections} ( |
CREATE TABLE {og_collections} ( |
| 23 |
grouptype varchar(32) NOT NULL, |
grouptype varchar(32) NOT NULL, |
| 24 |
version int(4) NOT NULL DEFAULT 0, |
version int(4) NOT NULL DEFAULT 0, |
| 25 |
defaults text NOT NULL, |
defaults text, |
| 26 |
PRIMARY KEY (grouptype) |
PRIMARY KEY (grouptype) |
| 27 |
) /*!40100 DEFAULT CHARACTER SET utf8 */ |
) /*!40100 DEFAULT CHARACTER SET utf8 */ |
| 28 |
EOT |
EOT |
| 75 |
CREATE TABLE {og_collections} ( |
CREATE TABLE {og_collections} ( |
| 76 |
grouptype varchar(32) NOT NULL, |
grouptype varchar(32) NOT NULL, |
| 77 |
version integer(4) NOT NULL DEFAULT 0, |
version integer(4) NOT NULL DEFAULT 0, |
| 78 |
defaults text NOT NULL DEFAULT '0', |
defaults text, |
| 79 |
PRIMARY KEY (grouptype) |
PRIMARY KEY (grouptype) |
| 80 |
) |
) |
| 81 |
EOT |
EOT |
| 160 |
return $ret; |
return $ret; |
| 161 |
} |
} |
| 162 |
|
|
| 163 |
|
function og_collections_update_5002() { |
| 164 |
|
$ret = array(); |
| 165 |
|
$ret[] = update_sql(<<<EOT |
| 166 |
|
CREATE TABLE {og_collections_versions} ( |
| 167 |
|
grouptype varchar(32) NOT NULL, |
| 168 |
|
vid int(4) NOT NULL DEFAULT 0, |
| 169 |
|
data mediumblob, |
| 170 |
|
PRIMARY KEY (grouptype, vid) |
| 171 |
|
) /*!40100 DEFAULT CHARACTER SET utf8 */ |
| 172 |
|
EOT |
| 173 |
|
); |
| 174 |
|
// db_query_temporary("SELECT DISTINCT pcpid FROM {og_collections_pcpanel}", 'og_col_update'); |
| 175 |
|
$result = db_query("SELECT DISTINCT pcpid FROM {og_collections_pcpanel}"); |
| 176 |
|
$pcpids = array(); |
| 177 |
|
while ($row = db_fetch_array($result)) { |
| 178 |
|
$pcpids[] = $row['pcpid']; |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
$ret[] = update_sql("ALTER TABLE {og_collections} ADD version int(4) NOT NULL DEFAULT 0 AFTER grouptype"); |
| 182 |
|
$ret[] = update_sql("ALTER TABLE {og_collections} ADD defaults text AFTER version"); |
| 183 |
|
$ret[] = update_sql("ALTER TABLE {og_collections_pcpanel} ADD pcpname varchar(32) AFTER pcpid"); |
| 184 |
|
|
| 185 |
|
if (!empty($pcpids)) { |
| 186 |
|
$i = 1000; // just a surefire means of differentiating the arrays later on |
| 187 |
|
$defaults = array(); |
| 188 |
|
$allcollections = db_query("SELECT * FROM {og_collections}"); |
| 189 |
|
while ($collectioncfg = db_fetch_array($allcollections)) { |
| 190 |
|
$grouptype = $collectioncfg['grouptype']; |
| 191 |
|
foreach ($collectioncfg as $field => $value) { |
| 192 |
|
if (in_array($field, array('grouptype', 'defaults', 'version'))) { |
| 193 |
|
continue; |
| 194 |
|
} |
| 195 |
|
$settings = unserialize($value); |
| 196 |
|
if (!empty($settings['usedef'])) { |
| 197 |
|
$defaults[$i][] = 'pcpanel_'. substr($field, 6); |
| 198 |
|
} |
| 199 |
|
unset ($settings['usedef']); |
| 200 |
|
$serialized_settings = serialize($settings); |
| 201 |
|
$ret[] = update_sql(<<<EOT |
| 202 |
|
UPDATE {og_collections} SET $field = '$serialized_settings' WHERE grouptype = '$grouptype' |
| 203 |
|
EOT |
| 204 |
|
); |
| 205 |
|
} |
| 206 |
|
if ($collectioncfg['grouptype'] != 'default') { // default group shouldn't have anything in its defaults field, although it doesn't really matter |
| 207 |
|
$groupdefaults = serialize($defaults[$i]); |
| 208 |
|
$ret[] = update_sql(<<<EOT |
| 209 |
|
UPDATE {og_collections} SET defaults = '$groupdefaults' WHERE grouptype = '$grouptype' |
| 210 |
|
EOT |
| 211 |
|
); |
| 212 |
|
} |
| 213 |
|
$i++; |
| 214 |
|
} |
| 215 |
|
$sql = "ALTER TABLE {og_collections} "; |
| 216 |
|
foreach ($pcpids as $pcpid) { |
| 217 |
|
$ret[] = update_sql("UPDATE {og_collections_pcpanel} SET pcpname = 'pcpanel_$pcpid' WHERE pcpid = $pcpid"); |
| 218 |
|
$sql .= "CHANGE pcpid_$pcpid pcpanel_$pcpid longtext, "; |
| 219 |
|
} |
| 220 |
|
$ret[] = update_sql(substr($sql, 0, -2)); |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
return $ret; |
| 224 |
|
} |
| 225 |
|
|
| 226 |
function og_collections_uninstall() { |
function og_collections_uninstall() { |
| 227 |
db_query('DROP TABLE {og_collections_pcpanel}'); |
db_query('DROP TABLE {og_collections_pcpanel}'); |
| 228 |
db_query('DROP TABLE {og_collections'); |
db_query('DROP TABLE {og_collections}'); |
| 229 |
db_query('DROP TABLE {og_collections_control}'); |
db_query('DROP TABLE {og_collections_control}'); |
| 230 |
db_query('DROP TABLE {og_collections_versions'); |
db_query('DROP TABLE {og_collections_versions}'); |
| 231 |
|
|
| 232 |
// Delete variables |
// Delete variables |
| 233 |
$variables = array('og_collections_settings'); |
$variables = array('og_collections_settings'); |