odea/batch/setMinMax.php

89 lines
2.0 KiB
PHP
Raw Normal View History

2012-02-24 11:19:34 +00:00
#!/usr/bin/php
2012-02-20 14:08:13 +00:00
<?php
2012-02-24 11:19:34 +00:00
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
2012-02-20 14:08:13 +00:00
2012-02-24 11:19:34 +00:00
// Define application environment
define('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|?' => "Aide.",
'cron' => "Mode automatique",
'manuel' => "Mode manuel",
)
);
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
//Usage
if(isset($opts->help))
{
echo $opts->getUsageMessage();
exit;
}
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'databases');
try {
$db = Zend_Db::factory($dbConfig->db);
} catch ( Exception $e ) {
exit ( $e->getMessage() );
}
//Définition bdd metier
try {
$dbMetier = Zend_Db::factory($dbConfig->jo);
} catch ( Exception $e ) {
exit ( $e->getMessage() );
}
2012-02-20 14:08:13 +00:00
$keys = array(
'nbActio','nbPart', 'teff_entrep', 'teff_etab', 'nbEtab',
'eff_entrep', 'eff_etab', 'capital', 'bilEE', 'bilFL', 'bilFK', 'bilFR', 'bilGF',
'bilGP', 'bilGW', 'bilHD', 'bilHH', 'bilHL', 'bilHM', 'bilHN', 'bilYP'
);
2012-02-24 11:19:34 +00:00
$sql = 'TRUNCATE TABLE minmax';
if ( !$db->query($sql) ) {
die ('Impossible de vider la table minmax');
}
2012-02-20 14:08:13 +00:00
foreach($keys as $key) {
2012-02-24 11:19:34 +00:00
//Lecture
2012-02-20 14:08:13 +00:00
$sql = 'SELECT MIN('.$key.') AS min, MAX('.$key.') AS max FROM etablissements_act';
2012-02-24 11:19:34 +00:00
$dbMetier->setFetchMode(Zend_Db::FETCH_ASSOC);
$result = $stmt->fetchAll($sql);
//Insertion
$data = array(
'key' => $key,
'min' => $result['min'],
'max' => $result['max'],
);
$db->insert('minmax', $data);
if ($opts->manuel) print($key.'-> min:'.$result['min'].' max:'.$result['max']."\n");
2012-02-20 14:08:13 +00:00
}
2012-02-24 11:19:34 +00:00
if ($opts->manuel) print('Terminé');