| Commit | Line | Data |
|---|---|---|
| 764ef8fb | 1 | <?php |
| eb62bc9b | 2 | // $Id$ |
| 3 | ||
| eb62bc9b | 4 | /** |
| ef6c4d6b | 5 | * TODO: upgrade all update_14+ updates to d6 |
| eb62bc9b | 6 | */ |
| ef6c4d6b | 7 | |
| eb62bc9b | 8 | |
| 9 | /** | |
| ef6c4d6b | 10 | * Definition of hook_schema(); |
| eb62bc9b | 11 | */ |
| ef6c4d6b | 12 | function og_schema() { |
| 13 | $schema = array(); | |
| 14 | ||
| 15 | $schema['og'] = array( | |
| 3c543f0b | 16 | 'description' => t('Stores information about each group.'), |
| ef6c4d6b | 17 | 'fields' => array( |
| 18 | 'nid' => array( | |
| 3c543f0b | 19 | 'description' => t("The group's {node}.nid."), |
| ef6c4d6b | 20 | 'type' => 'int', |
| 21 | 'size' => 'normal', | |
| 22 | 'not null' => TRUE, | |
| 23 | ), | |
| 1f9bbe02 | 24 | 'og_selective' => array( |
| 3c543f0b | 25 | 'description' => t('Determines how subscription requests are handled (open, moderated, invite only, closed).'), |
| ef6c4d6b | 26 | 'type' => 'int', |
| 27 | 'size' => 'normal', | |
| 28 | 'not null' => TRUE, | |
| 29 | 'default' => 0, | |
| 30 | ), | |
| 1f9bbe02 | 31 | 'og_description' => array( |
| 3c543f0b | 32 | 'description' => t('Group description. Shows up by default on group directory.'), |
| ef6c4d6b | 33 | 'type' => 'varchar', |
| 34 | 'length' => 255, | |
| 35 | 'not null' => FALSE, | |
| 36 | ), | |
| 1f9bbe02 | 37 | 'og_theme' => array( |
| 3c543f0b | 38 | 'description' => t('The group specific theme (if any). See {system}.name.'), |
| ef6c4d6b | 39 | 'type' => 'varchar', |
| 40 | 'length' => 255, | |
| 41 | 'not null' => FALSE, | |
| 42 | ), | |
| 1f9bbe02 | 43 | 'og_register' => array( |
| 3c543f0b | 44 | 'description' => t('Should users be able to join this group from registration form.'), |
| ef6c4d6b | 45 | 'type' => 'int', |
| 46 | 'size' => 'tiny', | |
| 47 | 'not null' => TRUE, | |
| 48 | 'default' => 0, | |
| 49 | ), | |
| 1f9bbe02 | 50 | 'og_directory' => array( |
| 3c543f0b | 51 | 'description' => t('Should this group appear in the groups directory.'), |
| ef6c4d6b | 52 | 'type' => 'int', |
| 53 | 'size' => 'tiny', | |
| 54 | 'not null' => TRUE, | |
| 55 | 'default' => 0, | |
| 56 | ), | |
| 1f9bbe02 | 57 | 'og_language' => array( |
| 3c543f0b | 58 | 'description' => t('Group specific language. See {languages}.language.'), |
| ef6c4d6b | 59 | 'type' => 'varchar', |
| 60 | 'length' => 12, | |
| 61 | 'not null' => TRUE, | |
| 62 | 'default' => '', | |
| 63 | ), | |
| 1f9bbe02 | 64 | 'og_private' => array( |
| 3c543f0b | 65 | 'description' => t('Is group home page private or public.'), |
| ef6c4d6b | 66 | 'type' => 'int', |
| 67 | 'size' => 'tiny', | |
| 68 | 'not null' => TRUE, | |
| 69 | 'default' => 0, | |
| 70 | ), | |
| 71 | ), | |
| 72 | 'primary key' => array('nid'), | |
| 73 | ); | |
| 433c33db | 74 | |
| ef6c4d6b | 75 | $schema['og_uid'] = array( |
| 3c543f0b | 76 | 'description' => t('Group memberships'), |
| ef6c4d6b | 77 | 'fields' => array( |
| 78 | 'nid' => array( | |
| 3c543f0b | 79 | 'description' => t("Group's {node}.nid."), |
| ef6c4d6b | 80 | 'type' => 'int', |
| 81 | 'size' => 'normal', | |
| 82 | 'not null' => TRUE, | |
| 83 | ), | |
| 84 | 'og_role' => array( | |
| 3c543f0b | 85 | 'description' => t('Not currently used.'), |
| ef6c4d6b | 86 | 'type' => 'int', |
| 87 | 'size' => 'tiny', | |
| 88 | 'not null' => TRUE, | |
| 89 | 'default' => 0, | |
| 90 | ), | |
| 91 | 'is_active' => array( | |
| 3c543f0b | 92 | 'description' => t('Is this membership active or pending?'), |
| ef6c4d6b | 93 | 'type' => 'int', |
| 94 | 'size' => 'tiny', | |
| 95 | 'not null' => TRUE, | |
| 96 | 'default' => 0, | |
| 97 | ), | |
| 98 | 'is_admin' => array( | |
| 3c543f0b | 99 | 'description' => t('Is this user a group administrator?'), |
| ef6c4d6b | 100 | 'type' => 'int', |
| 101 | 'size' => 'tiny', | |
| 102 | 'not null' => TRUE, | |
| 103 | 'default' => 0, | |
| 104 | ), | |
| 105 | 'uid' => array( | |
| 3c543f0b | 106 | 'description' => t('The user for this membership. See {users}.uid.'), |
| ef6c4d6b | 107 | 'type' => 'int', |
| 108 | 'size' => 'normal', | |
| 109 | 'not null' => TRUE, | |
| 110 | ), | |
| ef6c4d6b | 111 | 'created' => array( |
| 3c543f0b | 112 | 'description' => t('Time when this membership was created.'), |
| ef6c4d6b | 113 | 'type' => 'int', |
| 114 | 'size' => 'normal', | |
| 115 | 'not null' => FALSE, | |
| 116 | 'default' => 0, | |
| 117 | ), | |
| 118 | 'changed' => array( | |
| 3c543f0b | 119 | 'description' => t('Time when this membership was last changed.'), |
| ef6c4d6b | 120 | 'type' => 'int', |
| 121 | 'size' => 'normal', | |
| 122 | 'not null' => FALSE, | |
| 123 | 'default' => 0, | |
| 124 | ), | |
| 125 | ), | |
| 126 | 'primary key' => array('nid', 'uid'), | |
| 127 | ); | |
| ef6c4d6b | 128 | $schema['og_ancestry'] = array( |
| 129 | 'description' => '', | |
| 130 | 'fields' => array( | |
| 131 | 'nid' => array( | |
| 3c543f0b | 132 | 'description' => t("The post's {node}.nid."), |
| ef6c4d6b | 133 | 'type' => 'int', |
| 134 | 'size' => 'normal', | |
| 135 | 'not null' => TRUE, | |
| 136 | ), | |
| 137 | 'group_nid' => array( | |
| 3c543f0b | 138 | 'description' => t("The group's {node}.nid."), |
| ef6c4d6b | 139 | 'type' => 'int', |
| 140 | 'size' => 'normal', | |
| 141 | 'not null' => TRUE, | |
| 142 | ), | |
| 143 | 'is_public' => array( | |
| 3c543f0b | 144 | 'description' => t('Is this a public or private post? This value is always the same across all groups for a given post.'), |
| ef6c4d6b | 145 | 'type' => 'int', |
| 146 | 'size' => 'tiny', | |
| 82630f07 | 147 | 'default' => 1, |
| ef6c4d6b | 148 | 'not null' => TRUE, |
| 149 | ), | |
| 150 | ), | |
| 151 | 'indexes' => array( | |
| 152 | 'nid' => array('nid'), | |
| 153 | 'group_nid' => array('group_nid'), | |
| 154 | ), | |
| 155 | ); | |
| 60329d55 | 156 | |
| ef6c4d6b | 157 | return $schema; |
| 60329d55 | 158 | } |
| 0d5a18d9 | 159 | |
| ef6c4d6b | 160 | function og_install() { |
| 161 | drupal_install_schema('og'); | |
| 0d5a18d9 | 162 | |
| ef6c4d6b | 163 | // enable standard og blocks. for custom profiles, block may not be included yet. |
| 35795f37 | 164 | if (function_exists('_block_rehash')) { |
| ef6c4d6b | 165 | _block_rehash(); |
| 0d5a18d9 | 166 | } |
| 167 | ||
| ef6c4d6b | 168 | |
| 169 | // Need og_readme() function. | |
| 170 | drupal_load('module', 'og'); | |
| 3c543f0b | 171 | drupal_set_message(t('Organic groups module enabled. Please see the included !readme_file for further installation instructions.', array('!readme_file' => og_readme()))); |
| 0d5a18d9 | 172 | } |
| 173 | ||
| ef6c4d6b | 174 | // First 5.x update. |
| 0d5a18d9 | 175 | // use the new na_arbitrator way of writing to node_access table |
| 176 | function og_update_14() { | |
| 4238c97f | 177 | switch ($GLOBALS['db_type']) { |
| 178 | case 'mysql': | |
| 179 | case 'mysqli': | |
| 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, | |
| 184 | KEY (nid), | |
| 185 | KEY (group_nid) | |
| 186 | ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); | |
| 187 | break; | |
| 188 | case 'pgsql': | |
| 189 | db_query("CREATE TABLE {og_ancestry} ( | |
| 261ffcd3 | 190 | nid int NOT NULL, |
| 191 | group_nid int NOT NULL, | |
| 192 | is_public smallint NOT NULL | |
| 193 | );"); | |
| 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);"); | |
| 4238c97f | 196 | break; |
| 0d5a18d9 | 197 | } |
| 4238c97f | 198 | og_migrate_type_basic_14(); |
| 0d5a18d9 | 199 | |
| 4238c97f | 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}"; | |
| 207 | db_query($sql); | |
| 0d5a18d9 | 208 | |
| 4238c97f | 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(); | |
| 212 | return array(); | |
| 0d5a18d9 | 213 | } |
| 214 | ||
| 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() { | |
| b914579f | 218 | if (og_is_group_type('og')) { |
| 0d5a18d9 | 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); | |
| 6a19ad3e | 221 | module_disable(array('og_basic')); |
| b914579f | 222 | node_types_rebuild(); |
| 0d5a18d9 | 223 | } |
| 224 | } | |
| 225 | ||
| a48ef886 | 226 | function og_update_15() { |
| 227 | variable_del('og_max_posts'); | |
| 228 | variable_del('og_home_page_presentation'); | |
| 6bffdc20 | 229 | return array(); |
| a48ef886 | 230 | } |
| 231 | ||
| d4c60c55 | 232 | function og_update_16() { |
| 233 | // we are no longer denying access to nodes without groups. see http://drupal.org/node/107289 | |
| b5cc463b | 234 | if (variable_get('og_enabled', 0)) { |
| 235 | node_access_rebuild(); | |
| 236 | } | |
| d4c60c55 | 237 | return array(); |
| 238 | } | |
| 239 | ||
| 4899e83d | 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(); | |
| 244 | } | |
| 245 | return array(); | |
| 246 | } | |
| 247 | ||
| be817721 | 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(); | |
| 252 | } | |
| 253 | return array(); | |
| 254 | } | |
| 255 | ||
| 44a425e3 | 256 | // Formerly contained og_uid_global code which is no longer required. |
| deb2cb69 | 257 | function og_update_19() { |
| 44a425e3 | 258 | return array(); |
| deb2cb69 | 259 | } |
| 260 | ||
| 78f8503e | 261 | function og_update_20() { |
| 262 | switch ($GLOBALS['db_type']) { | |
| 263 | case 'mysql': | |
| 264 | case 'mysqli': | |
| 265 | $ret[] = update_sql("ALTER TABLE {og} ADD private int(1) NOT NULL default 0"); | |
| 266 | break; | |
| 267 | case 'pgsql': | |
| 261ffcd3 | 268 | $ret[] = update_sql("ALTER TABLE {og} ADD private smallint NOT NULL default 0"); |
| 78f8503e | 269 | break; |
| 270 | } | |
| 271 | return $ret; | |
| 272 | } | |
| 9d9774b3 | 273 | |
| 274 | /** | |
| 275 | * Changes '@body' to '@node_teaser' in existing e-mail templates. | |
| 276 | */ | |
| 277 | function og_update_5600() { | |
| 278 | $ret = array(); | |
| 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"); | |
| 285 | } | |
| 286 | } | |
| 287 | return $ret; | |
| 288 | } | |
| 289 | ||
| bed5463f | 290 | /** |
| 291 | * Enable og_access module if needed | |
| 292 | */ | |
| 293 | function og_update_5700() { | |
| 294 | $ret = array(); | |
| 295 | if (variable_get('og_enabled', FALSE) && !module_exists('og_access')) { | |
| a412ae71 | 296 | drupal_install_modules('og_access'); |
| bed5463f | 297 | } |
| 298 | // variable_del('og_enabled'); is harmless to leave around, and will help if someone reruns the update. | |
| 299 | ||
| 300 | return $ret; | |
| 301 | } | |
| 302 | ||
| 8df5259b | 303 | /** |
| 304 | * Update variables to new content type system. Also rebuild node_access for new grants system. | |
| 305 | * | |
| 306 | * @return void | |
| 307 | **/ | |
| 18e68e88 | 308 | function og_update_5701() { |
| 309 | $ret = array(); | |
| 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'); | |
| 314 | } | |
| 315 | elseif (in_array($type->type, variable_get('og_omitted', array('og')))) { | |
| 316 | variable_set('og_content_type_usage_'. $type->type, 'omitted'); | |
| 317 | } | |
| 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'); | |
| 320 | } | |
| 321 | else { | |
| 322 | variable_set('og_content_type_usage_'. $type->type, 'group_post_standard_mail'); | |
| 323 | } | |
| 324 | } | |
| 325 | ||
| 326 | node_access_rebuild(); | |
| 327 | return $ret; | |
| 328 | } | |
| 329 | ||
| 44a425e3 Z |
330 | /** |
| 331 | * Notifications upgrade: Set flag to indicate that this is an upgraded | |
| 332 | * installation. | |
| 333 | */ | |
| 334 | function og_update_5703() { | |
| 335 | // Remove mail / no mail options from OG group types and move preferences to | |
| 336 | // og_notifications. | |
| 763a6ede | 337 | drupal_load('module', 'og'); |
| 44a425e3 Z |
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, ''); | |
| 343 | switch ($usage) { | |
| 344 | case 'group_post_standard_mail': | |
| 345 | $mail_types[$type] = $type; | |
| 346 | case 'group_post_standard_nomail': | |
| 347 | variable_set($variable, 'group_post_standard'); | |
| 348 | break; | |
| 349 | case 'group_post_wiki_mail': | |
| 350 | $mail_types[$type] = $type; | |
| 351 | case 'group_post_wiki_nomail': | |
| 352 | variable_set($variable, 'group_post_wiki'); | |
| 353 | break; | |
| 354 | } | |
| 355 | } | |
| 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); | |
| deb2cb69 | 359 | |
| 44a425e3 Z |
360 | // Vestigial variable. |
| 361 | variable_del('og_omitted_email_node_types'); | |
| deb2cb69 | 362 | |
| 44a425e3 Z |
363 | // Set update flag for og_notifications. |
| 364 | variable_set('og_notifications_update_required', 1); | |
| 365 | ||
| 366 | return array(); | |
| deb2cb69 | 367 | } |
| 368 | ||
| 7dc4064c Z |
369 | function og_update_6000() { |
| 370 | $ret = array(); | |
| 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); | |
| 376 | } | |
| a892cf2b | 377 | return $ret; |
| 7dc4064c Z |
378 | } |
| 379 | ||
| 380 | // Update to support views modularization while retaining backward compatibility. | |
| 381 | function og_update_6001() { | |
| 382 | $ret = array(); | |
| 383 | drupal_install_modules(array('og_views')); | |
| 384 | //enable the og_views block instead of the plain og one | |
| a892cf2b | 385 | $ret[] = update_sql("UPDATE {blocks} SET module = 'og_views', delta = '1' WHERE module = 'og' AND delta = '5'"); |
| 7dc4064c Z |
386 | return $ret; |
| 387 | } | |
| 388 | ||
| 389 | // Change field names in {og} table. Enables use of drupal_write_record() | |
| 390 | function og_update_6002() { | |
| 391 | $ret = array(); | |
| 392 | ||
| 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']); | |
| 402 | return $ret; | |
| 403 | } | |
| 404 | ||
| 44a425e3 Z |
405 | // end updates // |
| 406 | ||
| 88a7d390 | 407 | function og_uninstall() { |
| ef6c4d6b | 408 | drupal_uninstall_schema('og'); |
| 88a7d390 | 409 | |
| ce1adabe Z |
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}'); | |
| 414 | } | |
| 415 | ||
| 88a7d390 | 416 | // Delete variables |
| dee00474 | 417 | $variables = array( |
| 25494e75 | 418 | 'og_help', 'og_block_cnt_2', 'og_block_cnt_3', |
| 8df5259b | 419 | 'og_audience_checkboxes', 'og_omitted', 'og_content_type_usage', |
| 44a425e3 | 420 | 'og_audience_required', |
| dee00474 | 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', | |
| 3eca35a2 | 429 | 'og_request_user_body', 'og_request_user_subject', |
| ce1adabe | 430 | 'og_notifications_update_required', 'og_notifications_content_types' |
| dee00474 | 431 | ); |
| 88a7d390 | 432 | foreach ($variables as $variable) { |
| 433 | variable_del($variable); | |
| 434 | } | |
| dee00474 | 435 | } |
| b1095845 | 436 | |
| 437 | function og_requirements($phase) { | |
| 438 | // Need og_readme() function. | |
| 439 | drupal_load('module', 'og'); | |
| 440 | ||
| 441 | $requirements = array(); | |
| 442 | // Ensure translations don't break at install time | |
| 443 | $t = get_t(); | |
| 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))) { | |
| 44a425e3 Z |
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, | |
| b1095845 | 452 | ); |
| 453 | } | |
| 44a425e3 | 454 | |
| b1095845 | 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 | |
| 460 | ); | |
| 461 | } | |
| 462 | } | |
| 463 | ||
| 464 | return $requirements; | |
| 465 | } |