Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));
- define('SF_APP', 'frontend');
- define('SF_ENVIRONMENT', 'prod');
- define('SF_DEBUG', false);
- require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
- // initialize database manager
- $databaseManager = new sfDatabaseManager();
- $databaseManager->initialize();
- $sites = array('fr', 'ge', 'vd', 'vs');
- $l = fopen(dirname(__FILE__).'/log/printer_import.log', 'w');
- foreach($sites AS $site)
- {
- echo "$site\n";
- $file = dirname(__FILE__).'/printers/'.'printers_' . $site .'.conf';
- if(file_exists($file))
- {
- // Initialisation du tableau des imprimantes
- $a_printers = array();
- $a_locations = array();
- fwrite($l, "--------------------\n");
- fwrite($l, "$site\n");
- fwrite($l, "--------------------\n");
- echo "Importation du fichier $file\n";
- $content = file_get_contents($file);
- $printers = split("\n", $content);
- foreach($printers AS $printer)
- {
- if(substr($printer,0,1) != '#')
- {
- if(strlen($printer) > 3)
- {
- list($id, $name, $default) = split("\t", $printer);
- echo "$id :: $name :: $default\n";
- if(!array_key_exists($name, $a_printers))
- {
- // Insertion dans la base de données
- $p = new Printer();
- $p->setSite($site);
- $p->setCode($name);
- $p->setName($name);
- $p->save();
- $a_printers[$name] = $p->getId();
- }
- $c = new Criteria();
- $c->add(LocationPeer::SITE, $site);
- $c->addAnd(LocationPeer::LOCATION_ID, $id);
- $location = LocationPeer::doSelectOne($c);
- if($location)
- {
- if($location->getParam1())
- {
- $message = $location->getLocationId() . ' '. $location->getOriginalName() . ' / ' . $name . ' (' . $a_printers[$name] . ')' . "\n";
- echo $message;
- $location->setPrinterId($a_printers[$name]);
- if(strtolower($default) == 'default')
- {
- $location->setPrinterDefault(1);
- }
- $location->save();
- fwrite($l, $message);
- }
- }
- }
- }
- }
- }
- }
- print "Fin de l'opération\n";
- fclose($l);
Add Comment
Please, Sign In to add comment