@@ -45,17 +45,25 @@ public function get_name(): string {
45
45
* Execute.
46
46
*/
47
47
public function execute () {
48
- global $ DB ;
48
+ global $ CFG , $ DB ;
49
49
50
50
// Get the certificatesperrun, includeinnotvisiblecourses, and certificateexecutionperiod configurations.
51
51
$ certificatesperrun = (int )get_config ('customcert ' , 'certificatesperrun ' );
52
52
$ includeinnotvisiblecourses = (bool )get_config ('customcert ' , 'includeinnotvisiblecourses ' );
53
53
$ certificateexecutionperiod = (int )get_config ('customcert ' , 'certificateexecutionperiod ' );
54
54
$ offset = (int )get_config ('customcert ' , 'certificate_offset ' );
55
55
56
- // We are going to issue certificates that have requested someone get emailed.
56
+ if ($ CFG ->dbtype === 'oci ' ) {
57
+ // For Oracle, convert the CLOB to a VARCHAR2 (limiting to 4000 characters) since we are using DISTINCT.
58
+ $ emailothersselect = "DBMS_LOB.SUBSTR(c.emailothers, 4000, 1) AS emailothers " ;
59
+ $ emailotherslengthsql = "DBMS_LOB.GETLENGTH(c.emailothers) " ;
60
+ } else {
61
+ $ emailothersselect = "c.emailothers " ;
62
+ $ emailotherslengthsql = $ DB ->sql_length ('c.emailothers ' );
63
+ }
64
+
57
65
$ emailotherslengthsql = $ DB ->sql_length ('c.emailothers ' );
58
- $ sql = "SELECT c.id, c.templateid, c.course, c.requiredtime, c.emailstudents, c.emailteachers, c.emailothers ,
66
+ $ sql = "SELECT DISTINCT c.id, c.templateid, c.course, c.requiredtime, c.emailstudents, c.emailteachers, $ emailothersselect ,
59
67
ct.id AS templateid, ct.name AS templatename, ct.contextid, co.id AS courseid,
60
68
co.fullname AS coursefullname, co.shortname AS courseshortname
61
69
FROM {customcert} c
@@ -66,11 +74,10 @@ public function execute() {
66
74
JOIN {course_categories} cat
67
75
ON co.category = cat.id
68
76
LEFT JOIN {customcert_issues} ci
69
- ON c.id = ci.customcertid " ;
70
-
71
- $ sql .= " WHERE (c.emailstudents = :emailstudents
72
- OR c.emailteachers = :emailteachers
73
- OR $ emailotherslengthsql >= 3) " ;
77
+ ON c.id = ci.customcertid
78
+ WHERE (c.emailstudents = :emailstudents
79
+ OR c.emailteachers = :emailteachers
80
+ OR $ emailotherslengthsql >= 3) " ;
74
81
75
82
$ params = ['emailstudents ' => 1 , 'emailteachers ' => 1 ];
76
83
@@ -88,8 +95,6 @@ public function execute() {
88
95
$ params ['enddate2 ' ] = $ params ['enddate ' ];
89
96
}
90
97
91
- $ sql .= " GROUP BY c.id, ct.id, ct.name, ct.contextid, co.id, co.fullname, co.shortname " ;
92
-
93
98
// Execute the SQL query.
94
99
$ customcerts = $ DB ->get_records_sql ($ sql , $ params , $ offset , $ certificatesperrun );
95
100
0 commit comments