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

132 lines
4.0 KiB
PHP
Executable File

<?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');
$application->bootstrap()->run();
// --- Options
$displayUsage = false;
try {
$opts = new Zend_Console_Getopt(array(
'help|?' => "Display usage information.",
'list' => "List client and prestations.",
'generate' => "Generate",
'send=s' => "Generate send incron file [client]/[name]",
'read=s' => "Generate read incron file [client]/[name]",
));
$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 $opts->getUsageMessage();
exit;
}
$logPath = realpath(__DIR__ . '/../shared');
$prestations = include APPLICATION_PATH . '/../config.php';
if ($opts->list)
{
if (count($prestations)>0)
{
foreach ($prestations as $client => $params)
{
echo "Client : ".$client."\n";
foreach ($params['prestations'] as $i => $item)
{
echo " ";
echo $item['name'] . " : ".$item['type'];
if (array_key_exists('directory', $item)) {
echo " - " .$item['directory'];
}
echo "\n";
}
echo "\n";
}
}
}
if ($opts->generate)
{
echo "Generate.\n";
if ($opts->send) {
$input = explode('/', $opts->send);
$client = $input[0];
$name = $input[1];
if (array_key_exists($client, $prestations))
{
foreach ($prestations[$client]['prestations'] as $item)
{
if ($item['name'] == $name)
{
$directory = 'send';
if (array_key_exists('directory', $item))
{
$directory = $item['directory'];
}
$fluxBasePath = '/home/data/' . strtolower($item['type']) . '/' . $client . '/' . $directory;
$file = __DIR__ . '/incron.d/' . strtolower($item['type']) . '_' . $client;
file_put_contents($file, "$fluxBasePath IN_CLOSE_WRITE php /home/flux/current/send.php --file $@/$# >> $logPath/send.log 2>&1");
echo "File created $file\n";
}
}
}
}
if ($opts->read) {
$input = explode('/', $opts->read);
$client = $input[0];
$name = $input[1];
if (array_key_exists($client, $prestations))
{
foreach ($prestations[$client]['prestations'] as $item)
{
if ($item['name'] == $name)
{
$directory = 'recv';
if (array_key_exists('directory', $item))
{
$directory = $item['directory'];
}
$fluxBasePath = '/home/data/' . strtolower($item['type']) . '/' . $client. '/' . $directory;
$file = __DIR__ . '/incron.d/' . strtolower($item['type']) . '_' . $client . '_recv';
file_put_contents($file, "$fluxBasePath IN_ACCESS php /home/flux/current/read.php --file $@/$# >> $logPath/read.log 2>&1");
echo "File created $file\n";
}
}
}
}
echo "Put the file to /etc/incron.d and restart incron.\n";
echo "Generate Ended.\n";
}