froot Posted December 18, 2023 Share Posted December 18, 2023 I wrote this search module: https://github.com/dtjngl/simpleSearch It works OK so far, however I don't know why I cannot uninstall it. When I uninstall it, it keeps reinstalling. Is that issue to be found in the module? Cause I do have locations in my website template files where I initiate this module but that shouldn't matter because it reinstalls (or doesn't uninstall) while still on the modules overview page in admin. Also no mentions of it on ready.php etc. Thanks for help! 1 Link to comment Share on other sites More sharing options...
bernhard Posted December 18, 2023 Share Posted December 18, 2023 Just install the module on another ProcessWire installation. If it's the same behaviour there the issue is in your module. If it's different, then the issue is in your current project. ? 1 Link to comment Share on other sites More sharing options...
monollonom Posted December 18, 2023 Share Posted December 18, 2023 6 hours ago, fruid said: Cause I do have locations in my website template files where I initiate this module but that shouldn't matter because it reinstalls (or doesn't uninstall) while still on the modules overview page in admin Or maybe it does? "get" does install and initialize the module, if available https://processwire.com/api/ref/modules/get/ Is it possible a visit occured right after you tried to uninstall? 1 Link to comment Share on other sites More sharing options...
froot Posted December 19, 2023 Author Share Posted December 19, 2023 3 hours ago, monollonom said: Is it possible a visit occured right after you tried to uninstall? highly unlikely, it was on my local machine. Link to comment Share on other sites More sharing options...
BitPoet Posted December 19, 2023 Share Posted December 19, 2023 22 hours ago, fruid said: Is that issue to be found in the module? After a quick glance, I don't think so. Have you tried writing into the PW log from ___install and ___uninstall? This should at least tell you whether uninstall+install happen. In the later case, you should also see the page request that triggers the re-installation. Just to make sure: you have $config->debug enabled so you don't miss any warnings, right? 1 Link to comment Share on other sites More sharing options...
froot Posted December 19, 2023 Author Share Posted December 19, 2023 yes I'm in debug and have tracy. When I uninstall, I can confirm that what ever I log from inside the __uninstall() method doesn't get logged. That is strange. Also, in the module I defined some hooks that get triggered when saving a template. Might that be the culprit? It still makes no sense to me since when I'm uninstalling the module, I'm not on and am not editing a template. public function ready() { $this->addHookAfter("ProcessTemplate::buildEditForm", $this, 'addSimpleSearchCategoryField'); $this->addHookBefore("ProcessTemplate::executeSave", $this, 'saveSimpleSearchCategoryFieldValue'); } Link to comment Share on other sites More sharing options...
BitPoet Posted December 19, 2023 Share Posted December 19, 2023 I really don't think the problem is within the module code. Are there any messages when you do a Modules -> Refresh? Do you have another module active that accesses simpleSearch? Additional idea: a debug_backtrace from within the constructor might be able to shed some light on it if it's really a case of the module being blocked from uninstall because it's in use. Link to comment Share on other sites More sharing options...
froot Posted December 19, 2023 Author Share Posted December 19, 2023 I tried refresh and clear compiled files, doesn't help. Now thinking maybe this problem is related? I posted here yesterday… https://processwire.com/talk/topic/21128-solved-invalid-module-name/?do=findComment&comment=237939 But AFAIK I followed the naming convention alright, that's why I'm kinda stuck. Link to comment Share on other sites More sharing options...
monollonom Posted December 19, 2023 Share Posted December 19, 2023 Last shot: could it be because you don’t call the parent’s uninstall function? See ProcessHello’s exemple https://github.com/ryancramerdesign/ProcessHello/blob/189029f494870760107d8a621dfb5a59db53959c/ProcessHello.module.php#L227C69-L227C69 1 Link to comment Share on other sites More sharing options...
froot Posted December 19, 2023 Author Share Posted December 19, 2023 2 hours ago, monollonom said: the parent’s uninstall function not sure what parent means in this context… Link to comment Share on other sites More sharing options...
monollonom Posted December 19, 2023 Share Posted December 19, 2023 The parent class but actually I’m seeing in ryan’s comment that it’s only necessary for “Process” modules, my bad 1 Link to comment Share on other sites More sharing options...
bernhard Posted December 19, 2023 Share Posted December 19, 2023 You could try to delete the row of your module in the "modules" database table. That would mean that the module is uninstalled. Then you could check if the module get's installed automatically on the next page load or modules refresh. If it get's installed you could add something like this to your install() method of the module: bd(debug_backtrace()); die(); In that backtrace you should then see what is triggering the installation of the module. 1 Link to comment Share on other sites More sharing options...
froot Posted December 21, 2023 Author Share Posted December 21, 2023 I actually found this in the modules.txt log file: 2023-12-21 11:36:09 admin https://mysite.ddev.site/admin/module/edit?name=SimpleSearch&collapse_info=1 Uninstalled module 'SimpleSearch' 2023-12-21 11:36:10 admin https://mysite.ddev.site/favicon.ico Installed module 'SimpleSearch' Super strange! I removed the favicon.ico links in the head tag, removed the favicon icons, cleared cache, refreshed modules, cleared compiled files, issue remains Will try this now: On 12/19/2023 at 8:54 PM, bernhard said: You could try to delete the row of your module in the "modules" database table. That would mean that the module is uninstalled. Then you could check if the module get's installed automatically on the next page load or modules refresh. If it get's installed you could add something like this to your install() method of the module: bd(debug_backtrace()); die(); EDIT: I just tried this and Tracy doesn't bd-log anything from inside the install() method nor the uninstall() method, I mean not even this gets logged: bd('install'); So strange! Link to comment Share on other sites More sharing options...
froot Posted December 25, 2023 Author Share Posted December 25, 2023 OK I found the culprit. I was initiating the module on a custom page class just to make use of one method., not a good idea.. Now that I found a work-around it works fine and I can uninstall with no issues. Link to comment Share on other sites More sharing options...
froot Posted December 25, 2023 Author Share Posted December 25, 2023 The module still needs quite some improvement. One issue that needs attendance is the following. I build a selector and select a page array from the database. $selector = $this->createSelector($this->q, $category); bd($selector); $unfilteredMatches = $this->pages("$selector, start=0, limit=99999"); As discussed in this thread it's (so far) impossible to select pages based on language specific field values. So the query looks through the field values in all languages for the search term. Since this is not what I want, instead I want the query to only match the fields values of the current user language, I do another loop and within that loop, with the method buildSnippets() I create the snippets for the markup. If this returns null (this is now language specific) I sort out the page entirely. $strippedFieldValue = strip_tags($fieldValue); // Find the position of the search term in the field value $position = stripos($strippedFieldValue, $searchTerm); // If the search term is not found, return an empty string if ($position === false) { return false; } So basically I'm selecting once via selector and then narrow it down with a loop. That works for a one-term search query or an exact phrase, but it makes sense that It won't and doesn't work when the search operand is on the fancier side as listed here: https://processwire.com/docs/selectors/operators/#contains What would you suggest? Is my approach so far sensible? Should I hard-code a different loop condition for each of the fancy search operands? I want to give the module-user (not enduser but admin user) the option to adjust the search operand in the module's settings. Thanks for help! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now