[MTOS-dev] Command-line rebuilds for MT 4.1?

Hirotaka Ogawa hirotaka.ogawa at gmail.com
Tue May 6 17:23:53 PDT 2008


Dan,

I can rewrite your code much simpler as like:

#!/usr/bin/perl

use strict;
use lib $ENV{MT_HOME} ? "$ENV{MT_HOME}/lib" : 'lib';
use MT::Bootstrap;

package TestBuilder;
use base qw( MT::Tool );

sub main {
    my $class = shift;
    my $app = $class->set_up_app();

    require MT::Blog;
    my $iter = MT::Blog->load_iter;
    while ( my $blog = $iter->() ) {
        print "Rebuilding blog " . $blog->id . "...\n";
        $app->rebuild( BlogID => $blog->id )
            or die "Rebuild error: " . $app->publish_error();
    }
}

__PACKAGE__->main() unless caller;

1;


On Wed, May 7, 2008 at 8:41 AM, Dan Sanderson <contact at dansanderson.com> wrote:
> Hi all -
>
> I'm trying to put together a command-line rebuild tool that works with MT
> 4.1.  I've seen Tim's mt-rebuild and other build-related extensions, but so
> far I haven't gotten the bootstrap code correct yet.  I'm now using Mark's
> MT::Tool (from SVN head), but so far it hasn't changed the equation.
>
> If someone already has a command-line rebuilder that works with MT 4.1, I'd
> like to see it, but I'd still be interested in sussing this out for future
> reference.
>
> What I have so far, based on mt-rebuild and MT::Tool:
>
>
> #!/usr/bin/perl -w
> use strict;
>
> my ($MT_DIR);
> BEGIN {
>     # TODO: hard-coded MT_DIR for now
>     $MT_DIR = "../../dansanderson.com/blog/mt/";
>
>     unshift @INC, $MT_DIR . 'lib';
>     unshift @INC, $MT_DIR . 'extlib';
> }
>
> use lib  qw( extlib lib );
> use base qw( MT::Tool );
> use MT;
>
> # TODO: borrowing this from MT::Tool so I can pass a Config param.
> sub set_up_app {
>     require MT;
>     my $mt = MT->new( Config    => $MT_DIR . 'mt-config.cgi',
>       Directory => $MT_DIR ) or die MT->errstr;
>
>     $mt->{vtbl} = { };
>     $mt->{is_admin} = 0;
>      $mt->{template_dir} = 'cms';
>     $mt->{user_class} = 'MT::Author';
>     $mt->{plugin_template_path} = 'tmpl';
>     $mt->run_callbacks('init_app', $mt);
>
>     return $mt;
> }
>
> sub main {
>     my $class = shift;
>     my ($verbose) = $class->SUPER::main(@_);
>
>     my $mt = MT->new( Config    => $MT_DIR . 'mt-config.cgi',
>       Directory => $MT_DIR )
>  || die MT->errstr;
>
>     require MT::Blog;
>     my $iter = MT::Blog->load_iter;
>     while ( my $blog = $iter->() ) {
>  print "Rebuilding blog " . $blog->id . "...\n";
>  $mt->rebuild( BlogID => $blog->id )
>     or die "Rebuild error: " . $mt->publish_error();
>     }
> }
>
> __PACKAGE__->main() unless caller;
>
> 1;
>
> With my current blog, which is a reasonably fresh install of MT 4.1 (and 10
> years of legacy data, woohoo):
>
> * Warning: "Odd number of elements in anonymous hash at [...]/MT/Blog.pm..."
> referring to set_defaults(), $blog->set_values_internal({...}).  This is
> caused by MT->config('DefaultLanguage') not returning a value, which messes
> up the whole hash.  (I've been away from Perl enough to have been surprised
> by this. :) )  Adding "DefaultLanguage en_US" to my config file fixes this,
> but obviously this should not be necessary.
>
> * Warning: "Use of uninitialized value in hash element at
> [...]/MT/Serialize.pm line 20", referring to new(), $_[0] being undefined.
>
> * Warning: "Use of uninitialized value in subroutine entry at
> [...]/MT/Serialize.pm line 40", referring to unserialize(),
> $ser->{thaw}->(@_).
>
> * Error: "Can't call method "new" on an undefined value at [...]/MT.pm lin
> 442", referring to log(), $log_class->new(), where $log_class =
> $mt->model('log').
>
> My apologies that I haven't given this the full debugger treatment yet to
> get real stack traces, I'll do that if necessary (as time allows).  Any
> hints come to mind from the above?  Anything obvious missing from my script?
>
> And FWIW, yes rebuilding from the web interface works fine, except for the
> inability to rebuild 4000 pages without tripping on server errors every few
> hundred pages.  (I haven't gotten MT-Hacks' SmartRebuild working yet either,
> but one thing at a time.)
>
> Thanks!
> -- Dan
>
>
> _______________________________________________
>  MTOS-dev mailing list
>  MTOS-dev at sixapart.com
>  http://www.sixapart.com/mailman/listinfo/mtos-dev
>
>



-- 
Hirotaka Ogawa
http://twitter.com/ogawa
http://as-is.net/blog/


More information about the MTOS-dev mailing list