21 private const TABLE_NAME =
'translate_translatable_bundles';
23 private ?
bool $tableExists =
null;
25 public function __construct(
26 private readonly IDatabase $database,
27 private readonly Collation $collation,
28 private readonly IMaintainableDatabase $dbMaintenance,
33 if ( !$this->doesTableExist() ) {
37 $sortKey = substr( $this->collation->getSortKey( $title->getPrefixedDBkey() ), 0, 255 );
38 $bundleTypeId = $this->getBundleTypeId( $bundleType );
39 $this->database->newReplaceQueryBuilder()
40 ->replaceInto( self::TABLE_NAME )
41 ->uniqueIndexFields( [
'ttb_page_id' ] )
43 'ttb_page_id' => $title->getId(),
44 'ttb_type' => $bundleTypeId,
45 'ttb_status' => $status->getId(),
46 'ttb_sortkey' => $sortKey
48 ->caller( __METHOD__ )
54 if ( !$this->doesTableExist() ) {
58 $resultSet = $this->database->newSelectQueryBuilder()
59 ->select( [
'ttb_page_id',
'ttb_status' ] )
60 ->from( self::TABLE_NAME )
61 ->caller( __METHOD__ )
65 foreach ( $resultSet as $row ) {
66 $result[$row->ttb_page_id] = (int)$row->ttb_status;
72 public function removeStatus(
int ...$pageIds ): void {
73 if ( !$this->doesTableExist() ) {
77 $this->database->newDeleteQueryBuilder()
78 ->deleteFrom( self::TABLE_NAME )
79 ->where( [
'ttb_page_id' => $pageIds ] )
80 ->caller( __METHOD__ )
84 private function getBundleTypeId(
string $bundle ): int {
85 if ( $bundle === TranslatablePage::class ) {
87 } elseif ( $bundle === MessageBundle::class ) {
91 throw new InvalidArgumentException(
"Unknown translatable bundle type: $bundle" );
95 private function doesTableExist(): bool {
96 if ( $this->tableExists === null ) {
97 $this->tableExists = $this->dbMaintenance->tableExists( self::TABLE_NAME, __METHOD__ );
100 return $this->tableExists;