You are here

protected function UploadInstance::initializeIterator in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/file/src/Plugin/migrate/source/d6/UploadInstance.php \Drupal\file\Plugin\migrate\source\d6\UploadInstance::initializeIterator()

Implementation of MigrateSource::performRewind().

We could simply execute the query and be functionally correct, but we will take advantage of the PDO-based API to optimize the query up-front.

Overrides SqlBase::initializeIterator

1 call to UploadInstance::initializeIterator()
UploadInstance::count in core/modules/file/src/Plugin/migrate/source/d6/UploadInstance.php
Get the source count.

File

core/modules/file/src/Plugin/migrate/source/d6/UploadInstance.php, line 28
Contains \Drupal\file\Plugin\migrate\source\d6\UploadInstance.

Class

UploadInstance
Drupal 6 upload instance source from database.

Namespace

Drupal\file\Plugin\migrate\source\d6

Code

protected function initializeIterator() {
  $node_types = $this
    ->select('node_type', 'nt')
    ->fields('nt', [
    'type',
  ])
    ->execute()
    ->fetchCol();
  $variables = array_map(function ($type) {
    return 'upload_' . $type;
  }, $node_types);
  $max_filesize = $this
    ->variableGet('upload_uploadsize_default', 1);
  $max_filesize = $max_filesize ? $max_filesize . 'MB' : '';
  $file_extensions = $this
    ->variableGet('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp');
  $return = array();
  $values = $this
    ->select('variable', 'v')
    ->fields('v', [
    'name',
    'value',
  ])
    ->condition('name', $variables, 'IN')
    ->execute()
    ->fetchAllKeyed();
  foreach ($node_types as $node_type) {
    $name = 'upload_' . $node_type;
    if (isset($values[$name])) {
      $enabled = unserialize($values[$name]);
      if ($enabled) {
        $return[$node_type]['node_type'] = $node_type;
        $return[$node_type]['max_filesize'] = $max_filesize;
        $return[$node_type]['file_extensions'] = $file_extensions;
      }
    }
  }
  return new \ArrayIterator($return);
}