root/branches/release-40/tools/upgrade @ 2570

Revision 2570, 2.8 kB (checked in by fumiakiy, 18 months ago)

Set default nickname for the new user. BugId:80084

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