array( __DIR__ . '/../../library/Zend/autoload_classmap.php', __DIR__ . '/../../library/Application/autoload_classmap.php', __DIR__ . '/../../library/Scores/autoload_classmap.php', __DIR__ . '/../../application/autoload_classmap.php', ), 'Zend_Loader_StandardAutoloader' => array( 'prefixes' => array( 'Zend' => __DIR__ . '/../../library/Zend', 'Application' => __DIR__ . '/../../library/Application', 'Scores' => __DIR__ . '/../../library/Scores', 'Metier' => __DIR__ . '/../../library/Metier', ), 'fallback_autoloader' => true ) )); // Zend_Application - Use it if you don't have autoloaders //require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $catalogs = array( 'evenements' => array( 'sql' => 'tabEvenements.sql', 'table' => 'tabEvenements', 'method' => array('name'=>'getCatalogEvent', 'params'=> array( null , array('codEven', 'libEven', 'libEvenEn') )) ), 'naf5' => array( 'sql' => 'tabNaf5.sql', 'table' => 'tabNaf5tmp', 'method' => array('name'=>'getCatalogNaf5', 'params'=> array( null , array('codNaf5', 'libNaf5', 'libNaf5en', 'codNaf4', 'codNaf3', 'codNaf2', 'codNaf1') )) ), 'fctdir' => array( 'sql' => 'tabFctDir.sql', 'table' => 'tabFctDir', 'method' => array('name'=>'getCatalogFctDir', 'params'=> array( null , array('codeFct', 'libelle') )) ), 'fj' => array( 'sql' => 'tabFJur.sql', 'table' => 'tabFJur', 'method' => array('name'=>'getCatalogLegalForm', 'params'=> array( null , array('code', 'libelle', 'libelleEn') )) ), 'city' => array( 'sql' => 'tabVilles.sql', 'table' => 'tabVilles', 'method' => array('name'=>'getCatalogCity', 'params'=> array( null , array('codePostal', 'LIBGEO') )) ), ); try { $opts = new Zend_Console_Getopt( //Options array( 'help|?' => "Display this help", 'name=s' => "Name of catalog to load", 'update' => "Only new content", 'list' => "List item", 'login-s' => "Login for the webservice", 'password-s' => "Password " ) ); $opts->parse(); } catch (Zend_Console_Getopt_Exception $e) { echo $e->getUsageMessage(); exit; } //Usage if( isset($opts->help) || count($opts->getOptions())==0 ) { echo $opts->getUsageMessage(); exit; } //Diplay list of catalog to load if ( $opts->list ) { foreach ($catalogs as $item => $options) { echo $item."\n"; } } require_once 'Scores/WsScores.php'; function wsCall($name, $params, $login, $pass) { $ws = new WsScores($login, $pass); return call_user_func_array(array($ws, $name), $params); } function createSql($filename, $db) { $sql = file_get_contents(realpath(dirname(__FILE__)).'/config/_sql/structure/'.$filename); $db->query($sql); } function insertData($data, $table, $db) { $result = $db->insert($table, $data); return $result; } $c = new Zend_Config($application->getOptions()); Zend_Registry::set('config', $c); $db = Zend_Db::factory($c->profil->db->sdv1); if ( array_key_exists($opts->name, $catalogs) ) { $catalog = $catalogs[$opts->name]; $sql = "DROP TABLE IF EXISTS ".$catalog['table'].";"; $db->query($sql); createSql($catalog['sql'], $db); $encode = wsCall($catalog['method']['name'], $catalog['method']['params'], $opts->login, md5($opts->login.'|'.$opts->password)); $rows = json_decode($encode, true); if (count($rows)>0) { foreach ($rows as $row) { insertData($row, $catalog['table'], $db); } } }