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.
  • Loading branch information
MusikAnimal committed Jul 25, 2023
1 parent 1ffdab1 commit 32b332e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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
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 32b332e

Please sign in to comment.