root/branches/release-26/tools/upgrade @ 1174

Revision 1174, 1.9 kB (checked in by bchoate, 23 months ago)

Updated copyright year for source.

  • 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
9use strict;
10
11use Getopt::Long;
12use Carp qw(confess);
13GetOptions("dryrun", \my($dryrun), "name:s", \my($name), "sql", \my($sqlonly));
14
15use lib 'extlib';
16use lib 'lib';
17
18use MT;
19use MT::Upgrade;
20
21my $mt = new MT(Config => 'mt.cfg') or die MT->errstr;
22
23MT->add_callback('MT::Upgrade::SQL', 1, undef, \&sql_cb) if $sqlonly;
24
25$dryrun = 1 if $sqlonly;
26
27if (!$sqlonly) {
28    print "upgrade -- A command line tool for upgrading the schema for Movable Type.\n";
29    print "(Non-destructive mode)\n" if $dryrun;
30}
31
32my $install;
33my $driver = MT::Object->driver;
34if (!$driver || !$driver->table_exists('MT::Author')) {
35    $install = 1;
36}
37
38unless ($install || $name) {
39    print "Please set username to set superuser at upgrading.  cf: upgrade --name Melody\n";
40    exit;
41}
42
43my $author_id;
44if (!$install && $name) {
45   require MT::BasicAuthor;
46   my $a = MT::BasicAuthor->load({name => $name});
47   die "Not found user $name:" . MT::BasicAuthor->errstr if !$a;
48   $author_id = $a->id || 0;
49}
50
51my $updated = MT::Upgrade->do_upgrade(App => 'main', 
52                                      DryRun => $dryrun,
53                                      Install => $install,
54                                      SuperUser => $author_id,
55                                      CLI => 1,
56                                      );
57
58if ($install) {
59    print "Installation complete.\n";
60} else {
61    print "Upgrade complete!\n" if !$dryrun && $updated;
62    print "Your schema is up to date already.\n" if defined $updated && !$updated;
63}
64
65sub progress {
66    my $pkg = shift;
67    my $msg = shift;
68    print "\t* " . $msg . "\n" unless $sqlonly;
69}
70sub error {
71    my $pkg = shift;
72    my $err = shift;
73    confess $err;
74}
75sub sql_cb {
76    my $cb = shift;
77    my ($upgrade, $stmt) = @_;
78    print "$stmt\n";
79}
Note: See TracBrowser for help on using the browser.