Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
75.00% covered (warning)
75.00%
3 / 4
CRAP
88.89% covered (warning)
88.89%
24 / 27
UploadInstance
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (warning)
80.00%
4 / 5
9.11
88.89% covered (warning)
88.89%
24 / 27
 initializeIterator
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
4 / 4
 anonymous function
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
0 / 0
 getIds
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 fields
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 count
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
/**
 * @file
 * Contains \Drupal\file\Plugin\migrate\source\d6\UploadInstance.
 */
namespace Drupal\file\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
use Drupal\migrate\Plugin\migrate\source\DummyQueryTrait;
/**
 * Drupal 6 upload instance source from database.
 *
 * @MigrateSource(
 *   id = "d6_upload_instance",
 *   source_provider = "upload"
 * )
 */
class UploadInstance extends DrupalSqlBase {
  use DummyQueryTrait;
  /**
   * {@inheritdoc}
   */
  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);
  }
  /**
   * {@inheritdoc}
   */
  public function getIds() {
    return array(
      'node_type' => array(
        'type' => 'string',
      ),
    );
  }
  /**
   * {@inheritdoc}
   */
  public function fields() {
    return array(
      'node_type' => $this->t('Node type'),
      'max_filesize' => $this->t('Max filesize'),
      'file_extensions' => $this->t('File extensions'),
    );
  }
  /**
   * {@inheritdoc}
   */
  public function count() {
    return count($this->initializeIterator());
  }
}