odea/batch/setMinMax.php

89 lines
2.1 KiB
PHP
Raw Normal View History

2012-02-24 12:19:34 +01:00
#!/usr/bin/php
2012-02-20 15:08:13 +01:00
<?php
2012-02-24 12:19:34 +01:00
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
2012-02-20 15:08:13 +01:00
2012-02-24 12:19:34 +01: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 15:08:13 +01:00
$keys = array(
'nbActio','nbPart', 'teff_entrep', 'teff_etab', 'nbEtab',
'eff_entrep', 'eff_etab', 'capital', 'bilEE', 'bilFL', 'bilFK', 'bilFR', 'bilGF',
2012-04-19 11:48:17 +02:00
'bilGP', 'bilGW', 'bilHD', 'bilHH', 'bilHL', 'bilHM', 'bilHN', 'bilYP', 'dateCrea_etab', 'dateCrea_ent',
'dateImmat'
2012-02-20 15:08:13 +01:00
);
2012-02-24 12:19:34 +01:00
$sql = 'TRUNCATE TABLE minmax';
if ( !$db->query($sql) ) {
die ('Impossible de vider la table minmax');
}
2012-02-20 15:08:13 +01:00
foreach($keys as $key) {
2012-02-24 12:19:34 +01:00
//Lecture
2012-02-20 15:08:13 +01:00
$sql = 'SELECT MIN('.$key.') AS min, MAX('.$key.') AS max FROM etablissements_act';
2012-03-05 17:55:26 +01:00
$stmt = $dbMetier->query($sql);
$result = $stmt->fetchObject();
2012-02-24 12:19:34 +01:00
//Insertion
$data = array(
2012-03-05 16:31:31 +01:00
'cle' => $key,
2012-03-05 17:55:26 +01:00
'min' => $result->min,
'max' => $result->max,
2012-02-24 12:19:34 +01:00
);
2012-03-05 17:55:26 +01:00
$db->insert('minmax', $data);
if ($opts->manuel) echo $key.' -> min:'.$result->min.' max:'.$result->max."\n";
2012-02-20 15:08:13 +01:00
}
2012-02-24 12:19:34 +01:00
if ($opts->manuel) print('Terminé');