diff options
Diffstat (limited to 'www/wiki/extensions/Translate/stash/TranslationStashStorage.php')
-rw-r--r-- | www/wiki/extensions/Translate/stash/TranslationStashStorage.php | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/www/wiki/extensions/Translate/stash/TranslationStashStorage.php b/www/wiki/extensions/Translate/stash/TranslationStashStorage.php index 08a3ef2b..fb67449f 100644 --- a/www/wiki/extensions/Translate/stash/TranslationStashStorage.php +++ b/www/wiki/extensions/Translate/stash/TranslationStashStorage.php @@ -4,18 +4,27 @@ * * @file * @author Niklas Laxström - * @license GPL-2.0+ + * @license GPL-2.0-or-later */ +use Wikimedia\Rdbms\IDatabase; + /** * Storage class for stashed translations. This one uses sql tables as storage. * @since 2013.06 */ class TranslationStashStorage { + /** @var IDatabase */ protected $db; + + /** @var string */ protected $dbTable; - public function __construct( DatabaseBase $db, $table = 'translate_stash' ) { + /** + * @param IDatabase $db + * @param string $table + */ + public function __construct( IDatabase $db, $table = 'translate_stash' ) { $this->db = $db; $this->dbTable = $table; } @@ -27,17 +36,17 @@ class TranslationStashStorage { * @param StashedTranslation $item */ public function addTranslation( StashedTranslation $item ) { - $row = array( + $row = [ 'ts_user' => $item->getUser()->getId(), 'ts_title' => $item->getTitle()->getDBkey(), 'ts_namespace' => $item->getTitle()->getNamespace(), 'ts_value' => $item->getValue(), 'ts_metadata' => serialize( $item->getMetadata() ), - ); + ]; - $indexes = array( - array( 'ts_user', 'ts_namespace', 'ts_title' ) - ); + $indexes = [ + [ 'ts_user', 'ts_namespace', 'ts_title' ] + ]; $this->db->replace( $this->dbTable, $indexes, $row, __METHOD__ ); } @@ -48,12 +57,12 @@ class TranslationStashStorage { * @return StashedTranslation[] */ public function getTranslations( User $user ) { - $conds = array( 'ts_user' => $user->getId() ); - $fields = array( 'ts_namespace', 'ts_title', 'ts_value', 'ts_metadata' ); + $conds = [ 'ts_user' => $user->getId() ]; + $fields = [ 'ts_namespace', 'ts_title', 'ts_value', 'ts_metadata' ]; $res = $this->db->select( $this->dbTable, $fields, $conds, __METHOD__ ); - $objects = array(); + $objects = []; foreach ( $res as $row ) { $objects[] = new StashedTranslation( $user, @@ -72,7 +81,7 @@ class TranslationStashStorage { * @since 2013.10 */ public function deleteTranslations( User $user ) { - $conds = array( 'ts_user' => $user->getId() ); + $conds = [ 'ts_user' => $user->getId() ]; $this->db->delete( $this->dbTable, $conds, __METHOD__ ); } } |