Skip to content

Commit

Permalink
Record: type cast page_namespace into int; make submission_id a string
Browse files Browse the repository at this point in the history
The version and/or configuration of the MySQL client can apparently mean
we get a string instead of an integer, causing the page titles to be
displayed incorrectly.

For good measure, we type cast all getters that should return an int.

The submission_id meanwhile can either be an int or a string, depending
on whether it's from the new Turnitin API or the old one. We cast to
string since we don't need the integer type for this field.

Also update the 'record-url-text' message, which no longer shows the
number of words due to a limitation with the new Turnitin API.
  • Loading branch information
MusikAnimal committed Jul 25, 2023
1 parent d67148e commit 655df55
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"record-editcount": "Edit count:",
"compare": "Compare",
"record-ithenticate": "iThenticate report",
"record-url-text": "$1 of edit ($2 words)",
"record-url-text": "$1 of edit",
"record-noeditor": "No editor found",
"record-noeditor-tooltip": "The revision may have been deleted or the data is not yet available in Labs database.",
"record-ores": "ORES score: $1",
Expand Down
2 changes: 1 addition & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"record-editcount": "Label to indicate number of edits a user has made",
"compare": "Button label to open a panel for text comparison between two pages\n{{Identical|Compare}}",
"record-ithenticate": "Button label for a button to go to the original plagiarism report generated by Turnitin",
"record-url-text": "Label text to show amount of plagiarism. Parameters:\n* $1 - Percentage of edit that was plagiarized.\n* $2 - Number of words plagiarized.",
"record-url-text": "Label text to show amount of plagiarism. Parameters:\n* $1 - Percentage of edit that was plagiarized.",
"record-noeditor": "Column text shown to user when no editor was found in database for an edit",
"record-noeditor-tooltip": "Tooltip for a text label, shown to editor to explain why no editor could be found",
"record-ores": "Ores score for a record. \n Parameters: $1 - Decimal number indicating percentage score.",
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function undoReviewAction(
}

/**
* @Route("/ithenticate/{id}", name="ithenticate", requirements={"id"="\d+"})
* @Route("/ithenticate/{id}", name="ithenticate", requirements={"id"="\d+|[\d+\-]"})
* @param CopyPatrolRepository $copyPatrolRepo
* @param string $iThenticateUser
* @param string $iThenticatePassword
Expand Down
14 changes: 7 additions & 7 deletions src/Model/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function __construct(
/**
* Get the submission ID.
*
* @return int
* @return string UUID or stringified integer for older submissions.
*/
public function getSubmissionId(): int {
return $this->data['submission_id'];
public function getSubmissionId(): string {
return (string)$this->data['submission_id'];
}

/**
Expand All @@ -76,7 +76,7 @@ public function getSources(): array {
* @return string
*/
public function getPageTitle( bool $underscored = false ): string {
$nsName = $this->data['page_namespace'] === WikiRepository::NS_ID_DRAFTS ? 'Draft:' : '';
$nsName = (int)$this->data['page_namespace'] === WikiRepository::NS_ID_DRAFTS ? 'Draft:' : '';
$pageTitle = $nsName . $this->data['page_title'];
if ( !$underscored ) {
// Remove underscores for display purposes.
Expand Down Expand Up @@ -157,7 +157,7 @@ public function getOresScore(): ?float {
* @return int
*/
public function getRevId(): int {
return $this->data['rev_id'];
return (int)$this->data['rev_id'];
}

/**
Expand All @@ -166,7 +166,7 @@ public function getRevId(): int {
* @return int
*/
public function getRevParentId(): int {
return $this->data['rev_parent_id'];
return (int)$this->data['rev_parent_id'];
}

/** EDITOR / USER */
Expand Down Expand Up @@ -242,7 +242,7 @@ public function getUserContribsUrl(): string {
* @return int On the CopyPatrolRepository::STATUS_ constants.
*/
public function getStatus(): int {
return $this->data['status'];
return (int)$this->data['status'];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/CopyPatrolRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public function getPlagiarismRecords( array $options = [], int $limit = 50 ): ar
'status_user_text', 'source_id', 'url', 'percent',
] )
->from( 'diffs', 'd' )
->join( 'd', 'report_sources', 's', 'd.submission_id = s.submission_id' )
->orderBy( 'diff_id', 'DESC' );
->join( 'd', 'report_sources', 's', 'd.submission_id = s.submission_id' );

if ( $options['id'] ) {
// if given an exact submission ID, don't allow any other filter options
Expand Down Expand Up @@ -119,6 +118,7 @@ public function getPlagiarismRecords( array $options = [], int $limit = 50 ): ar

return $outerQuery->select( '*' )
->from( '(' . $qb->getSQL() . ') a' )
->orderBy( 'diff_id', 'DESC' )
->setMaxResults( $limit )
->executeQuery()
->fetchAllAssociative();
Expand Down
2 changes: 1 addition & 1 deletion tests/Model/RecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function setUp(): void {
}

public function testGetters(): void {
static::assertSame( 23323186, $this->record->getSubmissionId() );
static::assertSame( '23323186', $this->record->getSubmissionId() );
static::assertSame( [
[
'source_id' => 28671,
Expand Down

0 comments on commit 655df55

Please sign in to comment.