Script development: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
Line 13: Line 13:
Once renaming is done, give it permissions to execute.
Once renaming is done, give it permissions to execute.
On linux, this is the command:
On linux, this is the command:
<pre>
<source lang="bash">
cd scripts/mydir;
cd scripts/mydir;
chmod a+rx myscript.php
chmod a+rx myscript.php
</pre>
</source>
Then, run it to see if you can run the script in a command line mode. For this, on Linux, type:
Then, run it to see if you can run the script in a command line mode. For this, on Linux, type:
<pre>php-cli ./myscript.php
<source lang="bash">
php-cli ./myscript.php
</source>
or
or
php ./myscript.php</pre>
<source lang="php">
You muste get the following output:
php ./myscript.php
<pre>
</source>
You must get the following output:
<source lang="bash">
Usage: myscript.php param1 param2 ...
Usage: myscript.php param1 param2 ...
</pre>
</source>


== Step 2 - Editing script code ==
== Step 2 - Editing script code ==
Modify the contents of the script to perform operations that interest you.  
Modify the contents of the script to perform operations that interest you.  
All the code that lies between the tags
All the code that lies between the tags
<pre>// ---------- START OF YOUR CODE HERE</pre>
<source lang="php">// ---------- START OF YOUR CODE HERE</source>
and
and
<pre>// ---------- END OY YOUR CODE</pre>
<source lang="php">// ---------- END OY YOUR CODE</source>
is provided as an example.  
is provided as an example.  
You can delete it and put the code that you want.  
You can delete it and put the code that you want.  
Line 38: Line 42:
=== Example to insert a product ===
=== Example to insert a product ===
For example to insert a product in the database Dolibarr, you can place the following code:
For example to insert a product in the database Dolibarr, you can place the following code:
<pre>
<source lang="php">
// Include mother classes for user and product
// Include mother classes for user and product
require_once(DOL_DOCUMENT_ROOT."/user.class.php");
require_once(DOL_DOCUMENT_ROOT."/user.class.php");
Line 71: Line 75:
if ($idproduct < 0) dol_print_error($db,$myproduct->error);
if ($idproduct < 0) dol_print_error($db,$myproduct->error);
else print "Product $idproduct created.\n";
else print "Product $idproduct created.\n";
</pre>
</source>

Navigation menu