Skip to content

Commit 2d62263

Browse files
authored
Fix tableName() usage in SearchPanes
* Solves SemanticMediaWiki#910 with reference to SemanticMediaWiki#942 * In select queries, we use $qobj->fromTables() and $qobj->joinConditions added in SemanticMediaWiki/SemanticMediaWiki#5715
1 parent d8dd5d4 commit 2d62263

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

formats/datatables/SearchPanes.php

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private function getPanesOptions(
125125
$querySegmentListProcessor->process( $rootid );
126126

127127
$qobj = $querySegmentList[$rootid];
128+
$qJoinAndFromTables = array_merge( [ $qobj->alias => $qobj->joinTable ], $qobj->fromTables );
128129

129130
$property = new DIProperty( DIProperty::newFromUserLabel( $printRequest->getCanonicalLabel() ) );
130131
$propTypeid = $property->findPropertyValueType();
@@ -134,15 +135,15 @@ private function getPanesOptions(
134135
// data-length without the GROUP BY clause
135136
$sql_options = [ 'LIMIT' => 1 ];
136137

137-
$dataLength = (int)$this->connection->selectField(
138-
$this->connection->tableName( $qobj->joinTable ) . " AS $qobj->alias" . $qobj->from
139-
. ' JOIN ' . $this->connection->tableName( 'smw_fpt_inst' ) . " AS insts ON $qobj->alias.smw_id = insts.s_id",
138+
$res = $this->connection->select(
139+
array_merge( $qJoinAndFromTables, [ 'insts' => 'smw_fpt_inst' ] ),
140140
"COUNT(*) AS count",
141141
$qobj->where,
142142
__METHOD__,
143-
$sql_options
143+
$sql_options,
144+
array_merge( $qobj->joinConditions, [ 'insts' => [ 'JOIN', "$qobj->alias.smw_id = insts.s_id" ] ] )
144145
);
145-
146+
$dataLength = $res ? (int)( $res->fetchRow()['count'] ?? 0 ) : 0;
146147
if ( !$dataLength ) {
147148
return [];
148149
}
@@ -168,14 +169,16 @@ private function getPanesOptions(
168169
*/
169170

170171
$res = $this->connection->select(
171-
$this->connection->tableName( $qobj->joinTable ) . " AS $qobj->alias" . $qobj->from
172-
// @see https://github.com/SemanticMediaWiki/SemanticDrilldown/blob/master/includes/Sql/SqlProvider.php
173-
. ' JOIN ' . $this->connection->tableName( 'smw_fpt_inst' ) . " AS insts ON $qobj->alias.smw_id = insts.s_id"
174-
. ' JOIN ' . $this->connection->tableName( SQLStore::ID_TABLE ) . " AS i ON i.smw_id = insts.o_id",
172+
array_merge( $qJoinAndFromTables, [
173+
'insts' => 'smw_fpt_inst',
174+
'i' => SQLStore::ID_TABLE ] ),
175175
"COUNT($groupBy) AS count, i.smw_id, i.smw_title, i.smw_namespace, i.smw_iw, i.smw_sort, i.smw_subobject",
176176
$qobj->where,
177177
__METHOD__,
178-
$sql_options
178+
$sql_options,
179+
array_merge( $qobj->joinConditions, [
180+
'insts' => [ "JOIN", "$qobj->alias.smw_id = insts.s_id" ],
181+
'i' => [ 'JOIN', 'i.smw_id = insts.o_id' ] ] )
179182
);
180183

181184
$isIdField = true;
@@ -209,14 +212,15 @@ private function getPanesOptions(
209212
// INNER JOIN (`smw_fpt_mdat` AS t2 INNER JOIN `smw_di_wikipage` AS t3 ON t2.s_id=t3.s_id) ON t0.smw_id=t2.s_id
210213
// WHERE ((t3.p_id=517)) LIMIT 500
211214

212-
$dataLength = (int)$this->connection->selectField(
213-
$this->connection->tableName( $qobj->joinTable ) . " AS $qobj->alias" . $qobj->from,
214-
"COUNT(*) as count",
215+
$res = $this->connection->select(
216+
$qJoinAndFromTables,
217+
'COUNT(*) AS count',
215218
$qobj->where,
216219
__METHOD__,
217-
$sql_options
220+
$sql_options,
221+
$qobj->joinConditions
218222
);
219-
223+
$dataLength = $res ? (int)( $res->fetchRow()['count'] ?? 0 ) : 0;
220224
if ( !$dataLength ) {
221225
return [];
222226
}
@@ -244,15 +248,18 @@ private function getPanesOptions(
244248

245249
// @see QueryEngine
246250
$res = $this->connection->select(
247-
$this->connection->tableName( $qobj->joinTable ) . " AS $qobj->alias" . $qobj->from
248-
. ( !$isIdField ? ''
249-
: " JOIN " . $this->connection->tableName( SQLStore::ID_TABLE ) . " AS `i` ON ($p_alias.o_id = i.smw_id)" ),
251+
!$isIdField
252+
? $qJoinAndFromTables
253+
: array_merge( $qJoinAndFromTables, [ 'i' => SQLStore::ID_TABLE ] ),
250254
implode( ',', $fields ),
251255
$qobj->where . ( !$isIdField ? '' : ( !empty( $qobj->where ) ? ' AND' : '' )
252256
. ' i.smw_iw!=' . $this->connection->addQuotes( SMW_SQL3_SMWIW_OUTDATED )
253257
. ' AND i.smw_iw!=' . $this->connection->addQuotes( SMW_SQL3_SMWDELETEIW ) ),
254258
__METHOD__,
255-
$sql_options
259+
$sql_options,
260+
!$isIdField
261+
? $qobj->joinConditions
262+
: array_merge( $qobj->joinConditions, [ 'i' => [ "JOIN", "$p_alias.o_id = i.smw_id" ] ] )
256263
);
257264

258265
}
@@ -643,7 +650,7 @@ private function searchPanesMainlabel( PrintRequest $printRequest, array $search
643650

644651
// @see QueryEngine
645652
$res = $this->connection->select(
646-
$this->connection->tableName( $qobj->joinTable ) . " AS $qobj->alias" . $qobj->from,
653+
array_merge( [ $qobj->alias => $qobj->joinTable ], $qobj->fromTables ),
647654
"$qobj->alias.smw_id AS id," .
648655
"$qobj->alias.smw_title AS t," .
649656
"$qobj->alias.smw_namespace AS ns," .
@@ -653,7 +660,8 @@ private function searchPanesMainlabel( PrintRequest $printRequest, array $search
653660
"$sortfields",
654661
$qobj->where,
655662
__METHOD__,
656-
$sql_options
663+
$sql_options,
664+
$qobj->joinConditions
657665
);
658666

659667
$diHandler = $this->datatables->store->getDataItemHandlerForDIType(

0 commit comments

Comments
 (0)