function uploadBiocaseFile($db, $xml, $reindex = FALSE, $diagnostics = FALSE, $resourceid = FALSE)
{
    $doc = new DOMDocument();
    $doc->loadXML($xml);
    //get config
    $config = array();
    $config['core'] = array();
    $handle = fopen('config/config_avh_db_core.csv', 'r');
    while (!feof($handle)) {
        $config['core'][] = fgetcsv($handle);
    }
    fclose($handle);
    $config['extension'] = array();
    $handle = fopen('config/config_avh_db_extension.csv', 'r');
    while (!feof($handle)) {
        $config['extension'][] = fgetcsv($handle);
    }
    fclose($handle);
    if ($diagnostics && $resourceid) {
        $diag = new BiocaseDiagnostic($db, $doc, $resourceid);
        $diag->diagnose();
    }
    $data = array();
    $dehispidator = new Hispid5ToCsv();
    $data['core'] = $dehispidator->parseHISPID5($doc);
    $data['extension'] = $dehispidator->DeterminationHistory($doc);
    $upload = new AvhDb($db, $data, $config);
    $upload->uploadCoreData($reindex);
}
Ejemplo n.º 2
0
 public function harvest()
 {
     $biocase = new BioCase($this->resourceurl, $this->resourcedsa, $this->resourceschema);
     $result = $biocase->biocaseCount();
     $doc = new DOMDocument('1.0', 'UTF-8');
     $doc->loadXML($result);
     $list = $doc->getElementsByTagName('count');
     $recordCount = $list->item(0)->nodeValue;
     if ($recordCount) {
         fwrite($this->log, date('Y-m-d H:i:s') . "\t" . str_pad($this->resource . ':', 6, ' ', STR_PAD_RIGHT) . "\t" . $recordCount . "\n");
         $offset = $this->offset;
         $date = date('Y-m-d');
         //get config
         $config = array();
         $config['core'] = array();
         $handle = fopen('config/config_avh_db_core.csv', 'r');
         while (!feof($handle)) {
             $config['core'][] = fgetcsv($handle);
         }
         fclose($handle);
         $config['extension'] = array();
         $handle = fopen('config/config_avh_db_extension.csv', 'r');
         while (!feof($handle)) {
             $config['extension'][] = fgetcsv($handle);
         }
         fclose($handle);
         while ($offset <= $recordCount) {
             $biocase = new BioCase($this->resourceurl, $this->resourcedsa, $this->resourceschema, $this->resourcelastupdated, $offset, $this->limit);
             $xml = $biocase->bulkHarvest();
             $filename = 'xml/' . $this->resource . '_' . $date . '_' . str_pad($offset, 7, '0', STR_PAD_LEFT) . '.xml';
             file_put_contents($filename, $xml);
             $doc = new DOMDocument('1.0', 'UTF-8');
             $doc->loadXML($xml);
             $diag = new BiocaseDiagnostic($this->db, $doc, $this->resourceid);
             $diag->diagnose();
             if ($this->resource == 'AD') {
                 $doc = new DOMDocument('1.0', 'UTF-8');
                 $xml = substr($xml, strpos($xml, '<DataSet>'));
                 $xml = substr($xml, 0, strpos($xml, '</DataSet>') + strlen('</DataSets>'));
                 $doc->loadXML($xml);
             }
             $data = array();
             $dehispidator = new Hispid5ToCsv();
             $data['core'] = $dehispidator->parseHISPID5($doc);
             $data['extension'] = $dehispidator->DeterminationHistory($doc);
             $upload = new AvhDb($this->db, $data, $config);
             $upload->uploadCoreData(TRUE);
             $upload->uploadExtensionData();
             $offset += $this->limit;
         }
         $select = "SELECT MAX(modified) FROM core WHERE \"institutionCode\"=?";
         $selStmt = $this->db->prepare($select);
         $selStmt->execute(array($this->resource));
         $r = $selStmt->fetch(PDO::FETCH_NUM);
         $lastModified = $r[0];
         $update = "UPDATE resource\n                SET date_last_queried=?\n                WHERE resource_id=?";
         $updStmt = $this->db->prepare($update);
         $updStmt->execute(array($lastModified, $this->resourceid));
     } else {
         fwrite($this->log, date('Y-m-d H:i:s') . "\t" . str_pad($this->resource . ':', 6, ' ', STR_PAD_RIGHT) . "\t0\n");
     }
 }