Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document: fix performance problem when downloading a folder - refs CB#320326 #4084

Merged
merged 3 commits into from
Apr 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions main/document/downloadfolder.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ function fixDocumentNameCallback($p_event, &$p_header)
$courseInfo['code']
);

$filesToZip = [];

// Admins are allowed to download invisible files
if (api_is_allowed_to_edit()) {
// Set the path that will be used in the query
Expand Down Expand Up @@ -180,14 +182,15 @@ function fixDocumentNameCallback($p_event, &$p_header)
}
}
}
$zip->add(
$sysCoursePath.$courseInfo['path'].'/document'.$not_deleted_file['path'],
PCLZIP_OPT_REMOVE_PATH,
$sysCoursePath.$courseInfo['path'].'/document'.$remove_dir,
PCLZIP_CB_PRE_ADD,
'fixDocumentNameCallback'
);
$filesToZip[] = $sysCoursePath.$courseInfo['path'].'/document'.$not_deleted_file['path'];
}
$zip->add(
$filesToZip,
PCLZIP_OPT_REMOVE_PATH,
$sysCoursePath.$courseInfo['path'].'/document'.$remove_dir,
PCLZIP_CB_PRE_ADD,
'fixDocumentNameCallback'
);

Session::erase('doc_files_to_download');
} else {
Expand Down Expand Up @@ -324,14 +327,15 @@ function fixDocumentNameCallback($p_event, &$p_header)

// Add all files in our final array to the zipfile
for ($i = 0; $i < count($files_for_zipfile); $i++) {
$zip->add(
$sysCoursePath.$courseInfo['path'].'/document'.$files_for_zipfile[$i],
PCLZIP_OPT_REMOVE_PATH,
$sysCoursePath.$courseInfo['path'].'/document'.$remove_dir,
PCLZIP_CB_PRE_ADD,
'fixDocumentNameCallback'
);
$filesToZip[] = $sysCoursePath.$courseInfo['path'].'/document'.$files_for_zipfile[$i];
}
$zip->add(
$filesToZip,
PCLZIP_OPT_REMOVE_PATH,
$sysCoursePath.$courseInfo['path'].'/document'.$remove_dir,
PCLZIP_CB_PRE_ADD,
'fixDocumentNameCallback'
);
Session::erase('doc_files_to_download');
}

Expand Down