Skip to content

Commit

Permalink
XAPI: Fix import package when calculating enough space - refs BT#16742
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Nov 27, 2020
1 parent 1b55f42 commit 33167e7
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions plugin/xapi/src/Importer/AbstractImporter.php
Expand Up @@ -23,11 +23,15 @@ abstract class AbstractImporter
/**
* @var string
*/
protected $relCourseDir;
protected $courseDirectoryPath;
/**
* @var string
*/
protected $packageDir;
protected $toolDirectoryPath;
/**
* @var string
*/
protected $packageDirectoryPath;
/**
* @var \PclZip
*/
Expand All @@ -37,19 +41,20 @@ abstract class AbstractImporter
* AbstractImporter constructor.
*
* @param array $fileInfo
* @param string $directoryName
* @param string $toolDirectory
* @param \Chamilo\CoreBundle\Entity\Course $course
*/
protected function __construct(array $fileInfo, $directoryName, Course $course)
protected function __construct(array $fileInfo, $toolDirectory, Course $course)
{
$this->course = $course;
$this->relCourseDir = api_get_course_path($this->course->getCode()).'/'.$directoryName;
$this->zipFile = new PclZip($fileInfo['tmp_name']);

$filePathInfo = pathinfo($fileInfo['name']);
$fileBaseName = str_replace(".{$filePathInfo['extension']}", '', $filePathInfo['basename']);
$pathInfo = pathinfo($fileInfo['name']);

$this->courseDirectoryPath = api_get_path(SYS_COURSE_PATH).$this->course->getDirectory();
$this->toolDirectoryPath = $this->courseDirectoryPath.'/'.$toolDirectory;
$this->packageDirectoryPath = $this->toolDirectoryPath.'/'.api_replace_dangerous_char($pathInfo['filename']);

$this->packageDir = '/'.api_replace_dangerous_char($fileBaseName);
$this->zipFile = new PclZip($fileInfo['tmp_name']);
}

/**
Expand All @@ -67,23 +72,19 @@ public function import()
{
$this->validPackage();

$sysCourseDir = api_get_path(SYS_COURSE_PATH).$this->relCourseDir;

if (!$this->isEnoughSpace()) {
throw new Exception('Not enough space to storage package.');
}

$fullSysPackageDir = $sysCourseDir.$this->packageDir;

$fs = new Filesystem();
$fs->mkdir(
$fullSysPackageDir,
$this->packageDirectoryPath,
api_get_permissions_for_new_directories()
);

$this->zipFile->extract($fullSysPackageDir);
$this->zipFile->extract($this->packageDirectoryPath);

return "$fullSysPackageDir/tincan.xml";
return "{$this->packageDirectoryPath}/tincan.xml";
}

/**
Expand Down Expand Up @@ -118,9 +119,7 @@ function ($accumulator, $zipEntry) {

$courseSpaceQuota = DocumentManager::get_course_quota($this->course->getCode());

$sysCourseDir = api_get_path(SYS_COURSE_PATH).$this->relCourseDir;

if (!enough_size($zipRealSize, $sysCourseDir, $courseSpaceQuota)) {
if (!enough_size($zipRealSize, $this->courseDirectoryPath, $courseSpaceQuota)) {
return false;
}

Expand Down

0 comments on commit 33167e7

Please sign in to comment.