Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
f14ec035
Commit
f14ec035
authored
Jan 10, 2015
by
Alex Pott
Browse files
Issue
#2394157
by benjy: Update the EntityFile destination to handle temporary files
parent
a3efcb6f
Changes
8
Hide whitespace changes
Inline
Side-by-side
core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php
View file @
f14ec035
...
...
@@ -42,8 +42,14 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
* {@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'
]);
$
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
;
$replace
=
FILE_EXISTS_REPLACE
;
if
(
!
empty
(
$this
->
configuration
[
'rename'
]))
{
$entity_id
=
$row
->
getDestinationProperty
(
$this
->
getKey
(
'id'
));
...
...
@@ -102,4 +108,18 @@ protected function urlencode($filename) {
return
$filename
;
}
/**
* Check if a file is a temp file.
*
* @param string $file
* The destination file path.
*
* @return bool
* TRUE if the file is temporary otherwise FALSE.
*/
protected
function
isTempFile
(
$file
)
{
$tmp
=
'temporary://'
;
return
substr
(
$file
,
0
,
strlen
(
$tmp
))
===
$tmp
;
}
}
core/modules/migrate_drupal/config/install/migrate.migration.d6_file.yml
View file @
f14ec035
...
...
@@ -14,6 +14,7 @@ process:
source
:
-
filepath
-
file_directory_path
-
temp_directory_path
-
is_public
filemime
:
filemime
filesize
:
filesize
...
...
core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_file.yml
View file @
f14ec035
...
...
@@ -13,6 +13,7 @@ process:
source
:
-
picture
-
file_directory_path
-
temp_directory_path
-
'
constants/is_public'
destination
:
plugin
:
entity:file
...
...
core/modules/migrate_drupal/src/Plugin/migrate/process/d6/FileUri.php
View file @
f14ec035
...
...
@@ -25,7 +25,13 @@ class FileUri extends ProcessPluginBase {
*/
public
function
transform
(
$value
,
MigrateExecutable
$migrate_executable
,
Row
$row
,
$destination_property
)
{
list
(
$filepath
,
$file_directory_path
,
$is_public
)
=
$value
;
list
(
$filepath
,
$file_directory_path
,
$temp_directory_path
,
$is_public
)
=
$value
;
// Specific handling using $temp_directory_path for temporary files.
if
(
substr
(
$filepath
,
0
,
strlen
(
$temp_directory_path
))
===
$temp_directory_path
)
{
$uri
=
preg_replace
(
'/^'
.
preg_quote
(
$temp_directory_path
,
'/'
)
.
'/'
,
''
,
$filepath
);
return
"temporary://
$uri
"
;
}
// Strip the files path from the uri instead of using basename
// so any additional folders in the path are preserved.
...
...
core/modules/migrate_drupal/src/Plugin/migrate/source/d6/File.php
View file @
f14ec035
...
...
@@ -26,6 +26,13 @@ class File extends DrupalSqlBase {
*/
protected
$filePath
;
/**
* The temporary file path.
*
* @var string
*/
protected
$tempFilePath
;
/**
* Flag for private or public file storage.
*
...
...
@@ -58,6 +65,7 @@ public function query() {
protected
function
runQuery
()
{
$conf_path
=
isset
(
$this
->
configuration
[
'conf_path'
])
?
$this
->
configuration
[
'conf_path'
]
:
'sites/default'
;
$this
->
filePath
=
$this
->
variableGet
(
'file_directory_path'
,
$conf_path
.
'/files'
)
.
'/'
;
$this
->
tempFilePath
=
$this
->
variableGet
(
'file_directory_temp'
,
'/tmp'
)
.
'/'
;
// FILE_DOWNLOADS_PUBLIC == 1 and FILE_DOWNLOADS_PRIVATE == 2.
$this
->
isPublic
=
$this
->
variableGet
(
'file_downloads'
,
1
)
==
1
;
...
...
@@ -69,6 +77,7 @@ protected function runQuery() {
*/
public
function
prepareRow
(
Row
$row
)
{
$row
->
setSourceProperty
(
'file_directory_path'
,
$this
->
filePath
);
$row
->
setSourceProperty
(
'temp_directory_path'
,
$this
->
tempFilePath
);
$row
->
setSourceProperty
(
'is_public'
,
$this
->
isPublic
);
return
parent
::
prepareRow
(
$row
);
}
...
...
core/modules/migrate_drupal/src/Plugin/migrate/source/d6/UserPictureFile.php
View file @
f14ec035
...
...
@@ -26,6 +26,13 @@ class UserPictureFile extends DrupalSqlBase {
*/
protected
$filePath
;
/**
* The temporary file path.
*
* @var string
*/
protected
$tempFilePath
;
/**
* {@inheritdoc}
*/
...
...
@@ -42,6 +49,7 @@ public function query() {
public
function
runQuery
()
{
$conf_path
=
isset
(
$this
->
configuration
[
'conf_path'
])
?
$this
->
configuration
[
'conf_path'
]
:
'sites/default'
;
$this
->
filePath
=
$this
->
variableGet
(
'file_directory_path'
,
$conf_path
.
'/files'
)
.
'/'
;
$this
->
tempFilePath
=
$this
->
variableGet
(
'file_directory_temp'
,
'/tmp'
)
.
'/'
;
return
parent
::
runQuery
();
}
...
...
@@ -51,6 +59,7 @@ public function runQuery() {
public
function
prepareRow
(
Row
$row
)
{
$row
->
setSourceProperty
(
'filename'
,
basename
(
$row
->
getSourceProperty
(
'picture'
)));
$row
->
setSourceProperty
(
'file_directory_path'
,
$this
->
filePath
);
$row
->
setSourceProperty
(
'temp_directory_path'
,
$this
->
tempFilePath
);
return
parent
::
prepareRow
(
$row
);
}
...
...
core/modules/migrate_drupal/src/Tests/Dump/Drupal6File.php
View file @
f14ec035
...
...
@@ -123,7 +123,18 @@ public function load() {
'status'
=>
'1'
,
'timestamp'
=>
'1388880668'
,
))
->
values
(
array
(
'fid'
=>
'4'
,
'uid'
=>
'1'
,
'filename'
=>
'some-temp-file.jpg'
,
'filepath'
=>
'/tmp/some-temp-file.jpg'
,
'filemime'
=>
'image/jpeg'
,
'filesize'
=>
'183'
,
'status'
=>
'0'
,
'timestamp'
=>
'1388880668'
,
))
->
execute
();
file_put_contents
(
'/tmp/some-temp-file.jpg'
,
''
);
}
}
core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php
View file @
f14ec035
...
...
@@ -68,6 +68,10 @@ public function testFiles() {
$file
=
entity_load
(
'file'
,
2
);
$this
->
assertEqual
(
$file
->
getFileUri
(),
'public://core/modules/simpletest/files/image-2.jpg'
);
// Ensure that a temporary file has been migrated.
$file
=
entity_load
(
'file'
,
4
);
$this
->
assertIdentical
(
$file
->
getFileUri
(),
'temporary://some-temp-file.jpg'
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment