Save & Rebuild

This hack is for versions of Movable Type prior to 3.2. This hack has been implemented into Movable Type 3.2
save_and_rebuild.png

I'm a lazy person and hate having to click repetitively to do tasks and I get easily annoyed at having to keep hitting save and then rebuild whilst making changes to my site. So a hack later I have a Save & Rebuild button which will first save the template and then rebuild it with just one click!

Open lib/MT/App/CMS.pm and around line 1149 find

sub save_object{
and add underneath it
my $sr = 0;
Next on line 1340 find
$obj->text($text);
and add underneath it
if($q->param('sr')){
$sr = 1;
$app->rebuild_indexes( BlogID => $obj->blog_id, Template => $obj,
Force => 1 )
or return;
}

Next find

$obj->rebuild_me : 1;
and add right underneath it
$param{sr} = 1 if($q->param('sr')) ;
Finally around line 1500 find
} else {
return $app->redirect($app->uri .
'?__mode=view&_type=' . $type . '&id=' . $obj->id .
'&blog_id=' . $blog_id . '&saved=1');
}
}
sub list_objects {

and replace it with

} else {
if($sr == 1){
return $app->redirect($app->uri .
'?__mode=view&_type=' . $type . '&id=' . $obj->id .
'&blog_id=' . $blog_id . '&sr=1');
$sr = 0;
} else {
return $app->redirect($app->uri .
'?__mode=view&_type=' . $type . '&id=' . $obj->id .
'&blog_id=' . $blog_id . '&saved=1');
}
}
}
sub list_objects {

Save CMS.pm and open tmpl/cms/edit_template.tmpl and find

<form method="post" action="<TMPL_VAR NAME=SCRIPT_URL>">

and add right above it

<TMPL_IF NAME=SR>
<div class="message">
<MT_TRANS phrase="Your template changes have been saved and your template has been rebuilt.">
</div></TMPL_IF>

Finally, right at the bottom of the file

<input type="button" onclick="doRebuildOne(<TMPL_VAR NAME=ID>)" value="<MT_TRANS phrase="Rebuild">" />

and add underneath it

<input type="submit" name="sr" value="<MT_TRANS phrase="Save & Rebuild">" />

Save edit_template.tmpl and upload the files to the appropriate places and you should find a Save & Rebuild button on your edit template page. When you hit this button, it will save and rebuild your template. Once you are returned to the edit template page, it will still show the "Your template has been saved, Rebuild This Template" message, however your template will have been rebuilt. When the template is successfully rebuilt, you will have a message to reflect this success "Your template changes have been saved and your template has been rebuilt."

18 Comments

quack said:
on Feb 7, 2005 4:48 AM | Reply

It's not working for me. I added the code where you said, but when I click on the new button it seems to just reload the template instead of saving what I entered.

Arvind Satyanarayan said:
on Feb 7, 2005 12:56 PM | Reply

Right it should work now. Was a silly mistake!

quack said:
on Feb 7, 2005 1:15 PM | Reply

Thanks for fixing it Arvind, it's working great now; and as you can see I posted a link on my blog.

Arvind Satyanarayan said:
on Feb 7, 2005 5:55 PM | Reply

Fixed the message issue too.

quack said:
on Feb 7, 2005 9:14 PM | Reply

Yup, all works for me now. Glad you got to the bottom of the problems!

Beth said:
on Feb 8, 2005 5:40 AM | Reply

Haha, I am always impressed by your ability to rectify the little annoyances, perhaps even before we even realize how annoying they really are :P

quack said:
on Feb 8, 2005 2:26 PM | Reply

This is such a simple hack, and so useful, I hope Six Apart take note and include it in a future release. It certainly makes sense!

Eli said:
on Feb 13, 2005 2:37 AM | Reply

That hack works beautifully! Thanks Arvind.

KO said:
on Feb 22, 2005 1:50 PM | Reply

Can you post the changed file? that will make it easier to implement the above.

Arvind Satyanarayan said:
on Feb 22, 2005 3:13 PM | Reply

No unfortunately I cannot post the new file for two main reasons

1) You may lose other hacks you have applied 2) It isn't allowed by Six Apart as per the notice at the top of their perl files.

don said:
on Feb 26, 2005 3:08 AM | Reply

in osx explorer, your site is broken. It seems to be squashed into a column about 15% of the page width below the navigation bar

Randy [Brock] Boland said:
on Apr 1, 2005 6:17 AM | Reply

Thanks for the hack, but you might want to clean up the code on the site a bit. It may be my browser (Firefox 1.0.2 on Win XP), but I'm seeing <em>'s and &amp's where there should be _ or &, respectively.

Arvind Satyanarayan said:
on Apr 1, 2005 7:27 AM | Reply

Thanks for the heads up, it should be fixed now.

ANna said:
on May 8, 2005 2:05 AM | Reply

Again, another great addition to Movable Type! Thank you.

Anna said:
on May 26, 2005 2:31 AM | Reply

I'm still seeing 's and &amp's in the two boxes under "Finally around line 1500 find".

Anna said:
on May 26, 2005 2:48 AM | Reply

FYI: I wasn't able to get this working on Version 3.16 even after removing the extra characters in the code.

I tried it 3 times.

Geroge said:
on Aug 15, 2005 2:24 AM | Reply

PERFECT! I've been looking for this for a while... why this isn't part of the standard is beyond me... who wants to click 3 buttons everytime a change is needed!!!

Many thx... saves me a ton of time and keeps me interested in MT.

Marius said:
on Oct 20, 2005 11:31 AM | Reply

Could not get this to work with MT3.2...Code seemed to be slightly different here and there, but after finding everything, it didn't implemend it right. It broke on me. It is such an annoyance to have to rebuild all files when I just want to rebuild a single module page.

Anybody got this working for MT3.2?

Regards,

Marius