/** * @param BaseObject $object */ public function attachCreatedObject(BaseObject $object) { $dropFolderFile = DropFolderFilePeer::retrieveByPK($this->getDropFolderFileId()); $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->getDropFolderId()); $entryId = $asset = null; // create import job for remote drop folder files if ($dropFolder instanceof RemoteDropFolder) { // get params if ($object instanceof asset) { $entryId = $object->getEntryId(); $asset = $object; } else { if ($object instanceof entry) { $entryId = $object->getId(); $asset = null; } else { return; } } $importUrl = $dropFolder->getFolderUrl(); $importUrl .= '/' . $dropFolderFile->getFileName(); $jobData = $dropFolder->getImportJobData(); $jobData->setDropFolderFileId($this->getDropFolderFileId()); // add job kJobsManager::addImportJob(null, $entryId, $dropFolderFile->getPartnerId(), $importUrl, $asset, $dropFolder->getFileTransferMgrType(), $jobData); // set file status to DOWNLOADING $dropFolderFile->setStatus(DropFolderFileStatus::DOWNLOADING); $dropFolderFile->save(); } }
/** * Allows you to add a new KalturaDropFolderFile object * * @action add * @param KalturaDropFolderFile $dropFolderFile * @return KalturaDropFolderFile * * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL * @throws KalturaDropFolderErrors::DROP_FOLDER_NOT_FOUND * @throws KalturaDropFolderErrors::DROP_FOLDER_FILE_ALREADY_EXISTS */ public function addAction(KalturaDropFolderFile $dropFolderFile) { // check for required parameters $dropFolderFile->validatePropertyNotNull('dropFolderId'); $dropFolderFile->validatePropertyNotNull('fileName'); $dropFolderFile->validatePropertyMinValue('fileSize', 0); // check that drop folder id exists in the system $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->dropFolderId); if (!$dropFolder) { throw new KalturaAPIException(KalturaDropFolderErrors::DROP_FOLDER_NOT_FOUND, $dropFolderFile->dropFolderId); } // check that the file doesn't already exist in the drop folder if (DropFolderFilePeer::retrieveByDropFolderIdAndFileName($dropFolderFile->dropFolderId, $dropFolderFile->fileName)) { throw new KalturaAPIException(KalturaDropFolderErrors::DROP_FOLDER_FILE_ALREADY_EXISTS, $dropFolderFile->dropFolderId, $dropFolderFile->fileName); } // save in database $dbDropFolderFile = $dropFolderFile->toInsertableObject(); /* @var $dbDropFolderFile DropFolderFile */ $dbDropFolderFile->setPartnerId($dropFolder->getPartnerId()); $dbDropFolderFile->setStatus(DropFolderFileStatus::UPLOADING); $dbDropFolderFile->save(); // return the saved object $dropFolderFile = new KalturaDropFolderFile(); $dropFolderFile->fromObject($dbDropFolderFile); return $dropFolderFile; }
public function toObject($object_to_fill = null, $props_to_skip = array()) { if (!$object_to_fill) { $object_to_fill = new kDropFolderFileResource(); } $object_to_fill = parent::toObject($object_to_fill, $props_to_skip); $dropFolderFile = DropFolderFilePeer::retrieveByPK($this->dropFolderFileId); if (!$dropFolderFile) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $this->dropFolderFileId); } $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->getDropFolderId()); if (!$dropFolder) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderFile->getDropFolderId()); } $object_to_fill->setDropFolderFileId($dropFolderFile->getId()); $fullPath = $dropFolder->getPath() . '/' . $dropFolderFile->getFileName(); $object_to_fill->setLocalFilePath($fullPath); if ($dropFolder->getType() == DropFolderType::LOCAL) { // if the drop folder is set to automatic with immidate deletion of files (days = 0) move the files instead of copying them. // this will result in fast handling of drop folder files $deleteOriginalFile = $dropFolder->getFileDeletePolicy() == DropFolderFileDeletePolicy::AUTO_DELETE && $dropFolder->getAutoFileDeleteDays() == 0; $object_to_fill->setKeepOriginalFile(!$deleteOriginalFile); $object_to_fill->setIsReady(true); } else { $object_to_fill->setKeepOriginalFile(false); $object_to_fill->setIsReady(false); } return $object_to_fill; }
public static function retrieveByPathDefaultFilter($path) { DropFolderPeer::setUseCriteriaFilter(false); $c = new Criteria(); DropFolderPeer::addDefaultCriteria($c); $c->addAnd(DropFolderPeer::PATH, $path, Criteria::EQUAL); $dropFolder = DropFolderPeer::doSelectOne($c); DropFolderPeer::setUseCriteriaFilter(true); return $dropFolder; }
public function shouldConsumeChangedEvent(BaseObject $object, array $modifiedColumns) { try { if ($object instanceof DropFolderFile && ($object->getStatus() == DropFolderFileStatus::PENDING || $object->getStatus() == DropFolderFileStatus::PURGED) && in_array(DropFolderFilePeer::STATUS, $modifiedColumns)) { $folder = DropFolderPeer::retrieveByPK($object->getDropFolderId()); if (!$folder) { KalturaLog::err('Failed to process shouldConsumeChangedEvent - Failed to retrieve drop folder with ID ' . $object->getDropFolderId()); return false; } if ($folder->getFileHandlerType() == DropFolderXmlBulkUploadPlugin::getFileHandlerTypeCoreValue(DropFolderXmlFileHandlerType::XML)) { return true; } } } catch (Exception $e) { KalturaLog::err('Failed to process shouldConsumeChangedEvent - ' . $e->getMessage()); } return false; }
public function getRootObjects(IRelatedObject $object) { return array(DropFolderPeer::retrieveByPK($object->getDropFolderId())); }
public function getFileUrl() { $dropFolder = DropFolderPeer::retrieveByPK($this->getDropFolderId()); return $dropFolder->getFolderUrl() . '/' . $this->getFileName(); }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(DropFolderPeer::DATABASE_NAME); $criteria->add(DropFolderPeer::ID, $pks, Criteria::IN); $objs = DropFolderPeer::doSelect($criteria, $con); } return $objs; }
/** * List KalturaDropFolder objects * * @action list * @param KalturaDropFolderFilter $filter * @param KalturaFilterPager $pager * @return KalturaDropFolderListResponse */ public function listAction(KalturaDropFolderFilter $filter = null, KalturaFilterPager $pager = null) { if (!$filter) { $filter = new KalturaDropFolderFilter(); } $dropFolderFilter = $filter->toObject(); $c = new Criteria(); $dropFolderFilter->attachToCriteria($c); $count = DropFolderPeer::doCount($c); if (!$pager) { $pager = new KalturaFilterPager(); } $pager->attachToCriteria($c); $list = DropFolderPeer::doSelect($c); $response = new KalturaDropFolderListResponse(); $response->objects = KalturaDropFolderArray::fromDbArray($list, $this->getResponseProfile()); $response->totalCount = $count; return $response; }
public function entryHandled(entry $dbEntry) { parent::entryHandled($dbEntry); $dropFolderFile = DropFolderFilePeer::retrieveByPK($this->dropFolderFileId); if (is_null($dropFolderFile)) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $this->dropFolderFileId); } if ($dropFolderFile->getStatus() != DropFolderFileStatus::DOWNLOADING) { $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->getDropFolderId()); if (!$dropFolder) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderFile->getDropFolderId()); } if ($dropFolder->getFileDeletePolicy() == DropFolderFileDeletePolicy::AUTO_DELETE && $dropFolder->getAutoFileDeleteDays() == 0) { $dropFolderFile->setStatus(DropFolderFileStatus::PURGED); } else { $dropFolderFile->setStatus(DropFolderFileStatus::HANDLED); } } $dropFolderFile->setEntryId($dbEntry->getId()); $dropFolderFile->save(); }
public function getFieldNameFromPeer($field_name) { $res = DropFolderPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME); return $res; }
<?php chdir(__DIR__ . '/../'); require_once __DIR__ . '/../bootstrap.php'; $dropFoldersCriteria = new Criteria(); $dropFoldersCriteria->add(DropFolderPeer::STATUS, DropFolderStatus::ENABLED); $dropFoldersCriteria->add(DropFolderPeer::TYPE, DropFolderType::SFTP); $dropFolders = DropFolderPeer::doSelect($dropFoldersCriteria); KalturaLog::debug("Drop folders count [" . count($dropFolders) . "]"); foreach ($dropFolders as $dropFolder) { /* @var $dropFolder SftpDropFolder */ $dropFolderId = $dropFolder->getId(); $passed = true; $sftp = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP_SEC_LIB); /* @var $sftp sftpSecLibMgr */ $dropFolderPublicKeyFile = uniqid('sftp-pub-'); $dropFolderPrivateKeyFile = uniqid('sftp-pvt-'); try { if ($dropFolder->getSshPrivateKey()) { file_put_contents($dropFolderPublicKeyFile, $dropFolder->getSshPublicKey()); file_put_contents($dropFolderPrivateKeyFile, $dropFolder->getSshPrivateKey()); $sftp->loginPubKey($dropFolder->getSshHost(), $dropFolder->getSshUsername(), $dropFolderPublicKeyFile, $dropFolderPrivateKeyFile, $dropFolder->getSshPassPhrase(), $dropFolder->getSshPort()); unlink($dropFolderPublicKeyFile); unlink($dropFolderPrivateKeyFile); } else { $sftp->login($dropFolder->getSshHost(), $dropFolder->getSshUsername(), $dropFolder->getSshPassword(), $dropFolder->getSshPort()); } } catch (Exception $e) { KalturaLog::err("Drop folder [{$dropFolderId}] login failed: " . $e->getMessage()); if (file_exists($dropFolderPublicKeyFile)) { unlink($dropFolderPublicKeyFile);
public static function cleanMemory() { DropFolderPeer::clearInstancePool(); DropFolderFilePeer::clearInstancePool(); }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = new Criteria(DropFolderPeer::DATABASE_NAME); $criteria->add(DropFolderPeer::ID, $this->id); if ($this->alreadyInSave) { if ($this->isColumnModified(DropFolderPeer::CUSTOM_DATA)) { if (!is_null($this->custom_data_md5)) { $criteria->add(DropFolderPeer::CUSTOM_DATA, "MD5(cast(" . DropFolderPeer::CUSTOM_DATA . " as char character set latin1)) = '{$this->custom_data_md5}'", Criteria::CUSTOM); } else { $criteria->add(DropFolderPeer::CUSTOM_DATA, NULL, Criteria::ISNULL); } } if (count($this->modifiedColumns) == 2 && $this->isColumnModified(DropFolderPeer::UPDATED_AT)) { $theModifiedColumn = null; foreach ($this->modifiedColumns as $modifiedColumn) { if ($modifiedColumn != DropFolderPeer::UPDATED_AT) { $theModifiedColumn = $modifiedColumn; } } $atomicColumns = DropFolderPeer::getAtomicColumns(); if (in_array($theModifiedColumn, $atomicColumns)) { $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL); } } } return $criteria; }
private function newFileAddedOrDetected(KalturaDropFolderFile $dropFolderFile, $fileStatus) { // check for required parameters $dropFolderFile->validatePropertyNotNull('dropFolderId'); $dropFolderFile->validatePropertyNotNull('fileName'); $dropFolderFile->validatePropertyMinValue('fileSize', 0); // check that drop folder id exists in the system $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->dropFolderId); if (!$dropFolder) { throw new KalturaAPIException(KalturaDropFolderErrors::DROP_FOLDER_NOT_FOUND, $dropFolderFile->dropFolderId); } // save in database $dropFolderFile->status = null; $dbDropFolderFile = $dropFolderFile->toInsertableObject(); /* @var $dbDropFolderFile DropFolderFile */ $dbDropFolderFile->setPartnerId($dropFolder->getPartnerId()); $dbDropFolderFile->setStatus($fileStatus); $dbDropFolderFile->setType($dropFolder->getType()); try { $dbDropFolderFile->save(); } catch (PropelException $e) { if ($e->getCause() && $e->getCause()->getCode() == self::MYSQL_CODE_DUPLICATE_KEY) { $existingDropFolderFile = DropFolderFilePeer::retrieveByDropFolderIdAndFileName($dropFolderFile->dropFolderId, $dropFolderFile->fileName); switch ($existingDropFolderFile->getStatus()) { case DropFolderFileStatus::PARSED: KalturaLog::info('Exisiting file status is PARSED, updating status to [' . $fileStatus . ']'); $existingDropFolderFile = $dropFolderFile->toUpdatableObject($existingDropFolderFile); $existingDropFolderFile->setStatus($fileStatus); $existingDropFolderFile->save(); $dbDropFolderFile = $existingDropFolderFile; break; case DropFolderFileStatus::DETECTED: KalturaLog::info('Exisiting file status is DETECTED, updating status to [' . $fileStatus . ']'); $existingDropFolderFile = $dropFolderFile->toUpdatableObject($existingDropFolderFile); if ($existingDropFolderFile->getStatus() != $fileStatus) { $existingDropFolderFile->setStatus($fileStatus); } $existingDropFolderFile->save(); $dbDropFolderFile = $existingDropFolderFile; break; case DropFolderFileStatus::UPLOADING: if ($fileStatus == DropFolderFileStatus::UPLOADING) { KalturaLog::log('Exisiting file status is UPLOADING, updating properties'); $existingDropFolderFile = $dropFolderFile->toUpdatableObject($existingDropFolderFile); $existingDropFolderFile->save(); $dbDropFolderFile = $existingDropFolderFile; break; } default: KalturaLog::log('Setting current file to PURGED [' . $existingDropFolderFile->getId() . ']'); $existingDropFolderFile->setStatus(DropFolderFileStatus::PURGED); $existingDropFolderFile->save(); $newDropFolderFile = $dbDropFolderFile->copy(); if ($existingDropFolderFile->getLeadDropFolderFileId() && $existingDropFolderFile->getLeadDropFolderFileId() != $existingDropFolderFile->getId()) { KalturaLog::info('Updating lead id [' . $existingDropFolderFile->getLeadDropFolderFileId() . ']'); $newDropFolderFile->setLeadDropFolderFileId($existingDropFolderFile->getLeadDropFolderFileId()); } $newDropFolderFile->save(); $dbDropFolderFile = $newDropFolderFile; } } else { throw $e; } } // return the saved object $dropFolderFile = KalturaDropFolderFile::getInstanceByType($dbDropFolderFile->getType()); $dropFolderFile->fromObject($dbDropFolderFile, $this->getResponseProfile()); return $dropFolderFile; }
/** * Convert all drop folder files' status from PROCESSING to HANDLED/DELETED in case of DropFolderFileDeletePolicy::AUTO_DELETE_WHEN_ENTRY_IS_READY * * Note that if the entry reached entryStatus::ERROR_CONVERTING, then the drop folder files' * conversions already failed, so there's no need to change their status (thus they won't be handled here). * * @param entry $entry */ private function onEntryStatusChanged($entry) { // Handle only files that are still in the PROCESSING state, which were left // in this state due to AUTO_DELETE_WHEN_ENTRY_IS_READY delete policy. $dropFolderFiles = DropFolderFilePeer::retrieveByEntryIdPartnerIdAndStatuses($entry->getId(), $entry->getPartnerId(), array(DropFolderFileStatus::PROCESSING)); $dropFolderIdToDropFolderCache = array(); $entryStatus = $entry->getStatus(); foreach ($dropFolderFiles as $dropFolderFile) { $newDropFolderFileStatus = null; if ($entryStatus == entryStatus::ERROR_CONVERTING) { $newDropFolderFileStatus = DropFolderFileStatus::ERROR_HANDLING; } elseif ($entryStatus == entryStatus::READY) { // Get the associated drop folder $dropFolderId = $dropFolderFile->getDropFolderId(); if (key_exists($dropFolderId, $dropFolderIdToDropFolderCache)) { $dropFolder = $dropFolderIdToDropFolderCache[$dropFolderId]; } else { $dropFolder = DropFolderPeer::retrieveByPK($dropFolderId); $dropFolderIdToDropFolderCache[$dropFolderId] = $dropFolder; } if ($dropFolder->getFileDeletePolicy() == DropFolderFileDeletePolicy::AUTO_DELETE_WHEN_ENTRY_IS_READY) { if ($dropFolder->getAutoFileDeleteDays() == 0) { $newDropFolderFileStatus = DropFolderFileStatus::DELETED; // Mark for immediate deletion } else { $newDropFolderFileStatus = DropFolderFileStatus::HANDLED; } } } KalturaLog::info("Entry id [{$entry->getId()}] status [{$entryStatus}], drop folder file id [{$dropFolderFile->getId()}] status [{$dropFolderFile->getStatus()}] => [" . ($newDropFolderFileStatus ? $newDropFolderFileStatus : "{$dropFolderFile->getStatus()} (unchanged)") . "]"); if ($newDropFolderFileStatus) { $dropFolderFile->setStatus($newDropFolderFileStatus); $dropFolderFile->save(); } } }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = new Criteria(DropFolderPeer::DATABASE_NAME); $criteria->add(DropFolderPeer::ID, $this->id); if ($this->alreadyInSave && count($this->modifiedColumns) == 2 && $this->isColumnModified(DropFolderPeer::UPDATED_AT)) { $theModifiedColumn = null; foreach ($this->modifiedColumns as $modifiedColumn) { if ($modifiedColumn != DropFolderPeer::UPDATED_AT) { $theModifiedColumn = $modifiedColumn; } } $atomicColumns = DropFolderPeer::getAtomicColumns(); if (in_array($theModifiedColumn, $atomicColumns)) { $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL); } } return $criteria; }