LPs: Fix scorm upload zip file saved in /var/upload/assets/scorm/ABC/

pull/3741/head
Julio Montoya 4 years ago
parent 55e34c5901
commit 166034e039
  1. 33
      public/main/lp/learnpath.class.php
  2. 3
      public/main/lp/lp_upload.php
  3. 4
      public/main/lp/scorm.class.php
  4. 12
      src/CoreBundle/Entity/Asset.php
  5. 39
      src/CoreBundle/EventListener/AssetListener.php
  6. 8
      src/CoreBundle/Resources/config/services.yml
  7. 2
      src/CourseBundle/Entity/CLp.php

@ -121,6 +121,7 @@ class learnpath
$debug = $this->debug;
$this->encoding = api_get_system_encoding();
$lp_id = (int) $entity->getIid();
$course_info = empty($course_info) ? api_get_course_info() : $course_info;
$course_id = (int) $course_info['real_id'];
$this->set_course_int_id($course_id);
if (empty($lp_id) || empty($course_id)) {
@ -372,7 +373,6 @@ class learnpath
error_log('End of learnpath constructor for learnpath '.$this->get_id());
}
}
}
/**
@ -946,7 +946,6 @@ class learnpath
return false;
}
$lp = Database::get_course_table(TABLE_LP_MAIN);
$lp_item = Database::get_course_table(TABLE_LP_ITEM);
$lp_view = Database::get_course_table(TABLE_LP_VIEW);
$lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
@ -967,7 +966,7 @@ class learnpath
WHERE c_id = $course_id AND lp_id = ".$this->lp_id;
Database::query($sql);
self::toggleVisibility($this->lp_id, 0);
//self::toggleVisibility($this->lp_id, 0);
/*if (2 == $this->type || 3 == $this->type) {
// This is a scorm learning path, delete the files as well.
@ -1008,14 +1007,13 @@ class learnpath
}
}*/
if (api_get_configuration_value('allow_lp_subscription_to_usergroups')) {
$table = Database::get_course_table(TABLE_LP_REL_USERGROUP);
$sql = "DELETE FROM $table
WHERE
lp_id = {$this->lp_id} AND
c_id = $course_id ";
Database::query($sql);
}
$table = Database::get_course_table(TABLE_LP_REL_USERGROUP);
$sql = "DELETE FROM $table
WHERE
lp_id = {$this->lp_id} AND
c_id = $course_id ";
Database::query($sql);
/*$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
$link = 'lp/lp_controller.php?action=view&lp_id='.$this->lp_id;
@ -1024,9 +1022,6 @@ class learnpath
WHERE c_id = $course_id AND (link LIKE '$link%' AND image='scormbuilder.gif')";
Database::query($sql);*/
/*$sql = "DELETE FROM $lp
WHERE iid = ".$this->lp_id;
Database::query($sql);*/
$repo = Container::getLpRepository();
$lp = $repo->find($this->lp_id);
Database::getManager()->remove($lp);
@ -1035,14 +1030,6 @@ class learnpath
// Updates the display order of all lps.
$this->update_display_order();
/*api_item_property_update(
api_get_course_info(),
TOOL_LEARNPATH,
$this->lp_id,
'delete',
api_get_user_id()
);*/
$link_info = GradebookUtils::isResourceInCourseGradebook(
api_get_course_id(),
4,
@ -1054,7 +1041,7 @@ class learnpath
GradebookUtils::remove_resource_from_course_gradebook($link_info['id']);
}
if ('true' == api_get_setting('search_enabled')) {
if ('true' === api_get_setting('search_enabled')) {
require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
}

@ -4,6 +4,7 @@
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
use Chamilo\CourseBundle\Entity\CLp;
/**
* Script managing the learnpath upload. To best treat the uploaded file, make sure we can identify it.
@ -79,7 +80,7 @@ if (isset($_POST) && $is_error) {
}
break;
case 'scorm':
$scorm = new scorm();
$scorm = new scorm(new CLp());
$scorm->import_package(
$_FILES['user_file'],
$current_dir,

@ -47,12 +47,12 @@ class scorm extends learnpath
* @param int Learnpath ID in DB
* @param int User ID
*/
public function __construct($courseCode = null, $resource_id = null, $user_id = null)
public function __construct($entity, $course_info = null, $user_id = null)
{
$this->items = [];
$this->subdir = '';
$this->manifestToString = '';
parent::__construct($courseCode, $resource_id, $user_id);
parent::__construct($entity, $course_info, $user_id);
}
/**

@ -45,7 +45,13 @@ class Asset
/**
* @var string
*
* @Assert\Choice({Asset::SCORM, Asset::WATERMARK, Asset::CSS}, message="Choose a valid category.")
* @Assert\Choice({
* Asset::SCORM,
* Asset::WATERMARK,
* Asset::CSS
* },
* message="Choose a valid category."
* )
*
* @ORM\Column(type="string", length=255)
*/
@ -339,12 +345,12 @@ class Asset
return $this;
}
public function getTitle(): string
public function getTitle()
{
return $this->title;
}
public function setTitle(string $title): Asset
public function setTitle($title): Asset
{
$this->title = $title;

@ -0,0 +1,39 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\EventListener;
use Chamilo\CoreBundle\Entity\Asset;
use Chamilo\CoreBundle\Repository\AssetRepository;
use Symfony\Component\HttpFoundation\Request;
use Vich\UploaderBundle\Event\Event;
class AssetListener
{
protected $assetRepository;
/**
* @var Request
*/
protected $request;
public function __construct(AssetRepository $assetRepository)
{
$this->assetRepository = $assetRepository;
}
public function onVichUploaderPostRemove(Event $event)
{
/** @var Asset $asset */
$asset = $event->getObject();
$mapping = $event->getMapping();
$folder = $mapping->getFile($asset)->getFilename();
// Deletes scorm folder: example: assets/scorm/myABC .
if (Asset::SCORM === $asset->getCategory() && !empty($folder)) {
$folder = Asset::SCORM.'/'.$folder;
$this->assetRepository->getFileSystem()->deleteDir($folder);
}
}
}

@ -90,6 +90,14 @@ services:
# tags:
# - {name: kernel.event_listener, event: kernel.controller, method: onCoreController}
Chamilo\CoreBundle\Repository\AssetRepository:
Chamilo\CoreBundle\EventListener\AssetListener:
arguments:
- '@Chamilo\CoreBundle\Repository\AssetRepository'
tags:
- {name: kernel.event_listener, event: vich_uploader.post_remove}
Chamilo\CoreBundle\Entity\Listener\ResourceListener:
tags:
- {name: doctrine.orm.entity_listener, entity_manager: default, lazy: true}

@ -287,7 +287,7 @@ class CLp extends AbstractResource implements ResourceInterface
/**
* @var Asset|null
*
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Asset")
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Asset", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="asset_id", referencedColumnName="id")
*/
protected $asset;

Loading…
Cancel
Save