Skip to content

Commit 5f4bcf6

Browse files
committed
remove branching for unsupported versions
1 parent 823a285 commit 5f4bcf6

File tree

6 files changed

+18
-79
lines changed

6 files changed

+18
-79
lines changed

classes/post/post.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,7 @@ public function moodleoverflow_get_complete_post() {
494494
global $DB, $CFG;
495495
$this->existence_check();
496496

497-
if ($CFG->branch >= 311) {
498-
$allnames = \core_user\fields::for_name()->get_sql('u', false, '', '', false)->selects;
499-
} else {
500-
$allnames = implode(', ', fields::get_name_fields());
501-
}
497+
$allnames = \core_user\fields::for_name()->get_sql('u', false, '', '', false)->selects;
502498
$sql = "SELECT p.*, d.moodleoverflow, $allnames, u.email, u.picture, u.imagealt
503499
FROM {moodleoverflow_posts} p
504500
JOIN {moodleoverflow_discussions} d ON p.discussion = d.id

classes/task/send_review_mails.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
namespace mod_moodleoverflow\task;
2626

27+
use core\cron;
2728
use core\session\exception;
2829
use mod_moodleoverflow\anonymous;
2930
use mod_moodleoverflow\manager\mail_manager;
@@ -123,12 +124,7 @@ public function send_review_notifications() {
123124

124125
foreach ($usersto as $userto) {
125126
try {
126-
// Check for moodle version. Version 401 supported until 8 December 2025.
127-
if ($CFG->branch >= 402) {
128-
\core\cron::setup_user($userto, $course);
129-
} else {
130-
cron_setup_user($userto, $course);
131-
}
127+
cron::setup_user($userto, $course);
132128

133129
$maildata = new moodleoverflow_email(
134130
$course,

locallib.php

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* @copyright 2017 Kennet Winter <[email protected]>
2525
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2626
*/
27+
28+
use core_user\fields;
2729
use mod_moodleoverflow\anonymous;
2830
use mod_moodleoverflow\capabilities;
2931
use mod_moodleoverflow\event\post_deleted;
@@ -69,28 +71,13 @@ function moodleoverflow_get_discussions($cm, $page = -1, $perpage = 0) {
6971
}
7072

7173
// Get all name fields as sql string snippet.
72-
if ($CFG->branch >= 311) {
73-
$allnames = \core_user\fields::for_name()->get_sql('u', false, '', '', false)->selects;
74-
} else {
75-
$allnames = get_all_user_name_fields(true, 'u');
76-
}
74+
$allnames = fields::for_name()->get_sql('u', false, '', '', false)->selects;
7775
$postdata = 'p.id, p.modified, p.discussion, p.userid, p.reviewed';
7876
$discussiondata = 'd.name, d.timemodified, d.timestart, d.usermodified, d.firstpost';
7977
$userdata = 'u.email, u.picture, u.imagealt';
8078

81-
if ($CFG->branch >= 311) {
82-
$usermodifiedfields = \core_user\fields::for_name()->get_sql(
83-
'um',
84-
false,
85-
'um',
86-
'',
87-
false
88-
)->selects .
79+
$usermodifiedfields = fields::for_name()->get_sql('um', false, 'um', '', false)->selects .
8980
', um.email AS umemail, um.picture AS umpicture, um.imagealt AS umimagealt';
90-
} else {
91-
$usermodifiedfields = get_all_user_name_fields(true, 'um', null, 'um') .
92-
', um.email AS umemail, um.picture AS umpicture, um.imagealt AS umimagealt';
93-
}
9481

9582
$params = [$cm->instance];
9683
$whereconditions = ['d.moodleoverflow = ?', 'p.parent = 0'];
@@ -313,11 +300,7 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = -
313300

314301
// Get information about the user who started the discussion.
315302
$startuser = new stdClass();
316-
if ($CFG->branch >= 311) {
317-
$startuserfields = \core_user\fields::get_picture_fields();
318-
} else {
319-
$startuserfields = explode(',', user_picture::fields());
320-
}
303+
$startuserfields = fields::get_picture_fields();
321304

322305
$startuser = username_load_fields_from_object($startuser, $discussion, null, $startuserfields);
323306
$startuser->id = $discussion->userid;
@@ -676,7 +659,7 @@ function moodleoverflow_get_discussions_unread($cm) {
676659
*/
677660
function moodleoverflow_get_post_full($postid) {
678661
global $DB;
679-
$allnames = \core_user\fields::for_name()->get_sql('u', false, '', '', false)->selects;
662+
$allnames = fields::for_name()->get_sql('u', false, '', '', false)->selects;
680663
$sql = "SELECT p.*, d.moodleoverflow, $allnames, u.email, u.picture, u.imagealt
681664
FROM {moodleoverflow_posts} p
682665
JOIN {moodleoverflow_discussions} d ON p.discussion = d.id
@@ -1093,11 +1076,7 @@ function moodleoverflow_get_all_discussion_posts($discussionid, $tracking, $modc
10931076
}
10941077

10951078
// Get all username fields.
1096-
if ($CFG->branch >= 311) {
1097-
$allnames = \core_user\fields::for_name()->get_sql('u', false, '', '', false)->selects;
1098-
} else {
1099-
$allnames = get_all_user_name_fields(true, 'u');
1100-
}
1079+
$allnames = fields::for_name()->get_sql('u', false, '', '', false)->selects;
11011080

11021081
$additionalwhere = '';
11031082

@@ -1284,11 +1263,7 @@ function moodleoverflow_print_post(
12841263

12851264
// Build the object that represents the posting user.
12861265
$postinguser = new stdClass();
1287-
if ($CFG->branch >= 311) {
1288-
$postinguserfields = \core_user\fields::get_picture_fields();
1289-
} else {
1290-
$postinguserfields = explode(',', user_picture::fields());
1291-
}
1266+
$postinguserfields = fields::get_picture_fields();
12921267
$postinguser = username_load_fields_from_object($postinguser, $post, null, $postinguserfields);
12931268

12941269
// Post was anonymized.

mod_form.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ public function definition() {
7171
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
7272

7373
// Adding the standard "intro" and "introformat" fields.
74-
if ($CFG->branch >= 29) {
75-
$this->standard_intro_elements();
76-
} else {
77-
$this->add_intro_editor();
78-
}
74+
$this->standard_intro_elements();
7975

8076
$currentsetting = $this->current && property_exists($this->current, 'anonymous') ? $this->current->anonymous : 0;
8177
$possiblesettings = [
@@ -174,7 +170,7 @@ public function definition() {
174170
$mform->addElement(
175171
'header',
176172
'gradeheading',
177-
$CFG->branch >= 311 ? get_string('gradenoun') : get_string('grade')
173+
get_string('gradenoun')
178174
);
179175

180176
$mform->addElement('text', 'grademaxgrade', get_string('modgrademaxgrade', 'grades'));

tests/behat/behat_mod_moodleoverflow.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -225,30 +225,10 @@ public function i_comment_moodleoverflow_post_with_message(string $postmessage,
225225
* @param TableNode $data
226226
*/
227227
public function i_add_moodleoverflow_to_course_and_fill_form(string $courseshortname, string $sectionnumber, TableNode $data) {
228-
global $CFG;
229-
230-
if ($CFG->branch >= 404) {
231-
$this->execute(
232-
"behat_course::i_add_to_course_section_and_i_fill_the_form_with",
233-
[$this->escape('moodleoverflow'), $this->escape($courseshortname), $this->escape($sectionnumber), $data]
234-
);
235-
} else {
236-
// This is the code from the deprecated behat function "i_add_to_section_and_i_fill_the_form_with".
237-
// Add activity to section.
238-
$this->execute(
239-
"behat_course::i_add_to_section",
240-
[$this->escape('moodleoverflow'), $this->escape($sectionnumber)]
241-
);
242-
243-
// Wait to be redirected.
244-
$this->execute('behat_general::wait_until_the_page_is_ready');
245-
246-
// Set form fields.
247-
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
248-
249-
// Save course settings.
250-
$this->execute("behat_forms::press_button", get_string('savechangesandreturntocourse'));
251-
}
228+
$this->execute(
229+
"behat_course::i_add_to_course_section_and_i_fill_the_form_with",
230+
[$this->escape('moodleoverflow'), $this->escape($courseshortname), $this->escape($sectionnumber), $data]
231+
);
252232
}
253233

254234
/**

tests/review_test.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,7 @@ private function assert_matches_properties($expected, $actual) {
262262
$expected = (array)$expected;
263263
$actual = (object)$actual;
264264
foreach ($expected as $key => $value) {
265-
if ($CFG->branch >= 404) {
266-
$this->assertObjectHasProperty($key, $actual, "Failed asserting that attribute '$key' exists.");
267-
} else {
268-
$this->assertObjectHasAttribute($key, $actual, "Failed asserting that attribute '$key' exists.");
269-
}
265+
$this->assertObjectHasProperty($key, $actual, "Failed asserting that attribute '$key' exists.");
270266
$this->assertEquals($value, $actual->$key, "Failed asserting that \$obj->$key '" . $actual->$key . "' equals '$value'");
271267
}
272268
}

0 commit comments

Comments
 (0)