Beispiel #1
0
 /**
  * Delete an array of IDs from the specified search backend
  *
  * @param string $backend Backend ID
  * @param array  $idList  Record IDs to delete
  *
  * @return void
  */
 public function deleteRecords($backend, $idList)
 {
     // Delete IDs:
     $deleteDoc = new DeleteDocument();
     $deleteDoc->addKeys($idList);
     $connector = $this->getConnector($backend);
     $connector->write($deleteDoc);
     // Update change tracker:
     $core = $this->getCore($connector);
     foreach ($idList as $id) {
         $this->changeTracker->markDeleted($core, $id);
     }
 }
 /**
  * Test change tracking
  *
  * @return void
  */
 public function testChangeTracker()
 {
     $core = 'testCore';
     $tracker = new ChangeTracker();
     // Create a new row:
     $tracker->index($core, 'test1', 1326833170);
     $row = $tracker->retrieve($core, 'test1');
     $this->assertTrue(is_object($row));
     $this->assertTrue(empty($row->deleted));
     $this->assertEquals($row->first_indexed, $row->last_indexed);
     $this->assertEquals($row->last_record_change, '2012-01-17 15:46:10');
     // Try to index an earlier record version -- changes should be ignored:
     $tracker->index($core, 'test1', 1326830000);
     $row = $tracker->retrieve($core, 'test1');
     $this->assertTrue(is_object($row));
     $this->assertTrue(empty($row->deleted));
     $this->assertEquals($row->first_indexed, $row->last_indexed);
     $this->assertEquals($row->last_record_change, '2012-01-17 15:46:10');
     // Index a later record version -- this should lead to changes:
     $tracker->index($core, 'test1', 1326833176);
     $row = $tracker->retrieve($core, 'test1');
     $this->assertTrue(is_object($row));
     $this->assertTrue(empty($row->deleted));
     $this->assertTrue(strtotime($row->first_indexed) <= strtotime($row->last_indexed));
     $this->assertEquals($row->last_record_change, '2012-01-17 15:46:16');
     // Delete the record:
     $tracker->markDeleted($core, 'test1');
     $row = $tracker->retrieve($core, 'test1');
     $this->assertTrue(is_object($row));
     $this->assertTrue(!empty($row->deleted));
     // Delete a record that hasn't previously been encountered:
     $tracker->markDeleted($core, 'test2');
     $row = $tracker->retrieve($core, 'test2');
     $this->assertTrue(is_object($row));
     $this->assertTrue(!empty($row->deleted));
     $this->assertTrue(empty($row->last_record_change));
     // Index the previously-deleted record and make sure it undeletes properly:
     $tracker->index($core, 'test2', 1326833170);
     $row = $tracker->retrieve($core, 'test2');
     $this->assertTrue(is_object($row));
     $this->assertTrue(empty($row->deleted));
     $this->assertEquals($row->last_record_change, '2012-01-17 15:46:10');
     // Clean up after ourselves:
     $tracker->delete(array('core' => $core));
 }