flux/fileRecv.php
2013-08-28 10:23:01 +00:00

100 lines
2.5 KiB
PHP

<?php
/**
* SD => Client
* Attention le script doit s'executer avec l'utilisateur root, afin de lire le fichier même
* s'il n'a pas les droits
*/
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
try {
$opts = new Zend_Console_Getopt(
//Options
array(
'help|?' => "Displays usage information.",
'file=s' => "Manually define the file to process",
'client=s' => "Define the client name for getting the file manually",
'debug' => "Send a mail for debug",
)
);
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
//Usage
if( isset($opts->help) || count($opts->getOptions())==0 )
{
echo "Place files in right directory for sending to the customer.\n";
echo $opts->getUsageMessage();
exit;
}
$c = new Zend_Config($application->getOptions());
$db = Zend_Db::factory($c->profil->metier);
Zend_Db_Table::setDefaultAdapter($db);
$fluxM = new Application_Model_Sv1FluxFileOut();
$sql = $fluxM->select()->where('dateEnd!=?','0000-00-00 00:00:00');
//Get specific file
if ( isset($opts->file) && isset($opts->client) ) {
$sql->where('client=?', $opts->client)
->where('fileOut=?', $opts->file);
} else {
$sql->where('dateEnd!=?', '0000-00-00 00:00:00');
$sql->where('depotDate=?', '0000-00-00 00:00:00');
}
$result = $fluxM->fetchAll($sql);
if ( $result->count() > 0 ) {
foreach ( $result as $item ) {
$source = $c->profil->path->storage .
DIRECTORY_SEPARATOR . $item->client .
DIRECTORY_SEPARATOR . 'recv' .
DIRECTORY_SEPARATOR . $item->fileOut;
switch ($item->typeDepot) {
case 'FTP':
$dest = $c->profil->path->ftp .
DIRECTORY_SEPARATOR . $item->client .
DIRECTORY_SEPARATOR . 'recv' .
DIRECTORY_SEPARATOR . $item->fileOut;
break;
case 'SFTP':
$dest = $c->profil->path->sftp .
DIRECTORY_SEPARATOR . $item->client .
DIRECTORY_SEPARATOR . 'recv' .
DIRECTORY_SEPARATOR . $item->fileOut;
break;
}
if ( copy($source, $dest) ) {
$fluxM->update(array(
'depotDate' => date('YmdHis'),
), 'id='.$item->id);
}
}
}