@@ -76,6 +76,19 @@ class QueryBuilder implements IQueryBuilder {
7676 /** @var string */
7777 protected $ lastInsertedTable ;
7878
79+ /**
80+ * Tables that require special attention and thus can't be queried by default
81+ *
82+ * @var list<string>
83+ */
84+ protected array $ shardedTables = [
85+ 'filecache ' ,
86+ 'filecache_extended ' ,
87+ 'files_metadata '
88+ ];
89+
90+ protected bool $ sharded = false ;
91+
7992 /**
8093 * Initializes a new QueryBuilder.
8194 *
@@ -677,6 +690,17 @@ public function insert($insert = null) {
677690 return $ this ;
678691 }
679692
693+ /**
694+ * @param string $table
695+ * @return void
696+ * @throws \Exception
697+ */
698+ private function checkTableAccess (string $ table ) {
699+ if (in_array ($ table , $ this ->shardedTables ) !== $ this ->sharded ) {
700+ throw new \Exception ("current query isn't allowed to access the $ table table " );
701+ }
702+ }
703+
680704 /**
681705 * Creates and adds a query root corresponding to the table identified by the
682706 * given alias, forming a cartesian product with any existing query roots.
@@ -693,6 +717,7 @@ public function insert($insert = null) {
693717 * @return $this This QueryBuilder instance.
694718 */
695719 public function from ($ from , $ alias = null ) {
720+ $ this ->checkTableAccess ($ from );
696721 $ this ->queryBuilder ->from (
697722 $ this ->getTableName ($ from ),
698723 $ this ->quoteAlias ($ alias )
@@ -719,6 +744,8 @@ public function from($from, $alias = null) {
719744 * @return $this This QueryBuilder instance.
720745 */
721746 public function join ($ fromAlias , $ join , $ alias , $ condition = null ) {
747+ $ this ->checkTableAccess ($ join );
748+
722749 $ this ->queryBuilder ->join (
723750 $ this ->quoteAlias ($ fromAlias ),
724751 $ this ->getTableName ($ join ),
@@ -747,6 +774,8 @@ public function join($fromAlias, $join, $alias, $condition = null) {
747774 * @return $this This QueryBuilder instance.
748775 */
749776 public function innerJoin ($ fromAlias , $ join , $ alias , $ condition = null ) {
777+ $ this ->checkTableAccess ($ join );
778+
750779 $ this ->queryBuilder ->innerJoin (
751780 $ this ->quoteAlias ($ fromAlias ),
752781 $ this ->getTableName ($ join ),
@@ -775,6 +804,8 @@ public function innerJoin($fromAlias, $join, $alias, $condition = null) {
775804 * @return $this This QueryBuilder instance.
776805 */
777806 public function leftJoin ($ fromAlias , $ join , $ alias , $ condition = null ) {
807+ $ this ->checkTableAccess ($ join );
808+
778809 $ this ->queryBuilder ->leftJoin (
779810 $ this ->quoteAlias ($ fromAlias ),
780811 $ this ->getTableName ($ join ),
@@ -803,6 +834,8 @@ public function leftJoin($fromAlias, $join, $alias, $condition = null) {
803834 * @return $this This QueryBuilder instance.
804835 */
805836 public function rightJoin ($ fromAlias , $ join , $ alias , $ condition = null ) {
837+ $ this ->checkTableAccess ($ join );
838+
806839 $ this ->queryBuilder ->rightJoin (
807840 $ this ->quoteAlias ($ fromAlias ),
808841 $ this ->getTableName ($ join ),
@@ -1360,4 +1393,16 @@ public function quoteAlias($alias) {
13601393 public function escapeLikeParameter (string $ parameter ): string {
13611394 return $ this ->connection ->escapeLikeParameter ($ parameter );
13621395 }
1396+
1397+ /**
1398+ * Mark the query as accessing the sharded tables
1399+ *
1400+ * Proper attention needs to be given to ensure that all requirements for accessing the sharded tables
1401+ *
1402+ * @param bool $sharded
1403+ * @return void
1404+ */
1405+ public function setSharded (bool $ sharded ): void {
1406+ $ this ->sharded = $ sharded ;
1407+ }
13631408}
0 commit comments