/**
  * 1. add resource in status PARSED
  * 2. if already exist, but is not processed yet update lead drop folder file id
  * 3. if already processed, mark processed file as purged and create new row in status PARSED
  * @param string $fileName
  * @param DropFolderFile $leadFile
  * @param DropFolder $folder
  * @throws Exception
  */
 private function addParsedContentResourceFile($fileName, DropFolderFile $leadFile, DropFolder $folder)
 {
     KalturaLog::debug('Trying to add content resource in status PARSED [' . $fileName . ']');
     try {
         $newFile = new DropFolderFile();
         $newFile->setDropFolderId($folder->getId());
         $newFile->setFileName($fileName);
         $newFile->setFileSize(0);
         $newFile->setStatus(DropFolderFileStatus::PARSED);
         $newFile->setLeadDropFolderFileId($leadFile->getId());
         $newFile->setPartnerId($folder->getPartnerId());
         $newFile->save();
     } catch (PropelException $e) {
         if ($e->getCause() && $e->getCause()->getCode() == kDropFolderXmlEventsConsumer::MYSQL_CODE_DUPLICATE_KEY) {
             $existingFile = DropFolderFilePeer::retrieveByDropFolderIdAndFileName($folder->getId(), $fileName);
             if ($existingFile) {
                 $unprocessedStatuses = array(DropFolderFileStatus::WAITING, DropFolderFileStatus::DETECTED, DropFolderFileStatus::UPLOADING, DropFolderFileStatus::PENDING);
                 if (in_array($existingFile->getStatus(), $unprocessedStatuses)) {
                     KalturaLog::debug('Updating drop folder file [' . $existingFile->getId() . '] with lead id [' . $leadFile->getId() . ']');
                     $existingFile->setLeadDropFolderFileId($leadFile->getId());
                     $existingFile->save();
                 } else {
                     KalturaLog::debug('Deleting drop folder file [' . $existingFile->getId() . ']');
                     $existingFile->setStatus(DropFolderFileStatus::PURGED);
                     $existingFile->save();
                     KalturaLog::debug('Adding new drop folder file [' . $newFile->getFileName() . '] with status PARSED');
                     $newFileCopy = $newFile->copy();
                     $newFileCopy->save();
                 }
             }
         } else {
             KalturaLog::err('Failed to add content resource for Xml file [' . $leadFile->getId() . '] - ' . $e->getMessage());
             throw new Exception(DropFolderXmlBulkUploadPlugin::ERROR_ADD_CONTENT_RESOURCE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::ERROR_ADD_CONTENT_RESOURCE));
         }
     }
 }