Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run MT::Worker::Publish specify the file path or template_id.
#!/usr/bin/perl
package MT::Tool::RebuildFile;
use strict;
use warnings;
use File::Spec;
use FindBin;
use lib map File::Spec->catdir( $FindBin::Bin, File::Spec->updir, $_ ), qw/lib extlib/;
use base qw( MT::Tool );
use MT::Util qw( log_time );
sub usage { '--file /path/to/file or or --template_id n' }
sub help {
return q {
Run MT::Worker::Publish specify the file path or template_id.
--file /path/to/file or --template_id n
};
}
my ( $debug, $file, $template_id );
sub options {
return (
'file=s' => \$file,
'template_id=i' => \$template_id,
);
}
sub main {
my $class = shift;
my ( $verbose ) = $class->SUPER::main( @_ );
my $app = MT->instance;
if ( (! $file ) && (! $template_id ) ) {
return;
}
my @ids;
if ( $template_id ) {
@ids = split( /\s*,\s*/, $template_id );
} else {
@ids = split( /\s*,\s*/, $file );
}
require MT::FileInfo;
require MT::TheSchwartz::FuncMap;
require MT::TheSchwartz::Job;
require MT::FileInfo;
require MT::WeblogPublisher;
my $funcmap = MT::TheSchwartz::FuncMap->load( { funcname => 'MT::Worker::Publish' } );
return unless $funcmap;
my @fis;
if ( $file ) {
@fis = MT::FileInfo->load( { file_path => \@ids } );
} else {
@fis = MT::FileInfo->load( { template_id => \@ids } );
}
for my $fi( @fis ) {
my @jobs = MT::TheSchwartz::Job->load( { funcid => $funcmap->funcid,
uniqkey => $fi->id } );
if (! scalar @jobs ) {
next;
}
my $res = MT->instance->publisher->rebuild_from_fileinfo( $fi );
if ( defined $res ) {
$app->log(
{ ( $fi->blog_id ? ( blog_id => $fi->blog_id ) : () ),
message => $app->translate('Background Publishing Done'),
metadata => log_time() . ' '
. $app->translate( 'Published: [_1]', $fi->file_path ),
category => "publish",
level => MT::Log::INFO(),
}
);
for my $job( @jobs ) {
$job->remove or die $job->errstr;
}
}
}
1;
}
__PACKAGE__->main() unless caller;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment