/** * Apply a SQL source file to the database as part of running an installation step. * * @param string $sourceFileMethod * @param string $stepName * @param bool $archiveTableMustNotExist * @return Status */ private function stepApplySourceFile($sourceFileMethod, $stepName, $archiveTableMustNotExist = false) { $status = $this->getConnection(); if (!$status->isOK()) { return $status; } $this->db->selectDB($this->getVar('wgDBname')); if ($archiveTableMustNotExist && $this->db->tableExists('archive', __METHOD__)) { $status->warning("config-{$stepName}-tables-exist"); $this->enableLB(); return $status; } $this->db->setFlag(DBO_DDLMODE); // For Oracle's handling of schema files $this->db->begin(__METHOD__); $error = $this->db->sourceFile(call_user_func([$this, $sourceFileMethod], $this->db)); if ($error !== true) { $this->db->reportQueryError($error, 0, '', __METHOD__); $this->db->rollback(__METHOD__); $status->fatal("config-{$stepName}-tables-failed", $error); } else { $this->db->commit(__METHOD__); } // Resume normal operations if ($status->isOK()) { $this->enableLB(); } return $status; }
public function testStoredFunctions() { if (!in_array(wfGetDB(DB_MASTER)->getType(), ['mysql', 'postgres'])) { $this->markTestSkipped('MySQL or Postgres required'); } global $IP; $this->dropFunctions(); $this->functionTest = true; $this->assertTrue($this->db->sourceFile("{$IP}/tests/phpunit/data/db/{$this->db->getType()}/functions.sql")); $res = $this->db->query('SELECT mw_test_function() AS test', __METHOD__); $this->assertEquals(42, $res->fetchObject()->test); }
/** * Applies a SQL patch * * @param string $path Path to the patch file * @param bool $isFullPath Whether to treat $path as a relative or not * @param string $msg Description of the patch * @return bool False if patch is skipped. */ protected function applyPatch($path, $isFullPath = false, $msg = null) { if ($msg === null) { $msg = "Applying {$path} patch"; } if ($this->skipSchema) { $this->output("...skipping schema change ({$msg}).\n"); return false; } $this->output("{$msg} ..."); if (!$isFullPath) { $path = $this->patchPath($this->db, $path); } if ($this->fileHandle !== null) { $this->copyFile($path); } else { $this->db->sourceFile($path); } $this->output("done.\n"); return true; }