getSourceProperty example

if (isset($this->configuration['node_type'])) {
      $query->condition('n.type', (array) $this->configuration['node_type'], 'IN');
    }

    return $query;
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $nid = $row->getSourceProperty('entity_id');
    $vid = $row->getSourceProperty('revision_id');
    $type = $row->getSourceProperty('type');
    $language = $row->getSourceProperty('language');

    // Get Field API field values.     foreach ($this->getFields('node', $type) as $field_name => $field) {
      // Ensure we're using the right language if the entity is translatable.       $field_language = $field['translatable'] ? $language : NULL;
      $row->setSourceProperty($field_name$this->getFieldValues('node', $field_name$nid$vid$field_language));
    }

    
if (isset($this->configuration['bundle'])) {
      $query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN');
    }

    return $query;
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $tid = $row->getSourceProperty('entity_id');
    $vocabulary = $row->getSourceProperty('machine_name');
    $language = $row->getSourceProperty('language');

    // Get Field API field values.     foreach ($this->getFields('taxonomy_term', $vocabulary) as $field_name => $field) {
      // Ensure we're using the right language if the entity is translatable.       $field_language = $field['translatable'] ? $language : NULL;
      $row->setSourceProperty($field_name$this->getFieldValues('taxonomy_term', $field_name$tid, NULL, $field_language));
    }

    // If the term name or term description were replaced by real fields using
/** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    // Get the i18n taxonomy translation setting for this vocabulary.     // 0 - No multilingual options     // 1 - Localizable terms. Run through the localization system.     // 2 - Predefined language for a vocabulary and its terms.     // 3 - Per-language terms, translatable (referencing terms with different     // languages) but not localizable.     $i18ntaxonomy_vocabulary = $this->variableGet('i18ntaxonomy_vocabulary', []);
    $vid = $row->getSourceProperty('vid');
    $state = 0;
    if (array_key_exists($vid$i18ntaxonomy_vocabulary)) {
      $state = $i18ntaxonomy_vocabulary[$vid];
    }
    $row->setSourceProperty('state', $state);
    return parent::prepareRow($row);
  }

  /** * {@inheritdoc} */
  

  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    // The instance widget_type helps determine what D8 field type we'll use.     // Identify the distinct widget_types being used in D6.     $widget_types = $this->select('content_node_field_instance', 'cnfi')
      ->fields('cnfi', ['widget_type'])
      ->condition('field_name', $row->getSourceProperty('field_name'))
      ->distinct()
      ->orderBy('widget_type')
      ->execute()
      ->fetchCol();
    // Arbitrarily use the first widget_type - if there are multiples, let the     // migrator know.     $row->setSourceProperty('widget_type', $widget_types[0]);
    if (count($widget_types) > 1) {
      $this->migration->getIdMap()->saveMessage(
        ['field_name' => $row->getSourceProperty('field_name')],
        $this->t('Widget types @types are used in Drupal 6 field instances: widget type @selected_type applied to the Drupal 8 base field', [
          
/** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    if (!parent::prepareRow($row)) {
      return FALSE;
    }
    // Set the i18n string table for use in I18nQueryTrait.     $this->i18nStringTable = static::I18N_STRING_TABLE;
    // Save the translation for this property.     $property_in_row = $row->getSourceProperty('property');
    // Get the translation for the property not already in the row and save it     // in the row.     $property_not_in_row = ($property_in_row === 'title') ? 'body' : 'title';
    return $this->getPropertyNotInRowTranslation($row$property_not_in_row, 'bid', $this->idMap);
  }

  /** * {@inheritdoc} */
  public function fields() {
    return [
      
$row = new Row($multi_source_ids_values$multi_source_ids);
    $this->assertSame(array_keys($multi_source_ids)array_keys($row->getSourceIdValues()));
  }

  /** * Tests getting the source property. * * @covers ::getSourceProperty */
  public function testGetSourceProperty() {
    $row = new Row($this->testValues, $this->testSourceIds);
    $this->assertSame($this->testValues['nid']$row->getSourceProperty('nid'));
    $this->assertSame($this->testValues['title']$row->getSourceProperty('title'));
    $this->assertNull($row->getSourceProperty('non_existing'));
  }

  /** * Tests setting and getting the destination. */
  public function testDestination() {
    $row = new Row($this->testValues, $this->testSourceIds);
    $this->assertEmpty($row->getDestination());
    $this->assertFalse($row->hasDestinationProperty('nid'));

    

class UserUpdate8002 extends ProcessPluginBase {

  /** * {@inheritdoc} * * Keep the predefined roles for rid 1 and 2. */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row$destination_property) {
    $rid = $row->getSourceProperty('rid');
    $map = [
      1 => 'anonymous',
      2 => 'authenticated',
    ];
    return $map[$rid] ?? $value;
  }

}
$query->addField('n', 'type', 'node_type');

    $query->orderBy('et.created');

    return $query;
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $cid = $row->getSourceProperty('entity_id');
    $language = $row->getSourceProperty('language');
    $node_type = $row->getSourceProperty('node_type');
    $comment_type = 'comment_node_' . $node_type;

    // Get Field API field values.     foreach ($this->getFields('comment', $comment_type) as $field_name => $field) {
      // Ensure we're using the right language if the entity is translatable.       $field_language = $field['translatable'] ? $language : NULL;
      $row->setSourceProperty($field_name$this->getFieldValues('comment', $field_name$cid, NULL, $field_language));
    }

    
'name' => $this->t('The name of the user role.'),
      'weight' => $this->t('The weight of the role.'),
    ];
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $permissions = $this->select('role_permission', 'rp')
      ->fields('rp', ['permission'])
      ->condition('rid', $row->getSourceProperty('rid'))
      ->execute()
      ->fetchCol();
    $row->setSourceProperty('permissions', $permissions);

    return parent::prepareRow($row);
  }

  /** * {@inheritdoc} */
  public function getIds() {
    
->fields('et')
      ->condition('et.entity_type', 'user')
      ->condition('et.source', '', '<>');

    return $query;
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $uid = $row->getSourceProperty('entity_id');
    $language = $row->getSourceProperty('language');

    // Get Field API field values.     foreach ($this->getFields('user') as $field_name => $field) {
      // Ensure we're using the right language if the entity is translatable.       $field_language = $field['translatable'] ? $language : NULL;
      $row->setSourceProperty($field_name$this->getFieldValues('user', $field_name$uid, NULL, $field_language));
    }

    return parent::prepareRow($row);
  }

  
->execute()
        ->fetchAllKeyed();
    }

    return $fields;
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $uid = $row->getSourceProperty('uid');

    $roles = $this->select('users_roles', 'ur')
      ->fields('ur', ['rid'])
      ->condition('ur.uid', $uid)
      ->execute()
      ->fetchCol();
    $row->setSourceProperty('roles', $roles);

    $row->setSourceProperty('data', unserialize($row->getSourceProperty('data') ?? ''));

    // If this entity was translated using Entity Translation, we need to get
