When running a migration from Drupal 6 to Drupal 8, the following notice ("status") arises:
Undefined index: allowed_html FilterSettings.php:45

Here is the result of a config-export:

uuid: xxxx
langcode: fr
status: true
dependencies: {  }
name: 'Filtered HTML'
format: filtered_html
weight: 0
filters:
  filter_html:
    id: filter_html
    provider: filter
    status: true
    weight: -10
    settings:
      allowed_html: ''
      filter_html_help: true
      filter_html_nofollow: false
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drzraf created an issue. See original summary.

harsh.behl’s picture

May be this could help.

harsh.behl’s picture

Status: Active » Needs review
drzraf’s picture

Fixed.
With this patch applied, the notice is gone.

mikeryan’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Can we get a test that triggers the notice?

+++ b/core/modules/filter/src/Plugin/migrate/process/FilterSettings.php
@@ -42,7 +42,9 @@ class FilterSettings extends ProcessPluginBase {
+	  if (!empty($value['allowed_html'])) {
+		$value['allowed_html'] = str_replace(array_keys($this->allowedHtmlDefaultAttributes), array_values($this->allowedHtmlDefaultAttributes), $value['allowed_html']);
+	  }

Patch contains tab characters - should be spaces.

drzraf’s picture

What I can say to help is that D6 DB contains various text formats,
* Some where allowed for no role
* Other where with none of the options (like a PHP-filter text format)
* Could be noted that I had some geshi filter stuff in the DB (the module was removed without proper uninstall)
Pretty sure that one of these triggered the notice.

harsh.behl’s picture

Updated patch with no tabs.

quietone’s picture

I am getting this error with a source D6 that is a fresh install of Ubercart 6, with a store and a couple of products. Made an brief attempt at a test but then, I couldn't generate the error again.

quietone’s picture

Tracked this to FilterFormat::prepareRow(). When the deita is 0, the $settings array is made from several variables, allowed_html_$format, filter_html_help_$format, and filter_html_nofollow_$format. In the failure case, when $format=1, all those variables do not exist. Then, in the process plugin, trying to write to any index on $settings fails, causing the error. I don't know how those variable got deleted when building an Ubercart test site.

So, making a test would require deleting those variables from the test database before running the test. That seems excessive for a change that we could argue should be made in of itself, that is the process should check that it is safe to write to the array before doing so.

quietone’s picture

Status: Needs work » Needs review

Marking NR, to get feedback on the need for a test.

mikeryan’s picture

Version: 8.2.2 » 8.3.x-dev
Assigned: Unassigned » mikeryan
mglaman’s picture

Just caught this, too. Running commerce_migrate tests caused a failure due to this notice.

mikeryan’s picture

Status: Needs review » Needs work

So, making a test would require deleting those variables from the test database before running the test. That seems excessive for a change that we could argue should be made in of itself, that is the process should check that it is safe to write to the array before doing so.

Sanity-checking inputs is something that should be done in and of itself, yes, and if we were purely sanity-checking for the sake of it I might agree we don't need tests. But, given that this is something multiple people have seen in real life, I do think we should test for it.

mikeryan’s picture

Assigned: mikeryan » Unassigned
quietone’s picture

Status: Needs work » Needs review
FileSize
3.04 KB
4.08 KB

OK, guess I'm just feeling lazy.
Here is a test and the fix.

The last submitted patch, 15: 2826505-15-test-only.patch, failed testing.

mikeryan’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Looks good, thanks!

drzraf’s picture

May I suggest to improve error reporting or at least document here what's going on?

The root causes of the DB inconsistency are unknown.
But isn't it for that lack of detail? Does the message "Undefined index: allowed_html FilterSettings.php:45" make it clear enough?

IE:
Is the named filter causing the issue by itself?
Is it only one of its configuration? (which one then?)
Also, now that the patch somehow ignore the filter (totally?) during the migration, will a warning/message be stored somewhere?

I think that could be of value if some of these questions could be answered in this thread.
thx

mglaman’s picture

For what it's worth, I realize that I am the cause of this bug. I tried to trim up the original commerce_migrate test fixtures to piggy back off of core's, and quietone had re-rolled them for me. So I did create a one of a kind possible scenario.

The root causes of the DB inconsistency are unknown.

I'm all for throwing exceptions and failing early. Perhaps we should throw an exception about an unexpected change from what a default Drupal 6 database would contain? Or, work around it as proposed.

quietone’s picture

The root causes of the DB inconsistency are unknown.

Not so sure about that. I just did a fresh install of D6. And in the variable table there is no entry for allowed_html. So, the process plugin really should check that the array key exists before trying to write to it.

MariaDB [uc6]> select * from variable where name like '%html%';
+---------------+-------+
| name          | value |
+---------------+-------+
| filter_html_1 | i:1;  |
+---------------+-------+
1 row in set (0.01 sec)
Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Looks good other than minor code style things, but especially a comment needs updating:

  1. +++ b/core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterSettingsTest.php
    @@ -0,0 +1,102 @@
    +  /**
    +   * Tests transformation of image field settings.
    

    Hm, not image field tests, right?

  2. +++ b/core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterSettingsTest.php
    @@ -0,0 +1,102 @@
    +      // Test with an empty source array
    ...
    +      // Test with an empty source array
    

    Minor: Period at end of line/sentence missing.

quietone’s picture

Status: Needs work » Needs review
FileSize
4.08 KB
1.12 KB

Both fixed.

phenaproxima’s picture

Status: Needs review » Needs work
+++ b/core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterSettingsTest.php
@@ -0,0 +1,102 @@
+ * Unit tests of the filter_id plugin.

It's filter_settings, not filter_id. :) Otherwise, this looks fine to me. RTBC once this is fixed.

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
FileSize
651 bytes
4.1 KB

Changes made as per comment #23 & also added interdiff.

mikeryan’s picture

Status: Needs review » Reviewed & tested by the community

Yep, think this is good to go.

  • Gábor Hojtsy committed dd7d7e5 on 8.4.x
    Issue #2826505 by quietone, pen, Yogesh Pawar, mikeryan, drzraf, mglaman...

  • Gábor Hojtsy committed 183e0e9 on 8.3.x
    Issue #2826505 by quietone, pen, Yogesh Pawar, mikeryan, drzraf, mglaman...
Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Looks good now, thanks! Great to see the added test coverage, woot :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.