public function operate(kOperator $operator = null, $inFilePath, $configFilePath = null)
 {
     if (kFile::fullMkfileDir($this->outFilePath)) {
         KalturaLog::debug('dir [' . $this->outFilePath . '] created');
         //outFilePath will be the path to the directory in which the images will be saved.
         $outDirPath = $this->outFilePath;
         //imageMagick decides the format of the output file according to the outFilePath's extension.so the format need to be added.
         $this->outFilePath = $this->outFilePath . DIRECTORY_SEPARATOR . basename($this->outFilePath) . self::LEADING_ZEROS_PADDING . '.' . $this->flavorParamsOutput->format;
     } else {
         KalturaLog::debug('failed to create [' . $this->outFilePath . '] directory');
         throw new KOperationEngineException('failed to create [' . $this->outFilePath . '] directory');
     }
     parent::operate($operator, $inFilePath, $configFilePath);
     $imagesListXML = $this->createImagesListXML($outDirPath);
     kFile::setFileContent($outDirPath . DIRECTORY_SEPARATOR . self::IMAGES_LIST_XML_NAME, $imagesListXML->asXML());
     kalturalog::info('images list xml [' . $outDirPath . DIRECTORY_SEPARATOR . self::IMAGES_LIST_XML_NAME . '] created');
 }
 /**
  * @param entry $entry
  * @param entry $tempEntry
  */
 public static function replaceEntry(entry $entry, entry $tempEntry = null)
 {
     KalturaLog::debug("in replaceEntry");
     if (!$tempEntry) {
         $tempEntry = entryPeer::retrieveByPK($entry->getReplacingEntryId());
     }
     if (!$tempEntry) {
         KalturaLog::err("Temp entry id [" . $entry->getReplacingEntryId() . "] not found");
         return;
     }
     //Extract all assets of the temp entry
     $tempAssets = assetPeer::retrieveByEntryId($tempEntry->getId());
     //Extract all assets of the existing entry
     $oldAssets = assetPeer::retrieveByEntryId($entry->getId());
     KalturaLog::debug("num of old assets: " . count($oldAssets));
     $newAssets = array();
     //Loop which creates a mapping between the new assets' paramsId and their type to the asset itself
     foreach ($tempAssets as $newAsset) {
         if ($newAsset->getStatus() != asset::FLAVOR_ASSET_STATUS_READY) {
             KalturaLog::debug("Do not add new asset [" . $newAsset->getId() . "] to flavor [" . $newAsset->getFlavorParamsId() . "] status [" . $newAsset->getStatus() . "]");
             continue;
         }
         //If doesn't exist - create a new array for the current asset's type.
         if (!isset($newAssets[$newAsset->getType()])) {
             $newAssets[$newAsset->getType()] = array();
         }
         if ($newAsset->getFlavorParamsId() || $newAsset instanceof flavorAsset) {
             $newAssets[$newAsset->getType()][$newAsset->getFlavorParamsId()] = $newAsset;
             KalturaLog::debug("Added new asset [" . $newAsset->getId() . "] for asset params [" . $newAsset->getFlavorParamsId() . "]");
         } else {
             $newAssets[$newAsset->getType()]['asset_' . count($newAssets[$newAsset->getType()])] = $newAsset;
             KalturaLog::debug("Added new asset [" . $newAsset->getId() . "] with no asset params");
         }
     }
     $saveEntry = false;
     $defaultThumbAssetNew = null;
     foreach ($oldAssets as $oldAsset) {
         /* @var $oldAsset asset */
         kFileSyncUtils::clearWAMSDataForKey($oldAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET));
         //If the newAssets map contains an asset of the same type and paramsId as the current old asset,
         // re-link the old asset to the new asset.
         if (isset($newAssets[$oldAsset->getType()]) && isset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()])) {
             $newAsset = $newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()];
             /* @var $newAsset asset */
             KalturaLog::debug("Create link from new asset [" . $newAsset->getId() . "] to old asset [" . $oldAsset->getId() . "] for flavor [" . $oldAsset->getFlavorParamsId() . "]");
             if ($oldAsset instanceof flavorAsset) {
                 $oldAsset->setBitrate($newAsset->getBitrate());
                 $oldAsset->setFrameRate($newAsset->getFrameRate());
                 $oldAsset->setVideoCodecId($newAsset->getVideoCodecId());
             }
             $oldAsset->setWidth($newAsset->getWidth());
             $oldAsset->setHeight($newAsset->getHeight());
             $oldAsset->setContainerFormat($newAsset->getContainerFormat());
             $oldAsset->setSize($newAsset->getSize());
             $oldAsset->setFileExt($newAsset->getFileExt());
             $oldAsset->setTags($newAsset->getTags());
             $oldAsset->setDescription($newAsset->getDescription());
             $oldAsset->incrementVersion();
             $oldAsset->setStatusLocalReady();
             $oldAsset->save();
             $oldFileSync = $oldAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             $newFileSync = $newAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             kFileSyncUtils::createSyncFileLinkForKey($oldFileSync, $newFileSync);
             $newFlavorMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($newAsset->getId());
             if ($newFlavorMediaInfo) {
                 $oldFlavorNewMediaInfo = $newFlavorMediaInfo->copy();
                 $oldFlavorNewMediaInfo->setFlavorAssetId($oldAsset->getId());
                 $oldFlavorNewMediaInfo->setFlavorAssetVersion($oldAsset->getVersion());
                 $oldFlavorNewMediaInfo->save();
             }
             unset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]);
             if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                 $defaultThumbAssetNew = $oldAsset;
                 KalturaLog::debug("Nominating ThumbAsset [" . $oldAsset->getId() . "] as the default ThumbAsset after replacent");
             }
         } elseif ($oldAsset instanceof flavorAsset || $oldAsset instanceof thumbAsset) {
             KalturaLog::debug("Delete old asset [" . $oldAsset->getId() . "] for paramsId [" . $oldAsset->getFlavorParamsId() . "]");
             $oldAsset->setStatus(flavorAsset::ASSET_STATUS_DELETED);
             $oldAsset->setDeletedAt(time());
             $oldAsset->save();
             $entry->removeFlavorParamsId($oldAsset->getFlavorParamsId());
             $saveEntry = true;
         }
     }
     foreach ($newAssets as $newAssetsByTypes) {
         foreach ($newAssetsByTypes as $newAsset) {
             $createdAsset = $newAsset->copyToEntry($entry->getId(), $entry->getPartnerId());
             KalturaLog::debug("Copied from new asset [" . $newAsset->getId() . "] to copied asset [" . $createdAsset->getId() . "] for flavor [" . $newAsset->getFlavorParamsId() . "]");
             if ($createdAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                 $defaultThumbAssetNew = $newAsset;
                 KalturaLog::debug("Nominating ThumbAsset [" . $newAsset->getId() . "] as the default ThumbAsset after replacent");
             }
         }
     }
     if ($defaultThumbAssetNew) {
         kBusinessConvertDL::setAsDefaultThumbAsset($defaultThumbAssetNew);
         kalturalog::debug("Setting ThumbAsset [" . $defaultThumbAssetNew->getId() . "] as the default ThumbAsset");
     } else {
         kalturalog::debug("No default ThumbAsset found for replacing entry [" . $tempEntry->getId() . "]");
         $entry->setThumbnail(".jpg");
         // thumbnailversion++
         $entry->save();
         $tempEntrySyncKey = $tempEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         $realEntrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         kFileSyncUtils::createSyncFileLinkForKey($realEntrySyncKey, $tempEntrySyncKey);
     }
     $entry->setDimensions($tempEntry->getWidth(), $tempEntry->getHeight());
     $entry->setLengthInMsecs($tempEntry->getLengthInMsecs());
     $entry->setConversionProfileId($tempEntry->getConversionProfileId());
     $entry->setConversionQuality($tempEntry->getConversionQuality());
     $entry->setReplacingEntryId(null);
     $entry->setReplacementStatus(entryReplacementStatus::NONE);
     $entry->setStatus($tempEntry->getStatus());
     $entry->save();
     myEntryUtils::deleteEntry($tempEntry, null, true);
     $te = new TrackEntry();
     $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_REPLACED_ENTRY);
     $te->setEntryId($entry->getId());
     $te->setParam1Str($tempEntry->getId());
     $te->setDescription(__METHOD__ . "[" . __LINE__ . "]");
     TrackEntry::addTrackEntry($te);
 }
