Stripping CVS keywords
[project/imagecache.git] / imagecache.install
CommitLineData
ed7d47b6 1<?php
ed7d47b6
DP
2
3function imagecache_install() {
2fc4f9ab
DP
4 switch ($GLOBALS['db_type']) {
5 case 'mysql':
6 case 'mysqli':
1b0c75d7 7 $ret1 = db_query('CREATE TABLE {imagecache_preset} (
e1112c83 8 presetid INT UNSIGNED NOT NULL PRIMARY KEY,
c87653a7
DP
9 presetname VARCHAR(255) NOT NULL DEFAULT \'\' )
10 /*!40100 DEFAULT CHARACTER SET utf8 */'
2fc4f9ab 11 );
ed7d47b6 12
1b0c75d7 13 $ret2 = db_query('CREATE TABLE {imagecache_action} (
e1112c83 14 actionid INT UNSIGNED NOT NULL PRIMARY KEY,
1b0c75d7 15 presetid INT UNSIGNED NOT NULL DEFAULT 0,
ed7d47b6 16 weight INT NOT NULL DEFAULT 0,
c87653a7
DP
17 data TEXT NOT NULL DEFAULT \'\')
18 /*!40100 DEFAULT CHARACTER SET utf8 */'
2fc4f9ab
DP
19 );
20 break;
21
22 case 'pgsql':
c87653a7
DP
23 $ret1 = db_query('CREATE TABLE {imagecache_preset} (
24 presetid INTEGER NOT NULL CHECK (presetid > 0),
1b0c75d7 25 presetname VARCHAR(255) NOT NULL DEFAULT \'\',
c87653a7 26 PRIMARY KEY (presetid));'
2fc4f9ab 27 );
c87653a7 28 $ret2 = db_query('CREATE TABLE {imagecache_action} (
e1112c83 29 actionid INTEGER NOT NULL CHECK (actionid > 0),
1b0c75d7 30 presetid INTEGER NOT NULL DEFAULT 0,
2fc4f9ab 31 weight INTEGER NOT NULL DEFAULT 0,
e1112c83 32 data TEXT NOT NULL DEFAULT \'\',
2fc4f9ab
DP
33 PRIMARY KEY (actionid));'
34 );
c87653a7
DP
35 db_query("CREATE SEQUENCE imagecache_preset_presetid_seq INCREMENT 1 START 1;");
36 db_query("CREATE SEQUENCE imagecache_action_actionid_seq INCREMENT 1 START 1;");
2fc4f9ab
DP
37 break;
38 }
39
40 if ($ret1 && $ret2) {
41 drupal_set_message(t('Imagecache module installed succesfully.'));
42 } else {
e1112c83 43 drupal_set_message(t('Imagecache module installation was unsuccessfull. Necessary database tables should be created by hand.', 'error'));
2fc4f9ab 44 }
1b0c75d7 45 return $ret;
ed7d47b6
DP
46}
47
1b0c75d7 48// Add action id to actions table.
ed7d47b6 49function imagecache_update_1() {
1b0c75d7
DP
50 $ret = array();
51 $ret[] = update_sql('ALTER TABLE {imagecache_actions} ADD COLUMN actionid INT UNSIGNED NOT NULL primary key auto_increment');
52 return $ret;
53}
54
55// Rename rulesets to presets; Make all table names singular;
56function imagecache_update_2() {
57 $ret = array();
58 $ret[] = update_sql('ALTER TABLE {imagecache_rulesets} RENAME TO {imagecache_preset}');
59 $ret[] = update_sql('ALTER TABLE {imagecache_actions} RENAME TO {imagecache_action}');
60 switch ($GLOBALS['db_type']) {
61 case 'mysql':
62 case 'mysqli':
63 $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetid presetid INT UNSIGNED NOT NULL AUTO_INCREMENT');
64 $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetname presetname VARCHAR(255) NOT NULL DEFAULT \'\'');
65 $ret[] = update_sql('ALTER TABLE {imagecache_action} CHANGE rulesetid presetid INTEGER NOT NULL DEFAULT 0');
66 break;
67
68 case 'pgsql':
69 $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetid TO presetid');
70 $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetname TO presetname');
71 $ret[] = update_sql('ALTER TABLE {imagecache_action} RENAME COLUMN rulesetid TO presetid');
72 break;
73 }
74 return $ret;
ed7d47b6 75}
e1112c83
DP
76
77
78/**
79 * Remove auto-increment from tables, instead depending on the sequences table and db_next_id()
80 */
81function imagecache_update_3() {
82 $ret = array();
c87653a7
DP
83
84 $count_action = db_result(db_query('SELECT max(actionid) FROM {imagecache_action}')) + 1;
85 $count_preset = db_result(db_query('SELECT max(presetid) FROM {imagecache_preset}')) + 1;
86
e1112c83
DP
87 switch ($GLOBALS['db_type']) {
88 case 'mysql':
89 case 'mysqli':
c87653a7
DP
90 $ret[] = update_sql("ALTER TABLE {imagecache_action} CHANGE actionid actionid INT UNSIGNED NOT NULL");
91 $ret[] = update_sql("ALTER TABLE {imagecache_preset} CHANGE presetid presetid INT UNSIGNED NOT NULL");
92 // Add the sequences
93 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_action}_actionid', $count_action)");
94 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_preset}_presetid', $count_preset)");
e1112c83
DP
95 break;
96 case 'pgsql':
97 db_change_column($ret, 'imagecache_action', 'actionid', 'actionid', 'INT', $attributes = array('not null' => TRUE, 'default' => '0'));
98 db_change_column($ret, 'imagecache_preset', 'presetid', 'presetid', 'INT', $attributes = array('not null' => TRUE, 'default' => '0'));
99 // Re-add our indexes
100 $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD PRIMARY KEY (actionid)");
c87653a7
DP
101 $ret[] = update_sql("ALTER TABLE {imagecache_preset} ADD PRIMARY KEY (rulesetid)");
102 // Add the sequences
103 $ret[] = update_sql("CREATE SEQUENCE {imagecache_action}_actionid_seq INCREMENT 1 START $count_action;");
104 $ret[] = update_sql("CREATE SEQUENCE {imagecache_preset}_presetid_seq INCREMENT 1 START $count_preset;");
105 }
e1112c83
DP
106 return $ret;
107}