fix replication and document it
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 8 Nov 2010 17:51:30 +0000 (18:51 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 8 Nov 2010 17:51:30 +0000 (18:51 +0100)
README
angular-server.pl

diff --git a/README b/README
index 8c716ea..dd7aa13 100644 (file)
--- a/README
+++ b/README
@@ -25,6 +25,13 @@ At it's current stage it provides support for angular $resource get, query and $
 http://angularjs.org/Service:$resource
 
 
+Server also supports replication using same API which can be triggered with
+
+ http://localhost:3000/_replicate?from=http://dpavlin.getangular.com/data/conference/
+
+Replication is currently good only for initial import of data since it doesn't
+support incremental replication and dies if data is allready present.
+
 
 Installation:
 
index 221f60d..4471a06 100755 (executable)
@@ -64,7 +64,6 @@ get '/_replicate' => sub {
        if ( my $from = $self->param('from') ) {
                my $got = $self->client->get( $from )->res->json;
                warn "# from $from ",dump($got);
-               _render_jsonp( $self,  $got );
 
                my $database = $got->{name};
                my $entities = $got->{entities};
@@ -74,11 +73,15 @@ get '/_replicate' => sub {
                                my $url = $from;
                                $url =~ s{/?$}{/}; # add slash at end
                                $url .= $entity;
-                               my $e = $self->client->get( $url )->res->json;
-                               warn "# replicated $url ", dump($e);
-                               _chouchdb_put( $self, $database, $entity, $e->{'$id'}, $e );
+                               my $all = $self->client->get( $url )->res->json;
+                               warn "# replicated $url ", dump($all);
+                               foreach my $e ( @$all ) {
+                                       delete $e->{_id}; # sanitize data from older implementation
+                                       _couchdb_put( "/$database/$entity." . $e->{'$id'} => $e );
+                               }
                        }
                }
+               _render_jsonp( $self,  $got );
        }
 };