21 private const TABLE_NAME =
'translate_translatable_bundles';
22 private IDatabase $database;
23 private Collation $collation;
24 private IMaintainableDatabase $dbMaintenance;
25 private ?
bool $tableExists =
null;
27 public function __construct(
30 IMaintainableDatabase $dbMaintenance
32 $this->database = $database;
33 $this->collation = $collation;
34 $this->dbMaintenance = $dbMaintenance;
38 if ( !$this->doesTableExist() ) {
42 $sortKey = substr( $this->collation->getSortKey( $title->getPrefixedDBkey() ), 0, 255 );
43 $bundleTypeId = $this->getBundleTypeId( $bundleType );
44 $this->database->replace(
48 'ttb_page_id' => $title->getArticleID(),
49 'ttb_type' => $bundleTypeId,
50 'ttb_status' => $status->getId(),
51 'ttb_sortkey' => $sortKey
59 if ( !$this->doesTableExist() ) {
63 $resultSet = $this->database->newSelectQueryBuilder()
64 ->select( [
'ttb_page_id',
'ttb_status' ] )
65 ->from( self::TABLE_NAME )
66 ->caller( __METHOD__ )
70 foreach ( $resultSet as $row ) {
71 $result[$row->ttb_page_id] = (int)$row->ttb_status;
77 public function removeStatus(
int ...$pageIds ): void {
78 if ( !$this->doesTableExist() ) {
82 $this->database->delete(
84 [
'ttb_page_id' => $pageIds ],
89 private function getBundleTypeId(
string $bundle ): int {
90 if ( $bundle === TranslatablePage::class ) {
92 } elseif ( $bundle === MessageBundle::class ) {
96 throw new InvalidArgumentException(
"Unknown translatable bundle type: $bundle" );
100 private function doesTableExist(): bool {
101 if ( $this->tableExists === null ) {
102 $this->tableExists = $this->dbMaintenance->tableExists( self::TABLE_NAME, __METHOD__ );
105 return $this->tableExists;