21 private const TABLE_NAME =
'translate_translatable_bundles';
27 private $dbMaintainance;
29 private $tableExists =
null;
31 public function __construct(
34 IMaintainableDatabase $dbMaintainance
36 $this->database = $database;
37 $this->collation = $collation;
38 $this->dbMaintainance = $dbMaintainance;
42 if ( !$this->doesTableExist() ) {
46 $sortKey = substr( $this->collation->getSortKey( $title->getPrefixedDBkey() ), 0, 255 );
47 $bundleTypeId = $this->getBundleTypeId( $bundleType );
48 $this->database->replace(
52 'ttb_page_id' => $title->getArticleID(),
53 'ttb_type' => $bundleTypeId,
54 'ttb_status' => $status->getId(),
55 'ttb_sortkey' => $sortKey
63 if ( !$this->doesTableExist() ) {
67 $resultSet = $this->database->newSelectQueryBuilder()
68 ->select( [
'ttb_page_id' ,
'ttb_status' ] )
69 ->from( self::TABLE_NAME )
73 foreach ( $resultSet as $row ) {
74 $result[$row->ttb_page_id] = (int)$row->ttb_status;
80 public function removeStatus(
int ...$pageIds ): void {
81 if ( !$this->doesTableExist() ) {
85 $this->database->delete(
87 [
'ttb_page_id' => $pageIds ],
92 private function getBundleTypeId(
string $bundle ): int {
93 if ( $bundle === TranslatablePage::class ) {
95 } elseif ( $bundle === MessageBundle::class ) {
99 throw new InvalidArgumentException(
"Unknown translatable bundle type: $bundle" );
103 private function doesTableExist(): bool {
104 if ( $this->tableExists === null ) {
105 $this->tableExists = $this->dbMaintainance->tableExists( self::TABLE_NAME, __METHOD__ );
108 return $this->tableExists;