You are here

public function DrupalFileMigration::__construct in Drupal-to-Drupal data migration 7.2

Required arguments:

source_connection - Connection key for the DatabaseConnection holding the source Drupal installation. source_version - Major version number (as an integer) of the source install. machine_name - Machine name under which a particular migration is registered. description - Description of the migration. group_name - The group (import job) containing this migration (import task).

Optional arguments:

source_database - Array describing the source connection, to be defined in the constructor. If absent, the source connection is assumed to be established elsewhere (typically settings.php). group - Migration group to add this migration to. dependencies - Array of migrations that must be run before this one. soft_dependencies - Array of migrations that should be listed before this one. format_mappings - Array keyed by source format IDs or machine names, with the values being the corresponding D7 machine name. If unspecified, source_options - Array to be passed as options to source constructors, overriding the defaults (map_joinable FALSE, cache_counts TRUE, cache_key derived from the machine name). version_class - The name of a custom DrupalVersion class overriding the default derived from source_version. new_only - For any destination types that support highwater marks or track_changes, suppress that support so repeated migrations only import new items.

Parameters

array $arguments:

Overrides DrupalMigration::__construct

3 calls to DrupalFileMigration::__construct()
DrupalFile5Migration::__construct in d5/file.inc
Required arguments:
DrupalFile6Migration::__construct in d6/file.inc
Required arguments:
DrupalFile7Migration::__construct in d7/file.inc
Required arguments:
3 methods override DrupalFileMigration::__construct()
DrupalFile5Migration::__construct in d5/file.inc
Required arguments:
DrupalFile6Migration::__construct in d6/file.inc
Required arguments:
DrupalFile7Migration::__construct in d7/file.inc
Required arguments:

File

./file.inc, line 25
Base class for migrating files into Drupal.

Class

DrupalFileMigration
Base class for all file migrations - handles commonalities across all supported source Drupal versions.

Code

public function __construct(array $arguments) {
  parent::__construct($arguments);
  if (!empty($arguments['user_migration'])) {
    $user_migration = $arguments['user_migration'];
    $this->dependencies[] = $user_migration;
  }
  if (empty($arguments['bundle'])) {
    $arguments['bundle'] = 'file';
  }
  if (empty($arguments['file_class'])) {
    $arguments['file_class'] = 'MigrateFileUri';
  }
  if (empty($arguments['destination_dir'])) {
    $arguments['destination_dir'] = 'public://';
  }
  $this->sourceFields += $this->version
    ->getSourceFields('file', $arguments['bundle']);

  // Allow derived classes to override this definition by setting it before
  // calling their parent constructor
  if (!isset($this->map)) {
    $this->map = new MigrateSQLMap($this->machineName, array(
      'fid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Source file ID',
        'alias' => 'f',
      ),
    ), MigrateDestinationFile::getKeySchema(), $this->mapConnection);
  }
  $this->source = new MigrateSourceSQL($this
    ->query(), $this->sourceFields, NULL, $this->sourceOptions);
  $this->destination = new MigrateDestinationFile($arguments['bundle'], $arguments['file_class']);

  // Setup common mappings
  $this
    ->addFieldMapping('destination_dir')
    ->defaultValue($arguments['destination_dir']);
  $this
    ->addFieldMapping('source_dir')
    ->defaultValue($arguments['source_dir']);
  $this
    ->addFieldMapping('file_replace')
    ->defaultValue(MigrateFile::FILE_EXISTS_REUSE);
  $this
    ->addFieldmapping('preserve_files')
    ->defaultValue(TRUE);
  if (isset($arguments['default_uid'])) {
    $default_uid = $arguments['default_uid'];
  }
  else {
    $default_uid = 1;
  }
  if (isset($user_migration)) {
    $this
      ->addFieldMapping('uid', 'uid')
      ->sourceMigration($user_migration)
      ->defaultValue($default_uid);
  }
  else {
    $this
      ->addFieldMapping('uid')
      ->defaultValue($default_uid);
  }
  $this
    ->addUnmigratedSources(array(
    'filename',
    'filemime',
    'filesize',
    'urlencode',
  ));
}