/** * Static admin function allowing removal of a learnpath * @param string Course code * @param integer Learnpath ID * @param string Whether to delete data or keep it (default: 'keep', others: 'remove') * @return boolean True on success, false on failure (might change that to return number of elements deleted) */ function delete($course = null, $id = null, $delete = 'keep') { //TODO implement a way of getting this to work when the current object is not set //In clear: implement this in the item class as well (abstract class) and use the given ID in queries //if(empty($course)){$course = api_get_course_id();} //if(empty($id)){$id = $this->get_id();} //If an ID is specifically given and the current LP is not the same, //prevent delete if (!empty($id) && $id != $this->lp_id) { return false; } $lp = Database::get_course_table(TABLE_LP_MAIN); $lp_item = Database::get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below. $lp_view = Database::get_course_table(TABLE_LP_VIEW); $lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);} //delete lp item id foreach ($this->items as $id => $dummy) { //$this->items[$id]->delete(); $sql_del_view = "DELETE FROM {$lp_item_view} WHERE lp_item_id = '" . $id . "'"; $res_del_item_view = Database::query($sql_del_view, __FILE__, __LINE__); } // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673 $sql_del_item = "DELETE FROM {$lp_item} WHERE lp_id = " . $this->lp_id; $res_del_item = Database::query($sql_del_item, __FILE__, __LINE__); $sql_del_view = "DELETE FROM {$lp_view} WHERE lp_id = " . $this->lp_id; //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);} $res_del_view = Database::query($sql_del_view, __FILE__, __LINE__); $this->toggle_publish($this->lp_id, 'i'); //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);} if ($this->type == 2 or $this->type == 3) { //this is a scorm learning path, delete the files as well $sql = "SELECT path FROM {$lp} WHERE id = " . $this->lp_id; $res = Database::query($sql, __FILE__, __LINE__); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res); $path = $row['path']; $sql = "SELECT id FROM {$lp} WHERE path = '{$path}' AND id != " . $this->lp_id; $res = Database::query($sql, __FILE__, __LINE__); if (Database::num_rows($res) > 0) { //another learning path uses this directory, so don't delete it if ($this->debug > 2) { error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0); } } else { //no other LP uses that directory, delete it $course_rel_dir = api_get_course_path() . '/scorm/'; //scorm dir web path starting from /courses $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; //absolute system path for this course if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty($course_scorm_dir)) { if ($this->debug > 2) { error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0); } // Proposed by Christophe (clefevre). if (strcmp(substr($path, -2), "/.") == 0) { $path = substr($path, 0, -1); // Remove "." at the end } //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way. rmdirr($course_scorm_dir . $path); } } } } $sql_del_lp = "DELETE FROM {$lp} WHERE id = " . $this->lp_id; //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);} $res_del_lp = Database::query($sql_del_lp, __FILE__, __LINE__); $this->update_display_order(); //updates the display order of all lps api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id()); require_once '../gradebook/lib/be.inc.php'; $tbl_grade_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); //delete link of gradebook tool $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";'; $result = Database::query($sql, __FILE__, __LINE__); $row = Database::fetch_array($result, 'ASSOC'); //fixing gradebook link deleted see #5229 if (!empty($row['id'])) { $link = LinkFactory::load($row['id']); if ($link[0] != null) { $link[0]->delete(); } } //TODO: also delete items and item-views if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian')) { require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id); } }
/** * Removes a link from search engine database * @param string $course_id Course code * @param int $link_id Document id to delete * @return void */ public static function delete_link_from_search_engine($course_id, $link_id) { // Remove from search engine if enabled. if (api_get_setting('search_enabled') == 'true') { $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1'; $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_LINK, $link_id); $res = Database::query($sql); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res); require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php'; $di = new ChamiloIndexer(); $di->remove_document((int) $row['search_did']); } $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1'; $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_LINK, $link_id); Database::query($sql); // Remove terms from db. require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; delete_all_values_for_item($course_id, TOOL_DOCUMENT, $link_id); } }
function search_engine_delete() { // remove from search engine if enabled if (api_get_setting('search.search_enabled') == 'true' && extension_loaded('xapian')) { $course_id = api_get_course_id(); $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level IS NULL LIMIT 1'; $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id); $res = Database::query($sql); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res); require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php'; $di = new ChamiloIndexer(); $di->remove_document((int) $row['search_did']); unset($di); $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION); foreach ($this->questionList as $question_i) { $sql = 'SELECT type FROM %s WHERE id=%s'; $sql = sprintf($sql, $tbl_quiz_question, $question_i); $qres = Database::query($sql); if (Database::num_rows($qres) > 0) { $qrow = Database::fetch_array($qres); $objQuestion = Question::getInstance($qrow['type']); $objQuestion = Question::read((int) $question_i); $objQuestion->search_engine_edit($this->id, FALSE, TRUE); unset($objQuestion); } } } $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level IS NULL LIMIT 1'; $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id); Database::query($sql); // remove terms from db require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; delete_all_values_for_item($course_id, TOOL_QUIZ, $this->id); } }
function search_engine_delete() { // remove from search engine if enabled if (api_get_setting('search.search_enabled') == 'true' && extension_loaded('xapian')) { $em = Database::getManager(); $course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id()); $res = $em->createQuery(' SELECT ser FROM ChamiloCoreBundle:SearchEngineRef ser WHERE ser.course = ?1 AND ser.toolId = ?2 AND ser.refIdHighLevel = ?3 AND ser.refIdSecondLevel IS NULL ')->setMaxResults(1)->execute([1 => $course, 2 => TOOL_QUIZ, 3 => $this->id]); if (count($res) > 0) { $row = current($res); require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php'; $di = new ChamiloIndexer(); $di->remove_document($row->getSearchDid()); unset($di); $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION); foreach ($this->questionList as $question_i) { $sql = 'SELECT type FROM %s WHERE id=%s'; $sql = sprintf($sql, $tbl_quiz_question, $question_i); $qres = Database::query($sql); if (Database::num_rows($qres) > 0) { $qrow = Database::fetch_array($qres); $objQuestion = Question::getInstance($qrow['type']); $objQuestion = Question::read((int) $question_i); $objQuestion->search_engine_edit($this->id, FALSE, TRUE); unset($objQuestion); } } } $em->createQuery(' DELETE FROM ChamiloCoreBundle:SearchEngineRef ser WHERE ser.course = ?1 AND ser.toolId = ?2 AND ser.refIdHighLevel = ?3 AND ser.refIdSecondLevel IS NULL ')->setMaxResults(1)->execute([1 => $course, 2 => TOOL_QUIZ, 3 => $this->id]); // remove terms from db require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; delete_all_values_for_item($course->getCode(), TOOL_QUIZ, $this->id); } }
/** * Removes documents from search engine database * * @param string $course_id Course code * @param int $document_id Document id to delete */ public static function delete_document_from_search_engine($course_id, $document_id) { // remove from search engine if enabled if (api_get_setting('search.search_enabled') == 'true') { $em = Database::getManager(); $course = $em->getRepository('ChamiloCoreBundle:Course')->findOneBy(['code' => $course_id]); $res = $em->getRepository('ChamiloCoreBundle:SearchEngineRef')->findOneBy(['course' => $course, 'toolId' => TOOL_DOCUMENT, 'refIdHighLevel' => $document_id]); if ($res) { require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php'; $di = new ChamiloIndexer(); $di->remove_document($res->getSearchDid()); } $em->createQuery(' DELETE FROM ChamiloCoreBundle:SearchEngineRef ser WHERE ser.course = ?1 AND ser.toolId = ?2 AND ser.refIdHighLevel = ?3 ')->setMaxResults(1)->execute([1 => $course, 2 => TOOL_DOCUMENT, 3 => $document_id]); // remove terms from db require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; delete_all_values_for_item($course->getCode(), TOOL_DOCUMENT, $document_id); } }
/** * Static admin function allowing removal of a learnpath * @param string Course code * @param integer Learnpath ID * @param string Whether to delete data or keep it (default: 'keep', others: 'remove') * @return boolean True on success, false on failure (might change that to return number of elements deleted) */ public function delete($course = null, $id = null, $delete = 'keep') { $course_id = api_get_course_int_id(); // TODO: Implement a way of getting this to work when the current object is not set. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries. // If an ID is specifically given and the current LP is not the same, prevent delete. if (!empty($id) && $id != $this->lp_id) { return false; } $lp = Database::get_course_table(TABLE_LP_MAIN); $lp_item = Database::get_course_table(TABLE_LP_ITEM); $lp_view = Database::get_course_table(TABLE_LP_VIEW); $lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); // Delete lp item id. foreach ($this->items as $id => $dummy) { $sql = "DELETE FROM {$lp_item_view}\n WHERE c_id = {$course_id} AND lp_item_id = '" . $id . "'"; Database::query($sql); } // Proposed by Christophe (nickname: clefevre) $sql = "DELETE FROM {$lp_item} WHERE c_id = " . $course_id . " AND lp_id = " . $this->lp_id; Database::query($sql); $sql = "DELETE FROM {$lp_view} WHERE c_id = " . $course_id . " AND lp_id = " . $this->lp_id; Database::query($sql); self::toggle_publish($this->lp_id, 'i'); if ($this->type == 2 || $this->type == 3) { // This is a scorm learning path, delete the files as well. $sql = "SELECT path FROM {$lp}\n WHERE c_id = " . $course_id . " AND id = " . $this->lp_id; $res = Database::query($sql); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res); $path = $row['path']; $sql = "SELECT id FROM {$lp}\n WHERE c_id = " . $course_id . " AND path = '{$path}' AND id != " . $this->lp_id; $res = Database::query($sql); if (Database::num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it. if ($this->debug > 2) { error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0); } } else { // No other LP uses that directory, delete it. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty($course_scorm_dir)) { if ($this->debug > 2) { error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0); } // Proposed by Christophe (clefevre). if (strcmp(substr($path, -2), "/.") == 0) { $path = substr($path, 0, -1); // Remove "." at the end. } //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way. rmdirr($course_scorm_dir . $path); } } } } $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $this->lp_id; // Delete tools $sql = "DELETE FROM {$tbl_tool}\n WHERE c_id = " . $course_id . " AND (link LIKE '{$link}%' AND image='scormbuilder.gif')"; Database::query($sql); $sql = "DELETE FROM {$lp} WHERE c_id = " . $course_id . " AND id = " . $this->lp_id; Database::query($sql); // Updates the display order of all lps. $this->update_display_order(); api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id()); $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 4, $id, api_get_session_id()); if ($link_info !== false) { GradebookUtils::remove_resource_from_course_gradebook($link_info['id']); } if (api_get_setting('search_enabled') == 'true') { require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id); } }