diff options
author | Andrew Manning <tamanning@zoho.com> | 2016-08-23 06:55:26 -0400 |
---|---|---|
committer | Andrew Manning <tamanning@zoho.com> | 2016-08-23 06:55:26 -0400 |
commit | 305e0538d293ff4ad72f30b11998ae3b06efa4ea (patch) | |
tree | 4bf1f79ba123758f34320019e445268318e1e734 /include | |
parent | d39cf23b2f15ed94048ea7596d7581be7ef8c001 (diff) | |
download | volse-hubzilla-305e0538d293ff4ad72f30b11998ae3b06efa4ea.tar.gz volse-hubzilla-305e0538d293ff4ad72f30b11998ae3b06efa4ea.tar.bz2 volse-hubzilla-305e0538d293ff4ad72f30b11998ae3b06efa4ea.zip |
Website export to cloud files works. Created new recursive copy function in attach.php.
Diffstat (limited to 'include')
-rw-r--r-- | include/attach.php | 47 | ||||
-rw-r--r-- | include/text.php | 4 |
2 files changed, 51 insertions, 0 deletions
diff --git a/include/attach.php b/include/attach.php index 172840b96..6b17cdca1 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1994,3 +1994,50 @@ function get_filename_by_cloudname($cloudname, $channel, $storepath) { } return null; } + + +// recursively copy a directory into cloud files +function copy_folder_to_cloudfiles($channel, $observer_hash, $srcpath, $cloudpath) +{ + if (!is_dir($srcpath) || !is_readable($srcpath)) { + logger('Error reading source path: ' . $srcpath, LOGGER_NORMAL); + return false; + } + $nodes = array_diff(scandir($srcpath), array('.', '..')); + foreach ($nodes as $node) { + $clouddir = $cloudpath . '/' . $node; // Sub-folder in cloud files destination + $nodepath = $srcpath . '/' . $node; // Sub-folder in source path + if(is_dir($nodepath)) { + $x = attach_mkdirp($channel, $observer_hash, array('pathname' => $clouddir)); + if(!$x['success']) { + logger('Error creating cloud path: ' . $clouddir, LOGGER_NORMAL); + return false; + } + // Recursively call this function where the source and destination are the subfolders + $success = copy_folder_to_cloudfiles($channel, $observer_hash, $nodepath, $clouddir); + if(!$success) { + logger('Error copying contents of folder: ' . $nodepath, LOGGER_NORMAL); + return false; + } + } elseif (is_file($nodepath) && is_readable($nodepath)) { + $x = attach_store($channel, $observer_hash, 'import', + array( + 'directory' => $cloudpath, + 'src' => $nodepath, + 'filename' => $node, + 'filesize' => @filesize($nodepath), + 'preserve_original' => true) + ); + if(!$x['success']) { + logger('Error copying file: ' . $nodepath , LOGGER_NORMAL); + logger('Return value: ' . json_encode($x), LOGGER_NORMAL); + return false; + } + } else { + logger('Error scanning source path', LOGGER_NORMAL); + return false; + } + } + + return true; +}
\ No newline at end of file diff --git a/include/text.php b/include/text.php index 1729048e9..99ac59ca7 100644 --- a/include/text.php +++ b/include/text.php @@ -2295,6 +2295,10 @@ function website_portation_tools() { '$file_download_text' => t('Export to a zip file'), '$filename_desc' => t('website.zip'), '$filename_hint' => t('Enter a name for the zip file.'), + '$cloud_export_text' => t('Export to cloud files'), + '$cloud_export_desc' => t('/path/to/export/folder'), + '$cloud_export_hint' => t('Enter a path to a cloud files destination.'), + '$cloud_export_select' => t('Specify folder'), )); } |