• Welcome to Simple Machines Community Forum. Please login or sign up.

Skip search option for reverse modification for uninstall

Started by kelvincool, November 16, 2014, 11:12:19 AM

Previous topic - Next topic

kelvincool

I think this extra attribute will help with the following situation:

I have two mods, both have their own configuration pages, thus I have something like this in the install.xml

<file name="$sourcedir/ManageSettings.php">
<operation>
<search position="before"><![CDATA['general' => array(
),]]></search>
<add><![CDATA['mymod' => array(
),]]></add>
</operation>
....


So first mod installs and changes the array to:

$subActions = array(
'general' => 'ModifyGeneralModSettings',
'mymod' => 'ModifyMyModSettings',
// Mod authors, once again, if you have a whole section to add do it AFTER this line, and keep a comma at the end.
);


Second mod then comes in:


$subActions = array(
'general' => 'ModifyGeneralModSettings',
'mymod2' => 'ModifyMyMod2Settings',
'mymod' => 'ModifyMyModSettings',
// Mod authors, once again, if you have a whole section to add do it AFTER this line, and keep a comma at the end.
);


This is fine when you only have one mod doing this but when there's two, the problem arises when you come to uninstall. You are forced to uninstall them in the reverse order otherwise you get errors because the lines don't match up anymore as the second mod added an extra line in between. The only way to get around this currently (that I can think of) is to write the uninstall script instead of using the reverse function on the install.xml. This is time consuming and tedious and error prone.

What I propose is an extra attribute in either package-info.xml for the modification tag or as part of modification.xml in the operation tag. For example:

<uninstall for="2.0-2.0.99">
<modification type="file" format="xml" reverse="true" skip-search="true">install.xml</modification>
...


So when skip-search is true, the search is skipped and the remove action works by searching for what you are removing and removing only that bit from the file. Of course this is very dependant on the bit of text being unique but it shouldn't be a problem if you have a habit of putting in things like /* Start of mymod */ in with your modifications. The attribute will not include actions like add or replace.

Arantor

No good deed goes unpunished
All helpful urges should be circumvented

Kindred

And, more importantly, gift Mart on Thurs used a before an ad after instead of replace then this would not even be an issue.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

kelvincool

That was a bad example I guess, what about situations where there's no hook to use. For example if you are adding things to templates.

@Kindred, not quite sure what you mean, can you show a snippet of an example?

Arantor

You would be surprised what can be done when hooks do not exist.
No good deed goes unpunished
All helpful urges should be circumvented

Kindred

Mod authors frequently use the replace commands instead of the add before and add after commands. Replace requires a correct,min altered set to be there in order to go back.   Add after or add before can parse more cleanly in an uninstall
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

kelvincool

I'm not sure why you are talking about replace, my example is all about using add (before or after) and the issues about the search when it comes to uninstalling. My example would be the same whether you used add or replace.  :-\

vbgamer45

I like    kelvincool idea but yeah a certain attribute should be set and should not be the default behavior.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Arantor

Or we could learn to use hooks bearing in mind 2.1 has many many many more hooks than 2.0 has.
No good deed goes unpunished
All helpful urges should be circumvented

Kindred

I disagree, kelvin...    If using add instead of replace, the it does not matter what code got added between the new code and the original target code, because the uninstall only targets the new, mod specific code, to removing, not the entire series of old+new code, like it would in a replace statement.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

Except he's right, actually.

Undoing a before/after requires finding old+new to remove the new.
No good deed goes unpunished
All helpful urges should be circumvented

live627


Kindred

Really?   How odd...   I swear it has always worked for me, despite installing other mods in the same area...


Meh, whatever, as you said, hooks is the way to go anyway.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

kelvincool

Hooks are great but doesn't always apply, for example if you were changing a bit of sql or adding the odd extra loadLanguage or something and like I said changes to the template.

Arantor

There are precisely two places that occur to me where you might do a loadLanguage on its own.

Changing the SQL... there are almost always alternative ways around this.

I am not talking hypothetically.
No good deed goes unpunished
All helpful urges should be circumvented

kelvincool

loadLanguage was just an example and like you said there are two places you could do it so it's possible someone might, you could be adding all sorts, if statements, extra bits of functionality within a function.

I'll loved to hear how you would get around doing changes to SQL, can you share some of that knowledge or link me?

And what about the templates?

Arantor

There are two places that it is needed. I seem to recall both have hooks that can be used to load language files manually, and it wouldn't be hard to add a new kind of hook solely for loadLanguage calls either.

As for queries, that's quite simple: add new queries rather than modifying existing ones. As long as you don't generate floods of queries per page, this is not a problem and having more smaller queries can often be better than fewer massive blocking ones. Seen this so many times in SMF.

You seem to presume that this whole 'hooks' thing is new to me... I've done things with SMF that have never been done before or since, including writing my own plugin for SMF with *its own hook based plugin manager* BEFORE SMF 2.0 RC4 when it introduced the ability to call multiple functions from hooks.

I'm currently writing a gallery that has pretty URL support in it - not vbgamer's one but its own, and it has to interact with the PHPSESSID injector. Guess what: that's all done with hooks. Fixing the ?debug injection, done with hooks. Fixing the URL preparsing from index.php?media/item/my-item-name.1/ to index.php?action=media;sa=item;item=my-item-name.1 so that who's online and everything else still works... all done with hooks.

Hell, I recently had to do something with the 'delete membergroups' functionality to clean up the cases when a membergroup gets deleted (since certain data really should be fixed at that point in the gallery). There isn't even a hook there for that. No matter, I just grabbed the running state later in the execution and made my own 'hook' out of it if you will.

As for templates, that depends on what you're doing. Yes, SMF can be improved here. The template layer is sub-ideal. Buffer rewrites can be a thing (SimpleDesk did this years ago to remove the quick search box if not enabled, and do so without any theme edits, along with rewriting the board index icons. It's fragile, but less fragile than depending on theme edits)

Yes, SMF can be improved, but it is already so much further along in the next version than I think you realise.
No good deed goes unpunished
All helpful urges should be circumvented

kelvincool

If you added new queries would you be adding new code right under the existing query? To be honest I haven't looked too deeply into the sql hooks (are there any?) so I'm assuming you mean there's some sort of way to hook new queries in without adding new code to existing source files. If you add new code you're going to have the issue I've described, unless you're just adding a new function at the end of the file or using hooks.

I certainly didn't presume you were new to hooks, if anything hooks are new to me. Your work sounds interesting (and hardcore).

I definitely agree with you on the templates being far from ideal, recently had to add new stats to the stats page, wasn't a pretty process at all because of the changes to the templates involved.

Arantor

No, you add new code, new queries in new files. In a lot of cases you can do this without having to disrupt anything, depends what you're trying to do. There's even ways to create hooks in actions that don't have hooks, where you interrupt the calling at action level, let it run what it was supposed to run and then play around with $context and whatnot before letting it go to the template. It's all doable.

The whole point of hooks is that you can leave the existing files alone and load new files and have them called at the right time.
No good deed goes unpunished
All helpful urges should be circumvented

kelvincool

I see what you mean, that's certainly a better way of doing things, I'm unfortunately not at that level yet. I've got much to learn.

Arantor

There is never a better time to start learning cool new stuff than "now" :)
No good deed goes unpunished
All helpful urges should be circumvented

Advertisement: