CORE-POS/IS4C

View on GitHub
documentation/Fannie/developer/cron.html

Summary

Maintainability
Test Coverage
<html>
<head>
    <title>Scheduled Tasks</title>
</head>
<body>
    <div style="text-align:center;margin-bottom:10px;font-size:80%;">
    updated as of: March 30, 2015<br />
    last author: Andy Theuninck
    </div>
    <div style="border: solid 1px black; font-size: 115%; padding: 1em;">
    The latest documentation can be found on the <a href="https://github.com/CORE-POS/IS4C/wiki/Fannie-Scheduled-Tasks">Project Wiki</a>.
    The information below may be out of date. 
    </div>


<!-- --COMMENTS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

. 17Oct2012 Eric Lee Add note about how to access "user facing documentation" is.

-->

<i>N.B. - pretty much all of this only applies if fannie
is installed a unix-style system</i>
<p />
To facilitate the use of a single configuration file and
minimize the number of languages required to run fannie,
I'm proposing scripts to run various scheduled tasks be
written in PHP when reasonably possible.
<p />
To keep scripts portable, the web interface for configuring
jobs will start all scripts with a working directory of
{FANNIE}/cron/. This is rather vital. Starting each script
in a consistent relative path means the script can locate
fannie's configuration file without hard-coding any paths.
<p />
To make scripts available to the web interface, they must
be located in {FANNIE}/cron/. Scripts can be placed in
further subdirectories; just keep in mind the inital working
directory will always be {FANNIE}/cron/.
<p />
If you place a comment block in your script containing the
string HELP, this comment will be used as user-facing
documentation explaining what the script does
that is available by clicking the link in the 'Command'
column of the web interface, {FANNIE}/cron/management/index.php .
<p />
By default, the web interface will direct script output
to {FANNIE}/logs/dayend.log.
<h3>Example</h3>
Here's a sample script to backup the products table. For
the sake of the example, consider the file to be
{FANNIE}/cron/TableBackups/products.php. The function
cron_msg() simply appends a timestamp and filename to
the given string for better logging.
<pre>
&lt;?php
/* HELP

   TableBackups/products.php

   This script makes a copy of products in
   prodBackup.
*/

chdir("TableBackups"); // because of inital working directory

include("../../config.php");
include($FANNIE_ROOT."src/mysql_connect.php");
include($FANNIE_ROOT."src/cron_msg.php");

$result1 = $dbc->query("TRUNCATE TABLE prodBackup");
$result2 = $dbc->query("INSERT INTO prodBackup SELECT * FROM products");

if ($result1 === false || $result2 === false)
    echo cron_msg("Error backing up table: products");
else
    echo cron_msg("Successfully backed up products");
?&gt;
</pre>
</body>
</html>