root/trunk/tools/upgrade

Revision 4233, 3.2 kB (checked in by asawada, 3 months ago)

Apply theme after new install from tools/upgrade. bugzid:102171.

  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl -w
2
3# Movable Type (r) Open Source (C) 2001-2009 Six Apart, Ltd.
4# This program is distributed under the terms of the
5# GNU General Public License, version 2.
6#
7# $Id$
8
9package MT::Tool::Upgrade;
10use strict;
11use utf8;
12
13use lib  qw( extlib lib );
14use base qw( MT::Tool );
15
16use Carp qw(confess);
17use MT::Upgrade;
18
19sub usage { '[--dryrun] [--sql] [--name <name>]' }
20
21sub help {
22    return q{
23        Installs or upgrades a database to the current MT schema.
24
25        --dryrun         Determine the upgrade steps required without
26                         executing any changes.
27        --sql            Report the SQL that would be performed instead
28                         of executing it.
29        --name <name>    The author as whom to perform the upgrade steps.
30                         Required when performing an upgrade (not at
31                         initial install).
32    };
33}
34
35my ($dryrun, $name, $sqlonly);
36
37sub options {
38    return (
39        'dryrun!' => \$dryrun,
40        'sql!'    => \$sqlonly,
41        'name=s'  => \$name,
42    );
43}
44
45
46sub main {
47    my $class = shift;
48    my ($verbose) = $class->SUPER::main(@_);
49
50    if ($sqlonly) {
51        $dryrun = 1;
52        MT->add_callback('MT::Upgrade::SQL', 1, undef, \&sql_cb);
53    }
54    else {
55        print "upgrade -- A command line tool for upgrading the schema for Movable Type.\n";
56        print "(Non-destructive mode)\n" if $dryrun;
57    }
58
59    my $install;
60    my $driver = MT::Object->driver;
61    if (!$driver || !$driver->table_exists('MT::Author')) {
62        $install = 1;
63    }
64
65    unless ($install || $name) {
66        print "Please set username to set superuser at upgrading.  cf: upgrade --name Melody\n";
67        exit;
68    }
69
70    my $author_id;
71    if (!$install && $name) {
72        require MT::BasicAuthor;
73        my $a = MT::BasicAuthor->load({name => $name})
74            or die "Not found user $name:" . MT::BasicAuthor->errstr;
75        $author_id = $a->id;
76    }
77
78    if ( $install ) {
79        $MT::Upgrade::Installing = 1;
80    }
81
82    local $SIG{__WARN__} = sub { __PACKAGE__->trace( $_[0] ) };
83
84    my $updated = MT::Upgrade->do_upgrade(
85        App       => __PACKAGE__, 
86        DryRun    => $dryrun,
87        Install   => $install,
88        SuperUser => $author_id,
89        CLI       => 1,
90        User      => { user_nickname => 'Melody Nelson' },
91    );
92
93    if ($install) {
94        my $blog = MT->model('blog')->load(1);
95        $blog->theme_id('classic_website');
96        $blog->save;
97        $blog->apply_theme;
98        print "Installation complete.\n";
99    } else {
100        print "Upgrade complete!\n" if !$dryrun && $updated;
101        print "Your schema is up to date already.\n" if defined $updated && !$updated;
102    }
103}
104
105sub progress {
106    my $pkg = shift;
107    my $msg = shift;
108    print "\t* " . Encode::encode( MT->config->PublishCharset || 'UTF-8', $msg ) . "\n" unless $sqlonly;
109}
110
111sub error {
112    my $pkg = shift;
113    my $err = shift;
114    confess Encode::encode( MT->config->PublishCharset || 'UTF-8', $err );
115}
116
117sub sql_cb {
118    my $cb = shift;
119    my ($upgrade, $stmt) = @_;
120    print "$stmt\n";
121}
122
123sub trace {
124    my $pkg = shift;
125    print "[warn] >> \t" . Encode::encode( MT->config->PublishCharset || 'UTF-8', $_[0] ) . "\n"; 
126}
127
128__PACKAGE__->main() unless caller;
129
1301;
131
Note: See TracBrowser for help on using the browser.