Commit 0d009046 authored by catch's avatar catch
Browse files

Issue #3034599 by heddn, jian he, alexpott: PHP 7.0 got error: Undefined class...

Issue #3034599 by heddn, jian he, alexpott: PHP 7.0 got error: Undefined class constant 'SOURCE_IDS_HASH'
parent 5cbd58e6
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -326,7 +326,7 @@ protected function ensureTables() {
        $source_id_schema[$mapkey]['not null'] = TRUE;
      }

      $source_ids_hash[static::SOURCE_IDS_HASH] = [
      $source_ids_hash[$this::SOURCE_IDS_HASH] = [
        'type' => 'varchar',
        'length' => '64',
        'not null' => TRUE,
@@ -375,7 +375,7 @@ protected function ensureTables() {
      $schema = [
        'description' => 'Mappings from source identifier value(s) to destination identifier value(s).',
        'fields' => $fields,
        'primary key' => [static::SOURCE_IDS_HASH],
        'primary key' => [$this::SOURCE_IDS_HASH],
        'indexes' => $indexes,
      ];
      $this->getDatabase()->schema()->createTable($this->mapTableName, $schema);
@@ -434,8 +434,8 @@ protected function ensureTables() {
          ]
        );
      }
      if (!$this->getDatabase()->schema()->fieldExists($this->mapTableName, static::SOURCE_IDS_HASH)) {
        $this->getDatabase()->schema()->addField($this->mapTableName, static::SOURCE_IDS_HASH, [
      if (!$this->getDatabase()->schema()->fieldExists($this->mapTableName, $this::SOURCE_IDS_HASH)) {
        $this->getDatabase()->schema()->addField($this->mapTableName, $this::SOURCE_IDS_HASH, [
          'type' => 'varchar',
          'length' => '64',
          'not null' => TRUE,
@@ -491,7 +491,7 @@ protected function getFieldSchema(array $id_definition) {
  public function getRowBySource(array $source_id_values) {
    $query = $this->getDatabase()->select($this->mapTableName(), 'map')
      ->fields('map');
    $query->condition(static::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
    $query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
    $result = $query->execute();
    return $result->fetchAssoc();
  }
@@ -591,7 +591,7 @@ public function lookupDestinationIds(array $source_id_values) {
      ->fields('map', $this->destinationIdFields());
    if (count($this->sourceIdFields()) === count($conditions)) {
      // Optimization: Use the primary key.
      $query->condition(self::SOURCE_IDS_HASH, $this->getSourceIdsHash(array_values($conditions)));
      $query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash(array_values($conditions)));
    }
    else {
      foreach ($conditions as $db_field => $value) {
@@ -641,7 +641,7 @@ public function saveIdMapping(Row $row, array $destination_id_values, $source_ro
    if ($this->migration->getTrackLastImported()) {
      $fields['last_imported'] = time();
    }
    $keys = [static::SOURCE_IDS_HASH => $this->getSourceIdsHash($source_id_values)];
    $keys = [$this::SOURCE_IDS_HASH => $this->getSourceIdsHash($source_id_values)];
    // Notify anyone listening of the map row we're about to save.
    $this->eventDispatcher->dispatch(MigrateEvents::MAP_SAVE, new MigrateMapSaveEvent($this, $fields));
    $this->getDatabase()->merge($this->mapTableName())
@@ -660,7 +660,7 @@ public function saveMessage(array $source_id_values, $message, $level = Migratio
        return;
      }
    }
    $fields[static::SOURCE_IDS_HASH] = $this->getSourceIdsHash($source_id_values);
    $fields[$this::SOURCE_IDS_HASH] = $this->getSourceIdsHash($source_id_values);
    $fields['level'] = $level;
    $fields['message'] = $message;
    $this->getDatabase()->insert($this->messageTableName())
@@ -679,7 +679,7 @@ public function getMessageIterator(array $source_id_values = [], $level = NULL)
    $query = $this->getDatabase()->select($this->messageTableName(), 'msg')
      ->fields('msg');
    if ($source_id_values) {
      $query->condition(static::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
      $query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
    }

    if ($level) {
@@ -772,13 +772,13 @@ public function delete(array $source_id_values, $messages_only = FALSE) {

    if (!$messages_only) {
      $map_query = $this->getDatabase()->delete($this->mapTableName());
      $map_query->condition(static::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
      $map_query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
      // Notify anyone listening of the map row we're about to delete.
      $this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values));
      $map_query->execute();
    }
    $message_query = $this->getDatabase()->delete($this->messageTableName());
    $message_query->condition(static::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
    $message_query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
    $message_query->execute();
  }

@@ -797,7 +797,7 @@ public function deleteDestination(array $destination_id_values) {
      $this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values));
      $map_query->execute();

      $message_query->condition(static::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
      $message_query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
      $message_query->execute();
    }
  }
@@ -969,7 +969,7 @@ function (array $id) {

    // If there's a bundle, it means we have a derived migration and we need to
    // find all the mapping tables from the related derived migrations.
    if ($base_id = substr($this->migration->id(), 0, strpos($this->migration->id(), static::DERIVATIVE_SEPARATOR))) {
    if ($base_id = substr($this->migration->id(), 0, strpos($this->migration->id(), $this::DERIVATIVE_SEPARATOR))) {
      $migration_manager = $this->getMigrationPluginManager();
      $migrations = $migration_manager->getDefinitions();
      foreach ($migrations as $migration_id => $migration) {
+50 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\migrate\Kernel;

use Drupal\migrate\Plugin\MigrationInterface;

/**
 * Tests the MigrateExecutable class.
 *
 * @group migrate
 */
class MigrateExecutableTest extends MigrateTestBase {

  public static $modules = [
    'entity_test',
    'user',
  ];

  public function setUp() {
    parent::setUp();
    $this->installEntitySchema('user');
    $this->installEntitySchema('entity_test');
  }

  /**
   * Tests the MigrateExecutable class.
   */
  public function testMigrateExecutable() {
    $data_rows = [
      ['key' => '1', 'field1' => 'f1value1', 'field2' => 'f2value1'],
      ['key' => '2', 'field1' => 'f1value2', 'field2' => 'f2value2'],
    ];
    $ids = ['key' => ['type' => 'integer']];
    $definition = [
      'migration_tags' => ['Embedded data test'],
      'source' => [
        'plugin' => 'embedded_data',
        'data_rows' => $data_rows,
        'ids' => $ids,
      ],
      'process' => [],
      'destination' => ['plugin' => 'entity:entity_test'],
    ];

    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
    $executable = new TestMigrateExecutable($migration);
    $this->assertEquals(MigrationInterface::RESULT_COMPLETED, $executable->import());
  }

}
+17 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\migrate\Kernel;

/**
 * Class to test FilterIterators.
 */
class TestFilterIterator extends \FilterIterator {

  /**
   * {@inheritdoc}
   */
  public function accept() {
    return TRUE;
  }

}
+28 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\migrate\Kernel;

use Drupal\migrate\MigrateExecutable;

/**
 * Tests MigrateExecutable.
 */
class TestMigrateExecutable extends MigrateExecutable {

  /**
   * {@inheritdoc}
   */
  protected function getIdMap() {
    // This adds test coverage that this works.
    return new TestFilterIterator(parent::getIdMap());
  }

  /**
   * {@inheritdoc}
   */
  protected function getSource() {
    // This adds test coverage that this works.
    return new TestFilterIterator(parent::getSource());
  }

}