Skip to content

Instantly share code, notes, and snippets.

@michaelesmith
Created April 5, 2011 21:22
Show Gist options
  • Save michaelesmith/904589 to your computer and use it in GitHub Desktop.
Save michaelesmith/904589 to your computer and use it in GitHub Desktop.
Object Updates
<?php
public function save(Doctrine_Connection $conn = null) {
$conn = $conn ? $conn : $this->getTable()->getConnection();
$conn->beginTransaction();
try {
$ret = parent::save($conn);
$this->updateLuceneIndex();
$conn->commit();
return $ret;
} catch (Exception $e) {
$conn->rollBack();
throw $e;
}
}
public function updateLuceneIndex(){
$index = ProjectConfiguration::getLuceneIndex();
$index->remove($this->getId(), 'lead');
$doc = new tmaSearchDocument($this->getId(), 'lead');
// index fields
$doc->addField(Zend_Search_Lucene_Field::UnStored('name', $this->__toString(), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('organization', $this->getOrganizationName(), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('postion', $this->getOrganizationPosition(), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('address', $this->getAddress(), 'utf-8'));
// add to the index
$index->addDocument($doc);
$index->commit();
}
public function delete(Doctrine_Connection $conn = null) {
$conn = $conn ? $conn : $this->getTable()->getConnection();
$conn->beginTransaction();
try {
$ret = parent::delete($conn);
$this->deleteFromLuceneIndex();
$conn->commit();
return $ret;
} catch (Exception $e) {
$conn->rollBack();
throw $e;
}
}
public function deleteFromLuceneIndex(){
ProjectConfiguration::getLuceneIndex()->remove($this->getId(), 'lead');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment