Problem/Motivation

When migrating D7 sites (such as for example webchick.net), you get lots of errors like
Notice: Undefined index: text_processing in Drupal\text\Plugin\migrate\field\d7\TextField->getFieldType() (line 76 of core/modules/text/src/Plugin/migrate/field/d7/TextField.php).

Wim Leers provides the analysis for why this occurs for D7 sites that were upgraded from D6 in #25.

Steps to reproduce

Perform a migration with a D7 source site which has text fields without the text_processing setting.

Proposed resolution

Harden the code by specifcally handling the case where text_processing is not defined.
Add tests
Remove duplicate tests in the Drupal\Tests\text\Unit\Migrate namespace.

Remaining tasks

Patch
Review
Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new949 bytes
huzooka’s picture

Assigned: Unassigned » huzooka
huzooka’s picture

Status: Needs review » Needs work
huzooka’s picture

Assigned: huzooka » Unassigned
Status: Needs work » Needs review
Issue tags: +Needs subsystem maintainer review
StatusFileSize
new1.49 KB
new1.49 KB

Found the right place for testing the issue, no need for adding new test file 😊.

huzooka’s picture

StatusFileSize
new3.32 KB

#5 has the test-only patch twice 😶, but not the complete one.

huzooka’s picture

Assigned: Unassigned » huzooka
Status: Needs review » Needs work
wim leers’s picture

Why does this still need work? Looks ready to me :D

huzooka’s picture

Assigned: huzooka » Unassigned
Status: Needs work » Needs review
StatusFileSize
new10.91 KB
new12.75 KB
new11.87 KB

huzooka’s picture

Assigned: Unassigned » huzooka
Status: Needs review » Needs work
huzooka’s picture

Assigned: huzooka » Unassigned
Status: Needs work » Needs review
StatusFileSize
new13.08 KB
new14.93 KB
new21.63 KB

I think that the unit test with the namespace \Drupal\Tests\text\Unit\Plugin\migrate\field\d7\TextFieldTest is now complete.

Since I don't see why we need two separate tests for the Drupal 7 TextField plugin, I removed the one with the namespace \Drupal\Tests\text\Unit\Migrate\d7\TextFieldTest.

huzooka’s picture

It seems that when text_processing is completely missing from the settings, then it equals to having text_processing = 1.

See #3168646: D7 sites upgraded from previous Drupal versions may not have a "text_processing" setting for their body fields.

Can anyone confirm this? I'm not familiar with Drupal 7 (anymore).

wim leers’s picture

Can anyone confirm this?

I know for a fact that that is how @webchick's site works at all at least 😎😅

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

quietone’s picture

Component: text.module » migration system

Changing component to where the migrate maintainers will see this.

quietone’s picture

Status: Needs review » Needs work

I'd like to understand why the case of text_processing not being set wasn't already handled. Is this a special case in D7? I don't know D7 very well so don't know.

I've only done a cursory look but the fix looks good. I do wonder if the deletion of core/modules/text/tests/src/Unit/Migrate/d7/TextFieldTest.php should be done in a separate issue.

In D7 why is text_processing not set?

