flux/scripts/build/incron.php

127 lines
3.8 KiB
PHP
Raw Normal View History

<?php
2015-10-13 11:41:19 +02:00
// --- Define path to application directory
defined('APPLICATION_PATH')
2015-10-13 11:41:19 +02:00
|| define('APPLICATION_PATH', realpath(__DIR__ . '/../../application'));
2015-10-13 11:41:19 +02:00
// --- Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
2015-10-13 11:41:19 +02:00
// --- Composer autoload
require_once realpath(__DIR__ . '/../../vendor/autoload.php');
2015-10-13 11:41:19 +02:00
// --- Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap()->run();
try {
$opts = new Zend_Console_Getopt(
//Options
array(
'help|?' => "Display usage information.",
'list' => "List client and prestations.",
2015-03-31 08:47:55 +02:00
'generate' => "Generate",
'send=s' => "Generate send incron file [client]/[name]",
'read=s' => "Generate read incron file [client]/[name]",
)
);
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
//Usage
if(isset($opts->help))
{
echo $opts->getUsageMessage();
exit;
}
2016-06-17 11:08:25 +02:00
$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";
2015-03-31 08:47:55 +02:00
if ($opts->send) {
2015-10-13 11:41:19 +02:00
2015-03-31 08:47:55 +02:00
$input = explode('/', $opts->send);
$client = $input[0];
$name = $input[1];
if (array_key_exists($client, $prestations))
{
2015-03-31 08:47:55 +02:00
foreach ($prestations[$client]['prestations'] as $item)
{
2015-03-31 08:47:55 +02:00
if ($item['name'] == $name)
{
2015-03-31 08:47:55 +02:00
$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;
2016-06-17 11:08:25 +02:00
file_put_contents($file, "$fluxBasePath IN_CLOSE_WRITE php /home/flux/current/send.php --file $@/$# >> /home/log/send.log 2>&1");
2015-03-31 08:47:55 +02:00
echo "File created $file\n";
}
}
}
2015-03-31 08:47:55 +02:00
}
2015-10-13 11:41:19 +02:00
2015-03-31 08:47:55 +02:00
if ($opts->read) {
2015-10-13 11:41:19 +02:00
2015-03-31 08:47:55 +02:00
$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';
2016-06-17 11:08:25 +02:00
file_put_contents($file, "$fluxBasePath IN_ACCESS php /home/flux/current/read.php --file $@/$# >> /home/log/read.log 2>&1");
2015-03-31 08:47:55 +02:00
echo "File created $file\n";
}
}
}
2015-10-13 11:41:19 +02:00
2015-03-31 08:47:55 +02:00
}
2015-10-13 11:41:19 +02:00
echo "Put the file to /etc/incron.d and restart incron.\n";
echo "Generate Ended.\n";
2015-10-13 11:41:19 +02:00
}