Advertisement:

Author Topic: [Tip] Quick maintenance  (Read 18245 times)

Offline Marcus Forsberg

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,608
  • Gender: Male
    • marcus.t.forsberg on Facebook
    • marcusforsberg on LinkedIn
    • @marcusforsberg on Twitter
    • marcusforsberg.net
[Tip] Quick maintenance
« on: December 28, 2008, 02:31:26 PM »
Hello world!

9:16PM. Boring day. What are we going to do?
*a few silent seconds*
I got it! Lets make a quick maintenance pull-down menu in the header ;D



Before we start, we should make sure we have SMF 2.0 Beta 4, and have the default theme activated.

* Nascar checks hes forum

Okey, lets do it!



Step one: Locate index.template.php, in ./Themes/default/.
Step two: Open the file
Ready?

Code: (Find this) [Select]
if (!empty($modSettings['enableOpenID']))
echo'
<br />
<input type="text" name="openid_url" id="openid_url" size="25" class="openid_login" />';

echo '
<input type="hidden" name="hash_passwrd" value="" />
</form>';
}

* Nascar searches

Now, add this after that code:

Code: (Add after) [Select]
// Show a quick pull-down menu whit links to maintenance tasks.. If they're permitted, that is.
if ($context['allow_admin'])
{ echo'
<form>
<select onChange="if(this.selectedIndex!=0)
self.location=this.options[this.selectedIndex].value">
<option value="" selected>' . $txt['quick_maintenance'] . '
<optgroup label="' . $txt['quick_maintenance_database'] . '">
<option value="' . $scripturl . '?action=admin;area=maintain;sa=optimize;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_optimize'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=admintask;activity=maintain_backup;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_backup'] . '
</optgroup>
<optgroup label="' . $txt['quick_maintenance_routine'] . '">
<option value="' . $scripturl . '?action=admin;area=maintain;sa=version">' . $txt['quick_maintenance_version'] . '
<option value="' . $scripturl . '?action=admin;area=repairboards">' . $txt['quick_maintenance_repairboards'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=recount;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_recount'] . '
</optgroup>
<optgroup label="' . $txt['quick_maintenance_members'] . '">
<option value="' . $scripturl . '?action=admin;area=maintain;sa=admintask;activity=maintain_members;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_maintain_members'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=admintask;activity=maintain_reattribute_posts;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_reattribute_posts'] . '
</optgroup>
<optgroup label="' . $txt['quick_maintenance_topics'] . '">
<option value="' . $scripturl . '?action=admin;area=maintain;sa=admintask;activity=maintain_old;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_old'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=admintask;activity=move_topics_maintenance;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_topics_maintenance'] . '
</optgroup>
<optgroup label="' . $txt['quick_maintenance_miscellaneous'] . '">
<option value="' . $scripturl . '?action=admin;area=maintain;sa=logs;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_logs'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=convertutf8">' . $txt['quick_maintenance_convertutf8'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=cleancache">' . $txt['quick_maintenance_cleancache'] . '
</optgroup>
</select>
</form> ';
}

When we've done that, our code should look like this:

Code: (Result) [Select]
if (!empty($modSettings['enableOpenID']))
echo'
<br />
<input type="text" name="openid_url" id="openid_url" size="25" class="openid_login" />';

echo '
<input type="hidden" name="hash_passwrd" value="" />
</form>';
}

// Show a quick pull-down menu whit links to maintenance tasks.. If they're permitted, that is.
if ($context['allow_admin'])
{ echo'
<form>
<select onChange="if(this.selectedIndex!=0)
self.location=this.options[this.selectedIndex].value">
<option value="" selected>' . $txt['quick_maintenance'] . '
<optgroup label="' . $txt['quick_maintenance_database'] . '">
<option value="' . $scripturl . '?action=admin;area=maintain;sa=optimize;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_optimize'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=admintask;activity=maintain_backup;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_backup'] . '
</optgroup>
<optgroup label="' . $txt['quick_maintenance_routine'] . '">
<option value="' . $scripturl . '?action=admin;area=maintain;sa=version">' . $txt['quick_maintenance_version'] . '
<option value="' . $scripturl . '?action=admin;area=repairboards">' . $txt['quick_maintenance_repairboards'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=recount;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_recount'] . '
</optgroup>
<optgroup label="' . $txt['quick_maintenance_members'] . '">
<option value="' . $scripturl . '?action=admin;area=maintain;sa=admintask;activity=maintain_members;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_maintain_members'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=admintask;activity=maintain_reattribute_posts;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_reattribute_posts'] . '
</optgroup>
<optgroup label="' . $txt['quick_maintenance_topics'] . '">
<option value="' . $scripturl . '?action=admin;area=maintain;sa=admintask;activity=maintain_old;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_old'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=admintask;activity=move_topics_maintenance;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_topics_maintenance'] . '
</optgroup>
<optgroup label="' . $txt['quick_maintenance_miscellaneous'] . '">
<option value="' . $scripturl . '?action=admin;area=maintain;sa=logs;sesc=' . $context['session_id'] . '">' . $txt['quick_maintenance_logs'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=convertutf8">' . $txt['quick_maintenance_convertutf8'] . '
<option value="' . $scripturl . '?action=admin;area=maintain;sa=cleancache">' . $txt['quick_maintenance_cleancache'] . '
</optgroup>
</select>
</form> ';
}

