Example #1
0
 /**
  * Clone the table structure
  */
 public function cloneTableStructure()
 {
     global $wgSharedTables, $wgSharedDB;
     foreach ($this->tablesToClone as $tbl) {
         if ($wgSharedDB && in_array($tbl, $wgSharedTables, true)) {
             // Shared tables don't work properly when cloning due to
             // how prefixes are handled (bug 65654)
             throw new RuntimeException("Cannot clone shared table {$tbl}.");
         }
         # Clean up from previous aborted run.  So that table escaping
         # works correctly across DB engines, we need to change the pre-
         # fix back and forth so tableName() works right.
         self::changePrefix($this->oldTablePrefix);
         $oldTableName = $this->db->tableName($tbl, 'raw');
         self::changePrefix($this->newTablePrefix);
         $newTableName = $this->db->tableName($tbl, 'raw');
         if ($this->dropCurrentTables && !in_array($this->db->getType(), ['postgres', 'oracle'])) {
             if ($oldTableName === $newTableName) {
                 // Last ditch check to avoid data loss
                 throw new LogicException("Not dropping new table, as '{$newTableName}'" . " is name of both the old and the new table.");
             }
             $this->db->dropTable($tbl, __METHOD__);
             wfDebug(__METHOD__ . " dropping {$newTableName}\n");
             // Dropping the oldTable because the prefix was changed
         }
         # Create new table
         wfDebug(__METHOD__ . " duplicating {$oldTableName} to {$newTableName}\n");
         $this->db->duplicateTableStructure($oldTableName, $newTableName, $this->useTemporaryTables);
     }
 }
Example #2
0
 /**
  * (MySQL only) Adds back fulltext index after populating the table.
  */
 private function createMysqlTextIndex()
 {
     $searchindex = $this->db->tableName('searchindex');
     $this->output("\nRebuild the index...\n");
     $sql = "ALTER TABLE {$searchindex} ADD FULLTEXT si_title (si_title), " . "ADD FULLTEXT si_text (si_text)";
     $this->db->query($sql, __METHOD__);
 }
 function tableName($name)
 {
     switch ($name) {
         case 'interwiki':
             return ForgeConfig::get('sys_dbname') . '.plugin_mediawiki_interwiki';
         default:
             return Database::tableName($name);
     }
 }
 /**
  * @param string $serverType
  * @param array $tables
  */
 protected function buildTestDatabase($tables)
 {
     global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
     $wgDBprefix = 'parsertest';
     $db = new Database($wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname);
     if ($db->isOpen()) {
         if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
             # Database that supports CREATE TABLE ... LIKE
             foreach ($tables as $tbl) {
                 $newTableName = $db->tableName($tbl);
                 #$tableName = $this->oldTableNames[$tbl];
                 $tableName = $tbl;
                 $db->query("CREATE TEMPORARY TABLE {$newTableName} (LIKE {$tableName})");
             }
         } else {
             # Hack for MySQL versions < 4.1, which don't support
             # "CREATE TABLE ... LIKE". Note that
             # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
             # would not create the indexes we need....
             foreach ($tables as $tbl) {
                 $res = $db->query("SHOW CREATE TABLE {$tbl}");
                 $row = $db->fetchRow($res);
                 $create = $row[1];
                 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `' . $wgDBprefix . '\\1`', $create);
                 if ($create === $create_tmp) {
                     # Couldn't do replacement
                     wfDie("could not create temporary table {$tbl}");
                 }
                 $db->query($create_tmp);
             }
         }
         return $db;
     } else {
         // Something amiss
         return null;
     }
 }
Example #5
0
 function realTableName($name, $format = 'quoted')
 {
     return parent::tableName($name, $format);
 }
