diff options
Diffstat (limited to 'maintenance/oracle/alterSharedConstraints.php')
-rw-r--r-- | maintenance/oracle/alterSharedConstraints.php | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/maintenance/oracle/alterSharedConstraints.php b/maintenance/oracle/alterSharedConstraints.php index e222314d..a46c5e1f 100644 --- a/maintenance/oracle/alterSharedConstraints.php +++ b/maintenance/oracle/alterSharedConstraints.php @@ -15,13 +15,14 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * + * @file * @ingroup Maintenance */ /** * When using shared tables that are referenced by foreign keys on local * tables you have to change the constraints on local tables. - * + * * The shared tables have to have GRANT REFERENCE on shared tables to local schema * i.e.: GRANT REFERENCES (user_id) ON mwuser TO hubclient; */ @@ -40,12 +41,12 @@ class AlterSharedConstraints extends Maintenance { public function execute() { global $wgSharedDB, $wgSharedTables, $wgSharedPrefix, $wgDBprefix; - + if ( $wgSharedDB == null ) { $this->output( "Database sharing is not enabled\n" ); return; } - + $dbw = wfGetDB( DB_MASTER ); foreach ( $wgSharedTables as $table ) { $stable = $dbw->tableNameInternal($table); @@ -54,7 +55,7 @@ class AlterSharedConstraints extends Maintenance { } else { $ltable = "{$wgDBprefix}{$stable}" ; } - + $result = $dbw->query( "SELECT uc.constraint_name, uc.table_name, ucc.column_name, uccpk.table_name pk_table_name, uccpk.column_name pk_column_name, uc.delete_rule, uc.deferrable, uc.deferred FROM user_constraints uc, user_cons_columns ucc, user_cons_columns uccpk WHERE uc.constraint_type = 'R' @@ -62,9 +63,9 @@ class AlterSharedConstraints extends Maintenance { AND uccpk.constraint_name = uc.r_constraint_name AND uccpk.table_name = '$ltable'" ); while (($row = $result->fetchRow()) !== false) { - + $this->output( "Altering {$row['constraint_name']} ..."); - + try { $dbw->query( "ALTER TABLE {$row['table_name']} DROP CONSTRAINT {$wgDBprefix}{$row['constraint_name']}" ); } catch (DBQueryError $exdb) { @@ -72,13 +73,13 @@ class AlterSharedConstraints extends Maintenance { throw $exdb; } } - + $deleteRule = $row['delete_rule'] == 'NO ACTION' ? '' : "ON DELETE {$row['delete_rule']}"; - $dbw->query( "ALTER TABLE {$row['table_name']} ADD CONSTRAINT {$wgDBprefix}{$row['constraint_name']} - FOREIGN KEY ({$row['column_name']}) - REFERENCES {$wgSharedDB}.$stable({$row['pk_column_name']}) + $dbw->query( "ALTER TABLE {$row['table_name']} ADD CONSTRAINT {$wgDBprefix}{$row['constraint_name']} + FOREIGN KEY ({$row['column_name']}) + REFERENCES {$wgSharedDB}.$stable({$row['pk_column_name']}) {$deleteRule} {$row['deferrable']} INITIALLY {$row['deferred']}" ); - + $this->output( "DONE\n" ); } } |