1 package Thrasher
::Backend
::Migrate
;
8 our @EXPORT_OK = qw(migrate migrate_from_spec);
13 sub migrate_from_spec
{
14 my $source_backend = shift;
15 my $source_backend_specs = shift;
16 my $dest_backend = shift;
17 my $dest_backend_specs = shift;
21 $source_backend = "Thrasher::Backend::$source_backend";
22 $dest_backend = "Thrasher::Backend::$dest_backend";
26 eval "use $source_backend;";
29 eval "use $dest_backend;";
33 my $source = $source_backend->new($source_backend_specs);
34 my $dest = $dest_backend->new($dest_backend_specs);
36 migrate
($source, $dest, @args);
44 my $dry_run = $args{dry_run
};
46 print "Preparing to migrate backend data...\n";
48 if (! $args{'protocol_module'}) {
49 die('No protocol_module to register; cannot get registration_items!');
51 eval("require $args{'protocol_module'};")
53 my $protocol = $args{'protocol_module'}->new({}, $dest);
54 $dest->register_protocol($protocol);
56 my $source_jids = $source->all_jids;
58 for my $jid (@
$source_jids) {
59 print "Migrating $jid... ";
62 # Migrate registration
63 my $registration = $source->registered($jid);
66 print "Would register $jid with: "
67 . Dumper
($registration);
69 $dest->register($jid, $registration);
73 # Migrate the mappings
74 my $mappings = $source->all_mappings($jid);
76 print "Got mappings to migrate: " . Dumper
($mappings);
78 while (my ($legacy, $mapped_jid) = each %$mappings) {
79 # The source transport may have a different
80 # canonical form for public IM usernames. This may
81 # cause Thrasher to think $legacy was not already
82 # mapped and create a duplicate mapping (e.g.
83 # optional spaces for AIM).
84 $legacy = $protocol->process_remote_username($legacy);
86 $dest->store_username_mapping($jid, $legacy, $mapped_jid);
91 my $roster = $source->get_roster($jid);
93 print "Got roster to migrate: " . Dumper
($roster);
95 $dest->set_roster($jid, $roster);
98 # Migrate misc, if any
102 my $all_misc = $source->all_misc($jid);
104 print "Got misc to migrate: "
107 while (my ($key, $value) = each %$all_misc) {
108 $dest->set_misc($jid, $key, $value);
112 # "If this errored for some reason other than
113 # one end or the other not supporting misc,
114 # propogate the error, otherwise eat it."
115 if ($@
&& $@
!~ /not implemented/) {
120 # Migrate the avatars.
121 my $avatars = $source->all_avatars($jid);
123 print "Got avatars to migrate: " . Dumper
(sort keys
126 while (my ($legacy, $avatar) = each %$avatars) {
127 $dest->set_avatar($jid, $legacy, $avatar);
133 warn "While trying to migrate $jid, got error: $@";