/**
* Action to generate the according folder and file structure from an uploaded zip file.
*
* @return multitype:multitype:
*/
public function actionUploadArchive()
{
if (Setting::Get('disableZipSupport', 'cfiles')) {
throw new HttpException(404, Yii::t('CfilesModule.base', 'Archive (zip) support is not enabled.'));
}
// cleanup all old files
$this->cleanup();
Yii::$app->response->format = 'json';
$response = [];
foreach (UploadedFile::getInstancesByName('files') as $cFile) {
if (strtolower($cFile->extension) === 'zip') {
$sourcePath = $this->getZipOutputPath() . DIRECTORY_SEPARATOR . 'zipped.zip';
$extractionPath = $this->getZipOutputPath() . DIRECTORY_SEPARATOR . 'extracted';
if ($cFile->saveAs($sourcePath, false)) {
$this->unpackArchive($response, $sourcePath, $extractionPath);
$this->generateModelsFromFilesystem($response, $this->getCurrentFolder()->id, $extractionPath);
} else {
$response['errormessages'][] = Yii::t('CfilesModule.base', 'Archive %filename% could not be extracted.', ['%filename%' => $cFile->name]);
}
} else {
$response['errormessages'][] = Yii::t('CfilesModule.base', '%filename% has invalid extension and was skipped.', ['%filename%' => $cFile->name]);
}
}
$response['files'] = $this->files;
return $response;
}