3 namespace Drupal\file\Plugin\migrate\source\d6;
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6 use Drupal\migrate\Plugin\migrate\source\DummyQueryTrait;
9 * Drupal 6 upload instance source from database.
12 * id = "d6_upload_instance",
13 * source_provider = "upload"
16 class UploadInstance extends DrupalSqlBase {
23 protected function initializeIterator() {
24 $node_types = $this->select('node_type', 'nt')
25 ->fields('nt', ['type'])
28 $variables = array_map(function($type) { return 'upload_' . $type; }, $node_types);
30 $max_filesize = $this->variableGet('upload_uploadsize_default', 1);
31 $max_filesize = $max_filesize ? $max_filesize . 'MB' : '';
32 $file_extensions = $this->variableGet('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp');
34 $values = $this->select('variable', 'v')
35 ->fields('v', ['name', 'value'])
36 ->condition('v.name', $variables, 'IN')
39 foreach ($node_types as $node_type) {
40 $name = 'upload_' . $node_type;
41 // By default, file attachments in D6 are enabled unless upload_<type> is
42 // false, so include types where the upload-variable is not set.
43 $enabled = !isset($values[$name]) || unserialize($values[$name]);
45 $return[$node_type]['node_type'] = $node_type;
46 $return[$node_type]['max_filesize'] = $max_filesize;
47 $return[$node_type]['file_extensions'] = $file_extensions;
51 return new \ArrayIterator($return);
57 public function getIds() {
68 public function fields() {
70 'node_type' => $this->t('Node type'),
71 'max_filesize' => $this->t('Max filesize'),
72 'file_extensions' => $this->t('File extensions'),
79 public function count() {
80 return count($this->initializeIterator());