Browse Source

Merge branch 'chamilo10'

Julio Montoya 11 years ago
parent
commit
c3a7b1ac6a
28 changed files with 1042 additions and 738 deletions
  1. 1 2
      main/inc/services.php
  2. 13 9
      main/work/add_document.php
  3. 1 4
      main/work/add_user.php
  4. 17 13
      main/work/download.php
  5. 23 15
      main/work/edit.php
  6. 9 14
      main/work/student_work.php
  7. 1 2
      main/work/upload.php
  8. 14 6
      main/work/view.php
  9. 174 54
      main/work/work.lib.php
  10. 3 28
      main/work/work.php
  11. 3 18
      main/work/work_list.php
  12. 3 1
      main/work/work_list_all.php
  13. 8 21
      main/work/work_list_others.php
  14. 13 23
      vendor/chamilo/chash/src/Chash/Command/Files/SetPermissionsAfterInstallCommand.php
  15. 48 35
      vendor/chamilo/chash/src/Chash/Command/Installation/CommonCommand.php
  16. 70 43
      vendor/chamilo/chash/src/Chash/Command/Installation/UpgradeCommand.php
  17. 32 3
      vendor/chamilo/chash/src/Chash/Helpers/ConfigurationHelper.php
  18. 251 0
      vendor/chamilo/chash/src/Chash/Migrations/Version10.php
  19. 6 0
      vendor/chamilo/chash/src/Chash/Migrations/Version11.php
  20. 9 61
      vendor/chamilo/chash/src/Chash/Resources/Database/1.10.0/db_main.sql
  21. 15 11
      vendor/chamilo/chash/src/Chash/Resources/Database/1.10.0/migrate-db-1.9.0-1.10.0-post.sql
  22. 61 278
      vendor/chamilo/chash/src/Chash/Resources/Database/1.10.0/migrate-db-1.9.0-1.10.0-pre.sql
  23. 49 21
      vendor/chamilo/chash/src/Chash/Resources/Database/1.10.0/update-db-1.9.0-1.10.0.inc.php
  24. 143 28
      vendor/chamilo/chash/src/Chash/Resources/Database/1.8.8/migrate-db-1.8.7-1.8.8-pre.sql
  25. 8 8
      vendor/chamilo/chash/src/Chash/Resources/Database/1.8.8/update-db-1.8.7-1.8.8.inc.php
  26. 54 26
      vendor/chamilo/chash/src/Chash/Resources/Database/1.9.0/migrate-db-1.8.8-1.9.0-pre.sql
  27. 11 11
      vendor/chamilo/chash/src/Chash/Resources/Database/1.9.0/update-db-1.8.8-1.9.0.inc.php
  28. 2 3
      vendor/chamilo/chash/src/Chash/Resources/Database/1.9.0/update-files-1.8.8-1.9.0.inc.php

+ 1 - 2
main/inc/services.php

