modx problem with in-line replace plus before-add

Discussion forum for MOD Writers regarding MOD Development.
Locked
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

modx problem with in-line replace plus before-add

Post by asinshesq »

I'm stuck on a modx change. I'm trying to replace some text in-line and add a comment before the line in question, and what I've done looks fine when I open the xml in a browser, passes the mpv and is allowed by automod, but when I actually install with automod the inline changes do not get done (though the before-add command does work). What am I doing wrong? Here's the code for my xml:

Code: Select all

		<open src="includes/functions_posting.php">
			<edit>
				<find><![CDATA[function user_notification(]]></find>
				<inline-edit>
					<inline-find><![CDATA[$author_name = '']]></inline-find>
					<inline-action type="replace-with"><![CDATA[$author_name, $post_approval, $mod_approved_poster_id]]></inline-action>
				</inline-edit>
				<action type="before-add"><![CDATA[// added $post_approval and mod_approved_poster_id parameters in next line to allow moderators to get notices of posts pending approval, and changed $author_name = '' to $author_name since our changes to mcp_queue.php mean that the function is always called with parameter]]></action>
			</edit>
		</open>
I also tried splitting things out so that the before-add line is in its own edit block like this:

Code: Select all

		<open src="includes/functions_posting.php">
			<edit>
				<find><![CDATA[function user_notification(]]></find>
				<action type="before-add"><![CDATA[// added $post_approval and mod_approved_poster_id parameters in next line to allow moderators to get notices of posts pending approval, and changed $author_name = '' to $author_name since our changes to mcp_queue.php mean that the function is always called with parameter]]></action>
			</edit>
			<edit>
				<find><![CDATA[function user_notification(]]></find>
				<inline-edit>
					<inline-find><![CDATA[$author_name = '']]></inline-find>
					<inline-action type="replace-with"><![CDATA[$author_name, $post_approval, $mod_approved_poster_id]]></inline-action>
				</inline-edit>
			</edit>
		</open>
but that didn't work either.

Any ideas?
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: modx problem with in-line replace plus before-add

Post by asinshesq »

I found a very unsatisfying kludge around the problem as follows:

Code: Select all

		<open src="includes/functions_posting.php">
			<edit>
				<find><![CDATA[/**
* User Notification
*/

]]></find>
				<action type="after-add"><![CDATA[// added $post_approval and mod_approved_poster_id parameters in next line to allow moderators to get notices of posts pending approval, and changed $author_name = '' to $author_name since our changes to mcp_queue.php mean that the function is always called with parameter]]></action>
			</edit>
			<edit>
				<find><![CDATA[function user_notification(]]></find>
				<inline-edit>
					<inline-find><![CDATA[$author_name = '']]></inline-find>
					<inline-action type="replace-with"><![CDATA[$author_name, $post_approval, $mod_approved_poster_id]]></inline-action>
				</inline-edit>
			</edit>
		</open>
But if anyone knows how to make this work more directly (like my first code block in my post above), I would appreciate it. I note that I have another change of the exact same type elsewhere in the mod (a find, an inline edit and then a regular edit) where the inline edit is an after-add, and that works fine, so I am wondering whether I might have run into an automod bug?
User avatar
5hocK
Registered User
Posts: 3011
Joined: Wed Nov 23, 2011 7:00 pm
Location: England

Re: modx problem with in-line replace plus before-add

Post by 5hocK »

I tried your original code on it's own and it installed fine
http://s20.postimg.org/snh1j11j1/test.png
http://s20.postimg.org/72byvf4sd/test2.png

Not sure why yours doesn't work.
A thread is pretty much a topic. Stop with the pedantics will ya.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: modx problem with in-line replace plus before-add

Post by asinshesq »

Thanks for checking. Mine installs fine too (i.e. it says success), but then when I go into functions_posting.php I see that the in-line replace-with action was not actually done. Are you sure that your changes actually took effect?
User avatar
5hocK
Registered User
Posts: 3011
Joined: Wed Nov 23, 2011 7:00 pm
Location: England

Re: modx problem with in-line replace plus before-add

Post by 5hocK »

Yes, 2nd screen is my ftp client with the changes added by Automod.
A thread is pretty much a topic. Stop with the pedantics will ya.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: modx problem with in-line replace plus before-add

Post by asinshesq »

Strange, but thanks for checking.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: modx problem with in-line replace plus before-add

Post by asinshesq »

Actually, I just looked at the changed file you pm'd me and you are seeing the same thing I am: automod added the comment before the line in question but did not make the the inline replace with change. I don't know if that's a automod bug or the wrong xml code that I was using.
User avatar
5hocK
Registered User
Posts: 3011
Joined: Wed Nov 23, 2011 7:00 pm
Location: England

Re: modx problem with in-line replace plus before-add

Post by 5hocK »

You're right, I got the line above added but not the inline replace, very odd.
A thread is pretty much a topic. Stop with the pedantics will ya.
Locked

Return to “[3.0.x] MOD Writers Discussion”