Beispiel #1
0
 /**
  * Constructor
  *
  * @param Database $db A database subclass
  * @param array $tablesToClone An array of tables to clone, unprefixed
  * @param string $newTablePrefix Prefix to assign to the tables
  * @param string $oldTablePrefix Prefix on current tables, if not $wgDBprefix
  * @param bool $dropCurrentTables
  */
 public function __construct(Database $db, array $tablesToClone, $newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true)
 {
     $this->db = $db;
     $this->tablesToClone = $tablesToClone;
     $this->newTablePrefix = $newTablePrefix;
     $this->oldTablePrefix = $oldTablePrefix ? $oldTablePrefix : $this->db->tablePrefix();
     $this->dropCurrentTables = $dropCurrentTables;
 }
Beispiel #2
0
 /**
  * @covers Database::tablePrefix()
  * @covers Database::dbSchema()
  */
 public function testMutators()
 {
     $old = $this->db->tablePrefix();
     $this->assertType('string', $old, 'Prefix is string');
     $this->assertEquals($old, $this->db->tablePrefix(), "Prefix unchanged");
     $this->assertEquals($old, $this->db->tablePrefix('xxx'));
     $this->assertEquals('xxx', $this->db->tablePrefix(), "Prefix set");
     $this->db->tablePrefix($old);
     $this->assertNotEquals('xxx', $this->db->tablePrefix());
     $old = $this->db->dbSchema();
     $this->assertType('string', $old, 'Schema is string');
     $this->assertEquals($old, $this->db->dbSchema(), "Schema unchanged");
     $this->assertEquals($old, $this->db->dbSchema('xxx'));
     $this->assertEquals('xxx', $this->db->dbSchema(), "Schema set");
     $this->db->dbSchema($old);
     $this->assertNotEquals('xxx', $this->db->dbSchema());
 }
Beispiel #3
0
 /**
  * Return the table name.
  *
  * @return string
  */
 public function getTableName($table = '')
 {
     return $table ? $this->db->tablePrefix() . $table : $this->db->tablePrefix() . $this->_name;
 }
 /**
  * @since 1.18
  *
  * @param Database $db
  *
  * @return array
  */
 public static function listTables(Database $db)
 {
     $prefix = $db->tablePrefix();
     $tables = $db->listTables($prefix, __METHOD__);
     if ($db->getType() === 'mysql') {
         static $viewListCache = null;
         if ($viewListCache === null) {
             $viewListCache = $db->listViews(null, __METHOD__);
         }
         // T45571: cannot clone VIEWs under MySQL
         $tables = array_diff($tables, $viewListCache);
     }
     array_walk($tables, [__CLASS__, 'unprefixTable'], $prefix);
     // Don't duplicate test tables from the previous fataled run
     $tables = array_filter($tables, [__CLASS__, 'isNotUnittest']);
     if ($db->getType() == 'sqlite') {
         $tables = array_flip($tables);
         // these are subtables of searchindex and don't need to be duped/dropped separately
         unset($tables['searchindex_content']);
         unset($tables['searchindex_segdir']);
         unset($tables['searchindex_segments']);
         $tables = array_flip($tables);
     }
     return $tables;
 }