Example #3
0
 /**
  * Update annotation by id 
  * 
  * @action update
  * @param string $id
  * @param KalturaAnnotation $annotation
  * @return KalturaAnnotation
  */
 function updateAction($id, KalturaAnnotation $annotation)
 {
     kalturalog::debug("annotation service updateAction");
     $dbAnnotation = AnnotationPeer::retrieveByPK($id);
     if ($dbAnnotation->getType() != AnnotationType::ANNOTATION) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id);
     }
     if (!$dbAnnotation) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id);
     }
     if ($annotation->text !== null) {
         $annotation->validatePropertyMaxLength("text", AnnotationPeer::MAX_ANNOTATION_TEXT);
     }
     if ($annotation->tags !== null) {
         $annotation->validatePropertyMaxLength("tags", AnnotationPeer::MAX_ANNOTATION_TAGS);
     }
     if ($annotation->entryId !== null) {
         $annotation->validateEntryId($annotation, $id);
     }
     if ($annotation->parentId !== null) {
         $annotation->validateParentId($annotation, $id);
     }
     if ($annotation->startTime !== null) {
         $annotation->validateStartTime($annotation, $id);
     }
     if ($annotation->endTime !== null) {
         $annotation->validateEndTime($annotation, $id);
     }
     $dbAnnotation = $annotation->toUpdatableObject($dbAnnotation);
     $dbAnnotation->setKuserId($this->getKuser()->getId());
     $dbAnnotation->save();
     $annotation->fromObject($dbAnnotation);
     return $annotation;
 }
 public function applyCondition(IKalturaIndexQuery $query, $xPaths = null)
 {
     $this->parentQuery = $query;
     if (!$this->condition) {
         if (is_null($xPaths)) {
             $xPaths = array();
             $profileFields = MetadataProfileFieldPeer::retrieveActiveByMetadataProfileId($this->metadataProfileId);
             foreach ($profileFields as $profileField) {
                 $xPaths[$profileField->getXpath()] = $profileField;
             }
         }
         $dataConditions = array();
         $subConditions = array();
         $pluginName = MetadataPlugin::PLUGIN_NAME;
         if (count($this->items)) {
             foreach ($this->items as $item) {
                 $dataCondition = null;
                 if ($item instanceof AdvancedSearchFilterComparableCondition) {
                     /* @var $item AdvancedSearchFilterComparableCondition  */
                     $field = $item->getField();
                     if (!isset($xPaths[$field])) {
                         $this->addCondition('1 <> 1');
                         KalturaLog::ERR("Missing field: {$field} in xpath array: " . print_r($xPaths, true));
                         continue;
                     }
                     switch ($item->getComparison()) {
                         case KalturaSearchConditionComparison::EQUEL:
                             $comparison = ' = ';
                             break;
                         case KalturaSearchConditionComparison::GREATER_THAN:
                             $comparison = ' > ';
                             break;
                         case KalturaSearchConditionComparison::GREATER_THAN_OR_EQUEL:
                             $comparison = ' >= ';
                             break;
                         case KalturaSearchConditionComparison::LESS_THAN:
                             $comparison = " < ";
                             break;
                         case KalturaSearchConditionComparison::LESS_THAN_OR_EQUEL:
                             $comparison = " <= ";
                             break;
                         default:
                             KalturaLog::ERR("Missing comparison type");
                             continue;
                     }
                     $metadataField = $this->getMetadataSearchField($field, $xPaths);
                     if (!$metadataField) {
                         KalturaLog::ERR("Missing metadataField for {$field} in xpath array: " . print_r($xPaths, true));
                         continue;
                     }
                     $value = $item->getValue();
                     if (!is_numeric($value)) {
                         switch ($value) {
                             case Criteria::CURRENT_DATE:
                                 $d = getdate();
                                 $value = mktime(0, 0, 0, $d['mon'], $d['mday'], $d['year']);
                                 break;
                             case Criteria::CURRENT_TIME:
                             case Criteria::CURRENT_TIMESTAMP:
                                 $value = time();
                                 break;
                             default:
                                 if ($xPaths[$field]->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_DATE || $xPaths[$field]->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_INT) {
                                     $this->addCondition('1 <> 1');
                                     KalturaLog::ERR("wrong search value: {$field} is numeric. search value: " . print_r($item->getValue(), true));
                                     continue;
                                 }
                                 $value = SphinxUtils::escapeString($value);
                                 break;
                         }
                     }
                     $newCondition = $metadataField . $comparison . $value;
                     if ($item->getComparison() != KalturaSearchConditionComparison::EQUEL) {
                         $newCondition = "({$newCondition} AND {$metadataField} <> 0)";
                     }
                     $this->addCondition($newCondition);
                 } elseif ($item instanceof AdvancedSearchFilterCondition) {
                     $field = $item->getField();
                     if (!isset($xPaths[$field])) {
                         $this->addCondition('1 <> 1');
                         KalturaLog::ERR("Missing field: {$field} in xpath array: " . print_r($xPaths, true));
                         continue;
                     }
                     $value = $item->getValue();
                     $value = SphinxUtils::escapeString($value);
                     $fieldId = $xPaths[$field]->getId();
                     // any value in the field
                     if (trim($value) == '*') {
                         $dataCondition = "{$pluginName}_{$fieldId}";
                     } elseif ($xPaths[$field]->getType() == self::KMC_FIELD_TYPE_LIST) {
                         $dataCondition = "\\\"{$pluginName}_{$fieldId} {$value} " . kMetadataManager::SEARCH_TEXT_SUFFIX . "_{$fieldId}" . "\\\"";
                     } else {
                         $dataCondition = "{$pluginName}_{$fieldId} << ( {$value} ) << " . kMetadataManager::SEARCH_TEXT_SUFFIX . "_{$fieldId}";
                     }
                     kalturalog::debug("add {$dataCondition}");
                     $dataConditions[] = "( {$dataCondition} )";
                 } elseif ($item instanceof MetadataSearchFilter) {
                     $item->applyCondition($this, $xPaths);
                 }
             }
         }
         if (count($dataConditions)) {
             $glue = $this->type == MetadataSearchFilter::SEARCH_AND ? ' ' : ' | ';
             $dataConditions = array_unique($dataConditions);
             $key = '@' . $this->getMetadataSearchField();
             $value = implode($glue, $dataConditions);
             $this->addMatch("{$key} {$value}");
         }
         $matchClause = array_unique($this->matchClause);
         $glue = $this->type == self::SEARCH_AND ? ' ' : ' | ';
         $this->condition = implode($glue, $matchClause);
         if ($this->type == self::SEARCH_OR) {
             $this->condition = "( {$this->condition} )";
         }
     }
     if ($this->condition) {
         $query->addMatch($this->condition);
     }
     if (isset($this->orderBy)) {
         $orderByField = substr($this->orderBy, 1);
         $orderByAscending = $this->orderBy[0] == '+' ? true : false;
         $metadataField = $this->getMetadataSearchField($orderByField);
         if ($metadataField) {
             if ($orderByAscending) {
                 $query->addOrderBy($metadataField, Criteria::ASC);
             } else {
                 $query->addOrderBy($metadataField, Criteria::DESC);
             }
         }
     }
 }