/** * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { $file = $row->getSourceProperty($this->configuration['source_path_property']); $destination = $row->getDestinationProperty($this->configuration['destination_path_property']); $source = $this->configuration['source_base_path'] . $file; // Ensure the source file exists, if it's a local URI or path. if ($this->isLocalUri($source) && !file_exists($source)) { throw new MigrateException(SafeMarkup::format('File @source does not exist.', ['@source' => $source])); } // If the start and end file is exactly the same, there is nothing to do. if ($this->isLocationUnchanged($source, $destination)) { return parent::import($row, $old_destination_id_values); } $replace = $this->getOverwriteMode($row); $success = $this->writeFile($source, $destination, $replace); if (!$success) { $dir = $this->getDirectory($destination); if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) { $success = $this->writeFile($source, $destination, $replace); } else { throw new MigrateException(SafeMarkup::format('Could not create directory @dir', ['@dir' => $dir])); } } if ($success) { return parent::import($row, $old_destination_id_values); } else { throw new MigrateException(SafeMarkup::format('File %source could not be copied to %destination.', ['%source' => $source, '%destination' => $destination])); } }
/** * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { $source = $this->configuration['source_base_path'] . $row->getSourceProperty($this->configuration['source_path_property']); $destination = $row->getDestinationProperty($this->configuration['destination_path_property']); $replace = FILE_EXISTS_REPLACE; if (!empty($this->configuration['rename'])) { $entity_id = $row->getDestinationProperty($this->getKey('id')); if (!empty($entity_id) && ($entity = $this->storage->load($entity_id))) { $replace = FILE_EXISTS_RENAME; } } $dirname = drupal_dirname($destination); if (!file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) { throw new MigrateException(t('Could not create directory %dirname', array('%dirname' => $dirname))); } if ($this->configuration['move']) { $copied = file_unmanaged_move($source, $destination, $replace); } else { // Determine whether we can perform this operation based on overwrite rules. $original_destination = $destination; $destination = file_destination($destination, $replace); if ($destination === FALSE) { throw new MigrateException(t('File %file could not be copied because a file by that name already exists in the destination directory (%destination)', array('%file' => $source, '%destination' => $original_destination))); } $source = $this->urlencode($source); $copied = copy($source, $destination); } if ($copied) { return parent::import($row, $old_destination_id_values); } else { throw new MigrateException(t('File %source could not be copied to %destination.', array('%source' => $source, '%destination' => $destination))); } }
/** * {@inheritdoc} * @throws \Drupal\migrate\MigrateException */ public function import(Row $row, array $old_destination_id_values = array()) { // Do not overwrite the root account password. if ($row->getDestinationProperty('uid') == 1) { $row->removeDestinationProperty('pass'); } return parent::import($row, $old_destination_id_values); }
/** * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { if ($row->isStub() && ($state = $this->state->get('comment.maintain_entity_statistics', 0))) { $this->state->set('comment.maintain_entity_statistics', 0); } $return = parent::import($row, $old_destination_id_values); if ($row->isStub() && $state) { $this->state->set('comment.maintain_entity_statistics', $state); } return $return; }
/** * {@inheritdoc} * @throws \Drupal\migrate\MigrateException */ public function import(Row $row, array $old_destination_id_values = array()) { if ($this->password) { if ($this->password instanceof MigratePassword) { $this->password->enableMd5Prefixing(); } else { throw new MigrateException('Password service has been altered by another module, aborting.'); } } $ids = parent::import($row, $old_destination_id_values); if ($this->password) { $this->password->disableMd5Prefixing(); } return $ids; }
/** * {@inheritdoc} * @throws \Drupal\migrate\MigrateException */ public function import(Row $row, array $old_destination_id_values = array()) { if ($this->password) { if ($this->password instanceof MigratePassword) { $this->password->enableMd5Prefixing(); } else { throw new MigrateException('Password service has been altered by another module, aborting.'); } } // Do not overwrite the root account password. if ($row->getDestinationProperty('uid') == 1) { $row->removeDestinationProperty('pass'); } $ids = parent::import($row, $old_destination_id_values); if ($this->password) { $this->password->disableMd5Prefixing(); } return $ids; }
/** * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { $source = $this->configuration['source_base_path'] . $row->getSourceProperty($this->configuration['source_path_property']); $destination = $row->getDestinationProperty($this->configuration['destination_path_property']); $replace = FILE_EXISTS_REPLACE; if (!empty($this->configuration['rename'])) { $entity_id = $row->getDestinationProperty($this->getKey('id')); if (!empty($entity_id) && ($entity = $this->storage->load($entity_id))) { $replace = FILE_EXISTS_RENAME; } } $dirname = drupal_dirname($destination); file_prepare_directory($dirname, FILE_CREATE_DIRECTORY); if ($this->configuration['move']) { file_unmanaged_move($source, $destination, $replace); } else { file_unmanaged_copy($source, $destination, $replace); } return parent::import($row, $old_destination_id_values); }
/** * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { $file = $row->getSourceProperty($this->configuration['source_path_property']); $destination = $row->getDestinationProperty($this->configuration['destination_path_property']); // We check the destination to see if this is a temporary file. If it is // then we do not prepend the source_base_path because temporary files are // already absolute. $source = $this->isTempFile($destination) ? $file : $this->configuration['source_base_path'] . $file; $dirname = drupal_dirname($destination); if (!file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) { throw new MigrateException(t('Could not create directory %dirname', array('%dirname' => $dirname))); } // If the start and end file is exactly the same, there is nothing to do. if (drupal_realpath($source) === drupal_realpath($destination)) { return parent::import($row, $old_destination_id_values); } $replace = FILE_EXISTS_REPLACE; if (!empty($this->configuration['rename'])) { $entity_id = $row->getDestinationProperty($this->getKey('id')); if (!empty($entity_id) && ($entity = $this->storage->load($entity_id))) { $replace = FILE_EXISTS_RENAME; } } if ($this->configuration['move']) { $copied = file_unmanaged_move($source, $destination, $replace); } else { // Determine whether we can perform this operation based on overwrite rules. $original_destination = $destination; $destination = file_destination($destination, $replace); if ($destination === FALSE) { throw new MigrateException(t('File %file could not be copied because a file by that name already exists in the destination directory (%destination)', array('%file' => $source, '%destination' => $original_destination))); } $source = $this->urlencode($source); $copied = @copy($source, $destination); } if ($copied) { return parent::import($row, $old_destination_id_values); } else { throw new MigrateException(t('File %source could not be copied to %destination.', array('%source' => $source, '%destination' => $destination))); } }
/** * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { // For stub rows, there is no real file to deal with, let the stubbing // process create the stub entity. if ($row->isStub()) { return parent::import($row, $old_destination_id_values); } $file = $row->getSourceProperty($this->configuration['source_path_property']); $destination = $row->getDestinationProperty($this->configuration['destination_path_property']); $source = $this->configuration['source_base_path'] . $file; // Ensure the source file exists, if it's a local URI or path. if ($this->isLocalUri($source) && !file_exists($source)) { throw new MigrateException("File '{$source}' does not exist."); } // If the start and end file is exactly the same, there is nothing to do. if ($this->isLocationUnchanged($source, $destination)) { return parent::import($row, $old_destination_id_values); } $replace = $this->getOverwriteMode($row); $success = $this->writeFile($source, $destination, $replace); if (!$success) { $dir = $this->getDirectory($destination); if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) { $success = $this->writeFile($source, $destination, $replace); } else { throw new MigrateException("Could not create directory '{$dir}'"); } } if ($success) { return parent::import($row, $old_destination_id_values); } else { throw new MigrateException("File {$source} could not be copied to {$destination}."); } }