Skip to content

Commit

Permalink
Recommit Profile2 importing code and README
Browse files Browse the repository at this point in the history
Re-adding Profile2 import code and README fixes that were lost in a regression.
  • Loading branch information
bugfolder committed Dec 11, 2020
1 parent f07f358 commit 1529ea1
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 17 deletions.
62 changes: 48 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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), [email protected]
* Joachim Noreiko (joachim), [email protected]
* Ported to Backdrop CMS by [docwilmot](https://github.com/docwilmot).

* Original Drupal maintained module by
* [Wolfgang Ziegler (fago)](https://www.drupal.org/u/fago), [email protected]
* [Joachim Noreiko (joachim)](https://www.drupal.org/u/joachim), [email protected]

150 changes: 147 additions & 3 deletions profile.install
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
function profile_install() {
}


/**
* Implements hook_schema().
*/
Expand Down Expand Up @@ -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');
Expand All @@ -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'");
}

0 comments on commit 1529ea1

Please sign in to comment.