Skip to content

Commit 4e0d0e5

Browse files
authored
[flag] Add flag editors table (#9478)
- Introduce a flag_editors table that tracks who has edited an instrument - Removes UserID from flag as it is replaced with the first entry of flag_editors - Removes User1 and User2 from conflicts_resolved as they are misleading columns, and also not useful now that UserID is gone from flag
1 parent 7c5810a commit 4e0d0e5

File tree

11 files changed

+11294
-5635
lines changed

11 files changed

+11294
-5635
lines changed

SQL/0000-00-00-schema.sql

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ CREATE TABLE `flag` (
299299
`Administration` enum('None','Partial','All') default NULL,
300300
`Validity` enum('Questionable','Invalid','Valid') default NULL,
301301
`Exclusion` enum('Fail','Pass') default NULL,
302-
`UserID` varchar(255) default NULL,
303302
`Testdate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
304303
`DataID` int(10) unsigned default NULL,
305304
PRIMARY KEY (`CommentID`),
@@ -309,12 +308,29 @@ CREATE TABLE `flag` (
309308
KEY `flag_Data_entry` (`Data_entry`),
310309
KEY `flag_Validity` (`Validity`),
311310
KEY `flag_Administration` (`Administration`),
312-
KEY `flag_UserID` (`UserID`),
313311
CONSTRAINT `FK_flag_1` FOREIGN KEY (`SessionID`) REFERENCES `session` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
314312
CONSTRAINT `FK_flag_3` FOREIGN KEY (`DataID`) REFERENCES `instrument_data` (`ID`),
315313
CONSTRAINT `FK_ibfk_1` FOREIGN KEY (`TestID`) REFERENCES `test_names` (`ID`)
316314
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
317315

316+
CREATE TABLE `flag_editors` (
317+
`userID` int(10) unsigned NOT NULL default '0',
318+
`CommentID` VARCHAR(255) NOT NULL default '',
319+
`editDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
320+
PRIMARY KEY (`userID`,`CommentID`),
321+
KEY `FK_flag_editors_2` (`CommentID`),
322+
CONSTRAINT `FK_flag_editors_2`
323+
FOREIGN KEY (`CommentID`)
324+
REFERENCES `flag` (`CommentID`)
325+
ON DELETE CASCADE
326+
ON UPDATE CASCADE,
327+
CONSTRAINT `FK_flag_editors_1`
328+
FOREIGN KEY (`userID`)
329+
REFERENCES `users` (`ID`)
330+
ON DELETE CASCADE
331+
ON UPDATE CASCADE
332+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
333+
318334
CREATE TABLE `history` (
319335
`id` int(11) NOT NULL auto_increment,
320336
`tbl` varchar(255) NOT NULL default '',
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CREATE TABLE `flag_editors` (
2+
`userID` int(10) unsigned NOT NULL default '0',
3+
`CommentID` VARCHAR(255) NOT NULL default '',
4+
`editDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
5+
PRIMARY KEY (`userID`,`CommentID`),
6+
KEY `FK_flag_editors_2` (`CommentID`),
7+
CONSTRAINT `FK_flag_editors_2`
8+
FOREIGN KEY (`CommentID`)
9+
REFERENCES `flag` (`CommentID`)
10+
ON DELETE CASCADE
11+
ON UPDATE CASCADE,
12+
CONSTRAINT `FK_flag_editors_1`
13+
FOREIGN KEY (`userID`)
14+
REFERENCES `users` (`ID`)
15+
ON DELETE CASCADE
16+
ON UPDATE CASCADE
17+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18+
19+
INSERT INTO flag_editors (userID, CommentID)
20+
SELECT users.ID, CommentID from flag JOIN users ON flag.UserID = users.UserID;
21+
22+
ALTER TABLE flag DROP COLUMN UserID;

modules/conflict_resolver/jsx/resolved_filterabledatatable.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,6 @@ class ResolvedFilterableDataTable extends Component {
178178
name: 'CorrectAnswer',
179179
type: 'text',
180180
}},
181-
{label: 'User 1', show: true, filter: {
182-
name: 'User1',
183-
type: 'text',
184-
}},
185-
{label: 'User 2', show: true, filter: {
186-
name: 'User2',
187-
type: 'text',
188-
}},
189181
{label: 'Resolver', show: true, filter: {
190182
name: 'Resolver',
191183
type: 'text',

modules/conflict_resolver/php/endpoints/unresolved.class.inc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,6 @@ class Unresolved extends Endpoint implements ETagCalculator
293293
'
294294
REPLACE INTO conflicts_resolved (
295295
UserID,
296-
User1,
297-
User2,
298296
TestName,
299297
ExtraKeyColumn,
300298
ExtraKey1,
@@ -309,8 +307,6 @@ class Unresolved extends Endpoint implements ETagCalculator
309307
)
310308
SELECT
311309
:v_username,
312-
f1.UserID,
313-
f2.UserID,
314310
cu.TestName,
315311
cu.ExtraKeyColumn,
316312
cu.ExtraKey1,
@@ -331,8 +327,6 @@ class Unresolved extends Endpoint implements ETagCalculator
331327
UNION DISTINCT
332328
SELECT
333329
:v_username,
334-
cr.User1,
335-
cr.User2,
336330
cr.TestName,
337331
cr.ExtraKeyColumn,
338332
cr.ExtraKey1,

modules/conflict_resolver/php/models/resolveddto.class.inc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ class ResolvedDTO implements DataInstance, SiteHaver
4848
protected $description;
4949
protected $oldValue;
5050
protected $correctanswer;
51-
protected $user1;
52-
protected $user2;
5351
protected $resolver;
5452
protected $resolutiontimestamp;
5553

@@ -73,8 +71,6 @@ class ResolvedDTO implements DataInstance, SiteHaver
7371
'Description' => "",
7472
'Incorrect Answer' => $this->oldValue,
7573
'Correct Answer' => $this->correctanswer,
76-
'User 1' => $this->user1,
77-
'User 2' => $this->user2,
7874
'Resolver' => $this->resolver,
7975
'ResolutionTimestamp' => $this->resolutiontimestamp,
8076
];

modules/conflict_resolver/php/provisioners/resolvedprovisioner.class.inc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class ResolvedProvisioner extends \LORIS\Data\Provisioners\DBObjectProvisioner
6969
ELSE conflicts_resolved.OldValue2
7070
END AS correctanswer,
7171
conflicts_resolved.ResolutionTimestamp as resolutiontimestamp,
72-
conflicts_resolved.User1 as user1,
73-
conflicts_resolved.User2 as user2,
7472
conflicts_resolved.UserID as resolver,
7573
psc.name as site,
7674
session.CenterID as centerid,

php/libraries/NDB_BVL_Battery.class.inc

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,23 @@ class NDB_BVL_Battery
249249
'SessionID' => $sessionData['SessionID'],
250250
'TestID' => $testId,
251251
'CommentID' => $commentID,
252-
'UserID' => $sessionData['UserID'],
253252
]
254253
);
255254

255+
$userID = $DB->pselectOne(
256+
"SELECT ID FROM users WHERE UserID=:uid",
257+
['uid' => $sessionData['UserID'] ?? ""]
258+
);
259+
if (($userID ?? "") != "") {
260+
$DB->insertOnDuplicateUpdate(
261+
"flag_editors",
262+
[
263+
'userID' => $userID,
264+
'CommentID' => $commentID,
265+
],
266+
);
267+
}
268+
256269
// insert the dde into the flag table
257270
if ($DDEEnabled) {
258271
$DB->insert(
@@ -261,9 +274,17 @@ class NDB_BVL_Battery
261274
'SessionID' => $sessionData['SessionID'],
262275
'TestID' => $testId,
263276
'CommentID' => $ddeCommentID,
264-
'UserID' => $sessionData['UserID'],
265277
]
266278
);
279+
if (($userID ?? "") != "") {
280+
$DB->insertOnDuplicateUpdate(
281+
"flag_editors",
282+
[
283+
'userID' => $userID,
284+
'CommentID' => $ddeCommentID,
285+
],
286+
);
287+
}
267288
}
268289

269290
return $commentID ?? '';

php/libraries/NDB_BVL_Instrument.class.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,19 @@ abstract class NDB_BVL_Instrument extends NDB_Page
829829
// don't overwrite data from other pages.
830830
$newData = array_merge($this->getInstanceData() ?? [], $values);
831831

832+
$userID = $db->pselectOne(
833+
"SELECT ID FROM users WHERE UserID=:uid",
834+
['uid' => $newData['UserID'] ?? ""]
835+
);
836+
if (($userID ?? "") != "") {
837+
$db->insertOnDuplicateUpdate(
838+
"flag_editors",
839+
[
840+
'userID' => $userID,
841+
'CommentID' => $this->getCommentID(),
842+
],
843+
);
844+
}
832845
// If there's already a row with the same data, re-use the DataID.
833846
// Otherwise, insert it, then update the DataID on flag.
834847
$jsonencoded = json_encode($newData);

0 commit comments

Comments
 (0)