public static function MigrateFileTest::migrateDumpAlter in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/file/src/Tests/Migrate/d6/MigrateFileTest.php \Drupal\file\Tests\Migrate\d6\MigrateFileTest::migrateDumpAlter()
Allows tests to alter dumps after they've loaded.
Parameters
\Drupal\simpletest\TestBase $test: The test that is being run.
Overrides MigrateDumpAlterInterface::migrateDumpAlter
File
- core/
modules/ file/ src/ Tests/ Migrate/ d6/ MigrateFileTest.php, line 129 - Contains \Drupal\file\Tests\Migrate\d6\MigrateFileTest.
Class
- MigrateFileTest
- file migration.
Namespace
Drupal\file\Tests\Migrate\d6Code
public static function migrateDumpAlter(TestBase $test) {
// Creates a random filename and updates the source database.
$random = new Random();
$temp_directory = $test
->getTempFilesDirectory();
file_prepare_directory($temp_directory, FILE_CREATE_DIRECTORY);
static::$tempFilename = $test
->getDatabasePrefix() . $random
->name() . '.jpg';
$file_path = $temp_directory . '/' . static::$tempFilename;
file_put_contents($file_path, '');
$db = Database::getConnection('default', 'migrate');
$db
->update('files')
->condition('fid', 6)
->fields(array(
'filename' => static::$tempFilename,
'filepath' => $file_path,
))
->execute();
$file = (array) $db
->select('files')
->fields('files')
->condition('fid', 5)
->execute()
->fetchObject();
unset($file['fid']);
$db
->insert('files')
->fields($file)
->execute();
return static::$tempFilename;
}