From 33167e7257551c63577a267cabe17e69ce9b023b Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 2 Nov 2020 16:21:49 -0500 Subject: [PATCH] XAPI: Fix import package when calculating enough space - refs BT#16742 --- plugin/xapi/src/Importer/AbstractImporter.php | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/plugin/xapi/src/Importer/AbstractImporter.php b/plugin/xapi/src/Importer/AbstractImporter.php index 3bb8d969cb5..21678faa68a 100644 --- a/plugin/xapi/src/Importer/AbstractImporter.php +++ b/plugin/xapi/src/Importer/AbstractImporter.php @@ -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 */ @@ -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']); } /** @@ -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"; } /** @@ -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; }