Commit 58a5b82f authored by Dries's avatar Dries

- Patch #1018602 by fago, catch, aspilicious: move entity system to a module.

parent 33fe4c1d
This diff is collapsed.
......@@ -253,12 +253,13 @@ function install_begin_request(&$install_state) {
// Set up $language, so t() caller functions will still work.
drupal_language_initialize();
include_once DRUPAL_ROOT . '/includes/entity.inc';
require_once DRUPAL_ROOT . '/includes/ajax.inc';
$module_list['system']['filename'] = 'modules/system/system.module';
$module_list['user']['filename'] = 'modules/user/user.module';
$module_list['entity']['filename'] = 'modules/entity/entity.module';
$module_list['user']['filename'] = 'modules/user/user.module';
module_list(TRUE, FALSE, FALSE, $module_list);
drupal_load('module', 'system');
drupal_load('module', 'entity');
drupal_load('module', 'user');
// Load the cache infrastructure using a "fake" cache implementation that
......
......@@ -424,8 +424,9 @@ function module_enable($module_list, $enable_dependencies = TRUE) {
registry_update();
// Refresh the schema to include it.
drupal_get_schema(NULL, TRUE);
// Clear entity cache.
entity_info_cache_clear();
// Allow modules to react prior to the installation of a module.
module_invoke_all('modules_preinstall', array($module));
// Now install the module if necessary.
if (drupal_get_installed_schema_version($module, TRUE) == SCHEMA_UNINSTALLED) {
......@@ -450,6 +451,9 @@ function module_enable($module_list, $enable_dependencies = TRUE) {
watchdog('system', '%module module installed.', array('%module' => $module), WATCHDOG_INFO);
}
// Allow modules to react prior to the enabling of a module.
module_invoke_all('modules_preenable', array($module));
// Enable the module.
module_invoke($module, 'enable');
......
......@@ -82,6 +82,7 @@ function update_prepare_d8_bootstrap() {
// Allow the database system to work even if the registry has not been
// created yet.
include_once DRUPAL_ROOT . '/includes/install.inc';
include_once DRUPAL_ROOT . '/modules/entity/entity.controller.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
// If the site has not updated to Drupal 8 yet, check to make sure that it is
......@@ -120,6 +121,35 @@ function update_fix_d8_requirements() {
}
}
/**
* Helper function to install a new module in Drupal 8 via hook_update_N().
*/
function update_module_enable(array $modules) {
foreach ($modules as $module) {
// Check for initial schema and install it. The schema version of a newly
// installed module is always 0. Using 8000 here would be inconsistent
// since $module_update_8000() may involve a schema change, and we want
// to install the schema as it was before any updates were added.
$function = $module . '_schema_0';
if (function_exists($function)) {
$schema = $function();
foreach ($schema as $table => $spec) {
db_create_table($table, $spec);
}
}
// Change the schema version from SCHEMA_UNINSTALLED to 0, so any module
// updates since the module's inception are executed in a core upgrade.
db_update('system')
->condition('type', 'module')
->condition('name', $module)
->fields(array('schema_version' => 0))
->execute();
system_list_reset();
// @todo: figure out what to do about hook_install() and hook_enable().
}
}
/**
* Perform one update and store the results for display on finished page.
*
......
......@@ -4,6 +4,7 @@ package = Core
version = VERSION
core = 8.x
dependencies[] = text
dependencies[] = entity
files[] = comment.module
files[] = comment.test
configure = admin/content/comment
......
This diff is collapsed.
This diff is collapsed.
name = Entity
description = API for managing entities like nodes and users.
package = Core
version = VERSION
core = 8.x
required = TRUE
files[] = entity.query.inc
files[] = entity.controller.inc
This diff is collapsed.
......@@ -7,5 +7,6 @@ files[] = field.module
files[] = field.attach.inc
files[] = tests/field.test
dependencies[] = field_sql_storage
dependencies[] = entity
required = TRUE
stylesheets[all][] = theme/field.css
......@@ -6,5 +6,6 @@ core = 8.x
files[] = node.module
files[] = node.test
required = TRUE
dependencies[] = entity
configure = admin/structure/types
stylesheets[all][] = node.css
This diff is collapsed.
......@@ -1623,10 +1623,10 @@ function system_update_last_removed() {
*/
/**
* Placeholder update to set the schema version to 8000.
* Enable entity module.
*/
function system_update_8000() {
// Fill in the first update to Drupal 8 when needed.
update_module_enable(array('entity'));
}
/**
......
......@@ -4,6 +4,7 @@ package = Core
version = VERSION
core = 8.x
dependencies[] = options
dependencies[] = entity
files[] = taxonomy.module
files[] = taxonomy.test
configure = admin/structure/taxonomy
<?php
/**
* @file Controller class for users.
*/
/**
* Controller class for users.
*
* This extends the DrupalDefaultEntityController class, adding required
* special handling for user objects.
*/
class UserController extends DrupalDefaultEntityController {
function attachLoad(&$queried_users, $revision_id = FALSE) {
// Build an array of user picture IDs so that these can be fetched later.
$picture_fids = array();
foreach ($queried_users as $key => $record) {
$picture_fids[] = $record->picture;
$queried_users[$key]->data = unserialize($record->data);
$queried_users[$key]->roles = array();
if ($record->uid) {
$queried_users[$record->uid]->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
}
else {
$queried_users[$record->uid]->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
}
}
// Add any additional roles from the database.
$result = db_query('SELECT r.rid, r.name, ur.uid FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid IN (:uids)', array(':uids' => array_keys($queried_users)));
foreach ($result as $record) {
$queried_users[$record->uid]->roles[$record->rid] = $record->name;
}
// Add the full file objects for user pictures if enabled.
if (!empty($picture_fids) && variable_get('user_pictures', 1) == 1) {
$pictures = file_load_multiple($picture_fids);
foreach ($queried_users as $account) {
if (!empty($account->picture) && isset($pictures[$account->picture])) {
$account->picture = $pictures[$account->picture];
}
else {
$account->picture = NULL;
}
}
}
// Call the default attachLoad() method. This will add fields and call
// hook_user_load().
parent::attachLoad($queried_users, $revision_id);
}
}
......@@ -3,7 +3,7 @@ description = Manages the user registration and login system.
package = Core
version = VERSION
core = 8.x
files[] = user.module
files[] = user.entity.inc
files[] = user.test
required = TRUE
configure = admin/config/people
......
......@@ -287,53 +287,6 @@ function user_load_multiple($uids = array(), $conditions = array(), $reset = FAL
return entity_load('user', $uids, $conditions, $reset);
}
/**
* Controller class for users.
*
* This extends the DrupalDefaultEntityController class, adding required
* special handling for user objects.
*/
class UserController extends DrupalDefaultEntityController {
function attachLoad(&$queried_users, $revision_id = FALSE) {
// Build an array of user picture IDs so that these can be fetched later.
$picture_fids = array();
foreach ($queried_users as $key => $record) {
$picture_fids[] = $record->picture;
$queried_users[$key]->data = unserialize($record->data);
$queried_users[$key]->roles = array();
if ($record->uid) {
$queried_users[$record->uid]->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
}
else {
$queried_users[$record->uid]->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
}
}
// Add any additional roles from the database.
$result = db_query('SELECT r.rid, r.name, ur.uid FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid IN (:uids)', array(':uids' => array_keys($queried_users)));
foreach ($result as $record) {
$queried_users[$record->uid]->roles[$record->rid] = $record->name;
}
// Add the full file objects for user pictures if enabled.
if (!empty($picture_fids) && variable_get('user_pictures', 1) == 1) {
$pictures = file_load_multiple($picture_fids);
foreach ($queried_users as $account) {
if (!empty($account->picture) && isset($pictures[$account->picture])) {
$account->picture = $pictures[$account->picture];
}
else {
$account->picture = NULL;
}
}
}
// Call the default attachLoad() method. This will add fields and call
// hook_user_load().
parent::attachLoad($queried_users, $revision_id);
}
}
/**
* Loads a user object.
*
......
......@@ -345,7 +345,6 @@ function update_check_requirements() {
require_once DRUPAL_ROOT . '/includes/update.inc';
require_once DRUPAL_ROOT . '/includes/common.inc';
require_once DRUPAL_ROOT . '/includes/file.inc';
require_once DRUPAL_ROOT . '/includes/entity.inc';
require_once DRUPAL_ROOT . '/includes/unicode.inc';
update_prepare_d8_bootstrap();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment