[Bast-commits] r4806 -
DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema
jgoulah at dev.catalyst.perl.org
jgoulah at dev.catalyst.perl.org
Mon Sep 15 17:15:54 BST 2008
Author: jgoulah
Date: 2008-09-15 17:15:53 +0100 (Mon, 15 Sep 2008)
New Revision: 4806
Modified:
DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema/Preview.pm
Log:
syncing preview changes
Modified: DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema/Preview.pm
===================================================================
--- DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema/Preview.pm 2008-09-13 16:28:48 UTC (rev 4805)
+++ DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema/Preview.pm 2008-09-15 16:15:53 UTC (rev 4806)
@@ -43,41 +43,49 @@
}
my $schema = $self->unpreviewed;
+sub with_deferred_fk_checks {
+ my ($self, $sub) = @_;
+
+
+ $sub->();
+ $self->dbh->do('SET foreign_key_checks=1');
+}
+
$schema->txn_do(
sub {
- $schema->storage->with_deferred_fk_checks(
- sub {
- foreach my $source_name ($schema->sources) {
- my $source = $schema->source($source_name);
- if ($source->can('previewed')) {
- my $original_rs = $schema->resultset($source->source_name);
- my $previewed_rs = $source->previewed->resultset;
-
- my $dirty_previewed_rs = $previewed_rs->search({ dirty => 1, deleted => 0 });
- while (my $dirty_row = $dirty_previewed_rs->next) {
- my $original_row = $original_rs->find($dirty_row->id);
- my %dirty_cols = $dirty_row->get_columns;
- delete $dirty_cols{dirty};
- delete $dirty_cols{deleted};
-
- if ($original_row) {
- $original_row->update(\%dirty_cols);
- } else {
- $original_rs->create(\%dirty_cols);
- }
- }
- $dirty_previewed_rs->update({ dirty => 0 });
-
- my $deleted_previewed_rs = $previewed_rs->search({ deleted => 1 });
- while (my $deleted_row = $deleted_previewed_rs->next) {
- my $original_row = $original_rs->find($deleted_row->id);
- $deleted_row->delete();
- $original_row->delete;
- }
- }
- }
- }
- );
+ $schema->storage->with_deferred_fk_checks(
+ sub {
+ foreach my $source_name ($schema->sources) {
+ my $source = $schema->source($source_name);
+ if ($source->can('previewed')) {
+ my $original_rs = $schema->resultset($source->source_name);
+ my $previewed_rs = $source->previewed->resultset;
+
+ my $dirty_previewed_rs = $previewed_rs->search({ dirty => 1, deleted => 0 });
+ while (my $dirty_row = $dirty_previewed_rs->next) {
+ my $original_row = $original_rs->find($dirty_row->id);
+ my %dirty_cols = $dirty_row->get_columns;
+ delete $dirty_cols{dirty};
+ delete $dirty_cols{deleted};
+
+ if ($original_row) {
+ $original_row->update(\%dirty_cols);
+ } else {
+ $original_rs->create(\%dirty_cols);
+ }
+ }
+ $dirty_previewed_rs->update({ dirty => 0 });
+
+ my $deleted_previewed_rs = $previewed_rs->search({ deleted => 1 });
+ while (my $deleted_row = $deleted_previewed_rs->next) {
+ my $original_row = $original_rs->find($deleted_row->id);
+ $deleted_row->delete();
+ if (defined $original_row) {$original_row->delete;}
+ }
+ }
+ }
+ }
+ );
}
);
}
More information about the Bast-commits
mailing list