Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/312862
Change subject: Always throw exception on execute failure ...................................................................... Always throw exception on execute failure Change-Id: I7d9763bc499f3c3fc447f76c32aadf9bc6040e8a --- M Core/DataStores/DamagedDatabase.php M Core/DataStores/SmashPigDatabase.php 2 files changed, 7 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig refs/changes/62/312862/1 diff --git a/Core/DataStores/DamagedDatabase.php b/Core/DataStores/DamagedDatabase.php index c5498ba..6b806c0 100644 --- a/Core/DataStores/DamagedDatabase.php +++ b/Core/DataStores/DamagedDatabase.php @@ -2,7 +2,6 @@ namespace SmashPig\Core\DataStores; use PDO; -use SmashPig\Core\SmashPigException; use SmashPig\Core\UtcDate; /** @@ -20,7 +19,6 @@ * @param int|null $retryDate When provided, re-process message after * this timestamp * @return int ID of message in damaged database - * @throws SmashPigException if insert fails */ public function storeMessage( $message, @@ -66,10 +64,7 @@ $insert = "INSERT INTO damaged ( $fieldList ) VALUES ( $paramList );"; - if ( $this->prepareAndExecute( $insert, $dbRecord ) ) { - return $this->getDatabase()->lastInsertId(); - } - throw new SmashPigException( 'Unable to insert into damaged db' ); + $this->prepareAndExecute( $insert, $dbRecord ); } /** diff --git a/Core/DataStores/SmashPigDatabase.php b/Core/DataStores/SmashPigDatabase.php index cb92dc1..4c9b3bc 100644 --- a/Core/DataStores/SmashPigDatabase.php +++ b/Core/DataStores/SmashPigDatabase.php @@ -3,6 +3,7 @@ use PDO; use PHPQueue\Exception\Exception; use SmashPig\Core\Context; +use SmashPig\Core\SmashPigException; abstract class SmashPigDatabase { @@ -70,7 +71,7 @@ * * @param string $sql parameterized SQL command * @param array $dbRecord associative array of values to bind - * @return bool true if execution succeeded + * @throws SmashPigException */ protected function prepareAndExecute( $sql, $dbRecord ) { $prepared = $this->getDatabase()->prepare( $sql ); @@ -82,6 +83,9 @@ PDO::PARAM_STR ); } - return $prepared->execute(); + if ( !$prepared->execute() ) { + $info = print_r( $this->getDatabase()->errorInfo() ); + throw new SmashPigException( "Failed to execute $sql: $info" ); + } } } -- To view, visit https://gerrit.wikimedia.org/r/312862 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7d9763bc499f3c3fc447f76c32aadf9bc6040e8a Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/SmashPig Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits