/** * @param array $params An associative array with one member: * - connection: An IDatabase connection object */ public function __construct(array $params) { if (!isset($params['connection'])) { throw new InvalidArgumentException("Missing 'connection' argument."); } $this->db = $params['connection']; parent::__construct(['servers' => [['type' => $this->db->getType(), 'host' => $this->db->getServer(), 'dbname' => $this->db->getDBname(), 'load' => 1]], 'trxProfiler' => isset($params['trxProfiler']) ? $params['trxProfiler'] : null, 'srvCache' => isset($params['srvCache']) ? $params['srvCache'] : null, 'wanCache' => isset($params['wanCache']) ? $params['wanCache'] : null]); if (isset($params['readOnlyReason'])) { $this->db->setLBInfo('readOnlyReason', $params['readOnlyReason']); } }
/** * @param IDatabase $db * @return string SearchEngine subclass name * @since 1.28 */ public static function getSearchEngineClass(IDatabase $db) { switch ($db->getType()) { case 'sqlite': return 'SearchSqlite'; case 'mysql': return 'SearchMySQL'; case 'postgres': return 'SearchPostgres'; case 'mssql': return 'SearchMssql'; case 'oracle': return 'SearchOracle'; default: return 'SearchEngineDummy'; } }
/** * Get the full path of a patch file. Originally based on archive() * from updaters.inc. Keep in mind this always returns a patch, as * it fails back to MySQL if no DB-specific patch can be found * * @param IDatabase $db * @param string $patch The name of the patch, like patch-something.sql * @return string Full path to patch file */ public function patchPath(IDatabase $db, $patch) { global $IP; $dbType = $db->getType(); if (file_exists("{$IP}/maintenance/{$dbType}/archives/{$patch}")) { return "{$IP}/maintenance/{$dbType}/archives/{$patch}"; } else { return "{$IP}/maintenance/archives/{$patch}"; } }
/** * Return a path to the DBMS-specific SQL file if it exists, * otherwise default SQL file * * @param IDatabase $db * @param string $filename * @return string */ private function getSqlFilePath($db, $filename) { global $IP; $dbmsSpecificFilePath = "{$IP}/maintenance/" . $db->getType() . "/{$filename}"; if (file_exists($dbmsSpecificFilePath)) { return $dbmsSpecificFilePath; } else { return "{$IP}/maintenance/{$filename}"; } }