Exemplo n.º 1
0
 function trigger_harvest($id = false, $mute = false)
 {
     header('Cache-Control: no-cache, must-revalidate');
     header('Content-type: application/json');
     set_exception_handler('json_exception_handler');
     if (!$id) {
         throw new Exception('Data source ID is required');
     }
     $this->load->model("data_sources", "ds");
     $ds = $this->ds->getByID($id);
     if (!$ds) {
         throw new Exception('Invalid Data source ID');
     }
     try {
         $ds->clearHarvestError();
         $harvestDate = strtotime($ds->getAttribute("harvest_date"));
         $nextRun = getNextHarvestDate($harvestDate, $ds->harvest_frequency);
         if ($ds->harvest_method == 'PMHHarvester' && $ds->oai_set) {
             $oai_msg = 'OAI Set: ' . $ds->oai_set;
         } else {
             $oai_msg = '';
         }
         if ($ds->advanced_harvest_mode == 'INCREMENTAL') {
             $incr_msg = 'From date: ' . date('Y-m-d H:i:s', strtotime($ds->last_harvest_run_date)) . NL . 'To date: ' . date('Y-m-d H:i:s', $harvestDate) . NL;
         } else {
             $incr_msg = '';
         }
         $scheduled_date = date('Y-m-d H:i:s P', $nextRun);
         if ($ds->harvest_frequency == '') {
             //once off
             $scheduled_date = date('Y-m-d H:i:s', time());
         }
         $ds->append_log('Harvest scheduled to run at ' . $scheduled_date . NL . 'URI: ' . $ds->uri . NL . 'Harvest Method: ' . readable($ds->harvest_method) . NL . 'Provider Type: ' . $ds->provider_type . NL . 'Advanced Harvest Mode: ' . $ds->advanced_harvest_mode . NL . $incr_msg . $oai_msg . NL);
         $ds->setHarvestRequest('HARVEST', false);
         $ds->setHarvestMessage('Harvest scheduled');
         $ds->updateImporterMessage(array());
     } catch (Exception $e) {
         throw new Exception($e);
     }
     if (!$mute) {
         echo json_encode(array('status' => 'OK', 'message' => 'Harvest Started'));
     }
 }
Exemplo n.º 2
0
 function setNextHarvestRun($harvestId)
 {
     $harvestDate = strtotime($this->getAttribute("harvest_date"));
     date_default_timezone_set('Australia/Canberra');
     $previousRun = date('Y-m-d\\TH:i:s.uP', time());
     $nextRun = getNextHarvestDate($harvestDate, $this->harvest_frequency);
     if ($nextRun) {
         $status = 'SCHEDULED';
         $batchNumber = strtoupper(sha1($nextRun));
         $this->db->where("harvest_id", $harvestId);
         try {
             $this->db->update('harvests', array('status' => $status, 'last_run' => $previousRun, 'next_run' => date('Y-m-d\\TH:i:s.uP', $nextRun), 'batch_number' => $batchNumber, 'mode' => 'HARVEST', 'message' => null));
         } catch (Exception $e) {
             throw new Exception('Cannot update harvest requests ' . $e);
         }
     }
 }