/** * @param BatchJob $dbBatchJob * @param kCaptureThumbJobData $data * @return BatchJob */ public static function handleCaptureThumbFinished(BatchJob $dbBatchJob, kCaptureThumbJobData $data) { if ($dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) { return $dbBatchJob; } // verifies that thumb asset created if (!$data->getThumbAssetId()) { throw new APIException(APIErrors::INVALID_THUMB_ASSET_ID, $data->getThumbAssetId()); } $thumbAsset = assetPeer::retrieveById($data->getThumbAssetId()); // verifies that thumb asset exists if (!$thumbAsset) { throw new APIException(APIErrors::INVALID_THUMB_ASSET_ID, $data->getThumbAssetId()); } $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY); if (file_exists($data->getThumbPath())) { list($width, $height, $type, $attr) = getimagesize($data->getThumbPath()); $thumbAsset->setWidth($width); $thumbAsset->setHeight($height); $thumbAsset->setSize(filesize($data->getThumbPath())); } $logPath = $data->getThumbPath() . '.log'; if (file_exists($logPath)) { $thumbAsset->incLogFileVersion(); $thumbAsset->save(); // creats the file sync $logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG); try { kFileSyncUtils::moveFromFile($logPath, $logSyncKey); } catch (Exception $e) { $err = 'Saving conversion log: ' . $e->getMessage(); KalturaLog::err($err); $desc = $dbBatchJob->getDescription() . "\n" . $err; $dbBatchJob->getDescription($desc); } } else { $thumbAsset->save(); } $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::moveFromFile($data->getThumbPath(), $syncKey); $data->setThumbPath(kFileSyncUtils::getLocalFilePathForKey($syncKey)); KalturaLog::info("Thumbnail archived file to: " . $data->getThumbPath()); // save the data changes to the db $dbBatchJob->setData($data); $dbBatchJob->save(); $entry = $thumbAsset->getentry(); if ($entry && $entry->getCreateThumb() && $thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $entry = $dbBatchJob->getEntry(false, false); if (!$entry) { throw new APIException(APIErrors::INVALID_ENTRY, $dbBatchJob, $dbBatchJob->getEntryId()); } // increment thumbnail version $entry->setThumbnail(".jpg"); $entry->setCreateThumb(false); $entry->save(); $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey); if ($syncFile) { // removes the DEFAULT_THUMB tag from all other thumb assets assetPeer::removeThumbAssetDeafultTags($entry->getId(), $thumbAsset->getId()); } } if (!is_null($thumbAsset->getFlavorParamsId())) { kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $thumbAsset->getFlavorParamsId()); } self::handleLocalFileSyncDeletion($dbBatchJob->getEntryId(), $dbBatchJob->getPartner()); return $dbBatchJob; }
/** * @param BatchJob $dbBatchJob * @param kCaptureThumbJobData $data * @param BatchJob $twinJob * @return BatchJob */ public static function handleCaptureThumbFailed(BatchJob $dbBatchJob, kCaptureThumbJobData $data, BatchJob $twinJob = null) { KalturaLog::debug("Captura thumbnail failed with destination file: " . $data->getThumbPath()); if ($dbBatchJob->getAbort()) { return $dbBatchJob; } // verifies that thumb asset created if (!$data->getThumbAssetId()) { throw new APIException(APIErrors::INVALID_THUMB_ASSET_ID, $data->getThumbAssetId()); } $thumbAsset = flavorAssetPeer::retrieveById($data->getThumbAssetId()); // verifies that thumb asset exists if (!$thumbAsset) { throw new APIException(APIErrors::INVALID_THUMB_ASSET_ID, $data->getThumbAssetId()); } $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR); $thumbAsset->save(); return $dbBatchJob; }
/** * @param BatchJob $dbBatchJob * @param kCaptureThumbJobData $data * @return BatchJob */ public static function handleCaptureThumbFailed(BatchJob $dbBatchJob, kCaptureThumbJobData $data) { KalturaLog::debug("Captura thumbnail failed with destination file: " . $data->getThumbPath()); if ($dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) { return $dbBatchJob; } // verifies that thumb asset created if (!$data->getThumbAssetId()) { throw new APIException(APIErrors::INVALID_THUMB_ASSET_ID, $data->getThumbAssetId()); } $thumbAsset = assetPeer::retrieveById($data->getThumbAssetId()); // verifies that thumb asset exists if (!$thumbAsset) { throw new APIException(APIErrors::INVALID_THUMB_ASSET_ID, $data->getThumbAssetId()); } $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR); $thumbAsset->save(); self::handleLocalFileSyncDeletion($dbBatchJob->getEntryId(), $dbBatchJob->getPartner()); return $dbBatchJob; }