Skip to content

Commit

Permalink
Issue backdrop-contrib#35: Port cleanup work.
Browse files Browse the repository at this point in the history
By @VasasA.
Progress towards completing the port. Work in progress.
  • Loading branch information
VasasA authored Feb 25, 2022
1 parent 8425712 commit ff9635f
Show file tree
Hide file tree
Showing 23 changed files with 350 additions and 886 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,42 @@ or moderated.
- [Organic Groups Terms, Definitions](https://github.com/backdrop-contrib/og/wiki/2.-Organic-Groups-Terms,-Definitions)
- [For Developers and Site Builders](https://github.com/backdrop-contrib/og/wiki/3.-For-Developers-and-Site-Builders)

## Upgrading Organic Groups from Drupal 7

If you are upgrading an existing Organic Groups installation from Drupal 7 (or upgrading a Drupal 7 module that requires Organic Groups), there are some steps you can (should) take to ensure that your upgraded installation is fully enabled at the end of the process.

#### Stub Modules

Backdrop Organic Groups relies on two modules that don't exist in Drupal:

- Entity UI (`entity_ui`), needed for the Backdrop version of Organic Groups;
- Entity Plus (`entity_plus`), also needed for the Backdrop version of Organic Groups.

When the Backdrop version of `update.php` runs, if those modules are not present and enabled, then the update will disable all of the Backdrop modules that depend on them, which includes Organic Groups, plus any further modules that depend on Organic Groups.

So the solution is to install "stub" modules in the Drupal installation prior to generating the database from which the Backdrop upgrade will take place.

#### Upgrade Process

Assuming you are following [the official upgrade instructions](https://backdropcms.org/upgrade-from-drupal) or something similar [like this](https://packweb.eu/blog/migrating-drupal-7-backdrop-cms), do the following:

1. Download and unzip these two modules, which are Drupal "stub" modules:
- [entity_plus.zip](https://github.com/backdrop-contrib/rules/wiki/files/entity_plus.zip)
- [entity_ui.zip](https://github.com/backdrop-contrib/rules/wiki/files/entity_ui.zip)

2. In Step 2, "Prepare your Drupal site for upgrade", prior to substep 9 ("Make a second backup...calling it backdrop-ready.sql"),

- Install those two modules into `sites/all/modules` of your Drupal installation;
- Enable those two modules. (They don't do anything. This just makes your database know that they exist, or rather, that they will be forthcoming.)

3. Continue with substep 9: make your second backup of the database to be used for Backdrop, e.g., backdrop-ready.sql.

4. Once you have made that second backup, you can uninstall and remove the two stub modules from your Drupal installation.

5. Continue with the rest of the migration/upgrade process.

Of course, make sure that you've already installed the Backdrop versions of Organic Groups, Entity Plus, and Entity UI in your Backdrop contrib folder prior to running `update.php`, or all of the above will be for naught.

## Issues

- Bugs and Feature requests should be reported in the
Expand Down
20 changes: 8 additions & 12 deletions config/og.settings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"_config_name": "og.settings",
"og_7000_add_field": "FALSE",
"og_content_type_usage_typetype": "dynamic variable in file /og/includes/migrate/7000/og_add_fields.inc line 27",
"og_7200_ogur_roles": "FALSE",
"og_user_roles_roles_typetype": "dynamic variable in file /og/includes/migrate/7000/og_ogur_roles.migrate.inc line 37",
"og_node_access_strict": "TRUE",
"og_use_queue": "FALSE",
"og_orphans_delete": "FALSE",
"og_is_group__entity_type__bundle": "dynamic variable in file /og/og.module line 1839",
"og_group_manager_full_access": "TRUE",
"og_is_group_default_access__group_type__bundle": "dynamic variable in file /og/og.module line 2617",
"og_maintain_overridden_roles": "TRUE",
"og_features_ignore_og_fields": "FALSE"
"og_7000_add_field": false,
"og_7200_ogur_roles": false,
"og_node_access_strict": true,
"og_use_queue": false,
"og_orphans_delete": false,
"og_group_manager_full_access": true,
"og_maintain_overridden_roles": true,
"og_features_ignore_og_fields": false
}
4 changes: 2 additions & 2 deletions og.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function hook_og_role_revoke($entity_type, $gid, $uid, $rid) {
*/
function hook_og_role_change_permissions($role, $grant, $revoke) {
if (!$role->gid) {
drupal_set_message(t('Global group permissions granted for @role users: @permissions', array('@role' => $role->name, '@permissions' => implode(', ', $grant))));
backdrop_set_message(t('Global group permissions granted for @role users: @permissions', array('@role' => $role->name, '@permissions' => implode(', ', $grant))));
}
}

Expand Down Expand Up @@ -233,7 +233,7 @@ function hook_og_invalidate_cache($gids = array()) {
);

foreach ($caches as $cache) {
drupal_static_reset($cache);
backdrop_static_reset($cache);
}
}

Expand Down
61 changes: 30 additions & 31 deletions og.install
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,6 @@ function og_install() {
* Implements hook_uninstall().
*/
function og_uninstall() {
db_delete('variable')
->condition('name', 'og_group_manager_default_rids_%', 'LIKE')
->execute();

db_delete('variable')
->condition('name', 'og_is_group_default_access__%__%', 'LIKE')
->execute();

$vars = array(
'og_context',
'og_group_manager_full_access',
'og_skip_access',
'og_update_batch_size',
'og_upgrade_7001',
'og_node_access_strict',
'og_features_ignore_og_fields',
'og_maintain_overridden_roles',
);
foreach ($vars as $var) {
// TODO This variable was probably removed in Backdrop without replacement.
variable_del($var);
}

// Delete OG-core fields.
$og_fields = array(
'group_group',
Expand Down Expand Up @@ -434,27 +411,49 @@ function og_update_last_removed() {
function og_update_1000() {
$config = config('og.settings');
$config->set('og_7000_add_field', update_variable_get('og_7000_add_field', 'FALSE'));
$config->set('og_content_type_usage_typetype', update_variable_get('og_content_type_usage_typetype', 'dynamic variable in file /og/includes/migrate/7000/og_add_fields.inc line 27'));
$config->set('og_7200_ogur_roles', update_variable_get('og_7200_ogur_roles', 'FALSE'));
$config->set('og_user_roles_roles_typetype', update_variable_get('og_user_roles_roles_typetype', 'dynamic variable in file /og/includes/migrate/7000/og_ogur_roles.migrate.inc line 37'));
$config->set('og_node_access_strict', update_variable_get('og_node_access_strict', 'TRUE'));
$config->set('og_use_queue', update_variable_get('og_use_queue', 'FALSE'));
$config->set('og_orphans_delete', update_variable_get('og_orphans_delete', 'FALSE'));
$config->set('og_is_group__entity_type__bundle', update_variable_get('og_is_group__entity_type__bundle', 'dynamic variable in file /og/og.module line 1839'));
$config->set('og_group_manager_full_access', update_variable_get('og_group_manager_full_access', 'TRUE'));
$config->set('og_is_group_default_access__group_type__bundle', update_variable_get('og_is_group_default_access__group_type__bundle', 'dynamic variable in file /og/og.module line 2617'));
$config->set('og_maintain_overridden_roles', update_variable_get('og_maintain_overridden_roles', 'TRUE'));
$config->set('og_features_ignore_og_fields', update_variable_get('og_features_ignore_og_fields', 'FALSE'));
$config->save();
update_variable_del('og_7000_add_field');
update_variable_del('og_content_type_usage_typetype');
update_variable_del('og_7200_ogur_roles');
update_variable_del('og_user_roles_roles_typetype');
update_variable_del('og_node_access_strict');
update_variable_del('og_use_queue');
update_variable_del('og_orphans_delete');
update_variable_del('og_is_group__entity_type__bundle');
update_variable_del('og_group_manager_full_access');
update_variable_del('og_is_group_default_access__group_type__bundle');
update_variable_del('og_maintain_overridden_roles');
update_variable_del('og_features_ignore_og_fields');

$result = db_select('variable', 'v')
->fields('v', array('name'))
->condition('name', 'og_group_manager_default_rids_%', 'LIKE')
->execute()
->fetchCol();
foreach($result as $name) {
$config->set($name, update_variable_get($name, array()));
update_variable_del($name);
}
$result = db_select('variable', 'v')
->fields('v', array('name'))
->condition('name', 'og_is_group_default_access__%__%', 'LIKE')
->execute()
->fetchCol();
foreach($result as $name) {
$config->set($name, update_variable_get($name, 'TRUE'));
update_variable_del($name);
}
$result = db_select('variable', 'v')
->fields('v', array('name'))
->condition('name', 'og_is_group__%__%', 'LIKE')
->execute()
->fetchCol();
foreach($result as $name) {
$config->set($name, update_variable_get($name, 'FALSE'));
update_variable_del($name);
}
$config->save();
}
24 changes: 17 additions & 7 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ function og_og_default_roles() {
*/
function og_config_info() {
$prefixes['og.settings'] = array(
'label' => t('Module name settings'),
'label' => t('Organic groups settings'),
'group' => t('Configuration'),
);
}
Expand Down Expand Up @@ -889,8 +889,7 @@ function og_entity_insert($entity, $entity_type) {
og_group($entity_type, $id, array('entity' => $entity->uid));
// Assign roles to group manager.
$name = 'og_group_manager_default_rids_' . $entity_type . '_' . $bundle;
// TODO This variable was probably removed in Backdrop without replacement.
if ($rids = variable_get($name)) {
if ($rids = config_get('og.settings', $name)) {
foreach ($rids as $rid) {
og_role_grant($entity_type, $id, $entity->uid, $rid);
}
Expand All @@ -916,8 +915,7 @@ function og_entity_update($entity, $entity_type) {
og_group($entity_type, $id, array('entity' => $entity->uid));
// Assign roles to group manager.
$name = 'og_group_manager_default_rids_' . $entity_type . '_' . $bundle;
// TODO This variable was probably removed in Backdrop without replacement.
if ($rids = variable_get($name)) {
if ($rids = config_get('og.settings', $name)) {
foreach ($rids as $rid) {
og_role_grant($entity_type, $id, $entity->uid, $rid);
}
Expand Down Expand Up @@ -1876,7 +1874,13 @@ function og_is_group($entity_type, $entity) {
}
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
if (!field_info_instance($entity_type, OG_GROUP_FIELD, $bundle)) {
return config_get('og.settings', "og_is_group__{$entity_type}__{$bundle}");
$config = config('og.settings');
$variable = "og_is_group__{$entity_type}__{$bundle}";
if ($config->get($variable) === NULL) {
$config->set($variable, FALSE);
$config->save();
}
return $config->get($variable);
}
$items = field_get_items($entity_type, $entity, OG_GROUP_FIELD);

Expand Down Expand Up @@ -2654,7 +2658,13 @@ function og_is_group_default_access($group_type, $gid) {
$bundle = $wrapper->getBundle();

if (!field_info_instance($group_type, OG_DEFAULT_ACCESS_FIELD, $bundle)) {
return config_get('og.settings', "og_is_group_default_access__{$group_type}__{$bundle}");
$config = config('og.settings');
$variable = "og_is_group_default_access__{$group_type}__{$bundle}";
if ($config->get($variable) === NULL) {
$config->set($variable, TRUE);
$config->save();
}
return $config->get($variable);
}

if (empty($wrapper->{OG_DEFAULT_ACCESS_FIELD})) {
Expand Down
4 changes: 4 additions & 0 deletions og_access/config/og_access.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_config_name": "og_access.settings",
"og_access_privacy_change_batch_processing": true
}
31 changes: 12 additions & 19 deletions og_access/og_access.install
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,22 @@
* Implements hook_uninstall().
*/
function og_access_uninstall() {
$vars = array(
'og_access_strict_private',
);
foreach ($vars as $var) {
// TODO This variable was probably removed in Backdrop without replacement.
variable_del($var);
}

// TODO This variable was probably removed in Backdrop without replacement.
variable_del(OG_ACCESS_PRIVACY_CHANGE_BATCH_PROCESSING);
}

/**
* Implements hook_schema();().
* Implements hook_update_N().
*/
function og_access_schema() {
if (db_table_exists('og_access_post')) {
db_rename_table('og_access_post', 'd6_og_access_post');
}
function og_access_update_1000() {
$config = config('og_access.settings');
$config->set('og_access_privacy_change_batch_processing', update_variable_get('og_access_privacy_change_batch_processing', 'TRUE'));
$config->save();
update_variable_del('og_access_privacy_change_batch_processing');
}

// TODO The old hook_update_N functions cannot be applied to Backdrop.
function og_access_update_7000(&$sandbox) { }

// TODO The old hook_update_N functions cannot be applied to Backdrop.
function og_access_update_7200(&$sandbox) { }
/**
* Implements hook_update_last_removed().
*/
function og_access_update_last_removed() {
return 7200;
}
17 changes: 13 additions & 4 deletions og_access/og_access.module
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ function og_access_og_access_invoke_node_access_acquire_grants($context) {
*/
function og_access_check_node_access_grants_is_needed($entity, $entity_type) {
// Check whether group privacy change batch processing is needed.
// TODO This variable was probably removed in Backdrop without replacement.
if (!variable_get(OG_ACCESS_PRIVACY_CHANGE_BATCH_PROCESSING, TRUE)) {
if (!config_get('og_access.settings', OG_ACCESS_PRIVACY_CHANGE_BATCH_PROCESSING)) {
return FALSE;
}

Expand Down Expand Up @@ -427,12 +426,11 @@ function og_access_invoke_node_access_acquire_grants($group_type, $group_id, &$c
* Implements hook_form_FORM_ID_alter().
*/
function og_access_form_og_ui_admin_settings_alter(&$form, &$form_state) {
// TODO This variable was probably removed in Backdrop without replacement.
$form[OG_ACCESS_PRIVACY_CHANGE_BATCH_PROCESSING] = array(
'#type' => 'checkbox',
'#title' => t('Update group content privacy'),
'#description' => t('Upon group privacy change, create batch operation to update group content.'),
'#default_value' => variable_get(OG_ACCESS_PRIVACY_CHANGE_BATCH_PROCESSING, TRUE),
'#default_value' => config_get('og_access.settings', OG_ACCESS_PRIVACY_CHANGE_BATCH_PROCESSING),
);
}

Expand All @@ -443,3 +441,14 @@ function og_access_autoload_info() {
return array(
);
}

/**
* Implements hook_config_info().
*/
function og_access_config_info() {
$prefixes['og_access.settings'] = array(
'label' => t('Organic groups access control settings'),
'group' => t('Configuration'),
);
return $prefixes;
}
Loading

0 comments on commit ff9635f

Please sign in to comment.