App-SD

 view release on metacpan or  search on metacpan

lib/App/SD/ForeignReplica.pm  view on Meta::CPAN

    lazy    => 1,
    isa     => 'Str',
    is      => 'ro',
    default => sub {
        my $self = shift;
        $self->uuid_for_url( $self->_uuid_url );
    }
);

=head2 save_username_and_token( $username, $token )

Saves the given username and token to the replica-specific config file,
so the user doesn't have to enter it every time.

=cut

sub save_username_and_token {
    my ($self, $username, $password) = @_;

    # make sure replica is initialized, since this method is generally called
    # in the BUILD method of an object, which makes it end up being called
    # before the initialize call in clone
    $self->app_handle->handle->after_initialize( sub { shift->app_handle->set_db_defaults } );
    $self->app_handle->handle->initialize;

    my $replica_username_key = 'replica.' . $self->scheme . ":" . $self->{url} . '.username';
    my $replica_token_key    = 'replica.' . $self->scheme . ":" . $self->{url} . '.secret_token';

    if ( !$self->app_handle->config->get( key => $replica_username_key ) ) {
        print "Setting replica's username and token in the config file";
        $self->app_handle->config->group_set(
            $self->app_handle->config->replica_config_file,
         [ {
            key      => $replica_username_key,
            value    => $username,
         }, {
            key      => $replica_token_key,
            value    => $password,
         } ],
        );
    }
}


sub integrate_changeset {
    my $self = shift;
    my %args = validate(
        @_,
        {   changeset          => { isa      => 'Prophet::ChangeSet' },
            resolver           => { optional => 1 },
            resolver_class     => { optional => 1 },
            resdb              => { optional => 1 },
            conflict_callback  => { optional => 1 },
            reporting_callback => { optional => 1 }
        }
    );

    my $changeset = $args{'changeset'};
    return if $self->last_changeset_from_source(
        $changeset->original_source_uuid) >= $changeset->original_sequence_no;
    $self->SUPER::integrate_changeset(%args);
}

=head2 integrate_change $change $changeset

Given a change (and the changeset it's part of), this routine will load
the push encoder for the foreign replica's type and call integrate_change
on it.

To avoid publishing prophet-private data, It skips any change with a record type
that record_type starts with '__'.

This is probably a bug.

=cut

sub integrate_change {
    my $self = shift;
    my ( $change, $changeset ) = validate_pos(
        @_,
        { isa => 'Prophet::Change' },
        { isa => 'Prophet::ChangeSet' },
    );

    # don't push internal records
    return if $change->record_type =~ /^__/;


    Prophet::App->require( $self->push_encoder());
    my $recoder = $self->push_encoder->new( { sync_source => $self } );
    $recoder->integrate_change($change,$changeset);
}

=head2 record_pushed_transactions

Walk the set of transactions on the ticket whose id you've passed in, looking
for updates by the 'current user' which happened after start_time and before
now. Then mark those transactions as ones that originated in SD, so we don't
accidentally push them later.

=over

=item ticket

=item changeset

=item start_time

=back

=cut

sub record_pushed_transactions {
    my $self = shift;
    my %args = validate( @_,
        { ticket => 1,
          changeset => { isa => 'Prophet::ChangeSet' }, start_time => 1} );

    my $earliest_valid_txn_date;

    # walk through every transaction on the ticket, starting with the latest



( run in 0.750 second using v1.01-cache-2.11-cpan-5a3173703d6 )