Problem/Motivation

Fix PHP 8 and 8.1 compatibility issues/deprecations

Proposed resolution

TBD

Issue fork feeds-3261188

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Discussed during call in ContributionWeekend2022, we are considering requiring dev release for tests of pathauto to resolve an issue that has been committed but not released for PHP 8.

megachriz’s picture

Hello

modestmoes’s picture

Collaborating with @joelpittet on this for ContributionWeekend2022

megachriz’s picture

Title: PHP 8.0 compatibility » PHP 8.0/8.1 compatibility for Feeds 8.x-3.x
Parent issue: #3254188: PHP 8.0/8.1 compatibility »
beanjammin’s picture

Watched over @joelpittet's shoulder while barking out the occasional "helpful" comment.

joelpittet’s picture

megachriz’s picture

I closed merge request !46 because there has been a new release of Pathauto which makes it no longer necessary to require the dev version of Pathauto for testing.

Opened a new issue fork to actively work on tests that fail on PHP 8.1. Some PHP 8.1 issues have been fixed in the mean time in other issues:
#3266706: Deprecated getIterator() and count() using PHP 8.1
#3267244: Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\feeds\Plugin\Field\FieldType\FeedsItem->preSave()
#3266704: PHP 8.1: do not pass null to Html::escape() and Unicode::truncate().

megachriz’s picture

Status: Needs review » Needs work

UpdateCustomSourcesUpdateTest test failure

The following failure looks like a bug in Drupal Core:

Drupal\Tests\feeds\Functional\Update\UpdateCustomSourcesUpdateTest::testUpdateCustomSources
Exception: Deprecated function: mb_strtolower(): Passing null to parameter #1 ($string) of type string is deprecated

mb_strtolower() is called in
In \Drupal\Core\Config\Entity\Query\Condition::compile():

elseif (!is_bool($condition['value'])) {
  $condition['value'] = mb_strtolower($condition['value']);
}

I've inspected what the condition is and it happens to be:
Array ( [field] => uuid [value] => NULL [operator] => = [langcode] => NULL)
In \Drupal\Core\Config\Entity\ConfigEntityBase::preSave() the entity's UUID is passed as condition:

$matching_entities = $storage->getQuery()
  ->condition('uuid', $this->uuid())
  ->execute();

But it is valid that ::uuid() can return NULL, see \Drupal\Core\Entity\EntityBase::uuid():

/**
 * {@inheritdoc}
 */
public function uuid() {
  return $this->uuid ?? NULL;
}

I've found some existing core issues related to this:
https://www.drupal.org/project/issues/drupal?text=mb_strtolower+null+uui...

I think it would be good to open a core issue for above.

auto_detect_line_endings

Using ini_set('auto_detect_line_endings', '1'); is deprecated in PHP 8.1. According to https://php.watch/versions/8.1/auto_detect_line_endings-ini-deprecated, this means that line-endings for \r characters are no longer supported.
But removing the usage of that in \Drupal\feeds\Component\CsvParser does now cause a test failure.
So the question is: should Feeds actively remove support for CSV files with \r line endings or is there a workaround?

megachriz’s picture

Status: Needs work » Needs review

Hopefully fixed all test failures now:

  • PasswordTest was failing because one of the imported items failed validation, but %guid was NULL and passing that as an argument t() causes an error when the translation gets rendered:

    Deprecated function: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Html::escape() (line 424 of core/lib/Drupal/Component/Utility/Html.php).

    Drupal\Component\Utility\Html::escape(NULL) (Line: 262)
    Drupal\Component\Render\FormattableMarkup::placeholderEscape(NULL) (Line: 232)
    Drupal\Component\Render\FormattableMarkup::placeholderFormat('Entity with %guid failed to validate', Array) (Line: 195)
    Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 15)
    Drupal\Core\StringTranslation\TranslatableMarkup->__toString() (Line: 1)

  • UpdateCustomSourcesUpdateTest gets fixed by adding a 'uuid' value to the test config file "feeds.feed_type.csv.yml" in tests/fixtures/feeds-8.x-3.0-alpha11.
  • CsvParserTest gets fixed by actively removing support for CSV files with \r line endings - the test coverage for this gets removed.

  • MegaChriz committed e044eb2 on 8.x-3.x
    Issue #3261188 by MegaChriz, joelpittet, modestmoes, Beanjammin, ramil g...
megachriz’s picture

Status: Needs review » Fixed

I merged the changes. I looked once more on why for certain methods of \Drupal\feeds\Component\CsvParser I added #[\ReturnTypeWillChange] and that is because the return type "mixed" is only available since PHP 8.1. Hm, should add an additional commit that notes that.

  • MegaChriz committed 7a64dee on 8.x-3.x
    Issue #3261188 by MegaChriz: added note to add return types to \Drupal\...

Status: Fixed » Closed (fixed)

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