@@ -126,13 +126,16 @@ public static function close() {
126126 }
127127
128128 /**
129- * Verify that DB connection resource is OK
129+ * Verify that DB connection resource/instance is OK
130+ *
131+ * PHP < 8.1: self::$db is a resource
132+ * PHP >= 8.1: self::$db is an instanceof \PgSql\Connection
130133 *
131134 * @access private
132- * @return bool true when DB connection resource is OK, false otherwise.
135+ * @return bool true when DB connection resource/instance is OK, false otherwise.
133136 */
134137 private static function check () {
135- return is_resource (self ::$ db ) && pg_connection_status (self ::$ db ) === PGSQL_CONNECTION_OK ;
138+ return ( is_resource (self ::$ db) || self :: $ db instanceof \ PgSql \Connection ) && pg_connection_status (self ::$ db ) === PGSQL_CONNECTION_OK ;
136139 }
137140
138141 /**
@@ -148,7 +151,7 @@ public static function get_courses($term) {
148151
149152 // Undergraduate courses from DB.
150153 $ sql = "SELECT course FROM courses WHERE term=$1 AND status=1 " ;
151- $ params = array ( $ term) ;
154+ $ params = [ $ term] ;
152155 $ res = pg_query_params (self ::$ db , $ sql , $ params );
153156 if ($ res === false )
154157 die ("Failed to retrieve course list from DB \n" );
@@ -171,7 +174,7 @@ public static function get_mapped_courses($term) {
171174
172175 // mapped courses from DB
173176 $ sql = "SELECT course, mapped_course FROM mapped_courses WHERE term=$1 " ;
174- $ params = array ( $ term) ;
177+ $ params = [ $ term] ;
175178 $ res = pg_query_params (self ::$ db , $ sql , $ params );
176179 if ($ res === false ) {
177180 die ("Failed to retrieve mapped courses from DB \n" );
@@ -199,15 +202,15 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
199202 die ("Not connected to DB when querying course enrollments \n" );
200203 }
201204
202- $ course_enrollments = array () ;
203- $ manual_flags = array () ;
205+ $ course_enrollments = [] ;
206+ $ manual_flags = [] ;
204207
205208 foreach ($ course_list as $ course ) {
206209 $ grad_course = array_search ($ course , $ mapped_courses );
207210 if ($ grad_course === false ) {
208211 // COURSE HAS NO GRAD SECTION (not mapped).
209212 $ sql = "SELECT COUNT(*) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section IS NOT NULL " ;
210- $ params = array ( $ term , $ course) ;
213+ $ params = [ $ term , $ course] ;
211214 $ res = pg_query_params (self ::$ db , $ sql , $ params );
212215 if ($ res === false )
213216 die ("Failed to lookup enrollments for {$ course }\n" );
@@ -222,7 +225,7 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
222225 } else {
223226 // UNDERGRADUATE SECTION
224227 $ sql = "SELECT COUNT(*) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section='1' " ;
225- $ params = array ( $ term , $ course) ;
228+ $ params = [ $ term , $ course] ;
226229 $ res = pg_query_params (self ::$ db , $ sql , $ params );
227230 if ($ res === false )
228231 die ("Failed to lookup enrollments for {$ course }\n" );
@@ -254,7 +257,7 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
254257 // Courses make up array keys. Sort by courses.
255258 ksort ($ course_enrollments );
256259 ksort ($ manual_flags );
257- return array ( $ course_enrollments , $ manual_flags) ;
260+ return [ $ course_enrollments , $ manual_flags] ;
258261 }
259262}
260263
@@ -282,7 +285,7 @@ public static function write_temp_csv($course_enrollments) {
282285 }
283286
284287 foreach ($ course_enrollments as $ course =>$ num_students ) {
285- fputcsv ($ fh , array ( $ course , $ num_students) , CSV_DELIM_CHAR );
288+ fputcsv ($ fh , [ $ course , $ num_students] , CSV_DELIM_CHAR );
286289 }
287290 fclose ($ fh );
288291 chmod ($ tmp_path . $ tmp_file , 0660 );
@@ -305,7 +308,7 @@ public static function read_temp_csv() {
305308
306309 unlink ($ tmp_path . $ tmp_file ); // remove tmp file.
307310 array_walk ($ csv , 'callbacks::str_getcsv_cb ' );
308- // return array of array( 'course' => enrollment) . e.g. ( 'csci1000' => 100)
311+ // return array of [ 'course' => enrollment] . e.g. [ 'csci1000' => 100]
309312 return array_combine (array_column ($ csv , 0 ), array_column ($ csv , 1 ));
310313 }
311314
@@ -321,9 +324,11 @@ public static function compile_report($prev_course_enrollments, $course_enrollme
321324 // Compile stats
322325 $ date = date ("F j, Y " );
323326 $ time = date ("g:i A " );
324- $ report = "Student autofeed counts report for {$ date } at {$ time }\n" ;
325- $ report .= "NOTE: Difference and ratio do not account for the manual flag. \n" ;
326- $ report .= "COURSE YESTERDAY TODAY MANUAL DIFFERENCE RATIO \n" ;
327+ $ report = <<<HEADING
328+ Student autofeed counts report for {$ date } at {$ time }
329+ NOTE: Difference and ratio do not account for the manual flag.
330+ COURSE YESTERDAY TODAY MANUAL DIFFERENCE RATIO \n
331+ HEADING ;
327332
328333 foreach ($ course_enrollments as $ course =>$ course_enrollment ) {
329334 // Calculate data
@@ -363,7 +368,7 @@ public static function send_report($term, $report) {
363368 $ from = ADD_DROP_FROM_EMAIL ;
364369 $ subject = "Submitty Autofeed Add/Drop Report For {$ date }" ;
365370 $ report = str_replace ("\n" , "\r\n" , $ report ); // needed for email formatting
366- $ is_sent = mail ($ to , $ subject , $ report , array ( 'from ' => $ from) );
371+ $ is_sent = mail ($ to , $ subject , $ report , [ 'from ' => $ from] );
367372 if (!$ is_sent ) {
368373 $ report = str_replace ("\r\n" , "\n" , $ report ); // revert back since not being emailed.
369374 fprintf (STDERR , "Add/Drop report could not be emailed. \n%s " , $ report );
0 commit comments