'cache' => $this->t('Whether the format is cacheable.'),
      'roles' => $this->t('The role IDs which can use the format.'),
      'filters' => $this->t('The filters configured for the format.'),
    ];
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $filters = [];
    $roles = $row->getSourceProperty('roles');
    $row->setSourceProperty('roles', array_values(array_filter(explode(',', $roles))));
    $format = $row->getSourceProperty('format');
    // Find filters for this row.     $results = $this->select('filters', 'f')
      ->fields('f', ['module', 'delta', 'weight'])
      ->condition('format', $format)
      ->execute();
    foreach ($results as $raw_filter) {
      $module = $raw_filter['module'];
      $delta = $raw_filter['delta'];
      $filter = [
        
$vocabulary_source_plugin->checkRequirements();
    }
    catch (RequirementsException $e) {
      // If the d7_taxonomy_vocabulary requirements failed, that means we do not       // have a Drupal source database configured - there is nothing to       // generate.       return $this->derivatives;
    }

    try {
      foreach ($vocabulary_source_plugin as $row) {
        $bundle = $row->getSourceProperty('machine_name');
        $values = $base_plugin_definition;

        $values['label'] = $this->t('@label (@type)', [
          '@label' => $values['label'],
          '@type' => $row->getSourceProperty('name'),
        ]);
        $values['source']['bundle'] = $bundle;
        $values['destination']['default_bundle'] = $bundle;

        /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
        $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
        

  protected function getPropertyNotInRowTranslation(Row $row$property_not_in_row$object_id_name, MigrateIdMapInterface $id_map) {
    $language = $row->getSourceProperty('language');
    if (!$language) {
      throw new MigrateException('No language found.');
    }
    $object_id = $row->getSourceProperty($object_id_name);
    if (!$object_id) {
      throw new MigrateException('No objectid found.');
    }

    // If this row has been migrated it is a duplicate so skip it.     if ($id_map->lookupDestinationIds([$object_id_name => $object_id, 'language' => $language])) {
      return FALSE;
    }
'plugin' => 'null',
        ],
        'destination' => [
          'plugin' => 'null',
        ],
      ];
      try {
        $profile_migration = $this->migrationPluginManager->createStubMigration($definition);
        // Ensure that Profile is enabled in the source DB.         $profile_migration->checkRequirements();
        foreach ($profile_migration->getSourcePlugin() as $row) {
          $name = $row->getSourceProperty('name');
          $this->process[$name] = $name;
        }
      }
      catch (RequirementsException $e) {
        // The checkRequirements() call will fail when the profile module does         // not exist on the source site.       }
    }
    return parent::getProcess();
  }

}
Home | Imprint | This part of the site doesn't use cookies.