From d6bdb64d3642a4fd5d0607911a0e8c26f4eff27c Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 17 Aug 2016 12:27:30 +0200 Subject: [PATCH 1/7] Check if tabke exists --- .../Schema/V110/Version20151101082300.php | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/Migrations/Schema/V110/Version20151101082300.php b/app/Migrations/Schema/V110/Version20151101082300.php index 476ad1edc4..de4d7c6cc7 100644 --- a/app/Migrations/Schema/V110/Version20151101082300.php +++ b/app/Migrations/Schema/V110/Version20151101082300.php @@ -27,25 +27,33 @@ class Version20151101082300 extends AbstractMigrationChamilo $accessUrlRelCourse->addForeignKeyConstraint('access_url', ['access_url_id'], ['id']); $accessUrlRelCourse->addForeignKeyConstraint('course', ['c_id'], ['id']); - $schema->renameTable('class', 'class_item'); + if ($schema->hasTable('class')) { + $schema->renameTable('class', 'class_item'); + } - $classUser = $schema->getTable('class_user'); - $classUser->getColumn('class_id')->setUnsigned(false); - $classUser->getColumn('user_id')->setUnsigned(false); + if ($schema->hasTable('class_user')) { + $classUser = $schema->getTable('class_user'); + $classUser->getColumn('class_id')->setUnsigned(false); + $classUser->getColumn('user_id')->setUnsigned(false); + } $course = $schema->getTable('course'); $course->getColumn('course_type_id')->setUnsigned(false); $course->addForeignKeyConstraint('room', ['room_id'], ['id']); - $courseRelClass = $schema->getTable('course_rel_class'); - $courseRelClass->getColumn('class_id')->setUnsigned(false)->setType(Type::getType(Type::INTEGER)); + if ($schema->hasTable('course_rel_class')) { + $courseRelClass = $schema->getTable('course_rel_class'); + $courseRelClass->getColumn('class_id')->setUnsigned(false)->setType(Type::getType(Type::INTEGER)); + } $courseRelUser = $schema->getTable('course_rel_user'); $courseRelUser->addForeignKeyConstraint('course', ['c_id'], ['id']); $courseRelUser->addForeignKeyConstraint('user', ['user_id'], ['id']); - $courseType = $schema->getTable('course_type'); - $courseType->getColumn('id')->setUnsigned(false); + if ($schema->hasTable('course_type')) { + $courseType = $schema->getTable('course_type'); + $courseType->getColumn('id')->setUnsigned(false); + } $schema->getTable('c_announcement')->addIndex(['c_id']); $schema->getTable('c_announcement_attachment')->addIndex(['c_id']); From 222be4037e6b2beff689800facd9234c9e9fa062 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 17 Aug 2016 12:50:26 +0200 Subject: [PATCH 2/7] Add 1.9.10.6 --- main/install/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/main/install/index.php b/main/install/index.php index 108a0d4e01..b6ada7473d 100755 --- a/main/install/index.php +++ b/main/install/index.php @@ -716,6 +716,7 @@ if (@$_POST['step2']) { case '1.9.10': case '1.9.10.2': case '1.9.10.4': + case '1.9.10.6': // Fix type "enum" before running the migration with Doctrine Database::query("ALTER TABLE course_category MODIFY COLUMN auth_course_child VARCHAR(40) DEFAULT 'TRUE'"); Database::query("ALTER TABLE course_category MODIFY COLUMN auth_cat_child VARCHAR(40) DEFAULT 'TRUE'"); From 5f4aa3e78202f57ec88ce1c9bfabcecc7787b8d8 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 17 Aug 2016 13:52:24 +0200 Subject: [PATCH 3/7] Remove FK that blocks bin/doctrine.php schema updates --- app/Migrations/Schema/V110/Version20151101082200.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Migrations/Schema/V110/Version20151101082200.php b/app/Migrations/Schema/V110/Version20151101082200.php index a140f6a97b..328fed355c 100644 --- a/app/Migrations/Schema/V110/Version20151101082200.php +++ b/app/Migrations/Schema/V110/Version20151101082200.php @@ -30,6 +30,16 @@ class Version20151101082200 extends AbstractMigrationChamilo $this->addSql("ALTER TABLE session MODIFY session_category_id INT NULL"); $this->addSql("UPDATE session SET session_category_id = NULL WHERE session_category_id NOT IN (SELECT id FROM session_category)"); + + $table = $schema->getTable('session_rel_course_rel_user'); + if ($table->hasForeignKey('FK_720167E91D79BD3')) { + $this->addSql("ALTER TABLE session_rel_course_rel_user DROP FOREIGN KEY FK_720167E91D79BD3"); + } + + $table = $schema->getTable('session_rel_course'); + if ($table->hasForeignKey('FK_12D110D391D79BD3')) { + $this->addSql("ALTER TABLE session_rel_course DROP FOREIGN KEY FK_12D110D391D79BD3"); + } } /** From a26f23bde1dc5b9839479422ba8acd09ffdcb7db Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 18 Aug 2016 08:44:11 +0200 Subject: [PATCH 4/7] Fix rename issue when uploading files using ajax. Undo change https://github.com/chamilo/chamilo-lms/commit/8f864966c9bc725047b09270e21db891399fb1ab --- main/inc/lib/document.lib.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 9b1e4c289f..5a15839f7f 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -2821,12 +2821,6 @@ class DocumentManager $upload_ok = process_uploaded_file($files[$fileKey], $show_output); if ($upload_ok) { - // File got on the server without problems, now process it - if ($title) { - $titleAndExt = explode('.', $files[$fileKey]['name']); - $ext = end($titleAndExt); - $files[$fileKey]['name'] = $title.'.'.$ext; - } $new_path = handle_uploaded_document( $course_info, $files[$fileKey], @@ -2873,6 +2867,10 @@ class DocumentManager } }*/ + if (!empty($title)) { + $params['title'] = $title; + } + if (!empty($comment)) { $params['comment'] = trim($comment); } From b270cac10e31e528e076fa280cf6667b75dd42de Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 18 Aug 2016 09:34:18 +0200 Subject: [PATCH 5/7] Minor - format code --- main/inc/lib/wami-recorder/record_document.php | 8 ++++---- src/Chamilo/CoreBundle/Component/Editor/Toolbar.php | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/main/inc/lib/wami-recorder/record_document.php b/main/inc/lib/wami-recorder/record_document.php index 23f54dc971..915ad5d390 100755 --- a/main/inc/lib/wami-recorder/record_document.php +++ b/main/inc/lib/wami-recorder/record_document.php @@ -56,16 +56,16 @@ if (!is_dir($saveDir)) { //avoid duplicates $waminame_to_save = $waminame; -$title_to_save = str_replace('_', ' ', $waminame); -$waminame_noex = basename($waminame, ".wav"); +$title_to_save = str_replace('_', ' ', $waminame); +$waminame_noex = basename($waminame, ".wav"); if (file_exists($saveDir.'/'.$waminame_noex.'.'.$ext)) { $i = 1; while (file_exists($saveDir.'/'.$waminame_noex.'_'.$i.'.'.$ext)) { $i++; } $waminame_to_save = $waminame_noex.'_'.$i.'.'.$ext; - $title_to_save = $waminame_noex.'_'.$i.'.'.$ext; - $title_to_save = str_replace('_', ' ', $title_to_save); + $title_to_save = $waminame_noex.'_'.$i.'.'.$ext; + $title_to_save = str_replace('_', ' ', $title_to_save); } $documentPath = $saveDir.'/'.$waminame_to_save; diff --git a/src/Chamilo/CoreBundle/Component/Editor/Toolbar.php b/src/Chamilo/CoreBundle/Component/Editor/Toolbar.php index 8e9407e631..c9b0956d4f 100644 --- a/src/Chamilo/CoreBundle/Component/Editor/Toolbar.php +++ b/src/Chamilo/CoreBundle/Component/Editor/Toolbar.php @@ -49,7 +49,8 @@ class Toolbar array_merge( $this->getDefaultPlugins(), $this->getPlugins(), - $this->getConditionalPlugins()) + $this->getConditionalPlugins() + ) ); return From c6c3215b10ac1609d44fc2a75f1a7c188211e68f Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 18 Aug 2016 10:27:55 +0200 Subject: [PATCH 6/7] Fix showing all documents in ckeditor "browser server" button see BT#11538 --- main/inc/lib/document.lib.php | 32 ++++- .../Component/Editor/Driver/CourseDriver.php | 129 ++++++++++++++++-- 2 files changed, 140 insertions(+), 21 deletions(-) diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 5a15839f7f..a36e922375 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -745,7 +745,8 @@ class DocumentManager public static function get_all_document_folders( $_course, $to_group_id = 0, - $can_see_invisible = false + $can_see_invisible = false, + $getInvisibleList = false ) { $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); @@ -776,7 +777,7 @@ class DocumentManager $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, false, 'docs.session_id'); $show_users_condition = ""; - if (api_get_setting('show_users_folders') == 'false') { + if (api_get_setting('show_users_folders') === 'false') { $show_users_condition = " AND docs.path NOT LIKE '%shared_folder%'"; } @@ -795,7 +796,7 @@ class DocumentManager $groupCondition AND docs.path NOT LIKE '%shared_folder%' AND docs.path NOT LIKE '%_DELETED_%' AND - last.visibility <> 2 + last.visibility <> 2 $condition_session "; } else { $sql = "SELECT DISTINCT docs.id, path @@ -808,10 +809,10 @@ class DocumentManager docs.c_id = {$_course['real_id']} ) WHERE - docs.filetype = 'folder' AND + docs.filetype = 'folder' AND docs.path NOT LIKE '%_DELETED_%' AND $groupCondition AND - last.visibility <> 2 + last.visibility <> 2 $show_users_condition $condition_session "; } $result = Database::query($sql); @@ -839,29 +840,44 @@ class DocumentManager return false; } } else { + // No invisible folders // Condition for the session $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, false, 'docs.session_id'); + + $visibilityCondition = 'last.visibility = 1'; + $fileType = "docs.filetype = 'folder' AND"; + if ($getInvisibleList) { + $visibilityCondition = 'last.visibility = 0'; + $fileType = ''; + } + //get visible folders $sql = "SELECT DISTINCT docs.id, path FROM $TABLE_ITEMPROPERTY AS last, $TABLE_DOCUMENT AS docs WHERE docs.id = last.ref AND - docs.filetype = 'folder' AND + $fileType last.tool = '" . TOOL_DOCUMENT . "' AND $groupCondition AND - last.visibility = 1 + $visibilityCondition $condition_session AND last.c_id = {$_course['real_id']} AND docs.c_id = {$_course['real_id']} "; $result = Database::query($sql); + $visibleFolders = array(); while ($row = Database::fetch_array($result, 'ASSOC')) { $visibleFolders[$row['id']] = $row['path']; } + if ($getInvisibleList) { + + return $visibleFolders; + } + // Condition for the session $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, false, 'docs.session_id'); @@ -900,6 +916,7 @@ class DocumentManager } } + //if both results are arrays -> //calculate the difference between the 2 arrays -> only visible folders are left :) if (is_array($visibleFolders) && is_array($invisibleFolders)) { $document_folders = array_diff($visibleFolders, $invisibleFolders); @@ -4507,6 +4524,7 @@ class DocumentManager file_exists($documentData['absolute_path']) ) { $mp3FilePath = self::convertWavToMp3($documentData['absolute_path']); + error_log($mp3FilePath); if (!empty($mp3FilePath) && file_exists($mp3FilePath)) { diff --git a/src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php b/src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php index 68983ff47a..87cca32c56 100644 --- a/src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php +++ b/src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php @@ -12,6 +12,8 @@ namespace Chamilo\CoreBundle\Component\Editor\Driver; class CourseDriver extends Driver implements DriverInterface { public $name = 'CourseDriver'; + public $visibleFiles = []; + private $coursePath; /** * Setups the folder @@ -21,15 +23,15 @@ class CourseDriver extends Driver implements DriverInterface $userId = api_get_user_id(); $userInfo = api_get_user_info(); $sessionId = api_get_session_id(); - $courseInfo = $this->connector->course; if (!empty($courseInfo)) { - $coursePath = api_get_path(SYS_COURSE_PATH); $courseDir = $courseInfo['directory'] . '/document'; $baseDir = $coursePath . $courseDir; + $this->coursePath = $baseDir; + // Creates shared folder if (!file_exists($baseDir . '/shared_folder')) { @@ -80,8 +82,9 @@ class CourseDriver extends Driver implements DriverInterface //$code = $this->connector->course->getCode(); $courseCode = $this->connector->course['code']; $alias = $courseCode.' '.get_lang('Documents'); + $userId = api_get_user_id(); - return array( + $config = array( 'driver' => 'CourseDriver', 'path' => $this->getCourseDocumentSysPath(), 'URL' => $this->getCourseDocumentRelativeWebPath(), @@ -95,9 +98,55 @@ class CourseDriver extends Driver implements DriverInterface 'write' => false, 'hidden' => true, 'locked' => false - ), + ) ) ); + + $folders = \DocumentManager::get_all_document_folders($this->connector->course, null, false, true); + if (!empty($folders)) { + foreach ($folders as $folder) { + //$folder = str_replace('-', "", $folder); + //\/ + $config['attributes'][] = [ + 'pattern' => '!'.$folder.'!', + 'read' => false, + 'write' => false, + 'hidden' => true, + 'locked' => false + ]; + } + } + + // Blocking all groups + + // hide all groups folders + $config['attributes'][] = [ + 'pattern' => '!_groupdocs_!', + 'read' => false, + 'write' => false, + 'hidden' => true, + 'locked' => false + ]; + + + // Allow only the groups I have access + $allGroups = \GroupManager::getAllGroupPerUserSubscription($userId); + if (!empty($allGroups)) { + foreach ($allGroups as $groupInfo) { + $groupId = $groupInfo['iid']; + if (\GroupManager::user_has_access($userId, $groupId, \GroupManager::GROUP_TOOL_DOCUMENTS)) { + $config['attributes'][] = [ + 'pattern' => '!'.$groupInfo['secret_directory'].'!', + 'read' => true, + 'write' => false, + 'hidden' => false, + 'locked' => false + ]; + } + } + } + + return $config; } return array(); @@ -165,13 +214,11 @@ class CourseDriver extends Driver implements DriverInterface { $this->setConnectorFromPlugin(); - if ($this->allow()) { + if ($this->allowToEdit()) { // upload file by elfinder. $result = parent::upload($fp, $dst, $name, $tmpname); - $name = $result['name']; - $filtered = \URLify::filter($result['name'], 80, '', true); if (strcmp($name, $filtered) != 0) { @@ -198,7 +245,6 @@ class CourseDriver extends Driver implements DriverInterface $result['name'] ); } - //error_log(print_r($this->error(),1)); return $result; } @@ -215,7 +261,7 @@ class CourseDriver extends Driver implements DriverInterface //parent::rm($hash); $this->setConnectorFromPlugin(); - if ($this->allow()) { + if ($this->allowToEdit()) { $path = $this->decode($hash); $stat = $this->stat($path); @@ -244,10 +290,65 @@ class CourseDriver extends Driver implements DriverInterface public function allow() { //if ($this->connector->security->isGranted('ROLE_ADMIN')) { - return - isset($this->connector->course) && - !empty($this->connector->course) && - !api_is_anonymous() - ; + + if (api_is_anonymous()) { + + return false; + } + + if (isset($this->connector->course) && !empty($this->connector->course)) { + + return true; + } + + return false; + } + + /** + * Allow to upload/delete folder or files + * + * @return bool + */ + public function allowToEdit() + { + $allow = $this->allow(); + + return $allow && api_is_allowed_to_edit(null, true); } + + /** + * @param string $attr + * @param string $path + * @param $data + * @param CourseDriver $volume + */ + /*public function access($attr, $path, $data, $volume) + { + if ($path == $this->coursePath) { + + return true; + } + + $allowToEdit = $this->allowToEdit(); + if ($allowToEdit) { + return true; + } + + $path = str_replace($this->coursePath, '', $path); + $documentId = \DocumentManager::get_document_id($this->connector->course, $path); + + if ($documentId) { + + $result = \DocumentManager::is_visible_by_id( + $documentId, + $this->connector->course, + api_get_session_id(), + api_get_user_id() + ); + return false; + } + + return false; + + }*/ } From 6be043f2b244929376ad5974de96dbe270133b66 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 18 Aug 2016 13:26:51 +0200 Subject: [PATCH 7/7] Fix mysql error when deleting a course when a document is added in a group See BT#11523 --- main/inc/lib/add_course.lib.inc.php | 3 +-- main/inc/lib/course.lib.php | 4 ++-- main/inc/lib/groupmanager.lib.php | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index d181352b61..7c5eae96b4 100755 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -195,14 +195,13 @@ class AddCourse public static function get_course_tables() { $tables = array(); - + $tables[] = 'item_property'; $tables[] = 'tool'; $tables[] = 'tool_intro'; $tables[] = 'group_info'; $tables[] = 'group_category'; $tables[] = 'group_rel_user'; $tables[] = 'group_rel_tutor'; - $tables[] = 'item_property'; $tables[] = 'userinfo_content'; $tables[] = 'userinfo_def'; $tables[] = 'course_description'; diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 92d7ba073e..4d9a3d4c29 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -2143,10 +2143,10 @@ class CourseManager } // Cleaning groups - $groups = GroupManager::get_groups(); + $groups = GroupManager::get_groups($courseId); if (!empty($groups)) { $groupList = array_column($groups, 'id'); - GroupManager::delete_groups($groupList); + GroupManager::delete_groups($groupList, $course['code']); } // Cleaning c_x tables diff --git a/main/inc/lib/groupmanager.lib.php b/main/inc/lib/groupmanager.lib.php index 4e6803c62d..9eb1e086a9 100755 --- a/main/inc/lib/groupmanager.lib.php +++ b/main/inc/lib/groupmanager.lib.php @@ -61,12 +61,12 @@ class GroupManager /** * @return array */ - public static function get_groups() + public static function get_groups($courseId = null) { $table_group = Database :: get_course_table(TABLE_GROUP); - $course_id = api_get_course_int_id(); + $courseId = !empty($courseId) ? (int) $courseId : api_get_course_int_id(); - $sql = "SELECT * FROM $table_group WHERE c_id = $course_id "; + $sql = "SELECT * FROM $table_group WHERE c_id = $courseId "; $result = Database::query($sql); return Database::store_result($result, 'ASSOC'); } @@ -773,7 +773,7 @@ class GroupManager while ($group = Database::fetch_object($res)) { $groups_to_delete[] = $group->id; } - self :: delete_groups($groups_to_delete); + self::delete_groups($groups_to_delete, $course_code); } $sql = "DELETE FROM $table_group_cat WHERE c_id = $course_id AND id='".$cat_id."'";