@@ -65,8 +65,7 @@ $app->register(new \Silex\Provider\SecurityServiceProvider, array(
     'security.firewalls' => array(
         'login' => array(
             'pattern' => '^/login$',
-            'anonymous' => true,
-            'security' => false
+            'anonymous' => true
         ),
         'secured' => array(
             'pattern' => '^/.*$',

+ 13 - 9
main/work/add_document.php

@@ -53,13 +53,12 @@ switch ($action) {
         break;
 }
 
-Display :: display_header(null);
-
 if (empty($docId)) {
-    echo Display::page_subheader(get_lang('DocumentsAdded'));
 
+    Display :: display_header(null);
     $documents = getAllDocumentToWork($workId, api_get_course_int_id());
     if (!empty($documents)) {
+        echo Display::page_subheader(get_lang('DocumentsAdded'));
         echo '<div class="well">';
         foreach ($documents as $doc) {
             $documentId = $doc['document_id'];
@@ -75,11 +74,11 @@ if (empty($docId)) {
     }
 
     $document_tree = DocumentManager::get_document_preview($courseInfo, null, null, 0, false, '/', api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId);
-    echo Display::page_subheader(get_lang('DocumentToAdd'));
+    echo Display::page_subheader(get_lang('Documents'));
     echo $document_tree;
     echo '<hr /><div class="clear"></div>';
-
 } else {
+    $message = null;
 
     $documentInfo = DocumentManager::get_document_data_by_id($docId, $courseInfo['code']);
     $form = new FormValidator('add_doc', 'post', api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&document_id='.$docId);
@@ -89,8 +88,6 @@ if (empty($docId)) {
     $form->addElement('hidden', 'document_id', $docId);
     $form->addElement('label', get_lang('File'), $documentInfo['title']);
     $form->addElement('style_submit_button', 'submit', get_lang('Add'));
-    $form->display();
-
     if ($form->validate()) {
         $values = $form->exportValues();
         $workId = $values['id'];
@@ -99,14 +96,21 @@ if (empty($docId)) {
 
         if (empty($data)) {
             addDocumentToWork($docId, $workId, api_get_course_int_id());
-            Display::display_confirmation_message(get_lang('Added'));
+            $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId;
+            header('Location: '.$url);
+            exit;
         } else {
-            Display::display_warning_message(get_lang('DocumentAlreadyAdded'));
+            $message = Display::return_message(get_lang('DocumentAlreadyAdded'), 'warning');
         }
     }
+
+    Display :: display_header(null);
+    echo $message;
+    $form->display();
 }
 
 /*
+ * DB changes needed
  *
 CREATE TABLE IF NOT EXISTS c_student_publication_rel_document (
     id  INT PRIMARY KEY NOT NULL AUTO_INCREMENT,

+ 1 - 4
main/work/add_user.php

@@ -44,7 +44,6 @@ $error_message = null;
 
 switch ($action) {
     case 'add':
-
         $data = getUserToWork($userId, $workId, api_get_course_int_id());
         if (empty($data)) {
             addUserToWork($userId, $workId, api_get_course_int_id());
@@ -52,7 +51,6 @@ switch ($action) {
         $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?id='.$workId;
         header('Location: '.$url);
         exit;
-
         break;
     case 'delete':
         if (!empty($workId) && !empty($userId)) {
@@ -66,11 +64,10 @@ switch ($action) {
 
 Display :: display_header(null);
 
-echo Display::page_subheader(get_lang('UsersAdded'));
-
 $items = getAllUserToWork($workId, api_get_course_int_id());
 $usersAdded = array();
 if (!empty($items)) {
+    echo Display::page_subheader(get_lang('UsersAdded'));
     echo '<div class="well">';
     foreach ($items as $data) {
         $myUserId = $data['user_id'];

+ 17 - 13
main/work/download.php

@@ -37,8 +37,8 @@ if (empty($course_info)) {
 $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
 
 if (!empty($course_info['real_id'])) {
-	$sql = 'SELECT * FROM '.$tbl_student_publication.' WHERE c_id = '.$course_info['real_id'].' AND id = "'.$id.'"';
-	$result = Database::query($sql);
+    $sql = 'SELECT * FROM '.$tbl_student_publication.' WHERE c_id = '.$course_info['real_id'].' AND id = "'.$id.'"';
+    $result = Database::query($sql);
     if ($result && Database::num_rows($result)) {
         $row = Database::fetch_array($result, 'ASSOC');
         $full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.$row['url'];
@@ -76,20 +76,24 @@ if (!empty($course_info['real_id'])) {
 
         $work_is_visible = ($item_info['visibility'] == 1 && $row['accepted'] == 1);
         $doc_visible_for_all = ($course_info['show_score'] == 1);
-        $is_editor = api_is_allowed_to_edit(true,true,true);
-        $student_is_owner_of_work = ($row['user_id'] == api_get_user_id());
 
-	    if ($is_editor
-	        || (!$doc_visible_for_all && $work_is_visible && $student_is_owner_of_work)
-	        || ($doc_visible_for_all && $work_is_visible)) {
-		    $title = str_replace(' ', '_', $row['title']);
+        $is_editor = api_is_allowed_to_edit(true, true, true);
+        $student_is_owner_of_work = user_is_author($row['id'], $row['user_id']);
+
+        if ($is_editor
+            //|| (!$doc_visible_for_all && $work_is_visible && $student_is_owner_of_work)
+            || ($student_is_owner_of_work)
+            || ($doc_visible_for_all && $work_is_visible)) {
+            $title = str_replace(' ', '_', $row['title']);
             event_download($title);
-		    if (Security::check_abs_path($full_file_name, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/')) {
-		        DocumentManager::file_send_for_download($full_file_name, true, $title);
-		    }
-	    } else {
+            if (Security::check_abs_path($full_file_name, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/')) {
+                DocumentManager::file_send_for_download($full_file_name, true, $title);
+            }
+        } else {
             api_not_allowed();
         }
-	}
+    }
+} else {
+    api_not_allowed();
 }
 exit;

+ 23 - 15
main/work/edit.php

@@ -66,16 +66,18 @@ if (!$is_author) {
     api_not_allowed(true);
 }
 
-// Student's can't edit work
+// Student's can't edit work only if he can delete his docs.
 if (!api_is_allowed_to_edit()) {
-    api_not_allowed(true);
+    if (api_get_course_setting('student_delete_own_publication') != 1) {
+        api_not_allowed(true);
+    }
 }
 
 if (!empty($my_folder_data)) {
     $homework = get_work_assignment_by_id($my_folder_data['id']);
 
     if ($homework['expires_on'] != '0000-00-00 00:00:00' || $homework['ends_on'] != '0000-00-00 00:00:00') {
-        $time_now		= time();
+        $time_now = time();
 
         if (!empty($homework['expires_on']) && $homework['expires_on'] != '0000-00-00 00:00:00') {
             $time_expires 	= api_strtotime($homework['expires_on'], 'UTC');
@@ -110,13 +112,19 @@ $form_title = get_lang('Edit');
 
 $interbreadcrumb[] = array('url' => '#', 'name'  => $form_title);
 
-$form = new FormValidator('form', 'POST', api_get_self()."?".api_get_cidreq()."&id=".$work_id."&gradebook=".Security::remove_XSS($_GET['gradebook'])."&origin=$origin", '', array('enctype' => "multipart/form-data"));
+$form = new FormValidator(
+    'form',
+    'POST',
+    api_get_self()."?".api_get_cidreq()."&id=".$work_id."&gradebook=".Security::remove_XSS($_GET['gradebook'])."&origin=$origin",
+    '',
+    array('enctype' => "multipart/form-data")
+);
 $form->addElement('header', $form_title);
 
 $show_progress_bar = false;
 
 if ($submitGroupWorkUrl) {
-    // For user comming from group space to publish his work
+    // For user coming from group space to publish his work
     $realUrl = str_replace($_configuration['root_sys'], api_get_path(WEB_PATH), str_replace("\\", '/', realpath($submitGroupWorkUrl)));
     $form->addElement('hidden', 'newWorkUrl', $submitGroupWorkUrl);
     $text_document = $form->addElement('text', 'document', get_lang('Document'));
@@ -129,7 +137,7 @@ if ($submitGroupWorkUrl) {
 $form->addElement('hidden', 'id', $work_id);
 $form->addElement('hidden', 'item_id', $item_id);
 $form->addElement('text', 'title', get_lang('Title'), array('id' => 'file_upload', 'class' => 'span4'));
-$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Work', 'Width' => '100%', 'Height' => '200'));
+$form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar());
 
 $defaults['title'] 			= $work_item['title'];
 $defaults["description"] 	= $work_item['description'];
@@ -142,7 +150,7 @@ if ($is_allowed_to_edit && !empty($item_id)) {
     $row = Database::fetch_array($result);
     $qualification_over = $row['qualification'];
     if (!empty($qualification_over) && intval($qualification_over) > 0) {
-        $form->addElement('text', 'qualification', array(get_lang('Qualification'),  null, " / ".$qualification_over), 'size="10"');
+        $form->addElement('text', 'qualification', array(get_lang('Qualification'), null, " / ".$qualification_over), 'size="10"');
         $form->addElement('hidden', 'qualification_over', $qualification_over);
     }
 }
@@ -179,27 +187,28 @@ if ($form->validate()) {
                 $work_data = get_work_data_by_id($item_to_edit_id);
 
                 if (!empty($_POST['title'])) {
-                    $title 		 = isset($_POST['title']) ? $_POST['title'] : $work_data['title'];
+                    $title = isset($_POST['title']) ? $_POST['title'] : $work_data['title'];
                 }
                 $description = isset($_POST['description']) ? $_POST['description'] : $work_data['description'];
 
                 if ($is_allowed_to_edit && ($_POST['qualification'] !='' )) {
-                    $add_to_update = ', qualificator_id ='."'".api_get_user_id()."',";
+                    $add_to_update = ', qualificator_id ='."'".api_get_user_id()."', ";
                     $add_to_update .= ' qualification = '."'".Database::escape_string($_POST['qualification'])."',";
-                    $add_to_update .= ' date_of_qualification ='."'".api_get_utc_datetime()."'";
+                    $add_to_update .= ' date_of_qualification = '."'".api_get_utc_datetime()."'";
                 }
 
-                if ((int)$_POST['qualification'] > (int)$_POST['qualification_over']) {
+                if ($_POST['qualification'] > $_POST['qualification_over']) {
                     Display::display_error_message(get_lang('QualificationMustNotBeMoreThanQualificationOver'));
                 } else {
                     $sql = "UPDATE  " . $work_table . "
-                            SET	title       = '" . Database::escape_string($title) . "',
-                                description = '" . Database::escape_string($description) . "'
+                            SET	title = '".Database::escape_string($title)."',
+                                description = '".Database::escape_string($description)."'
                                 ".$add_to_update."
                             WHERE c_id = $course_id AND id = $item_to_edit_id";
                     Database::query($sql);
                 }
                 api_item_property_update($_course, 'work', $item_to_edit_id, 'DocumentUpdated', $user_id);
+
                 $succeed = true;
                 $error_message .= Display::return_message(get_lang('ItemUpdated'), false);
             } else {
@@ -210,14 +219,13 @@ if ($form->validate()) {
         }
         Security::clear_token();
     } else {
-        //Bad token or can't add works
+        // Bad token or can't add works
         $error_message = Display::return_message(get_lang('IsNotPosibleSaveTheDocument'), 'error');
     }
     $script = 'work_list.php';
     if ($is_allowed_to_edit) {
         $script = 'work_list_all.php';
     }
-
     header('Location: '.api_get_path(WEB_CODE_PATH).'work/'.$script.'?'.api_get_cidreq().'&id='.$work_id.'&error_message='.$error_message);
     exit;
 }

+ 9 - 14
main/work/student_work.php

@@ -8,15 +8,11 @@ $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
 require_once '../inc/global.inc.php';
 $current_course_tool  = TOOL_STUDENTPUBLICATION;
 
-/*	Configuration settings */
-
 api_protect_course_script(true);
 
-// Including necessary files
 require_once 'work.lib.php';
 $this_section = SECTION_COURSES;
 
-//$workId = isset($_GET['id']) ? intval($_GET['id']) : null;
 $studentId = isset($_GET['studentId']) ? intval($_GET['studentId']) : null;
 
 if (empty($studentId)) {
@@ -27,11 +23,14 @@ $tool_name = get_lang('StudentPublications');
 $group_id = api_get_group_id();
 
 $userInfo = api_get_user_info($studentId);
+$courseInfo = api_get_course_info();
 
-if (empty($userInfo)) {
+if (empty($userInfo) || empty($courseInfo)) {
     api_not_allowed(true);
 }
 
+// Only a teachers page.
+
 if (!empty($group_id)) {
     $group_properties  = GroupManager :: get_group_properties($group_id);
     $show_work = false;
@@ -89,11 +88,9 @@ foreach ($workPerUser as $work) {
         $column++;
         $table->setCellContents($row, $column, $userResult['sent_date']);
         $column++;
-        //$dateQualification = !empty($workExtraData['expires_on']) && $workExtraData['expires_on'] != '0000-00-00 00:00:00' ? api_get_utc_datetime($workExtraData['expires_on']) : '-';
         $dateQualification = !empty($workExtraData['expires_on']) && $workExtraData['expires_on'] != '0000-00-00 00:00:00' ? api_get_local_time($workExtraData['expires_on']) : '-';
         $table->setCellContents($row, $column, $dateQualification);
         $column++;
-        //var_dump($userResult);
         $score = '-';
         if (!empty($scoreWeight)) {
             $score = strip_tags($userResult['qualification'])."/".$scoreWeight;
@@ -104,16 +101,14 @@ foreach ($workPerUser as $work) {
         // Actions
         $links = null;
 
-        if (empty($userResult['url'])) {
-            // is a text
-            $url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$userResult['id'];
-            $links .= Display::url(Display::return_icon('default.png'), $url);
-        } else {
+        // is a text
+        $url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$userResult['id'];
+        $links .= Display::url(Display::return_icon('default.png'), $url);
 
+        if (!empty($userResult['url'])) {
             $url = api_get_path(WEB_CODE_PATH).'work/download.php?'.api_get_cidreq().'&id='.$userResult['id'];
-            $links .= Display::url(Display::return_icon('save.png'), $url);
+            $links .= Display::url(Display::return_icon('save.png', get_lang('Download')), $url);
         }
-
         $url = api_get_path(WEB_CODE_PATH).'work/edit.php?'.api_get_cidreq().'&item_id='.$userResult['id'].'&id='.$workId.'&parent_id='.$workId;
         $links .= Display::url(Display::return_icon('edit.png', get_lang('Comment')), $url);
 

+ 1 - 2
main/work/upload.php

@@ -151,7 +151,7 @@ if ($submitGroupWorkUrl) {
 $form->addElement('hidden', 'id', $work_id);
 $form->addElement('hidden', 'contains_file', 0, array('id'=>'contains_file_id'));
 $form->addElement('text', 'title', get_lang('Title'), array('id' => 'file_upload', 'class' => 'span4'));
-$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Work', 'Width' => '100%', 'Height' => '200'));
+$form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar());
 
 $form->addElement('hidden', 'active', 1);
 $form->addElement('hidden', 'accepted', 1);
@@ -328,7 +328,6 @@ if ($form->validate()) {
 }
 
 $htmlHeadXtra[] = to_javascript_work();
-
 Display :: display_header(null);
 
 if (!empty($work_id)) {

+ 14 - 6
main/work/view.php

@@ -23,11 +23,17 @@ $course_info = api_get_course_info();
 allowOnlySubscribedUser(api_get_user_id(), $work['parent_id'], $course_info['real_id']);
 
 if (user_is_author($id) || $course_info['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) {
-    $url_dir = 'work.php?&id=' . $my_folder_data['id'];
-    $interbreadcrumb[] = array ('url' => $url_dir,'name' =>  $my_folder_data['title']);
-    $interbreadcrumb[] = array ('url' => '#','name' =>  $work['title']);
-
-    if (($course_info['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) || api_is_allowed_to_edit() || ($work['user_id'] == api_get_user_id() && $work['active'] == 1 && $work['accepted'] == 1)) {
+    if (api_is_allowed_to_edit(null, true)) {
+        $url_dir = 'work_list_all.php?id='.$my_folder_data['id'];
+    } else {
+        $url_dir = 'work_list.php?id='.$my_folder_data['id'];
+    }
+    $interbreadcrumb[] = array('url' => $url_dir, 'name' =>  $my_folder_data['title']);
+    $interbreadcrumb[] = array('url' => '#','name' =>  $work['title']);
+    if (
+        ($course_info['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) ||
+        api_is_allowed_to_edit() ||
+        (user_is_author($id))) {
         $tpl = new Template();
         $tpl->assign('work', $work);
         $template = $tpl->get_template('work/view.tpl');
@@ -35,6 +41,8 @@ if (user_is_author($id) || $course_info['show_score'] == 0 && $work['active'] ==
         $tpl->assign('content', $content);
         $tpl->display_one_col_template();
     } else {
-        api_not_allowed();
+        api_not_allowed(true);
     }
+} else {
+    api_not_allowed(true);
 }

+ 174 - 54
main/work/work.lib.php

@@ -8,7 +8,7 @@
  * 	@author Roan Embrechts, code refactoring and virtual course support
  * 	@author Frederic Vauthier, directories management
  *  @author Julio Montoya <gugli100@gmail.com> BeezNest 2011 LOTS of bug fixes
- * 	@todo 	this lib should be convert in a static class and moved to main/inc/lib
+ * 	@todo 	this lib should be convert in a static class and moved to magein/inc/lib
  */
 /**
  * Initialization
@@ -17,7 +17,11 @@ require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
 require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
 require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
 
-define('ADD_DOCUMENT_TO_WORK', false);
+if (isset($_configuration['add_document_to_work'])) {
+    define('ADD_DOCUMENT_TO_WORK', $_configuration['add_document_to_work']);
+} else {
+    define('ADD_DOCUMENT_TO_WORK', false);
+}
 
 /**
  * Displays action links (for admins, authorized groups members and authorized students)
@@ -55,8 +59,6 @@ function display_action_links($id, $cur_dir_path, $action)
         }
     }
 
-
-
     if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath' && api_is_allowed_to_session_edit(false, true)) {
         // Delete all files
         if (api_get_setting('permanently_remove_deleted_files') == 'true'){
@@ -66,7 +68,6 @@ function display_action_links($id, $cur_dir_path, $action)
         }
     }
 
-
 	if ($display_output != '') {
 		echo '<div class="actions">';
 		echo $display_output;
@@ -160,7 +161,6 @@ function display_studentsdelete_form() {
         </label>
 		</div>
 </div>
-
 <?php
 }
 
@@ -227,7 +227,6 @@ function create_group_date_select($prefix = '') {
 	return $group_name;
 }
 
-
 function get_work_data_by_path($path) {
 	$path = Database::escape_string($path);
     $course_id 	= api_get_course_int_id();
@@ -254,6 +253,11 @@ function get_work_data_by_id($id) {
 	return $return;
 }
 
+/**
+ * @param int $user_id
+ * @param int $work_id
+ * @return int
+ */
 function get_work_count_by_student($user_id, $work_id) {
 	$user_id = intval($user_id);
 	$work_id = intval($work_id);
@@ -272,6 +276,10 @@ function get_work_count_by_student($user_id, $work_id) {
 	return $return;
 }
 
+/**
+ * @param int $id
+ * @return array
+ */
 function get_work_assignment_by_id($id) {
 	$id = intval($id);
     $course_id = api_get_course_int_id();
@@ -285,6 +293,12 @@ function get_work_assignment_by_id($id) {
 	return $return;
 }
 
+/**
+ * @param int $id
+ * @param array $my_folder_data
+ * @param string $add_in_where_query
+ * @return array
+ */
 function getWorkList($id, $my_folder_data, $add_in_where_query)
 {
     $work_table      = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
@@ -342,6 +356,10 @@ function getWorkList($id, $my_folder_data, $add_in_where_query)
     return $work_parents;
 }
 
+/**
+ * @param int $userId
+ * @return array
+ */
 function getWorkPerUser($userId)
 {
     $works = getWorkList(null, null, null);
@@ -449,9 +467,6 @@ function display_student_publications_list($id, $my_folder_data, $work_parents,
 	$my_params      = $sort_params;
 	$origin         = Security::remove_XSS($origin);
 
-	// Getting the work data
-	//$my_folder_data = get_work_data_by_id($id);
-
     $qualification_exists = false;
     if (!empty($my_folder_data['qualification']) && intval($my_folder_data['qualification']) > 0) {
         $qualification_exists = true;
@@ -493,7 +508,6 @@ function display_student_publications_list($id, $my_folder_data, $work_parents,
 
     $group_id = api_get_group_id();
 
-
 	if (is_array($work_parents)) {
 		foreach ($work_parents as $work_parent) {
 			$sql_select_directory = "SELECT
@@ -516,7 +530,7 @@ function display_student_publications_list($id, $my_folder_data, $work_parents,
 			} else {
 				$sql_select_directory .= " work.post_group_id = '0' ";
 			}
-			$sql_select_directory .= "  AND  ".
+			$sql_select_directory .= " AND ".
 			                           "  work.c_id = $course_id AND ".
 			                           "  work.id  = ".$work_parent->id." AND ".
 			                           "  work.filetype = 'folder' AND ".
@@ -595,9 +609,7 @@ function display_student_publications_list($id, $my_folder_data, $work_parents,
 
                         $weight_input2[] = $form_folder->createElement('text', 'weight');
                         $form_folder -> addGroup($weight_input2, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
-
                         $form_folder -> addElement('html', '</div>');
-
                         $defaults['weight[weight]'] = $link_info['weight'];
 
                         if (!empty($link_info)) {
@@ -620,7 +632,6 @@ function display_student_publications_list($id, $my_folder_data, $work_parents,
 
 					} else {
 						$homework['expires_on'] = api_get_local_time();
-
 						$expires_date_array = convert_date_to_array(api_get_local_time(), 'expires');
 						$defaults 			= array_merge($defaults, $expires_date_array);
 
@@ -847,12 +858,10 @@ function display_student_publications_list($id, $my_folder_data, $work_parents,
 
 				$work_title = !empty($work_data['title']) ? $work_data['title'] : basename($work_data['url']);
 
-				//Work name
-				//if (api_is_allowed_to_edit()) {
-                    if ($cant_files > 0 ) {
-                        $zip = '<a href="downloadfolder.inc.php?id='.$work_data['id'].'">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), ICON_SIZE_SMALL).'</a>';
-                    }
-				//}
+				// Work name
+                if ($cant_files > 0 ) {
+                    $zip = '<a href="downloadfolder.inc.php?id='.$work_data['id'].'">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), ICON_SIZE_SMALL).'</a>';
+                }
 
                 $link = 'work_list.php';
                 if (api_is_allowed_to_edit()) {
@@ -908,7 +917,7 @@ function display_student_publications_list($id, $my_folder_data, $work_parents,
 	$sorting_options = array();
 	$sorting_options['column'] = 1;
 
-	// Here we change the way how the colums are going to be sorted
+	// Here we change the way how the columns are going to be sorted
 	// in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
 	// because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
 
@@ -1631,6 +1640,16 @@ function get_count_work($work_id, $onlyMeUserId = null, $notMeUserId = null)
     return $users_with_work;
 }
 
+/**
+ * @param int $start
+ * @param int $limit
+ * @param int $column
+ * @param string $direction
+ * @param int $work_id
+ * @param array $where_condition
+ * @param int $studentId
+ * @return array
+ */
 function get_work_user_list($start, $limit, $column, $direction, $work_id, $where_condition, $studentId = null)
 {
     $work_table         = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
@@ -1668,12 +1687,11 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
         if ($is_allowed_to_edit) {
             $extra_conditions .= ' AND work.active IN (0, 1) ';
         } else {
-            $extra_conditions .= ' AND work.active IN (1) ';
 
             if (isset($course_info['show_score']) &&  $course_info['show_score'] == 1) {
-                $extra_conditions .= " AND u.user_id = ".api_get_user_id()." ";
+                $extra_conditions .= " AND (u.user_id = ".api_get_user_id()." AND work.active IN (0, 1) OR work.active = 1) ";
             } else {
-                $extra_conditions .= '';
+                $extra_conditions .= ' AND work.active = 1 ';
             }
         }
 
@@ -1692,7 +1710,7 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
         }
 
         $sql = "SELECT $select
-                FROM $work_condition  $user_condition $course_conditions
+                FROM $work_condition  $user_condition
                 WHERE  $extra_conditions $where_condition $condition_session ";
 
         $sql .= " ORDER BY $column $direction ";
@@ -1702,10 +1720,9 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
         $works = array();
 
         while ($work = Database::fetch_array($result, 'ASSOC')) {
-           //var_dump($work);
             $item_id = $work['id'];
 
-            //Get the author ID for that document from the item_property table
+            // Get the author ID for that document from the item_property table
 			$is_author  = false;
             $can_read   = false;
 
@@ -1720,7 +1737,7 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
 				$is_author = true;
 			}
 
-            if ($course_info['show_score'] == 0 ) {
+            if ($course_info['show_score'] == 0) {
                 $can_read = true;
             }
 
@@ -1747,19 +1764,23 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
 
             $add_string = '';
             $time_expires = api_strtotime($work_assignment['expires_on'], 'UTC');
+
             if (!empty($work_assignment['expires_on']) && $work_assignment['expires_on'] != '0000-00-00 00:00:00' && $time_expires && ($time_expires < api_strtotime($work['sent_date'], 'UTC'))) {
-                $add_string = Display::label(get_lang('Expired'),'important');
+                $add_string = Display::label(get_lang('Expired'), 'important');
             }
 
-            if (($can_read && $work['accepted'] == '1') || ($is_author && $work['accepted'] == '1') || $is_allowed_to_edit) {
+            if (
+                ($can_read && $work['accepted'] == '1') ||
+                ($is_author && in_array($work['accepted'], array('1','0'))) ||
+                $is_allowed_to_edit
+            ) {
 
-                //Firstname, lastname, username
+                // Firstname, lastname, username
                 $work['firstname'] = Display::div($work['firstname'], array('class' => $class));
                 $work['lastname'] = Display::div($work['lastname'], array('class' => $class));
-                //$work['username'] = Display::div($work['username'], array('class' => $class));
 
                 if (strlen($work['title']) > 30) {
-                    $short_title = substr($work['title'],0,27).'...';
+                    $short_title = substr($work['title'], 0, 27).'...';
                     $work['title'] = Display::span($short_title, array('class' => $class, 'title' => $work['title']));
                 } else {
                     $work['title'] = Display::div($work['title'], array('class' => $class));
@@ -1774,8 +1795,7 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
                 if ($work['contains_file']) {
                     $link_to_download = '<a href="download.php?id='.$item_id.'">'.Display::return_icon('save.png', get_lang('Save'),array(), ICON_SIZE_SMALL).'</a> ';
                 } else {
-                    //api_get_cidreq()
-                   //$link_to_download = '<a href="view.php?id='.$item_id.'">'.Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a> ';
+                   //$link_to_download = '<a href="view.php?id='.$item_id.'">'.Display::return_icon('save_na.png', get_lang('Save'),array(), ICON_SIZE_SMALL).'</a> ';
                 }
 
                 $send_to = Portfolio::share('work', $work['id'],  array('style' => 'white-space:nowrap;'));
@@ -1790,6 +1810,9 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
                 $url = api_get_path(WEB_CODE_PATH).'work/';
                 $action = '';
                 if ($is_allowed_to_edit) {
+                    $action .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.
+                        Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a> ';
+
                     if ($locked) {
                         if ($qualification_exists) {
                             $action .= Display::return_icon('rate_work_na.png', get_lang('CorrectAndRate'),array(), ICON_SIZE_SMALL);
@@ -1805,6 +1828,7 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
                             Display::return_icon('edit.png', get_lang('Comment'),array(), ICON_SIZE_SMALL).'</a>';
                         }
                     }
+
                     if ($work['contains_file']) {
                         if ($locked) {
                             $action .= Display::return_icon('move_na.png', get_lang('Move'),array(), ICON_SIZE_SMALL);
@@ -1817,23 +1841,26 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
                     } else {
                         $action .= '<a href="'.$url.'work.php?'.api_get_cidreq().'&action=make_visible&item_id='.$item_id.'&amp;'.$sort_params.'" title="'.get_lang('Visible').'" >'.Display::return_icon('invisible.png', get_lang('Visible'),array(), ICON_SIZE_SMALL).'</a> ';
                     }
+
                     if ($locked) {
                         $action .= Display::return_icon('delete_na.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
                     } else {
                         $action .= '<a href="'.$url.'work.php?'.api_get_cidreq().'&action=delete&amp;item_id='.$item_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'" >'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
                     }
                 } elseif ($is_author && (empty($work['qualificator_id']) || $work['qualificator_id'] == 0)) {
-                    if (api_is_allowed_to_session_edit(false, true)) {
-                        //$action .= '<a href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$work['parent_id'].'" title="'.get_lang('Modify').'"  >'.Display::return_icon('edit.png', get_lang('Modify'),array(), ICON_SIZE_SMALL).'</a>';
-                        $action .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('Modify').'">'.
-                            Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a>';
-                    } else {
-                        $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
-                    }
+                    $action .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a>';
+
                     if (api_get_course_setting('student_delete_own_publication') == 1) {
+                        if (api_is_allowed_to_session_edit(false, true)) {
+                            $action .= '<a href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$work['parent_id'].'&gradebook='.Security::remove_XSS($_GET['gradebook']).'" title="'.get_lang('Modify').'">'.
+                                Display::return_icon('edit.png', get_lang('Comment'),array(), ICON_SIZE_SMALL).'</a>';
+                        }
                         $action .= ' <a href="'.$url.'work.php?'.api_get_cidreq().'&action=delete&amp;item_id='.$item_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'"  >'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
+                    } else {
+                        $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
                     }
                 } else {
+                    $action .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a>';
                     $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
                 }
 
@@ -1920,6 +1947,10 @@ function send_email_on_homework_creation($course_id) {
 	}
 }
 
+/**
+ * @param string $url
+ * @return bool
+ */
 function is_work_exist_by_url($url) {
 	$work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
 	$url = Database::escape_string($url);
@@ -1972,12 +2003,19 @@ function draw_date_picker($prefix, $default = '') {
 	return $date_form;
 }
 
-function get_date_from_select($prefix) {
+function get_date_from_select($prefix)
+{
 	return $_POST[$prefix.'_year'].'-'.two_digits($_POST[$prefix.'_month']).'-'.two_digits($_POST[$prefix.'_day']).' '.two_digits($_POST[$prefix.'_hour']).':'.two_digits($_POST[$prefix.'_minute']).':00';
 }
 
-/* Check if a user is the author of the item */
-function user_is_author($item_id, $user_id = null) {
+/**
+ * Check if a user is the author of the item
+ * @param int $item_id
+ * @param int  $user_id
+ * @return bool
+ */
+function user_is_author($item_id, $user_id = null)
+{
     if (empty($item_id)) {
         return false;
     }
@@ -1996,6 +2034,7 @@ function user_is_author($item_id, $user_id = null) {
             $is_author = true;
         }
     }
+
     if (!$is_author) {
         //api_not_allowed();
         return false;
@@ -2003,7 +2042,6 @@ function user_is_author($item_id, $user_id = null) {
     return $is_author;
 }
 
-
 /**
  * Get list of users who have not given the task
  * @param int
@@ -2124,7 +2162,11 @@ function display_list_users_without_publication($task_id, $studentId = null)
 }
 
 // Document to work
-
+/**
+ * @param int $documentId
+ * @param int $workId
+ * @param int $courseId
+ */
 function addDocumentToWork($documentId, $workId, $courseId)
 {
     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT);
@@ -2136,6 +2178,12 @@ function addDocumentToWork($documentId, $workId, $courseId)
     Database::insert($table, $params);
 }
 
+/**
+ * @param int $documentId
+ * @param int $workId
+ * @param int $courseId
+ * @return array
+ */
 function getDocumentToWork($documentId, $workId, $courseId)
 {
     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT);
@@ -2145,6 +2193,11 @@ function getDocumentToWork($documentId, $workId, $courseId)
     return Database::select('*', $table, array('where' => $params));
 }
 
+/**
+ * @param int $workId
+ * @param int $courseId
+ * @return array
+ */
 function getAllDocumentToWork($workId, $courseId)
 {
     if (ADD_DOCUMENT_TO_WORK == false) {
@@ -2157,7 +2210,11 @@ function getAllDocumentToWork($workId, $courseId)
     return Database::select('*', $table, array('where' => $params));
 }
 
-
+/**
+ * @param int $documentId
+ * @param int $workId
+ * @param int $courseId
+ */
 function deleteDocumentToWork($documentId, $workId, $courseId)
 {
     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT);
@@ -2167,9 +2224,11 @@ function deleteDocumentToWork($documentId, $workId, $courseId)
     Database::delete($table, $params);
 }
 
-// User to work
-
-
+/**
+ * @param int $userId
+ * @param int $workId
+ * @param int $courseId
+ */
 function addUserToWork($userId, $workId, $courseId)
 {
     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER);
@@ -2181,6 +2240,12 @@ function addUserToWork($userId, $workId, $courseId)
     Database::insert($table, $params);
 }
 
+/**
+ * @param int $userId
+ * @param int $workId
+ * @param int $courseId
+ * @return array
+ */
 function getUserToWork($userId, $workId, $courseId)
 {
     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER);
@@ -2190,6 +2255,11 @@ function getUserToWork($userId, $workId, $courseId)
     return Database::select('*', $table, array('where' => $params));
 }
 
+/**
+ * @param int $workId
+ * @param int $courseId
+ * @return array
+ */
 function getAllUserToWork($workId, $courseId)
 {
     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER);
@@ -2208,7 +2278,11 @@ function userAddedToWork($userId, $workId, $courseId)
     $result = Database::select('count(*)', $table, array('where' => $params));*/
 }
 
-
+/**
+ * @param int $userId
+ * @param int $workId
+ * @param int $courseId
+ */
 function deleteUserToWork($userId, $workId, $courseId)
 {
     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER);
@@ -2218,6 +2292,12 @@ function deleteUserToWork($userId, $workId, $courseId)
     Database::delete($table, $params);
 }
 
+/**
+ * @param int $userId
+ * @param int $workId
+ * @param int $courseId
+ * @return bool
+ */
 function userIsSubscribedToWork($userId, $workId, $courseId)
 {
     if (ADD_DOCUMENT_TO_WORK == false) {
@@ -2239,6 +2319,12 @@ function userIsSubscribedToWork($userId, $workId, $courseId)
     return false;
 }
 
+/**
+ * @param int $userId
+ * @param int $workId
+ * @param int $courseId
+ * @return bool
+ */
 function allowOnlySubscribedUser($userId, $workId, $courseId)
 {
     if (ADD_DOCUMENT_TO_WORK == false) {
@@ -2250,9 +2336,13 @@ function allowOnlySubscribedUser($userId, $workId, $courseId)
     if (userIsSubscribedToWork($userId, $workId, $courseId) == false) {
         api_not_allowed(true);
     }
-
 }
 
+/**
+ * @param int $workId
+ * @param array $courseInfo
+ * @return array
+ */
 function getDocumentTemplateFromWork($workId, $courseInfo)
 {
     $documents = getAllDocumentToWork($workId, $courseInfo['real_id']);
@@ -2270,3 +2360,33 @@ function getDocumentTemplateFromWork($workId, $courseInfo)
     }
     return array();
 }
+
+/**
+ * @param $workId
+ * @param $courseInfo
+ */
+function getAllDocumentsFromWorkToString($workId, $courseInfo)
+{
+    $documents = getAllDocumentToWork($workId, $courseInfo['real_id']);
+    if (!empty($documents)) {
+        $docContent = '<ul class="nav nav-list well">';
+        $docContent .= '<li class="nav-header">'.get_lang('Documents').'</li>';
+        foreach ($documents as $doc) {
+            $docData = DocumentManager::get_document_data_by_id($doc['document_id'], $courseInfo['code']);
+            if ($docData) {
+                $docContent .= '<li><a target="_blank" href="'.$docData['url'].'">'.$docData['title'].'</a></li>';
+            }
+        }
+        $docContent .= '</ul><br />';
+        echo $docContent;
+    }
+}
+
+/**
+ * Returns fckeditor toolbar
+ * @return array
+ */
+function getWorkDescriptionToolbar()
+{
+    return array('ToolbarSet' => 'Work', 'Width' => '100%', 'Height' => '400');
+}

+ 3 - 28
main/work/work.php

@@ -172,7 +172,7 @@ if (!empty($gradebook) && $gradebook == 'view') {
 }
 
 if (!empty($group_id)) {
-    $group_properties  = GroupManager :: get_group_properties($group_id);
+    $group_properties  = GroupManager::get_group_properties($group_id);
     $show_work = false;
 
     if (api_is_allowed_to_edit(false, true)) {
@@ -319,8 +319,7 @@ switch ($action) {
             $form->addElement('text', 'new_dir', get_lang('AssignmentName'));
             $form->addRule('new_dir', get_lang('ThisFieldIsRequired'), 'required');
 
-            //$form->addElement('html_editor', 'description', get_lang('Description'));
-            $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Work', 'Width' => '100%', 'Height' => '200'));
+            $form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar());
 
             $form->addElement('advanced_settings', '<a href="javascript: void(0);" onclick="javascript: return plus();"><span id="plus">'.Display::return_icon('div_show.gif',get_lang('AdvancedParameters'), array('style' => 'vertical-align:center')).' '.get_lang('AdvancedParameters').'</span></a>');
 
@@ -509,17 +508,10 @@ switch ($action) {
             if ($path = get_work_path($item_id)) {
 
                 if (move($course_dir.'/'.$path, $base_work_dir . $move_to_path)) {
-                    //update db
+                    // Update db
                     update_work_url($item_id, 'work' . $move_to_path, $_REQUEST['move_to_id']);
-
                     api_item_property_update($_course, 'work', $_REQUEST['move_to_id'], 'FolderUpdated', $user_id);
 
-                    /*
-                    // update all the parents in the table item propery
-                    $list_id = get_parent_directories($move_to_path);
-                    for ($i = 0; $i < count($list_id); $i++) {
-                        api_item_property_update($_course, 'work', $list_id[$i], 'FolderUpdated', $user_id);
-                    }*/
                     Display :: display_confirmation_message(get_lang('DirMv'));
                 } else {
                     Display :: display_error_message(get_lang('Impossible'));
@@ -549,13 +541,6 @@ switch ($action) {
         if ($is_allowed_to_edit && $action == 'make_visible') {
             if (!empty($item_id)) {
                 if (isset($item_id) && $item_id == 'all') {
-                    //never happens
-                    /*
-                    $sql = "ALTER TABLE  " . $work_table . " CHANGE accepted accepted TINYINT(1) DEFAULT '1'";
-                    Database::query($sql);
-                    $sql = "UPDATE  " . $work_table . " SET accepted = 1";
-                    Database::query($sql);
-                    Display::display_confirmation_message(get_lang('AllFilesVisible'));*/
                 } else {
                     $sql = "UPDATE " . $work_table . "	SET accepted = 1 WHERE c_id = $course_id AND id = '" . $item_id . "'";
                     Database::query($sql);
@@ -570,13 +555,6 @@ switch ($action) {
             /*	MAKE INVISIBLE WORK COMMAND */
             if (!empty($item_id)) {
                 if (isset($item_id) && $item_id == 'all') {
-                    /*
-                    $sql = "ALTER TABLE " . $work_table . "
-                        CHANGE accepted accepted TINYINT(1) DEFAULT '0'";
-                    Database::query($sql);
-                    $sql = "UPDATE  " . $work_table . " SET accepted = 0";
-                    Database::query($sql);
-                    Display::display_confirmation_message(get_lang('AllFilesInvisible'));*/
                 } else {
                     $sql = "UPDATE  " . $work_table . " SET accepted = 0
                             WHERE c_id = $course_id AND id = '" . $item_id . "'";
@@ -741,11 +719,8 @@ switch ($action) {
             echo $table->toHtml();
             echo '</div>';
         } else {
-
-
             display_student_publications_list($work_id, $my_folder_data, $work_parents, $origin, $add_query, null);
         }
-
     break;
 }
 if ($origin != 'learnpath') {

+ 3 - 18
main/work/work_list.php

@@ -78,26 +78,12 @@ if (!empty($my_folder_data['description'])) {
     echo '<p><div><strong>'.get_lang('Description').':</strong><p>'.Security::remove_XSS($my_folder_data['description']).'</p></div></p>';
 }
 
-$documents = getAllDocumentToWork($workId, $courseInfo['real_id']);
-if (!empty($documents)) {
-    $docContent = '<ul class="nav nav-list well">';
-    $docContent .= '<li class="nav-header">'.get_lang('Documents').'</li>';
-    foreach ($documents as $doc) {
-        $docData = DocumentManager::get_document_data_by_id($doc['document_id'], $courseInfo['code']);
-        if ($docData) {
-            $docContent .= '<li><a target="_blank" href="'.$docData['url'].'">'.$docData['title'].'</a></li>';
-        }
-
-    }
-    $docContent .= '</ul><br />';
-    echo $docContent;
-}
+echo getAllDocumentsFromWorkToString($workId, $courseInfo);
 
 $check_qualification = intval($my_folder_data['qualification']);
 
 if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) {
     $type = 'simple';
-    //$columns        = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'),  get_lang('Status'), get_lang('Actions'));
     $columns        = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'), get_lang('Status'), get_lang('Actions'));
     $column_model   = array (
         array('name'=>'type',           'index'=>'file',            'width'=>'12',   'align'=>'left', 'search' => 'false'),
@@ -113,7 +99,6 @@ if (!empty($work_data['enable_qualification']) && !empty($check_qualification))
     );
 } else {
     $type = 'complex';
-    //$columns  = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'), get_lang('Date'),  get_lang('Actions'));
     $columns  = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Date'),  get_lang('Actions'));
     $column_model   = array (
         array('name'=>'type',           'index'=>'file',            'width'=>'12',   'align'=>'left', 'search' => 'false'),
@@ -131,10 +116,10 @@ if (!empty($work_data['enable_qualification']) && !empty($check_qualification))
 
 $extra_params = array();
 
-//Autowidth
+// Auto width
 $extra_params['autowidth'] = 'true';
 
-//height auto
+// Height
 $extra_params['height'] = 'auto';
 
 $extra_params['sortname'] = 'firstname';

+ 3 - 1
main/work/work_list_all.php

@@ -73,7 +73,7 @@ if (api_is_allowed_to_session_edit(false, true) && !empty($workId)) {
         echo Display::return_icon('new_document.png', get_lang('AddDocument'), '', ICON_SIZE_MEDIUM).'</a>';
 
         echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/add_user.php?'.api_get_cidreq().'&id='.$workId.'">';
-        echo Display::return_icon('user.png', get_lang('AddUser'), '', ICON_SIZE_MEDIUM).'</a>';
+        echo Display::return_icon('user.png', get_lang('AddUsers'), '', ICON_SIZE_MEDIUM).'</a>';
     }
 
     $display_output .= '<a href="'.api_get_path(WEB_CODE_PATH).'work/work_missing.php?'.api_get_cidreq().'&amp;id='.$workId.'&amp;curdirpath='.$cur_dir_path.'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;list=without">'.
@@ -153,6 +153,8 @@ $(function() {
 </script>
 <?php
 
+echo getAllDocumentsFromWorkToString($workId, $courseInfo);
+
 echo Display::grid_html('results');
 
 Display :: display_footer();

+ 8 - 21
main/work/work_list_others.php

@@ -8,11 +8,8 @@ $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
 require_once '../inc/global.inc.php';
 $current_course_tool  = TOOL_STUDENTPUBLICATION;
 
-/*	Configuration settings */
-
 api_protect_course_script(true);
 
-// Including necessary files
 require_once 'work.lib.php';
 $this_section = SECTION_COURSES;
 
@@ -64,7 +61,6 @@ if (!empty($group_id)) {
 $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(), 'name' => get_lang('StudentPublications'));
 $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work_list_others.php?'.api_get_cidreq().'&id='.$workId, 'name' =>  $my_folder_data['title']);
 
-
 Display :: display_header(null);
 
 echo '<div class="actions">';
@@ -80,46 +76,37 @@ $check_qualification = intval($my_folder_data['qualification']);
 
 if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) {
     $type = 'simple';
-    //$columns        = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'),  get_lang('Status'), get_lang('Actions'));
-    $columns        = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'),  get_lang('Status'), get_lang('Actions'));
-    $column_model   = array (
+    $columns = array(
+        get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'),  get_lang('Status'), get_lang('Actions')
+    );
+    $column_model   = array(
         array('name'=>'type',           'index'=>'file',            'width'=>'12',   'align'=>'left', 'search' => 'false'),
         array('name'=>'firstname',      'index'=>'firstname',       'width'=>'35',   'align'=>'left', 'search' => 'true'),
         array('name'=>'lastname',		'index'=>'lastname',        'width'=>'35',   'align'=>'left', 'search' => 'true'),
-        //array('name'=>'username',       'index'=>'username',        'width'=>'30',   'align'=>'left', 'search' => 'true'),
         array('name'=>'title',          'index'=>'title',           'width'=>'40',   'align'=>'left', 'search' => 'false', 'wrap_cell' => 'true'),
-        //                array('name'=>'file',           'index'=>'file',            'width'=>'20',   'align'=>'left', 'search' => 'false'),
         array('name'=>'qualification',	'index'=>'qualification',	'width'=>'20',   'align'=>'left', 'search' => 'true'),
-        array('name'=>'sent_date',           'index'=>'sent_date',            'width'=>'50',   'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'),
+        array('name'=>'sent_date',       'index'=>'sent_date',            'width'=>'50',   'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'),
         array('name'=>'qualificator_id','index'=>'qualificator_id', 'width'=>'30',   'align'=>'left', 'search' => 'true'),
         array('name'=>'actions',        'index'=>'actions',         'width'=>'40',   'align'=>'left', 'search' => 'false', 'sortable'=>'false')
     );
 } else {
     $type = 'complex';
-    //$columns  = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'), get_lang('Date'),  get_lang('Actions'));
-    $columns  = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Date'),  get_lang('Actions'));
+    $columns  = array(
+        get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Date'),  get_lang('Actions')
+    );
     $column_model   = array (
         array('name'=>'type',           'index'=>'file',            'width'=>'12',   'align'=>'left', 'search' => 'false'),
         array('name'=>'firstname',      'index'=>'firstname',       'width'=>'35',   'align'=>'left', 'search' => 'true'),
         array('name'=>'lastname',		'index'=>'lastname',        'width'=>'35',   'align'=>'left', 'search' => 'true'),
-        //array('name'=>'username',       'index'=>'username',        'width'=>'30',   'align'=>'left', 'search' => 'true'),
         array('name'=>'title',          'index'=>'title',           'width'=>'40',   'align'=>'left', 'search' => 'false', 'wrap_cell' => "true"),
-        //                array('name'=>'file',           'index'=>'file',            'width'=>'20',   'align'=>'left', 'search' => 'false'),
-        //array('name'=>'qualification',	'index'=>'qualification',	'width'=>'20',   'align'=>'left', 'search' => 'true'),
         array('name'=>'sent_date',       'index'=>'sent_date',            'width'=>'50',   'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'),
-        //array('name'=>'qualificator_id','index'=>'qualificator_id', 'width'=>'30',   'align'=>'left', 'search' => 'true'),
         array('name'=>'actions',        'index'=>'actions',         'width'=>'40',   'align'=>'left', 'search' => 'false', 'sortable'=>'false')
     );
 }
 
 $extra_params = array();
-
-//Autowidth
 $extra_params['autowidth'] = 'true';
-
-//height auto
 $extra_params['height'] = 'auto';
-
 $extra_params['sortname'] = 'firstname';
 $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_work_user_list_others&work_id='.$workId.'&type='.$type;
 ?>

+ 13 - 23
vendor/chamilo/chash/src/Chash/Command/Files/SetPermissionsAfterInstallCommand.php

@@ -10,7 +10,10 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Filesystem\Filesystem;
 
-
+/**
+ * Class SetPermissionsAfterInstallCommand
+ * @package Chash\Command\Files
+ */
 class SetPermissionsAfterInstallCommand extends CommonChamiloDatabaseCommand
 {
     /**
@@ -34,25 +37,11 @@ class SetPermissionsAfterInstallCommand extends CommonChamiloDatabaseCommand
     protected function execute(InputInterface $input, OutputInterface $output)
     {
         parent::execute($input, $output);
-        $this->writeCommandHeader($output, 'Setting permissions.');
+        $this->writeCommandHeader($output, 'Setting permissions ...');
 
         $linuxUser = $input->getOption('linux-user');
         $linuxGroup = $input->getOption('linux-group');
 
-
-        /*$dialog = $this->getHelperSet()->get('dialog');
-
-        if (!$dialog->askConfirmation(
-            $output,
-            '<question>Are you sure you want to clean your config files? (y/N)</question>',
-            false
-        )
-        ) {
-            return;
-        }*/
-
-        // $configuration = $this->getConfigurationArray();
-
         // All files
         $files = $this->getConfigurationHelper()->getSysFolders();
         $this->setPermissions($output, $files, 0777, $linuxUser, $linuxGroup, false);
@@ -92,11 +81,11 @@ class SetPermissionsAfterInstallCommand extends CommonChamiloDatabaseCommand
         $fs = new Filesystem();
         try {
             if ($dryRun) {
-
-                $output->writeln("<comment>Files to be changed to permission ".decoct($permission)."</comment>");
+                $output->writeln("<comment>Modifying files permission to: ".decoct($permission)."</comment>");
                 $output->writeln("<comment>user: ".$user."</comment>");
                 $output->writeln("<comment>group: ".$group."</comment>");
                 if ($listFiles) {
+                    $output->writeln("<comment>Files: </comment>");
                     foreach ($files as $file) {
                         $output->writeln($file->getPathName());
                     }
@@ -104,19 +93,22 @@ class SetPermissionsAfterInstallCommand extends CommonChamiloDatabaseCommand
             } else {
 
                 if (!empty($permission)) {
-                    $output->writeln("<comment>Modifying files permission: ".decoct($permission)."</comment>");
+                    $output->writeln("<comment>Modifying files permission to: ".decoct($permission)."</comment>");
                 }
                 if (!empty($user)) {
-                    $output->writeln("<comment>user: ".$user."</comment>");
+                    $output->writeln("<comment>Modifying file user: ".$user."</comment>");
                 }
                 if (!empty($group)) {
-                    $output->writeln("<comment>group: ".$group."</comment>");
+                    $output->writeln("<comment>Modifying file group: ".$group."</comment>");
                 }
 
                 if ($listFiles) {
+                    $output->writeln("<comment>Files: </comment>");
                     foreach ($files as $file) {
                         $output->writeln($file->getPathName());
                     }
+                } else {
+                    $output->writeln("<comment>Skipping file list (too long)... </comment>");
                 }
 
                 if (!empty($permission)) {
@@ -130,9 +122,7 @@ class SetPermissionsAfterInstallCommand extends CommonChamiloDatabaseCommand
                 if (!empty($group)) {
                     $fs->chgrp($files, $group, true);
                 }
-
             }
-
         } catch (IOException $e) {
             echo "\n An error occurred while removing the directory: ".$e->getMessage()."\n ";
         }

+ 48 - 35
vendor/chamilo/chash/src/Chash/Command/Installation/CommonCommand.php

@@ -9,6 +9,8 @@ use Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand;
 use Symfony\Component\Filesystem\Filesystem;
 use Symfony\Component\Filesystem\Exception\IOException;
 use Alchemy\Zippy\Zippy;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Input\InputInterface;
 
 class CommonCommand extends AbstractCommand
 {
@@ -22,16 +24,16 @@ class CommonCommand extends AbstractCommand
     private $migrationConfigurationFile;
 
     /**
-     * @param array $configuration
-     */
+    * @param array $configuration
+    */
     public function setConfigurationArray(array $configuration)
     {
         $this->configuration = $configuration;
     }
 
     /**
-     * @return array
-     */
+    * @return array
+    */
     public function getConfigurationArray()
     {
         return $this->configuration;
@@ -107,16 +109,16 @@ class CommonCommand extends AbstractCommand
         return $this->databaseSettings;
     }
 
-        /**
-     * @param array $databaseSettings
-     */
+    /**
+    * @param array $databaseSettings
+    */
     public function setExtraDatabaseSettings(array $databaseSettings)
     {
         $this->extraDatabaseSettings = $databaseSettings;
     }
 
     /**
-     * @return array
+     * @return mixed
      */
     public function getExtraDatabaseSettings()
     {
@@ -526,6 +528,9 @@ class CommonCommand extends AbstractCommand
         return $this->migrationConfigurationFile;
     }
 
+    /**
+     * @param string $file
+     */
     public function setMigrationConfigurationFile($file)
     {
         $this->migrationConfigurationFile = $file;
@@ -593,13 +598,12 @@ class CommonCommand extends AbstractCommand
         // Session lifetime
         $configuration['session_lifetime']         = 3600;
         // Activation for multi-url access
-        $_configuration['multiple_access_urls']   = false;
+        $configuration['multiple_access_urls']   = false;
         //Deny the elimination of users
         $configuration['deny_delete_users']        = false;
         //Prevent all admins from using the "login_as" feature
         $configuration['login_as_forbidden_globally'] = false;
 
-
         // Version settings
         $configuration['system_version']           = $version;
 
@@ -651,11 +655,13 @@ class CommonCommand extends AbstractCommand
 
     /**
      * Updates the configuration.yml file
-     * @param string $version
      *
+     * @param OutputInterface $output
+     * @param $dryRun
+     * @param $newValues
      * @return bool
      */
-    public function updateConfiguration($output, $dryRun, $newValues)
+    public function updateConfiguration(OutputInterface $output, $dryRun, $newValues)
     {
         $this->getConfigurationPath();
 
@@ -678,7 +684,6 @@ class CommonCommand extends AbstractCommand
             'scorm_database'
         );
 
-
         foreach ($_configuration as $key => $value) {
             if (in_array($key, $paramsToRemove)) {
                 unset($_configuration[$key]);
@@ -882,7 +887,7 @@ class CommonCommand extends AbstractCommand
      * @param \Symfony\Component\Console\Output\OutputInterface $output
      * @return int
      */
-    public function removeFiles($files, \Symfony\Component\Console\Output\OutputInterface $output)
+    public function removeFiles($files, OutputInterface $output)
     {
         $dryRun = $this->getConfigurationHelper()->getDryRun();
 
@@ -892,6 +897,7 @@ class CommonCommand extends AbstractCommand
         }
 
         $fs = new Filesystem();
+
         try {
             if ($dryRun) {
                 $output->writeln('<comment>Files to be removed (--dry-run is on).</comment>');
@@ -916,7 +922,7 @@ class CommonCommand extends AbstractCommand
      * @param array $params
      * @return array
      */
-    public function getParamsFromOptions(\Symfony\Component\Console\Input\InputInterface $input, array $params)
+    public function getParamsFromOptions(InputInterface $input, array $params)
     {
         $filledParams = array();
 
@@ -935,7 +941,7 @@ class CommonCommand extends AbstractCommand
      * @param string $defaultTempFolder
      * @return int|null|String
      */
-    public function getPackage(\Symfony\Component\Console\Output\OutputInterface $output, $version, $updateInstallation, $defaultTempFolder)
+    public function getPackage(OutputInterface $output, $version, $updateInstallation, $defaultTempFolder)
     {
         $fs = new Filesystem();
 
@@ -1078,11 +1084,11 @@ class CommonCommand extends AbstractCommand
     }
 
     /**
-     * @param $output
+     * @param OutputInterface $output
      * @param string $chamiloLocationPath
      * @param string $destinationPath
      */
-    public function copyPackageIntoSystem($output, $chamiloLocationPath, $destinationPath)
+    public function copyPackageIntoSystem(OutputInterface $output, $chamiloLocationPath, $destinationPath)
     {
         $fileSystem = new Filesystem();
 
@@ -1138,7 +1144,7 @@ class CommonCommand extends AbstractCommand
     /**
      * @param \Symfony\Component\Console\Output\OutputInterface $output
      */
-    public function generateConfFiles(\Symfony\Component\Console\Output\OutputInterface $output)
+    public function generateConfFiles(OutputInterface $output)
     {
         $confDir = $this->getConfigurationPath();
         $fs = new Filesystem();
@@ -1159,13 +1165,14 @@ class CommonCommand extends AbstractCommand
      * Copy files from main/inc/conf to the new location config
      * @param \Symfony\Component\Console\Output\OutputInterface $output
      */
-    public function copyConfigFilesToNewLocation(\Symfony\Component\Console\Output\OutputInterface $output)
+    public function copyConfigFilesToNewLocation(OutputInterface $output)
     {
         $output->writeln('<comment>Copy files to new location</comment>');
         // old config main/inc/conf
         $confDir = $this->getConfigurationPath();
 
         $configurationPath = $this->getConfigurationHelper()->convertOldConfigurationPathToNewPath($confDir);
+
         $fs = new Filesystem();
         $configList = $this->getConfigFiles();
         $configList[] = 'configuration.dist.php';
@@ -1175,25 +1182,33 @@ class CommonCommand extends AbstractCommand
                 continue;
             }
             $configFile = str_replace('dist.', '', $file);
-            $output->writeln("<comment> Moving file from: </comment>".$confDir.$configFile);
-            $output->writeln("<comment> to: </comment>".$configurationPath.$configFile);
-            if (!file_exists($configurationPath.$configFile)) {
-                $fs->copy($confDir.$configFile, $configurationPath.$configFile);
+
+            if (file_exists($confDir.$configFile)) {
+                $output->writeln("<comment> Moving file from: </comment>".$confDir.$configFile);
+                $output->writeln("<comment> to: </comment>".$configurationPath.$configFile);
+                if (!file_exists($configurationPath.$configFile)) {
+                    $fs->copy($confDir.$configFile, $configurationPath.$configFile);
+                }
+            } else {
+                $output->writeln("<comment> File not found: </comment>".$confDir.$configFile);
             }
         }
 
         $backupConfPath = str_replace('inc/conf', 'inc/conf_old', $confDir);
-        $output->writeln('<comment>Renaming conf folder: </comment>'.$confDir.' to '.$backupConfPath.'');
-
-        $fs->rename($confDir, $backupConfPath);
+        if ($confDir != $backupConfPath) {
+            $output->writeln('<comment>Renaming conf folder: </comment>'.$confDir.' to '.$backupConfPath.'');
+            $fs->rename($confDir, $backupConfPath);
+        } else {
+            $output->writeln('<comment>No need to rename the conf folder: </comment>'.$confDir.' = '.$backupConfPath.'');
+        }
         $this->setConfigurationPath($configurationPath);
     }
 
     /**
-     *
-     * @param \Symfony\Component\Console\Output\OutputInterface $output
+     * @param OutputInterface $output
+     * @param $path
      */
-    public function removeUnUsedFiles(\Symfony\Component\Console\Output\OutputInterface $output, $path)
+    public function removeUnUsedFiles(OutputInterface $output, $path)
     {
         $output->writeln('<comment>Removing unused files</comment>');
         $fs = new Filesystem();
@@ -1216,7 +1231,7 @@ class CommonCommand extends AbstractCommand
      * @param \Symfony\Component\Console\Output\OutputInterface $output
      * @param \Doctrine\DBAL\Connection $connection
      */
-    public function setPortalSettingsInChamilo(\Symfony\Component\Console\Output\OutputInterface $output, \Doctrine\DBAL\Connection $connection)
+    public function setPortalSettingsInChamilo(OutputInterface $output, \Doctrine\DBAL\Connection $connection)
     {
         $adminSettings = $this->getAdminSettings();
 
@@ -1241,14 +1256,13 @@ class CommonCommand extends AbstractCommand
      * @param \Symfony\Component\Console\Output\OutputInterface $output
      * @param \Doctrine\DBAL\Connection $connection
      */
-    public function setAdminSettingsInChamilo(\Symfony\Component\Console\Output\OutputInterface $output, \Doctrine\DBAL\Connection $connection)
+    public function setAdminSettingsInChamilo(OutputInterface $output, \Doctrine\DBAL\Connection $connection)
     {
         $settings = $this->getAdminSettings();
 
         $settings['password'] = $this->getEncryptedPassword($settings['password']);
 
         $connection->update('user', array('auth_source' => 'platform'), array('user_id' => '1'));
-
         $connection->update('user', array('username' => $settings['username']), array('user_id' => '1'));
         $connection->update('user', array('firstname' => $settings['firstname']), array('user_id' => '1'));
         $connection->update('user', array('lastname' => $settings['lastname']), array('user_id' => '1'));
@@ -1259,7 +1273,6 @@ class CommonCommand extends AbstractCommand
 
         // Already updated by the script
         //$connection->insert('admin', array('user_id' => 1));
-
         $connection->update('user', array('language' => $settings['language']), array('user_id' => '2'));
     }
 
@@ -1282,7 +1295,7 @@ class CommonCommand extends AbstractCommand
                 return $password;
             case 'md5':
             default:
-                return empty($salt) ? md5($password)  : md5($password.$salt);
+                return empty($salt) ? md5($password) : md5($password.$salt);
         }
     }
 }

+ 70 - 43
vendor/chamilo/chash/src/Chash/Command/Installation/UpgradeCommand.php

@@ -10,9 +10,6 @@ use Symfony\Component\Filesystem\Filesystem;
 use Symfony\Component\Yaml\Dumper;
 use Symfony\Component\Yaml\Parser;
 
-// Constant needed in order to call migrate-db-* and update-files-*
-define('SYSTEM_INSTALLATION', 1);
-
 /**
  * Class UpgradeCommand
  */
@@ -31,6 +28,9 @@ class UpgradeCommand extends CommonCommand
         return $this->getHelper('db')->getConnection();
     }
 
+    /**
+     *
+     */
     protected function configure()
     {
         $this
@@ -62,7 +62,7 @@ class UpgradeCommand extends CommonCommand
             $this->commandLine = false;
         }
 
-        // Setting up Chash:
+        // Setting up Chash
         $command = $this->getApplication()->find('chash:setup');
         $migrationPath = $input->getOption('migration-yml-path');
         $migrationDir = $input->getOption('migration-class-path');
@@ -88,6 +88,7 @@ class UpgradeCommand extends CommonCommand
             $output->writeln("<error>Set the --migration-yml-path and --migration-class-path manually.</error>");
             return 0;
         }
+
         // Checking Resources/Database dir
         $migrationFileFolder = $this->getInstallationFolder();
         if (!is_dir($migrationFileFolder)) {
@@ -138,9 +139,7 @@ class UpgradeCommand extends CommonCommand
 
         // Doctrine migrations version
         //$doctrineVersion = $configuration->getCurrentVersion();
-
-
-         // Moves files from main/inc/conf to config/
+        // Moves files from main/inc/conf to config/
 
         $doctrineVersion = null;
 
@@ -260,6 +259,7 @@ class UpgradeCommand extends CommonCommand
          // Getting configuration file.
         $_configuration = $this->getHelper('configuration')->getConfiguration($path);
 
+        // Upgrade always from a mysql driver
         $databaseSettings = array(
             'driver' => 'pdo_mysql',
             'host' => $_configuration['db_host'],
@@ -280,7 +280,6 @@ class UpgradeCommand extends CommonCommand
 
         $this->setExtraDatabaseSettings($extraDatabaseSettings);
         $this->setDoctrineSettings();
-
         $conn = $this->getConnection();
 
         if ($conn) {
@@ -290,6 +289,7 @@ class UpgradeCommand extends CommonCommand
             return 0;
         }
 
+        // Get course list
         $query = "SELECT * FROM course";
         $result = $conn->executeQuery($query);
         $courseList = $result->fetchAll();
@@ -312,6 +312,7 @@ class UpgradeCommand extends CommonCommand
             }
         }
 
+        // Update chamilo files
         if ($dryRun == false) {
             $this->copyPackageIntoSystem($output, $chamiloLocationPath, null);
             if ($version == '1.10.0') {
@@ -343,7 +344,9 @@ class UpgradeCommand extends CommonCommand
         $input = new ArrayInput($arguments);
         $command->run($input, $output);
 
-        $this->updateConfiguration($output, $dryRun, array('system_version' => $version));
+        // Update configuration file new system_version
+        $newParams = array('system_version' => $version);
+        $this->updateConfiguration($output, $dryRun, $newParams);
 
         $output->writeln("<comment>Hurrah!!! You just finish to migrate. Too check the current status of your platform. Run </comment><info>chamilo:status</info>");
     }
@@ -383,6 +386,55 @@ class UpgradeCommand extends CommonCommand
             $this->processQueryList($courseList, $output, $path, $toVersion, $dryRun, 'pre');
         }
 
+        try {
+            // Doctrine migrations:
+
+            $output->writeln('');
+            $output->writeln("<comment>You have to select 'yes' for the 'Chamilo Migrations'<comment>");
+
+            $command = $this->getApplication()->find('migrations:migrate');
+            $arguments = array(
+                'command' => 'migrations:migrate',
+                'version' => $versionInfo['hook_to_doctrine_version'],
+                '--configuration' => $this->getMigrationConfigurationFile(),
+                '--dry-run' => $dryRun
+            );
+
+            $output->writeln("<comment>Executing migrations:migrate ".$versionInfo['hook_to_doctrine_version']." --configuration=".$this->getMigrationConfigurationFile()."<comment>");
+            $input = new ArrayInput($arguments);
+            if ($this->commandLine == false) {
+                $input->setInteractive(false);
+            }
+            $command->run($input, $output);
+
+            $output->writeln("<comment>Migration ended successfully</comment>");
+
+        } catch (\Exception $e) {
+            // Reverting changes
+
+            /*$output->writeln("<comment>Reverting changes ... <comment>");
+
+            $command = $this->getApplication()->find('migrations:execute');
+            $arguments = array(
+                'command' => 'migrations:execute',
+                'version' => $versionInfo['hook_to_doctrine_version'],
+                '--down' => true,
+                '--configuration' => $this->getMigrationConfigurationFile(),
+                '--dry-run' => $dryRun
+            );
+
+            $output->writeln("<comment>Executing migrations:migrate ".($versionInfo['hook_to_doctrine_version'] - 1)."<comment>");
+            $input = new ArrayInput($arguments);
+            if ($this->commandLine == false) {
+                $input->setInteractive(false);
+            }
+            $command->run($input, $output);
+            */
+            $output->write(sprintf('<error>Migration failed. Error %s</error>', $e->getMessage()));
+
+            throw $e;
+        }
+
         // Processing "db" changes.
         if (isset($versionInfo['update_db']) && !empty($versionInfo['update_db'])) {
             $sqlToInstall = $installPath.$versionInfo['update_db'];
@@ -393,8 +445,9 @@ class UpgradeCommand extends CommonCommand
                     $output->writeln("<comment>Executing update db: <info>'$sqlToInstall'</info>");
                 }
                 require $sqlToInstall;
+
                 if (!empty($update)) {
-                    $update($_configuration, $conn, $courseList, $dryRun, $output);
+                    $update($_configuration, $conn, $courseList, $dryRun, $output, $this);
                 }
             }
         }
@@ -407,9 +460,11 @@ class UpgradeCommand extends CommonCommand
                     $output->writeln("<comment>Files to be executed but dry-run is on: <info>'$sqlToInstall'</info>");
                 } else {
                     $output->writeln("<comment>Executing update files: <info>'$sqlToInstall'</info>");
+
                     require $sqlToInstall;
+
                     if (!empty($updateFiles)) {
-                        $updateFiles($_configuration, $conn, $courseList, $dryRun, $output);
+                        $updateFiles($_configuration, $conn, $courseList, $dryRun, $output, $this);
                     }
                 }
             }
@@ -423,30 +478,6 @@ class UpgradeCommand extends CommonCommand
             $this->processQueryList($courseList, $output, $path, $toVersion, $dryRun, 'post');
         }
 
-        if (1) {
-            // Doctrine migrations:
-
-            $output->writeln('');
-            $output->writeln("<comment>You have to select 'yes' for the 'Chamilo Migrations'<comment>");
-
-            $command = $this->getApplication()->find('migrations:migrate');
-            $arguments = array(
-                'command' => 'migrations:migrate',
-                'version' => $versionInfo['hook_to_doctrine_version'],
-                '--configuration' => $this->getMigrationConfigurationFile(),
-                '--dry-run' => $dryRun
-            );
-
-            $output->writeln("<comment>Executing migrations:migrate ".$versionInfo['hook_to_doctrine_version']." --configuration=".$this->getMigrationConfigurationFile()."<comment>");
-            $input = new ArrayInput($arguments);
-            if ($this->commandLine == false) {
-                $input->setInteractive(false);
-            }
-            $command->run($input, $output);
-
-            $output->writeln("<comment>Migration ended successfully</comment>");
-        }
-
         return false;
     }
 
@@ -494,7 +525,7 @@ class UpgradeCommand extends CommonCommand
                     !empty($this->queryList[$type][$section])
                 ) {
                     $queryList = $this->queryList[$type][$section];
-                    //$output->writeln("<comment>Loading query list: $type - $section </comment>");
+                    $output->writeln("<comment>Loading query list: '$type' - '$section'</comment>");
 
                     if (!empty($queryList)) {
 
@@ -617,9 +648,7 @@ class UpgradeCommand extends CommonCommand
     public function generateDatabaseList($courseList)
     {
         $courseDbList = array();
-
         $_configuration = $this->getConfigurationArray();
-
         if (!empty($courseList)) {
             foreach ($courseList as $course) {
                 if (!empty($course['db_name'])) {
@@ -638,7 +667,6 @@ class UpgradeCommand extends CommonCommand
                     'prefix' => null
                 )
             );
-
         }
 
         $databaseSection = array(
@@ -686,11 +714,10 @@ class UpgradeCommand extends CommonCommand
      */
     public function getDatabaseList($output, $courseList, $path, $version, $type)
     {
-        $configurationPath = $this->getHelper('configuration')->getConfigurationPath($path);
-        $newConfigurationFile = $configurationPath.'db_migration_status_'.$version.'_'.$type.'.yml';
-
         return $this->generateDatabaseList($courseList);
 
+        $configurationPath = $this->getHelper('configuration')->getConfigurationPath($path);
+        $newConfigurationFile = $configurationPath.'db_migration_status_'.$version.'_'.$type.'.yml';
         if (file_exists($newConfigurationFile)) {
             $yaml = new Parser();
             $output->writeln("<comment>Loading database list status from file:</comment> <info>$newConfigurationFile</info>");
@@ -791,7 +818,7 @@ class UpgradeCommand extends CommonCommand
         //prepare the resulting array
         $section_contents = array();
         $record = false;
-        foreach ($file_contents as $index => $line) {
+        foreach ($file_contents as $line) {
             if (substr($line, 0, 2) == '--') {
                 //This is a comment. Check if section name, otherwise ignore
                 $result = array();

+ 32 - 3
vendor/chamilo/chash/src/Chash/Helpers/ConfigurationHelper.php

@@ -24,11 +24,17 @@ class ConfigurationHelper extends Helper
 
     }
 
+    /**
+     * @return bool
+     */
     public function getDryRun()
     {
         return $this->dryRun;
     }
 
+    /**
+     * @param $dryRun
+     */
     public function setDryRun($dryRun)
     {
         $this->dryRun = $dryRun;
@@ -349,23 +355,36 @@ class ConfigurationHelper extends Helper
         return $finder;
     }
 
+    /**
+     * @return Finder
+     */
     public function getSysFolders()
     {
         $finder = new Finder();
         $sysPath = $this->getSysPath();
         $finder->directories()->in($sysPath);
+        // Skipping files
+        $finder->notPath('vendor');
+        $finder->notPath('tests');
         return $finder;
     }
 
+    /**
+     * @return Finder
+     */
     public function getSysFiles()
     {
         $finder = new Finder();
         $sysPath = $this->getSysPath();
         $finder->files()->in($sysPath);
+        $finder->notPath('vendor');
+        $finder->notPath('tests');
         return $finder;
     }
 
-
+    /**
+     * @return Finder
+     */
     public function getDataFolders()
     {
         $finder = new Finder();
@@ -377,6 +396,9 @@ class ConfigurationHelper extends Helper
 
     }
 
+    /**
+     * @return Finder
+     */
     public function getConfigFolders()
     {
         $finder = new Finder();
@@ -387,6 +409,9 @@ class ConfigurationHelper extends Helper
         return $finder;
     }
 
+    /**
+     * @return Finder
+     */
     public function getTempFolders()
     {
         $finder = new Finder();
@@ -402,6 +427,9 @@ class ConfigurationHelper extends Helper
         $this->sysPath = $sysPath;
     }
 
+    /**
+     * @return array
+     */
     public function getTempFolderList()
     {
         // Copied from the resources/prod.php file in Chamilo
@@ -458,6 +486,9 @@ class ConfigurationHelper extends Helper
         return $app['temp.paths']->folders;
     }
 
+    /**
+     * @return string
+     */
     public function getSysPath()
     {
         return $this->sysPath;
@@ -552,6 +583,4 @@ class ConfigurationHelper extends Helper
     {
         return 'configuration';
     }
-
-
 }

+ 251 - 0
vendor/chamilo/chash/src/Chash/Migrations/Version10.php

@@ -17,6 +17,257 @@ class Version10 extends AbstractMigration
      */
     public function up(Schema $schema)
     {
+        $trackDefaultTable = $schema->getTable('track_e_default');
+        $trackDefaultTable->addColumn('session_id', 'integer', array('default' => 0, 'Notnull' => true));
+
+        $this->addSql('ALTER TABLE notification ADD COLUMN sender_id INT NOT NULL DEFAULT 0');
+        $this->addSql('ALTER TABLE session_rel_user ADD COLUMN moved_to INT NOT NULL DEFAULT 0');
+        $this->addSql('ALTER TABLE session_rel_user ADD COLUMN moved_status INT NOT NULL DEFAULT 0');
+        $this->addSql('ALTER TABLE session_rel_user ADD COLUMN moved_at datetime NOT NULL default "0000-00-00 00:00:00"');
+        $this->addSql('ALTER TABLE session ADD COLUMN display_start_date datetime NOT NULL default "0000-00-00 00:00:00"');
+        $this->addSql('ALTER TABLE session ADD COLUMN display_end_date datetime NOT NULL default "0000-00-00 00:00:00"');
+        $this->addSql('ALTER TABLE session ADD COLUMN access_start_date datetime NOT NULL default "0000-00-00 00:00:00"');
+        $this->addSql('ALTER TABLE session ADD COLUMN access_end_date datetime NOT NULL default "0000-00-00 00:00:00"');
+        $this->addSql('ALTER TABLE session ADD COLUMN coach_access_start_date datetime NOT NULL default "0000-00-00 00:00:00"');
+        $this->addSql('ALTER TABLE session ADD COLUMN coach_access_end_date datetime NOT NULL default "0000-00-00 00:00:00"');
+        $this->addSql('ALTER TABLE grade_components ADD COLUMN prefix VARCHAR(255) DEFAULT NULL');
+        $this->addSql('ALTER TABLE grade_components  ADD COLUMN exclusions VARCHAR(255) DEFAULT NULL');
+        $this->addSql('ALTER TABLE grade_components ADD COLUMN count_elements VARCHAR(255) DEFAULT NULL');
+        $this->addSql('ALTER TABLE track_e_online ADD INDEX idx_trackonline_uat (login_user_id, access_url_id, login_date)');
+
+        $this->addSql('ALTER TABLE session_field_options ADD INDEX idx_session_field_options_field_id(field_id)');
+        $this->addSql('ALTER TABLE session_field_values ADD INDEX idx_session_field_values_session_id(session_id)');
+        $this->addSql('ALTER TABLE session_field_values ADD INDEX idx_session_field_values_field_id(field_id)');
+
+        $this->addSql('ALTER TABLE session MODIFY COLUMN session_category_id int default NULL');
+        $this->addSql('ALTER TABLE session MODIFY COLUMN name CHAR(150) NOT NULL DEFAULT ""');
+        $this->addSql('ALTER TABLE session MODIFY COLUMN id INT unsigned NOT NULL');
+        $this->addSql('ALTER TABLE session MODIFY COLUMN id INT unsigned NOT NULL auto_increment;');
+
+        $this->addSql('ALTER TABLE session_rel_course MODIFY COLUMN course_code char(40) NOT NULL');
+        $this->addSql('ALTER TABLE session_rel_course MODIFY COLUMN id_session INT unsigned NOT NULL');
+        $this->addSql('ALTER TABLE session_rel_course ADD COLUMN c_id INT NOT NULL DEFAULT "0"');
+        $this->addSql('ALTER TABLE session_rel_course ADD COLUMN id INT NOT NULL');
+        $this->addSql('ALTER TABLE session_rel_course DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE session_rel_course MODIFY COLUMN id int unsigned PRIMARY KEY AUTO_INCREMENT');
+        $this->addSql('ALTER TABLE session_rel_course ADD INDEX idx_session_rel_course_course_id (c_id)');
+
+        $this->addSql('ALTER TABLE session_rel_course_rel_user MODIFY COLUMN id_session INT unsigned NOT NULL');
+        $this->addSql('ALTER TABLE session_rel_course_rel_user ADD COLUMN c_id INT NOT NULL DEFAULT "0"');
+        $this->addSql('ALTER TABLE session_rel_course_rel_user ADD COLUMN id INT NOT NULL');
+        $this->addSql('ALTER TABLE session_rel_course_rel_user DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE session_rel_course_rel_user ADD PRIMARY KEY (id)');
+        $this->addSql('ALTER TABLE session_rel_course_rel_user ADD INDEX idx_session_rel_course_rel_user_id_user (id_user)');
+        $this->addSql('ALTER TABLE session_rel_course_rel_user ADD INDEX idx_session_rel_course_rel_user_course_id (c_id)');
+        $this->addSql('ALTER TABLE session_rel_user ADD INDEX idx_session_rel_user_id_user_moved (id_user, moved_to)');
+
+        $this->addSql('ALTER TABLE c_item_property ADD INDEX idx_itemprop_id_tool (c_id, tool(8))');
+        $this->addSql('ALTER TABLE c_quiz_answer ADD INDEX idx_quiz_answer_c_q (c_id, question_id)');
+
+        $this->addSql('ALTER TABLE c_quiz_question_rel_category MODIFY COLUMN c_id INT unsigned NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_question_rel_category MODIFY COLUMN question_id INT unsigned NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_question_rel_category DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_quiz_question_rel_category ADD COLUMN iid INT unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT');
+
+        $this->addSql('ALTER TABLE session ADD INDEX idx_id_coach (id_coach)');
+        $this->addSql('ALTER TABLE session ADD INDEX idx_id_session_admin_id (session_admin_id)');
+
+        $this->addSql('ALTER TABLE settings_current ADD INDEX idx_settings_current_au_cat (access_url, category(5))');
+
+        $this->addSql('ALTER TABLE course_module change `row` row_module int unsigned NOT NULL default "0"');
+        $this->addSql('ALTER TABLE course_module change `column` column_module int unsigned NOT NULL default "0"');
+
+        $this->addSql('ALTER TABLE c_quiz_question ADD COLUMN parent_id INT unsigned NOT NULL DEFAULT 0');
+        $this->addSql('ALTER TABLE c_quiz ADD COLUMN email_notification_template TEXT DEFAULT ""');
+        $this->addSql('ALTER TABLE c_quiz ADD COLUMN model_type INT DEFAULT 1');
+        $this->addSql('ALTER TABLE c_quiz ADD COLUMN score_type_model INT DEFAULT 0');
+        $this->addSql('ALTER TABLE gradebook_evaluation ADD COLUMN evaluation_type_id INT NOT NULL DEFAULT 0');
+        $this->addSql('ALTER TABLE gradebook_link ADD COLUMN evaluation_type_id INT NOT NULL DEFAULT 0');
+        $this->addSql('ALTER TABLE access_url ADD COLUMN url_type tinyint unsigned default 1');
+        $this->addSql('ALTER TABLE c_survey_invitation ADD COLUMN group_id INT NOT NULL DEFAULT 0');
+        $this->addSql('ALTER TABLE c_lp ADD COLUMN category_id INT unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE c_lp ADD COLUMN max_attempts INT NOT NULL default 0');
+        $this->addSql('ALTER TABLE c_lp ADD COLUMN subscribe_users INT NOT NULL default 0');
+        $this->addSql('ALTER TABLE usergroup ADD COLUMN group_type INT unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE usergroup ADD COLUMN picture varchar(255) NOT NULL');
+        $this->addSql('ALTER TABLE usergroup ADD COLUMN url varchar(255) NOT NULL');
+        $this->addSql('ALTER TABLE usergroup ADD COLUMN visibility varchar(255) NOT NULL');
+        $this->addSql('ALTER TABLE usergroup ADD COLUMN updated_on varchar(255) NOT NULL');
+        $this->addSql('ALTER TABLE usergroup ADD COLUMN created_on varchar(255) NOT NULL');
+
+        $this->addSql('ALTER TABLE course_rel_user ADD COLUMN c_id int unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE course_rel_user DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE course_rel_user ADD COLUMN id int unsigned AUTO_INCREMENT, ADD PRIMARY KEY (id)');
+        $this->addSql('ALTER TABLE course_rel_user ADD INDEX course_rel_user_c_id_user_id (c_id, user_id)');
+
+        $this->addSql('ALTER TABLE c_item_property MODIFY id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_item_property DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_item_property DROP COLUMN id');
+        $this->addSql('ALTER TABLE c_item_property ADD COLUMN id bigint unsigned NOT NULL auto_increment, ADD PRIMARY KEY (id)');
+
+        $this->addSql('ALTER TABLE c_item_property MODIFY id_session INT default NULL');
+        $this->addSql('ALTER TABLE c_item_property MODIFY COLUMN start_visible datetime default NULL');
+        $this->addSql('ALTER TABLE c_item_property MODIFY COLUMN end_visible datetime default NULL');
+
+        $this->addSql('ALTER TABLE c_group_info MODIFY id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_group_info MODIFY c_id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_group_info MODIFY session_id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_group_info DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_group_info ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY');
+
+        $this->addSql('ALTER TABLE usergroup_rel_tag ADD INDEX usergroup_rel_tag_usergroup_id ( usergroup_id )');
+        $this->addSql('ALTER TABLE usergroup_rel_tag ADD INDEX usergroup_rel_tag_tag_id (tag_id)');
+        $this->addSql('ALTER TABLE usergroup_rel_user ADD COLUMN relation_type int NOT NULL default 0');
+        $this->addSql('ALTER TABLE usergroup_rel_user ADD INDEX usergroup_rel_user_usergroup_id (usergroup_id)');
+        $this->addSql('ALTER TABLE usergroup_rel_user ADD INDEX usergroup_rel_user_user_id (user_id)');
+        $this->addSql('ALTER TABLE usergroup_rel_user ADD INDEX usergroup_rel_user_relation_type (relation_type)');
+        $this->addSql('ALTER TABLE usergroup_rel_usergroup ADD INDEX usergroup_rel_usergroup_group_id( group_id )');
+        $this->addSql('ALTER TABLE usergroup_rel_usergroup ADD INDEX usergroup_rel_usergroup_subgroup_id( subgroup_id )');
+        $this->addSql('ALTER TABLE usergroup_rel_usergroup ADD INDEX usergroup_rel_usergroup_relation_type( relation_type )');
+
+        $this->addSql('ALTER TABLE announcement_rel_group DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE announcement_rel_group ADD COLUMN id INT unsigned NOT NULL auto_increment PRIMARY KEY');
+        $this->addSql('ALTER TABLE track_e_hotpotatoes ADD COLUMN c_id int unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE track_e_exercices ADD COLUMN c_id int unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE track_e_attempt ADD COLUMN c_id int unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE track_e_hotspot ADD COLUMN c_id int unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE track_e_course_access ADD COLUMN c_id INT NOT NULL DEFAULT 0');
+        $this->addSql('ALTER TABLE access_url_rel_course ADD COLUMN c_id int unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE track_e_lastaccess ADD COLUMN c_id int unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE track_e_access ADD COLUMN c_id int unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE track_e_downloads ADD COLUMN c_id int unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE track_e_links ADD COLUMN c_id int unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE track_e_lastaccess ADD INDEX track_e_lastaccess_c_id_access_user_id (c_id, access_user_id)');
+
+        $this->addSql('ALTER TABLE access_url_rel_course DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE access_url_rel_course ADD COLUMN id int unsigned NOT NULL auto_increment PRIMARY KEY');
+
+        $this->addSql('ALTER TABLE c_quiz ADD COLUMN autolaunch int DEFAULT 0');
+        $this->addSql('RENAME TABLE c_quiz_question_category TO c_quiz_category');
+        $this->addSql('ALTER TABLE c_quiz_category ADD COLUMN parent_id int unsigned default NULL');
+
+        $this->addSql('ALTER TABLE c_quiz DROP INDEX session_id');
+        $this->addSql('ALTER TABLE c_quiz MODIFY id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz MODIFY c_id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_quiz ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY');
+
+        $this->addSql('ALTER TABLE c_quiz_question MODIFY id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_question MODIFY c_id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_question DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_quiz_question ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY');
+
+        $this->addSql('ALTER TABLE c_quiz_answer MODIFY id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_answer MODIFY c_id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_answer MODIFY id_auto INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_answer DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_quiz_answer ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_quiz_answer ADD INDEX idx_cqa_qid (question_id)');
+
+        $this->addSql('ALTER TABLE c_quiz_question_option MODIFY id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_question_option MODIFY c_id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_question_option DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_quiz_question_option ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY');
+
+        $this->addSql('ALTER TABLE c_quiz_rel_question MODIFY question_id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_rel_question MODIFY exercice_id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_rel_question DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_quiz_rel_question ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_quiz_rel_question ADD INDEX idx_cqrq_id (question_id)');
+        $this->addSql('ALTER TABLE c_quiz_rel_question ADD INDEX idx_cqrq_cidexid (c_id, exercice_id)');
+
+        $this->addSql('ALTER TABLE c_quiz_category MODIFY id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_category MODIFY c_id INT NOT NULL');
+        $this->addSql('ALTER TABLE c_quiz_category DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_quiz_category ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY');
+
+        $this->addSql('ALTER TABLE question_field_options ADD INDEX idx_question_field_options_field_id(field_id)');
+        $this->addSql('ALTER TABLE question_field_values ADD INDEX idx_question_field_values_question_id(question_id)');
+        $this->addSql('ALTER TABLE question_field_values ADD INDEX idx_question_field_values_field_id(field_id)');
+
+        $this->addSql('ALTER TABLE question_field_values ADD COLUMN user_id INT unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE session_field_values ADD COLUMN user_id INT unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE course_field_values ADD COLUMN user_id INT unsigned NOT NULL default 0');
+        $this->addSql('ALTER TABLE user_field_values ADD COLUMN author_id INT unsigned NOT NULL default 0');
+
+        $this->addSql('ALTER TABLE c_quiz_category ADD COLUMN lvl int');
+        $this->addSql('ALTER TABLE c_quiz_category ADD COLUMN lft int');
+        $this->addSql('ALTER TABLE c_quiz_category ADD COLUMN rgt int');
+        $this->addSql('ALTER TABLE c_quiz_category ADD COLUMN root int');
+        $this->addSql('ALTER TABLE c_quiz_category MODIFY COLUMN parent_id int default null');
+
+        $this->addSql('ALTER TABLE track_e_course_access MODIFY COLUMN course_access_id bigint unsigned auto_increment');
+        $this->addSql('ALTER TABLE user_field ADD COLUMN field_loggeable int default 0');
+        $this->addSql('ALTER TABLE session_field ADD COLUMN field_loggeable int default 0');
+        $this->addSql('ALTER TABLE course_field ADD COLUMN field_loggeable int default 0');
+        $this->addSql('ALTER TABLE question_field ADD COLUMN field_loggeable int default 0');
+
+        $this->addSql('ALTER TABLE user_field_values ADD COLUMN comment VARCHAR(100) default ""');
+        $this->addSql('ALTER TABLE session_field_values ADD COLUMN comment VARCHAR(100) default ""');
+        $this->addSql('ALTER TABLE course_field_values ADD COLUMN comment VARCHAR(100) default ""');
+        $this->addSql('ALTER TABLE question_field_values ADD COLUMN comment VARCHAR(100) default ""');
+        $this->addSql('ALTER TABLE c_quiz ADD COLUMN end_button int NOT NULL default 0');
+        $this->addSql('ALTER TABLE user ADD COLUMN salt VARCHAR(255) DEFAULT NULL');
+
+        $this->addSql('ALTER TABLE question_field_options ADD COLUMN priority INT default NULL');
+        $this->addSql('ALTER TABLE course_field_options ADD COLUMN priority INT default NULL');
+        $this->addSql('ALTER TABLE user_field_options ADD COLUMN priority INT default NULL');
+        $this->addSql('ALTER TABLE session_field_options ADD COLUMN priority INT default NULL');
+
+        $this->addSql('ALTER TABLE question_field_options ADD COLUMN priority_message varchar(255) default NULL');
+        $this->addSql('ALTER TABLE course_field_options ADD COLUMN priority_message varchar(255) default NULL');
+        $this->addSql('ALTER TABLE user_field_options ADD COLUMN priority_message varchar(255) default NULL');
+        $this->addSql('ALTER TABLE session_field_options ADD COLUMN priority_message varchar(255) default NULL');
+
+        $this->addSql('ALTER TABLE c_announcement CHANGE id id int unsigned not null');
+        $this->addSql('ALTER TABLE c_announcement DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_announcement add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST');
+        $this->addSql('ALTER TABLE c_announcement add UNIQUE KEY(c_id,id)');
+        $this->addSql('ALTER TABLE c_announcement ENGINE = InnoDB');
+        $this->addSql('ALTER TABLE c_announcement_attachment CHANGE id id int unsigned not null');
+        $this->addSql('ALTER TABLE c_announcement_attachment DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_announcement_attachment add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST');
+        $this->addSql('ALTER TABLE c_announcement_attachment add UNIQUE KEY(c_id,id)');
+        $this->addSql('ALTER TABLE c_announcement_attachment ENGINE = InnoDB');
+        $this->addSql('ALTER TABLE c_attendance CHANGE id id int unsigned not null');
+        $this->addSql('ALTER TABLE c_attendance DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_attendance add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST');
+        $this->addSql('ALTER TABLE c_attendance add UNIQUE KEY(c_id,id)');
+        $this->addSql('ALTER TABLE c_attendance ENGINE = InnoDB');
+        $this->addSql('ALTER TABLE c_attendance_calendar CHANGE id id int unsigned not null');
+        $this->addSql('ALTER TABLE c_attendance_calendar DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_attendance_calendar add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST');
+        $this->addSql('ALTER TABLE c_attendance_calendar add UNIQUE KEY(c_id,id)');
+        $this->addSql('ALTER TABLE c_attendance_calendar ENGINE = InnoDB');
+        $this->addSql('ALTER TABLE c_attendance_result CHANGE id id int unsigned not null');
+        $this->addSql('ALTER TABLE c_attendance_result DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_attendance_result add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST');
+        $this->addSql('ALTER TABLE c_attendance_result add UNIQUE KEY(c_id,id)');
+        $this->addSql('ALTER TABLE c_attendance_result ENGINE = InnoDB');
+        $this->addSql('ALTER TABLE c_attendance_sheet DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_attendance_sheet add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST');
+        $this->addSql('ALTER TABLE c_attendance_sheet add UNIQUE KEY(c_id,user_id,attendance_calendar_id)');
+        $this->addSql('ALTER TABLE c_attendance_sheet ENGINE = InnoDB');
+        $this->addSql('ALTER TABLE c_attendance_sheet_log CHANGE id id int unsigned not null');
+        $this->addSql('ALTER TABLE c_attendance_sheet_log DROP PRIMARY KEY');
+        $this->addSql('ALTER TABLE c_attendance_sheet_log add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST');
+        $this->addSql('ALTER TABLE c_attendance_sheet_log add UNIQUE KEY(c_id,id)');
+        $this->addSql('ALTER TABLE c_attendance_sheet_log ENGINE = InnoDB');
+        $this->addSql('ALTER TABLE session ADD COLUMN description TEXT');
+        $this->addSql('ALTER TABLE session ADD COLUMN show_description int default NULL');
+
+        $this->addSql('ALTER TABLE c_quiz_category ADD COLUMN visibility INT default 1');
+        $this->addSql('ALTER TABLE c_quiz_question ADD INDEX idx_c_q_qst_cpt (c_id, parent_id, type)');
+        $this->addSql('ALTER TABLE c_quiz_question_rel_category ADD INDEX idx_c_q_qst_r_cat_qc(question_id, c_id)');
+        $this->addSql('ALTER TABLE c_quiz ADD COLUMN question_selection_type INT DEFAULT 1');
+        $this->addSql('ALTER TABLE c_quiz ADD COLUMN hide_question_title INT DEFAULT 0');
+        $this->addSql('ALTER TABLE c_quiz ADD COLUMN global_category_id INT DEFAULT NULL');
+
+        $this->addSql('ALTER TABLE user MODIFY COLUMN chatcall_user_id int unsigned default 0');
+        $this->addSql('ALTER TABLE user MODIFY COLUMN chatcall_date datetime default NULL');
+        $this->addSql('ALTER TABLE user MODIFY COLUMN chatcall_text varchar(50) default NULL');
+        $this->addSql('ALTER TABLE user MODIFY COLUMN expiration_date datetime default NULL');
+
         $this->addSql(
             "UPDATE settings_current SET selected_value = '1.10.0' WHERE variable = 'chamilo_database_version'"
         );

+ 6 - 0
vendor/chamilo/chash/src/Chash/Migrations/Version11.php

@@ -11,11 +11,17 @@ use Doctrine\DBAL\Migrations\AbstractMigration,
  */
 class Version11 extends AbstractMigration
 {
+    /**
+     * @param Schema $schema
+     */
     public function up(Schema $schema)
     {
         $this->addSql('UPDATE settings_current SET selected_value = "1.11.final" WHERE variable = "chamilo_database_version"');
     }
 
+    /**
+     * @param Schema $schema
+     */
     public function down(Schema $schema)
     {
         $this->addSql('UPDATE settings_current SET selected_value = "1.10" WHERE variable = "chamilo_database_version"');

+ 9 - 61
vendor/chamilo/chash/src/Chash/Resources/Database/1.10.0/db_main.sql

@@ -381,8 +381,8 @@ CREATE TABLE IF NOT EXISTS course_rel_user (
   legal_agreement INTEGER DEFAULT 0,
   PRIMARY KEY(id)
 );
-ALTER TABLE course_rel_user ADD INDEX (user_id);
-ALTER TABLE course_rel_user ADD INDEX (c_id, user_id);
+ALTER TABLE course_rel_user ADD INDEX course_rel_user_user_id (user_id);
+ALTER TABLE course_rel_user ADD INDEX course_rel_user_c_id_user_id (c_id, user_id);
 
 --
 -- Dumping data for table course_rel_user
@@ -958,6 +958,7 @@ VALUES
 ('session_page_enabled', NULL, 'radio', 'Session', 'true', 'SessionPageEnabledTitle', 'SessionPageEnabledComment', NULL, NULL, 1),
 ('settings_latest_update', NULL, NULL, NULL, '', '','', NULL, NULL, 0),
 ('user_name_order', NULL, 'textfield', 'Platform', '', 'UserNameOrderTitle', 'UserNameOrderComment', NULL, NULL, 1),
+('user_name_sort_by', NULL, 'textfield', 'Platform', '', 'UserNameSortByTitle', 'UserNameSortByComment', NULL, NULL, 1),
 ('allow_teachers_to_create_sessions', NULL,'radio','Session','false','AllowTeachersToCreateSessionsTitle','AllowTeachersToCreateSessionsComment', NULL, NULL, 0),
 ('use_virtual_keyboard', NULL, 'radio', 'Platform', 'false','ShowVirtualKeyboardTitle','ShowVirtualKeyboardComment', NULL, NULL, 1),
 ('disable_copy_paste', NULL, 'radio', 'Platform', 'false','DisableCopyPasteTitle','DisableCopyPasteComment', NULL, NULL, 1),
@@ -2849,8 +2850,8 @@ CREATE TABLE IF NOT EXISTS usergroup_rel_tag(
     PRIMARY KEY (id)
 );
 
-ALTER TABLE usergroup_rel_tag ADD INDEX ( usergroup_id );
-ALTER TABLE usergroup_rel_tag ADD INDEX ( tag_id );
+ALTER TABLE usergroup_rel_tag ADD INDEX usergroup_rel_tag_usergroup_id( usergroup_id );
+ALTER TABLE usergroup_rel_tag ADD INDEX usergroup_rel_tag_tag_id ( tag_id );
 
 DROP TABLE IF EXISTS usergroup_rel_usergroup;
 CREATE TABLE IF NOT EXISTS usergroup_rel_usergroup (
@@ -2861,9 +2862,9 @@ CREATE TABLE IF NOT EXISTS usergroup_rel_usergroup (
 	PRIMARY KEY (id)
 );
 
-ALTER TABLE usergroup_rel_usergroup ADD INDEX ( group_id );
-ALTER TABLE usergroup_rel_usergroup ADD INDEX ( subgroup_id );
-ALTER TABLE usergroup_rel_usergroup ADD INDEX ( relation_type );
+ALTER TABLE usergroup_rel_usergroup ADD INDEX usergroup_rel_usergroup_group_id (group_id );
+ALTER TABLE usergroup_rel_usergroup ADD INDEX usergroup_rel_usergroup_subgroup_id ( subgroup_id );
+ALTER TABLE usergroup_rel_usergroup ADD INDEX usergroup_rel_usergroup_relation_type ( relation_type );
 
 --
 -- Structure for Mail notifications
@@ -3142,50 +3143,6 @@ CREATE TABLE IF NOT EXISTS branch_transaction_data (
     data text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL
 );
 
-
--- Stats database
-
-DROP TABLE IF EXISTS track_c_browsers;
-CREATE TABLE track_c_browsers (
-  id int NOT NULL auto_increment,
-  browser varchar(255) NOT NULL default '',
-  counter int NOT NULL default 0,
-  PRIMARY KEY  (id)
-);
-
-DROP TABLE IF EXISTS track_c_countries;
-CREATE TABLE track_c_countries (
-  id int NOT NULL auto_increment,
-  code varchar(40) NOT NULL default '',
-  country varchar(50) NOT NULL default '',
-  counter int NOT NULL default 0,
-  PRIMARY KEY  (id)
-);
-
-DROP TABLE IF EXISTS track_c_os;
-CREATE TABLE track_c_os (
-  id int NOT NULL auto_increment,
-  os varchar(255) NOT NULL default '',
-  counter int NOT NULL default 0,
-  PRIMARY KEY  (id)
-);
-
-DROP TABLE IF EXISTS track_c_providers;
-CREATE TABLE track_c_providers (
-  id int NOT NULL auto_increment,
-  provider varchar(255) NOT NULL default '',
-  counter int NOT NULL default 0,
-  PRIMARY KEY  (id)
-);
-
-DROP TABLE IF EXISTS track_c_referers;
-CREATE TABLE track_c_referers (
-  id int NOT NULL auto_increment,
-  referer varchar(255) NOT NULL default '',
-  counter int NOT NULL default 0,
-  PRIMARY KEY (id)
-);
-
 DROP TABLE IF EXISTS track_e_access;
 CREATE TABLE track_e_access (
   access_id int NOT NULL auto_increment,
@@ -3346,15 +3303,6 @@ CREATE TABLE track_e_online (
   PRIMARY KEY  (login_id),
   KEY login_user_id (login_user_id)
 );
-DROP TABLE IF EXISTS track_e_open;
-CREATE TABLE track_e_open (
-  open_id int NOT NULL auto_increment,
-  open_remote_host tinytext NOT NULL,
-  open_agent tinytext NOT NULL,
-  open_referer tinytext NOT NULL,
-  open_date datetime NOT NULL default '0000-00-00 00:00:00',
-  PRIMARY KEY  (open_id)
-);
 
 DROP TABLE IF EXISTS track_e_uploads;
 CREATE TABLE track_e_uploads (
@@ -3632,4 +3580,4 @@ CREATE TABLE curriculum_rel_user (
 
 
 -- Do not move this
-UPDATE settings_current SET selected_value = '1.10.0.043' WHERE variable = 'chamilo_database_version';
+UPDATE settings_current SET selected_value = '1.10.0.044' WHERE variable = 'chamilo_database_version';

+ 15 - 11
vendor/chamilo/chash/src/Chash/Resources/Database/1.10.0/migrate-db-1.9.0-1.10.0-post.sql

@@ -15,7 +15,6 @@
 
 -- ALTER TABLE session_rel_course DROP COLUMN course_code;
 -- ALTER TABLE session_rel_course_rel_user DROP COLUMN course_code;
-
 -- ALTER TABLE track_e_hotpotatoes DROP COLUMN course_code;
 -- ALTER TABLE track_e_exercices DROP COLUMN course_code;
 -- ALTER TABLE track_e_attempt DROP COLUMN course_code;
@@ -23,16 +22,21 @@
 -- ALTER TABLE track_e_course_access DROP COLUMN course_code;
 -- ALTER TABLE access_url_rel_course DROP COLUMN course_code;
 -- ALTER TABLE course_rel_user DROP COLUMN course_code;
-
 -- ALTER TABLE track_e_lastaccess DROP COLUMN access_cours_code;
 
-ALTER TABLE track_e_lastaccess DROP COLUMN access_cours_code;
-ALTER TABLE track_e_access    DROP COLUMN access_cours_code ;
-ALTER TABLE track_e_course_access DROP COLUMN  course_code;
-ALTER TABLE track_e_downloads DROP COLUMN  down_cours_id;
-
-ALTER TABLE track_e_links DROP COLUMN  links_cours_id;
-
-ALTER TABLE session DROP COLUMN date_start;
-ALTER TABLE session DROP COLUMN date_end;
+DROP TABLE IF EXISTS track_c_referers;
+DROP TABLE IF EXISTS track_c_providers;
+DROP TABLE IF EXISTS track_c_os;
+DROP TABLE IF EXISTS track_c_countries;
+DROP TABLE IF EXISTS track_c_browsers;
+DROP TABLE IF EXISTS track_e_open;
+
+--ALTER TABLE track_e_lastaccess DROP COLUMN access_cours_code;
+--ALTER TABLE track_e_access    DROP COLUMN access_cours_code ;
+--ALTER TABLE track_e_course_access DROP COLUMN course_code;
+--ALTER TABLE track_e_downloads DROP COLUMN  down_cours_id;
+--ALTER TABLE track_e_links DROP COLUMN links_cours_id;
+
+--ALTER TABLE session DROP COLUMN date_start;
+--ALTER TABLE session DROP COLUMN date_end;
 

+ 61 - 278
vendor/chamilo/chash/src/Chash/Resources/Database/1.10.0/migrate-db-1.9.0-1.10.0-pre.sql

@@ -15,7 +15,6 @@
 
 -- Optimize tracking query very often queried on busy campuses
 
-
 CREATE TABLE IF NOT EXISTS session_field_options (id int NOT NULL auto_increment, field_id int NOT NULL, option_value text, option_display_text varchar(255), option_order int, tms DATETIME NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (id));
 CREATE TABLE IF NOT EXISTS course_field_options (id int NOT NULL auto_increment, field_id int NOT NULL, option_value text, option_display_text varchar(255), option_order int, tms DATETIME NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (id));
 CREATE TABLE IF NOT EXISTS c_quiz_order( iid bigint unsigned NOT NULL auto_increment, c_id int unsigned NOT NULL, session_id int unsigned NOT NULL, exercise_id int NOT NULL, exercise_order INT NOT NULL, PRIMARY KEY (iid));
@@ -35,338 +34,122 @@ CREATE TABLE IF NOT EXISTS roles (id INT auto_increment, name VARCHAR(255), role
 CREATE TABLE IF NOT EXISTS users_roles (user_id INT NOT NULL, role_id INT NOT NULL, PRIMARY KEY(user_id, role_id));
 CREATE TABLE IF NOT EXISTS usergroup_rel_tag( id int NOT NULL AUTO_INCREMENT, tag_id int NOT NULL, usergroup_id int NOT NULL, PRIMARY KEY (id));
 CREATE TABLE IF NOT EXISTS usergroup_rel_usergroup (id int NOT NULL AUTO_INCREMENT, group_id int NOT NULL, subgroup_id int NOT NULL, relation_type int NOT NULL, PRIMARY KEY (id));
-
 CREATE TABLE IF NOT EXISTS branch_sync( id int unsigned not null AUTO_INCREMENT PRIMARY KEY, access_url_id int unsigned not null, branch_name varchar(250) default '', branch_ip varchar(40) default '', latitude decimal(15,7), longitude decimal(15,7), dwn_speed int unsigned default null, up_speed int unsigned default null, delay int unsigned default null, admin_mail varchar(250) default '', admin_name varchar(250) default '', admin_phone varchar(250) default '', last_sync_trans_id bigint unsigned default 0, last_sync_trans_date datetime, last_sync_type char(20) default 'full');
 CREATE TABLE IF NOT EXISTS branch_sync_log( id bigint unsigned not null AUTO_INCREMENT PRIMARY KEY, branch_sync_id int unsigned not null, sync_trans_id bigint unsigned default 0, sync_trans_date datetime, sync_type char(20));
 CREATE TABLE IF NOT EXISTS branch_transaction_status (id tinyint not null PRIMARY KEY AUTO_INCREMENT,  title char(20));
 CREATE TABLE IF NOT EXISTS branch_transaction (id bigint unsigned not null AUTO_INCREMENT, transaction_id bigint unsigned, branch_id int unsigned not null default 0,  action char(20),  item_id char(36),  orig_id char(36),  dest_id char(36),  info char(20), status_id tinyint not null default 0,  time_insert datetime NOT NULL DEFAULT '0000-00-00 00:00:00',  time_update datetime NOT NULL DEFAULT '0000-00-00 00:00:00', message VARCHAR(255) default '' , PRIMARY KEY (id, transaction_id, branch_id));
 
-ALTER TABLE track_e_online ADD INDEX idx_trackonline_uat (login_user_id, access_url_id, login_date);
-ALTER TABLE track_e_default ADD COLUMN session_id INT NOT NULL DEFAULT 0;
-ALTER TABLE notification ADD COLUMN sender_id INT NOT NULL DEFAULT 0;
-ALTER TABLE session_rel_user ADD COLUMN moved_to INT NOT NULL DEFAULT 0;
-ALTER TABLE session_rel_user ADD COLUMN moved_status INT NOT NULL DEFAULT 0;
-ALTER TABLE session_rel_user ADD COLUMN moved_at datetime NOT NULL default '0000-00-00 00:00:00';
-
-ALTER TABLE session ADD COLUMN display_start_date datetime default '0000-00-00 00:00:00';
-ALTER TABLE session ADD COLUMN display_end_date datetime default '0000-00-00 00:00:00';
-ALTER TABLE session ADD COLUMN access_start_date datetime default '0000-00-00 00:00:00';
-ALTER TABLE session ADD COLUMN access_end_date datetime default '0000-00-00 00:00:00';
-ALTER TABLE session ADD COLUMN coach_access_start_date datetime default '0000-00-00 00:00:00';
-ALTER TABLE session ADD COLUMN coach_access_end_date datetime default '0000-00-00 00:00:00';
-ALTER TABLE session MODIFY COLUMN session_category_id int default NULL;
-
-ALTER TABLE grade_components ADD COLUMN prefix VARCHAR(255) DEFAULT NULL;
-ALTER TABLE grade_components ADD COLUMN exclusions INT DEFAULT 0;
-ALTER TABLE grade_components ADD COLUMN count_elements INT DEFAULT 0;
-
-ALTER TABLE session_field_options ADD INDEX idx_session_field_options_field_id(field_id);
-ALTER TABLE session_field_values ADD INDEX idx_session_field_values_session_id(session_id);
-ALTER TABLE session_field_values ADD INDEX idx_session_field_values_field_id(field_id);
-
-ALTER TABLE session MODIFY COLUMN name CHAR(150) NOT NULL DEFAULT '';
-ALTER TABLE session MODIFY COLUMN id INT unsigned NOT NULL;
-
-ALTER TABLE session_rel_course MODIFY COLUMN course_code char(40) NOT NULL;
-ALTER TABLE session_rel_course MODIFY COLUMN id_session INT unsigned NOT NULL;
-ALTER TABLE session_rel_course DROP PRIMARY KEY;
-ALTER TABLE session_rel_course ADD COLUMN c_id INT NOT NULL DEFAULT '0';
-
--- remove course_code
-ALTER TABLE session_rel_course ADD COLUMN id INT NOT NULL;
-ALTER TABLE session_rel_course MODIFY COLUMN id int unsigned PRIMARY KEY AUTO_INCREMENT;
-ALTER TABLE session_rel_course ADD INDEX idx_session_rel_course_course_id (c_id);
-
-ALTER TABLE session_rel_course_rel_user MODIFY COLUMN id_session INT unsigned NOT NULL;
-ALTER TABLE session_rel_course_rel_user ADD COLUMN c_id INT NOT NULL DEFAULT '0';
-ALTER TABLE session_rel_course_rel_user ADD COLUMN id INT NOT NULL;
-ALTER TABLE session_rel_course_rel_user DROP PRIMARY KEY;
-ALTER TABLE session_rel_course_rel_user ADD PRIMARY KEY (id);
-ALTER TABLE session_rel_course_rel_user ADD INDEX idx_session_rel_course_rel_user_id_user (id_user);
-ALTER TABLE session_rel_course_rel_user ADD INDEX idx_session_rel_course_rel_user_course_id (c_id);
-ALTER TABLE session_rel_user ADD INDEX idx_session_rel_user_id_user_moved (id_user, moved_to);
-
 -- ALTER TABLE c_lp_item ADD INDEX idx_c_lp_item_cid_lp_id (c_id, lp_id);
 -- ALTER TABLE c_lp_item_view ADD INDEX idx_c_lp_item_view_cid_lp_view_id_lp_item_id(c_id, lp_view_id, lp_item_id);
 
-ALTER TABLE c_item_property ADD INDEX idx_itemprop_id_tool (c_id, tool(8));
 ALTER TABLE c_tool_intro MODIFY COLUMN intro_text MEDIUMTEXT NOT NULL;
-ALTER TABLE c_quiz_answer ADD INDEX idx_quiz_answer_c_q (c_id, question_id);
-
-ALTER TABLE c_quiz_question_rel_category MODIFY COLUMN c_id INT unsigned NOT NULL;
-ALTER TABLE c_quiz_question_rel_category MODIFY COLUMN question_id INT unsigned NOT NULL;
-ALTER TABLE c_quiz_question_rel_category DROP PRIMARY KEY;
-ALTER TABLE c_quiz_question_rel_category ADD COLUMN iid INT unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT;
-
-ALTER TABLE session ADD INDEX idx_id_coach (id_coach);
-ALTER TABLE session ADD INDEX idx_id_session_admin_id (session_admin_id);
-
-ALTER TABLE c_quiz_question ADD COLUMN parent_id INT unsigned NOT NULL DEFAULT 0;
-ALTER TABLE c_quiz ADD COLUMN email_notification_template TEXT DEFAULT '';
-ALTER TABLE c_quiz ADD COLUMN model_type INT DEFAULT 1;
-ALTER TABLE c_quiz ADD COLUMN score_type_model INT DEFAULT 0;
-
-ALTER TABLE gradebook_evaluation ADD COLUMN evaluation_type_id INT NOT NULL DEFAULT 0;
-ALTER TABLE gradebook_link ADD COLUMN evaluation_type_id INT NOT NULL DEFAULT 0;
-ALTER TABLE access_url ADD COLUMN url_type tinyint unsigned default 1;
-
-ALTER TABLE settings_current ADD INDEX idx_settings_current_au_cat (access_url, category(5));
-
-ALTER TABLE course_module change `row` row_module int unsigned NOT NULL default '0';
-ALTER TABLE course_module change `column` column_module int unsigned NOT NULL default '0';
-
-ALTER TABLE c_survey_invitation ADD COLUMN group_id INT NOT NULL DEFAULT 0;
-
-ALTER TABLE c_lp ADD COLUMN category_id INT unsigned NOT NULL default 0;
-ALTER TABLE c_lp ADD COLUMN max_attempts INT NOT NULL default 0;
-ALTER TABLE c_lp ADD COLUMN subscribe_users INT NOT NULL default 0;
 ALTER TABLE user MODIFY COLUMN hr_dept_id int unsigned default 0;
-ALTER TABLE session MODIFY COLUMN id INT unsigned NOT NULL auto_increment;
 ALTER TABLE session MODIFY COLUMN nbr_courses int unsigned NOT NULL default 0;
 ALTER TABLE session MODIFY COLUMN nbr_users int unsigned NOT NULL default 0;
 ALTER TABLE session MODIFY COLUMN nbr_classes int unsigned NOT NULL default 0;
-
 ALTER TABLE session_rel_course MODIFY COLUMN nbr_users int unsigned NOT NULL default 0;
 ALTER TABLE track_e_exercices MODIFY COLUMN session_id int unsigned NOT NULL default 0;
 ALTER TABLE track_e_exercices MODIFY COLUMN exe_exo_id int unsigned NOT NULL default 0;
 
-ALTER TABLE course_rel_user ADD COLUMN c_id int unsigned NOT NULL default 0;
-ALTER TABLE course_rel_user DROP PRIMARY KEY;
-ALTER TABLE course_rel_user ADD COLUMN id int unsigned AUTO_INCREMENT, ADD PRIMARY KEY (id);
-ALTER TABLE course_rel_user ADD INDEX (c_id, user_id);
-
-ALTER TABLE c_item_property MODIFY id INT NOT NULL;
-ALTER TABLE c_item_property DROP PRIMARY KEY;
-ALTER TABLE c_item_property DROP COLUMN id;
-ALTER TABLE c_item_property ADD COLUMN id bigint unsigned NOT NULL auto_increment, ADD PRIMARY KEY (id);
-
-ALTER TABLE c_item_property MODIFY id_session INT default NULL;
-ALTER TABLE c_item_property MODIFY COLUMN start_visible datetime default NULL;
-ALTER TABLE c_item_property MODIFY COLUMN end_visible datetime default NULL;
-
-ALTER TABLE c_group_info MODIFY id INT NOT NULL;
-ALTER TABLE c_group_info MODIFY c_id INT NOT NULL;
-ALTER TABLE c_group_info MODIFY session_id INT NOT NULL;
-ALTER TABLE c_group_info DROP PRIMARY KEY;
-ALTER TABLE c_group_info ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY;
-
-ALTER TABLE usergroup ADD COLUMN group_type INT unsigned NOT NULL default 0;
-ALTER TABLE usergroup ADD COLUMN picture varchar(255) NOT NULL;
-ALTER TABLE usergroup ADD COLUMN url varchar(255) NOT NULL;
-ALTER TABLE usergroup ADD COLUMN visibility varchar(255) NOT NULL;
-ALTER TABLE usergroup ADD COLUMN updated_on varchar(255) NOT NULL;
-ALTER TABLE usergroup ADD COLUMN created_on varchar(255) NOT NULL;
-ALTER TABLE usergroup_rel_tag ADD INDEX ( usergroup_id );
-ALTER TABLE usergroup_rel_tag ADD INDEX ( tag_id );
-ALTER TABLE usergroup_rel_user ADD relation_type int NOT NULL default 0;
-ALTER TABLE usergroup_rel_user ADD INDEX ( usergroup_id );
-ALTER TABLE usergroup_rel_user ADD INDEX ( user_id );
-ALTER TABLE usergroup_rel_user ADD INDEX ( relation_type );
-ALTER TABLE usergroup_rel_usergroup ADD INDEX ( group_id );
-ALTER TABLE usergroup_rel_usergroup ADD INDEX ( subgroup_id );
-ALTER TABLE usergroup_rel_usergroup ADD INDEX ( relation_type );
-
-ALTER TABLE announcement_rel_group DROP PRIMARY KEY;
-ALTER TABLE announcement_rel_group ADD COLUMN id INT unsigned NOT NULL auto_increment PRIMARY KEY;
-ALTER TABLE track_e_hotpotatoes ADD COLUMN c_id int unsigned NOT NULL default 0;
-ALTER TABLE track_e_exercices ADD COLUMN c_id int unsigned NOT NULL default 0;
-ALTER TABLE track_e_attempt ADD COLUMN c_id int unsigned NOT NULL default 0;
-ALTER TABLE track_e_hotspot ADD COLUMN c_id int unsigned NOT NULL default 0;
-ALTER TABLE track_e_course_access ADD COLUMN c_id INT NOT NULL DEFAULT 0;
-ALTER TABLE access_url_rel_course ADD COLUMN c_id int unsigned NOT NULL default 0;
-ALTER TABLE track_e_lastaccess ADD COLUMN c_id int unsigned NOT NULL default 0;
-ALTER TABLE track_e_access ADD COLUMN c_id int unsigned NOT NULL default 0;
-ALTER TABLE track_e_downloads ADD COLUMN c_id int unsigned NOT NULL default 0;
-ALTER TABLE track_e_links ADD COLUMN c_id int unsigned NOT NULL default 0;
-ALTER TABLE track_e_lastaccess ADD INDEX (c_id, access_user_id);
-
-ALTER TABLE access_url_rel_course DROP PRIMARY KEY;
-ALTER TABLE access_url_rel_course ADD COLUMN id int unsigned NOT NULL auto_increment PRIMARY KEY;
-
-ALTER TABLE c_quiz ADD COLUMN autolaunch int DEFAULT 0;
-RENAME TABLE c_quiz_question_category TO c_quiz_category;
-ALTER TABLE c_quiz_category ADD COLUMN parent_id int unsigned default NULL;
-
-ALTER TABLE c_quiz DROP INDEX session_id;
-ALTER TABLE c_quiz MODIFY id INT NOT NULL;
-ALTER TABLE c_quiz MODIFY c_id INT NOT NULL;
-ALTER TABLE c_quiz DROP PRIMARY KEY;
-ALTER TABLE c_quiz ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY;
-
-ALTER TABLE c_quiz_question MODIFY id INT NOT NULL;
-ALTER TABLE c_quiz_question MODIFY c_id INT NOT NULL;
-ALTER TABLE c_quiz_question DROP PRIMARY KEY;
-ALTER TABLE c_quiz_question ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY;
-
-ALTER TABLE c_quiz_answer MODIFY id INT NOT NULL;
-ALTER TABLE c_quiz_answer MODIFY c_id INT NOT NULL;
-ALTER TABLE c_quiz_answer MODIFY id_auto INT NOT NULL;
-ALTER TABLE c_quiz_answer DROP PRIMARY KEY;
-ALTER TABLE c_quiz_answer ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY;
-ALTER TABLE c_quiz_answer ADD INDEX idx_cqa_qid (question_id);
-
-ALTER TABLE c_quiz_question_option MODIFY id INT NOT NULL;
-ALTER TABLE c_quiz_question_option MODIFY c_id INT NOT NULL;
-ALTER TABLE c_quiz_question_option DROP PRIMARY KEY;
-ALTER TABLE c_quiz_question_option ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY;
+TRUNCATE  roles;
+INSERT INTO roles (id, name, role) VALUES('1', 'Teacher', 'ROLE_TEACHER');
+INSERT INTO roles (id, name, role) VALUES('4', 'RRHH', 'ROLE_RRHH');
+INSERT INTO roles (id, name, role) VALUES('3', 'Session Manager', 'ROLE_SESSION_MANAGER');
+INSERT INTO roles (id ,name, role) VALUES('5', 'Student', 'ROLE_STUDENT');
+INSERT INTO roles (id, name, role) VALUES('6', 'Anonymous', 'ROLE_ANONYMOUS');
+INSERT INTO roles (id, name, role) VALUES('11', 'Admin', 'ROLE_ADMIN');
+INSERT INTO roles (id, name, role) VALUES('17', 'Question Manager', 'ROLE_QUESTION_MANAGER');
+INSERT INTO roles (id, name, role) VALUES('18', 'Global admin', 'ROLE_GLOBAL_ADMIN');
 
-ALTER TABLE c_quiz_rel_question MODIFY question_id INT NOT NULL;
-ALTER TABLE c_quiz_rel_question MODIFY exercice_id INT NOT NULL;
-ALTER TABLE c_quiz_rel_question DROP PRIMARY KEY;
-ALTER TABLE c_quiz_rel_question ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY;
-ALTER TABLE c_quiz_rel_question ADD INDEX idx_cqrq_id (question_id);
-ALTER TABLE c_quiz_rel_question ADD INDEX idx_cqrq_cidexid (c_id, exercice_id);
+-- Admin
+TRUNCATE  users_roles;
+INSERT INTO users_roles VALUES (1, 11);
 
-ALTER TABLE c_quiz_category MODIFY id INT NOT NULL;
-ALTER TABLE c_quiz_category MODIFY c_id INT NOT NULL;
-ALTER TABLE c_quiz_category DROP PRIMARY KEY;
-ALTER TABLE c_quiz_category ADD COLUMN iid INT unsigned NOT NULL auto_increment PRIMARY KEY;
+DELETE FROM settings_current WHERE variable = 'session_tutor_reports_visibility';
+DELETE FROM settings_options WHERE variable = 'session_tutor_reports_visibility';
 
-ALTER TABLE question_field_options ADD INDEX idx_question_field_options_field_id(field_id);
-ALTER TABLE question_field_values ADD INDEX idx_question_field_values_question_id(question_id);
-ALTER TABLE question_field_values ADD INDEX idx_question_field_values_field_id(field_id);
+DELETE FROM settings_current WHERE variable = 'gradebook_show_percentage_in_reports';
+DELETE FROM settings_options WHERE variable = 'gradebook_show_percentage_in_reports';
 
-ALTER TABLE question_field_values ADD COLUMN user_id INT unsigned NOT NULL default 0;
-ALTER TABLE session_field_values ADD COLUMN user_id INT unsigned NOT NULL default 0;
-ALTER TABLE course_field_values ADD COLUMN user_id INT unsigned NOT NULL default 0;
-ALTER TABLE user_field_values ADD COLUMN author_id INT unsigned NOT NULL default 0;
+DELETE FROM settings_current WHERE variable = 'login_as_allowed';
+DELETE FROM settings_options WHERE variable = 'login_as_allowed';
 
-ALTER TABLE c_quiz_category ADD COLUMN lvl int;
-ALTER TABLE c_quiz_category ADD COLUMN lft int;
-ALTER TABLE c_quiz_category ADD COLUMN rgt int;
-ALTER TABLE c_quiz_category ADD COLUMN root int;
-ALTER TABLE c_quiz_category MODIFY COLUMN parent_id int default null;
+DELETE FROM settings_current WHERE variable = 'admins_can_set_users_pass';
+DELETE FROM settings_options WHERE variable = 'admins_can_set_users_pass';
 
-ALTER TABLE track_e_course_access MODIFY COLUMN course_access_id bigint unsigned auto_increment;
-ALTER TABLE user_field ADD COLUMN field_loggeable int default 0;
-ALTER TABLE session_field ADD COLUMN field_loggeable int default 0;
-ALTER TABLE course_field ADD COLUMN field_loggeable int default 0;
-ALTER TABLE question_field ADD COLUMN field_loggeable int default 0;
+DELETE FROM settings_current WHERE variable = 'session_page_enabled';
+DELETE FROM settings_options WHERE variable = 'session_page_enabled';
 
-ALTER TABLE user_field_values ADD COLUMN comment VARCHAR(100) default '';
-ALTER TABLE session_field_values ADD COLUMN comment VARCHAR(100) default '';
-ALTER TABLE course_field_values ADD COLUMN comment VARCHAR(100) default '';
-ALTER TABLE question_field_values ADD COLUMN comment VARCHAR(100) default '';
-ALTER TABLE c_quiz ADD COLUMN end_button int NOT NULL default 0;
-ALTER TABLE user ADD COLUMN salt VARCHAR(255) DEFAULT NULL;
+DELETE FROM settings_current WHERE variable = 'settings_latest_update';
+DELETE FROM settings_options WHERE variable = 'settings_latest_update';
 
-ALTER TABLE question_field_options ADD COLUMN priority INT default NULL;
-ALTER TABLE course_field_options ADD COLUMN priority INT default NULL;
-ALTER TABLE user_field_options ADD COLUMN priority INT default NULL;
-ALTER TABLE session_field_options ADD COLUMN priority INT default NULL;
+DELETE FROM settings_current WHERE variable = 'user_name_order';
+DELETE FROM settings_current WHERE variable = 'user_name_sort_by';
 
-ALTER TABLE question_field_options ADD COLUMN priority_message varchar(255) default NULL;
-ALTER TABLE course_field_options ADD COLUMN priority_message varchar(255) default NULL;
-ALTER TABLE user_field_options ADD COLUMN priority_message varchar(255) default NULL;
-ALTER TABLE session_field_options ADD COLUMN priority_message varchar(255) default NULL;
+DELETE FROM settings_current WHERE variable = 'allow_teachers_to_create_sessions';
+DELETE FROM settings_options WHERE variable = 'allow_teachers_to_create_sessions';
 
--- update tables to add iid field
-ALTER TABLE c_announcement CHANGE id id int unsigned not null;
-ALTER TABLE c_announcement DROP PRIMARY KEY;
-ALTER TABLE c_announcement add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST;
-ALTER TABLE c_announcement add UNIQUE KEY(c_id,id);
-ALTER TABLE c_announcement ENGINE = InnoDB;
-ALTER TABLE c_announcement_attachment CHANGE id id int unsigned not null;
-ALTER TABLE c_announcement_attachment DROP PRIMARY KEY;
-ALTER TABLE c_announcement_attachment add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST;
-ALTER TABLE c_announcement_attachment add UNIQUE KEY(c_id,id);
-ALTER TABLE c_announcement_attachment ENGINE = InnoDB;
-ALTER TABLE c_attendance CHANGE id id int unsigned not null;
-ALTER TABLE c_attendance DROP PRIMARY KEY;
-ALTER TABLE c_attendance add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST;
-ALTER TABLE c_attendance add UNIQUE KEY(c_id,id);
-ALTER TABLE c_attendance ENGINE = InnoDB;
-ALTER TABLE c_attendance_calendar CHANGE id id int unsigned not null;
-ALTER TABLE c_attendance_calendar DROP PRIMARY KEY;
-ALTER TABLE c_attendance_calendar add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST;
-ALTER TABLE c_attendance_calendar add UNIQUE KEY(c_id,id);
-ALTER TABLE c_attendance_calendar ENGINE = InnoDB;
-ALTER TABLE c_attendance_result CHANGE id id int unsigned not null;
-ALTER TABLE c_attendance_result DROP PRIMARY KEY;
-ALTER TABLE c_attendance_result add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST;
-ALTER TABLE c_attendance_result add UNIQUE KEY(c_id,id);
-ALTER TABLE c_attendance_result ENGINE = InnoDB;
-ALTER TABLE c_attendance_sheet DROP PRIMARY KEY;
-ALTER TABLE c_attendance_sheet add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST;
-ALTER TABLE c_attendance_sheet add UNIQUE KEY(c_id,user_id,attendance_calendar_id);
-ALTER TABLE c_attendance_sheet ENGINE = InnoDB;
-ALTER TABLE c_attendance_sheet_log CHANGE id id int unsigned not null;
-ALTER TABLE c_attendance_sheet_log DROP PRIMARY KEY;
-ALTER TABLE c_attendance_sheet_log add COLUMN iid int unsigned not null AUTO_INCREMENT PRIMARY KEY FIRST;
-ALTER TABLE c_attendance_sheet_log add UNIQUE KEY(c_id,id);
-ALTER TABLE c_attendance_sheet_log ENGINE = InnoDB;
-ALTER TABLE session ADD COLUMN description TEXT;
-ALTER TABLE session ADD COLUMN show_description int default NULL;
+DELETE FROM settings_current WHERE variable = 'template';
 
-ALTER TABLE c_quiz_category ADD COLUMN visibility INT default 1;
-ALTER TABLE c_quiz_question ADD INDEX idx_c_q_qst_cpt (c_id, parent_id, type);
-ALTER TABLE c_quiz_question_rel_category ADD INDEX idx_c_q_qst_r_cat_qc(question_id, c_id);
-ALTER TABLE c_quiz ADD COLUMN question_selection_type INT DEFAULT 1;
-ALTER TABLE c_quiz ADD COLUMN hide_question_title INT DEFAULT 0;
-ALTER TABLE c_quiz ADD COLUMN global_category_id INT DEFAULT NULL;
+DELETE FROM settings_current WHERE variable = 'use_virtual_keyboard';
+DELETE FROM settings_options WHERE variable = 'use_virtual_keyboard';
 
-ALTER TABLE user MODIFY COLUMN chatcall_user_id int unsigned default 0;
-ALTER TABLE user MODIFY COLUMN chatcall_date datetime default NULL;
-ALTER TABLE user MODIFY COLUMN chatcall_text varchar(50) default NULL;
-ALTER TABLE user MODIFY COLUMN expiration_date datetime default NULL;
+DELETE FROM settings_current WHERE variable = 'breadcrumb_navigation_display';
+DELETE FROM settings_options WHERE variable = 'breadcrumb_navigation_display';
 
+DELETE FROM settings_current WHERE variable = 'default_calendar_view';
+DELETE FROM settings_options WHERE variable = 'default_calendar_view';
 
-INSERT INTO roles (id, name, role) VALUES('1', 'Teacher', 'ROLE_TEACHER');
-INSERT INTO roles (id, name, role) VALUES('4', 'RRHH', 'ROLE_RRHH');
-INSERT INTO roles (id, name, role) VALUES('3', 'Session Manager', 'ROLE_SESSION_MANAGER');
-INSERT INTO roles (id ,name, role) VALUES('5', 'Student', 'ROLE_STUDENT');
-INSERT INTO roles (id, name, role) VALUES('6', 'Anonymous', 'ROLE_ANONYMOUS');
-INSERT INTO roles (id, name, role) VALUES('11', 'Admin', 'ROLE_ADMIN');
-INSERT INTO roles (id, name, role) VALUES('17', 'Question Manager', 'ROLE_QUESTION_MANAGER');
-INSERT INTO roles (id, name, role) VALUES('18', 'Global admin', 'ROLE_GLOBAL_ADMIN');
+DELETE FROM settings_current WHERE variable = 'disable_copy_paste';
+DELETE FROM settings_options WHERE variable = 'disable_copy_paste';
+DELETE FROM settings_current WHERE variable = 'showonline';
 
--- Admin
-INSERT INTO users_roles VALUES (1, 11);
+DELETE FROM settings_options WHERE variable = 'last_transaction_id';
 
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('session_tutor_reports_visibility', NULL, 'radio', 'Session', 'true', 'SessionTutorsCanSeeExpiredSessionsResultsTitle', 'SessionTutorsCanSeeExpiredSessionsResultsComment', NULL, NULL, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('gradebook_show_percentage_in_reports', NULL,'radio','Gradebook','true','GradebookShowPercentageInReportsTitle','GradebookShowPercentageInReportsComment', NULL, NULL, 0);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('login_as_allowed', NULL, 'radio', 'security', 'true','AdminLoginAsAllowedTitle', 'AdminLoginAsAllowedComment', 1, 0, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('admins_can_set_users_pass', NULL, 'radio', 'security', 'true', 'AdminsCanChangeUsersPassTitle', 'AdminsCanChangeUsersPassComment', 1, 0, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('session_page_enabled', NULL, 'radio', 'Session', 'true', 'SessionPageEnabledTitle', 'SessionPageEnabledComment', NULL, NULL, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('settings_latest_update', NULL, NULL, NULL, '', '','', NULL, NULL, 0);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('user_name_order', NULL, 'textfield', 'Platform', '', 'UserNameOrderTitle', 'UserNameOrderComment', NULL, NULL, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('user_name_sort_by', NULL, 'textfield', 'Platform', '', 'UserNameSortByTitle', 'UserNameSortByComment', NULL, NULL, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('allow_teachers_to_create_sessions', NULL,'radio','Session','false','AllowTeachersToCreateSessionsTitle','AllowTeachersToCreateSessionsComment', NULL, NULL, 0);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('template', NULL, 'text', 'stylesheets', 'default', 'DefaultTemplateTitle', 'DefaultTemplateComment', NULL, NULL, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('breadcrumb_navigation_display', NULL, 'radio', 'Platform','true','BreadcrumbNavigationDisplayTitle', 'BreadcrumbNavigationDisplayComment', NULL, NULL, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('use_virtual_keyboard', NULL, 'radio', 'Platform', 'false','ShowVirtualKeyboardTitle','ShowVirtualKeyboardComment', NULL, NULL, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('default_calendar_view', NULL, 'radio', 'Platform','month','DefaultCalendarViewTitle', 'DefaultCalendarViewComment', NULL, NULL, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('disable_copy_paste', NULL, 'radio', 'Platform', 'false','DisableCopyPasteTitle','DisableCopyPasteComment', NULL, NULL, 1);
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('showonline','session','checkbox','Platform','true','ShowOnlineTitle','ShowOnlineComment',NULL,'ShowOnlineSession', 0);
+
 INSERT INTO settings_options (variable, value, display_text) VALUES ('session_tutor_reports_visibility', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('session_tutor_reports_visibility', 'false', 'No');
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('gradebook_show_percentage_in_reports', NULL,'radio','Gradebook','true','GradebookShowPercentageInReportsTitle','GradebookShowPercentageInReportsComment', NULL, NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('gradebook_show_percentage_in_reports', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('gradebook_show_percentage_in_reports', 'false', 'No');
-INSERT INTO settings_current(variable, type, subkey, category, selected_value, title, comment, access_url, access_url_changeable, access_url_locked) VALUES ('login_as_allowed', NULL, 'radio', 'security', 'true','AdminLoginAsAllowedTitle', 'AdminLoginAsAllowedComment', 1, 0, 1);
-INSERT INTO settings_options(variable, value, display_text) VALUES ('login_as_allowed','true','Yes'),('login_as_allowed','false','No');
-INSERT INTO settings_current(variable, type, subkey, category, selected_value, title, comment, access_url, access_url_changeable, access_url_locked) VALUES ('admins_can_set_users_pass', NULL, 'radio', 'security', 'true', 'AdminsCanChangeUsersPassTitle', 'AdminsCanChangeUsersPassComment', 1, 0, 1);
-INSERT INTO settings_options(variable, value, display_text) VALUES('admins_can_set_users_pass','true','Yes'),('admins_can_set_users_pass','false','No');
-INSERT INTO settings_options(variable, value) VALUES ('last_transaction_id','0');
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('session_page_enabled', NULL, 'radio', 'Session', 'true', 'SessionPageEnabledTitle', 'SessionPageEnabledComment', NULL, NULL, 1);
+INSERT INTO settings_options (variable, value, display_text) VALUES ('login_as_allowed','true','Yes');
+INSERT INTO settings_options (variable, value, display_text) VALUES ('login_as_allowed','false','No');
+INSERT INTO settings_options (variable, value, display_text) VALUES ('admins_can_set_users_pass','true','Yes');
+INSERT INTO settings_options (variable, value, display_text) VALUES ('admins_can_set_users_pass','false','No');
+INSERT INTO settings_options (variable, value, display_text) VALUES ('last_transaction_id', '0', '');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('session_page_enabled', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('session_page_enabled', 'false', 'No');
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('settings_latest_update', NULL, NULL, NULL, '', '','', NULL, NULL, 0);
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('user_name_order', NULL, 'textfield', 'Platform', '', 'UserNameOrderTitle', 'UserNameOrderComment', NULL, NULL, 1);
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('allow_teachers_to_create_sessions', NULL,'radio','Session','false','AllowTeachersToCreateSessionsTitle','AllowTeachersToCreateSessionsComment', NULL, NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_teachers_to_create_sessions', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_teachers_to_create_sessions', 'false', 'No');
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('template', NULL, 'text', 'stylesheets', 'default', 'DefaultTemplateTitle', 'DefaultTemplateComment', NULL, NULL, 1);
-
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('breadcrumb_navigation_display', NULL, 'radio', 'Platform','true','BreadcrumbNavigationDisplayTitle', 'BreadcrumbNavigationDisplayComment', NULL, NULL, 1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('breadcrumb_navigation_display', 'true', 'Show');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('breadcrumb_navigation_display', 'false', 'Hide');
-
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('use_virtual_keyboard', NULL, 'radio', 'Platform', 'false','ShowVirtualKeyboardTitle','ShowVirtualKeyboardComment', NULL, NULL, 1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('use_virtual_keyboard', 'true', 'Show');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('use_virtual_keyboard', 'false', 'Hide');
-
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('disable_copy_paste', NULL, 'radio', 'Platform', 'false','DisableCopyPasteTitle','DisableCopyPasteComment', NULL, NULL, 1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('disable_copy_paste', 'true', 'Show');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('disable_copy_paste', 'false', 'Hide');
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('showonline','session','checkbox','Platform','true','ShowOnlineTitle','ShowOnlineComment',NULL,'ShowOnlineSession', 0);
-
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('default_calendar_view', NULL, 'radio', 'Platform','month','DefaultCalendarViewTitle', 'DefaultCalendarViewComment', NULL, NULL, 1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('default_calendar_view', 'month', 'Month');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('default_calendar_view', 'basicWeek', 'BasicWeek');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('default_calendar_view', 'agendaWeek', 'Week');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('default_calendar_view', 'agendaDay', 'Day');
 
-
+TRUNCATE branch_transaction_status;
 INSERT INTO branch_transaction_status VALUES (1, 'To be executed'), (2, 'Executed successfully'), (3, 'Execution deprecated'), (4, 'Execution failed');
 
 UPDATE course_field SET field_type = 3 WHERE field_variable = 'special_course';
 
 -- Do not move this
-UPDATE settings_current SET selected_value = '1.10.0.043' WHERE variable = 'chamilo_database_version';
+UPDATE settings_current SET selected_value = '1.10.0.044' WHERE variable = 'chamilo_database_version';

+ 49 - 21
vendor/chamilo/chash/src/Chash/Resources/Database/1.10.0/update-db-1.9.0-1.10.0.inc.php

@@ -1,7 +1,7 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-$update = function($_configuration, \Doctrine\DBAL\Connection $mainConnection, $courseList, $dryRun, $output) {
+$update = function($_configuration, \Doctrine\DBAL\Connection $mainConnection, $courseList, $dryRun, $output, $upgrade) {
 
     $mainConnection->beginTransaction();
 
@@ -11,19 +11,33 @@ $update = function($_configuration, \Doctrine\DBAL\Connection $mainConnection, $
     $session_rel_course_table = "$dbNameForm.session_rel_course";
     $session_rel_course_rel_user_table = "$dbNameForm.session_rel_course_rel_user";
     $course_table = "$dbNameForm.course";
+    $courseRelUserTable = "$dbNameForm.course_rel_user";
 
-    //Fixes new changes in sessions
-    $sql = "SELECT id, date_start, date_end, nb_days_access_before_beginning, nb_days_access_after_end FROM $session_table ";
+    $accessUrlRelUserTable = "$dbNameForm.access_url_rel_user";
+    $accessUrlRelCourseTable = "$dbNameForm.access_url_rel_course";
+    $accessUrlRelSessionTable = "$dbNameForm.access_url_rel_session";
+
+    // Fixes new changes in sessions
+    $sql = "SELECT id, date_start, date_end, nb_days_access_before_beginning, nb_days_access_after_end FROM $session_table";
     $result = $mainConnection->executeQuery($sql);
     $sessions = $result->fetchAll();
 
     foreach ($sessions as $session) {
         $session_id = $session['id'];
 
-        //Fixing date_start
+        // Check if the session is registered in the access_url_rel_session table
+        $sql = "SELECT session_id FROM $accessUrlRelSessionTable WHERE session_id = $session_id";
+        $result = $mainConnection->executeQuery($sql);
+        if ($result->rowCount() == 0) {
+            $sql = "INSERT INTO $accessUrlRelSessionTable (session_id, access_url_id) VALUES ('$session_id', '1')";
+            $mainConnection->executeQuery($sql);
+        }
+
+        // Fixing date_start
         if (isset($session['date_start']) && !empty($session['date_start']) && $session['date_start'] != '0000-00-00') {
             $datetime = $session['date_start'].' 00:00:00';
-            $update_sql = "UPDATE $session_table SET display_start_date = '$datetime' , access_start_date = '$datetime' WHERE id = $session_id";
+            $update_sql = "UPDATE $session_table SET display_start_date = '$datetime', access_start_date = '$datetime'
+                           WHERE id = $session_id";
             $mainConnection->executeQuery($update_sql);
 
             //Fixing nb_days_access_before_beginning
@@ -35,10 +49,11 @@ $update = function($_configuration, \Doctrine\DBAL\Connection $mainConnection, $
             }
         }
 
-        //Fixing end_date
+        // Fixing end_date
         if (isset($session['date_end']) && !empty($session['date_end']) && $session['date_end'] != '0000-00-00') {
             $datetime = $session['date_end'].' 00:00:00';
-            $update_sql = "UPDATE $session_table SET display_end_date = '$datetime', access_end_date = '$datetime' WHERE id = $session_id";
+            $update_sql = "UPDATE $session_table SET display_end_date = '$datetime', access_end_date = '$datetime'
+                           WHERE id = $session_id";
             $mainConnection->executeQuery($update_sql);
 
             //Fixing nb_days_access_before_beginning
@@ -51,27 +66,40 @@ $update = function($_configuration, \Doctrine\DBAL\Connection $mainConnection, $
         }
     }
 
-    //Fixes new changes session_rel_course
-    $sql = "SELECT id_session, sc.course_code, c.id FROM $course_table c INNER JOIN $session_rel_course_table sc ON sc.course_code = c.code";
+    // Fixes new changes course_rel_course
+    $sql = "SELECT id, code FROM $course_table";
     $result = $mainConnection->executeQuery($sql);
     $rows = $result->fetchAll();
     foreach ($rows as $row) {
-        $sql = "UPDATE $session_rel_course_table SET c_id = {$row['id']}
-                WHERE course_code = '{$row['course_code']}' AND id_session = {$row['id_session']} ";
+        $courseId = $row['id'];
+        $courseCode = $row['code'];
+
+        $sql = "UPDATE $courseRelUserTable SET c_id = '$courseId'
+                WHERE  course_code = '$courseCode'";
         $mainConnection->executeQuery($sql);
-    }
 
-    //Fixes new changes in session_rel_course_rel_user
-    $sql = "SELECT id_session, sc.course_code, c.id FROM $course_table c INNER JOIN $session_rel_course_rel_user_table sc ON sc.course_code = c.code";
-    $result = $mainConnection->executeQuery($sql);
-    $rows = $result->fetchAll();
-    foreach ($rows as $row) {
-        $sql = "UPDATE $session_rel_course_rel_user_table SET c_id = {$row['id']}
-                WHERE course_code = '{$row['course_code']}' AND id_session = {$row['id_session']} ";
+        $sql = "UPDATE $session_rel_course_rel_user_table SET c_id = '$courseId'
+                WHERE  course_code = '$courseCode'";
+        $mainConnection->executeQuery($sql);
+
+        $sql = "UPDATE $session_rel_course_table SET c_id = '$courseId'
+                WHERE course_code = '$courseCode' ";
+        $mainConnection->executeQuery($sql);
+
+        $sql = "UPDATE $accessUrlRelCourseTable SET c_id = '$courseId'
+                WHERE course_code = '$courseCode' ";
         $mainConnection->executeQuery($sql);
+
+        // Check if the course is registered in the access_url_rel_course table
+        $sql = "SELECT c_id FROM $accessUrlRelCourseTable WHERE c_id = $courseId";
+        $result = $mainConnection->executeQuery($sql);
+        if ($result->rowCount() == 0) {
+            $sql = "INSERT INTO $accessUrlRelCourseTable (access_url_id, course_code, c_id) VALUES ('1', '$courseCode', '$courseId')";
+            $mainConnection->executeQuery($sql);
+        }
     }
 
-    //Updating c_quiz_order
+    // Updating c_quiz_order
     $teq = "$dbNameForm.c_quiz";
     $sql = "SELECT c_id, session_id, id FROM $teq ORDER BY c_id, session_id, id";
     $result = $mainConnection->executeQuery($sql);
@@ -99,7 +127,7 @@ $update = function($_configuration, \Doctrine\DBAL\Connection $mainConnection, $
         $order++;
     }
 
-    //Fixing special course
+    // Fixing special course
     $output->writeln('Fixing special course');
     $sql = "SELECT id FROM $dbNameForm.course_field WHERE field_variable = 'special_course'";
     $result = $mainConnection->executeQuery($sql);

+ 143 - 28
vendor/chamilo/chash/src/Chash/Resources/Database/1.8.8/migrate-db-1.8.7-1.8.8-pre.sql

@@ -14,28 +14,41 @@
 
 -- xxMAINxx
 
+DROP PROCEDURE IF EXISTS dropIndexIfExists;
+CREATE PROCEDURE dropIndexIfExists(in theTable varchar(128), in theIndexName varchar(128) ) BEGIN  IF((SELECT COUNT(*) AS index_exists FROM information_schema.statistics WHERE TABLE_SCHEMA = DATABASE() and table_name = theTable AND index_name = theIndexName) > 0) THEN SET @s = CONCAT('DROP INDEX `' , theIndexName , '` ON `' , theTable, '`');   PREPARE stmt FROM @s;   EXECUTE stmt; END IF; END;
+DROP PROCEDURE IF EXISTS AddColumnUnlessExists;
+CREATE PROCEDURE AddColumnUnlessExists( IN dbName tinytext,	IN tableName tinytext,	IN fieldName tinytext, IN fieldDef text) BEGIN IF NOT EXISTS (		SELECT * FROM information_schema.COLUMNS	WHERE column_name = fieldName	and table_name = tableName		and table_schema=dbName) THEN set @ddl=CONCAT('ALTER TABLE ',dbName,'.',tableName, ' ADD COLUMN ', fieldName, ' ',fieldDef); prepare stmt from @ddl;		execute stmt;	END IF;end;
+
 CREATE TABLE IF NOT EXISTS course_request (id int NOT NULL AUTO_INCREMENT, code varchar(40) NOT NULL, user_id int unsigned NOT NULL default '0', directory varchar(40) DEFAULT NULL, db_name varchar(40) DEFAULT NULL, course_language varchar(20) DEFAULT NULL, title varchar(250) DEFAULT NULL, description text, category_code varchar(40) DEFAULT NULL, tutor_name varchar(200) DEFAULT NULL, visual_code varchar(40) DEFAULT NULL, request_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00', objetives text, target_audience text, status int unsigned NOT NULL default '0', info int unsigned NOT NULL default '0', exemplary_content int unsigned NOT NULL default '0', PRIMARY KEY (id), UNIQUE KEY code (code));
 CREATE TABLE IF NOT EXISTS career (id INT NOT NULL AUTO_INCREMENT,	name VARCHAR(255) NOT NULL, description TEXT NOT NULL, status INT NOT NULL default '0', created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id));
 CREATE TABLE IF NOT EXISTS promotion (id INT NOT NULL AUTO_INCREMENT,	name VARCHAR(255) NOT NULL, description TEXT NOT NULL, status INT NOT NULL default '0', career_id INT NOT NULL, created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', updated_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY(id));
 CREATE TABLE IF NOT EXISTS usergroup ( id INT NOT NULL AUTO_INCREMENT,	name VARCHAR(255) NOT NULL, description TEXT NOT NULL,PRIMARY KEY (id));
-CREATE TABLE IF NOT EXISTS usergroup_rel_user    ( usergroup_id INT NOT NULL, user_id 	INT NOT NULL );
-CREATE TABLE IF NOT EXISTS usergroup_rel_course  ( usergroup_id INT NOT NULL, course_id 	INT NOT NULL );
-CREATE TABLE IF NOT EXISTS usergroup_rel_session ( usergroup_id INT NOT NULL, session_id  INT NOT NULL );
+CREATE TABLE IF NOT EXISTS usergroup_rel_user ( usergroup_id INT NOT NULL, user_id INT NOT NULL );
+CREATE TABLE IF NOT EXISTS usergroup_rel_course ( usergroup_id INT NOT NULL, course_id INT NOT NULL );
+CREATE TABLE IF NOT EXISTS usergroup_rel_session ( usergroup_id INT NOT NULL, session_id INT NOT NULL );
 CREATE TABLE IF NOT EXISTS notification (id BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT,dest_user_id INT NOT NULL, dest_mail CHAR(255),title CHAR(255), content CHAR(255), send_freq SMALLINT DEFAULT 1, created_at DATETIME NOT NULL, sent_at DATETIME NULL);
 
-DROP INDEX unique_setting ON settings_current;
-DROP INDEX unique_setting_option ON settings_options;
+call dropIndexIfExists('settings_current', 'unique_setting');
+call dropIndexIfExists('settings_options', 'unique_setting_option');
+
+call dropIndexIfExists('course', 'idx_course_category_code');
+call dropIndexIfExists('course', 'idx_course_directory');
+call dropIndexIfExists('notification', 'mail_notify_sent_index');
+call dropIndexIfExists('notification', 'mail_notify_freq_index');
 
-ALTER TABLE course ADD INDEX idx_course_category_code (category_code);
+ALTER TABLE course ADD INDEX idx_course_category_code(category_code);
 ALTER TABLE course ADD INDEX idx_course_directory (directory(10));
+ALTER TABLE notification ADD INDEX mail_notify_sent_index(sent_at);
+ALTER TABLE notification ADD INDEX mail_notify_freq_index(sent_at, send_freq, created_at);
+
 ALTER TABLE user MODIFY COLUMN username VARCHAR(40) NOT NULL;
-ALTER TABLE sys_announcement ADD COLUMN access_url_id INT  NOT NULL default 1;
-ALTER TABLE sys_calendar ADD COLUMN access_url_id INT  NOT NULL default 1;
-ALTER TABLE session ADD COLUMN promotion_id INT NOT NULL;
-ALTER TABLE notification ADD index mail_notify_sent_index (sent_at);
-ALTER TABLE notification ADD index mail_notify_freq_index (sent_at, send_freq, created_at);
-ALTER TABLE session_category ADD COLUMN access_url_id INT NOT NULL default 1;
-ALTER TABLE gradebook_evaluation ADD COLUMN locked int NOT NULL DEFAULT 0;
+
+call AddColumnUnlessExists(Database(), 'sys_announcement', 'access_url_id', 'INT NOT NULL default 1');
+call AddColumnUnlessExists(Database(), 'sys_calendar', 'access_url_id', 'INT NOT NULL default 1');
+call AddColumnUnlessExists(Database(), 'session', 'promotion_id', 'INT NOT NULL');
+call AddColumnUnlessExists(Database(), 'session_category', 'access_url_id', 'INT NOT NULL default 1');
+call AddColumnUnlessExists(Database(), 'gradebook_evaluation', 'locked', 'int NOT NULL DEFAULT 0');
+
 ALTER TABLE settings_current ADD UNIQUE unique_setting (variable(110), subkey(110), category(110), access_url);
 ALTER TABLE settings_options ADD UNIQUE unique_setting_option (variable(165), value(165));
 ALTER TABLE settings_current CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
@@ -43,13 +56,30 @@ ALTER TABLE settings_options CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_
 
 LOCK TABLES settings_current WRITE, settings_options WRITE;
 
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES('users_copy_files', NULL, 'radio', 'Tools', 'true', 'AllowUsersCopyFilesTitle','AllowUsersCopyFilesComment', NULL,NULL, 1);
+
+DELETE FROM settings_current WHERE variable = 'users_copy_files';
+DELETE FROM settings_options WHERE variable = 'users_copy_files';
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('users_copy_files', NULL, 'radio', 'Tools', 'true', 'AllowUsersCopyFilesTitle','AllowUsersCopyFilesComment', NULL,NULL, 1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('users_copy_files', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('users_copy_files', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'course_validation';
+DELETE FROM settings_options WHERE variable = 'course_validation';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('course_validation', NULL, 'radio', 'Platform', 'false', 'EnableCourseValidation', 'EnableCourseValidationComment', NULL, NULL, 1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('course_validation', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('course_validation', 'false', 'No');
+
+DELETE FROM settings_current WHERE variable = 'course_validation_terms_and_conditions_url';
+DELETE FROM settings_current WHERE variable = 'sso_authentication';
+DELETE FROM settings_current WHERE variable = 'sso_authentication_domain';
+DELETE FROM settings_current WHERE variable = 'sso_authentication_auth_uri';
+DELETE FROM settings_current WHERE variable = 'sso_authentication_unauth_uri';
+DELETE FROM settings_current WHERE variable = 'sso_authentication_protocol';
+
+DELETE FROM settings_options WHERE variable = 'sso_authentication';
+DELETE FROM settings_options WHERE variable = 'sso_authentication_protocol';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('course_validation_terms_and_conditions_url', NULL, 'textfield', 'Platform', '', 'CourseValidationTermsAndConditionsLink', 'CourseValidationTermsAndConditionsLinkComment', NULL, NULL, 1);
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('sso_authentication',NULL,'radio','Security','false','EnableSSOTitle','EnableSSOComment',NULL,NULL,1);
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('sso_authentication_domain',NULL,'textfield','Security','','SSOServerDomainTitle','SSOServerDomainComment',NULL,NULL,1);
@@ -60,72 +90,134 @@ INSERT INTO settings_options (variable, value, display_text) VALUES ('sso_authen
 INSERT INTO settings_options (variable, value, display_text) VALUES ('sso_authentication', 'false', 'No');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('sso_authentication_protocol', 'http://', 'http://');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('sso_authentication_protocol', 'https://', 'https://');
+
+DELETE FROM settings_current WHERE variable = 'enabled_asciisvg';
+DELETE FROM settings_options WHERE variable = 'enabled_asciisvg';
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enabled_asciisvg',NULL,'radio','Editor','false','AsciiSvgTitle','AsciiSvgComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_asciisvg', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_asciisvg', 'false', 'No');
+
+DELETE FROM settings_current WHERE variable = 'include_asciimathml_script';
+DELETE FROM settings_options WHERE variable = 'include_asciimathml_script';
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('include_asciimathml_script',NULL,'radio','Editor','false','IncludeAsciiMathMlTitle','IncludeAsciiMathMlComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('include_asciimathml_script', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('include_asciimathml_script', 'false', 'No');
+
+DELETE FROM settings_current WHERE variable = 'enabled_wiris';
+DELETE FROM settings_options WHERE variable = 'enabled_wiris';
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enabled_wiris',NULL,'radio','Editor','false','EnabledWirisTitle','EnabledWirisComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_wiris', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_wiris', 'false', 'No');
+
+DELETE FROM settings_current WHERE variable = 'allow_spellcheck';
+DELETE FROM settings_options WHERE variable = 'allow_spellcheck';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('allow_spellcheck',NULL,'radio','Editor','false','AllowSpellCheckTitle','AllowSpellCheckComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_spellcheck', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_spellcheck', 'false', 'No');
+
+DELETE FROM settings_current WHERE variable = 'force_wiki_paste_as_plain_text';
+DELETE FROM settings_options WHERE variable = 'force_wiki_paste_as_plain_text';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('force_wiki_paste_as_plain_text',NULL,'radio','Editor','false','ForceWikiPasteAsPlainText','ForceWikiPasteAsPlainTextComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('force_wiki_paste_as_plain_text', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('force_wiki_paste_as_plain_text', 'false', 'No');
+
+DELETE FROM settings_current WHERE variable = 'enabled_googlemaps';
+DELETE FROM settings_options WHERE variable = 'enabled_googlemaps';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enabled_googlemaps',NULL,'radio','Editor','false','EnabledGooglemapsTitle','EnabledGooglemapsComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_googlemaps', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_googlemaps', 'false', 'No');
+
+DELETE FROM settings_current WHERE variable = 'enabled_imgmap';
+DELETE FROM settings_options WHERE variable = 'enabled_imgmap';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enabled_imgmap',NULL,'radio','Editor','true','EnabledImageMapsTitle','EnabledImageMapsComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_imgmap', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_imgmap', 'false', 'No');
+
+DELETE FROM settings_current WHERE variable = 'enabled_support_svg';
+DELETE FROM settings_options WHERE variable = 'enabled_support_svg';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enabled_support_svg',NULL,'radio','Tools','true','EnabledSVGTitle','EnabledSVGComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_support_svg', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_support_svg', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'pdf_export_watermark_enable';
+DELETE FROM settings_options WHERE variable = 'pdf_export_watermark_enable';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('pdf_export_watermark_enable',	NULL,'radio',		'Platform',	'false','PDFExportWatermarkEnableTitle',	'PDFExportWatermarkEnableComment','platform',NULL,  1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('pdf_export_watermark_enable','true','Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('pdf_export_watermark_enable','false','No');
 
+DELETE FROM settings_current WHERE variable = 'pdf_export_watermark_by_course';
+DELETE FROM settings_options WHERE variable = 'pdf_export_watermark_by_course';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('pdf_export_watermark_by_course',	NULL,'radio',		'Platform',	'false','PDFExportWatermarkByCourseTitle',	'PDFExportWatermarkByCourseComment','platform',NULL, 1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('pdf_export_watermark_by_course','true','Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('pdf_export_watermark_by_course','false','No');
 
+DELETE FROM settings_current WHERE variable = 'hide_courses_in_sessions';
+DELETE FROM settings_options WHERE variable = 'hide_courses_in_sessions';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('hide_courses_in_sessions',	NULL,'radio',		'Platform',	'false','HideCoursesInSessionsTitle',	'HideCoursesInSessionsComment','platform',NULL, 1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('hide_courses_in_sessions','true','Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('hide_courses_in_sessions','false','No');
 
+DELETE FROM settings_current WHERE variable = 'pdf_export_watermark_text';
+DELETE FROM settings_options WHERE variable = 'pdf_export_watermark_text';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('pdf_export_watermark_text',		NULL,'textfield',	'Platform',	'',		'PDFExportWatermarkTextTitle','PDFExportWatermarkTextComment','platform',NULL, 	1);
 
+DELETE FROM settings_current WHERE variable = 'enabled_insertHtml';
+DELETE FROM settings_options WHERE variable = 'enabled_insertHtml';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enabled_insertHtml',NULL,'radio','Editor','true','EnabledInsertHtmlTitle','EnabledInsertHtmlComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_insertHtml', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_insertHtml', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'students_export2pdf';
+DELETE FROM settings_options WHERE variable = 'students_export2pdf';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('students_export2pdf',NULL,'radio','Tools','true','EnabledStudentExport2PDFTitle','EnabledStudentExport2PDFComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('students_export2pdf', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('students_export2pdf', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'exercise_min_score';
+DELETE FROM settings_current WHERE variable = 'exercise_max_score';
+DELETE FROM settings_current WHERE variable = 'show_users_folders';
+DELETE FROM settings_options WHERE variable = 'show_users_folders';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('exercise_min_score', NULL,'textfield',	'Course',	'',		'ExerciseMinScoreTitle',		'ExerciseMinScoreComment','platform',NULL, 	1);
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('exercise_max_score', NULL,'textfield',	'Course',	'',		'ExerciseMaxScoreTitle',		'ExerciseMaxScoreComment','platform',NULL, 	1);
-
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('show_users_folders',NULL,'radio','Tools','true','ShowUsersFoldersTitle','ShowUsersFoldersComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('show_users_folders', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('show_users_folders', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'show_default_folders';
+DELETE FROM settings_options WHERE variable = 'show_default_folders';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('show_default_folders',NULL,'radio','Tools','true','ShowDefaultFoldersTitle','ShowDefaultFoldersComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('show_default_folders', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('show_default_folders', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'show_chat_folder';
+DELETE FROM settings_options WHERE variable = 'show_chat_folder';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('show_chat_folder',NULL,'radio','Tools','true','ShowChatFolderTitle','ShowChatFolderComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('show_chat_folder', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('show_chat_folder', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'enabled_text2audio';
+DELETE FROM settings_options WHERE variable = 'enabled_text2audio';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enabled_text2audio',NULL,'radio','Tools','false','Text2AudioTitle','Text2AudioComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_text2audio', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_text2audio', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'course_hide_tools';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('course_hide_tools','course_description','checkbox','Tools','false','CourseHideToolsTitle','CourseHideToolsComment',NULL,'CourseDescription', 1);
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('course_hide_tools','calendar_event','checkbox','Tools','false','CourseHideToolsTitle','CourseHideToolsComment',NULL,'Agenda', 1);
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('course_hide_tools','document','checkbox','Tools','false','CourseHideToolsTitle','CourseHideToolsComment',NULL,'Documents', 1);
@@ -151,22 +243,40 @@ INSERT INTO settings_current (variable, subkey, type, category, selected_value,
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('course_hide_tools','course_maintenance','checkbox','Tools','false','CourseHideToolsTitle','CourseHideToolsComment',NULL,'Maintenance',1);
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('course_hide_tools','course_setting','checkbox','Tools','false','CourseHideToolsTitle','CourseHideToolsComment',NULL,'CourseSettings',1);
 
+DELETE FROM settings_current WHERE variable = 'enabled_support_pixlr';
+DELETE FROM settings_options WHERE variable = 'enabled_support_pixlr';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enabled_support_pixlr',NULL,'radio','Tools','false','EnabledPixlrTitle','EnabledPixlrComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_support_pixlr', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enabled_support_pixlr', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'show_groups_to_users';
+DELETE FROM settings_options WHERE variable = 'show_groups_to_users';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('show_groups_to_users',NULL,'radio','Platform','false','ShowGroupsToUsersTitle','ShowGroupsToUsersComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('show_groups_to_users', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('show_groups_to_users', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'accessibility_font_resize';
+DELETE FROM settings_options WHERE variable = 'accessibility_font_resize';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('accessibility_font_resize',NULL,'radio','Platform','false','EnableAccessibilityFontResizeTitle','EnableAccessibilityFontResizeComment',NULL,NULL, 1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('accessibility_font_resize', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('accessibility_font_resize', 'false', 'No');
 
+DELETE FROM settings_current WHERE variable = 'enable_quiz_scenario';
+DELETE FROM settings_options WHERE variable = 'enable_quiz_scenario';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enable_quiz_scenario', NULL,'radio','Course','false','EnableQuizScenarioTitle','EnableQuizScenarioComment',NULL,NULL, 1);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enable_quiz_scenario', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enable_quiz_scenario', 'false', 'No');
+
+DELETE FROM settings_options WHERE variable = 'homepage_view' and value = 'activity_big';
 INSERT INTO settings_options (variable, value, display_text) VALUES ('homepage_view', 'activity_big', 'HomepageViewActivityBig');
+
+DELETE FROM settings_current WHERE variable = 'enable_nanogong';
+DELETE FROM settings_options WHERE variable = 'enable_nanogong';
+
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enable_nanogong',NULL,'radio','Tools','false','EnableNanogongTitle','EnableNanogongComment',NULL,NULL, 0);
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enable_nanogong', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enable_nanogong', 'false', 'No');
@@ -179,26 +289,31 @@ UPDATE settings_current SET variable='chamilo_database_version' WHERE variable='
 UPDATE settings_current SET selected_value = '1.8.8.14911' WHERE variable = 'chamilo_database_version';
 
 -- xxSTATSxx
-ALTER TABLE track_e_exercices ADD COLUMN orig_lp_item_view_id INT NOT NULL DEFAULT 0;
+call AddColumnUnlessExists(Database(), 'track_e_exercices', 'orig_lp_item_view_id', 'INT NOT NULL DEFAULT 0');
 
 -- xxUSERxx
+ALTER TABLE personal_agenda MODIFY id INT NOT NULL;
+--ALTER TABLE personal_agenda DROP PRIMARY KEY;
 ALTER TABLE personal_agenda ADD PRIMARY KEY (id);
+
+call dropIndexIfExists('personal_agenda', 'idx_personal_agenda_user');
+call dropIndexIfExists('personal_agenda', 'idx_personal_agenda_parent');
+call dropIndexIfExists('user_course_category','idx_user_c_cat_uid');
+
 ALTER TABLE personal_agenda ADD INDEX idx_personal_agenda_user (user);
 ALTER TABLE personal_agenda ADD INDEX idx_personal_agenda_parent (parent_event_id);
 ALTER TABLE user_course_category ADD INDEX idx_user_c_cat_uid (user_id);
 
 -- xxCOURSExx
 
-CREATE TABLE {prefix}quiz_question_option (id int NOT NULL, name varchar(255), position int unsigned NOT NULL, PRIMARY KEY (id));
-CREATE TABLE {prefix}attendance_sheet_log (id INT  NOT NULL AUTO_INCREMENT, attendance_id INT  NOT NULL DEFAULT 0, lastedit_date DATETIME  NOT NULL DEFAULT '0000-00-00 00:00:00', lastedit_type VARCHAR(200)  NOT NULL, lastedit_user_id INT  NOT NULL DEFAULT 0, calendar_date_value DATETIME NULL, PRIMARY KEY (id));
+CREATE TABLE IF NOT EXISTS {prefix}quiz_question_option (id int NOT NULL, name varchar(255), position int unsigned NOT NULL, PRIMARY KEY (id));
+CREATE TABLE IF NOT EXISTS {prefix}attendance_sheet_log (id INT  NOT NULL AUTO_INCREMENT, attendance_id INT  NOT NULL DEFAULT 0, lastedit_date DATETIME  NOT NULL DEFAULT '0000-00-00 00:00:00', lastedit_type VARCHAR(200)  NOT NULL, lastedit_user_id INT  NOT NULL DEFAULT 0, calendar_date_value DATETIME NULL, PRIMARY KEY (id));
 
 ALTER TABLE {prefix}course_setting CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
-ALTER TABLE {prefix}forum_forum ADD start_time DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
-ALTER TABLE {prefix}forum_forum ADD end_time DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
-ALTER TABLE {prefix}wiki_mailcue ADD session_id smallint DEFAULT 0;
+ALTER TABLE {prefix}forum_forum ADD COLUMN start_time DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
+ALTER TABLE {prefix}forum_forum ADD COLUMN end_time DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
+ALTER TABLE {prefix}wiki_mailcue ADD COLUMN session_id smallint DEFAULT 0;
 ALTER TABLE {prefix}lp ADD COLUMN use_max_score INT DEFAULT 1;
-ALTER TABLE {prefix}lp_item MODIFY COLUMN max_score FLOAT UNSIGNED DEFAULT 100;
-ALTER TABLE {prefix}tool MODIFY COLUMN category varchar(20) not null default 'authoring';
 ALTER TABLE {prefix}lp ADD COLUMN autolunch INT DEFAULT 0;
 ALTER TABLE {prefix}lp ADD COLUMN created_on 	DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
 ALTER TABLE {prefix}lp ADD COLUMN modified_on 	DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
@@ -207,11 +322,11 @@ ALTER TABLE {prefix}lp ADD COLUMN publicated_on DATETIME NOT NULL DEFAULT '0000-
 ALTER TABLE {prefix}quiz_question ADD COLUMN extra varchar(255) DEFAULT NULL;
 ALTER TABLE {prefix}quiz_question CHANGE question question TEXT NOT NULL;
 ALTER TABLE {prefix}quiz ADD COLUMN propagate_neg INT NOT NULL DEFAULT 0;
-ALTER TABLE {prefix}quiz_answer MODIFY COLUMN hotspot_type ENUM('square','circle','poly','delineation','oar');
 ALTER TABLE {prefix}attendance ADD COLUMN locked int NOT NULL default 0;
 
-INSERT INTO {prefix}course_setting(variable,value,category) VALUES ('enable_lp_auto_launch',0,'learning_path');
-INSERT INTO {prefix}course_setting(variable,value,category) VALUES ('pdf_export_watermark_text','','course');
-
-
+ALTER TABLE {prefix}quiz_answer MODIFY COLUMN hotspot_type ENUM('square','circle','poly','delineation','oar');
+ALTER TABLE {prefix}lp_item MODIFY COLUMN max_score FLOAT UNSIGNED DEFAULT 100;
+ALTER TABLE {prefix}tool MODIFY COLUMN category varchar(20) not null default 'authoring';
 
+INSERT INTO {prefix}course_setting(variable, value, category) VALUES ('enable_lp_auto_launch',0,'learning_path');
+INSERT INTO {prefix}course_setting(variable, value, category) VALUES ('pdf_export_watermark_text','','course');

+ 8 - 8
vendor/chamilo/chash/src/Chash/Resources/Database/1.8.8/update-db-1.8.7-1.8.8.inc.php

@@ -1,18 +1,18 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-$update = function($_configuration, $mainConnection, $courseList, $dryRun, $output)
+$update = function($_configuration, $mainConnection, $courseList, $dryRun, $output, $upgrade)
 {
-    $portalSettings = $this->getPortalSettings();
-    $databaseList = $this->generateDatabaseList($courseList);
+    $portalSettings = $upgrade->getPortalSettings();
+    $databaseList = $upgrade->generateDatabaseList($courseList);
     $courseDatabaseConnectionList = $databaseList['course']; // main  user stats course
 
     /** @var \Doctrine\DBAL\Connection $userConnection */
-    $userConnection = $this->getHelper($databaseList['user'][0]['database'])->getConnection();
+    $userConnection = $upgrade->getHelper($databaseList['user'][0]['database'])->getConnection();
     /** @var \Doctrine\DBAL\Connection $mainConnection */
-    $mainConnection = $this->getHelper($databaseList['main'][0]['database'])->getConnection();
+    $mainConnection = $upgrade->getHelper($databaseList['main'][0]['database'])->getConnection();
     /** @var \Doctrine\DBAL\Connection $statsConnection */
-    $statsConnection = $this->getHelper($databaseList['stats'][0]['database'])->getConnection();
+    $statsConnection = $upgrade->getHelper($databaseList['stats'][0]['database'])->getConnection();
 
     $mainConnection->beginTransaction();
 
@@ -20,7 +20,7 @@ $update = function($_configuration, $mainConnection, $courseList, $dryRun, $outp
         if (!empty($courseList)) {
             foreach ($courseList as $row_course) {
 
-                $prefix = $this->getTablePrefix($_configuration, $row_course['db_name']);
+                $prefix = $upgrade->getTablePrefix($_configuration, $row_course['db_name']);
 
                 $output->writeln('Updating course db: '.$row_course['db_name']);
 
@@ -32,7 +32,7 @@ $update = function($_configuration, $mainConnection, $courseList, $dryRun, $outp
                 foreach ($courseDatabaseConnectionList as $database) {
                     if ($database['database'] == '_chamilo_course_'.$row_course['db_name']) {
                         /** @var \Doctrine\DBAL\Connection $courseConnection */
-                        $courseConnection = $this->getHelper($database['database'])->getConnection();
+                        $courseConnection = $upgrade->getHelper($database['database'])->getConnection();
                     }
                 }
 

File diff suppressed because it is too large
+ 54 - 26
vendor/chamilo/chash/src/Chash/Resources/Database/1.9.0/migrate-db-1.8.8-1.9.0-pre.sql


+ 11 - 11
vendor/chamilo/chash/src/Chash/Resources/Database/1.9.0/update-db-1.8.8-1.9.0.inc.php

@@ -1,22 +1,22 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-$update = function($_configuration, $mainConnection, $courseList, $dryRun, $output)
+$update = function($_configuration, $mainConnection, $courseList, $dryRun, $output, $upgrade)
 {
 
-    $portalSettings = $this->getPortalSettings();
+    $portalSettings = $upgrade->getPortalSettings();
 
     define('DB_COURSE_PREFIX', 'c_');
 
-    $databaseList = $this->generateDatabaseList($courseList);
+    $databaseList = $upgrade->generateDatabaseList($courseList);
     $courseDatabaseConnectionList = $databaseList['course']; // main  user stats course
 
     /** @var \Doctrine\DBAL\Connection $userConnection */
-    $userConnection = $this->getHelper($databaseList['user'][0]['database'])->getConnection();
+    $userConnection = $upgrade->getHelper($databaseList['user'][0]['database'])->getConnection();
     /** @var \Doctrine\DBAL\Connection $mainConnection */
-    $mainConnection = $this->getHelper($databaseList['main'][0]['database'])->getConnection();
+    $mainConnection = $upgrade->getHelper($databaseList['main'][0]['database'])->getConnection();
     /** @var \Doctrine\DBAL\Connection $statsConnection */
-    $statsConnection = $this->getHelper($databaseList['stats'][0]['database'])->getConnection();
+    $statsConnection = $upgrade->getHelper($databaseList['stats'][0]['database'])->getConnection();
 
     $mainConnection->beginTransaction();
 
@@ -192,18 +192,18 @@ $update = function($_configuration, $mainConnection, $courseList, $dryRun, $outp
             $output->writeln($sql);
         }
 
-        $this->createCourseTables($output, $dryRun);
+        $upgrade->createCourseTables($output, $dryRun);
 
         if (!empty($courseList)) {
 
             $output->writeln("<comment>Moving old course tables to the new structure 1: single database</comment>");
 
-            $progress = $this->getHelperSet()->get('progress');
+            $progress = $upgrade->getHelperSet()->get('progress');
             $progress->start($output, count($courseList));
 
             foreach ($courseList as $row_course) {
 
-                $prefix = $this->getTablePrefix($_configuration, $row_course['db_name']);
+                $prefix = $upgrade->getTablePrefix($_configuration, $row_course['db_name']);
 
                 // Course tables to be migrated.
                 $table_list = array(
@@ -303,7 +303,7 @@ $update = function($_configuration, $mainConnection, $courseList, $dryRun, $outp
                 foreach ($courseDatabaseConnectionList as $database) {
                     if ($database['database'] == '_chamilo_course_'.$row_course['db_name']) {
                         /** @var \Doctrine\DBAL\Connection $courseConnection */
-                        $courseConnection = $this->getHelper($database['database'])->getConnection();
+                        $courseConnection = $upgrade->getHelper($database['database'])->getConnection();
                     }
                 }
 
@@ -383,7 +383,7 @@ $update = function($_configuration, $mainConnection, $courseList, $dryRun, $outp
             $work_table = "c_student_publication";
             $item_table = "c_item_property";
 
-            $sys_course_path = $this->getCourseSysPath();
+            $sys_course_path = $upgrade->getCourseSysPath();
 
             $today = time();
             $user_id = 1;

+ 2 - 3
vendor/chamilo/chash/src/Chash/Resources/Database/1.9.0/update-files-1.8.8-1.9.0.inc.php

@@ -1,8 +1,7 @@
 <?php
-
 /* For licensing terms, see /license.txt */
 
-$updateFiles = function($_configuration, $mainConnection, $courseList, $dryRun, $output)
+$updateFiles = function($_configuration, $mainConnection, $courseList, $dryRun, $output, $upgrade)
 {
-    $this->generateConfFiles($output);
+    $upgrade->generateConfFiles($output);
 };

Some files were not shown because too many files changed in this diff