Awight has uploaded a new change for review. https://gerrit.wikimedia.org/r/300745
Change subject: Singleton PDO For the pending database ...................................................................... Singleton PDO For the pending database More convenient for testing. Note that we assume an app will only use one pending database per run. Change-Id: I3be06d1a2dad92661945baa9d5922eead7bfb603 --- M Core/DataStores/PendingDatabase.php 1 file changed, 12 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig refs/changes/45/300745/1 diff --git a/Core/DataStores/PendingDatabase.php b/Core/DataStores/PendingDatabase.php index 50e2454..1900541 100644 --- a/Core/DataStores/PendingDatabase.php +++ b/Core/DataStores/PendingDatabase.php @@ -13,19 +13,23 @@ /** * @var PDO + * We do the silly singleton thing for convenient testing with in-memory + * databases that would otherwise not be shared between components. */ - protected $db; + protected static $db; protected function __construct() { $config = Context::get()->getConfiguration(); - $this->db = $config->object( 'data-store/pending-db' ); + if ( !self::$db ) { + self::$db = $config->object( 'data-store/pending-db' ); + } } /** * @return PDO */ public function getDatabase() { - return $this->db; + return self::$db; } public static function get() { @@ -80,7 +84,7 @@ $paramList = ':' . implode( ', :', array_keys( $dbRecord ) ); $insert = "INSERT INTO pending ( $fieldList ) values ( $paramList );"; - $prepared = $this->db->prepare( $insert ); + $prepared = self::$db->prepare( $insert ); foreach ( $dbRecord as $field => $value ) { $prepared->bindValue( @@ -100,7 +104,7 @@ * @return array|null Record related to a transaction, or null if nothing matches */ public function fetchMessageByGatewayOrderId( $gatewayName, $orderId ) { - $prepared = $this->db->prepare( ' + $prepared = self::$db->prepare( ' select * from pending where gateway = :gateway and order_id = :order_id @@ -122,7 +126,7 @@ * @return array|null Message or null if nothing is found. */ public function fetchMessageByGatewayOldest( $gatewayName ) { - $prepared = $this->db->prepare( ' + $prepared = self::$db->prepare( ' select * from pending where gateway = :gateway order by date asc @@ -150,7 +154,7 @@ * @return array|null Message or null if nothing is found. */ public function fetchMessageByGatewayFirstSinceId( $gatewayName, $offsetId = 0 ) { - $prepared = $this->db->prepare( ' + $prepared = self::$db->prepare( ' select * from pending where gateway = :gateway and id > :offset_id @@ -174,7 +178,7 @@ * @param array $message */ public function deleteMessage( $message ) { - $prepared = $this->db->prepare( ' + $prepared = self::$db->prepare( ' delete from pending where gateway = :gateway and order_id = :order_id' ); -- To view, visit https://gerrit.wikimedia.org/r/300745 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3be06d1a2dad92661945baa9d5922eead7bfb603 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/SmashPig Gerrit-Branch: master Gerrit-Owner: Awight <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits