diff --git a/core/includes/database.inc b/core/includes/database.inc index 798cb74..7f1f278 100644 --- a/core/includes/database.inc +++ b/core/includes/database.inc @@ -34,7 +34,7 @@ * results that need to be presented on multiple pages, and the Tablesort * Extender for generating appropriate queries for sortable tables. * - * For example, one might wish to return a list of the most recent 10 nodes + * For example, one might wish to return a list of the most recent 10 rows * authored by a given user. Instead of directly issuing the SQL query * @code * SELECT e.id, e.title, e.created FROM example e WHERE e.uid = $uid LIMIT 0, 10; @@ -47,7 +47,7 @@ * // Perform operations on $record->title, etc. here. * } * @endcode - * Curly braces are used around "node" to provide table prefixing via + * Curly braces are used around "example" to provide table prefixing via * DatabaseConnection::prefixTables(). The explicit use of a user ID is pulled * out into an argument passed to db_query() so that SQL injection attacks * from user input can be caught and nullified. The LIMIT syntax varies between @@ -109,7 +109,7 @@ * object-oriented API for defining a query structurally. For example, rather * than: * @code - * INSERT INTO example (id, title, body) VALUES (1, 'my title', 'my body'); + * INSERT INTO {example} (id, uid, path, name) VALUES (1, 2, 'home', 'Home path'); * @endcode * one would instead write: * @code diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index f967372..3e1dd4b 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -131,7 +131,7 @@ public function __construct($entityType) { $this->uuidKey = FALSE; } - // Check if the entity type has multilingual support. + // Check if the entity type has a dedicated table for properties. if (!empty($this->entityInfo['data table'])) { $this->dataTable = $this->entityInfo['data table']; } @@ -546,7 +546,12 @@ public function save(EntityInterface $entity) { $this->saveRevision($entity); } if ($this->dataTable) { - drupal_write_record($this->entityInfo['data table'], $entity, $this->idKey); + $primary_keys = array( + $this->idKey, + $this->revisionKey, + 'langcode', + ); + drupal_write_record($this->entityInfo['data table'], $entity, $primary_keys); } $this->resetCache(array($entity->id())); $this->postSave($entity, TRUE); diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 85c088e..faa1539 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -42,6 +42,7 @@ function comment_enable() { $query->addExpression('0', 'comment_count'); $query->addExpression('NULL', 'last_comment_name'); $query->isNull('ncs.comment_count'); + // @todo Replace by proper language handling. $query->groupBy('npd.nid'); db_insert('node_comment_statistics') diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index 0c26767..ba9f4c4 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -517,7 +517,7 @@ function node_admin_nodes() { } } $nids = $query - ->fields('npd',array('nid')) + ->fields('npd', array('nid')) ->limit(50) ->orderByHeader($header) ->addTag('node_access') diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 983d670..9d5467f 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -27,7 +27,7 @@ function node_schema() { // Defaults to NULL in order to avoid a brief period of potential // deadlocks on the index. 'vid' => array( - 'description' => 'The current {node_revision}.vid version identifier.', + 'description' => 'The current {node_property_revision}.vid version identifier.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, @@ -62,9 +62,9 @@ function node_schema() { ), ), 'indexes' => array( - 'node_type' => array(array('type', 4)), - 'tnid' => array('tnid'), - 'translate' => array('translate'), + 'node_type' => array(array('type', 4)), + 'tnid' => array('tnid'), + 'translate' => array('translate'), ), 'unique keys' => array( 'vid' => array('vid'), @@ -90,7 +90,7 @@ function node_schema() { 'not null' => TRUE, ), 'vid' => array( - 'description' => 'The current {node_revision}.vid version identifier.', + 'description' => 'The current {node_property_revision}.vid version identifier.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, @@ -162,11 +162,11 @@ function node_schema() { ), 'indexes' => array( 'node_created' => array('created'), - 'node_changed' => array('changed'), - 'node_frontpage' => array('promote', 'status', 'sticky', 'changed'), - 'node_status' => array('status', 'nid'), - 'node_title' => array('title'), - 'uid' => array('uid'), + 'node_changed' => array('changed'), + 'node_frontpage' => array('promote', 'status', 'sticky', 'changed'), + 'node_status' => array('status', 'nid'), + 'node_title' => array('title'), + 'uid' => array('uid'), ), 'unique keys' => array( 'vid' => array('vid'), @@ -745,7 +745,6 @@ function node_update_8006(&$sandbox) { */ function node_update_8007() { $schema = node_schema(); - $node_count = db_select('node')->countQuery()->execute()->fetchColumn(); // Create property table if necessary. if (!db_table_exists('node_property_data')) { db_create_table('node_property_data', $schema['node_property_data']); @@ -763,8 +762,8 @@ function node_update_8007() { function node_update_8008(&$sandbox) { if (!isset($sandbox['progress'])) { $sandbox['progress'] = 0; - $sandbox['last'] = (int) db_query('SELECT npd.nid FROM node_property_data npd ORDER BY nid DESC')->fetchField(); - $sandbox['max'] = db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN node_property_data npd ON npd.nid = n.nid WHERE npd.nid IS NULL')->fetchField(); + $sandbox['last'] = (int) db_query('SELECT npd.nid FROM {node_property_data npd} ORDER BY nid DESC')->fetchField(); + $sandbox['max'] = db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN {node_property_data} npd ON npd.nid = n.nid WHERE npd.nid IS NULL')->fetchField(); } // Create initial property data set if necessary. @@ -783,13 +782,13 @@ function node_update_8008(&$sandbox) { 'promote', 'sticky', )) - ->range(0, 5000) + ->range(0, 10) ->condition('nid', $sandbox['last'], '>') ->orderBy('nid'); $source_query->addField('node', 'langcode', 'default_langcode'); db_insert('node_property_data')->from($source_query)->execute(); - $sandbox['last'] = db_query('SELECT npd.nid FROM node_property_data npd ORDER BY nid DESC')->fetchField(); - $sandbox['progress'] += 5000; + $sandbox['last'] = db_query('SELECT npd.nid FROM {node_property_data} npd ORDER BY nid DESC')->fetchField(); + $sandbox['progress'] += 10; } $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); @@ -802,7 +801,7 @@ function node_update_8009(&$sandbox) { if (!isset($sandbox['progress'])) { $sandbox['progress'] = 0; $sandbox['last'] = (int) db_query('SELECT npr.vid FROM {node_property_revision} npr ORDER BY vid DESC')->fetchField(); - $sandbox['max'] = db_query('SELECT COUNT(*) FROM {node_revision} nr LEFT JOIN node_property_revision npr ON npr.vid = nr.vid WHERE npr.vid IS NULL')->fetchField(); + $sandbox['max'] = db_query('SELECT COUNT(*) FROM {node_revision} nr LEFT JOIN {node_property_revision} npr ON npr.vid = nr.vid WHERE npr.vid IS NULL')->fetchField(); } // Create initial revision set if necessary. @@ -820,7 +819,7 @@ function node_update_8009(&$sandbox) { 'log', 'timestamp', )) - ->range(0, 1) + ->range(0, 10) ->condition('nr.vid', $sandbox['last'], '>') ->orderBy('nr.vid'); $source_query->innerJoin('node_property_data', 'npd', 'npd.nid = nr.nid'); @@ -829,7 +828,7 @@ function node_update_8009(&$sandbox) { db_insert('node_property_revision')->from($source_query)->execute(); $sandbox['last'] = db_query('SELECT npr.vid FROM {node_property_revision} npr ORDER BY vid DESC')->fetchField(); - $sandbox['progress'] += 1; + $sandbox['progress'] += 10; } $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); @@ -839,7 +838,7 @@ function node_update_8009(&$sandbox) { * Cleanup old tables after finishing switch to dedicated property tables. */ function node_update_8010() { - $deprecated_base_table_fields = array( + $old_base_table_fields = array( 'title', 'uid', 'status', @@ -849,7 +848,7 @@ function node_update_8010() { 'promote', 'sticky', ); - $deprecated_base_table_indexes = array( + $old_base_table_indexes = array( 'node_created', 'node_changed', 'node_frontpage', @@ -867,9 +866,9 @@ function node_update_8010() { // Modify original tables if possible and necessary. if ($node_property_count == $node_count) { // Drop deprecated indexes. - foreach ($deprecated_base_table_indexes as $deprecated_index) { - if (db_index_exists('node', $deprecated_index)) { - db_drop_index('node', 'node_changed'); + foreach ($old_base_table_indexes as $old_index) { + if (db_index_exists('node', $old_index)) { + db_drop_index('node', $old_index); } } // Recreate index. @@ -877,15 +876,22 @@ function node_update_8010() { db_add_index('node', 'node_type', array(array('type', 4))); } // Drop deprecated fields. - foreach ($deprecated_base_table_fields as $deprecated_base_field) { + foreach ($old_base_table_fields as $deprecated_base_field) { if (db_field_exists('node', $deprecated_base_field)) { db_drop_field('node', $deprecated_base_field); } } } + else { + throw new DrupalUpdateException('The data migration from the node to the new node_property_data table seems to be inconsistent.'); + } + if (db_table_exists('node_revision') && $node_revision_count == $node_property_revision_count) { db_drop_table('node_revision'); } + else { + throw new DrupalUpdateException('The data migration from the node_revision to the new node_property_revision table seems to be inconsistent.'); + } } /**