Example #6
0
 function tableName($name, $format = 'quoted')
 {
     /*
     Replace reserved words with better ones
     Using uppercase because that's the only way Oracle can handle
     quoted tablenames
     */
     switch ($name) {
         case 'user':
             $name = 'MWUSER';
             break;
         case 'text':
             $name = 'PAGECONTENT';
             break;
     }
     return strtoupper(parent::tableName($name, $format));
 }
 /**
  * @param Database $dbw
  * @return void
  */
 private function truncate($dbw)
 {
     $test = $dbw->tableName('test');
     $dbw->query("TRUNCATE TABLE {$test}");
 }
 /**
  * Make sure that each of the column descriptions in the given array is
  * indexed by *one* index in the given DB table.
  *
  * @param string $tableName table name. Does not need to have been passed to DatabaseBase->tableName yet.
  * @param array $indexes array of strings, each a comma separated list with column names to index
  * @param DatabaseBase|Database $db DatabaseBase or Database
  * @param object $reportTo object to report messages to; since 1.8
  */
 public static function setupIndex($rawTableName, array $indexes, $db, $reportTo = null)
 {
     global $wgDBtype;
     $tableName = $wgDBtype == 'postgres' ? $db->tableName($rawTableName, 'raw') : $db->tableName($rawTableName);
     self::reportProgress("Checking index structures for table {$tableName} ...\n", $reportTo);
     // First remove obsolete indexes.
     $oldIndexes = self::getIndexInfo($db, $tableName);
     if ($wgDBtype == 'sqlite') {
         // SQLite
         /// TODO We do not currently get the right column definitions in
         /// SQLLite; hence we can only drop all indexes. Wasteful.
         foreach ($oldIndexes as $key => $index) {
             self::dropIndex($db, $key, $tableName, $key, $reportTo);
         }
     } else {
         foreach ($oldIndexes as $key => $indexColumn) {
             $id = array_search($indexColumn, $indexes);
             if ($id !== false || $key == 'PRIMARY') {
                 self::reportProgress("   ... index {$indexColumn} is fine.\n", $reportTo);
                 unset($indexes[$id]);
             } else {
                 // Duplicate or unrequired index.
                 self::dropIndex($db, $key, $tableName, $indexColumn, $reportTo);
             }
         }
     }
     // Add new indexes.
     foreach ($indexes as $key => $index) {
         // If the index is an array, it contains the column
         // name as first element, and index type as second one.
         if (is_array($index)) {
             $columns = $index[0];
             $type = count($index) > 1 ? $index[1] : 'INDEX';
         } else {
             $columns = $index;
             $type = 'INDEX';
         }
         self::createIndex($db, $type, "{$tableName}_index{$key}", $tableName, $columns, $reportTo);
     }
     self::reportProgress("   ... done.\n", $reportTo);
     return true;
 }
Example #9
0
 /**
  * call this instead of tableName() in the updater when renaming tables
  * @param string $name
  * @param string $format One of quoted, raw, or split
  * @return string
  */
 function realTableName($name, $format = 'quoted')
 {
     $table = parent::tableName($name, $format);
     if ($format == 'split') {
         // Used internally, we want the schema split off from the table name and returned
         // as a list with 3 elements (database, schema, table)
         $table = explode('.', $table);
         while (count($table) < 3) {
             array_unshift($table, false);
         }
     }
     return $table;
 }
Example #10
0
 /**
  * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
  *
  * @param string $name
  * @param string $format
  * @return string
  */
 function tableName($name, $format = 'quoted')
 {
     // table names starting with sqlite_ are reserved
     if (strpos($name, 'sqlite_') === 0) {
         return $name;
     }
     return str_replace('"', '', parent::tableName($name, $format));
 }
Example #11
0
 /**
  * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
  */
 function tableName($name)
 {
     return str_replace('`', '', parent::tableName($name));
 }
 function tableName($name, $forddl = false)
 {
     # First run any transformations from the parent object
     $name = parent::tableName($name);
     # Replace backticks into empty
     # Note: "foo" and foo are not the same in Oracle!
     $name = str_replace('`', '', $name);
     # Now quote Oracle reserved keywords
     switch ($name) {
         case 'user':
         case 'group':
         case 'validate':
             if ($forddl) {
                 return $name;
             } else {
                 return '"' . $name . '"';
             }
         default:
             return strtoupper($name);
     }
 }
