From 3878de9bc7ea9e4e74b6abefb3838fc2d01edf31 Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Mon, 15 Jul 2024 19:10:20 -0500 Subject: [PATCH] Internal: Remove special_course field and related data --- public/main/inc/lib/course.lib.php | 80 +++++++------------ .../DataFixtures/ExtraFieldFixtures.php | 8 -- .../Schema/V200/Version20240715183456.php | 37 +++++++++ 3 files changed, 68 insertions(+), 57 deletions(-) create mode 100644 src/CoreBundle/Migrations/Schema/V200/Version20240715183456.php diff --git a/public/main/inc/lib/course.lib.php b/public/main/inc/lib/course.lib.php index 3459e5b1bf..b1342835cb 100644 --- a/public/main/inc/lib/course.lib.php +++ b/public/main/inc/lib/course.lib.php @@ -2714,53 +2714,37 @@ class CourseManager public static function get_special_course_list() { $courseTable = Database::get_main_table(TABLE_MAIN_COURSE); - $tbl_course_field = Database::get_main_table(TABLE_EXTRA_FIELD); - $tbl_course_field_value = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); $tbl_url_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); - $extraFieldType = EntityExtraField::COURSE_FIELD_TYPE; - $courseList = []; - // get course list auto-register - $sql = "SELECT id FROM $tbl_course_field - WHERE item_type = $extraFieldType AND - variable = 'special_course'"; + // Get list of special courses (appear to all) + $sql = "SELECT id FROM $courseTable WHERE sticky = 1"; $result = Database::query($sql); - $courseList = []; + while ($row = Database::fetch_assoc($result)) { + $courseList[] = $row['id']; + } - if (Database::num_rows($result) > 0) { - $row = Database::fetch_assoc($result); - // Get list of special courses (appear to all) - // Note: The value is better indexed as string, so - // using '1' instead of integer is more efficient - $sql = "SELECT DISTINCT(item_id) as cid - FROM $tbl_course_field_value - WHERE field_id = ".$row['id']." AND field_value = '1'"; - $result = Database::query($sql); - while ($row = Database::fetch_assoc($result)) { - $courseList[] = $row['cid']; - } - if (count($courseList) < 1) { - return $courseList; + if (count($courseList) < 1) { + return $courseList; + } + + if (api_get_multiple_access_url()) { + // We filter the courses by the active URL + $coursesSelect = ''; + if (1 == count($courseList)) { + $coursesSelect = $courseList[0]; + } else { + $coursesSelect = implode(',', $courseList); } - if (api_get_multiple_access_url()) { - //we filter the courses by the active URL - $coursesSelect = ''; - if (1 == count($courseList)) { - $coursesSelect = $courseList[0]; - } else { - $coursesSelect = implode(',', $courseList); - } - $access_url_id = api_get_current_access_url_id(); - if (-1 != $access_url_id) { - $sql = "SELECT c_id FROM $tbl_url_course - WHERE access_url_id = $access_url_id - AND c_id IN ($coursesSelect)"; - $result = Database::query($sql); - while ($row = Database::fetch_assoc($result)) { - $courseList[] = $row['c_id']; - } + $access_url_id = api_get_current_access_url_id(); + if (-1 != $access_url_id) { + $sql = "SELECT c_id FROM $tbl_url_course + WHERE access_url_id = $access_url_id + AND c_id IN ($coursesSelect)"; + $result = Database::query($sql); + while ($row = Database::fetch_assoc($result)) { + $courseList[] = $row['c_id']; } } } @@ -3470,16 +3454,14 @@ class CourseManager */ public static function isSpecialCourse($courseId) { - $extraFieldValue = new ExtraFieldValue('course'); - $result = $extraFieldValue->get_values_by_handler_and_field_variable( - $courseId, - 'special_course' - ); + $courseTable = Database::get_main_table(TABLE_MAIN_COURSE); - if (!empty($result)) { - if (1 == $result['field_value']) { - return true; - } + $sql = "SELECT sticky FROM $courseTable WHERE id = " . intval($courseId); + $result = Database::query($sql); + $row = Database::fetch_assoc($result); + + if (!empty($row) && 1 === (int) $row['sticky']) { + return true; } return false; diff --git a/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php b/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php index 88bc63c094..eb2ffecd59 100644 --- a/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php +++ b/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php @@ -76,14 +76,6 @@ class ExtraFieldFixtures extends Fixture implements FixtureGroupInterface 'item_type' => ExtraField::USER_FIELD_TYPE, 'value_type' => ExtraField::FIELD_TYPE_TEXT, ], - [ - 'variable' => 'special_course', - 'display_text' => 'Special course', - 'item_type' => ExtraField::COURSE_FIELD_TYPE, - 'value_type' => ExtraField::FIELD_TYPE_CHECKBOX, - 'visible_to_self' => true, - 'changeable' => true, - ], [ 'variable' => 'tags', 'display_text' => 'Tags', diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240715183456.php b/src/CoreBundle/Migrations/Schema/V200/Version20240715183456.php new file mode 100644 index 0000000000..746c67789a --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240715183456.php @@ -0,0 +1,37 @@ +addSql("DELETE FROM extra_field_values WHERE field_id IN ( + SELECT id FROM extra_field + WHERE item_type = $extraFieldType AND variable = 'special_course' + )"); + + // Delete the extra_field + $this->addSql("DELETE FROM extra_field WHERE variable = 'special_course' AND item_type = $extraFieldType"); + } + + public function down(Schema $schema): void + { + } +}