File: WidgetManager.pl

package info (click to toggle)
movabletype-opensource 4.2.3-1%2Blenny3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 21,268 kB
  • ctags: 15,862
  • sloc: perl: 178,892; php: 26,178; sh: 161; makefile: 82
file content (103 lines) | stat: -rwxr-xr-x 3,389 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Movable Type (r) Open Source (C) 2005-2008 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id: WidgetManager.pl 2123 2008-04-28 03:06:13Z fumiakiy $

# WidgetManager plugin for Movable Type
# Author: Byrne Reese, Six Apart (http://www.sixapart.com)
# Released under the Artistic and GPLv2 License

package MT::Plugin::WidgetManager;

use strict;

use base qw( MT::Plugin );
use constant DEBUG => 0;
use MT::Template;
use MT::Util qw( escape_unicode );
use MT::I18N qw( encode_text );

our $VERSION = '1.1';

my $plugin = MT::Plugin::WidgetManager->new({
    id             => 'WidgetManager',
    name           => 'Widget Manager Upgrade Assistant',
    description    => q(<MT_TRANS phrase="Widget Manager version 1.1; This version of the plugin is to upgrade data from older version of Widget Manager that has been shipped with Movable Type to the Movable Type core schema.  No other features are included.  You can safely remove this plugin after installing/upgrading Movable Type.">),
    version        => $VERSION,
    schema_version => $VERSION,
    author_name    => 'Six Apart, Ltd.',
    key            => 'widget-manager',
    l10n_class     => 'WidgetManager::L10N',
});
MT->add_plugin($plugin);

sub instance { $plugin; }

sub init_registry { 
    my $plugin = shift;
    $plugin->registry({
        upgrade_functions => {
            'upgrade_widgetmanagers_nv' => {
                # this is to workaround absence of PluginSchemaVersion
                code => \&upgrade_widgetmanagers,
            },
            'upgrade_widgetmanagers' => {
                version_limit => 1.1,
                code => \&upgrade_widgetmanagers,
            }
        },
    });
    return 1;
}

sub _disable_widgetmanager { 
    my $switch = MT->config('PluginSwitch') || {}; 
    $switch->{$plugin->{plugin_sig}} = 0; 
    MT->config('PluginSwitch', $switch, 1); 
    MT->config->save_config(); 
} 

sub _translate_escape { 
    my $trans = $plugin->translate(@_); 
    return $trans if $MT::Upgrade::CLI; 
    $trans = MT::I18N::encode_text($trans, undef, 'utf-8'); 
    return MT::Util::escape_unicode($trans); 
} 

sub upgrade_widgetmanagers { 
    my $upg = shift; 

    require MT::PluginData;
    my $iter = MT::PluginData->load_iter(
        { plugin => $plugin->key }
    );
    while ( my $pd = $iter->() ) {
        next unless $plugin->key eq $pd->plugin;
        my ( $blog_id ) = $pd->key =~ /configuration:blog:(\d+)/;
        next unless $blog_id;
        my $config = $pd->data;
        next unless $config;
        my $modulesets = $config->{modulesets};
        next unless $modulesets;
        foreach my $mod_key ( keys %$modulesets ) {
            $upg->progress(_translate_escape('Moving storage of Widget Manager [_1]...', $mod_key));
            my $tmpl_ids = $modulesets->{$mod_key};
            my $tmpl = MT::Template->new;
            $tmpl->blog_id($blog_id);
            $tmpl->name($mod_key);
            $tmpl->type('widgetset');
            $tmpl->build_dynamic(0);
            $tmpl->rebuild_me(0);
            $tmpl->modulesets($tmpl_ids);
            $tmpl->save_widgetset
                or $upg->progress(_translate_escape('Failed.')), next;
            $upg->progress(_translate_escape('Done.'));
        }
        $pd->remove;
    }
    _disable_widgetmanager;
}

1;
__END__