Templates kann man installieren, und wenn man sie nicht mehr
mag, schönere gefunden hat, oder es andere Gründe gibt, auch
wieder de-installieren.
Da taucht aber manchmal die Fehlermeldung auf, das das leider nicht
geht, weil dieses Template benutzt wird. "Template is in use ...".
Leider sagt uns die Fehlermeldung nicht "wo" ... und der Grund ist
ein klein wenig erschreckend:
File: admin/templates/uninstall.php
Zeile: 53 ff.
PHP-Code:
// Check if the template is in use
if($_POST['file'] == DEFAULT_TEMPLATE) {
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']);
} else {
$query_templates = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE template = '".$admin->add_slashes($_POST['file'])."' LIMIT 1");
if($query_templates->numRows() > 0) {
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']);
}
}
Au backe:
- die Fehlermeldung, für "Es ist das Standard-Template" und "Es wird benuzt" ist die gleiche! Armer User, hat er doch nun keine Chance herraus zu bekommen, wird das Template einmal oder mehrfach verwendet.
- "limit 1" - Hilfe: selbst wenn es mehrfach verwendet wird: es wird nur eines(!) aus der DB herausgelesen.
- Dazu kommt: es wird nur (!) die page_id herausgelesen: nicht der Titel, oder der Status, geschweige der Link zu der Seite.
Das wird eine größere Schnippselei:
PHP-Code:
require ("../../engines/black_hawk/x_connection.php");
require ("../../engines/black_hawk/xFastTemplate2.php");
/**
* Check if the template is the default-template
*
* @version 0.1.0
*
*/
/** Patch 2008-06-15 **/
$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'] = "Can't unistall this template <b>".$file."</b> because it's the standardtemplate!";
if ($file == DEFAULT_TEMPLATE) {
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE']); /** Text is missing! 2008-06-15 */
} else {
/**
* Check if the template is still in use by a page ...
*
* @version 0.1.0
* @build 2
* @since 0.1.0
* @lastchange 2008-06-15
*
*/
$info = $gDatabase->do_query("SELECT page_id, page_title FROM ".TABLE_PREFIX."pages WHERE template='".$file."' order by page_title", 30600);
if ($info->numRows() > 0) {
/**
* Template is still in use, so we're collecting the page-titles
*
* @version 0.1.1
* @build 2
* @since 0.1.0
* @lastchange 2008-07-13
*
* 0.1.1 add this page <if we found only one> / these pages
*
* @notice All listed pages got linked to "settings.php" so the user can easy change
* the template-settings. Modifications could be made in "page_template_str".
* For additional informations you will have to modify the query, the page_template_str
* and the page_info array.
*
* @todo 1 - Additional informations about the pages (modified, modified_by, visibility, etc)
*
* 2 - What happends about pages, the user is not allowed to edit?
* Marked "red"?
*
* 3 - Outsourcing the templates in an external file - using blocks?
*
* 4 - Multiple language support here ...
*/
$xft2 = new HTML_Template_xFastTemplate2();
/**
* The base-message template-string for the top of the message
*
* 0.1.1 this page/ these pages
*
*/
$add = $info->numRows() == 1 ? "this page" : "these pages";
$msg_template_str = "<br /><br />Template <b>{{ template_name }}</b> could not be uninstalled because it is still in use by ".$add.":<br /><i>click for editing.</i><br /><br />";;
/**
* The template-string for displaying the Page-Titles ... in this case as a link
*/
$page_template_str = "- <b><a href='../pages/settings.php?page_id={{ id }}'>{{ title }}</a></b><br />";;
$msg = $xft2->get_by_source( $msg_template_str, array ('template_name' => $file) );
$page_names = "";
while ($data = $info->fetchRow(DB_FETCHMODE_ASSOC) ) {
$page_info = array(
'id' => $data['page_id'],
'title' => $data['page_title']
);
$page_names .= $xft2->get_by_source( $page_template_str, $page_info );
}
/**
* Printing out the error-message and die().
*/
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE'].$msg.$page_names);
}
}
Gut - das Beispiel macht hier gebrauch von "xConnection" und "xFastTemplate" und ist aus einem älteren Projekt hier erst einmal so übernommen worden,
aber es zeigt zumindest den Weg auf, den man gehen kann um den User/Admin
das Leben mit Templates die noch irgendwo verwendet werden, leichter zu machen.
To be continued ...
Edit: im Attachement die WB27 Version ohne Engines
out of the box ...
Edit 2: Und weil uns das Thema bei den Modulen auch heimsucht im zweiten Attachment der Zipfile für die Module: admin/modules/uninstall.php
have fun ...
Gruß
Aldus