예제 #1
0
 public function execute()
 {
     // Shouldn't be needed for Postgres
     $this->db = $this->getDB(DB_MASTER);
     if ($this->db->getType() == 'postgres') {
         $this->error("This script is not needed when using Postgres.\n", true);
     }
     if ($this->db->getType() == 'sqlite') {
         if (!DatabaseSqlite::getFulltextSearchModule()) {
             $this->error("Your version of SQLite module for PHP doesn't " . "support full-text search (FTS3).\n", true);
         }
         if (!$this->db->checkForEnabledSearch()) {
             $this->error("Your database schema is not configured for " . "full-text search support. Run update.php.\n", true);
         }
     }
     if ($this->db->getType() == 'mysql') {
         $this->dropMysqlTextIndex();
         $this->clearSearchIndex();
         $this->populateSearchIndex();
         $this->createMysqlTextIndex();
     } else {
         $this->clearSearchIndex();
         $this->populateSearchIndex();
     }
     $this->output("Done.\n");
 }
예제 #2
0
 function getCountQuery($filteredTerm, $fulltext)
 {
     $match = $this->parseQuery($filteredTerm, $fulltext);
     $page = $this->db->tableName('page');
     $searchindex = $this->db->tableName('searchindex');
     return "SELECT COUNT(*) AS c " . "FROM {$page},{$searchindex} " . "WHERE page_id={$searchindex}.rowid AND {$match}" . $this->queryRedirect() . ' ' . $this->queryNamespaces();
 }
예제 #3
0
 protected function sqliteSetupSearchindex()
 {
     $module = DatabaseSqlite::getFulltextSearchModule();
     $fts3tTable = $this->updateRowExists('fts3');
     if ($fts3tTable && !$module) {
         $this->applyPatch('searchindex-no-fts.sql', false, 'PHP is missing FTS3 support, downgrading tables');
     } elseif (!$fts3tTable && $module == 'FTS3') {
         $this->applyPatch('searchindex-fts3.sql', false, "Adding FTS3 search capabilities");
     } else {
         $this->output("...fulltext search table appears to be in order.\n");
     }
 }
예제 #4
0
 /**
  * @param $status Status
  * @return Status
  */
 public function setupSearchIndex(&$status)
 {
     global $IP;
     $module = DatabaseSqlite::getFulltextSearchModule();
     $fts3tTable = $this->db->checkForEnabledSearch();
     if ($fts3tTable && !$module) {
         $status->warning('config-sqlite-fts3-downgrade');
         $this->db->sourceFile("{$IP}/maintenance/sqlite/archives/searchindex-no-fts.sql");
     } elseif (!$fts3tTable && $module == 'FTS3') {
         $this->db->sourceFile("{$IP}/maintenance/sqlite/archives/searchindex-fts3.sql");
     }
     return $status;
 }
 $dataFile = DatabaseSqlite::generateFileName($wgSQLiteDataDir, $wgDBname);
 if (file_exists($dataFile)) {
     if (!is_writable($dataFile)) {
         echo "data file not writable</li>";
         $errs['SQLiteDataDir'] = basename($dataFile) . " is not writable";
         continue;
     }
 } else {
     if (file_put_contents($dataFile, '') === false) {
         echo 'could not create database file "' . htmlspecialchars(basename($dataFile)) . "\"</li>\n";
         $errs['SQLiteDataDir'] = "couldn't create " . basename($dataFile);
         continue;
     }
 }
 try {
     $wgDatabase = new DatabaseSqlite(false, false, false, $wgDBname, 1);
 } catch (MWException $ex) {
     echo 'error: ' . htmlspecialchars($ex->getMessage()) . "</li>\n";
     continue;
 }
 if (!$wgDatabase->isOpen()) {
     print "error: " . htmlspecialchars($wgDatabase->lastError()) . "</li>\n";
     $errs['SQLiteDataDir'] = 'Could not connect to database';
     continue;
 } else {
     $myver = $wgDatabase->getServerVersion();
 }
 if (is_callable(array($wgDatabase, 'initial_setup'))) {
     $wgDatabase->initial_setup('', $wgDBname);
 }
 echo "ok</li>\n";
예제 #6
0
 /**
  * Check if the searchindext table is FTS enabled.
  * @return bool False if not enabled.
  */
 function checkForEnabledSearch()
 {
     if (self::$fulltextEnabled === null) {
         self::$fulltextEnabled = false;
         $table = $this->tableName('searchindex');
         $res = $this->query("SELECT sql FROM sqlite_master WHERE tbl_name = '{$table}'", __METHOD__);
         if ($res) {
             $row = $res->fetchRow();
             self::$fulltextEnabled = stristr($row['sql'], 'fts') !== false;
         }
     }
     return self::$fulltextEnabled;
 }
예제 #7
0
 /**
  * Environment check for DB types.
  */
 protected function envCheckDB()
 {
     global $wgLang;
     $allNames = array();
     foreach (self::getDBTypes() as $name) {
         $allNames[] = wfMsg("config-type-{$name}");
     }
     if (!$this->getVar('_CompiledDBs')) {
         $this->showError('config-no-db', $wgLang->commaList($allNames));
         // @todo FIXME: This only works for the web installer!
         return false;
     }
     // Check for FTS3 full-text search module
     $sqlite = $this->getDBInstaller('sqlite');
     if ($sqlite->isCompiled()) {
         if (DatabaseSqlite::getFulltextSearchModule() != 'FTS3') {
             $this->showMessage('config-no-fts3');
         }
     }
 }
예제 #8
0
 public function testToString()
 {
     $db = DatabaseSqlite::newStandaloneInstance(':memory:');
     $toString = (string) $db;
     $this->assertContains('SQLite ', $toString);
 }
예제 #9
0
 /**
  * @covers DatabaseSqlite::numFields
  */
 public function testNumFields()
 {
     $db = DatabaseSqlite::newStandaloneInstance(':memory:');
     $databaseCreation = $db->query('CREATE TABLE a ( a_1 )', __METHOD__);
     $this->assertInstanceOf('ResultWrapper', $databaseCreation, "Failed to create table a");
     $res = $db->select('a', '*');
     $this->assertEquals(0, $db->numFields($res), "expects to get 0 fields for an empty table");
     $insertion = $db->insert('a', array('a_1' => 10), __METHOD__);
     $this->assertTrue($insertion, "Insertion failed");
     $res = $db->select('a', '*');
     $this->assertEquals(1, $db->numFields($res), "wrong number of fields");
     $this->assertTrue($db->close(), "closing database");
 }