Fix folder creation using elfinder/ckeditor see #2231

pull/2487/head
jmontoyaa 7 years ago
parent a54faeb526
commit 4673586d6b
  1. 13
      src/Chamilo/CoreBundle/Component/Editor/Connector.php
  2. 23
      src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php

@ -275,15 +275,15 @@ class Connector
public function getOperations()
{
//https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options-2.1
$opts = array(
$opts = [
//'debug' => true,
'bind' => array(
'upload rm' => array($this, 'manageCommands')
)
);
'bind' => [
'upload rm mkdir' => array($this, 'manageCommands')
],
'sessionCloseEarlier' => false
];
$this->setDrivers();
$opts['roots'] = $this->getRoots();
return $opts;
@ -340,6 +340,7 @@ class Connector
public function manageCommands($cmd, $result, $args, $elFinder)
{
$cmd = ucfirst($cmd);
$cmd = 'after'.$cmd;
/*
if (isset($args['target'])) {

@ -166,7 +166,7 @@ class CourseDriver extends Driver implements DriverInterface
return $config;
}
return array();
return [];
}
/**
@ -229,6 +229,7 @@ class CourseDriver extends Driver implements DriverInterface
*/
public function upload($fp, $dst, $name, $tmpname, $hashes = array())
{
// Needed to load course information in elfinder
$this->setConnectorFromPlugin();
if ($this->allowToEdit()) {
@ -331,23 +332,25 @@ class CourseDriver extends Driver implements DriverInterface
/**
* @inheritdoc
*/
protected function _mkdir($path, $name)
public function mkdir($path, $name)
{
// Needed to load course information in elfinder
$this->setConnectorFromPlugin();
if ($this->allowToEdit() == false) {
return false;
}
$path = $this->_joinPath($path, $name);
$result = parent::mkdir($path, $name);
if (mkdir($path)) {
$this->setConnectorFromPlugin();
chmod($path, $this->options['dirMode']);
clearstatcache();
if ($result && isset($result['hash'])) {
$_course = $this->connector->course;
$realPathRoot = $this->getCourseDocumentSysPath();
$realPath = $this->realpath($result['hash']);
// Removing course path
$newPath = str_replace($realPathRoot, '/', $path);
$newPath = str_replace($realPathRoot, '/', $realPath);
$documentId = add_document(
$_course,
$newPath,
@ -363,12 +366,12 @@ class CourseDriver extends Driver implements DriverInterface
);
if (empty($documentId)) {
unlink($path);
$this->rm($result['hash']);
return false;
}
return $path;
return $result;
}
return false;

Loading…
Cancel
Save