root/trunk/BackupRestoreSample/BackupRestoreSample.pl

Revision 696, 1.9 kB (checked in by mpaschal, 6 months ago)

Move BackupRestoreSample? plugin from mt extras to mtplugins repo

Line 
1 # Movable Type (r) Open Source (C) 2005-2008 Six Apart, Ltd.
2 # This program is distributed under the terms of the
3 # GNU General Public License, version 2.
4 #
5 # $Id: BackupRestoreSample.pl 1174 2008-01-08 21:02:50Z bchoate $
6
7 package MT::Plugin::BackupRestoreSample;
8
9 use strict;
10 use base 'MT::Plugin';
11 use vars qw($VERSION);
12 $VERSION = '0.1';
13
14 use BackupRestoreSample::Object;
15
16 my $plugin;
17 my $ns = 'urn:sixapart.com:ns:pluginsample';
18 $plugin = MT::Plugin::BackupRestoreSample->new({
19     name => "BackupRestoreSample",
20     version => $VERSION,
21     description => "<MT_TRANS phrase=\"This plugin is to test out the backup restore callback.\">",
22     author_name => "Fumiaki Yoshimatsu",
23     author_link => "http://www.sixapart.com/",
24     #l10n_class => 'BackupRestore::L10N',
25     object_classes => [
26         'BackupRestoreSample::Object'
27     ],
28     schema_version => '0.1',
29 });
30 MT->add_plugin($plugin);
31 MT->add_callback('Backup', 9, $plugin, \&backup);
32 MT->add_callback("Restore.backup_restore_sample_object:$ns", 9, $plugin, \&restore);
33
34 sub backup {
35     my ($cb, $blog_ids, $progress) = @_;
36     my $xml;
37     my $terms = {};
38     $terms->{blog_id} = $blog_ids if defined($blog_ids) && (0 < scalar(@$blog_ids));
39     my @objects = BackupRestoreSample::Object->load($terms);
40     for my $object (@objects) {
41         $xml .= $object->to_xml($ns);
42     }
43     $progress->('BackupRestoreSampleObject is backed up.', 'BackupRestoreSample::Object');
44     return $xml;
45 }
46
47 sub restore {
48     my ($cb, $data, $objects, $deferred, $progress) = @_;
49     return 0 if $ns ne $data->{NamespaceURI};
50    
51     my $attrs = $data->{Attributes};
52     my %column_data = map { $attrs->{$_}->{LocalName} => $attrs->{$_}->{Value} }
53         grep { $attrs->{$_}->{Value} ne $ns } keys(%$attrs);
54     my $obj = BackupRestoreSample::Object->new;
55     $obj->set_values(\%column_data);
56     $progress->('BackupRestoreSampleObject is restored.', 'BackupRestoreSample::Object');
57     return $obj;
58 }
59
60 1;
Note: See TracBrowser for help on using the browser.