+++ b/core/modules/text/src/Plugin/migrate/field/d6/TextField.php
@@ -109,7 +109,7 @@ public function getFieldType(Row $row) {
+      $field_type = !empty($settings['text_processing']) ? 'text' : 'string';

@@ -117,7 +117,7 @@ public function getFieldType(Row $row) {
+      $field_type = !empty($settings['text_processing']) ? 'text_long' : 'string_long';

Can we change these to empty instead of !empty? Just makes is a little easier to read.

wim leers’s picture

In D7 why is text_processing not set?

… maybe … it is only happening for D7 upgraded from D6? Not sure, just theorizing. 🤔

shubham.prakash’s picture

StatusFileSize
new14.92 KB

Did the condition change as suggested in #19.

shubham.prakash’s picture

StatusFileSize
new1.05 KB
shubham.prakash’s picture

Status: Needs work » Needs review
marvil07’s picture

Can we change these to empty instead of !empty? Just makes is a little easier to read.

I see that 21 applied that change.

I do wonder if the deletion of core/modules/text/tests/src/Unit/Migrate/d7/TextFieldTest.php should be done in a separate issue.

It seems like it is truly related, so unless some maintainer feel strongly about this, doing it here sounds OK.
If that is the case that change may also like to remove the d7_filter_format references over Drupal\text\Plugin\migrate\field\d6\TextField and Drupal\Tests\text\Unit\Migrate\d6\TextFieldTest.

I was confused at first, on why Drupal\Tests\text\Unit\Migrate\d7\TextFieldTest was being removed.
My first reaction was to address the problem by overriding the relevant methods to set the right plugin class.
The main reason seems to be that there is already another test dealing with the text migrate field plugin unit tests at Drupal\Tests\text\Unit\Plugin\migrate\field\d7\TextFieldTest, which seems more relevant, and it is where the code has been added.

It also brings up the question of unification of approach, and why Drupal\Tests\text\Unit\Migrate\d6\TextFieldTest lives at a different namespace.
A clear hint about it is that the two related classes are mostly the same, see textfieldunittest-migrate-vs-plugin-namespace.patch.txt, the output from diff -up core/modules/text/tests/src/Unit/Migrate/d6/TextFieldTest.php core/modules/text/tests/src/Unit/Plugin/migrate/field/d6/TextFieldTest.php.

I would suggest to either open a follow-up about the duplication of code problem, or address it here, unifying d6 and d7 unit test likely with a test base class.

I am keeping the issue in NR to get an opinion from a migration subsystem maintainer.

wim leers’s picture

Title: Undefined index: text_processing in Drupal\text\Plugin\migrate\field\d7\TextField » Undefined index: text_processing in Drupal\text\Plugin\migrate\field\d7\TextField for D7 sites previously upgraded from D6

#24:

I would suggest to either open a follow-up about the duplication of code problem, or address it here, unifying d6 and d7 unit test likely with a test base class.

Please do that in a follow-up.

We need to prioritize helping people migrating into D8|9 over code cleanliness, especially when it's only partial (but not complete) duplication of code.

#19:

I'd like to understand why the case of text_processing not being set wasn't already handled. Is this a special case in D7? I don't know D7 very well so don't know.

I theorized in #20, where I wrote … maybe … it is only happening for D7 upgraded from D6? Not sure, just theorizing. 🤔

I just checked that theory.

  • Drupal 6.x contains zero occurrences of the string text_processing: https://git.drupalcode.org/search?utf8=%E2%9C%93&search=text_processing&...
  • Drupal 7.x contains many occurrences of the string text_processing: https://git.drupalcode.org/search?utf8=%E2%9C%93&search=text_processing&...
  • The 6-to-7 upgrade path attempts to "fix" the field definitions in field_update_7001() — but has no special measures to ensure that text_processing gets set. In fact, it doesn't really update the field configuration at all.
  • You can also see that among the ~20 or so matches in the second bullet's link none of them relate to the upgrade path.
  • Finally: the two cases where I know this to happen are Gábor Hojtsy's site and webchick's site. In both cases I know for a fact that their Drupal 7 sites are upgrades from previous versions of Drupal.

    Updated title accordingly.

quietone’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs subsystem maintainer review

I reviewed the field plugins and the tests. It would help to have some comments in the field plugins explaining why text_processing may be empty.

  1. +++ b/core/modules/text/src/Plugin/migrate/field/d6/TextField.php
    @@ -109,7 +109,7 @@ public function getFieldType(Row $row) {
    +      $field_type = empty($settings['text_processing']) ? 'string' : 'text';
    

    Let's add a comment here explaining why text_processing is empty.

  2. +++ b/core/modules/text/src/Plugin/migrate/field/d7/TextField.php
    @@ -72,8 +72,8 @@ public function getFieldType(Row $row) {
    +      $text_processing = unserialize($instance['data'])['settings']['text_processing'] ?? '0';
    

    Add a comment here as well.

The tests do test what needs to be tested. Which is great but the changes for d6 are in one namespace and for d7 in another. Let's get them all into the correct namespace, which is Drupal\Tests\text\Unit\Plugin\migrate\field.

I have thought more about the deletion of the D7 test and still think it is out of scope and should be done in a followup that deletes both the D6 and D7 test in \Drupal\Tests\text\Unit\Migrate. And with the changes to the tests to be done in the correct namespace that will be conceptually easier.

The deletion of tests should always be questioned, so here is my reasoning. We know we can delete them because the D7 test in that namespace wrongly covers the D6 field plugin and the D6 test there is a functional duplicate of the D6 test in the correct namespace. Proof of that is given in the diff provided by marvil07 in #25. Thanks marvil07!

In regards to the duplicate code and adding a base class, there is no need to take on that work. The problem exists in many migrate tests and the focus on the work remains on functionality and bugs. The exception would be for tests in the migrate module itself.

Setting to NW.

wim leers’s picture

+++ b/core/modules/text/src/Plugin/migrate/field/d7/TextField.php
@@ -72,8 +72,8 @@ public function getFieldType(Row $row) {
+      $text_processing = unserialize($instance['data'])['settings']['text_processing'] ?? '0';

Looking at this again, we'll also need to change this line to not fall back to '0' but to '1'.

Why?

See #15 + #16: both on webchick's site text_processing is not set at all on her body field(s). But we still need to have text processing enabled in D8|9.

This is what she has:

MariaDB [webchick]> SELECT * FROM field_config WHERE field_name = 'body';
+----+------------+-------------------+--------+--------+-------------------+-------------------+----------------+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+--------------+---------+
| id | field_name | type              | module | active | storage_type      | storage_module    | storage_active | locked | data                                                                                                                                                                                                                                                                                     | cardinality | translatable | deleted |
+----+------------+-------------------+--------+--------+-------------------+-------------------+----------------+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+--------------+---------+
|  3 | body       | text_with_summary | text   |      1 | field_sql_storage | field_sql_storage |              1 |      0 | a:5:{s:12:"entity_types";a:1:{i:0;s:4:"node";}s:12:"translatable";b:1;s:8:"settings";a:0:{}s:7:"indexes";a:1:{s:6:"format";a:1:{i:0;s:6:"format";}}s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";i:1;}} |           1 |            0 |       0 |
+----+------------+-------------------+--------+--------+-------------------+-------------------+----------------+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+--------------+---------+
1 row in set (0.014 sec)

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Postponed

The Migrate Drupal Module was approved for removal in #3371229: [Policy] Migrate Drupal and Migrate Drupal UI after Drupal 7 EOL.

This is Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.

The deprecation work is in #3522602: [meta] Tasks to remove Migrate Drupal module and the removal work in #3522602: [meta] Tasks to remove Migrate Drupal module.

Migrate Drupal will not be moved to a contributed project. It will be removed from core after the Drupal 12.x branch is open.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.