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");
     }
 }
     $units = array();
     foreach ($unitIDs as $unit) {
         $units[] = '<value>' . $unit . '</value>';
     }
     $source['Units'] = implode('', $units);
     $sources[] = $source;
 }
 $filter = '<or>';
 foreach ($sources as $source) {
     $filter .= '<and>';
     $filter .= "<equals path='/DataSets/DataSet/Units/Unit/SourceInstitutionID'>" . $source['Name'] . "</equals>";
     $filter .= "<in path='/DataSets/DataSet/Units/Unit/UnitID'>" . $source['Units'] . '</in>';
     $filter .= '</and>';
 }
 $filter .= '</or>';
 $biocase = new BioCase('http://www.envappsqa.sa.gov.au/biocase2/pywrapper.cgi', 'adherb', 'http://www.tdwg.org/schemas/abcd/2.06', FALSE, 0, 500);
 $xml = $biocase->biocaseGeneralFilter($filter);
 file_put_contents('xml/AD_0000000.xml', $xml);
 /*$doc = new DOMDocument('1.0', 'UTF-8');
     $doc->loadXML($xml);
     
     $diag = new BiocaseDiagnostic($pgdb, $doc, 1);
     $diag->diagnose();
     
     $dehispidator = new Hispid5ToCsv();
     $data['core'] = $dehispidator->parseHISPID5($doc);
     $data['extension'] = $dehispidator->DeterminationHistory($doc);
 
     $upload = new AvhDb($pgdb, $data, $config);
     $upload->uploadCoreData(FALSE);
     $upload->uploadExtensionData();