[Bast-commits] r4724 - in DBIx-Class-Preview/1.000/trunk:
lib/DBIx/Class lib/DBIx/Class/ResultSource/Table
lib/DBIx/Class/Schema t t/var
lukes at dev.catalyst.perl.org
lukes at dev.catalyst.perl.org
Sat Aug 2 12:51:58 BST 2008
Author: lukes
Date: 2008-08-02 12:51:58 +0100 (Sat, 02 Aug 2008)
New Revision: 4724
Modified:
DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Preview.pm
DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Preview.pm
DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema/Preview.pm
DBIx-Class-Preview/1.000/trunk/t/delete.t
DBIx-Class-Preview/1.000/trunk/t/var/DBIxClass.db
Log:
added delete functionality
Modified: DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Preview.pm
===================================================================
--- DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Preview.pm 2008-08-02 11:02:55 UTC (rev 4723)
+++ DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Preview.pm 2008-08-02 11:51:58 UTC (rev 4724)
@@ -51,6 +51,17 @@
return $self->next::method(@_);
}
+sub delete {
+ my $self = shift;
+
+ # mark row as dirty
+ if ($self->result_source->schema->preview_active() && $self->result_source->can('is_preview_source')) {
+ return $self->update({ deleted => 1 });
+ } else {
+ return $self->next::method(@_);
+ }
+}
+
# dirty col set here by default value on the table def
sub new {
my $self = shift;
Modified: DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Preview.pm
===================================================================
--- DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Preview.pm 2008-08-02 11:02:55 UTC (rev 4723)
+++ DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Preview.pm 2008-08-02 11:51:58 UTC (rev 4724)
@@ -11,4 +11,13 @@
sub from { return shift->preview_table }
sub is_preview_source { 1 };
+sub resultset {
+ my $self = shift;
+
+ my $rs = $self->next::method(@_);
+ return ($self->schema->preview_active()) ?
+ $rs->search({ deleted => 0 }) :
+ $rs;
+}
+
1;
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-08-02 11:02:55 UTC (rev 4723)
+++ DBIx-Class-Preview/1.000/trunk/lib/DBIx/Class/Schema/Preview.pm 2008-08-02 11:51:58 UTC (rev 4724)
@@ -41,7 +41,7 @@
warn 'preview mode not activated, can not publish';
return;
}
- my $schema = $self->unpreviewed;
+ my $schema = $self->unpreviewed;
$schema->txn_do(
sub {
@@ -49,9 +49,9 @@
my $source = $schema->source($source_name);
if ($source->can('previewed')) {
my $original_rs = $schema->resultset($source->source_name);
- my $previewed_rs = $self->resultset($source->source_name);
+ my $previewed_rs = $source->previewed->resultset;
- my $dirty_previewed_rs = $previewed_rs->search({ dirty => 1 });
+ 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;
@@ -64,6 +64,13 @@
}
}
$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;
+ }
}
}
}
Modified: DBIx-Class-Preview/1.000/trunk/t/delete.t
===================================================================
--- DBIx-Class-Preview/1.000/trunk/t/delete.t 2008-08-02 11:02:55 UTC (rev 4723)
+++ DBIx-Class-Preview/1.000/trunk/t/delete.t 2008-08-02 11:51:58 UTC (rev 4724)
@@ -15,6 +15,8 @@
my $orig_row = $unpreviewed_schema->resultset('Artist')->find($row->id);
$row->delete;
+
+$schema->resultset('Artist')->search({});
ok(!$schema->resultset('Artist')->find($row->id), 'artist no longer visible in previewed table');
ok($unpreviewed_schema->resultset('Artist')->find($row->id), 'artist still visible in unpreviewed table');
Modified: DBIx-Class-Preview/1.000/trunk/t/var/DBIxClass.db
===================================================================
(Binary files differ)
More information about the Bast-commits
mailing list