when boolean settings are disabled with 'Off' via php_admin_value/php_value
* (bug 11292) Fixed unserialize errors with Postgres by creating special Blob object.
* (bug 11363) Make all metadata fields bytea when using Postgres.
+* (bug 11331) Add buildConcat() and use CASE not IF for DB compatibility. Make oldimage
+ cascade delete via image table for Postgres, change fa_storage_key TEXT.
=== API changes in 1.12 ===
return $this->tableName( $matches[1] );
}
+ /*
+ * Build a concatenation list to feed into a SQL query
+ */
+ function buildConcat( $stringList ) {
+ return 'CONCAT(' . implode( ',', $stringList ) . ')';
+ }
+
}
/**
return true;
}
+ function hasConstraint( $name ) {
+ $SQL = "SELECT 1 FROM pg_catalog.pg_constraint WHERE conname = '" . pg_escape_string( $name ) . "'";
+ return $this->numRows($res = $this->doQuery($SQL));
+ }
+
static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0)
{
return new DatabasePostgres( $server, $user, $password, $dbName, $failFunction, $flags );
return false;
}
+ function buildConcat( $stringList ) {
+ return implode( ' || ', $stringList );
+ }
+
} // end DatabasePostgres class
list( $oldRels, $deleteCurrent ) = $this->getOldRels();
if ( $deleteCurrent ) {
+ $concat = $dbw->buildConcat( array( "img_sha1", $encExt ) );
$where = array( 'img_name' => $this->file->getName() );
$dbw->insertSelect( 'filearchive', 'image',
array(
'fa_storage_group' => $encGroup,
- 'fa_storage_key' => "IF(img_sha1='', '', CONCAT(img_sha1,$encExt))",
-
+ 'fa_storage_key' => "CASE WHEN img_sha1='' THEN '' ELSE $concat END",
'fa_deleted_user' => $encUserId,
'fa_deleted_timestamp' => $encTimestamp,
'fa_deleted_reason' => $encReason,
}
if ( count( $oldRels ) ) {
+ $concat = $dbw->buildConcat( array( "oi_sha1", $encExt ) );
$where = array(
'oi_name' => $this->file->getName(),
'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')' );
-
$dbw->insertSelect( 'filearchive', 'oldimage',
array(
'fa_storage_group' => $encGroup,
- 'fa_storage_key' => "IF(oi_sha1='', '', CONCAT(oi_sha1,$encExt))",
-
+ 'fa_storage_key' => "CASE WHEN oi_sha1='' THEN '' ELSE $concat END",
'fa_deleted_user' => $encUserId,
'fa_deleted_timestamp' => $encTimestamp,
'fa_deleted_reason' => $encReason,
CREATE INDEX img_sha1 ON image (img_sha1);
CREATE TABLE oldimage (
- oi_name TEXT NOT NULL REFERENCES image(img_name),
+ oi_name TEXT NOT NULL,
oi_archive_name TEXT NOT NULL,
oi_size INTEGER NOT NULL,
oi_width INTEGER NOT NULL,
oi_deleted CHAR NOT NULL DEFAULT '0',
oi_sha1 TEXT NOT NULL DEFAULT ''
);
+ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascade FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE;
CREATE INDEX oi_name_timestamp ON oldimage (oi_name,oi_timestamp);
CREATE INDEX oi_name_archive_name ON oldimage (oi_name,oi_archive_name);
CREATE INDEX oi_sha1 ON oldimage (oi_sha1);
fa_name TEXT NOT NULL,
fa_archive_name TEXT,
fa_storage_group VARCHAR(16),
- fa_storage_key CHAR(64),
+ fa_storage_key TEXT,
fa_deleted_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
fa_deleted_timestamp TIMESTAMPTZ NOT NULL,
fa_deleted_reason TEXT,
# table, column, desired type, USING clause if needed
$typechanges = array(
array("filearchive", "fa_metadata", "bytea", "decode(fa_metadata,'escape')"),
+ array("filearchive", "fa_storage_key", "text", ""),
array("image", "img_metadata", "bytea", "decode(img_metadata,'escape')"),
array("image", "img_size", "int4", ""),
array("image", "img_width", "int4", ""),
dbsource(archive($nr[2]));
}
+ if ($wgDatabase->hasConstraint("oldimage_oi_name_fkey")) {
+ echo "... change oldimage to CASCADE DELETE on image deletion\n";
+ $wgDatabase->query("ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey");
+ $wgDatabase->query("ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascade ".
+ "FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE");
+ }
+
if (!$wgDatabase->triggerExists("page", "page_deleted")) {
echo "... create page_deleted trigger\n";
dbsource(archive('patch-page_deleted.sql'));