Skip to content

Commit

Permalink
Merge branch 'MDL-75072-master' of https://github.com/junpataleta/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Jun 30, 2022
2 parents 718cb29 + d4fe1b3 commit 3af7eee
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 115 deletions.
2 changes: 1 addition & 1 deletion mod/forum/backup/moodle2/backup_forum_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function define_structure() {
'maxbytes', 'maxattachments', 'forcesubscribe', 'trackingtype',
'rsstype', 'rssarticles', 'timemodified', 'warnafter',
'blockafter', 'blockperiod', 'completiondiscussions', 'completionreplies',
'completionposts', 'displaywordcount', 'lockdiscussionafter', 'grade_forum', 'usecoursefullname'));
'completionposts', 'displaywordcount', 'lockdiscussionafter', 'grade_forum'));

$discussions = new backup_nested_element('discussions');

Expand Down
3 changes: 1 addition & 2 deletions mod/forum/classes/local/data_mappers/legacy/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public function to_legacy_objects(array $forums) : array {
'displaywordcount' => $forum->should_display_word_count(),
'lockdiscussionafter' => $forum->get_lock_discussions_after(),
'duedate' => $forum->get_due_date(),
'cutoffdate' => $forum->get_cutoff_date(),
'usecoursefullname' => $forum->use_course_fullname()
'cutoffdate' => $forum->get_cutoff_date()
];
}, $forums);
}
Expand Down
16 changes: 1 addition & 15 deletions mod/forum/classes/local/entities/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ class forum {
private $duedate;
/** @var int $cutoffdate Timestamp after which forum posts will no longer be accepted */
private $cutoffdate;
/** @var bool $usecoursefullname Whether to use course full name instead of short name in notifications */
private $usecoursefullname;

/**
* Constructor
Expand Down Expand Up @@ -146,7 +144,6 @@ class forum {
* @param int $lockdiscussionafter Timestamp after which discussions should be locked
* @param int $duedate Timestamp that represents the due date for forum posts
* @param int $cutoffdate Timestamp after which forum posts will no longer be accepted
* @param bool $usecoursefullname Whether to use course full name instead of short name in notifications
*/
public function __construct(
context $context,
Expand Down Expand Up @@ -181,8 +178,7 @@ public function __construct(
bool $displaywordcount,
int $lockdiscussionafter,
int $duedate,
int $cutoffdate,
bool $usecoursefullname = false
int $cutoffdate
) {
$this->context = $context;
$this->coursemodule = $coursemodule;
Expand Down Expand Up @@ -217,7 +213,6 @@ public function __construct(
$this->lockdiscussionafter = $lockdiscussionafter;
$this->duedate = $duedate;
$this->cutoffdate = $cutoffdate;
$this->usecoursefullname = $usecoursefullname;
}

/**
Expand Down Expand Up @@ -674,13 +669,4 @@ public function is_discussion_locked(discussion_entity $discussion) : bool {

return $this->is_discussion_time_locked($discussion);
}

/**
* Should use course full name instead of short name in notifications?
*
* @return bool
*/
public function use_course_fullname(): bool {
return $this->usecoursefullname;
}
}
3 changes: 1 addition & 2 deletions mod/forum/classes/local/factories/entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public function get_forum_from_stdclass(
$record->displaywordcount,
$record->lockdiscussionafter,
$record->duedate,
$record->cutoffdate,
$record->usecoursefullname ?? false
$record->cutoffdate
);
}

Expand Down
17 changes: 2 additions & 15 deletions mod/forum/classes/output/forum_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected function export_for_template_text(\mod_forum_renderer $renderer) {
$data = $this->export_for_template_shared($renderer);
return $data + array(
'id' => html_entity_decode($this->post->id),
'coursename' => html_entity_decode($this->get_forum_coursename()),
'coursename' => html_entity_decode($this->get_coursename()),
'courselink' => html_entity_decode($this->get_courselink()),
'forumname' => html_entity_decode($this->get_forumname()),
'showdiscussionname' => html_entity_decode($this->get_showdiscussionname()),
Expand Down Expand Up @@ -197,7 +197,7 @@ protected function export_for_template_html(\mod_forum_renderer $renderer) {
$data = $this->export_for_template_shared($renderer);
return $data + array(
'id' => $this->post->id,
'coursename' => $this->get_forum_coursename(),
'coursename' => $this->get_coursename(),
'courselink' => $this->get_courselink(),
'forumname' => $this->get_forumname(),
'showdiscussionname' => $this->get_showdiscussionname(),
Expand Down Expand Up @@ -485,19 +485,6 @@ public function get_coursename() {
));
}

/**
* The name of the course that the forum is in, based on forum setting.
*
* @return string
*/
public function get_forum_coursename() {
if ($this->forum->usecoursefullname) {
return $this->get_coursefullname();
} else {
return $this->get_coursename();
}
}

/**
* The name of the forum.
*
Expand Down
3 changes: 2 additions & 1 deletion mod/forum/classes/task/send_user_notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ protected function send_post($course, $forum, $discussion, $post, $cm, $context)
'sitefullname' => format_string($site->fullname),
'siteshortname' => format_string($site->shortname),
'courseidnumber' => $data->get_courseidnumber(),
'coursename' => $data->get_forum_coursename(),
'coursefullname' => $data->get_coursefullname(),
'courseshortname' => $data->get_coursename(),
];
$postsubject = html_to_text(get_string('postmailsubject', 'forum', $a), 0);

Expand Down
1 change: 0 additions & 1 deletion mod/forum/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<FIELD NAME="completionposts" TYPE="int" LENGTH="9" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Nonzero if a certain number of posts or replies (total) are required to mark this forum complete for a user."/>
<FIELD NAME="displaywordcount" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="lockdiscussionafter" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="usecoursefullname" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
20 changes: 12 additions & 8 deletions mod/forum/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,21 @@ function xmldb_forum_upgrade($oldversion) {
// Automatically generated Moodle v4.0.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2022041901) {
// Define field usecoursefullname to be added to forum.
if ($oldversion < 2022062700) {
// Unset $CFG->forum_usecoursefullname.
unset_config('forum_usecoursefullname');

// Define field usecoursefullname to be dropped from forum.
$table = new xmldb_table('forum');
$field = new xmldb_field('usecoursefullname', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0',
'lockdiscussionafter');
$field = new xmldb_field('usecoursefullname');

// Conditionally launch add field usecoursefullname.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
// Conditionally launch drop field usecoursefullname.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
upgrade_mod_savepoint(true, 2022041901, 'forum');

// Forum savepoint reached.
upgrade_mod_savepoint(true, 2022062700, 'forum');
}

return true;
Expand Down
1 change: 0 additions & 1 deletion mod/forum/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public static function get_forums_by_courses_returns() {
'numdiscussions' => new external_value(PARAM_INT, 'Number of discussions in the forum', VALUE_OPTIONAL),
'cancreatediscussions' => new external_value(PARAM_BOOL, 'If the user can create discussions', VALUE_OPTIONAL),
'lockdiscussionafter' => new external_value(PARAM_INT, 'After what period a discussion is locked', VALUE_OPTIONAL),
'usecoursefullname' => new external_value(PARAM_INT, 'Whether to use course full name for notifications'),
'istracked' => new external_value(PARAM_BOOL, 'If the user is tracking the forum', VALUE_OPTIONAL),
'unreadpostscount' => new external_value(PARAM_INT, 'The number of unread posts for tracked forums',
VALUE_OPTIONAL),
Expand Down
5 changes: 1 addition & 4 deletions mod/forum/lang/en/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
$string['configshortpost'] = 'Any post under this length (in characters not including HTML) is considered short (see below).';
$string['configtrackingtype'] = 'Default setting for read tracking.';
$string['configtrackreadposts'] = 'Set to \'yes\' if you want to track read/unread for each user.';
$string['configusecoursefullname'] = 'Default setting to use course full name instead of course short name for notifications.';
$string['configusermarksread'] = 'If \'yes\', the user must manually mark a post as read. If \'no\', when the post is viewed it is marked as read.';
$string['confirmsubscribediscussion'] = 'Do you really want to subscribe to discussion \'{$a->discussion}\' in forum \'{$a->forum}\'?';
$string['confirmunsubscribediscussion'] = 'Do you really want to unsubscribe from discussion \'{$a->discussion}\' in forum \'{$a->forum}\'?';
Expand Down Expand Up @@ -525,7 +524,7 @@
$string['postmailinfo'] = 'This is a copy of a message posted in {$a}.';
$string['postmailnow'] = '<p>This post will be mailed out immediately to all forum subscribers.</p>';
$string['postmailreply'] = 'To reply click on this link: {$a}';
$string['postmailsubject'] = '{$a->coursename}: {$a->subject}';
$string['postmailsubject'] = '{$a->courseshortname}: {$a->subject}';
$string['postrating1'] = 'Mostly separate knowing';
$string['postrating2'] = 'Separate and connected';
$string['postrating3'] = 'Mostly connected knowing';
Expand Down Expand Up @@ -744,8 +743,6 @@
$string['unsubscribeallempty'] = 'You are not subscribed to any forums. To disable all notifications from this server go to Messaging in My Profile Settings.';
$string['unsubscribed'] = 'Unsubscribed';
$string['unsubscribeshort'] = 'Unsubscribe';
$string['usecoursefullname'] = 'Use course full name in notifications';
$string['usecoursefullname_help'] = 'Use course full name instead of course short name for notifications.';
$string['useexperimentalui'] = 'Use experimental nested discussion view';
$string['usermarksread'] = 'Manual message read marking';
$string['usernavigation'] = 'User navigation';
Expand Down
9 changes: 2 additions & 7 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ function forum_update_instance($forum, $mform) {
$forum->assesstimefinish = 0;
}

if (empty($forum->usecoursefullname)) {
$forum->usecoursefullname = 0;
}

$oldforum = $DB->get_record('forum', array('id'=>$forum->id));

// MDL-3942 - if the aggregation type or scale (i.e. max grade) changes then recalculate the grades for the entire forum
Expand Down Expand Up @@ -596,7 +592,7 @@ function forum_print_recent_activity($course, $viewfullnames, $timestart) {
f.scale, f.grade_forum, f.maxbytes, f.maxattachments, f.forcesubscribe,
f.trackingtype, f.rsstype, f.rssarticles, f.timemodified, f.warnafter, f.blockafter,
f.blockperiod, f.completiondiscussions, f.completionreplies, f.completionposts,
f.displaywordcount, f.lockdiscussionafter, f.grade_forum_notify, f.usecoursefullname,
f.displaywordcount, f.lockdiscussionafter, f.grade_forum_notify,
d.name AS discussionname, d.firstpost, d.userid AS discussionstarter,
d.assessed AS discussionassessed, d.timemodified, d.usermodified, d.forum, d.groupid,
d.timestart, d.timeend, d.pinned, d.timelocked,
Expand Down Expand Up @@ -688,8 +684,7 @@ function forum_print_recent_activity($course, $viewfullnames, $timestart) {
'completionposts' => $post->completionposts,
'displaywordcount' => $post->displaywordcount,
'lockdiscussionafter' => $post->lockdiscussionafter,
'grade_forum_notify' => $post->grade_forum_notify,
'usecoursefullname' => $post->usecoursefullname
'grade_forum_notify' => $post->grade_forum_notify
];
// Build the forum entity from the factory.
$forumentity = $entityfactory->get_forum_from_stdclass($forumrecord, $context, $coursemodule, $course);
Expand Down
4 changes: 0 additions & 4 deletions mod/forum/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ function definition() {
}
$mform->setDefault('trackingtype', $default);

$mform->addElement('checkbox', 'usecoursefullname', get_string('usecoursefullname', 'forum'), null);
$mform->addHelpButton('usecoursefullname', 'usecoursefullname', 'forum');
$mform->setDefault('usecoursefullname', $CFG->forum_usecoursefullname);

if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) {
//-------------------------------------------------------------------------------
$mform->addElement('header', 'rssheader', get_string('rss'));
Expand Down
4 changes: 0 additions & 4 deletions mod/forum/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@
$settings->add(new admin_setting_configselect('digestmailtime', get_string('digestmailtime', 'forum'),
get_string('configdigestmailtime', 'forum'), 17, $options));

// Use full course name for notification.
$settings->add(new admin_setting_configcheckbox('forum_usecoursefullname', get_string('usecoursefullname', 'forum'),
get_string('configusecoursefullname', 'forum'), 0));

if (empty($CFG->enablerssfeeds)) {
$options = array(0 => get_string('rssglobaldisabled', 'admin'));
$str = get_string('configenablerssfeeds', 'forum').'<br />'.get_string('configenablerssfeedsdisabled2', 'admin');
Expand Down
5 changes: 1 addition & 4 deletions mod/forum/tests/entities_forum_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function test_entity() {
$lockdiscussionafter = 0;
$duedate = 0;
$cutoffdate = 0;
$usecoursefullname = 0;
$sendnotification = false;
$forum = new forum_entity(
$context,
Expand Down Expand Up @@ -125,8 +124,7 @@ public function test_entity() {
$displaywordcount,
$lockdiscussionafter,
$duedate,
$cutoffdate,
$usecoursefullname
$cutoffdate
);

$this->assertEquals($context, $forum->get_context());
Expand Down Expand Up @@ -169,6 +167,5 @@ public function test_entity() {
$this->assertEquals(false, $forum->is_due_date_reached());
$this->assertEquals(false, $forum->has_cutoff_date());
$this->assertEquals(false, $forum->is_cutoff_date_reached());
$this->assertEquals(false, $forum->use_course_fullname());
}
}
46 changes: 1 addition & 45 deletions mod/forum/tests/mail_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ public function test_long_subject() {

// Post a discussion to the forum.
$subject = 'This is the very long forum post subject that somebody was very kind of leaving, it is intended to check if long subject comes in mail correctly. Thank you.';
$a = (object)array('coursename' => $course->shortname, 'forumname' => $forum->name, 'subject' => $subject);
$a = (object)array('courseshortname' => $course->shortname, 'forumname' => $forum->name, 'subject' => $subject);
$expectedsubject = get_string('postmailsubject', 'forum', $a);
list($discussion, $post) = $this->helper_post_to_forum($forum, $author, array('name' => $subject));

Expand All @@ -930,50 +930,6 @@ public function test_long_subject() {
$this->assertEquals($expectedsubject, $message->subject);
}

/**
* Test usecoursefullname option for notification.
*
* @covers \mod_forum\task\send_user_notifications
*/
public function test_usecoursefullname() {
$this->resetAfterTest();

$record = [];
$record['fullname'] = 'Test Course Full Name';
$record['shortname'] = 'Shortname';

// Create a course, with a forum.
$course = $this->getDataGenerator()->create_course($record);

$options = array('course' => $course->id, 'forcesubscribe' => FORUM_FORCESUBSCRIBE, 'usecoursefullname' => true);
$forum = $this->getDataGenerator()->create_module('forum', $options);

// Create a user enrolled in the course as student.
list($author) = $this->helper_create_users($course, 1);

// Post a discussion to the forum.
$subject = 'This is the forum post subject.';
// Expect coursefullname instead of shortname.
$a = (object)array('coursename' => $course->fullname, 'subject' => $subject);
$expectedsubject = get_string('postmailsubject', 'forum', $a);
list($discussion, $post) = $this->helper_post_to_forum($forum, $author, array('name' => $subject));

// Run cron and check that the expected number of users received the notification.
$expect = [
'author' => (object) [
'userid' => $author->id,
'messages' => 1,
],
];
$this->queue_tasks_and_assert($expect);

$this->send_notifications_and_assert($author, [$post]);
$messages = $this->messagesink->get_messages();
$this->assertEquals($expectedsubject, $messages[0]->subject);
$this->assertStringContainsString($course->fullname, $messages[0]->fullmessage);
$this->assertStringContainsString($course->fullname, $messages[0]->fullmessagehtml);
}

/**
* Test inital email and reply email subjects
*/
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022041901; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2022062700; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2022041200; // Requires this Moodle version.
$plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)

0 comments on commit 3af7eee

Please sign in to comment.