Commit 40318d20 authored by Lisa Seeto's avatar Lisa Seeto

Bug 1847379: The 'read' column for module_multirecipient_userrelation is a char and not integer

- alter module_multirecipient_userrelation install file to use int type
- upgrade module_multirecipient_userrelation to alter type in versioning
- upgrade version number

behatnotneeded

Change-Id: I255382518241cba2430bae544fa53cc82a0b266b
Signed-off-by: default avatarLisa Seeto <lisaseeto@catalyst.net.nz>
parent 1babdfd1
......@@ -1552,5 +1552,16 @@ function xmldb_core_upgrade($oldversion=0) {
ElasticsearchIndexing::drop_trigger_functions();
}
if ($oldversion < 2019111500) {
log_debug('Alter module_multirecipient_userrelation table column types');
$table = new XMLDBTable('module_multirecipient_userrelation');
$field = new XMLDBField('read');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
change_field_type($table, $field, true, true);
$field = new XMLDBField('deleted');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
change_field_type($table, $field, true, true);
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2019111100;
$config->version = 2019111500;
$config->series = '20.04';
$config->release = '20.04dev';
$config->minupgradefrom = 2017031605;
......
......@@ -28,8 +28,8 @@
<FIELD NAME="role" TYPE="char" LENGTH="9" ENUM="true" ENUMVALUES="'sender','recipient'" NOTNULL="true" DEFAULT="recipient" COMMENT="the role of user-relation"/>
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="relation to the user"/>
<FIELD NAME="notification" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="the message-relation"/>
<FIELD NAME="read" TYPE="char" LENGTH="1" ENUM="true" ENUMVALUES="'0','1'" DEFAULT="0" NOTNULL="true" COMMENT="boolean value indicating if the message has been read"/>
<FIELD NAME="deleted" TYPE="char" LENGTH="1" ENUM="true" ENUMVALUES="'0','1'" DEFAULT="0" NOTNULL="true" COMMENT="boolean value indicating if the message has been deleted"/>
<FIELD NAME="read" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" COMMENT="boolean value indicating if the message has been read"/>
<FIELD NAME="deleted" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" COMMENT="boolean value indicating if the message has been deleted"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
......@@ -38,4 +38,4 @@
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
\ No newline at end of file
</XMLDB>
......@@ -197,7 +197,7 @@ function delete_all_notifications_submit() {
ON msg.id = rel.notification
AND rel.usr = ?
AND rel.role = ?
AND rel.deleted = \'0\'
AND rel.deleted = 0
' . $typecond;
$result = get_records_sql_array($query, array($userid, 'recipient'));
$msgids = array();
......
......@@ -82,7 +82,7 @@ if ($markasread) {
$column = 'id';
}
set_field_select(
$list, 'read', '1',
$list, 'read', 1,
$column . ' IN (' . join(',', array_map('db_quote', $idsperlist)) . ') AND usr = ?',
array($USER->get('id'))
);
......
......@@ -136,7 +136,7 @@ class PluginModuleMultirecipientnotification extends PluginModule {
UNION
SELECT COUNT(*) AS counts FROM {notification_internal_activity} WHERE \"read\" = ? AND usr = ?
) AS countsum
) WHERE id = ?", array('0', $usr, 0, $usr, $usr), false);
) WHERE id = ?", array(0, $usr, 0, $usr, $usr), false);
}
public static function postinst($prevversion) {
......
......@@ -79,7 +79,7 @@ function activitylistin($type='all', $limit=10, $offset=0) {
ON a.id = b.notification
INNER JOIN {activity_type} AS at ON a.type = at.id
WHERE b.usr = ?
AND b.deleted = '0'
AND b.deleted = 0
AND b.role = '" . $notificationtargetrole . "'
" . $typesql . "
)";
......@@ -459,7 +459,7 @@ function activitylistout($type='all', $limit=10, $offset=0) {
ON a.id = b.notification
INNER JOIN {activity_type} AS at ON a.type = at.id
WHERE b.usr = ?
AND b.deleted = '0'
AND b.deleted = 0
AND b.role = '" . $notificationtargetrole . "'
" . $typesql . "
)";
......
......@@ -139,7 +139,7 @@ function mark_as_read_mr(array $msgids, $usr = null, $read = true) {
db_begin();
foreach ($msgids as $msgid) {
$change = new stdClass();
$change->read = $read ? '1' : '0';
$change->read = $read ? 1 : 0;
$where = array(
'notification' => $msgid,
......@@ -172,8 +172,8 @@ function delete_messages_mr(array $msgids, $usr = null) {
$query = '
UPDATE {module_multirecipient_userrelation}
SET deleted = \'1\',
"read" = \'1\'
SET deleted = 1,
"read" = 1
WHERE usr = ?
AND notification in (' . join(',', $msgids) . ')';
execute_sql($query, array($usr));
......@@ -182,7 +182,7 @@ function delete_messages_mr(array $msgids, $usr = null) {
SELECT DISTINCT a.id
FROM {module_multirecipient_notification} AS a
LEFT JOIN {module_multirecipient_userrelation} AS ur
ON a.id = ur.notification AND ur.deleted = \'0\'
ON a.id = ur.notification AND ur.deleted = 0
WHERE a.id IN (' . join(',', array_map('db_quote', $msgids)) . ')
AND ur.id IS NULL';
$deleteidrecords = get_records_sql_array($query, array());
......@@ -344,10 +344,10 @@ function get_message_mr($usr, $msgid) {
$message->fromid = -1;
foreach ($userrelations as $userrel) {
if ($userrel->usr == $usr) {
if ('1' === $userrel->deleted) {
if ($userrel->deleted) {
return null;
}
else if ('1' === $userrel->read) {
else if ($userrel->read) {
$message->read = 1;
}
else {
......@@ -429,7 +429,7 @@ function get_messages_by_ids_mr($usr, array $msgids) {
if (!array_key_exists($msgid, $return)) {
continue;
}
if (($userrel->usr == $usr) && ('1' === $userrel->deleted)) {#
if (($userrel->usr == $usr) && ($userrel->deleted)) {
$return = array_diff_assoc($return, array($msgid => $return[$msgid]));
continue;
}
......
......@@ -119,7 +119,7 @@ function get_message_search($searchstring, $type, $offset, $limit, $location, $u
FROM {module_multirecipient_notification} AS notif
INNER JOIN {module_multirecipient_userrelation} AS relation
ON notif.id = relation.notification
WHERE " . $query_new_where . " AND relation.deleted = '0'
WHERE " . $query_new_where . " AND relation.deleted = 0
)";
$query_old_where = array();
$query_new_where = array();
......@@ -315,4 +315,4 @@ function get_message_search($searchstring, $type, $offset, $limit, $location, $u
$return['Message']['data'] = null;
}
return $return;
}
\ No newline at end of file
}
......@@ -99,7 +99,7 @@ class ActivityTypeMultirecipientmessage extends ActivityTypeUsermessage {
}
if ('sender' === $userdata->role) {
$userdata->read = '0';
$userdata->read = 0;
}
$userdata->internalid = insert_record('module_multirecipient_userrelation',
......@@ -108,7 +108,7 @@ class ActivityTypeMultirecipientmessage extends ActivityTypeUsermessage {
$changes->url = $userdata->url = $this->url;
}
if ($user->method != 'internal') {
$changes->read = (string)(int) ($user->method != 'internal');
$changes->read = (int) ($user->method != 'internal');
$changes->id = $userdata->internalid;
update_record('module_multirecipient_userrelation', $changes);
}
......
......@@ -175,7 +175,7 @@ function delete_all_notifications_submit() {
ON msg.id = rel.notification
AND rel.usr = ?
AND rel.role = ?
AND rel.deleted = \'0\'
AND rel.deleted = 0
' . $typecond;
$result = get_records_sql_array($query, array($userid, 'sender'));
$msgids = array();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment