コード例 #1
0
 /**
  * Import Kloster table into the FLOW domain_model tabel subugoe_germaniasacra_domain_model_kloster
  * @return int
  */
 public function importKlosterAction()
 {
     if ($this->logger) {
         $start = microtime(true);
     }
     /** @var \Doctrine\DBAL\Connection $sqlConnection */
     $sqlConnection = $this->entityManager->getConnection();
     $tbl = 'subugoe_germaniasacra_domain_model_urltyp';
     $sql = 'SELECT * FROM ' . $tbl . ' WHERE name = "Quelle"';
     $urltyp = $sqlConnection->fetchAll($sql);
     if (count($urltyp) > 0) {
         $urltypUUID = $urltyp[0]['persistence_object_identifier'];
     }
     if (!isset($urltypUUID)) {
         $urlTypeName = "Quelle";
         $urltypObject = new Urltyp();
         $urltypObject->setName($urlTypeName);
         $this->urltypRepository->add($urltypObject);
         $this->persistenceManager->persistAll();
         $urltypUUID = $urltypObject->getUUID();
     }
     $sql = 'SELECT * FROM ' . $tbl . ' WHERE name = "GND"';
     $gndurltyp = $sqlConnection->fetchAll($sql);
     if (count($gndurltyp) > 0) {
         $gndurltypUUID = $gndurltyp[0]['persistence_object_identifier'];
     }
     if (!isset($gndurltypUUID)) {
         $gndurlTypeName = "GND";
         $urltypObject = new Urltyp();
         $urltypObject->setName($gndurlTypeName);
         $this->urltypRepository->add($urltypObject);
         $this->persistenceManager->persistAll();
         $gndurltypUUID = $urltypObject->getUUID();
     }
     $sql = 'SELECT * FROM ' . $tbl . ' WHERE name = "Wikipedia"';
     $wikiurltyp = $sqlConnection->fetchAll($sql);
     if (count($wikiurltyp) > 0) {
         $wikiurltypUUID = $wikiurltyp[0]['persistence_object_identifier'];
     }
     if (!isset($wikiurltypUUID)) {
         $wikiurlTypeName = "Wikipedia";
         $urltypObject = new Urltyp();
         $urltypObject->setName($wikiurlTypeName);
         $this->urltypRepository->add($urltypObject);
         $this->persistenceManager->persistAll();
         $wikiurltypUUID = $urltypObject->getUUID();
     }
     $sql = 'SELECT * FROM Kloster ORDER BY Klosternummer ASC';
     $klosters = $sqlConnection->fetchAll($sql);
     if (isset($klosters) and is_array($klosters)) {
         $nKloster = 0;
         foreach ($klosters as $key => $kloster) {
             $uid = $kloster['Klosternummer'];
             $numberOfKloster = count($this->klosterRepository->findOneByKloster_id($uid));
             if ($numberOfKloster == 0) {
                 $wikipedia = $kloster['Wikipedia'];
                 $gnd = $kloster['GND'];
                 $hauptRessource = $kloster['HauptRessource'];
                 $bearbeitungsstand = $kloster['Bearbeitungsstand'];
                 $patrozinium = $kloster['Patrozinium'];
                 $bemerkung = $kloster['Bemerkungen'];
                 $creationdate = $kloster['Datensatz_angelegt'];
                 $bearbeiter = trim($kloster['Bearbeiter']);
                 $bearbeitungsstatus = trim($kloster['Status']);
                 $personallistenstatus = trim($kloster['Personallisten']);
                 if (!empty($bearbeiter)) {
                     /** @var Bearbeiter $bearbeiterObject */
                     $bearbeiterObject = $this->bearbeiterRepository->findOneByUid($bearbeiter);
                     if (!empty($bearbeitungsstatus)) {
                         /** @var Bearbeitungsstatus $bearbeitungsstatusObject */
                         $bearbeitungsstatusObject = $this->bearbeitungsstatusRepository->findOneByName($bearbeitungsstatus);
                         if (!empty($personallistenstatus)) {
                             /** @var Personallistenstatus $personallistenstatusObject */
                             $personallistenstatusObject = $this->personallistenstatusRepository->findOneByName($personallistenstatus);
                             $band = $kloster['GermaniaSacraBandNr'];
                             $band_seite = $kloster['GSBandSeite'];
                             $text_gs_band = $kloster['TextGSBand'];
                             $kloster = $kloster['Klostername'];
                             $klosterObject = new Kloster();
                             $klosterObject->setUid($uid);
                             if (is_object($bearbeiterObject)) {
                                 $klosterObject->setBearbeiter($bearbeiterObject);
                             }
                             if (is_object($bearbeitungsstatusObject) and $bearbeitungsstatusObject->getName() !== null) {
                                 $klosterObject->setBearbeitungsstatus($bearbeitungsstatusObject);
                             } else {
                                 $result = $this->bearbeitungsstatusRepository->findLastEntry();
                                 if (count($result) === 1) {
                                     foreach ($result as $res) {
                                         $lastBearbeitungsstatusEntry = $res->getUid();
                                     }
                                     $bearbeitungsstatusUid = $lastBearbeitungsstatusEntry + 1;
                                 } else {
                                     $bearbeitungsstatusUid = 1;
                                 }
                                 $bearbeitungsstatusObject = new Bearbeitungsstatus();
                                 $bearbeitungsstatusObject->setUid($bearbeitungsstatusUid);
                                 $bearbeitungsstatusObject->setName($bearbeitungsstatus);
                                 $this->bearbeitungsstatusRepository->add($bearbeitungsstatusObject);
                                 $this->persistenceManager->persistAll();
                                 $bearbeitungsstatusUUID = $bearbeitungsstatusObject->getUUID();
                                 $bearbeitungsstatusObject = $this->bearbeitungsstatusRepository->findByIdentifier($bearbeitungsstatusUUID);
                                 $klosterObject->setBearbeitungsstatus($bearbeitungsstatusObject);
                                 $this->importExportLogger->log('Bearbeitungsstatus "' . $bearbeitungsstatus . '" fehlte in der Bearbeitungsstatustabelle. Er ist nun hinzugefügt. Kloster-uid: ' . $klosterObject->getUid(), LOG_INFO);
                             }
                             if (is_object($personallistenstatusObject)) {
                                 $klosterObject->setPersonallistenstatus($personallistenstatusObject);
                             }
                             $klosterObject->setKloster_id($uid);
                             $klosterObject->setKloster($kloster);
                             $klosterObject->setPatrozinium($patrozinium);
                             $klosterObject->setBemerkung($bemerkung);
                             if (null !== $band) {
                                 /** @var Band $bandObject */
                                 $bandObject = $this->bandRepository->findOneByUid($band);
                                 $klosterObject->setBand($bandObject);
                                 $klosterObject->setBand_seite($band_seite);
                                 $klosterObject->setText_gs_band($text_gs_band);
                             }
                             $klosterObject->setBearbeitungsstand($bearbeitungsstand);
                             $klosterObject->setcreationDate(new \DateTime($creationdate));
                             $this->klosterRepository->add($klosterObject);
                             $this->persistenceManager->persistAll();
                             $klosterUUID = $klosterObject->getUUID();
                             if ($hauptRessource) {
                                 $parts = explode("#", $hauptRessource);
                                 if (count($parts) > 1) {
                                     $urlTypeName = "Quelle";
                                     if (!isset($urltypUUID)) {
                                         $urltypObject = new Urltyp();
                                         $urltypObject->setName($urlTypeName);
                                         $this->urltypRepository->add($urltypObject);
                                         $this->persistenceManager->persistAll();
                                         $urltypUUID = $urltypObject->getUUID();
                                     }
                                     foreach ($parts as $k => $value) {
                                         if (!($k % 2)) {
                                             if (!empty($value)) {
                                                 $urlBemerkung = $value;
                                             }
                                         }
                                         if ($k % 2) {
                                             if (!empty($value)) {
                                                 $url = $value;
                                             }
                                         }
                                         if (isset($url) && !empty($url)) {
                                             $urlObject = new Url();
                                             $urlObject->setUrl($url);
                                             $urlObject->setBemerkung($urlBemerkung);
                                             /** @var UrlTyp $urltypObject */
                                             $urltypObject = $this->urltypRepository->findByIdentifier($urltypUUID);
                                             $urlObject->setUrltyp($urltypObject);
                                             $this->urlRepository->add($urlObject);
                                             $this->persistenceManager->persistAll();
                                             $urlUUID = $urlObject->getUUID();
                                             $klosterhasurlObject = new Klosterhasurl();
                                             /** @var Kloster $klosterObject */
                                             $klosterObject = $this->klosterRepository->findByIdentifier($klosterUUID);
                                             $klosterhasurlObject->setKloster($klosterObject);
                                             /** @var Url $urlObject */
                                             $urlObject = $this->urlRepository->findByIdentifier($urlUUID);
                                             $klosterhasurlObject->setUrl($urlObject);
                                             $this->klosterHasUrlRepository->add($klosterhasurlObject);
                                             $this->persistenceManager->persistAll();
                                         }
                                         if (isset($url)) {
                                             unset($url);
                                         }
                                     }
                                 }
                             }
                             if (isset($gnd) && !empty($gnd)) {
                                 $gnd = str_replace("\t", " ", $gnd);
                                 $gnd = str_replace("http:// ", " ", $gnd);
                                 $gnd = str_replace(" http", ";http", $gnd);
                                 $gnd = str_replace(";", "#", $gnd);
                                 $gnds = explode("#", $gnd);
                                 if (isset($gnds) && is_array($gnds)) {
                                     $oldgnd = "";
                                     foreach ($gnds as $gnd) {
                                         if (isset($gnd) && !empty($gnd)) {
                                             if ($gnd != $oldgnd) {
                                                 $gnd = str_replace(" ", "", $gnd);
                                                 $gnd = str_replace("# ", "", $gnd);
                                                 $gndid = str_replace("http://d-nb.info/gnd/", "", $gnd);
                                                 $gndbemerkung = $kloster . " [" . $gndid . "]";
                                                 $urlObject = new Url();
                                                 $urlObject->setUrl($gnd);
                                                 $urlObject->setBemerkung($gndbemerkung);
                                                 /** @var UrlTyp $gndurltypObject */
                                                 $gndurltypObject = $this->urltypRepository->findByIdentifier($gndurltypUUID);
                                                 $urlObject->setUrltyp($gndurltypObject);
                                                 $this->urlRepository->add($urlObject);
                                                 $this->persistenceManager->persistAll();
                                                 $gndurlUUID = $urlObject->getUUID();
                                                 $oldgnd = $gnd;
                                                 $klosterhasurlObject = new Klosterhasurl();
                                                 /** @var Kloster $klosterObject */
                                                 $klosterObject = $this->klosterRepository->findByIdentifier($klosterUUID);
                                                 $klosterhasurlObject->setKloster($klosterObject);
                                                 /** @var Url $gndurlObject */
                                                 $gndurlObject = $this->urlRepository->findByIdentifier($gndurlUUID);
                                                 $klosterhasurlObject->setUrl($gndurlObject);
                                                 $this->klosterHasUrlRepository->add($klosterhasurlObject);
                                                 $this->persistenceManager->persistAll();
                                             }
                                         }
                                     }
                                 }
                             }
                             if (isset($wikipedia) && !empty($wikipedia)) {
                                 $wikipedia = str_replace("http:// ", " ", $wikipedia);
                                 $wikipedia = str_replace(";", "#", $wikipedia);
                                 $wikipedias = explode("#", $wikipedia);
                                 if (isset($wikipedias) && is_array($wikipedias)) {
                                     $oldwikipedia = "";
                                     foreach ($wikipedias as $wikipedia) {
                                         if (isset($wikipedia) && !empty($wikipedia)) {
                                             if ($wikipedia != $oldwikipedia) {
                                                 $wikipediabemerkung = str_replace("http://de.wikipedia.org/wiki/", "", $wikipedia);
                                                 $wikipediabemerkung = str_replace("_", " ", $wikipediabemerkung);
                                                 $wikipediabemerkung = rawurldecode($wikipediabemerkung);
                                                 $urlObject = new Url();
                                                 $urlObject->setUrl($wikipedia);
                                                 $urlObject->setBemerkung($wikipediabemerkung);
                                                 $wikiurltypObject = $this->urltypRepository->findByIdentifier($wikiurltypUUID);
                                                 $urlObject->setUrltyp($wikiurltypObject);
                                                 $this->urlRepository->add($urlObject);
                                                 $this->persistenceManager->persistAll();
                                                 $wikiurlUUID = $urlObject->getUUID();
                                                 $oldwikipedia = $wikipedia;
                                                 $klosterhasurlObject = new Klosterhasurl();
                                                 $klosterObject = $this->klosterRepository->findByIdentifier($klosterUUID);
                                                 $klosterhasurlObject->setKloster($klosterObject);
                                                 $wikiurlObject = $this->urlRepository->findByIdentifier($wikiurlUUID);
                                                 $klosterhasurlObject->setUrl($wikiurlObject);
                                                 $this->klosterHasUrlRepository->add($klosterhasurlObject);
                                                 $this->persistenceManager->persistAll();
                                             }
                                         }
                                     }
                                 }
                             }
                         } else {
                             $this->importExportLogger->log('Personallistenstatus zum Kloster ' . $uid . ' fehlt.', LOG_ERR);
                         }
                     } else {
                         $this->importExportLogger->log('Bearbeitungsstatus zum Kloster ' . $uid . ' fehlt.', LOG_ERR);
                         if (empty($personallistenstatus)) {
                             $this->importExportLogger->log('Personallistenstatus zum Kloster ' . $uid . ' fehlt.', LOG_ERR);
                         }
                     }
                 } else {
                     $this->importExportLogger->log('Bearbeiter zum Kloster ' . $uid . ' fehlt.', LOG_ERR);
                     if (empty($bearbeitungsstatus)) {
                         $this->importExportLogger->log('Bearbeitungsstatus zum Kloster ' . $uid . ' fehlt.', LOG_ERR);
                     }
                     if (empty($personallistenstatus)) {
                         $this->importExportLogger->log('Personallistenstatus zum Kloster ' . $uid . ' fehlt.', LOG_ERR);
                     }
                 }
                 $nKloster++;
             } else {
                 $this->importExportLogger->log('Doppelter Eintrag mit der Id = ' . $uid . ' in Klostertabelle. Der 2. Eintrag wurde ausgelassen.', LOG_ERR);
             }
             if (empty($uid)) {
                 $this->importExportLogger->log('Das Kloster ' . $kloster . ' hat keine Klosternummer.', LOG_ERR);
             }
         }
         if ($this->logger) {
             $end = microtime(true);
             $time = number_format($end - $start, 2);
             $this->logger->log('Kloster import completed in ' . round($time / 60, 2) . ' minutes.');
         }
         return $nKloster;
     }
 }
