parent
87217f8f46
commit
b484376f00
@ -0,0 +1,50 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Loader; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Traits\FileFinderTrait; |
||||
use Symfony\Component\Filesystem\Filesystem; |
||||
|
||||
/** |
||||
* Class FilesForScormScoLoader. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Loader |
||||
*/ |
||||
class FilesForScormScoLoader extends CourseFilesLoader |
||||
{ |
||||
use FileFinderTrait; |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function load(array $incomingData) |
||||
{ |
||||
$course = api_get_course_entity($incomingData['c_id']); |
||||
|
||||
try { |
||||
$moodleFilePath = $this->findFilePath($incomingData['contenthash']); |
||||
} catch (\Exception $exception) { |
||||
return 0; |
||||
} |
||||
|
||||
$sysCourseScormPath = api_get_path(SYS_COURSE_PATH).$course->getDirectory().'/scorm'; |
||||
$lpDirectory = CourseModulesScormLoader::generateDirectoryName($incomingData['lp_name']); |
||||
$lpDirectoryPath = "$sysCourseScormPath/$lpDirectory"; |
||||
$fileDirectoryPath = $lpDirectoryPath.$incomingData['filepath']; |
||||
$filePath = $fileDirectoryPath.$incomingData['filename']; |
||||
|
||||
$fileSystem = new Filesystem(); |
||||
|
||||
if ($incomingData['filepath'] != '/') { |
||||
$fileSystem->mkdir( |
||||
$fileDirectoryPath, |
||||
api_get_permissions_for_new_directories() |
||||
); |
||||
} |
||||
|
||||
$fileSystem->copy($moodleFilePath, $filePath); |
||||
|
||||
return 0; |
||||
} |
||||
} |
||||
@ -0,0 +1,82 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Task; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Extractor\CourseExtractor; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Loader\FilesForScormScoLoader; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\BaseTransformer; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseLookup; |
||||
|
||||
/** |
||||
* Class FilesForScormScoesTask. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Task |
||||
*/ |
||||
class FilesForScormScoesTask extends BaseTask |
||||
{ |
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function getExtractConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => CourseExtractor::class, |
||||
'query' => "SELECT |
||||
f.id, |
||||
f.contenthash, |
||||
f.filepath, |
||||
f.filename, |
||||
f.mimetype, |
||||
s.name scorm_name, |
||||
cm.course |
||||
FROM mdl_files f |
||||
INNER JOIN mdl_context ctx ON f.contextid = ctx.id |
||||
INNER JOIN mdl_course_modules cm ON ctx.instanceid = cm.id |
||||
INNER JOIN mdl_modules m ON cm.module = m.id |
||||
INNER JOIN mdl_scorm s ON (cm.course = s.course AND cm.instance = s.id) |
||||
WHERE |
||||
m.name = 'scorm' |
||||
AND ctx.contextlevel = 70 |
||||
AND f.filename NOT IN ('.', '..') |
||||
AND s.reference != f.filename |
||||
AND f.filearea = 'content' |
||||
AND f.component = 'mod_scorm' |
||||
ORDER BY s.course, s.id", |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
/** |
||||
* @return array |
||||
*/ |
||||
public function getTransformConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => BaseTransformer::class, |
||||
'map' => [ |
||||
'contenthash' => 'contenthash', |
||||
'filepath' => 'filepath', |
||||
'filename' => 'filename', |
||||
'mimetype' => 'mimetype', |
||||
'c_id' => [ |
||||
'class' => LoadedCourseLookup::class, |
||||
'properties' => ['course'], |
||||
], |
||||
'lp_name' => 'scorm_name', |
||||
], |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function getLoadConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => FilesForScormScoLoader::class, |
||||
]; |
||||
} |
||||
} |
||||
@ -0,0 +1,36 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Traits; |
||||
|
||||
/** |
||||
* Class FileFinderTrait. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Traits\MapTrait |
||||
*/ |
||||
trait FileFinderTrait |
||||
{ |
||||
/** |
||||
* @param $contentHash |
||||
* |
||||
* @throws \Exception |
||||
* |
||||
* @return string |
||||
*/ |
||||
protected function findFilePath($contentHash) |
||||
{ |
||||
$d1 = substr($contentHash, 0, 2); |
||||
$d2 = substr($contentHash, 2, 2); |
||||
|
||||
$moodleDataPath = '/var/www/moodle/moodledata'; |
||||
$moodleDataPath = rtrim($moodleDataPath, ' /'); |
||||
|
||||
$filePath = "$moodleDataPath/filedir/$d1/$d2/$contentHash"; |
||||
|
||||
if (!file_exists($filePath)) { |
||||
throw new \Exception("File $contentHash not found in $moodleDataPath/filedir"); |
||||
} |
||||
|
||||
return $filePath; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue