Created
April 5, 2011 21:22
-
-
Save michaelesmith/904589 to your computer and use it in GitHub Desktop.
Object Updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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