From f07f3583db1bb757df710ffe6d0b90db234d876f Mon Sep 17 00:00:00 2001 From: "Robert J. Lang" Date: Thu, 10 Dec 2020 16:43:19 -0800 Subject: [PATCH 1/4] Minor code formatting --- profile.module | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/profile.module b/profile.module index 7f7f72c..c8aca52 100644 --- a/profile.module +++ b/profile.module @@ -235,7 +235,7 @@ function profile_user_edit_access($account, $type_name) { $profile = profile_load_by_user($account, $type_name); if (empty($profile)) { $profile = profile_create(array('type' => $type_name, 'uid' => $account->uid)); - } + } if (profile_access('edit', $profile, $account)) { return TRUE; } @@ -464,12 +464,12 @@ function profile_type_save($type) { $data = (array) $type; $data += array( - 'userview' => true, + 'userview' => TRUE, 'registration' => 0, 'roles' => array( 'authenticated' => 'authenticated', ), - 'module' => null, + 'module' => NULL, 'weight' => '0', 'storage' => 1, 'status' => 1, @@ -499,7 +499,7 @@ function profile_type_delete($type) { } /** - * Implements hook_profile_type_delete() + * Implements hook_profile_type_delete(). */ function profile_profile_type_delete($type) { $pids = array_keys(profile_load_multiple(FALSE, array('type' => $type->type))); @@ -530,8 +530,8 @@ function profile_user_view($account, $view_mode, $langcode) { /** * Implements hook_form_FORM_ID_alter() for the user edit form. * - * @see profile_form_validate_handler - * @see profile_form_submit_handler + * @see profile_form_validate_handler() + * @see profile_form_submit_handler() */ function profile_form_user_profile_form_alter(&$form, &$form_state, $form_id) { $profile_display = config_get('profile.settings', 'profile_display'); @@ -562,7 +562,7 @@ function profile_form_user_profile_form_alter(&$form, &$form_state, $form_id) { $profile = profile_create(array('type' => $type_name, 'uid' => $form_state['user']->uid)); } $form_state['profiles'][$profile->type] = $profile; - profile_attach_form($form, $form_state); + profile_attach_form($form, $form_state); } } else { @@ -570,10 +570,10 @@ function profile_form_user_profile_form_alter(&$form, &$form_state, $form_id) { $profile = profile_load_by_user($form_state['user'], $type_name); if (empty($profile)) { $profile = profile_create(array('type' => $type_name, 'uid' => $form_state['user']->uid)); - } + } if (profile_access('edit', $profile)) { $form_state['profiles'][$profile->type] = $profile; - profile_attach_form($form, $form_state); + profile_attach_form($form, $form_state); // Wrap each profile form in a fieldset. $form['profile_' . $type_name] += array( '#type' => 'fieldset', @@ -659,7 +659,7 @@ function profile_attach_form(&$form, &$form_state) { // Provide a central place for modules to alter the profile forms, but // skip that in case the caller cares about invoking the hooks. - // @see profile_form(). + // @see profile_form() if (!isset($form_state['profile_skip_hook'])) { $hooks[] = 'form_profile_edit_' . $type . '_form'; $hooks[] = 'form_profile_form'; @@ -1038,6 +1038,9 @@ function profile_user_get_properties($account, array $options, $name) { } +/** + * Return class autoload information. + */ function profile_autoload_info() { return array( 'Profile' => 'profile.entity.inc', @@ -1136,12 +1139,12 @@ function profile_config_info() { */ function profile_type_set_defaults() { $new_type = array( - 'userview' => true, + 'userview' => TRUE, 'type' => '', 'label' => '', 'registration' => 1, 'roles' => array(), - 'module' => null, + 'module' => NULL, 'weight' => 0, 'storage' => PROFILE_STORAGE_NORMAL, 'status' => PROFILE_STATUS_ENABLED, From 1529ea152373e07b9ca3b951297bf9c88d48a075 Mon Sep 17 00:00:00 2001 From: "Robert J. Lang" Date: Thu, 10 Dec 2020 16:49:58 -0800 Subject: [PATCH 2/4] Recommit Profile2 importing code and README Re-adding Profile2 import code and README fixes that were lost in a regression. --- README.md | 62 +++++++++++++++----- profile.install | 150 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 195 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2e99475..90fe129 100644 --- a/README.md +++ b/README.md @@ -3,31 +3,65 @@ Profile Supports configurable user profiles. +This module is the successor to the [Drupal 7 Profile2 module](https://drupal.org/project/profile2). + Installation ------------- - * Copy the whole profile directory to your modules directory and - activate the module. - +* Install this module using the official Backdrop CMS instructions at + https://backdropcms.org/guide/modules. Usage ----- - - * Go to /admin/structure/profiles for managing profile types. - * By default users may view their profile at /user and edit them at - 'user/X/edit'. -LICENSE ---------------- +* Visit the configuration page under Administration > Structure > + Profiles (admin/structure/profiles) for managing profile types. + +* By default users may view their profile at /user and edit them at + user/N/edit. + +Upgrading from Drupal 7 +----------------------- + +This module is the successor to the [Drupal 7 Profile2 +module](https://drupal.org/project/profile2) and will automatically import and +convert any Profile2 profiles when upgrading from a Drupal 7 installation. + +Note that this module does NOT import from the [deprecated Profile +module](https://www.drupal.org/node/874026) that was provided in Drupal 7 core +as an upgrade path from Drupal 6 sites that used Profiles. If you have profiles +from the Drupal 7 Profile module, you should either convert them to Profile2 +profiles in Drupal 7 prior to upgrading to Backdrop, or recreate them in +Backdrop after you upgrade. + +Documentation +------------- + +Additional documentation is located in the [Wiki](https://github.com/backdrop-contrib/profile/wiki/Documentation). + +Issues +------ + +Bugs and feature requests should be reported in the [Issue Queue](https://github.com/backdrop-contrib/profile/issues). + +License +--------------- -This project is GPL v2 software. See the LICENSE.txt file in this directory +This project is GPL v2 software. See the LICENSE.txt file in this directory for complete text. + +Current Maintainers +------------------- + +* [Robert J. Lang](https://github.com/bugfolder) + Credits: ---------- -Ported by docwlmot -Original Drupal maintained module by - * Wolfgang Ziegler (fago), nuppla@zites.net - * Joachim Noreiko (joachim), joachim.n+backdrop@gmail.com +* Ported to Backdrop CMS by [docwilmot](https://github.com/docwilmot). + +* Original Drupal maintained module by + * [Wolfgang Ziegler (fago)](https://www.drupal.org/u/fago), nuppla@zites.net + * [Joachim Noreiko (joachim)](https://www.drupal.org/u/joachim), joachim.n+backdrop@gmail.com diff --git a/profile.install b/profile.install index f1f4226..bce3c5f 100644 --- a/profile.install +++ b/profile.install @@ -11,6 +11,7 @@ function profile_install() { } + /** * Implements hook_schema(). */ @@ -74,8 +75,9 @@ function profile_schema() { return $schema; } + /** - * Implements hook_uninstall() + * Implements hook_uninstall(). */ function profile_uninstall() { $config_names = config_get_names_with_prefix('profile'); @@ -86,9 +88,151 @@ function profile_uninstall() { } } + +/** + * Implements hook_requirements(). + * + * This is here to deal with an update numbering problem in early versions of + * this module (updates started numbering at 10000, not 1000). If the wrong + * number is detected for the last update version, we fix it so that updates + * proceed properly going forward. + */ +function profile_requirements($phase) { + if ($phase == 'update' || $phase == 'runtime') { + if (backdrop_get_installed_schema_version('profile') == 10000) { + backdrop_set_installed_schema_version('profile', 1000); + } + } + return array(); +} + + /** - * Implements hook_update_N() + * Implements hook_update_dependencies(). + * + * Make sure field module has already created the config files before running + * update 1001. + * + * @see field_update_1001(). */ -function profile_update_10000() { +function profile_update_dependencies() { + $dependencies['profile'][1001] = array( + 'field' => 1001, + ); +} + + +/** + * Initialize the profile settings to use fieldsets. + */ +function profile_update_1000() { config_set('profile.settings', 'profile_display', 'fieldsets'); } + + +/** + * Migrate any existing Profile2 profiles into this module. + */ +function profile_update_1001() { + if (!db_table_exists('profile_type')) { + return; + } + + // Get Profile2 types from the table left behind in the db. + $profile2_types = db_query(' + SELECT * + FROM {profile_type} + ') + ->fetchAllAssoc('id', PDO::FETCH_ASSOC); + + // Create profile.type config files for each type. + foreach ($profile2_types as &$type) { + $type['data'] = unserialize($type['data']); + if (isset($type['data']['roles'])) { + // Authenticated role changes its key in Backdrop. + if (isset($type['data']['roles']['2'])) { + unset($type['data']['roles']['2']); + $type['data']['roles'][BACKDROP_AUTHENTICATED_ROLE] = + BACKDROP_AUTHENTICATED_ROLE; + } + } + else { + $type['data']['roles'] = array(); + } + $config = config('profile.type.' . $type['type']); + $config_data = array( + 'userview' => TRUE, + 'type' => $type['type'], + 'label' => $type['label'], + 'registration' => $type['data']['registration'], + 'roles' => $type['data']['roles'], + 'weight' => $type['weight'], + 'status' => $type['status'], + 'module' => $type['module'], + 'storage' => 1, + ); + $config->setData($config_data); + $config->save(); + } + + // Drop the profile_type db table, no longer needed. + db_drop_table('profile_type'); + + // Backdrop's standard upgrade process converted the Profile2 bundles and + // their fields to the new config style, but it left their entity_type as + // 'profile2', whereas this module uses the entity_type of 'profile'. So we + // need to further convert config files and db tables. + + // Get Profile2 bundles from config and convert to entity_type profile. + $config_names = config_get_names_with_prefix('field.bundle.profile2.'); + foreach ($config_names as $config_file) { + $config = config($config_file); + $config->setName(str_replace('profile2', 'profile', $config->getName())); + $config->set('entity_type', 'profile'); + $config->save(); + + // Remove the bundle data from the variables table. + $bundle = $config->get('bundle'); + update_variable_del('field_bundle_settings__' . $bundle); + + // Remove the old bundle config file that contains 'profile2'. + $old_config = config($config_file); + $old_config->delete(); + } + + // Get Profile2 field instances from config and convert to entity_type profile. + $config_names = config_get_names_with_prefix('field.instance.profile2.'); + foreach ($config_names as $config_file) { + $config = config($config_file); + $config->setName(str_replace('profile2', 'profile', $config->getName())); + $config->set('entity_type', 'profile'); + $config->save(); + + // The field tables exist (and have data), but their entity_type is left as + // profile2 after Backdrop does its upgrade, so we need to change that + // column for the data and revision tables. + $field_name = $config->get('field_name'); + db_update('field_data_' . $field_name) + ->fields(array( + 'entity_type' => 'profile', + )) + ->condition('entity_type', 'profile2') + ->execute(); + db_update('field_revision_' . $field_name) + ->fields(array( + 'entity_type' => 'profile', + )) + ->condition('entity_type', 'profile2') + ->execute(); + + // Remove the old field instance config file that contains 'profile2'. + $old_config = config($config_file); + $old_config->delete(); + } + + // Remove the residue of the D7 Profile2 module. + db_query(" + DELETE FROM {system} + WHERE name = 'profile2' + AND type = 'module'"); +} From d2e1ceebbb86a50cf7204917a89e63b1a920ac59 Mon Sep 17 00:00:00 2001 From: "Robert J. Lang" Date: Thu, 14 Jan 2021 06:39:58 -0800 Subject: [PATCH 3/4] Add cleanup from Profile module Add cleanup of residue from Profile modules. Small tweaks to titles and descriptions of admin pages. --- README.md | 7 +++++-- profile.admin.inc | 4 ++-- profile.install | 8 ++++++++ profile.module | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 90fe129..bbdbb6d 100644 --- a/README.md +++ b/README.md @@ -24,16 +24,18 @@ Upgrading from Drupal 7 ----------------------- This module is the successor to the [Drupal 7 Profile2 -module](https://drupal.org/project/profile2) and will automatically import and +module](https://drupal.org/project/profile2) and can automatically import and convert any Profile2 profiles when upgrading from a Drupal 7 installation. -Note that this module does NOT import from the [deprecated Profile +Note that this module does _not_ import from the [deprecated Profile module](https://www.drupal.org/node/874026) that was provided in Drupal 7 core as an upgrade path from Drupal 6 sites that used Profiles. If you have profiles from the Drupal 7 Profile module, you should either convert them to Profile2 profiles in Drupal 7 prior to upgrading to Backdrop, or recreate them in Backdrop after you upgrade. +If you are migrating Drupal 7 Profile2 profiles to Backdrop Profile, you should, however, _enable_ the Drupal 7 Profile module before preparing the db for migration. + Documentation ------------- @@ -65,3 +67,4 @@ Credits: * [Wolfgang Ziegler (fago)](https://www.drupal.org/u/fago), nuppla@zites.net * [Joachim Noreiko (joachim)](https://www.drupal.org/u/joachim), joachim.n+backdrop@gmail.com +`` diff --git a/profile.admin.inc b/profile.admin.inc index ace445e..d950a2b 100644 --- a/profile.admin.inc +++ b/profile.admin.inc @@ -27,7 +27,7 @@ function profile_display_settings_form($form, &$form_state) { '#value' => t('Save configuration'), '#weight' => 40, ); - + return $form; } @@ -119,7 +119,7 @@ function profile_type_form($form, &$form_state, $profile_type, $op = 'edit') { '#submit' => array('profile_type_form_submit_delete') ); } - + return $form; } diff --git a/profile.install b/profile.install index bce3c5f..c842a6b 100644 --- a/profile.install +++ b/profile.install @@ -236,3 +236,11 @@ function profile_update_1001() { WHERE name = 'profile2' AND type = 'module'"); } + +/** + * Drop any leftover D7 Profile module tables. + */ +function profile_update_1002() { + db_drop_table('profile_field'); + db_drop_table('profile_value'); +} diff --git a/profile.module b/profile.module index c8aca52..9704316 100644 --- a/profile.module +++ b/profile.module @@ -137,10 +137,10 @@ function profile_menu() { ); $items['admin/config/people/profiles'] = array( - 'title' => 'Profile display settings', + 'title' => 'Profile display', 'page callback' => 'backdrop_get_form', 'page arguments' => array('profile_display_settings_form'), - 'description' => 'Profile display settings form.', + 'description' => 'Configure how profile edit forms are displayed when editing accounts.', 'access arguments' => array('administer profile'), 'file' => 'profile.admin.inc', ); From 42b553f0d5d2325ecde676936b34eaaa1a5e5b72 Mon Sep 17 00:00:00 2001 From: "Robert J. Lang" Date: Thu, 14 Jan 2021 07:06:32 -0800 Subject: [PATCH 4/4] formatting --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bbdbb6d..dabc75b 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,9 @@ from the Drupal 7 Profile module, you should either convert them to Profile2 profiles in Drupal 7 prior to upgrading to Backdrop, or recreate them in Backdrop after you upgrade. -If you are migrating Drupal 7 Profile2 profiles to Backdrop Profile, you should, however, _enable_ the Drupal 7 Profile module before preparing the db for migration. +If you are migrating Drupal 7 Profile2 profiles to Backdrop Profile, you should, +however, _enable_ the Drupal 7 Profile module before preparing the db for +migration. Documentation -------------