Commit e7787c9c authored by webchick's avatar webchick

Issue #1642526 by andypost, Berdir, dixon_: Add upgrade path from for...

Issue #1642526 by andypost, Berdir, dixon_: Add upgrade path from for generating UUIDs for all core entities.
parent 93173604
......@@ -11,6 +11,7 @@
use Drupal\Component\Graph\Graph;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\ConfigException;
use Drupal\Component\Uuid\Uuid;
/**
* Minimum schema version of Drupal 7 required for upgrade to Drupal 8.
......@@ -1125,3 +1126,30 @@ function update_variables_to_config($config_name, array $variable_map) {
// Delete the migrated variables.
db_delete('variable')->condition('name', array_keys($variable_map), 'IN')->execute();
}
/**
* Helper function to update entities with uuid.
*
* @param array $sandbox
* A sandbox where conversion happens.
* @param string $table
* A table whose data should be updated.
* @param string $primary_key
* A $table primary key column.
* @param array $values
* A $primary_key values of rows to be updated.
*/
function update_add_uuids(&$sandbox, $table, $primary_key, $values) {
$uuid = new Uuid();
foreach ($values as $value) {
db_update($table)
->fields(array(
'uuid' => $uuid->generate(),
))
->condition($primary_key, $value)
->isNull('uuid')
->execute();
$sandbox['progress']++;
$sandbox['last'] = $value;
}
}
......@@ -295,8 +295,6 @@ function comment_update_8000() {
/**
* Create a UUID column for comments.
*
* @todo UUID upgrade path: http://drupal.org/node/1642526
*/
function comment_update_8001() {
$spec = array(
......@@ -367,6 +365,22 @@ function comment_update_8002() {
);
}
/**
* Generate an UUID for all comments.
*/
function comment_update_8003(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['last'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(cid) FROM {comment} WHERE uuid IS NULL')->fetchField();
}
$cids = db_query_range('SELECT cid FROM {comment} WHERE cid > :cid AND uuid IS NULL ORDER BY cid ASC', 0, 10, array(':cid' => $sandbox['last']))->fetchCol();
update_add_uuids($sandbox, 'comment', 'cid', $cids);
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}
/**
* @} End of "addtogroup updates-7.x-to-8.x".
* The next series of updates should start at 9000.
......
......@@ -582,8 +582,6 @@ function node_update_8003() {
/**
* Create a UUID column for nodes.
*
* @todo UUID upgrade path: http://drupal.org/node/1642526
*/
function node_update_8004() {
$spec = array(
......@@ -663,6 +661,22 @@ function node_update_8005() {
);
}
/**
* Generate an UUID for all nodes.
*/
function node_update_8006(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['last'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(nid) FROM {node} WHERE uuid IS NULL')->fetchField();
}
$nids = db_query_range('SELECT nid FROM {node} WHERE nid > :nid AND uuid IS NULL ORDER BY nid ASC', 0, 10, array(':nid' => $sandbox['last']))->fetchCol();
update_add_uuids($sandbox, 'node', 'nid', $nids);
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}
/**
* @} End of "addtogroup updates-7.x-to-8.x"
* The next series of updates should start at 9000.
......
<?php
/**
* @file
* Definition of Drupal\system\Tests\Upgrade\UuidUpgradePathTest.
*/
namespace Drupal\system\Tests\Upgrade;
/**
* Performs major version release upgrade tests on a populated database.
*
* Loads an installation of Drupal 7.x and runs the upgrade process on it.
*
* The install contains the minimal profile modules (along with generated
* content) so that an update from of a site under this profile may be tested.
*/
class UuidUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'Uuid upgrade test',
'description' => 'Upgrade tests for a node and user data.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Path to the database dump files.
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.filled.standard_all.database.php.gz',
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.language.database.php',
);
parent::setUp();
}
/**
* Tests a successful point release update.
*/
public function testUuidUpgrade() {
$this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
// Confirm that all {node} entries has uuid.
$result = db_query('SELECT COUNT(*) FROM {comment} WHERE uuid IS NULL')->fetchField();
$this->assertFalse($result, 'All comments has uuid assigned');
// Confirm that all {node} entries has uuid.
$result = db_query('SELECT COUNT(*) FROM {file_managed} WHERE uuid IS NULL')->fetchField();
$this->assertFalse($result, 'All files has uuid assigned');
// Confirm that all {node} entries has uuid.
$result = db_query('SELECT COUNT(*) FROM {node} WHERE uuid IS NULL')->fetchField();
$this->assertFalse($result, 'All nodes has uuid assigned');
// Confirm that all {node} entries has uuid.
$result = db_query('SELECT COUNT(*) FROM {taxonomy_term_data} WHERE uuid IS NULL')->fetchField();
$this->assertFalse($result, 'All taxonomy terms has uuid assigned');
// Confirm that all {user} entries has uuid.
$result = db_query('SELECT COUNT(*) FROM {users} WHERE uuid IS NULL')->fetchField();
$this->assertFalse($result, 'All users has uuid assigned');
}
}
......@@ -1937,8 +1937,6 @@ function system_update_8014() {
/**
* Create a UUID column for managed files.
*
* @todo UUID upgrade path: http://drupal.org/node/1642526
*/
function system_update_8015() {
$spec = array(
......@@ -2184,6 +2182,22 @@ function system_update_8023() {
db_create_table('key_value_expire', $table);
}
/**
* Generate an UUID for all files.
*/
function system_update_8024(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['last'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(fid) FROM {file_managed} WHERE uuid IS NULL')->fetchField();
}
$fids = db_query_range('SELECT fid FROM {file_managed} WHERE fid > :fid AND uuid IS NULL ORDER BY fid ASC', 0, 10, array(':fid' => $sandbox['last']))->fetchCol();
update_add_uuids($sandbox, 'file_managed', 'fid', $fids);
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}
/**
* @} End of "defgroup updates-7.x-to-8.x".
* The next series of updates should start at 9000.
......
......@@ -312,8 +312,6 @@ function taxonomy_update_8001() {
/**
* Create a UUID column for taxonomy terms.
*
* @todo UUID upgrade path: http://drupal.org/node/1642526
*/
function taxonomy_update_8002() {
$spec = array(
......@@ -335,3 +333,19 @@ function taxonomy_update_8002() {
db_add_field('taxonomy_term_data', 'uuid', $spec, $keys);
}
}
/**
* Generate an UUID for all terms.
*/
function taxonomy_update_8003(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['last'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(tid) FROM {taxonomy_term_data} WHERE uuid IS NULL')->fetchField();
}
$tids = db_query_range('SELECT tid FROM {taxonomy_term_data} WHERE tid > :tid AND uuid IS NULL ORDER BY tid ASC', 0, 10, array(':tid' => $sandbox['last']))->fetchCol();
update_add_uuids($sandbox, 'taxonomy_term_data', 'tid', $tids);
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}
......@@ -458,8 +458,6 @@ function user_update_8002() {
/**
* Create a UUID column for users.
*
* @todo UUID upgrade path: http://drupal.org/node/1642526
*/
function user_update_8003() {
$spec = array(
......@@ -583,6 +581,23 @@ function user_update_8008() {
);
}
/**
* Generate an UUID for all users.
*/
function user_update_8009(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
// The first user id is 0, so it needs to start with -1.
$sandbox['last'] = -1;
$sandbox['max'] = db_query('SELECT COUNT(uid) FROM {users} WHERE uuid IS NULL')->fetchField();
}
$uids = db_query_range('SELECT uid FROM {users} WHERE uid > :uid AND uuid IS NULL ORDER BY uid ASC', 0, 10, array(':uid' => $sandbox['last']))->fetchCol();
update_add_uuids($sandbox, 'users', 'uid', $uids);
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}
/**
* @} End of "addtogroup updates-7.x-to-8.x".
*/
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