Skip to content

Commit 61a300c

Browse files
author
Nathaniel Catchpole
committed
Issue #2859315 by quietone, heddn, jhodgdon: SQL error from profile_fields when migrating d6 (or d7) to d8 without Profile module
(cherry picked from commit d74e36a)
1 parent c458921 commit 61a300c

File tree

4 files changed

+97
-11
lines changed

4 files changed

+97
-11
lines changed

modules/migrate_drupal_ui/tests/src/Functional/d7/MultilingualReviewPageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ protected function getAvailablePaths() {
7878
'options',
7979
'path',
8080
'phone',
81-
'profile',
8281
'rdf',
8382
'search',
8483
'shortcut',
@@ -158,6 +157,7 @@ protected function getMissingPaths() {
158157
'i18n_translation',
159158
'i18n_user',
160159
'i18n_variable',
160+
'profile',
161161
'variable',
162162
'variable_admin',
163163
'variable_realm',

modules/user/src/Plugin/migrate/source/ProfileField.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\user\Plugin\migrate\source;
44

5+
use Drupal\migrate\Exception\RequirementsException;
56
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
67
use Drupal\migrate\Row;
78

@@ -33,16 +34,7 @@ class ProfileField extends DrupalSqlBase {
3334
* {@inheritdoc}
3435
*/
3536
public function query() {
36-
if (empty($this->fieldTable) || empty($this->valueTable)) {
37-
if ($this->getModuleSchemaVersion('system') >= 7000) {
38-
$this->fieldTable = 'profile_field';
39-
$this->valueTable = 'profile_value';
40-
}
41-
else {
42-
$this->fieldTable = 'profile_fields';
43-
$this->valueTable = 'profile_values';
44-
}
45-
}
37+
$this->setTableNames();
4638
return $this->select($this->fieldTable, 'pf')->fields('pf');
4739
}
4840

@@ -105,4 +97,32 @@ public function getIds() {
10597
return $ids;
10698
}
10799

100+
/**
101+
* {@inheritdoc}
102+
*/
103+
public function checkRequirements() {
104+
$this->setTableNames();
105+
if (!$this->getDatabase()->schema()->tableExists($this->fieldTable)) {
106+
// If we make it to here, the profile module isn't installed.
107+
throw new RequirementsException('Profile module not enabled on source site');
108+
}
109+
parent::checkRequirements();
110+
}
111+
112+
/**
113+
* Helper to set the profile field table names.
114+
*/
115+
protected function setTableNames() {
116+
if (empty($this->fieldTable) || empty($this->valueTable)) {
117+
if ($this->getModuleSchemaVersion('system') >= 7000) {
118+
$this->fieldTable = 'profile_field';
119+
$this->valueTable = 'profile_value';
120+
}
121+
else {
122+
$this->fieldTable = 'profile_fields';
123+
$this->valueTable = 'profile_values';
124+
}
125+
}
126+
}
127+
108128
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Drupal\Tests\user\Kernel\Migrate\d6;
4+
5+
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
6+
use Drupal\migrate\Exception\RequirementsException;
7+
8+
/**
9+
* Tests check requirements for profile_field source plugin.
10+
*
11+
* @group user
12+
*/
13+
class ProfileFieldCheckRequirementsTest extends MigrateDrupal6TestBase {
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public function setup() {
19+
parent::setUp();
20+
$this->sourceDatabase->schema()->dropTable('profile_fields');
21+
}
22+
23+
/**
24+
* Tests exception in thrown when profile_fields tables does not exist.
25+
*/
26+
public function testCheckRequirements() {
27+
$this->setExpectedException(RequirementsException::class, 'Profile module not enabled on source site');
28+
$this->getMigration('user_profile_field')
29+
->getSourcePlugin()
30+
->checkRequirements();
31+
}
32+
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Drupal\Tests\user\Kernel\Migrate\d7;
4+
5+
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
6+
use Drupal\migrate\Exception\RequirementsException;
7+
8+
/**
9+
* Tests check requirements for profile_field source plugin.
10+
*
11+
* @group user
12+
*/
13+
class ProfileFieldCheckRequirementsTest extends MigrateDrupal7TestBase {
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public function setup() {
19+
parent::setUp();
20+
$this->sourceDatabase->schema()->dropTable('profile_field');
21+
}
22+
23+
/**
24+
* Tests exception in thrown when profile_fields tables does not exist.
25+
*/
26+
public function testCheckRequirements() {
27+
$this->setExpectedException(RequirementsException::class, 'Profile module not enabled on source site');
28+
$this->getMigration('user_profile_field')
29+
->getSourcePlugin()
30+
->checkRequirements();
31+
}
32+
33+
}

0 commit comments

Comments
 (0)