* Nascar fixes hes file (Don't tell anyone he did it wrong)

We should now see a select in our header. (if we're the admin of course)

* Nascar checks

But, now what?  ???
We can't see anything!  :'(

Let's fix this, by opening Modifications.english.php in ./Themes/default/languages/, and add this to the end of the file (Before ?>)

Code: [Select]
// Start Quick maintenance strings
$txt['quick_maintenance'] = 'Quick maintenance';
$txt['quick_maintenance_database'] = 'Database';
$txt['quick_maintenance_optimize'] = 'Optimize tables';
$txt['quick_maintenance_backup'] = 'Backup Database';
$txt['quick_maintenance_routine'] = 'Routine';
$txt['quick_maintenance_version'] = 'Check files';
$txt['quick_maintenance_repairboards'] = 'Repair errors';
$txt['quick_maintenance_recount'] = 'Recount data';
$txt['quick_maintenance_members'] = 'Members';
$txt['quick_maintenance_maintain_members'] = 'Remove inactive';
$txt['quick_maintenance_reattribute_posts'] = 'Reattribute posts';
$txt['quick_maintenance_topics'] = 'Topics';
$txt['quick_maintenance_old'] = 'Remove old posts';
$txt['quick_maintenance_topics_maintenance'] = 'Move topics';
$txt['quick_maintenance_miscellaneous'] = 'Miscellaneous';
$txt['quick_maintenance_logs'] = 'Empty logs';
$txt['quick_maintenance_convertutf8'] = 'Convert to UTF-8';
$txt['quick_maintenance_cleancache'] = 'Empty file cache';
// End Quick maintenance strings

* Nascar runs of checking.

Nope, no change.
That's because we haven't emptied our file cache!
Do it by going to Admin > Forum Maintenance > Empty the file cache.
(We won't have to travel this long way when we've finished this ;))

NOW we can check.
* Nascar checks.



TADAAA!
A quick maintenance pull-down.


Notes:
  • This will work fine on custom themes, you just have to change what you search for in index.template.php.
  • 1.1.x users: I'm working on it.
  • If you want to release this as a mod, PM me. Be the first ;)

Enjoy, and happy holidays!
Nascar
« Last Edit: December 28, 2008, 02:38:27 PM by Nascar »

Offline Mr^Lonely

  • Newbie
  • *
  • Posts: 1
Re: [Tip] Quick maintenance
« Reply #1 on: December 30, 2008, 04:19:34 PM »
Thanks

Offline daleb30

  • Newbie
  • *
  • Posts: 7
Re: [Tip] Quick maintenance
« Reply #2 on: January 10, 2009, 10:04:23 PM »
Works great, very useful.
Thanks

Offline ѕησω

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,427
  • Gender: Male
  • Nisi credideritis, non intelligetis.
    • wade.poulsen93 on Facebook
    • acans on GitHub
    • https://www.linkedin.com/profile/view?id=145186638 on LinkedIn
    • @imacans on Twitter
    • Acans
Re: [Tip] Quick maintenance
« Reply #3 on: January 11, 2009, 04:14:06 AM »
Tested on fresh install 2.0.4 and tiss good, anyway to change it from default administrator group to member = 1
"The Book of Arantor, 17:3-5
  And I said unto him, thy database query shalt always be sent by the messenger of $smcFunc
  And $smcFunc shall protect you against injections and evil
  And so it came to pass that mysql_query was declared deprecated and even though he says he is not dead yet, the time was soon to come to pass when mysql_query shall be gone and no more."

Offline Marcus Forsberg

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,608
  • Gender: Male
    • marcus.t.forsberg on Facebook
    • marcusforsberg on LinkedIn
    • @marcusforsberg on Twitter
    • marcusforsberg.net
Re: [Tip] Quick maintenance
« Reply #4 on: January 11, 2009, 05:48:07 AM »
Try changing

Code: [Select]
   if ($context['allow_admin'])
to

Code: [Select]
   if ($context['user']['id'] == 1)

Offline ѕησω

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,427
  • Gender: Male
  • Nisi credideritis, non intelligetis.
    • wade.poulsen93 on Facebook
    • acans on GitHub
    • https://www.linkedin.com/profile/view?id=145186638 on LinkedIn
    • @imacans on Twitter
    • Acans
Re: [Tip] Quick maintenance
« Reply #5 on: January 11, 2009, 10:04:32 AM »
Works perfectly nascar

If i wanted this to work with a group it would be

   if ($context['group']['id'] == "group id number")

without  ""
"The Book of Arantor, 17:3-5
  And I said unto him, thy database query shalt always be sent by the messenger of $smcFunc
  And $smcFunc shall protect you against injections and evil
  And so it came to pass that mysql_query was declared deprecated and even though he says he is not dead yet, the time was soon to come to pass when mysql_query shall be gone and no more."

Offline Marcus Forsberg

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,608
  • Gender: Male
    • marcus.t.forsberg on Facebook
    • marcusforsberg on LinkedIn
    • @marcusforsberg on Twitter
    • marcusforsberg.net
Re: [Tip] Quick maintenance
« Reply #6 on: January 11, 2009, 12:23:25 PM »
Er.. I think it whould be:

Code: [Select]
   if ($context['user']['group'] == "groupname")

Offline FlixyaFriend

  • Semi-Newbie
  • *
  • Posts: 18
    • samsung ue46c8000
Re: [Tip] Quick maintenance
« Reply #7 on: January 19, 2009, 04:32:46 AM »
Works great, very useful.
Thanks

Offline ndesigns

  • Semi-Newbie
  • *
  • Posts: 11
Re: [Tip] Quick maintenance
« Reply #8 on: January 26, 2010, 08:49:23 PM »
great, very useful.
Thanks   ;D