90 lines
2.4 KiB
PHP
90 lines
2.4 KiB
PHP
#!/usr/bin/php
|
|
<?php
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
// Durée maximale du script
|
|
$dureeMaxi = 300; // secondes (soit 5 minutes)
|
|
// Interval entre chaque tentative de récupération des Kbis sur le FTP
|
|
$dureeInterval = 5; // secondes
|
|
set_time_limit(($dureeMaxi+10));
|
|
|
|
error_reporting(E_ALL & ~E_NOTICE);
|
|
|
|
// Define path to application directory
|
|
defined('APPLICATION_PATH')
|
|
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
|
|
|
|
// Define application environment
|
|
defined('APPLICATION_ENV')
|
|
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
|
|
|
// 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.',
|
|
)
|
|
);
|
|
$opts->parse();
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
echo $e->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
//Usage
|
|
if(isset($opts->help))
|
|
{
|
|
echo $opts->getUsageMessage();
|
|
echo "\n";
|
|
echo basename($argv[0]). " BASE FICHIER.SQL FICHIER.CSV\n";
|
|
echo "Génération d'un fichier CSV à partir d'un fichier SQL sur la BASE en paramètre.";
|
|
exit;
|
|
}
|
|
elseif (count($opts)==1 && $argc==4)
|
|
{
|
|
require_once realpath(dirname(__FILE__)).'/../config/config.php';
|
|
require_once 'framework/fwk.php';
|
|
require_once 'framework/common/chiffres.php';
|
|
require_once 'framework/common/dates.php';
|
|
require_once 'framework/mail/sendMail.php';
|
|
require_once 'Metier/insee/classMInsee.php';
|
|
require_once 'Metier/partenaires/classMGreffes.php';
|
|
require_once 'Metier/partenaires/classMBilans.php';
|
|
|
|
$base = $argv[1];
|
|
$sql = $argv[2];
|
|
$csv = $argv[3];
|
|
|
|
$heureDemande = date('Hi');
|
|
|
|
$iDb = new WDB($base);
|
|
$nbLignes = $iDb->exportCSV(file_get_contents($sql), $csv.'.tmp');
|
|
$fp = fopen("./csv2sql.log", 'a');
|
|
fwrite($fp, date('Y-m-d H:i:s')." - $base $sql $csv : $nbLignes lignes extraites".EOL);
|
|
fclose($fp);
|
|
move($csv.'.tmp', $csv);
|
|
exit;
|
|
} else {
|
|
echo "Erreur !\n";
|
|
}
|
|
|
|
|
|
|
|
|
|
|