Author Topic: Modul is in use ... but where ...  (Read 5456 times)

aldus

  • Guest
Modul is in use ... but where ...
« on: August 23, 2008, 03:20:34 PM »
Hello

I'll keep it brief: it happend today again and drives me xxx:
"Can't uninstall modul, modul is in use ...".
To get rid of this situation here is a code-snipped for
"admin/modules/uninstall.php", line 53 ff.
Code: [Select]
<?php
/**
*    Check if the module is in use
*
*    @version    0.1.0
*    @build        1
*    @date        2008-08-16
*    @author        aldus
*    @package    WebsiteBaker - Admin - modules
*    @state        @dev
*
*/

function replace_all ($aStr "", &$aArray ) {
    foreach(
$aArray as $k=>$v$aStr str_replace("{{".$k."}}"$v$aStr);
    return 
$aStr;
}

$info $database->query("SELECT section_id, page_id FROM ".TABLE_PREFIX."sections WHERE module=&#39;".$_POST[&#39;file&#39;]."&#39;" );

if ( $info->numRows() > 0) {
    
    
/**
    *    Modul is in use, so we have to warn the user
    */
    
    
$add $info->numRows() == "this page" "these pages";
    
$msg_template_str  "<br /><br />Modul <b>{{modul_name}}</b> could not be uninstalled because it is still in use on ";
    
$msg_template_str .= $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=&#39;../pages/sections.php?page_id={{id}}&#39;>{{title}}</a></b><br />";
    
    
$values = array (&#39;modul_name&#39; => $file);
    
$msg replace_all $msg_template_str,  $values );
        
    
$page_names "";
    
    while (
$data $info->fetchRow(DB_FETCHMODE_ASSOC) ) {
    
        
$temp $database->query("SELECT page_title from ".TABLE_PREFIX."pages where page_id=".$data[&#39;page_id&#39;]);
        
$temp_title $temp->fetchRowDB_FETCHMODE_ASSOC );
        
        
$page_info = array(
            &
#39;id&#39;    => $data[&#39;page_id&#39;], 
            
&#39;title&#39; => $temp_title[&#39;page_title&#39;]
        
);
            
        
$page_names .= replace_all $page_template_str$page_info );
    }
    
    
/**
    *    Printing out the error-message and die().
    */
    
$admin->print_error(str_replace ("Datei""Modul"$MESSAGE[&#39;GENERIC&#39;][&#39;CANNOT_UNINSTALL_IN_USE&#39;]).$msg.$page_names);
}
?>


Without the "<?php" and "?>" lines ...
Edit:
And for the templates (wb/admin/templates/uninstall.php, line 56 ff.) this one:
Code: [Select]
<?php
/**
*    Check if the template is the standard-template or still in use
*/
$MESSAGE[&#39;GENERIC&#39;][&#39;CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE&#39;] = "Can&#39;t unistall this template <b>".$file."</b> because it&#39;s the standardtemplate!";

if ($file == DEFAULT_TEMPLATE) {
    
$admin->print_error($MESSAGE[&#39;GENERIC&#39;][&#39;CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE&#39;]); /** Text is missing! 2008-06-15 */

} else {
    
    
/**
    *    Check if the template is still in use by a page ...
    *
    *    @version    0.2.0
    *    @build        4
    *    @author        aldus
    *    @since        0.1.0
    *    @lastchange 2008-08-16
    *
    */
    
$info $database->query("SELECT page_id, page_title FROM ".TABLE_PREFIX."pages WHERE template=&#39;".$file."&#39; order by page_title");
    
    if (
$info->numRows() > 0) {
    
        
/**
        *    Template is still in use, so we&#39;re collecting the page-titles
        *
        *    @version    0.2.0
        *    @build        4
        *    @since        0.1.0
        *    @lastchange 2008-08-16
        *
        *    0.2.0        Codechanges for WebsiteBaker to use it without the Black-Hawk-Engine
        *
        *    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 - Multiple language support here ...
        */
        
        /**
        *    The base-message template-string for the top of the message
        *
        *    0.1.2    this page/ these pages
        *
        */
        
$add $info->numRows() == "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 ";
        
$msg_template_str .= $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=&#39;../pages/settings.php?page_id={{id}}&#39;>{{title}}</a></b><br />";
        
        
$values = array (&#39;template_name&#39; => $file);
        
$msg replace_all $msg_template_str,  $values );
        
        
$page_names "";
        
        while (
$data $info->fetchRow(DB_FETCHMODE_ASSOC) ) {
            
            
$page_info = array(
                &
#39;id&#39;    => $data[&#39;page_id&#39;], 
                
&#39;title&#39; => $data[&#39;page_title&#39;]
            
);
            
            
$page_names .= replace_all $page_template_str$page_info );
        }
        
        
/**
        *    Printing out the error-message and die().
        */
        
$admin->print_error($MESSAGE[&#39;GENERIC&#39;][&#39;CANNOT_UNINSTALL_IN_USE&#39;].$msg.$page_names);
    
}
}
?>


Regards
Aldus
« Last Edit: August 23, 2008, 03:35:55 PM by aldus »

Offline Stefek

  • Posts: 6177
  • Gender: Male
  • ("ړ)
Re: Modul is in use ... but where ...
« Reply #1 on: August 23, 2008, 04:58:02 PM »
Using this snippets you are able to deinstall modules/templates althaugh they're in use?

What if you really need them?

Is there something i missed?

Regards,
Stefek
"Gemeinsam schafft man mehr."

gemeinsam
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

aldus

  • Guest
Re: Modul is in use ... but where ...
« Reply #2 on: August 23, 2008, 05:28:27 PM »
No - they tell you where in use - incl. link to the page (-settings)

Regards
Aldus

[gelöscht durch Administrator]
« Last Edit: August 23, 2008, 05:30:14 PM by aldus »

Offline Stefek

  • Posts: 6177
  • Gender: Male
  • ("ړ)
Re: Modul is in use ... but where ...
« Reply #3 on: August 23, 2008, 05:32:38 PM »
Aaaaahh *lightsup*

I got it.

Well this is helpfull. It's a real nightmare if you have to search manually for the modules.
 :roll:

Should be standard I think.

Best Regards,
Stefek
"Gemeinsam schafft man mehr."

gemeinsam
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

erpe0812

  • Guest
Re: Modul is in use ... but where ...
« Reply #4 on: August 23, 2008, 06:25:38 PM »
Hi Stefek,

Ruebenwurzel told me,  the easiest way to achieve this is to make a new ticket!

rgds

erpe

Offline Stefek

  • Posts: 6177
  • Gender: Male
  • ("ړ)
Re: Modul is in use ... but where ...
« Reply #5 on: August 23, 2008, 06:39:11 PM »
Yes I know, Erpe.
But why do you address these words to me?  :-D

If Aldus decide that his efforts are worth it being implemented, than he will do.

I'm just telling  that I think they're worth it  :wink:

Regards,
Stefek
"Gemeinsam schafft man mehr."

gemeinsam
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

erpe0812

  • Guest
Re: Modul is in use ... but where ...
« Reply #6 on: August 23, 2008, 07:32:55 PM »
Hi Stefek,

As I can read you are a member of the marketing team.
Maybe from this point of view?

If you think, it is a good idea to let it implement as a standard, than you can open a new ticket?
Maybe I'm wrong, but this is my oppinion.

I agree to what you had said, so I will open an new ticket as soon as I can reach the project-site (timeouts)

Have a nice day.

erpe

Offline Stefek

  • Posts: 6177
  • Gender: Male
  • ("ړ)
Re: Modul is in use ... but where ...
« Reply #7 on: August 23, 2008, 07:41:19 PM »
As I can read you are a member of the marketing team.
Maybe from this point of view?

Nope, this has nothing to do with the Marketing.

Best Regard,
Stefek
"Gemeinsam schafft man mehr."

gemeinsam
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

erpe0812

  • Guest
Re: Modul is in use ... but where ...
« Reply #8 on: August 23, 2008, 07:58:20 PM »
no comment

Offline Stefek

  • Posts: 6177
  • Gender: Male
  • ("ړ)
Re: Modul is in use ... but where ...
« Reply #9 on: August 23, 2008, 08:13:03 PM »
"Gemeinsam schafft man mehr."

gemeinsam
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

 

postern-length