MediaWiki  1.23.2
CloneDatabase.php
Go to the documentation of this file.
1 <?php
29  private $newTablePrefix = '';
30 
32  private $oldTablePrefix = '';
33 
35  private $tablesToClone = array();
36 
38  private $dropCurrentTables = true;
39 
41  private $useTemporaryTables = true;
42 
52  public function __construct( DatabaseBase $db, array $tablesToClone,
54  ) {
55  $this->db = $db;
56  $this->tablesToClone = $tablesToClone;
57  $this->newTablePrefix = $newTablePrefix;
58  $this->oldTablePrefix = $oldTablePrefix ? $oldTablePrefix : $this->db->tablePrefix();
59  $this->dropCurrentTables = $dropCurrentTables;
60  }
61 
66  public function useTemporaryTables( $u = true ) {
67  $this->useTemporaryTables = $u;
68  }
69 
73  public function cloneTableStructure() {
74  foreach ( $this->tablesToClone as $tbl ) {
75  # Clean up from previous aborted run. So that table escaping
76  # works correctly across DB engines, we need to change the pre-
77  # fix back and forth so tableName() works right.
78 
79  self::changePrefix( $this->oldTablePrefix );
80  $oldTableName = $this->db->tableName( $tbl, 'raw' );
81 
82  self::changePrefix( $this->newTablePrefix );
83  $newTableName = $this->db->tableName( $tbl, 'raw' );
84 
85  if ( $this->dropCurrentTables
86  && !in_array( $this->db->getType(), array( 'postgres', 'oracle' ) )
87  ) {
88  $this->db->dropTable( $tbl, __METHOD__ );
89  wfDebug( __METHOD__ . " dropping {$newTableName}\n" );
90  //Dropping the oldTable because the prefix was changed
91  }
92 
93  # Create new table
94  wfDebug( __METHOD__ . " duplicating $oldTableName to $newTableName\n" );
95  $this->db->duplicateTableStructure( $oldTableName, $newTableName, $this->useTemporaryTables );
96  }
97  }
98 
103  public function destroy( $dropTables = false ) {
104  if ( $dropTables ) {
105  self::changePrefix( $this->newTablePrefix );
106  foreach ( $this->tablesToClone as $tbl ) {
107  $this->db->dropTable( $tbl );
108  }
109  }
110  self::changePrefix( $this->oldTablePrefix );
111  }
112 
119  public static function changePrefix( $prefix ) {
120  global $wgDBprefix;
121  wfGetLBFactory()->forEachLB( array( 'CloneDatabase', 'changeLBPrefix' ), array( $prefix ) );
122  $wgDBprefix = $prefix;
123  }
124 
130  public static function changeLBPrefix( $lb, $prefix ) {
131  $lb->forEachOpenConnection( array( 'CloneDatabase', 'changeDBPrefix' ), array( $prefix ) );
132  }
133 
139  public static function changeDBPrefix( $db, $prefix ) {
140  $db->tablePrefix( $prefix );
141  }
142 }
CloneDatabase\cloneTableStructure
cloneTableStructure()
Clone the table structure.
Definition: CloneDatabase.php:68
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
CloneDatabase\$useTemporaryTables
bool $useTemporaryTables
Whether to use temporary tables or not *.
Definition: CloneDatabase.php:36
CloneDatabase\$tablesToClone
array $tablesToClone
List of tables to be cloned *.
Definition: CloneDatabase.php:32
CloneDatabase\changeDBPrefix
static changeDBPrefix( $db, $prefix)
Definition: CloneDatabase.php:134
$lb
if( $wgAPIRequestLog) $lb
Definition: api.php:126
CloneDatabase\changeLBPrefix
static changeLBPrefix( $lb, $prefix)
Definition: CloneDatabase.php:125
CloneDatabase\$oldTablePrefix
string $oldTablePrefix
Current table prefix *.
Definition: CloneDatabase.php:30
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
CloneDatabase\__construct
__construct(DatabaseBase $db, array $tablesToClone, $newTablePrefix, $oldTablePrefix='', $dropCurrentTables=true)
Constructor.
Definition: CloneDatabase.php:47
DatabaseBase
Database abstraction object.
Definition: Database.php:219
CloneDatabase\destroy
destroy( $dropTables=false)
Change the prefix back to the original.
Definition: CloneDatabase.php:98
CloneDatabase\useTemporaryTables
useTemporaryTables( $u=true)
Set whether to use temporary tables or not.
Definition: CloneDatabase.php:61
CloneDatabase
Definition: CloneDatabase.php:27
wfGetLBFactory
& wfGetLBFactory()
Get the load balancer factory object.
Definition: GlobalFunctions.php:3669
CloneDatabase\changePrefix
static changePrefix( $prefix)
Change the table prefix on all open DB connections/.
Definition: CloneDatabase.php:114
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
CloneDatabase\$dropCurrentTables
bool $dropCurrentTables
Should we DROP tables containing the new names? *.
Definition: CloneDatabase.php:34
CloneDatabase\$newTablePrefix
string $newTablePrefix
Table prefix for cloning *.
Definition: CloneDatabase.php:28