Skip to content
Snippets Groups Projects
Commit d9c0cc41 authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

manage single zipped file. #14

parent d2c55fd2
Branches
Tags
No related merge requests found
...@@ -99,7 +99,8 @@ class XML2HTMLPlugin extends GenericPlugin ...@@ -99,7 +99,8 @@ class XML2HTMLPlugin extends GenericPlugin
* @param $zipPath * @param $zipPath
* @return string * @return string
*/ */
private static function getHTMLPathFromZipPath($zipPath){ private static function getHTMLPathFromZipPath($zipPath)
{
$fileMgr = new PrivateFileManager(); $fileMgr = new PrivateFileManager();
$filesDir = $fileMgr->getBasePath() . DIRECTORY_SEPARATOR; $filesDir = $fileMgr->getBasePath() . DIRECTORY_SEPARATOR;
$fullZipPath = $filesDir . $zipPath; $fullZipPath = $filesDir . $zipPath;
...@@ -137,7 +138,8 @@ class XML2HTMLPlugin extends GenericPlugin ...@@ -137,7 +138,8 @@ class XML2HTMLPlugin extends GenericPlugin
* @param $verb * @param $verb
* @return mixed * @return mixed
*/ */
public function getActions($request, $verb) { public function getActions($request, $verb)
{
$router = $request->getRouter(); $router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal'); import('lib.pkp.classes.linkAction.request.AjaxModal');
return array_merge( return array_merge(
...@@ -191,7 +193,8 @@ class XML2HTMLPlugin extends GenericPlugin ...@@ -191,7 +193,8 @@ class XML2HTMLPlugin extends GenericPlugin
} }
function getPluginAssetsPath($request) { function getPluginAssetsPath($request)
{
return $request->getBaseUrl() . '/' . $this->getPluginPath() . '/resources/'; return $request->getBaseUrl() . '/' . $this->getPluginPath() . '/resources/';
} }
...@@ -222,6 +225,11 @@ class XML2HTMLPlugin extends GenericPlugin ...@@ -222,6 +225,11 @@ class XML2HTMLPlugin extends GenericPlugin
} }
/**
* @param string $path
* @return string|void|null
* @throws Exception
*/
static function unzipXMLArchive(string $path) static function unzipXMLArchive(string $path)
{ {
$fileManager = new FileManager(); $fileManager = new FileManager();
...@@ -238,12 +246,20 @@ class XML2HTMLPlugin extends GenericPlugin ...@@ -238,12 +246,20 @@ class XML2HTMLPlugin extends GenericPlugin
} }
if ($zip->open($zipPath) === TRUE) { if ($zip->open($zipPath) === TRUE) {
$archiveFolderName = NULL; $nbFiles = $zip->numFiles;
if ($zip->numFiles > 0) {//gets zip top folder name if ($nbFiles > 0) {
$archiveFolderName = $zip->getNameIndex(0); //a zipped file
} else { if ($nbFiles == 1 && str_ends_with($zip->getNameIndex(0), '.xml')) {
throw new \Exception("Bad zip Submission file."); $basePath = $zipPathParts['dirname'] . DIRECTORY_SEPARATOR . $zipPathParts['filename'] . '/';
} $zip->extractTo($basePath);
rename(
$basePath . $zip->getNameIndex(0),
$basePath . $zipPathParts['filename'] . '.xml'
);
return $basePath . $zipPathParts['filename'] . '.xml';
} //a zipped folder
else if (str_ends_with($zip->getNameIndex(0), '/')) {
$archiveFolderName = $zip->getNameIndex(0); //gets root folder name
$zip->extractTo($zipPathParts['dirname']); $zip->extractTo($zipPathParts['dirname']);
rename( rename(
$zipPathParts['dirname'] . DIRECTORY_SEPARATOR . $archiveFolderName, $zipPathParts['dirname'] . DIRECTORY_SEPARATOR . $archiveFolderName,
...@@ -263,6 +279,14 @@ class XML2HTMLPlugin extends GenericPlugin ...@@ -263,6 +279,14 @@ class XML2HTMLPlugin extends GenericPlugin
} }
} }
} else {
throw new \Exception("Bad zip Submission file.");
}
} else {
throw new \Exception("Bad zip Submission file.");
}
} else { } else {
return NULL; return NULL;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment