root/branches/release-36/plugins/WidgetManager/WidgetManager.pl @ 2052

Revision 2052, 3.3 kB (checked in by fumiakiy, 19 months ago)

Integrated Widget Manager to the core. BugId:68750

Now a widgetset is another type of template. The widgets contained in a widgetset is stored in a meta field.

  • Property svn:executable set to *
  • Property svn:keywords set to Id Revision
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$
6
7# WidgetManager plugin for Movable Type
8# Author: Byrne Reese, Six Apart (http://www.sixapart.com)
9# Released under the Artistic and GPLv2 License
10
11package MT::Plugin::WidgetManager;
12
13use strict;
14
15use base qw( MT::Plugin );
16use constant DEBUG => 0;
17use MT::Template;
18use MT::Util qw( escape_unicode );
19use MT::I18N qw( encode_text );
20
21our $VERSION = '1.1';
22
23my $plugin = MT::Plugin::WidgetManager->new({
24    id             => 'WidgetManager',
25    name           => 'Widget Manager Upgrade Assistant',
26    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.\">),
27    version        => $VERSION,
28    schema_version => $VERSION,
29    author_name    => 'Six Apart, Ltd.',
30    key            => 'widget-manager',
31    l10n_class     => 'WidgetManager::L10N',
32});
33MT->add_plugin($plugin);
34
35sub instance { $plugin; }
36
37sub init_registry { 
38    my $plugin = shift;
39    $plugin->registry({
40        upgrade_functions => {
41            'upgrade_widgetmanagers_nv' => {
42                # this is to workaround absence of PluginSchemaVersion
43                code => \&upgrade_widgetmanagers,
44            },
45            'upgrade_widgetmanagers' => {
46                version_limit => 1.1,
47                code => \&upgrade_widgetmanagers,
48            }
49        },
50    });
51    return 1;
52}
53
54sub _disable_widgetmanager { 
55    my $switch = MT->config('PluginSwitch') || {}; 
56    $switch->{$plugin->{plugin_sig}} = 0; 
57    MT->config('PluginSwitch', $switch, 1); 
58    MT->config->save_config(); 
59} 
60
61sub _translate_escape { 
62    my $trans = $plugin->translate(@_); 
63    return $trans if $MT::Upgrade::CLI; 
64    $trans = MT::I18N::encode_text($trans, undef, 'utf-8'); 
65    return MT::Util::escape_unicode($trans); 
66} 
67
68sub upgrade_widgetmanagers { 
69    my $upg = shift; 
70
71    require MT::PluginData;
72    my $iter = MT::PluginData->load_iter(
73        { plugin => $plugin->key }
74    );
75    while ( my $pd = $iter->() ) {
76        next unless $plugin->key eq $pd->plugin;
77        my ( $blog_id ) = $pd->key =~ /configuration:blog:(\d+)/;
78        next unless $blog_id;
79        my $config = $pd->data;
80        next unless $config;
81        my $modulesets = $config->{modulesets};
82        next unless $modulesets;
83        foreach my $mod_key ( keys %$modulesets ) {
84            $upg->progress(_translate_escape('Moving storage of Widget Manager [_1]...', $mod_key));
85            my $tmpl_ids = $modulesets->{$mod_key};
86            my $tmpl = MT::Template->new;
87            $tmpl->blog_id($blog_id);
88            $tmpl->name($mod_key);
89            $tmpl->type('widgetset');
90            $tmpl->build_dynamic(0);
91            $tmpl->rebuild_me(0);
92            $tmpl->modulesets($tmpl_ids);
93            $tmpl->save_widgetset
94                or $upg->progress(_translate_escape('Failed.')), next;
95            $upg->progress(_translate_escape('Done.'));
96        }
97        $pd->remove;
98    }
99    _disable_widgetmanager;
100}
101
1021;
103__END__
Note: See TracBrowser for help on using the browser.