Search/Replace (Edit File) does not work as expected

SDK Docs: http://installatron.com/developer/apps
SDK GUI Editor: http://installatron.com/editor
Kubik-Rubik
Posts: 5
Joined: Tue Feb 09, 2016 8:59 am

Search/Replace (Edit File) does not work as expected

Postby Kubik-Rubik » Tue Feb 09, 2016 9:09 am

Hi guys,

I need to modify the configuration file of the application "Moodle", actually add a value to the file. The Search/Replace (Edit File) feature does not work as expected for me. Could you please check?

My code for the addition is:

Code: Select all

$o->sr('config.php', '#(\$CFG = new stdClass\(\);)#', "$1\n\n".'$CFG->slasharguments = false;');


Expected result:

Code: Select all

$CFG = new stdClass();

$CFG->slasharguments = false;


Actual result:

Code: Select all

$CFG = new stdClass();

$CFG->slasharguments = false;

$CFG->slasharguments = false;


As you see, the new value is added twice. Yes, the application still works like this but this is not a logical replacement. Why this is replaced like this and how do I have to use the sr function properly?

Thanks in advance!

Regards
Viktor

Kubik-Rubik
Posts: 5
Joined: Tue Feb 09, 2016 8:59 am

Re: Search/Replace (Edit File) does not work as expected

Postby Kubik-Rubik » Tue Feb 09, 2016 10:27 am

Update:

I saw that the rule is applied twice instead of only once (custom code is called twice)! I use the following call trigger:

Code: Select all

$this->registerCustomCode("moodle", "all", "install", "last", "process", "moodleInstall");


What should I change so that the replacement is only executed once?

Greetings

Phil
Staff
Posts: 486
Joined: Tue Jun 19, 2007 6:06 am

Re: Search/Replace (Edit File) does not work as expected

Postby Phil » Tue Feb 09, 2016 12:40 pm

Hello,

The custom code should only be called once. We're reviewing what's going on there.

To get this fixed use this expression instead to block the second match:

Code: Select all

$o->sr('config.php', '#\$CFG = new stdClass\(\);#', '$CFG = new stdClass( );'."\n\n".'$CFG->slasharguments = false;');


Thank you,
Phil
Phillip Stier
Installatron Co-Founder

Kubik-Rubik
Posts: 5
Joined: Tue Feb 09, 2016 8:59 am

Re: Search/Replace (Edit File) does not work as expected

Postby Kubik-Rubik » Wed Feb 10, 2016 4:35 am

Hey Phil,

I can verify the bug, the custom code is called twice. If I do the following "trick", then the result is as expected:

Code: Select all

static $run_once = false;

if($run_once == false)
{
   $o->sr('config.php', '#(\$CFG = new stdClass\(\);)#', "$1\n\n".'$CFG->slasharguments = false;');

   $run_once = true;
}


I hope it helps you to fix it!

Greetings


Return to “Application Packaging SDK and Application Customizations”

Who is online

Users browsing this forum: No registered users and 2 guests