0

I`m trying to replace a chunk of code on the model with custom code, that I wrote.

Here is the code. I works, but it leaves a lot of offset. Maybe there is a better way to do this

<operation info="Example of the vQmod">
<search position="replace" offset="3"><![CDATA[
Some code I want to Replace
Some code I want to Replace
Some code I want to Replace
]]></search>
<add><![CDATA[
Replaced Code
Replaced Code
Replaced Code
]]></add>
</operation>
HDP
  • 4,005
  • 2
  • 36
  • 58
nikksan
  • 3,341
  • 3
  • 22
  • 27
  • Vqmods offset value is for replacing a line and the following x lines, however the search is for one line only. Vqmod doesn't match multiple lines. – HDP Sep 23 '15 at 08:46

2 Answers2

0

Vqmods offset value is for replacing a line and the following x lines, however the search is for one line only. Vqmod doesn't match multiple lines in search.

Example :

Input

 public function index() {
        $a = rand();
        $b = rand();
        if ($a == $b) {
            echo 'oh noes';
            return false;
        }
    }

Script

 <?xml version="1.0" encoding="UTF-8"?>
    <modification>
        <id>Replace many lines with one</id>
        <version>1.0</version>
        <vqmver>2.X</vqmver>
        <author>xxx</author>
        <file name="path/to/testfile.php">
            <operation info="Replace index function">
                <search position="replace" offset="7"><![CDATA[
                public function index() {
                ]]></search>
                <add><![CDATA[
                public function index($arr = array()) {
                    foreach ($arr as $a) {
                        echo $a;
                        }
                }
                ]]></add>
            </operation>
        </file>
    </modification>

Output

 public function index($arr = array()) {
        foreach ($arr as $a) {
            echo $a;
            }
    }

Note : There are still 7 blank lines. The offset clears the extra 7 lines of code from the input, but the replaced code is added in place of the initial line. So there will be 7 extra spaces after the new code, but it will not affect the code functionality, only the look of the vqcache file which is of no importance.

zed Blackbeard
  • 760
  • 12
  • 30
0

In Opencart, you cannot search for multiple lines of code and replace it with new multiple lines of codes. It can only search a single line and then replace or add with single line or multiple lines of code.

Offset is to search a single line of code and then offset the number of lines below and then replace or add new coding. Something like this:

   <operation info="Example of the vQmod">
    <search position="replace" offset="3"><![CDATA[
    code I want to Replace at offset line 3
    ]]></search>
    <add><![CDATA[
    Replaced Code
    add code
    add code
    ]]></add>
    </operation>