Example #13
0
 public function testTableNameRawForeign()
 {
     $this->assertEquals($this->prefixAndQuote('tablename', 'databasename', '', 'raw'), $this->db->tableName('databasename.tablename', 'raw'));
 }
Example #14
0
    function execute()
    {
        $this->dbw = $this->getDB(DB_MASTER);
        $logging = $this->dbw->tableName('logging');
        $logging_1_10 = $this->dbw->tableName('logging_1_10');
        $logging_pre_1_10 = $this->dbw->tableName('logging_pre_1_10');
        if ($this->dbw->tableExists('logging_pre_1_10') && !$this->dbw->tableExists('logging')) {
            # Fix previous aborted run
            echo "Cleaning up from previous aborted run\n";
            $this->dbw->query("RENAME TABLE {$logging_pre_1_10} TO {$logging}", __METHOD__);
        }
        if ($this->dbw->tableExists('logging_pre_1_10')) {
            echo "This script has already been run to completion\n";
            return;
        }
        # Create the target table
        if (!$this->dbw->tableExists('logging_1_10')) {
            global $wgDBTableOptions;
            $sql = <<<EOT
CREATE TABLE {$logging_1_10} (
  -- Log ID, for referring to this specific log entry, probably for deletion and such.
  log_id int unsigned NOT NULL auto_increment,

  -- Symbolic keys for the general log type and the action type
  -- within the log. The output format will be controlled by the
  -- action field, but only the type controls categorization.
  log_type varbinary(10) NOT NULL default '',
  log_action varbinary(10) NOT NULL default '',

  -- Timestamp. Duh.
  log_timestamp binary(14) NOT NULL default '19700101000000',

  -- The user who performed this action; key to user_id
  log_user int unsigned NOT NULL default 0,

  -- Key to the page affected. Where a user is the target,
  -- this will point to the user page.
  log_namespace int NOT NULL default 0,
  log_title varchar(255) binary NOT NULL default '',

  -- Freeform text. Interpreted as edit history comments.
  log_comment varchar(255) NOT NULL default '',

  -- LF separated list of miscellaneous parameters
  log_params blob NOT NULL,

  -- rev_deleted for logs
  log_deleted tinyint unsigned NOT NULL default '0',

  PRIMARY KEY log_id (log_id),
  KEY type_time (log_type, log_timestamp),
  KEY user_time (log_user, log_timestamp),
  KEY page_time (log_namespace, log_title, log_timestamp),
  KEY times (log_timestamp)

) {$wgDBTableOptions}
EOT;
            echo "Creating table logging_1_10\n";
            $this->dbw->query($sql, __METHOD__);
        }
        # Synchronise the tables
        echo "Doing initial sync...\n";
        $this->sync('logging', 'logging_1_10');
        echo "Sync done\n\n";
        # Rename the old table away
        echo "Renaming the old table to {$logging_pre_1_10}\n";
        $this->dbw->query("RENAME TABLE {$logging} TO {$logging_pre_1_10}", __METHOD__);
        # Copy remaining old rows
        # Done before the new table is active so that $copyPos is accurate
        echo "Doing final sync...\n";
        $this->sync('logging_pre_1_10', 'logging_1_10');
        # Move the new table in
        echo "Moving the new table in...\n";
        $this->dbw->query("RENAME TABLE {$logging_1_10} TO {$logging}", __METHOD__);
        echo "Finished.\n";
    }
 function tableName($name)
 {
     # First run any transformations from the parent object
     $name = parent::tableName($name);
     # Replace backticks into double quotes
     $name = strtr($name, '`', '"');
     # Now quote PG reserved keywords
     switch ($name) {
         case 'user':
         case 'old':
         case 'group':
             return '"' . $name . '"';
         default:
             return $name;
     }
 }