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

Contents of /contributions/modules/drupalorg/drupalorg/drupalorg.install

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


Revision 1.1 - (show annotations) (download) (as text)
Tue Feb 10 17:03:19 2009 UTC (9 months, 2 weeks ago) by goba
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
Cleanup of drupalorg module and some blocks_and_nodes modules for starting new feature development.

 - All project* related things moved into drupalorg_project module, including project stuff from drupalorg module, bingo.*, branches.*, project_stuff.* and redirects.*.
 - The drupalorg module itself moved down to a drupalorg subdirectory, so the supplemental files do not interfer with the rest of the modules.
1 <?php
2 // $Id: drupalorg.install,v 1.17 2009/02/09 12:26:46 goba Exp $
3
4 /**
5 * @file
6 * Install and upgrade functionality for drupalorg.module.
7 */
8
9 /**
10 * Implementation of hook_install().
11 *
12 * Set the system weight heavier than cvslog so our form_alter comes later.
13 * See http://drupal.org/node/210497 for more information.
14 */
15 function drupalorg_install() {
16 db_query("UPDATE {system} SET weight = 5 WHERE name = 'drupalorg'");
17 }
18
19 /**
20 * Set the system weight to 1 so that it is invoked after project_usage.
21 *
22 * See http://drupal.org/node/327548 for more information.
23 */
24 function drupalorg_update_1() {
25 $ret = array();
26 $ret[] = update_sql("UPDATE {system} SET weight = 1 WHERE name = 'drupalorg'");
27 return $ret;
28 }
29
30 /**
31 * Set the system weight heavier than cvslog so our form_alter comes later.
32 *
33 * See http://drupal.org/node/210497 for more information.
34 */
35 function drupalorg_update_2() {
36 $ret = array();
37 $ret[] = update_sql("UPDATE {system} SET weight = 5 WHERE name = 'drupalorg'");
38 return $ret;
39 }
40
41 /**
42 * Enable modules and set some permissions and settings.
43 */
44 function drupalorg_update_6000() {
45 // Add new admin menu module and views module.
46 drupal_install_modules(array('admin_menu', 'views', 'view_ui', 'apachesolr', 'site_network', 'apachesolr_search', 'apachesolr_mess_up_results'));
47
48 // Segregate book block to book pages only.
49 variable_set('book_block_mode', 'book pages');
50
51 // Set temporary ApacheSolr settings.
52 variable_set('apachesolr_host', 'solr-do.drupalfr.org');
53 variable_set('apachesolr_port', '8080');
54 variable_set('apachesolr_enabled_facets', array('apachesolr_search' => array('uid' => 'uid', 'type' => 'type')));
55 variable_set('apachesolr_index_last', array(
56 // Those values come from the test site. They will need to be tweaked to match
57 // the D5 database dump we used to build the index.
58 'apachesolr_search' => array(
59 'last_change' => '1233245289',
60 'last_nid' => '320451',
61 ),
62 ));
63
64 // Enable drupal.org as a site_network server.
65 variable_set('site_network_server', 1);
66
67 // Add permissions to admins and some users.
68 _drupalorg_add_permissions(array(
69 'administrator' => array(
70 // Contact
71 'administer site-wide contact form',
72 // Forum
73 'delete any forum topic', 'delete own forum topics', 'edit any forum topic',
74 // Nodes
75 'create page content', 'create story content',
76 'delete any book content', 'delete any page content', 'delete any story content',
77 'delete own book content', 'delete own page content', 'delete own story content',
78 'edit any page content', 'edit any story content',
79 'edit own page content', 'edit own story content',
80 // Project
81 'browse project listings',
82 // System
83 'access site reports', 'administer actions', 'administer files',
84 // Admin_menu
85 'access administration menu', 'display drupal links',
86 // Views UI for development
87 'administer views'
88 ),
89 'anonymous' => array(
90 // Project
91 'browse project listings',
92 ),
93 'authenticated user' => array(
94 // Project
95 'browse project listings',
96 )
97 ));
98
99 return array();
100 }
101
102 /**
103 * Work around that image_update_5200() is insanely broken on Drupal 6.
104 *
105 * image_update_5200() tries to run a database change as if we are on the Drupal 5
106 * database. We are not. So that query fails, but we need to run the good one here
107 * to have the proper data.
108 */
109 function drupalorg_update_6001() {
110 $ret = array();
111 // Copy image files records into the new table.
112 $args = array_map('db_escape_string', array_keys(image_get_sizes()));
113 $cond = " IN ('". implode("', '", $args) ."')";
114 $ret[] = update_sql("INSERT INTO {image} SELECT DISTINCT u.nid, f.fid, f.filename FROM {files} f INNER JOIN {upload} u ON f.fid = u.fid INNER JOIN {node} n ON u.nid = n.nid WHERE n.type='image' AND f.filename". $cond);
115 return $ret;
116 }
117
118 /**
119 * Migrate simplenews news items to forums.
120 */
121 function drupalorg_update_6002() {
122 $ret = array();
123 // Fix one buggy newsletter post from the past and move it to the security news.
124 $ret[] = update_sql('UPDATE {simplenews_newsletters} SET tid = 44 WHERE tid = 0');
125 // Bogus existing forum IDs, which break our stuff.
126 $ret[] = update_sql('DELETE FROM {forum} WHERE nid IN (25390, 27678, 29754)');
127 // Add data for all newsletter posts as if they were forum topics all along.
128 // This data already exists in the term_node table, so we don't need to deal with that.
129 $ret[] = update_sql('INSERT INTO {forum} (nid, vid, tid) SELECT s.nid, n.vid, s.tid FROM {simplenews_newsletters} s LEFT JOIN {node} n ON s.nid = n.nid');
130 // Move all newsletters to the forums, except the test newsletter.
131 $ret[] = update_sql('UPDATE {term_data} SET vid = 1 WHERE vid = 4 AND tid != 121');
132 // Install the lists schema.
133 drupal_install_schema('lists');
134 // Add rows to lists_mailman, so it stores info on all things sent, and
135 // not going to resend them. Only do that for mails which we actually sent.
136 // There are old but unsent mails in there, which have s_status != 2.
137 $ret[] = update_sql('INSERT INTO {lists_mailman} (nid, uid, timestamp) SELECT nid, 1, NOW() FROM {simplenews_newsletters} WHERE s_status = 2');
138
139 // Now that we have the forum connections set up, convert existing simplenews
140 // nodes to forum nodes.
141 $ret[] = update_sql("UPDATE {node} SET type = 'forum' WHERE type = 'simplenews'");
142
143 // @todo The container for newsletters will be added manually and these three
144 // newsletters will be added to it via the slick drag and drop UI.
145 return $ret;
146 }
147
148 /**
149 * Migrate polls to story nodes.
150 */
151 function drupalorg_update_6003() {
152 $ret = array();
153
154 // Get node identifiers of all poll nodes for conversion.
155 $list_result = db_query("SELECT nid FROM {node} WHERE type = 'poll'");
156 while ($poll_node = db_fetch_object($list_result)) {
157
158 // We only have one revision per poll (polls were on way before revisions),
159 // so we will update their single node_revisions entry right away. Those only
160 // have the teaser/body set up with asterisks for RSS purposes, as poll
161 // module does by default in core, so we can replace that.
162 $poll_result = db_query("SELECT * from {poll_choices} WHERE nid = %d ORDER by chorder ASC", $poll_node->nid);
163 $poll_body = array();
164 while ($poll_choice = db_fetch_object($poll_result)) {
165 // Drupal.org uses format 1 (filtered HTML) for these nodes. It has <p>,
166 // <ul>, <li>, <strong> and <i> enabled, and that is all that is needed
167 // for these nodes, so we should be fine with that.
168 $poll_body[] = $poll_choice->chtext .' <strong>('. $poll_choice->chvotes .' votes)</strong>';
169 }
170 // Tell people this is an archived poll result node, present choices and votes statically.
171 $poll_body = '<p>Archived poll results:</p><ul><li>'. join('</li><li>', $poll_body) .'</li></ul>';
172 db_query('UPDATE {node_revisions} SET teaser = %d, body = %d WHERE nid = %d', $poll_body, $poll_body .'<!--break-->', $poll_node->nid);
173 }
174
175 // Now that we have the bodies and teasers, convert all poll nodes to story nodes.
176 $ret[] = update_sql("UPDATE {node} SET type = 'story' WHERE type = 'poll'");
177
178 return $ret;
179 }
180
181 /**
182 * Utility function to add permissions to certain user roles.
183 */
184 function _drupalorg_add_permissions($permissions) {
185 foreach ($permissions as $role => $grants) {
186 if (is_string($role)) {
187 $role = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", $role));
188 }
189 if ($role) {
190 $authz = db_result(db_query('SELECT perm FROM {permission} WHERE rid = %d', $role));
191 if (empty($authz)) {
192 // No permission record yet.
193 db_query("INSERT INTO {permission} (perm, rid) VALUES ('%s', %d)", join(', ', $grants), $role);
194 }
195 else {
196 // Existing permission record.
197 $authz_changed = FALSE;
198 foreach ($grants as $grant) {
199 if (strpos($authz, $grant) === FALSE) {
200 $authz .= ', '. $grant;
201 $authz_changed = TRUE;
202 }
203 }
204 if ($authz_changed) {
205 db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $authz, $role);
206 }
207 }
208 }
209 }
210 }

  ViewVC Help
Powered by ViewVC 1.1.2