webservice/scripts/build/genLog.php
2016-09-30 16:01:35 +02:00

88 lines
2.7 KiB
PHP

<?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');
// --- Options
$displayUsage = false;
try {
$opts = new Zend_Console_Getopt(array(
'help|?' => "Aide.",
'log' => "",
));
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
$displayUsage = true;
}
// --- Aide / Options
if (count($opts->getOptions())==0 || isset($opts->help)) {
$displayUsage = true;
}
// --- Usage
if ($displayUsage) {
echo "\nLog\n\n";
echo $opts->getUsageMessage();
exit;
}
if ($opts->log) {
// Database
$c = new Zend_Config($this->getOptions());
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array(
'dbname' => $c->profil->db->metier->params->dbname,
'user' => $c->profil->db->metier->params->username,
'password' => $c->profil->db->metier->params->password,
'host' => $c->profil->db->metier->params->host,
'charset' => 'utf8',
'driver' => 'pdo_mysql',
);
try {
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
} catch (\Doctrine\DBAL\DBALException $e) {
echo "Connection Database impossible.\n";
exit;
}
$sql = "SELECT * FROM sdv1.logs_item";
$stmt = $conn->prepare($sql);
$stmt->execute();
$outPath = APPLICATION_PATH . '/../library/Scores/Account/Log/List.php';
$outFile = $outPath . '/Config.php';
if ($stmt->rowCount() > 0) {
$result = $stmt->fetchAll(\PDO::FETCH_OBJ);
file_put_contents($outFile, "<?php\n");
file_put_contents($outFile, "/* Auto generated ".date('Y-m-d H:i:s')." */\n");
file_put_contents($outFile, "return array(\n", FILE_APPEND);
foreach ($result as $c) {
file_put_contents($outFile, "\t'". $c->Code . "' => array(,\n", FILE_APPEND);
file_put_contents($outFile, "\t\t'Label' => ". $c->Label . ",\n", FILE_APPEND);
file_put_contents($outFile, "\t\'Description' => ". $c->Description . ",\n", FILE_APPEND);
file_put_contents($outFile, "\t\t'Category' => ". $c->Category . ",\n", FILE_APPEND);
file_put_contents($outFile, "\t),\n", FILE_APPEND);
}
file_put_contents($outFile, ");\n", FILE_APPEND);
}
}