News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

[Tip] Quick maintenance

Started by Marcus Forsberg, December 28, 2008, 02:31:26 PM

Previous topic - Next topic

Marcus Forsberg

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 ?>)

// 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


daleb30

Works great, very useful.
Thanks

Acans

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

Marcus Forsberg

Try changing

   if ($context['allow_admin'])

to

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

Acans

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

Marcus Forsberg

Er.. I think it whould be:


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

FlixyaFriend

Works great, very useful.
Thanks
samsung ue46c8000 [nofollow]

ndesigns


Advertisement: