flux/trigger.php

71 lines
1.9 KiB
PHP
Raw Permalink Normal View History

<?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');
2017-03-02 14:17:33 +01:00
// --- 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();
2017-03-02 14:17:33 +01:00
$optsNb = $opts->getOptions();
} catch (Zend_Console_Getopt_Exception $e) {
2017-03-02 14:17:33 +01:00
$displayUsage = true;
}
// --- Aide / Options
if ($optsNb == 0 || isset($opts->help)) {
$displayUsage = true;
}
// --- Usage
2017-03-02 14:17:33 +01:00
if ($displayUsage) {
echo "Proxy Event Trigger.\n";
echo $opts->getUsageMessage();
exit;
}
// --- Basic file information
if (empty($opts->file)) {
exit;
}
2017-03-02 14:37:05 +01:00
$logPath = realpath(__DIR__ . '/../shared');
$pathParts = pathinfo($opts->file);
$filename = $pathParts['basename'];
$extension = $pathParts['extension'];
switch($opts->event)
{
case 'IN_CLOSE_WRITE':
if ($extension == 'tck') {
2017-03-02 14:37:05 +01:00
passthru(__DIR__ . '/tck.php --file '.$opts->file.' >> '.$logPath.'/tck.log 2>&1');
} else {
2017-03-02 14:37:05 +01:00
passthru(__DIR__ . '/send.php --file '.$opts->file.' >> '.$logPath.'/send.log 2>&1');
}
2015-11-19 16:25:31 +01:00
break;
case 'IN_ACCESS':
case 'IN_CLOSE_NOWRITE':
2017-03-02 14:37:05 +01:00
passthru(__DIR__ . '/read.php --file '.$opts->file.' >> '.$logPath.'/read.log 2>&1');
break;
case 'IN_DELETE':
2017-03-02 14:37:05 +01:00
passthru(__DIR__ . '/read.php --file '.$opts->file.' >> '.$logPath.'/read.log 2>&1');
break;
}