/** * Validate if all the files ready: * 1. Yes: add BulkUpload job * 2. No: set status to Waiting * @param DropFolder $folder * @param DropFolderFile $file */ private function onXmlDropFolderFileStatusChangedToPending(DropFolder $folder, DropFolderFile $file) { KalturaLog::debug('in onXmlDropFolderFileStatusChangedToPending file id [' . $file->getId() . '] folder id [' . $folder->getId() . ']'); $relatedFiles = array(); try { $xmlFileHandler = kDropFolderXmlFileHandler::getHandlerInstance($folder->getType()); $xmlFileHandler->handlePendingDropFolderFile($folder, $file); } catch (Exception $e) { KalturaLog::err("Error in onXmlDropFolderFileStatusChangedToPending -" . $e->getMessage()); if ($e->getCode() == DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::ERROR_ADDING_BULK_UPLOAD)) { foreach ($relatedFiles as $relatedFile) { $this->setFileError($relatedFile, DropFolderFileStatus::ERROR_HANDLING, $e->getCode(), $e->getMessage()); } } else { $this->setFileError($file, DropFolderFileStatus::ERROR_HANDLING, $e->getCode(), $e->getMessage()); } } }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param DropFolder $value A DropFolder object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(DropFolder $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param DropFolder $value A DropFolder object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(DropFolder $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) { self::$instances[$key] = $obj; kMemoryManager::registerPeer('DropFolderPeer'); } } }
protected function getOriginalOrTransformIfNeeded(DropFolder $folder, $xmlPath) { if (!file_exists($xmlPath) || !filesize($xmlPath)) { throw new Exception('Empty file supplied as input'); } if (!$folder->getConversionProfileId()) { KalturaLog::debug('No conversion profile found on drop folder [' . $folder->getId() . '] assuming no xsl transformation is needed'); return file_get_contents($xmlPath); } $conversionProfile = conversionProfile2Peer::retrieveByPK($folder->getConversionProfileId()); if (!$conversionProfile || strlen($conversionProfile->getXsl()) == 0) { KalturaLog::debug('No conversion profile found Or no xsl transform found'); return file_get_contents($xmlPath); } $originalXmlDoc = file_get_contents($xmlPath); $origianlXml = new KDOMDocument(); if (!$origianlXml->loadXML($originalXmlDoc)) { KalturaLog::debug('Could not load original xml'); $errorMessage = kXml::getLibXmlErrorDescription($originalXmlDoc); throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE)); } libxml_clear_errors(); $proc = new XSLTProcessor(); $xsl = new KDOMDocument(); if (!$xsl->loadXML($conversionProfile->getXsl())) { KalturaLog::debug('Could not load xsl ' . $conversionProfile->getXsl()); $errorMessage = kXml::getLibXmlErrorDescription($conversionProfile->getXsl()); throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE)); } $proc->importStyleSheet($xsl); libxml_clear_errors(); $transformedXml = $proc->transformToXML($origianlXml); if (!$transformedXml) { KalturaLog::debug('Could not transform xml ' . $conversionProfile->getXsl()); $errorMessage = kXml::getLibXmlErrorDescription($conversionProfile->getXsl()); throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE)); } $xmlDoc = new KDOMDocument(); $res = $xmlDoc->loadXML($transformedXml); if (!$res) { throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE)); } return $transformedXml; }
public function setData(DropFolder $folder, DropFolderFile $dropFolderFileForObject, $dropFolderFileIds) { $this->dropFolderId = $folder->getId(); $this->setConversionProfileId($folder->getConversionProfileId()); $this->setParsedSlug($dropFolderFileForObject->getParsedSlug()); $this->setContentMatchPolicy($folder->getFileHandlerConfig()->getContentMatchPolicy()); $this->setDropFolderFileIds($dropFolderFileIds); if ($dropFolderFileForObject->getParsedUserId()) { $this->setParsedUserId($dropFolderFileForObject->getParsedUserId()); } }