/** * @param DatabasePostgres $dbw * @param int $id * @param LoggerInterface $logger */ public function __construct(DatabasePostgres $dbw, $id, LoggerInterface $logger) { $this->dbw = $dbw; $this->logger = $logger; $this->id = $id; $this->didbegin = false; /* If we are not in a transaction, we need to be for savepoint trickery */ if (!$dbw->trxLevel()) { $dbw->begin(__CLASS__, DatabasePostgres::TRANSACTION_INTERNAL); $this->didbegin = true; } }
function update($pageid, $title, $text) { ## We don't want to index older revisions $SQL = "UPDATE pagecontent SET textvector = NULL WHERE old_id IN " . "(SELECT rev_text_id FROM revision WHERE rev_page = " . intval($pageid) . " ORDER BY rev_text_id DESC OFFSET 1)"; $this->db->query($SQL); return true; }
protected function tsearchFixes() { # Tweak the page_title tsearch2 trigger to filter out slashes # This is create or replace, so harmless to call if not needed $this->applyPatch('patch-ts2pagetitle.sql', false, "Refreshing ts2_page_title()"); # If the server is 8.3 or higher, rewrite the tsearch2 triggers # in case they have the old 'default' versions # Gather version numbers in case we need them if ($this->db->getServerVersion() >= 8.300000000000001) { $this->applyPatch('patch-tsearch2funcs.sql', false, "Rewriting tsearch2 triggers"); } }
function tableName($name, $format = 'quoted') { global $wgDBmwschema; switch ($name) { case 'interwiki': $v = 'plugin_mediawiki_interwiki'; break; default: return DatabasePostgres::tableName($name, $format); } if ($wgDBmwschema != 'public') { $v = 'public.' . $v; } return $v; }
/** * @param DatabasePostgres $db * @param string $table * @param string $field * @return null|PostgresField */ static function fromText(DatabasePostgres $db, $table, $field) { $q = <<<SQL SELECT attnotnull, attlen, conname AS conname, atthasdef, adsrc, COALESCE(condeferred, 'f') AS deferred, COALESCE(condeferrable, 'f') AS deferrable, CASE WHEN typname = 'int2' THEN 'smallint' WHEN typname = 'int4' THEN 'integer' WHEN typname = 'int8' THEN 'bigint' WHEN typname = 'bpchar' THEN 'char' ELSE typname END AS typname FROM pg_class c JOIN pg_namespace n ON (n.oid = c.relnamespace) JOIN pg_attribute a ON (a.attrelid = c.oid) JOIN pg_type t ON (t.oid = a.atttypid) LEFT JOIN pg_constraint o ON (o.conrelid = c.oid AND a.attnum = ANY(o.conkey) AND o.contype = 'f') LEFT JOIN pg_attrdef d on c.oid=d.adrelid and a.attnum=d.adnum WHERE relkind = 'r' AND nspname=%s AND relname=%s AND attname=%s; SQL; $table = $db->remappedTableName($table); $res = $db->query(sprintf($q, $db->addQuotes($db->getCoreSchema()), $db->addQuotes($table), $db->addQuotes($field))); $row = $db->fetchObject($res); if (!$row) { return null; } $n = new PostgresField(); $n->type = $row->typname; $n->nullable = $row->attnotnull == 'f'; $n->name = $field; $n->tablename = $table; $n->max_length = $row->attlen; $n->deferrable = $row->deferrable == 't'; $n->deferred = $row->deferred == 't'; $n->conname = $row->conname; $n->has_default = $row->atthasdef === 't'; $n->default = $row->adsrc; return $n; }