summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgit2017-10-14 12:26:14 (GMT)
committerolstjos2017-10-14 12:26:14 (GMT)
commitcf6c8f15ae3d189291c71e0edb4c290ba3bcfd69 (patch)
tree29cb626f2075b8c713ef7133c346a5a825e25e59
parentb81337e0976218960fb6721b5891e7b512dbb0a8 (diff)
Issue #2916043 by lorisbel, joseph.olstad: Bulk upload files into a specific folder
-rw-r--r--media.module10
-rw-r--r--modules/media_bulk_upload/includes/media_bulk_upload.admin.inc16
2 files changed, 21 insertions, 5 deletions
diff --git a/media.module b/media.module
index 098e503..c17e861 100644
--- a/media.module
+++ b/media.module
@@ -607,7 +607,7 @@ function media_parse_to_uri($url) {
* @see media_parse_to_uri()
* @see media_add_from_url_submit()
*/
-function media_parse_to_file($url) {
+function media_parse_to_file($url, $params = array()) {
try {
$uri = media_parse_to_uri($url);
}
@@ -646,9 +646,15 @@ function media_parse_to_file($url) {
return;
}
$source_file = file_uri_to_object($source_uri);
- $scheme = variable_get('file_default_scheme', 'public') . '://';
+ if(isset($params['to_directory'])){
+ $scheme = variable_get('file_default_scheme', 'public') . '://' . $params['to_directory'] . '/';
+ }
+ else{
+ $scheme = variable_get('file_default_scheme', 'public') . '://';
+ }
$uri = file_stream_wrapper_uri_normalize($scheme . $source_file->filename);
// Now to its new home.
+ file_prepare_directory($scheme, FILE_CREATE_DIRECTORY || FILE_MODIFY_PERMISSIONS);
$file = file_move($source_file, $uri, FILE_EXISTS_RENAME);
}
diff --git a/modules/media_bulk_upload/includes/media_bulk_upload.admin.inc b/modules/media_bulk_upload/includes/media_bulk_upload.admin.inc
index bc0b77f..4fdd9ad 100644
--- a/modules/media_bulk_upload/includes/media_bulk_upload.admin.inc
+++ b/modules/media_bulk_upload/includes/media_bulk_upload.admin.inc
@@ -19,6 +19,13 @@ function media_bulk_upload_import($form, &$form_state) {
'#required' => TRUE,
);
+ $form['to_directory'] = array(
+ '#type' => 'textfield',
+ '#title' => t('To Directory'),
+ '#description' => t('Enter the subdirectory of /sites/default/files where files will be copied. If empty the default directory will be use.'),
+ '#required' => FALSE,
+ );
+
$form['pattern'] = array(
'#type' => 'textarea',
'#title' => t('Pattern'),
@@ -76,6 +83,7 @@ function media_bulk_upload_import_validate($form, &$form_state) {
form_set_error('pattern', t('No files were found in %directory matching the regular expression %pattern', array('%directory' => $directory, '%pattern' => $pattern_quoted)));
}
$form_state['storage']['files'] = $files;
+ $form_state['storage']['to_directory'] = $form_state['values']['to_directory'];
}
}
@@ -85,10 +93,12 @@ function media_bulk_upload_import_validate($form, &$form_state) {
function media_bulk_upload_import_submit($form, &$form_state) {
if ($form_state['values']['op'] == t('Confirm')) {
$files = $form_state['storage']['files'];
+ $params = array();
+ $params['to_directory'] = $form_state['storage']['to_directory'];
$batch = array(
'title' => t('Importing'),
'operations' => array(
- array('media_bulk_upload_import_batch_import_files', array($files)),
+ array('media_bulk_upload_import_batch_import_files', array($files, $params)),
),
'finished' => 'media_bulk_upload_import_batch_import_complete',
'file' => drupal_get_path('module', 'media_bulk_upload') . '/includes/media_bulk_upload.admin.inc',
@@ -103,7 +113,7 @@ function media_bulk_upload_import_submit($form, &$form_state) {
/**
* BatchAPI callback op for media import.
*/
-function media_bulk_upload_import_batch_import_files($files, &$context) {
+function media_bulk_upload_import_batch_import_files($files, $params, &$context) {
if (!isset($context['sandbox']['files'])) {
// This runs the first time the batch runs.
// This is stupid, but otherwise, I don't think it will work...
@@ -121,7 +131,7 @@ function media_bulk_upload_import_batch_import_files($files, &$context) {
foreach ($to_process as $file) {
try {
- $file_obj = media_parse_to_file($file);
+ $file_obj = media_parse_to_file($file, $params);
$context['results']['success'][] = $file;
if (!$image_in_message) {
// @todo Is this load step really necessary? When there's time, test