コード例 #1
0
 /**
  * Test state functionality.
  *
  * @return void
  */
 public function testState()
 {
     $tmp = sys_get_temp_dir() . '/';
     $date = '2016-07-12';
     $manager = new StateManager($tmp);
     $manager->saveState('foo', 'bar', $date);
     $this->assertEquals(['foo', 'bar', $date], $manager->loadState());
     $this->assertTrue(file_exists($tmp . 'last_state.txt'));
     $manager->clearState();
     $this->assertFalse(file_exists($tmp . 'last_state.txt'));
 }
コード例 #2
0
 /**
  * Check an OAI-PMH response for errors that need to be handled.
  *
  * @param object $result OAI-PMH response (SimpleXML object)
  *
  * @return void
  *
  * @throws \Exception
  */
 protected function checkResponseForErrors($result)
 {
     // Detect errors and die if one is found:
     if ($result->error) {
         $attribs = $result->error->attributes();
         // If this is a bad resumption token error and we're trying to
         // restore a prior state, we should clean up.
         if ($attribs['code'] == 'badResumptionToken' && $this->stateManager->loadState()) {
             $this->stateManager->clearState();
             throw new \Exception("Token expired; removing last_state.txt. Please restart harvest.");
         }
         throw new \Exception("OAI-PMH error -- code: {$attribs['code']}, " . "value: {$result->error}");
     }
 }