Guest User

Untitled

a guest
Apr 27th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <?php
  2.  
  3. define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));
  4. define('SF_APP', 'frontend');
  5. define('SF_ENVIRONMENT', 'prod');
  6. define('SF_DEBUG', false);
  7.  
  8. require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
  9.  
  10. // initialize database manager
  11. $databaseManager = new sfDatabaseManager();
  12. $databaseManager->initialize();
  13.  
  14. $sites = array('fr', 'ge', 'vd', 'vs');
  15.  
  16. $l = fopen(dirname(__FILE__).'/log/printer_import.log', 'w');
  17.  
  18. foreach($sites AS $site)
  19. {
  20. echo "$site\n";
  21. $file = dirname(__FILE__).'/printers/'.'printers_' . $site .'.conf';
  22. if(file_exists($file))
  23. {
  24. // Initialisation du tableau des imprimantes
  25. $a_printers = array();
  26. $a_locations = array();
  27.  
  28. fwrite($l, "--------------------\n");
  29. fwrite($l, "$site\n");
  30. fwrite($l, "--------------------\n");
  31.  
  32. echo "Importation du fichier $file\n";
  33. $content = file_get_contents($file);
  34. $printers = split("\n", $content);
  35. foreach($printers AS $printer)
  36. {
  37. if(substr($printer,0,1) != '#')
  38. {
  39. if(strlen($printer) > 3)
  40. {
  41. list($id, $name, $default) = split("\t", $printer);
  42. echo "$id :: $name :: $default\n";
  43. if(!array_key_exists($name, $a_printers))
  44. {
  45.  
  46. // Insertion dans la base de données
  47. $p = new Printer();
  48. $p->setSite($site);
  49. $p->setCode($name);
  50. $p->setName($name);
  51. $p->save();
  52.  
  53. $a_printers[$name] = $p->getId();
  54. }
  55.  
  56. $c = new Criteria();
  57. $c->add(LocationPeer::SITE, $site);
  58. $c->addAnd(LocationPeer::LOCATION_ID, $id);
  59. $location = LocationPeer::doSelectOne($c);
  60. if($location)
  61. {
  62. if($location->getParam1())
  63. {
  64. $message = $location->getLocationId() . ' '. $location->getOriginalName() . ' / ' . $name . ' (' . $a_printers[$name] . ')' . "\n";
  65. echo $message;
  66. $location->setPrinterId($a_printers[$name]);
  67. if(strtolower($default) == 'default')
  68. {
  69. $location->setPrinterDefault(1);
  70. }
  71. $location->save();
  72. fwrite($l, $message);
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
  80. print "Fin de l'opération\n";
  81. fclose($l);
Add Comment
Please, Sign In to add comment