Skip to content

Instantly share code, notes, and snippets.

@sinkovsky
Created October 15, 2009 22:08
Show Gist options
  • Save sinkovsky/211335 to your computer and use it in GitHub Desktop.
Save sinkovsky/211335 to your computer and use it in GitHub Desktop.
MT::App::CMS->add_callback('CMSPreSave_entry', 9, $plugin, sub {
my ($eh, $app, $entry) = @_;
my $q = $app->{'query'};
# Only AP entries from Wires blog here
return 1 unless $entry->blog_id == 18;
return 1 unless $entry->author->name eq 'AP';
my $extra = huff::EntryExtra->load($entry->id);
return 1 if $extra->ap_edited;
## $entry has updated title already, right, in PreSave handler
$old_entry = MT::Entry->load($entry->id);
if ( $entry->title ne $old_entry->title ) {
my $old_permalink = $entry->permalink;
my $blog_root = $entry->blog->site_path();
my ($filename) = $old_permalink =~ m{wires/(.+)$};
my $filepath = $blog_root."/".$filename;
if ( -s $filepath ) {
open my $fp, ">", $filepath;
my $redirect_url = $entry->blog->site_url."/_".$entry->id.".html";
print $fp qq{<?php header("Location: $redirect_url"); ?>};
close $fp;
}
$entry->basename("");
}
# Changing author
#
my $user = $app->user;
$q->{author_id_change} = [ $user->id ];
## Storing edited flag
$extra->ap_edited(1);
$extra->save;
1;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment