prepareQuery example


  protected function values() {
    // Create an ID field so we can record migration in the map table.     // Arbitrarily, use the first variable name.     $values['id'] = reset($this->variables);
    return $values + array_map('unserialize', $this->prepareQuery()->execute()->fetchAllKeyed());
  }

  /** * {@inheritdoc} */
  protected function doCount() {
    if (empty($this->variablesNoRowIfMissing)) {
      return 1;
    }
    $variable_names = array_keys($this->query()->execute()->fetchAllAssoc('name'));

    
// The 'language_content_type_%' variables tells us which node type and       // which comment type uses entity translation.       ->condition('name', 'language_content_type_%', 'LIKE');
    $query->condition($condition);
    return $query;
  }

  /** * {@inheritdoc} */
  protected function initializeIterator() {
    $results = array_map('unserialize', $this->prepareQuery()->execute()->fetchAllKeyed());
    $rows = [];

    // Find out which entity type uses entity translation by looking at the     // 'entity_translation_entity_types' variable.     $entity_types = array_filter($results['entity_translation_entity_types']);

    // If no entity type uses entity translation, there's nothing to do.     if (empty($entity_types)) {
      return new \ArrayIterator($rows);
    }

    

class FieldInstancePerFormDisplay extends DrupalSqlBase {

  /** * {@inheritdoc} */
  protected function initializeIterator() {
    $rows = [];
    $result = $this->prepareQuery()->execute();
    while ($field_row = $result->fetchAssoc()) {
      $bundle = $field_row['type_name'];
      $field_name = $field_row['field_name'];

      $index = "$bundle.$field_name";
      $rows[$index]['type_name'] = $bundle;
      $rows[$index]['widget_active'] = (bool) $field_row['widget_active'];
      $rows[$index]['field_name'] = $field_name;
      $rows[$index]['type'] = $field_row['type'];
      $rows[$index]['module'] = $field_row['module'];
      $rows[$index]['weight'] = $field_row['weight'];
      
/** * Return the values of the variables specified in the plugin configuration. * * @return array * An associative array where the keys are the variables specified in the * plugin configuration and the values are the values found in the source. * A key/value pair is added for the language code. Only those values are * returned that are actually in the database. */
  protected function values() {
    $values = [];
    $result = $this->prepareQuery()->execute()->FetchAllAssoc('language');
    foreach ($result as $i18n_variable) {
      $values[]['language'] = $i18n_variable->language;
    }
    $result = $this->prepareQuery()->execute()->FetchAll();
    foreach ($result as $i18n_variable) {
      foreach ($values as $key => $value) {
        if ($values[$key]['language'] === $i18n_variable->language) {
          $values[$key][$i18n_variable->name] = unserialize($i18n_variable->value);
          break;
        }
      }
    }
// Valid batch sizes are integers >= 0.       if (is_int($this->configuration['batch_size']) && ($this->configuration['batch_size']) >= 0) {
        $this->batchSize = $this->configuration['batch_size'];
      }
      else {
        throw new MigrateException("batch_size must be greater than or equal to zero");
      }
    }

    // If a batch has run the query is already setup.     if ($this->batch == 0) {
      $this->prepareQuery();

      // The rules for determining what conditions to add to the query are as       // follows (applying first applicable rule):       // 1. If the map is joinable, join it. We will want to accept all rows       // which are either not in the map, or marked in the map as NEEDS_UPDATE.       // Note that if high water fields are in play, we want to accept all rows       // above the high water mark in addition to those selected by the map       // conditions, so we need to OR them together (but AND with any existing       // conditions in the query). So, ultimately the SQL condition will look       // like (original conditions) AND (map IS NULL OR map needs update       // OR above high water).

class ViewMode extends ViewModeBase {

  /** * {@inheritdoc} */
  protected function initializeIterator() {
    $rows = [];
    $result = $this->prepareQuery()->execute();
    while ($field_row = $result->fetchAssoc()) {
      $field_row['display_settings'] = unserialize($field_row['display_settings']);
      foreach ($this->getViewModes() as $view_mode) {
        // Append to the return value if the row has display settings for this         // view mode and the view mode is neither hidden nor excluded.         // @see \Drupal\field\Plugin\migrate\source\d6\FieldInstancePerViewMode::initializeIterator()         if (isset($field_row['display_settings'][$view_mode]) && $field_row['display_settings'][$view_mode]['format'] != 'hidden' && empty($field_row['display_settings'][$view_mode]['exclude'])) {
          if (!isset($rows[$view_mode])) {
            $rows[$view_mode]['entity_type'] = 'node';
            $rows[$view_mode]['view_mode'] = $view_mode;
          }
        }

      $query->condition('fc.field_name', $title_fields, 'NOT IN');
    }

    return $query;
  }

  /** * {@inheritdoc} */
  protected function initializeIterator() {
    $results = $this->prepareQuery()->execute()->fetchAll();

    // Group all instances by their base field.     $instances = [];
    foreach ($results as $result) {
      $instances[$result['field_id']][] = $result;
    }

    // Add the array of all instances using the same base field to each row.     $rows = [];
    foreach ($results as $result) {
      $result['instances'] = $instances[$result['field_id']];
      
/** * Return the values of the variables specified in the plugin configuration. * * @return array * An associative array where the keys are the variables specified in the * plugin configuration and the values are the values found in the source. * A key/value pair is added for the language code. Only those values are * returned that are actually in the database. */
  protected function values() {
    $values = [];
    $result = $this->prepareQuery()->execute()->FetchAllAssoc('realm_key');
    foreach ($result as $variable_store) {
      $values[]['language'] = $variable_store['realm_key'];
    }
    $result = $this->prepareQuery()->execute()->FetchAll();
    foreach ($result as $variable_store) {
      foreach ($values as $key => $value) {
        if ($values[$key]['language'] === $variable_store['realm_key']) {
          if ($variable_store['serialized']) {
            $values[$key][$variable_store['name']] = unserialize($variable_store['value']);
            break;
          }
          

class FieldInstancePerViewMode extends ViewModeBase {

  /** * {@inheritdoc} */
  protected function initializeIterator() {
    $rows = [];
    $result = $this->prepareQuery()->execute();
    while ($field_row = $result->fetchAssoc()) {
      // These are added to every view mode row.       $field_row['display_settings'] = unserialize($field_row['display_settings']);
      $field_row['widget_settings'] = unserialize($field_row['widget_settings']);
      $bundle = $field_row['type_name'];
      $field_name = $field_row['field_name'];

      foreach ($this->getViewModes() as $view_mode) {
        // Append to the return value if the row has display settings for this         // view mode and the view mode is neither hidden nor excluded.         // @see \Drupal\node\Plugin\migrate\source\d6\ViewMode::initializeIterator()
Home | Imprint | This part of the site doesn't use cookies.