2 // $Id: og.install,v 1.71 2009/01/30 02:54:16 weitzman Exp $
5 * TODO: upgrade all update_14+ updates to d6
10 * Definition of hook_schema();
12 function og_schema() {
15 $schema['og'] = array(
16 'description' => t('Stores information about each group.'),
19 'description' => t("The group's {node}.nid."),
24 'og_selective' => array(
25 'description' => t('Determines how subscription requests are handled (open, moderated, invite only, closed).'),
31 'og_description' => array(
32 'description' => t('Group description. Shows up by default on group directory.'),
38 'description' => t('The group specific theme (if any). See {system}.name.'),
43 'og_register' => array(
44 'description' => t('Should users be able to join this group from registration form.'),
50 'og_directory' => array(
51 'description' => t('Should this group appear in the groups directory.'),
57 'og_language' => array(
58 'description' => t('Group specific language. See {languages}.language.'),
64 'og_private' => array(
65 'description' => t('Is group home page private or public.'),
72 'primary key' => array('nid'),
75 $schema['og_uid'] = array(
76 'description' => t('Group memberships'),
79 'description' => t("Group's {node}.nid."),
85 'description' => t('Not currently used.'),
92 'description' => t('Is this membership active or pending?'),
99 'description' => t('Is this user a group administrator?'),
106 'description' => t('The user for this membership. See {users}.uid.'),
112 'description' => t('Time when this membership was created.'),
119 'description' => t('Time when this membership was last changed.'),
126 'primary key' => array('nid', 'uid'),
128 $schema['og_ancestry'] = array(
132 'description' => t("The post's {node}.nid."),
137 'group_nid' => array(
138 'description' => t("The group's {node}.nid."),
143 'is_public' => array(
144 'description' => t('Is this a public or private post? This value is always the same across all groups for a given post.'),
152 'nid' => array('nid'),
153 'group_nid' => array('group_nid'),
160 function og_install() {
161 drupal_install_schema('og');
163 // enable standard og blocks. for custom profiles, block may not be included yet.
164 if (function_exists('_block_rehash')) {
169 // Need og_readme() function.
170 drupal_load('module', 'og');
171 drupal_set_message(t('Organic groups module enabled. Please see the included !readme_file for further installation instructions.', array('!readme_file' => og_readme())));
175 // use the new na_arbitrator way of writing to node_access table
176 function og_update_14() {
177 switch ($GLOBALS['db_type']) {
180 $ret[] = update_sql("CREATE TABLE {og_ancestry} (
181 nid int(11) NOT NULL,
182 group_nid int(11) NOT NULL,
183 is_public int(1) NULL,
186 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
189 db_query("CREATE TABLE {og_ancestry} (
191 group_nid int NOT NULL,
192 is_public smallint NOT NULL
194 db_query("CREATE INDEX {og_ancestry}_nid_idx ON {og_ancestry} (nid);");
195 db_query("CREATE INDEX {og_ancestry}_group_nid_idx ON {og_ancestry} (group_nid);");
198 og_migrate_type_basic_14();
200 // populate og_ancestry.
201 $result = db_query_temporary(
202 "SELECT na.nid, na.gid, IF(MIN(na.realm) = 'og_all', 1, 0) AS is_public
203 FROM {node_access} na INNER JOIN {node} n ON na.nid=n.nid
204 WHERE realm IN ('og_all', 'og_subscriber') AND n.type NOT IN ('%s') GROUP BY na.nid, na.gid ORDER BY nid ASC",
205 implode(', ', variable_get('og_node_types', array('og'))), 'og_migrate');
206 $sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) SELECT nid, gid, is_public FROM {og_migrate}";
209 // rebuild takes care of writing new access records
210 // too bad this part can't be performed over multiple updates
211 node_access_rebuild();
215 // Create a user managed node type which replaces the deprecated og_basic module
216 // helper function for og_update_14
217 function og_migrate_type_basic_14() {
218 if (og_is_group_type('og')) {
219 $info = array('type' => 'og', 'name' => 'group', 'module' => 'node', 'has_title' => 1, 'title_label' => 'Group name', 'has_body' => 1, 'body_label' => 'Welcome message', 'description' => 'A group provides a home page for like minded users. There they post articles about their shared interest.', 'help' => '', 'min_word_count' => 0, 'custom' => 1, 'modified' => 1, 'locked' => 0, 'orig_type' => 'og');
220 node_type_save((object)$info);
221 module_disable(array('og_basic'));
222 node_types_rebuild();
226 function og_update_15() {
227 variable_del('og_max_posts');
228 variable_del('og_home_page_presentation');
232 function og_update_16() {
233 // we are no longer denying access to nodes without groups. see http://drupal.org/node/107289
234 if (variable_get('og_enabled', 0)) {
235 node_access_rebuild();
240 function og_update_17() {
241 // we are once again putting group nodes into the node access system. see http://drupal.org/node/128306
242 if (variable_get('og_enabled', 0)) {
243 node_access_rebuild();
248 function og_update_18() {
249 // woops. got it a bit wrong last time
250 if (variable_get('og_enabled', 0)) {
251 node_access_rebuild();
256 // Formerly contained og_uid_global code which is no longer required.
257 function og_update_19() {
261 function og_update_20() {
262 switch ($GLOBALS['db_type']) {
265 $ret[] = update_sql("ALTER TABLE {og} ADD private int(1) NOT NULL default 0");
268 $ret[] = update_sql("ALTER TABLE {og} ADD private smallint NOT NULL default 0");
275 * Changes '@body' to '@node_teaser' in existing e-mail templates.
277 function og_update_5600() {
279 $variables = array('og_new_node_body', 'og_new_node_subject');
280 foreach ($variables as $variable) {
281 $value = variable_get($variable, '');
282 if (!empty($value)) {
283 variable_set($variable, str_replace('@body', '@node_teaser', $value));
284 $ret[] = array('success' => TRUE, 'query' => "Replaced @body with @node_teaser in $variable");
291 * Enable og_access module if needed
293 function og_update_5700() {
295 if (variable_get('og_enabled', FALSE) && !module_exists('og_access')) {
296 drupal_install_modules('og_access');
298 // variable_del('og_enabled'); is harmless to leave around, and will help if someone reruns the update.
304 * Update variables to new content type system. Also rebuild node_access for new grants system.
308 function og_update_5701() {
310 $types = node_get_types();
311 foreach ($types as $type) {
312 if (in_array($type->type, variable_get('og_node_types', array('og')))) {
313 variable_set('og_content_type_usage_'. $type->type, 'group');
315 elseif (in_array($type->type, variable_get('og_omitted', array('og')))) {
316 variable_set('og_content_type_usage_'. $type->type, 'omitted');
318 elseif (in_array($type->type, variable_get('og_omitted_email_node_types', array('og')))) {
319 variable_set('og_content_type_usage_'. $type->type, 'group_post_standard_nomail');
322 variable_set('og_content_type_usage_'. $type->type, 'group_post_standard_mail');
326 node_access_rebuild();
331 * Notifications upgrade: Set flag to indicate that this is an upgraded
334 function og_update_5703() {
335 // Remove mail / no mail options from OG group types and move preferences to
337 drupal_load('module', 'og');
338 $types = og_get_types('group_post');
339 $mail_types = array();
340 foreach ($types as $type) {
341 $variable = 'og_content_type_usage_'. $type;
342 $usage = variable_get($variable, '');
344 case 'group_post_standard_mail':
345 $mail_types[$type] = $type;
346 case 'group_post_standard_nomail':
347 variable_set($variable, 'group_post_standard');
349 case 'group_post_wiki_mail':
350 $mail_types[$type] = $type;
351 case 'group_post_wiki_nomail':
352 variable_set($variable, 'group_post_wiki');
356 // Set variable for og_notifications. If it is never enabled, this variable
357 // is also deleted in og_uninstall.
358 variable_set('og_notifications_content_types', $mail_types);
360 // Vestigial variable.
361 variable_del('og_omitted_email_node_types');
363 // Set update flag for og_notifications.
364 variable_set('og_notifications_update_required', 1);
369 function og_update_6000() {
371 // Fix how we append the custom request text from a group join request.
372 $name = 'og_request_user_body';
373 if ($txt = variable_get($name, FALSE)) {
374 $txt .= "\n\nPersonal message from @username:\n------------------\n\n@request";
375 variable_set($name, $txt);
380 // Update to support views modularization while retaining backward compatibility.
381 function og_update_6001() {
383 drupal_install_modules(array('og_views'));
384 //enable the og_views block instead of the plain og one
385 $ret[] = update_sql("UPDATE {blocks} SET module = 'og_views', delta = '1' WHERE module = 'og' AND delta = '5'");
389 // Change field names in {og} table. Enables use of drupal_write_record()
390 function og_update_6002() {
393 $schema = drupal_get_schema_unprocessed('og', 'og');
394 $fields = $schema['fields'];
395 db_change_field($ret, 'og', 'selective', 'og_selective', $fields['og_selective']);
396 db_change_field($ret, 'og', 'register', 'og_register', $fields['og_register']);
397 db_change_field($ret, 'og', 'theme', 'og_theme', $fields['og_theme']);
398 db_change_field($ret, 'og', 'directory', 'og_directory', $fields['og_directory']);
399 db_change_field($ret, 'og', 'description', 'og_description', $fields['og_description']);
400 db_change_field($ret, 'og', 'language', 'og_language', $fields['og_language']);
401 db_change_field($ret, 'og', 'private', 'og_private', $fields['og_private']);
407 function og_uninstall() {
408 drupal_uninstall_schema('og');
410 // In case og_notifications has never been enabled, the vestigial
411 // og_uid_global table will still be around.
412 if (variable_get('og_notifications_update_required', FALSE)) {
413 db_query('DROP TABLE {og_uid_global}');
418 'og_help', 'og_block_cnt_2', 'og_block_cnt_3',
419 'og_audience_checkboxes', 'og_omitted', 'og_content_type_usage',
420 'og_audience_required',
421 'og_visibility_directory', 'og_visibility_registration',
422 'og_home_page_view', 'og_email_max', 'og_node_types',
423 'og_admin_email_body', 'og_email_notification_pattern',
424 'og_approve_user_body', 'og_approve_user_subject',
425 'og_deny_user_body', 'og_deny_user_subject',
426 'og_invite_user_body', 'og_invite_user_subject',
427 'og_new_admin_body', 'og_new_admin_subject',
428 'og_new_node_body', 'og_new_node_subject',
429 'og_request_user_body', 'og_request_user_subject',
430 'og_notifications_update_required', 'og_notifications_content_types'
432 foreach ($variables as $variable) {
433 variable_del($variable);
437 function og_requirements($phase) {
438 // Need og_readme() function.
439 drupal_load('module', 'og');
441 $requirements = array();
442 // Ensure translations don't break at install time
444 if ($phase == 'runtime') {
445 $og_types = og_get_types('group');
446 $all_types = array_keys(node_get_types('types'));
447 if (!count(array_intersect($og_types, $all_types))) {
448 $requirements['og_group_types'] = array(
449 'title' => $t('Organic groups group type'),
450 'value' => $t('You have no node types which are acting as groups. See the notes section of the !readme_file and the content types fieldset at top of <a href="!settings">OG settings</a>.', array('!readme_file' => og_readme(), '!settings' => url('admin/og/og'))),
451 'severity' => REQUIREMENT_ERROR,
455 if (!module_exists('og_access')) {
456 $requirements['og_access'] = array(
457 'title' => $t('Organic groups access control'),
458 'value' => $t('Organic groups access control module is disabled. See the <a href="@modules">modules page</a>.', array('@modules' => url('admin/build/modules'))),
459 'severity' => REQUIREMENT_INFO
464 return $requirements;