summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--devel_generate/file.devel_generate.inc21
1 files changed, 15 insertions, 6 deletions
diff --git a/devel_generate/file.devel_generate.inc b/devel_generate/file.devel_generate.inc
index 4751ebe..84ed5ed 100644
--- a/devel_generate/file.devel_generate.inc
+++ b/devel_generate/file.devel_generate.inc
@@ -14,22 +14,31 @@ function _file_devel_generate($object, $field, $instance, $bundle) {
if (empty($file)) {
if ($path = devel_generate_textfile()) {
+ $source = new stdClass();
$source->uri = $path;
$source->uid = 1; // TODO: randomize? use case specific.
$source->filemime = 'text/plain';
$source->filename = array_pop(explode("//", $path));
- $destination = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'] . '/' . basename($path);
- $file = file_move($source, $destination);
+ $destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
+ file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
+ $destination = $destination_dir . '/' . basename($path);
+ $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
}
else {
return FALSE;
}
}
- $object_field['fid'] = $file->fid;
- $object_field['display'] = $field['settings']['display_default'];
- $object_field['description'] = devel_create_greeking(10);
+ if (!$file) {
+ // In case a previous file operation failed or no file is set, return FALSE
+ return FALSE;
+ }
+ else {
+ $object_field['fid'] = $file->fid;
+ $object_field['display'] = $field['settings']['display_default'];
+ $object_field['description'] = devel_create_greeking(10);
- return $object_field;
+ return $object_field;
+ }
}
/**