Пример #1
0
 public function setDwcArr($dwcObj)
 {
     $recArr = json_decode($dwcObj, true);
     if ($recArr) {
         $recArr = array_change_key_case($recArr);
         //Translate fields
         foreach ($this->fieldTranslation as $otherName => $symbName) {
             if (array_key_exists($otherName, $recArr) && !array_key_exists($symbName, $recArr)) {
                 $recArr[$symbName] = $recArr[$otherName];
                 unset($recArr[$otherName]);
             }
         }
         //Filter out unapproved fields
         $recArr = array_intersect_key($recArr, array_flip($this->approvedFields));
         $this->dwcArr = OccurrenceUtilities::occurrenceArrayCleaning($recArr);
         if ($this->dwcArr) {
             return true;
         }
     }
     return false;
 }
Пример #2
0
 protected function loadRecord($recMap)
 {
     //Only import record if at least one of the minimal fields have data
     if (array_key_exists('dbpk', $recMap) && $recMap['dbpk'] || array_key_exists('catalognumber', $recMap) && $recMap['catalognumber'] || array_key_exists('recordedby', $recMap) && $recMap['recordedby'] || array_key_exists('eventdate', $recMap) && $recMap['eventdate'] || array_key_exists('locality', $recMap) && $recMap['locality'] || array_key_exists('sciname', $recMap) && $recMap['sciname'] || array_key_exists('scientificname', $recMap) && $recMap['scientificname']) {
         $recMap = OccurrenceUtilities::occurrenceArrayCleaning($recMap);
         //Remove institution and collection codes when they match what is in omcollections
         if (array_key_exists('institutioncode', $recMap) && $recMap['institutioncode'] == $this->collMetadataArr["institutioncode"]) {
             unset($recMap['institutioncode']);
         }
         if (array_key_exists('collectioncode', $recMap) && $recMap['collectioncode'] == $this->collMetadataArr["collectioncode"]) {
             unset($recMap['collectioncode']);
         }
         //If a DiGIR load, set dbpk value
         if ($this->pKField && array_key_exists($this->pKField, $recMap) && !array_key_exists('dbpk', $recMap)) {
             $recMap['dbpk'] = $recMap[$this->pKField];
         }
         //Do some cleaning on the dbpk; remove leading and trailing whitespaces and convert multiple spaces to a single space
         if (array_key_exists('dbpk', $recMap)) {
             $recMap['dbpk'] = trim(preg_replace('/\\s\\s+/', ' ', $recMap['dbpk']));
         }
         //Temporarily code until Specify output UUID as occurrenceID
         if ($this->sourceDatabaseType == 'specify' && (!isset($recMap['occurrenceid']) || !$recMap['occurrenceid'])) {
             if (strlen($recMap['dbpk']) == 36) {
                 $recMap['occurrenceid'] = $recMap['dbpk'];
             }
         }
         $sqlFragments = $this->getSqlFragments($recMap, $this->fieldMap);
         $sql = 'INSERT INTO uploadspectemp(collid' . $sqlFragments['fieldstr'] . ') ' . 'VALUES(' . $this->collId . $sqlFragments['valuestr'] . ')';
         //echo "<div>SQL: ".$sql."</div>";
         if ($this->conn->query($sql)) {
             $this->transferCount++;
             if ($this->transferCount % 1000 == 0) {
                 $this->outputMsg('<li style="margin-left:10px;">Count: ' . $this->transferCount . '</li>');
             }
             ob_flush();
             flush();
             //$this->outputMsg("<li>");
             //$this->outputMsg("Appending/Replacing observation #".$this->transferCount.": SUCCESS");
             //$this->outputMsg("</li>");
         } else {
             $this->outputMsg("<li>FAILED adding record #" . $this->transferCount . "</li>");
             $this->outputMsg("<li style='margin-left:10px;'>Error: " . $this->conn->error . "</li>");
             $this->outputMsg("<li style='margin:0px 0px 10px 10px;'>SQL: {$sql}</li>");
         }
     }
 }