/[drupal]/contributions/modules/domain/domain.install
ViewVC logotype

Contents of /contributions/modules/domain/domain.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.25 - (show annotations) (download) (as text)
Sat Oct 24 22:11:26 2009 UTC (4 weeks, 6 days ago) by agentken
Branch: MAIN
CVS Tags: DRUPAL-6--2-0, HEAD
Branch point for: DRUPAL-6--2
Changes since 1.24: +3 -3 lines
File MIME type: text/x-php
fixes clode style issues
1 <?php
2 // $Id: domain.install,v 1.24 2009/10/24 16:18:52 agentken Exp $
3
4 /**
5 * @file
6 * Install file.
7 */
8
9 /**
10 * Implement hook_install()
11 */
12 function domain_install() {
13 drupal_install_schema('domain');
14 $root = strtolower(rtrim($_SERVER['SERVER_NAME']));
15 $site = variable_get('site_name', 'Drupal');
16 $scheme = 'http';
17 if (!empty($_SERVER['HTTPS'])) {
18 $scheme = 'https';
19 }
20 db_query("UPDATE {domain} SET subdomain = '%s', sitename = '%s', scheme = '%s', valid = 1 WHERE domain_id = 0", $root, $site, $scheme);
21 if (!db_affected_rows()) {
22 db_query("INSERT INTO {domain} (subdomain, sitename, scheme, valid) VALUES ('%s', '%s', '%s', %d)", $root, $site, $scheme, 1);
23 // MySQL won't let us insert row 0 into an autoincrement table.
24 // Similar to the {users} table, this leaves us with no row 1.
25 db_query("UPDATE {domain} SET domain_id = domain_id - 1");
26 }
27 // Set the default domain variables.
28 variable_set('domain_root', $root);
29 variable_set('domain_scheme', $scheme);
30 variable_set('domain_sitename', $site);
31 }
32
33 /**
34 * Implement hook_schema()
35 */
36 function domain_schema() {
37 $schema['domain'] = array(
38 'fields' => array(
39 'domain_id' => array('type' => 'serial', 'not null' => TRUE),
40 'subdomain' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
41 'sitename' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
42 'scheme' => array('type' => 'varchar', 'length' => '8', 'not null' => TRUE, 'default' => 'http'),
43 'valid' => array('type' => 'varchar', 'length' => '1', 'not null' => TRUE, 'default' => '1')),
44 'primary key' => array('domain_id'),
45 'indexes' => array(
46 'subdomain' => array('subdomain')),
47 );
48 $schema['domain_access'] = array(
49 'fields' => array(
50 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
51 'gid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
52 'realm' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => '')),
53 'primary key' => array('nid', 'gid', 'realm'),
54 'indexes' => array(
55 'nid' => array('nid')),
56 );
57 $schema['domain_editor'] = array(
58 'fields' => array(
59 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
60 'domain_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)),
61 'primary key' => array('uid', 'domain_id'),
62 );
63 return $schema;
64 }
65
66 /**
67 * Implement hook_uninstall()
68 */
69 function domain_uninstall() {
70 drupal_uninstall_schema('domain');
71 db_query("DELETE from {variable} WHERE name LIKE '%s%%'", 'domain_');
72 }
73
74 /**
75 * Update note.
76 *
77 * Since versions prior to 5.x.1.0 are not supported, and ther are no schema changes from
78 * 5.x.1 to 6.x.1, no update functions have been provided for Drupal 6.
79 *
80 * To upgrade from a release candidate, first upgrade the module to 5.x.1.0. Then upgrade
81 * to Drupal 6.
82 *
83 */
84
85 /**
86 * Updates from 5.x.1.2 to 5.x.1.3. This change affected the size
87 * of the columns for 'subdomain' and 'sitename'. See http://drupal.org/node/244142
88 */
89 function domain_update_6100() {
90 $ret = array();
91 db_drop_index($ret, 'domain', 'subdomain');
92 db_change_field($ret, 'domain', 'subdomain', 'subdomain', array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''));
93 db_add_index($ret, 'domain', 'subdomain', array('subdomain'));
94 db_change_field($ret, 'domain', 'sitename', 'sitename', array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''));
95 return $ret;
96 }
97
98 /**
99 * Updates to 6.x.2.
100 *
101 * Deprecates the domain_editor grant.
102 * Adds the {domain_editor} table.
103 * Installs the new Domain Boostrap routine.
104 * Moves records from {user} (data) to {domain_editor}.
105 */
106 function domain_update_6200() {
107 $ret = array();
108
109 // Remove the old editors information.
110 variable_del('domain_editors');
111 // Promopt the user to rebuild node access.
112 node_access_needs_rebuild(TRUE);
113
114 // Update the new bootstrap information.
115 domain_bootstrap_register();
116
117 // Try to register the default domain.
118 $root = variable_get('domain_root', rtrim($_SERVER['HTTP_HOST']));
119 db_query("INSERT INTO {domain} (subdomain, sitename, scheme, valid) VALUES ('%s', '%s', '%s', %d)", $root, variable_get('domain_sitename', variable_get('site_name', 'Drupal')), variable_get('domain_scheme', 'http://'), 1);
120 // MySQL won't let us insert row 0 into an autoincrement table.
121 db_query("UPDATE {domain} SET domain_id = 0 WHERE subdomain = '%s'", $root);
122
123 // Install the {domain_editor} table.
124 $schema = domain_schema();
125 db_create_table($ret, 'domain_editor', $schema['domain_editor']);
126
127 // Move records from $user->data to {domain_editor}.
128 if (!db_table_exists('domain_editor')) {
129 return;
130 }
131 $result = db_query("SELECT uid, data FROM {users}");
132 while ($account = db_fetch_object($result)) {
133 $data = unserialize($account->data);
134 if (!empty($data['domain_user'])) {
135 foreach ($data['domain_user'] as $domain_id => $status) {
136 // A zero flag indicated not selected.
137 if ($status != 0) {
138 // Convert the -1 checkbox to a zero.
139 if ($domain_id == -1) {
140 $domain_id = 0;
141 }
142 db_query("INSERT INTO {domain_editor} (uid, domain_id) VALUES (%d, %d)", $account->uid, $domain_id);
143 }
144 }
145 }
146 }
147 return $ret;
148 }
149
150 /**
151 * Updates to 6.x.2.
152 *
153 * Deletes entries from {domain_editor} for domains that no longer exist.
154 *
155 * This update is needed by people who have been running 6.x.2rc versions.
156 *
157 */
158 function domain_update_6201() {
159 $ret = array();
160 db_query("DELETE FROM {domain_editor} WHERE NOT EXISTS (SELECT domain_id FROM {domain} WHERE {domain}.domain_id={domain_editor}.domain_id)");
161 return $ret;
162 }
163
164 /**
165 * Updates to 6.x.2.
166 *
167 * Removes the authoring and menu settings for the node form.
168 *
169 */
170 function domain_update_6202() {
171 $ret = array();
172 $options = variable_get('domain_form_elements', array());
173 if (isset($options['author'])) {
174 unset($options['author']);
175 }
176 if (isset($options['menu'])) {
177 unset($options['menu']);
178 }
179 variable_set('domain_form_elements', $options);
180 return $ret;
181 }
182
183 /**
184 * Fixes permission naming error in rc9 and lower.
185 */
186 function domain_update_6203() {
187 $ret = array();
188 $result = db_query("SELECT * FROM {permission}");
189 while ($permission = db_fetch_object($result)) {
190 if (strpos($permission->perm, 'publish to any assigned domains') > 0) {
191 $pid = (int) $permission->pid;
192 $string = db_escape_string(str_replace('publish to any assigned domains', 'publish to any assigned domain', $permission->perm));
193 $ret[] = update_sql("UPDATE {permission} SET perm = '$string' WHERE pid = $pid");
194 }
195 }
196 return $ret;
197 }
198
199 /**
200 * Adds the new 'access inactive domains' permission.
201 */
202 function domain_update_6204() {
203 $ret = array();
204 $result = db_query("SELECT * FROM {permission}");
205 while ($permission = db_fetch_object($result)) {
206 if (strpos($permission->perm, 'administer domains') > 0) {
207 $pid = (int) $permission->pid;
208 $string = db_escape_string($permission->perm .', access inactive domains');
209 if (module_exists('domain_nav')) {
210 $string .= ', access domain navigation';
211 }
212 $ret[] = update_sql("UPDATE {permission} SET perm = '$string' WHERE pid = $pid");
213 }
214 }
215 return $ret;
216 }

  ViewVC Help
Powered by ViewVC 1.1.2