<?php
class kMetadataObjectDeletedHandler implements kObjectDeletedEventConsumer
{
	/**
	 * @param BaseObject $object
	 */
	public function objectDeleted(BaseObject $object) 
	{
		if($object instanceof entry)
			$this->deleteMetadataObjects(Metadata::TYPE_ENTRY, $object->getId());
	}
	
	protected function deleteMetadataObjects($objectType, $objectId) 
	{
		$c = new Criteria();
		$c->add(MetadataPeer::OBJECT_TYPE, $objectType);
		$c->add(MetadataPeer::OBJECT_ID, $objectId);
		$c->add(MetadataPeer::STATUS, KalturaMetadataStatus::DELETED, Criteria::NOT_EQUAL);
		
		$update = new Criteria();
		$update->add(MetadataPeer::STATUS, KalturaMetadataStatus::DELETED);
			
		$con = Propel::getConnection(MetadataPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		$count = BasePeer::doUpdate($c, $update, $con);
		
		$peer = null;
		MetadataPeer::setUseCriteriaFilter(false);
		$metadatas = MetadataPeer::doSelect($c);
		foreach($metadatas as $metadata)
		{
			kEventsManager::raiseEvent(new kObjectDeletedEvent($metadata));
			
			if(!$peer)
				$peer = kMetadataManager::getObjectPeer($metadata->getObjectType());
				
			$peer->saveToSphinx($metadata->getObjectId(), array());
		}
	}
}
Delete metadata objects for deleted entries
Delete metadata objects for deleted entries

git-svn-id: 8a2ccb88241e16c78017770bc38d91d6d5396a5a@50661 6b8eccd3-e8c5-4e7d-8186-e12b5326b719
