flux/trigger.php
2017-03-02 14:37:05 +01:00

71 lines
1.9 KiB
PHP

<?php
// --- Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(__DIR__ . '/application'));
// --- Define application environment
defined('APPLICATION_ENV')
| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// --- Composer autoload
require_once realpath(__DIR__ . '/vendor/autoload.php');
// --- Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
// --- Options
$displayUsage = false;
try {
// --- Options
$opts = new Zend_Console_Getopt(array(
'help|?' => "Displays usage information.",
'file|f=s' => "Full file path to integrate",
'event=s' => "Event",
));
$opts->parse();
$optsNb = $opts->getOptions();
} catch (Zend_Console_Getopt_Exception $e) {
$displayUsage = true;
}
// --- Aide / Options
if ($optsNb == 0 || isset($opts->help)) {
$displayUsage = true;
}
// --- Usage
if ($displayUsage) {
echo "Proxy Event Trigger.\n";
echo $opts->getUsageMessage();
exit;
}
// --- Basic file information
if (empty($opts->file)) {
exit;
}
$logPath = realpath(__DIR__ . '/../shared');
$pathParts = pathinfo($opts->file);
$filename = $pathParts['basename'];
$extension = $pathParts['extension'];
switch($opts->event)
{
case 'IN_CLOSE_WRITE':
if ($extension == 'tck') {
passthru(__DIR__ . '/tck.php --file '.$opts->file.' >> '.$logPath.'/tck.log 2>&1');
} else {
passthru(__DIR__ . '/send.php --file '.$opts->file.' >> '.$logPath.'/send.log 2>&1');
}
break;
case 'IN_ACCESS':
case 'IN_CLOSE_NOWRITE':
passthru(__DIR__ . '/read.php --file '.$opts->file.' >> '.$logPath.'/read.log 2>&1');
break;
case 'IN_DELETE':
passthru(__DIR__ . '/read.php --file '.$opts->file.' >> '.$logPath.'/read.log 2>&1');
break;
}