Skip to content

Commit

Permalink
MDL-32639 files: Removing '0' start folder in archives created with f…
Browse files Browse the repository at this point in the history
…ilemanager
  • Loading branch information
vadimonus authored and Frederic Massart committed Dec 10, 2012
1 parent 4bd6f71 commit 697ade2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
10 changes: 6 additions & 4 deletions lib/filestorage/zip_archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,20 @@ public function add_directory($localname) {
if (!isset($this->za)) {
return false;
}
$localname = ltrim($localname, '/'). '/';
$localname = trim($localname, '/'). '/';
$localname = $this->mangle_pathname($localname);

if ($localname === '/') {
//sorry - conversion failed badly
return false;
}

if (!$this->za->addEmptyDir($localname)) {
return false;
if ($localname !== '') {
if (!$this->za->addEmptyDir($localname)) {
return false;
}
$this->modified = true;
}
$this->modified = true;
return true;
}

Expand Down
7 changes: 5 additions & 2 deletions repository/draftfiles_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@
$file = $fs->get_file($user_context->id, 'user', 'draft', $draftid, $filepath, '.');

$parent_path = $file->get_parent_directory()->get_filepath();

$filepath = explode('/', trim($file->get_filepath(), '/'));
$filepath = array_pop($filepath);

if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $draftid, $parent_path, $filepath.'.zip', $USER->id)) {
if ($newfile = $zipper->archive_to_storage(array($filepath => $file), $user_context->id, 'user', 'draft', $draftid, $parent_path, $filepath.'.zip', $USER->id)) {
$return = new stdClass();
$return->filepath = $parent_path;
echo json_encode($return);
Expand Down Expand Up @@ -251,7 +254,7 @@

// archive compressed file to an unused draft area
$newdraftitemid = file_get_unused_draft_itemid();
if ($newfile = $zipper->archive_to_storage(array($stored_file), $user_context->id, 'user', 'draft', $newdraftitemid, '/', $filename, $USER->id)) {
if ($newfile = $zipper->archive_to_storage(array('/' => $stored_file), $user_context->id, 'user', 'draft', $newdraftitemid, '/', $filename, $USER->id)) {
$return = new stdClass();
$return->fileurl = moodle_url::make_draftfile_url($newdraftitemid, '/', $filename)->out();
$return->filepath = $parent_path;
Expand Down
8 changes: 5 additions & 3 deletions repository/draftfiles_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
$filename = get_string('files').'.zip';
}

if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id)) {
if ($newfile = $zipper->archive_to_storage(array('/' => $file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id)) {
$fileurl = moodle_url::make_draftfile_url($itemid, '/', $filename)->out();
header('Location: ' . $fileurl );
} else {
Expand All @@ -161,14 +161,16 @@
$file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
if (!$file->get_parent_directory()) {
$parent_path = '/';
$filepath = '/';
$filename = get_string('files').'.zip';
} else {
$parent_path = $file->get_parent_directory()->get_filepath();
$filepath = explode('/', trim($file->get_filepath(), '/'));
$filename = array_pop($filepath).'.zip';
$filepath = array_pop($filepath);
$filename = $filepath.'.zip';
}

$newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id);
$newfile = $zipper->archive_to_storage(array($filepath => $file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id);

$home_url->param('action', 'browse');
$home_url->param('draftpath', $parent_path);
Expand Down

0 comments on commit 697ade2

Please sign in to comment.