Example #1
0
 /**
  * This method works only if your PHP is compiled with cURL.
  *
  * @see DataBackend::update()
  * @throws DataBackendIOException
  * @throws FileException
  * @throws DownloaderException
  */
 public function update()
 {
     $downloader = new Downloader();
     $content = $downloader->downloadContent(self::DOWNLOAD_URI);
     $uriPicker = new FallbackURIPicker();
     $path = $uriPicker->pickURI($content);
     if (strlen($path) > 0 && $path[0] != "/") {
         $path = sprintf("/%s/%s", dirname(self::DOWNLOAD_URI), $path);
     }
     $pathParts = explode('/', $path);
     foreach ($pathParts as $i => $part) {
         switch ($part) {
             case '..':
                 unset($pathParts[$i - 1]);
                 // fall-through as the current part ("..") should be removed as well.
             // fall-through as the current part ("..") should be removed as well.
             case '.':
                 unset($pathParts[$i]);
                 break;
         }
     }
     $path = implode('/', $pathParts);
     $urlParts = parse_url(self::DOWNLOAD_URI);
     $url = sprintf("%s://%s%s", $urlParts["scheme"], $urlParts["host"], $path);
     // download file
     $file = $downloader->downloadFile($url);
     // Validate file format.
     $validator = new FileValidator();
     $validator->validate($file);
     // blz_20100308.txt is not sorted.
     $parser = new FileParser($file);
     $lastBankID = $parser->getBankID($parser->getLines());
     if ($lastBankID < 80000000) {
         $this->sortFile($file);
     }
     $this->fileUtil->safeRename($file, $this->parser->getFile());
     chmod($this->parser->getFile(), 0644);
 }
Example #2
0
 public function update()
 {
     $this->em->transactional(function (EntityManager $em) {
         // Download data
         $fileUtil = new FileUtil();
         $fileBackend = new FileDataBackend(tempnam($fileUtil->getTempDirectory(), 'bav'));
         $fileBackend->install();
         // Delete all
         $em->createQuery("DELETE FROM malkusch\\bav\\Agency")->execute();
         $em->createQuery("DELETE FROM malkusch\\bav\\Bank")->execute();
         // Inserting data
         foreach ($fileBackend->getAllBanks() as $bank) {
             try {
                 $em->persist($bank);
                 $agencies = $bank->getAgencies();
                 $agencies[] = $bank->getMainAgency();
                 foreach ($agencies as $agency) {
                     $em->persist($agency);
                 }
             } catch (NoMainAgencyException $e) {
                 trigger_error("Skipping bank {$e->getBank()->getBankID()} without any main agency.");
             }
         }
         // last modified
         $lastModified = $em->find("malkusch\\bav\\MetaData", MetaData::LASTMODIFIED);
         if ($lastModified == null) {
             $lastModified = new MetaData();
         }
         $lastModified->setName(MetaData::LASTMODIFIED);
         $lastModified->setValue(time());
         $em->persist($lastModified);
     });
 }