1package Prophet::CLI::MirrorCommand;
2{
3  $Prophet::CLI::MirrorCommand::VERSION = '0.751';
4}
5use Any::Moose 'Role';
6with 'Prophet::CLI::ProgressBar';
7use Params::Validate ':all';
8
9sub get_cache_for_source {
10    my $self = shift;
11    my ($source) = validate_pos( @_, { isa => 'Prophet::Replica' } );
12    my $target = Prophet::Replica->get_handle(
13        url        => 'prophet_cache:' . $source->uuid,
14        app_handle => $self->app_handle
15    );
16
17    if ( !$target->replica_exists && !$target->can_initialize ) {
18        die "The target replica path you specified can't be created.\n";
19    }
20
21    $target->initialize_from_source($source);
22    return $target;
23}
24
25sub sync_cache_from_source {
26    my $self = shift;
27    my %args = validate(
28        @_,
29        {
30            target => { isa => 'Prophet::Replica::prophet_cache' },
31            source => { isa => 'Prophet::Replica' }
32        }
33    );
34
35    if ( $args{target}->latest_sequence_no ==
36        $args{source}->latest_sequence_no )
37    {
38        print "Mirror of " . $args{source}->url . " is already up to date\n";
39        return;
40    }
41
42    print "Mirroring resolutions from " . $args{source}->url . "\n";
43    $args{target}->resolution_db_handle->mirror_from(
44        source             => $args{source}->resolution_db_handle,
45        reporting_callback => $self->progress_bar(
46            max =>
47              ( $args{source}->resolution_db_handle->latest_sequence_no || 0 )
48        )
49    );
50    print "\nMirroring changesets from " . $args{source}->url . "\n";
51    $args{target}->mirror_from(
52        source             => $args{source},
53        reporting_callback => $self->progress_bar(
54            max => ( $args{source}->latest_sequence_no || 0 )
55        )
56    );
57}
58
59no Any::Moose 'Role';
60
611;
62
63__END__
64
65=pod
66
67=head1 NAME
68
69Prophet::CLI::MirrorCommand
70
71=head1 VERSION
72
73version 0.751
74
75=head1 AUTHORS
76
77=over 4
78
79=item *
80
81Jesse Vincent <jesse@bestpractical.com>
82
83=item *
84
85Chia-Liang Kao <clkao@bestpractical.com>
86
87=item *
88
89Christine Spang <christine@spang.cc>
90
91=back
92
93=head1 COPYRIGHT AND LICENSE
94
95This software is Copyright (c) 2009 by Best Practical Solutions.
96
97This is free software, licensed under:
98
99  The MIT (X11) License
100
101=head1 BUGS AND LIMITATIONS
102
103You can make new bug reports, and view existing ones, through the
104web interface at L<https://rt.cpan.org/Public/Dist/Display.html?Name=Prophet>.
105
106=head1 CONTRIBUTORS
107
108=over 4
109
110=item *
111
112Alex Vandiver <alexmv@bestpractical.com>
113
114=item *
115
116Casey West <casey@geeknest.com>
117
118=item *
119
120Cyril Brulebois <kibi@debian.org>
121
122=item *
123
124Florian Ragwitz <rafl@debian.org>
125
126=item *
127
128Ioan Rogers <ioanr@cpan.org>
129
130=item *
131
132Jonas Smedegaard <dr@jones.dk>
133
134=item *
135
136Kevin Falcone <falcone@bestpractical.com>
137
138=item *
139
140Lance Wicks <lw@judocoach.com>
141
142=item *
143
144Nelson Elhage <nelhage@mit.edu>
145
146=item *
147
148Pedro Melo <melo@simplicidade.org>
149
150=item *
151
152Rob Hoelz <rob@hoelz.ro>
153
154=item *
155
156Ruslan Zakirov <ruz@bestpractical.com>
157
158=item *
159
160Shawn M Moore <sartak@bestpractical.com>
161
162=item *
163
164Simon Wistow <simon@thegestalt.org>
165
166=item *
167
168Stephane Alnet <stephane@shimaore.net>
169
170=item *
171
172Unknown user <nobody@localhost>
173
174=item *
175
176Yanick Champoux <yanick@babyl.dyndns.org>
177
178=item *
179
180franck cuny <franck@lumberjaph.net>
181
182=item *
183
184robertkrimen <robertkrimen@gmail.com>
185
186=item *
187
188sunnavy <sunnavy@bestpractical.com>
189
190=back
191
192=cut
193