Example #1
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kCaptureThumbJobData $data
  * @param BatchJob $twinJob
  * @return BatchJob
  */
 public static function handleCaptureThumbFinished(BatchJob $dbBatchJob, kCaptureThumbJobData $data, BatchJob $twinJob = null)
 {
     KalturaLog::debug("Captire thumbnail finished 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 = thumbAssetPeer::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::debug("Thumbnail archived file to: " . $data->getThumbPath());
     // save the data changes to the db
     $dbBatchJob->setData($data);
     $dbBatchJob->save();
     if ($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->save();
         $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey, false);
         if ($syncFile) {
             // removes the DEFAULT_THUMB tag from all other thumb assets
             $entryThumbAssets = thumbAssetPeer::retrieveByEntryId($thumbAsset->getEntryId());
             foreach ($entryThumbAssets as $entryThumbAsset) {
                 if ($entryThumbAsset->getId() == $thumbAsset->getId()) {
                     continue;
                 }
                 if (!$entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                     continue;
                 }
                 $entryThumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB));
                 $entryThumbAsset->save();
             }
         }
     }
     if (!is_null($thumbAsset->getFlavorParamsId())) {
         kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $thumbAsset->getFlavorParamsId());
     }
     return $dbBatchJob;
 }
Example #2
0
 /**
  * @action delete
  * @param string $thumbAssetId
  * 
  * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND
  */
 public function deleteAction($thumbAssetId)
 {
     $thumbAssetDb = thumbAssetPeer::retrieveById($thumbAssetId);
     if (!$thumbAssetDb) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
     }
     $thumbAssetDb->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_DELETED);
     $thumbAssetDb->setDeletedAt(time());
     $thumbAssetDb->save();
 }