コード例 #2
0
 /** Updates the list of Kloster
  * @FLOW\SkipCsrfProtection
  * @return int $status http status
  */
 public function updateListAction()
 {
     if ($this->request->hasArgument('data')) {
         $klosterlist = $this->request->getArgument('data');
     }
     if (empty($klosterlist)) {
         $this->throwStatus(400, 'Required data arguemnts not provided', null);
     }
     $role = array_keys($this->securityContext->getAccount()->getRoles())[0];
     if (trim($role) == 'Flow.Login:Hiwi') {
         if (is_array($klosterlist) && !empty($klosterlist)) {
             $error = 0;
             foreach ($klosterlist as $k => $v) {
                 $bearbeitungsstatus = $this->bearbeitungsstatusRepository->findByIdentifier($v['bearbeitungsstatus']);
                 if (is_object($bearbeitungsstatus)) {
                     $bearbeitungsstatusName = $bearbeitungsstatus->getName();
                 }
                 if (isset($bearbeitungsstatusName) && !empty($bearbeitungsstatusName)) {
                     if (trim($bearbeitungsstatusName) == 'Online') {
                         $error++;
                     }
                 }
             }
         }
         if ($error > 0) {
             $this->throwStatus(400, 'You are not allowed to set a Kloster entry online', null);
         }
     }
     if (is_array($klosterlist) && !empty($klosterlist)) {
         foreach ($klosterlist as $k => $v) {
             $klosterObject = $this->klosterRepository->findByIdentifier((string) $k);
             $klosterObject->setKloster($v['kloster']);
             $bearbeitungsstatusObject = $this->bearbeitungsstatusRepository->findByIdentifier($v['bearbeitungsstatus']);
             $klosterObject->setBearbeitungsstatus($bearbeitungsstatusObject);
             $klosterObject->setBearbeitungsstand($v['bearbeitungsstand']);
             $this->klosterRepository->update($klosterObject);
             $gndAlreadyExists = false;
             $klosterHasUrls = $klosterObject->getKlosterHasUrls();
             if (is_object($klosterHasUrls) && count($klosterHasUrls) > 0) {
                 foreach ($klosterHasUrls as $klosterHasUrl) {
                     $urlObject = $klosterHasUrl->getUrl();
                     $urlTypObject = $urlObject->getUrltyp();
                     $urlTyp = $urlTypObject->getName();
                     if ($urlTyp == "GND") {
                         if (!empty($v['gnd'])) {
                             $urlObject->setUrl($v['gnd']);
                             $this->urlRepository->update($urlObject);
                         } elseif (isset($v['gnd']) && empty($v['gnd'])) {
                             $this->klosterHasUrlRepository->remove($klosterHasUrl);
                             $this->urlRepository->remove($urlObject);
                         }
                         $gndAlreadyExists = true;
                     }
                 }
             }
             if (!$gndAlreadyExists) {
                 $urlObject = new Url();
                 $urlObject->setUrl($v['gnd']);
                 $gndid = str_replace('http://d-nb.info/gnd/', '', $v['gnd']);
                 $gndbemerkung = $v['kloster'] . ' [' . $gndid . ']';
                 $urlObject->setBemerkung($gndbemerkung);
                 $urlTypObj = $this->urltypRepository->findOneByName('GND');
                 $urlObject->setUrltyp($urlTypObj);
                 $this->urlRepository->add($urlObject);
                 $klosterhasurl = new KlosterHasUrl();
                 $klosterhasurl->setKloster($klosterObject);
                 $klosterhasurl->setUrl($urlObject);
                 $this->klosterHasUrlRepository->add($klosterhasurl);
             }
         }
         $this->persistenceManager->persistAll();
     }
     $this->throwStatus(200, null, null);
 }