You are here

protected function DrupalNode6Migration::query in Drupal-to-Drupal data migration 7.2

Query for basic node fields from Drupal 6.

Return value

QueryConditionInterface

Overrides DrupalMigration::query

2 calls to DrupalNode6Migration::query()
DrupalNode6Migration::prepareRow in d6/node.inc
Called after the query data is fetched - we'll use this to populate the source row with the CCK fields.
DrupalNode6Migration::__construct in d6/node.inc

File

d6/node.inc, line 66
Implementation of DrupalNodeMigration for Drupal 6 sources.

Class

DrupalNode6Migration
Handling specific to a Drupal 6 source for nodes.

Code

protected function query() {
  $query = Database::getConnection('default', $this->sourceConnection)
    ->select('node', 'n')
    ->fields('n', array(
    'nid',
    'vid',
    'language',
    'title',
    'uid',
    'status',
    'created',
    'changed',
    'comment',
    'promote',
    'moderate',
    'sticky',
    'tnid',
    'translate',
  ))
    ->condition('n.type', $this->sourceType)
    ->orderBy($this->newOnly ? 'n.nid' : 'n.changed');
  $query
    ->innerJoin('node_revisions', 'nr', 'n.vid=nr.vid');
  $query
    ->fields('nr', array(
    'body',
    'teaser',
    'format',
  ));

  // Pick up simple CCK fields
  $cck_table = 'content_type_' . $this->sourceType;
  if (Database::getConnection('default', $this->sourceConnection)
    ->schema()
    ->tableExists($cck_table)) {
    $query
      ->leftJoin($cck_table, 'f', 'n.vid=f.vid');

    // The main column for the field should be rendered with
    // the field name, not the column name (e.g., field_foo rather
    // than field_foo_value).
    $field_info = $this->version
      ->getSourceFieldInfo();
    foreach ($field_info as $field_name => $info) {
      if (isset($info['columns']) && !$info['multiple'] && $info['db_storage']) {
        $i = 0;
        $data = FALSE;
        foreach ($info['columns'] as $display_name => $column_name) {
          if ($i++ == 0) {
            $query
              ->addField('f', $column_name, $field_name);
          }
          else {

            // The database API won't allow colons in column aliases, so we
            // will accept the default alias, and fix up the field names later.
            // Remember how to translate the field names.
            $clean_name = str_replace(':', '_', $display_name);
            $this->fixFieldNames[$clean_name] = $display_name;
            if ($info['type'] == 'filefield' && (strpos($display_name, ':list') || strpos($display_name, ':description') || strpos($display_name, ':alt') || strpos($display_name, ':title'))) {
              if (!$data) {
                $this->fileDataFields[] = $field_name . '_data';
                $query
                  ->addField('f', $field_name . '_data');
                $data = TRUE;
              }
            }
            else {
              $query
                ->addField('f', $column_name);
            }
          }
        }
      }
    }
  }

  // Join node_counter for Statistics support
  if ($this
    ->moduleExists('statistics')) {
    $query
      ->leftJoin('node_counter', 'nc', 'n.nid=nc.nid');
    $query
      ->addField('nc', 'daycount');
    $query
      ->addField('nc', 'timestamp');
    $query
      ->addField('nc', 'totalcount');
  }
  return $query;
}