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 )
69 foreach ( $resultSet as $row ) {
70 $result[$row->ttb_page_id] = (int)$row->ttb_status;
76 public function removeStatus(
int ...$pageIds ): void {
77 if ( !$this->doesTableExist() ) {
81 $this->database->delete(
83 [
'ttb_page_id' => $pageIds ],
88 private function getBundleTypeId(
string $bundle ): int {
89 if ( $bundle === TranslatablePage::class ) {
91 } elseif ( $bundle === MessageBundle::class ) {
95 throw new InvalidArgumentException(
"Unknown translatable bundle type: $bundle" );
99 private function doesTableExist(): bool {
100 if ( $this->tableExists === null ) {
101 $this->tableExists = $this->dbMaintenance->tableExists( self::TABLE_NAME, __METHOD__ );
104 return $this->tableExists;