jenkins-bot has submitted this change and it was merged.
Change subject: This fixes all instances of using array indexes instead of
field names for accessing database rows.
......................................................................
This fixes all instances of using array indexes instead of field
names for accessing database rows.
Change-Id: I6550d33c4cd440464e99108dbdf57e179df0ecc6
---
M CargoPageData.php
M CargoUtils.php
M drilldown/CargoAppliedFilter.php
M drilldown/CargoFilter.php
M drilldown/CargoSpecialDrilldown.php
M parserfunctions/CargoAttach.php
M specials/CargoRecreateData.php
M specials/CargoTables.php
8 files changed, 50 insertions(+), 41 deletions(-)
Approvals:
Yaron Koren: Looks good to me, approved
jenkins-bot: Verified
diff --git a/CargoPageData.php b/CargoPageData.php
index 87a1c88..22002a8 100644
--- a/CargoPageData.php
+++ b/CargoPageData.php
@@ -123,12 +123,12 @@
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
'revision',
- 'COUNT(*)',
+ 'COUNT(*) as total',
array( 'rev_page' => $title->getArticleID() ),
__METHOD__
);
$row = $dbr->fetchRow( $res );
- $pageDataValues['_numRevisions'] = $row[0];
+ $pageDataValues['_numRevisions'] =
intval($row['total']);
}
CargoStore::storeAllData( $title, '_pageData', $pageDataValues,
$tableSchemas['_pageData'] );
diff --git a/CargoUtils.php b/CargoUtils.php
index c8433b1..bd4606e 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -132,7 +132,7 @@
$dbw = wfGetDB( DB_MASTER );
$res = $dbw->select( 'cargo_tables', 'main_table' );
while ( $row = $dbw->fetchRow( $res ) ) {
- $tableNames[] = $row[0];
+ $tableNames[] = $row['main_table'];
}
return $tableNames;
}
diff --git a/drilldown/CargoAppliedFilter.php b/drilldown/CargoAppliedFilter.php
index 906f6e7..a52e926 100644
--- a/drilldown/CargoAppliedFilter.php
+++ b/drilldown/CargoAppliedFilter.php
@@ -176,7 +176,7 @@
$cdb = CargoUtils::getDB();
$res = $cdb->select( $tableName, "DISTINCT " . $value_field );
while ( $row = $cdb->fetchRow( $res ) ) {
- $possible_values[] = $row[0];
+ $possible_values[] = $row[$value_field];
}
$cdb->freeResult( $res );
return $possible_values;
diff --git a/drilldown/CargoFilter.php b/drilldown/CargoFilter.php
index 9d00922..dfebdb2 100644
--- a/drilldown/CargoFilter.php
+++ b/drilldown/CargoFilter.php
@@ -47,10 +47,10 @@
$cdb = CargoUtils::getDB();
$date_field = $this->name;
list( $tableNames, $conds, $joinConds ) = $this->getQueryParts(
$fullTextSearchTerm, $appliedFilters );
- $res = $cdb->select( $tableNames, array( "MIN($date_field)",
"MAX($date_field)" ), $conds, null,
+ $res = $cdb->select( $tableNames, array( "MIN($date_field) AS
min_date", "MAX($date_field) AS max_date" ), $conds, null,
null, $joinConds );
$row = $cdb->fetchRow( $res );
- $minDate = $row[0];
+ $minDate = $row['min_date'];
if ( is_null( $minDate ) ) {
return null;
}
@@ -61,7 +61,7 @@
$minYear = $minDateParts[0];
$minMonth = $minDay = 0;
}
- $maxDate = $row[1];
+ $maxDate = $row['max_date'];
$maxDateParts = explode( '-', $maxDate );
if ( count( $maxDateParts ) == 3 ) {
list( $maxYear, $maxMonth, $maxDay ) = $maxDateParts;
@@ -127,50 +127,59 @@
$timePeriod = $this->getTimePeriod( $fullTextSearchTerm,
$appliedFilters );
if ( $timePeriod == 'day' ) {
- $fields = "YEAR($date_field), MONTH($date_field),
DAYOFMONTH($date_field)";
+ $fields = "YEAR($date_field) AS year_field,
MONTH($date_field) AS month_field, DAYOFMONTH($date_field) AS
day_of_month_field";
} elseif ( $timePeriod == 'month' ) {
- $fields = "YEAR($date_field), MONTH($date_field)";
+ $fields = "YEAR($date_field) AS year_field,
MONTH($date_field) AS month_field";
} elseif ( $timePeriod == 'year' ) {
- $fields = "YEAR($date_field)";
+ $fields = "YEAR($date_field) AS year_field";
} else { // if ( $timePeriod == 'decade' ) {
- $fields = "YEAR($date_field)";
+ $fields = "YEAR($date_field) AS year_field";
}
list( $tableNames, $conds, $joinConds ) = $this->getQueryParts(
$fullTextSearchTerm, $appliedFilters );
- $selectOptions = array( 'GROUP BY' => $fields, 'ORDER BY' =>
$fields );
+ $selectOptions = [ 'GROUP BY' => $fields, 'ORDER BY' => $fields
];
if ( $this->searchableFiles ) {
- $countClause = "COUNT(DISTINCT
cargo__{$this->tableName}._pageID)";
+ $fields[] = "COUNT(DISTINCT
cargo__{$this->tableName}._pageID) AS total";
} else {
- $countClause = "COUNT(*)";
+ $fields[] = "COUNT(*) AS total";
}
+
$cdb = CargoUtils::getDB();
- $res = $cdb->select( $tableNames, array( $fields, $countClause
), $conds, null, $selectOptions,
- $joinConds );
+
+ $res = $cdb->select(
+ $tableNames,
+ $fields,
+ $conds,
+ __METHOD__,
+ $selectOptions,
+ $joinConds
+ );
+
while ( $row = $cdb->fetchRow( $res ) ) {
- if ( $row[0] == null ) {
- $possible_dates['_none'] = $row[$countClause];
+ if ( empty( current( $row ) ) ) {
+ $possible_dates['_none'] = $row['total'];
} elseif ( $timePeriod == 'day' ) {
- $date_string =
CargoDrilldownUtils::monthToString( $row[1] ) . ' ' . $row[2] . ', ' . $row[0];
- $possible_dates[$date_string] = $row[3];
+ $date_string =
CargoDrilldownUtils::monthToString( $row['month_field'] ) . ' ' .
$row['day_of_month_field'] . ', ' . $row['year_field'];
+ $possible_dates[$date_string] = $row['total'];
} elseif ( $timePeriod == 'month' ) {
- $date_string =
CargoDrilldownUtils::monthToString( $row[1] ) . ' ' . $row[0];
- $possible_dates[$date_string] = $row[2];
+ $date_string =
CargoDrilldownUtils::monthToString( $row['month_field'] ) . ' ' .
$row['year_field'];
+ $possible_dates[$date_string] = $row['total'];
} elseif ( $timePeriod == 'year' ) {
- $date_string = $row[0];
- $possible_dates[$date_string] = $row[1];
+ $date_string = $row['year_field'];
+ $possible_dates[$date_string] = $row['total'];
} else { // if ( $timePeriod == 'decade' )
// Unfortunately, there's no SQL DECADE()
// function - so we have to take these values,
// which are grouped into year "buckets", and
// re-group them into decade buckets.
- $year_string = $row[0];
+ $year_string = $row['year_field'];
$start_of_decade = $year_string - (
$year_string % 10 );
$end_of_decade = $start_of_decade + 9;
$decade_string = $start_of_decade . ' - ' .
$end_of_decade;
if ( !array_key_exists( $decade_string,
$possible_dates ) ) {
- $possible_dates[$decade_string] =
$row[1];
+ $possible_dates[$decade_string] =
$row['total'];
} else {
- $possible_dates[$decade_string] +=
$row[1];
+ $possible_dates[$decade_string] +=
$row['total'];
}
}
}
@@ -199,20 +208,20 @@
}
if ( $this->searchableFiles ) {
- $countClause = "COUNT(DISTINCT
cargo__{$this->tableName}._pageID)";
+ $countClause = "COUNT(DISTINCT
cargo__{$this->tableName}._pageID) AS total";
} else {
- $countClause = "COUNT(*)";
+ $countClause = "COUNT(*) AS total";
}
$res = $cdb->select( $tableNames, array( $fieldName,
$countClause ), $conds, null,
array( 'GROUP BY' => $fieldName ), $joinConds );
$possible_values = array();
while ( $row = $cdb->fetchRow( $res ) ) {
- $value_string = $row[0];
+ $value_string = $row['_value'];
if ( $value_string == '' ) {
$value_string = ' none';
}
- $possible_values[$value_string] = $row[1];
+ $possible_values[$value_string] = $row['total'];
}
$cdb->freeResult( $res );
diff --git a/drilldown/CargoSpecialDrilldown.php
b/drilldown/CargoSpecialDrilldown.php
index d57a1ef..869ec80 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -285,9 +285,9 @@
}
$cdb = CargoUtils::getDB();
foreach ( $tables as $table ) {
- $res = $cdb->select( $table, 'COUNT(*)' );
+ $res = $cdb->select( $table, 'COUNT(*) AS total' );
$row = $cdb->fetchRow( $res );
- $tableRows = $row[0];
+ $tableRows = $row['total'];
$realTableName = str_replace( '_', ' ', $table );
$tableStr = "$realTableName ($tableRows)";
if ( $this->tableName == $table ) {
diff --git a/parserfunctions/CargoAttach.php b/parserfunctions/CargoAttach.php
index 31eb9e5..ebf862e 100644
--- a/parserfunctions/CargoAttach.php
+++ b/parserfunctions/CargoAttach.php
@@ -42,9 +42,9 @@
}
$dbw = wfGetDB( DB_MASTER );
- $res = $dbw->select( 'cargo_tables', 'COUNT(*)', array(
'main_table' => $tableName ) );
+ $res = $dbw->select( 'cargo_tables', 'COUNT(*) AS total',
array( 'main_table' => $tableName ) );
$row = $dbw->fetchRow( $res );
- if ( $row[0] == 0 ) {
+ if ( !empty( $row ) && $row['total'] == 0 ) {
return CargoUtils::formatError( "Error: The specified
table, \"$tableName\", does not exist." );
}
diff --git a/specials/CargoRecreateData.php b/specials/CargoRecreateData.php
index eaf8327..840f075 100644
--- a/specials/CargoRecreateData.php
+++ b/specials/CargoRecreateData.php
@@ -112,7 +112,7 @@
function getNumPagesThatCallTemplate( $dbw, $templateTitle ) {
$res = $dbw->select(
array( 'page', 'templatelinks' ),
- 'COUNT(*)',
+ 'COUNT(*) AS total',
array(
"tl_from=page_id",
"tl_namespace" =>
$templateTitle->getNamespace(),
@@ -121,7 +121,7 @@
array()
);
$row = $dbw->fetchRow( $res );
- return $row[0];
+ return intval($row['total']);
}
}
diff --git a/specials/CargoTables.php b/specials/CargoTables.php
index 39055b1..08b2929 100644
--- a/specials/CargoTables.php
+++ b/specials/CargoTables.php
@@ -39,14 +39,14 @@
// First, display a count.
try {
- $res = $cdb->select( $tableName, 'COUNT(*)' );
+ $res = $cdb->select( $tableName, 'COUNT(*) AS total' );
} catch ( Exception $e ) {
$out->addHTML( Html::element( 'div', array( 'class' =>
'error' ),
$this->msg(
'cargo-cargotables-tablenotfound', $tableName )->parse() ) . "\n" );
return;
}
$row = $cdb->fetchRow( $res );
- $out->addWikiText( $this->msg( 'cargo-cargotables-totalrows'
)->numParams( $row[0] )->text() . "\n" );
+ $out->addWikiText( $this->msg( 'cargo-cargotables-totalrows'
)->numParams( intval($row['total']) )->text() . "\n" );
$sqlQuery = new CargoSQLQuery();
$sqlQuery->mTablesStr = $tableName;
@@ -160,9 +160,9 @@
$this->msg( 'delete' )->text()
);
}
- $res = $cdb->select( $tableName, 'COUNT(*)' );
+ $res = $cdb->select( $tableName, 'COUNT(*) AS total' );
$row = $cdb->fetchRow( $res );
- $numRowsText = $this->msg(
'cargo-cargotables-totalrowsshort' )->numParams( $row[0] )->parse();
+ $numRowsText = $this->msg(
'cargo-cargotables-totalrowsshort' )->numParams( intval($row['total'])
)->parse();
// "Declared by" text
if ( !array_key_exists( $tableName,
$templatesThatDeclareTables ) ) {
--
To view, visit https://gerrit.wikimedia.org/r/316831
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6550d33c4cd440464e99108dbdf57e179df0ecc6
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Alexia <[email protected]>
Gerrit-Reviewer: Alexia <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits