Commit e044eb20 authored by Youri van Koppen's avatar Youri van Koppen
Browse files

Issue #3261188 by MegaChriz, joelpittet, modestmoes, Beanjammin, ramil g: PHP...

Issue #3261188 by MegaChriz, joelpittet, modestmoes, Beanjammin, ramil g: PHP 8.0/8.1 compatibility for Feeds 8.x-3.x
parent 4dd1278d
Loading
Loading
Loading
Loading
+5 −12
Original line number Diff line number Diff line
@@ -84,13 +84,8 @@ class CsvParser implements \Iterator {
    if (!is_file($filepath) || !is_readable($filepath)) {
      throw new \InvalidArgumentException('$filepath must exist and be readable.');
    }

    $previous = ini_set('auto_detect_line_endings', '1');

    $handle = fopen($filepath, 'rb');

    ini_set('auto_detect_line_endings', $previous);

    return new static($handle);
  }

@@ -104,12 +99,8 @@ class CsvParser implements \Iterator {
   *   A new CsvParser object.
   */
  public static function createFromString($string) {
    $previous = ini_set('auto_detect_line_endings', '1');

    $handle = fopen('php://temp', 'w+b');

    ini_set('auto_detect_line_endings', $previous);

    fwrite($handle, $string);
    fseek($handle, 0);

@@ -197,6 +188,7 @@ class CsvParser implements \Iterator {
  /**
   * Implements \Iterator::current().
   */
  #[\ReturnTypeWillChange]
  public function current() {
    return $this->currentLine;
  }
@@ -204,6 +196,7 @@ class CsvParser implements \Iterator {
  /**
   * Implements \Iterator::key().
   */
  #[\ReturnTypeWillChange]
  public function key() {
    return $this->linesRead - 1;
  }
@@ -211,7 +204,7 @@ class CsvParser implements \Iterator {
  /**
   * Implements \Iterator::next().
   */
  public function next() {
  public function next(): void {
    // Record the file position before reading the next line since we
    // preemptively read lines to avoid returning empty rows.
    $this->filePosition = ftell($this->handle);
@@ -235,7 +228,7 @@ class CsvParser implements \Iterator {
  /**
   * Implements \Iterator::rewind().
   */
  public function rewind() {
  public function rewind(): void {
    rewind($this->handle);

    if ($this->hasHeader && !$this->startByte) {
@@ -253,7 +246,7 @@ class CsvParser implements \Iterator {
  /**
   * Implements \Iterator::valid().
   */
  public function valid() {
  public function valid(): bool {
    return (bool) $this->currentLine;
  }

+4 −4
Original line number Diff line number Diff line
@@ -579,8 +579,8 @@ abstract class EntityProcessorBase extends ProcessorBase implements EntityProces
    // Compose error message. If available, use the entity label to indicate
    // which item failed. Fallback to the GUID value (if available) or else
    // no indication.
    $label = $entity->label();
    $guid = $entity->get('feeds_item')->guid;
    $label = (string) $entity->label();
    $guid = (string) $entity->get('feeds_item')->guid;

    $messages = [];
    $args = [
@@ -590,10 +590,10 @@ abstract class EntityProcessorBase extends ProcessorBase implements EntityProces
      '@errors' => \Drupal::service('renderer')->renderRoot($element),
      ':url' => $this->url('entity.feeds_feed_type.mapping', ['feeds_feed_type' => $this->feedType->id()]),
    ];
    if ($label || $label === '0' || $label === 0) {
    if ($label || $label === '0') {
      $messages[] = $this->t('The @entity %label failed to validate with the following errors: @errors', $args);
    }
    elseif ($guid || $guid === '0' || $guid === 0) {
    elseif ($guid || $guid === '0') {
      $messages[] = $this->t('The @entity with GUID %guid failed to validate with the following errors: @errors', $args);
    }
    else {
+1 −0
Original line number Diff line number Diff line
uuid: 91c601fd-ce86-499e-b15e-bbd9262a90d6
langcode: en
status: true
dependencies:
+0 −6
Original line number Diff line number Diff line
@@ -65,15 +65,9 @@ class CsvParserTest extends FeedsUnitTestCase {
      $item = str_replace("\r\n", "\n", $item);
    });

    $mac = $expected;
    array_walk_recursive($mac, function (&$item, $key) {
      $item = str_replace("\r\n", "\r", $item);
    });

    return [
      [$expected, "\r\n"],
      [$unix, "\n"],
      [$mac, "\r"],
    ];
  }