Exemplo n.º 1
0
 /**
  * @param KalturaMetadataFilter $filter
  * @param $shouldUpdate
  * @return int
  */
 protected function indexMetadataObjects(KalturaMetadataFilter $filter, $shouldUpdate)
 {
     $filter->orderBy = KalturaMetadataOrderBy::CREATED_AT_ASC;
     $metadataPlugin = KalturaMetadataClientPlugin::get(KBatchBase::$kClient);
     $metadataList = $metadataPlugin->metadata->listAction($filter, $this->pager);
     if (!count($metadataList->objects)) {
         return 0;
     }
     KBatchBase::$kClient->startMultiRequest();
     foreach ($metadataList->objects as $metadata) {
         $metadataPlugin->metadata->index($metadata->id, $shouldUpdate);
     }
     $results = KBatchBase::$kClient->doMultiRequest();
     foreach ($results as $index => $result) {
         if (!is_int($result)) {
             unset($results[$index]);
         }
     }
     if (!count($results)) {
         return 0;
     }
     $lastIndexId = end($results);
     $this->setLastIndexId($lastIndexId);
     return count($results);
 }
Exemplo n.º 2
0
function kaltura_meta_profile()
{
    $metadataPlugin = KalturaMetadataClientPlugin::get($mypenguin->getClientconf());
    $result = $metadataPlugin->metadataprofile->listAction();
    ?>
  <form method = "post" action = "">
    <table>
      <tr>
        <td><label for="row">zaglavie</label></td>
        <td><input type="text" id="row"></td>
      </tr>
    </table>
    <?php 
    var_dump($result);
    ?>
  </form>
  <?php 
}
 /**
  * @param KalturaBaseEntry $object
  */
 function processObject($object)
 {
     /** @var KalturaExecuteMetadataXsltObjectTask $objectTask */
     $objectTask = $this->getObjectTask();
     if (is_null($objectTask)) {
         return;
     }
     $entryId = $object->id;
     $metadataProfileId = $objectTask->metadataProfileId;
     $metadataObjectType = $objectTask->metadataObjectType;
     $xslt = $objectTask->xslt;
     $client = $this->getClient();
     $metadataPlugin = KalturaMetadataClientPlugin::get($client);
     $filter = new KalturaMetadataFilter();
     $filter->objectIdEqual = $entryId;
     $filter->metadataProfileIdEqual = $metadataProfileId;
     $filter->metadataObjectTypeEqual = $metadataObjectType;
     try {
         $this->impersonate($object->partnerId);
         $metadataResult = $metadataPlugin->metadata->listAction($filter);
         $this->unimpersonate();
     } catch (Exception $ex) {
         $this->unimpersonate();
         throw $ex;
     }
     if (!count($metadataResult->objects)) {
         KalturaLog::info(sprintf('Metadata object was not found for entry %s, profile id %s and object type %s', $entryId, $metadataProfileId, $metadataObjectType));
         return;
     }
     $xsltFilePath = sys_get_temp_dir() . '/xslt_' . time(true) . '.xslt';
     file_put_contents($xsltFilePath, $xslt);
     $metadataId = $metadataResult->objects[0]->id;
     try {
         $this->impersonate($object->partnerId);
         $metadataPlugin->metadata->updateFromXSL($metadataId, $xsltFilePath);
         $this->unimpersonate();
     } catch (Exception $ex) {
         $this->unimpersonate();
         throw $ex;
     }
     unlink($xsltFilePath);
 }
 /**
  * @return KalturaMetadataClientPlugin
  */
 public static function get(KalturaClient $client)
 {
     if (!self::$instance) {
         self::$instance = new KalturaMetadataClientPlugin($client);
     }
     return self::$instance;
 }
 public function handleCustomData($objectId, SimpleXMLElement $customData)
 {
     $action = KBulkUploadEngine::$actionsMap[KalturaBulkUploadAction::REPLACE];
     if (isset($customData->action)) {
         $action = strtolower($customData->action);
     }
     $metadataProfileId = null;
     if (!empty($customData['metadataProfileId'])) {
         $metadataProfileId = (int) $customData['metadataProfileId'];
     }
     if (!$metadataProfileId && !empty($customData['metadataProfile'])) {
         $metadataProfileId = $this->getMetadataProfileId($customData['metadataProfile']);
     }
     if (!$metadataProfileId) {
         throw new KalturaBatchException("Missing custom data metadataProfile attribute", KalturaBatchJobAppErrors::BULK_MISSING_MANDATORY_PARAMETER);
     }
     $metadataPlugin = KalturaMetadataClientPlugin::get(KBatchBase::$kClient);
     $metadataFilter = new KalturaMetadataFilter();
     $metadataFilter->metadataObjectTypeEqual = $this->objectType;
     $metadataFilter->objectIdEqual = $objectId;
     $metadataFilter->metadataProfileIdEqual = $metadataProfileId;
     $pager = new KalturaFilterPager();
     $pager->pageSize = 1;
     $metadataListResponse = $metadataPlugin->metadata->listAction($metadataFilter, $pager);
     $metadataId = null;
     $metadata = null;
     if (is_array($metadataListResponse->objects) && count($metadataListResponse->objects) > 0) {
         $metadata = reset($metadataListResponse->objects);
         $metadataId = $metadata->id;
     }
     switch ($action) {
         case KBulkUploadEngine::$actionsMap[KalturaBulkUploadAction::TRANSFORM_XSLT]:
             if (!isset($customData->xslt)) {
                 throw new KalturaBatchException($this->containerName . '->' . $this->nodeName . "->xslt element is missing", KalturaBatchJobAppErrors::BULK_ELEMENT_NOT_FOUND);
             }
             if ($metadata) {
                 $metadataXml = $metadata->xml;
             } else {
                 $metadataXml = '<metadata></metadata>';
             }
             $decodedXslt = kXml::decodeXml($customData->xslt);
             $metadataXml = kXml::transformXmlUsingXslt($metadataXml, $decodedXslt);
             break;
         case KBulkUploadEngine::$actionsMap[KalturaBulkUploadAction::REPLACE]:
             if (!isset($customData->xmlData)) {
                 throw new KalturaBatchException($this->containerName . '->' . $this->nodeName . "->xmlData element is missing", KalturaBatchJobAppErrors::BULK_ELEMENT_NOT_FOUND);
             }
             $metadataXmlObject = $customData->xmlData->children();
             $metadataXml = $metadataXmlObject->asXML();
             break;
         default:
             throw new KalturaBatchException($this->containerName . '->' . $this->nodeName . "->action: {$action} is not supported", KalturaBatchJobAppErrors::BULK_ACTION_NOT_SUPPORTED);
     }
     if ($metadataId) {
         $metadataPlugin->metadata->update($metadataId, $metadataXml);
     } else {
         $metadataPlugin->metadata->add($metadataProfileId, $this->objectType, $objectId, $metadataXml);
     }
 }
 /**
  * 
  * Adds the metadata search test data
  * @param KalturaClient $client
  */
 protected static function addMetadataSearchData(KalturaClient $client)
 {
     //add metadata profile
     $metadataProfile = new KalturaMetadataProfile();
     $metadataProfile->name = 'Metadata profile for tests';
     $metadataProfile->createMode = KalturaMetadataProfileCreateMode::API;
     $metadataProfile->systemName = 'Metadata profile for tests';
     $metadataProfileXsd = '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">   <xsd:element name="metadata">     <xsd:complexType>       <xsd:sequence>         <xsd:element id="md_90192848-AAE47-03390173D13A"         name="Startdate" minOccurs="0" maxOccurs="1" type="dateType">           <xsd:annotation>             <xsd:documentation></xsd:documentation>             <xsd:appinfo>               <label>startdate</label>               <key>startdate</key>               <searchable>true</searchable>               <description></description>             </xsd:appinfo>           </xsd:annotation>         </xsd:element>         <xsd:element id="md_D7EAD7A91-6360-BF2F-03393913BE11"         name="Enddate" minOccurs="0" maxOccurs="1" type="dateType">           <xsd:annotation>             <xsd:documentation></xsd:documentation>             <xsd:appinfo>               <label>enddate</label>               <key>enddate</key>               <searchable>true</searchable>               <description></description>             </xsd:appinfo>           </xsd:annotation>         </xsd:element> 		<xsd:element id="md_D7EADC16-791-6360-BF2F-03393913Bs11"         name="MyNumber" minOccurs="0" maxOccurs="1" type="intType">           <xsd:annotation>             <xsd:documentation></xsd:documentation>             <xsd:appinfo>               <label>MyNumber</label>               <key>MyNumber</key>               <searchable>true</searchable>               <description></description>             </xsd:appinfo>           </xsd:annotation>         </xsd:element> 		<xsd:element id="md_D7EADC16-7A91-6360F-03393913Bs11"         name="MyNumber2" minOccurs="0" maxOccurs="1" type="intType">           <xsd:annotation>             <xsd:documentation></xsd:documentation>             <xsd:appinfo>               <label>MyNumber2</label>               <key>MyNumber2</key>               <searchable>true</searchable>               <description></description>             </xsd:appinfo>           </xsd:annotation>         </xsd:element> 		<xsd:element id="md_D7EADC16-7A91-6360-BF2F-033932s11"         name="MyNumber3" minOccurs="0" maxOccurs="1" type="intType">           <xsd:annotation>             <xsd:documentation></xsd:documentation>             <xsd:appinfo>               <label>MyNumber3</label>               <key>MyNumber3</key>               <searchable>true</searchable>               <description></description>             </xsd:appinfo>           </xsd:annotation>         </xsd:element>         <xsd:element id="md_C084580E-43B0-38A7-9F23-033B3"         name="MyTextList" minOccurs="0" maxOccurs="1">           <xsd:annotation>             <xsd:documentation></xsd:documentation>             <xsd:appinfo>               <label>my text list</label>               <key>my text list</key>               <searchable>true</searchable>               <description></description>             </xsd:appinfo>           </xsd:annotation>           <xsd:simpleType>             <xsd:restriction base="listType">               <xsd:enumeration value="a1" />               <xsd:enumeration value="b2" />               <xsd:enumeration value="c3" />             </xsd:restriction>           </xsd:simpleType>         </xsd:element> 		<xsd:element id="md_D7EADC16-7ABF2F-033932s11"         name="MyTest" minOccurs="0" maxOccurs="1" type="textType">           <xsd:annotation>             <xsd:documentation></xsd:documentation>             <xsd:appinfo>               <label>MyTest</label>               <key>MyTest</key>               <searchable>true</searchable>               <description></description>             </xsd:appinfo>           </xsd:annotation>         </xsd:element>       </xsd:sequence>     </xsd:complexType>   </xsd:element>   <xsd:complexType name="textType">     <xsd:simpleContent>       <xsd:extension base="xsd:string" />     </xsd:simpleContent>   </xsd:complexType>     <xsd:complexType name="intType">     <xsd:simpleContent>       <xsd:extension base="xsd:long" />     </xsd:simpleContent>   </xsd:complexType>   <xsd:complexType name="dateType">     <xsd:simpleContent>       <xsd:extension base="xsd:long" />     </xsd:simpleContent>   </xsd:complexType>   <xsd:complexType name="objectType">     <xsd:simpleContent>       <xsd:extension base="xsd:string" />     </xsd:simpleContent>   </xsd:complexType>   <xsd:simpleType name="listType">     <xsd:restriction base="xsd:string" />   </xsd:simpleType> </xsd:schema>';
     $metadataClient = KalturaMetadataClientPlugin::get($client);
     $metadataProfile = $metadataClient->metadataProfile->add($metadataProfile, $metadataProfileXsd);
     KalturaGlobalData::setData("@METADATA_SEARCH_PROFILE_ID@", $metadataProfile->id);
     KalturaGlobalData::setData("@METADATA_SEARCH_FIELD_NAME1@", '/*[local-name()=\'metadata\']/*[local-name()=\'MyTest\']');
     KalturaGlobalData::setData("@METADATA_SEARCH_FIELD_VALUE1@", 'myTest');
     KalturaGlobalData::setData("@METADATA_SEARCH_FIELD_NAME2@", '/*[local-name()=\'metadata\']/*[local-name()=\'Startdate\']');
     KalturaGlobalData::setData("@METADATA_SEARCH_FIELD_VALUE2@", '1310503500');
     KalturaGlobalData::setData("@METADATA_SEARCH_FIELD_NAME3@", '/*[local-name()=\'metadata\']/*[local-name()=\'MyNumber\']');
     //add entries
     $entries = array();
     $xmlData = array(0 => '<metadata><Startdate>1310503400</Startdate><Enddate>1310504000</Enddate><MyNumber>6</MyNumber><MyNumber2>2</MyNumber2><MyNumber3>3</MyNumber3><MyTextList>a1</MyTextList><MyTest>myTest</MyTest></metadata>', 1 => '<metadata><Startdate>1310503000</Startdate><Enddate>1310508000</Enddate><MyNumber>3</MyNumber><MyNumber2>4</MyNumber2><MyNumber3>5</MyNumber3><MyTextList>b2</MyTextList><MyTest>just some words...</MyTest></metadata>', 2 => '<metadata><Startdate>1310504000</Startdate><Enddate>1310508000</Enddate><MyNumber>2</MyNumber><MyNumber2>5</MyNumber2><MyNumber3>6</MyNumber3><MyTextList>b2</MyTextList><MyTest>just some words...</MyTest></metadata>', 3 => '<metadata><Startdate>1310508000</Startdate><Enddate>1310509000</Enddate><MyNumber>5</MyNumber><MyNumber2>2</MyNumber2><MyNumber3>8</MyNumber3><MyTextList>a1</MyTextList><MyTest>myTest</MyTest></metadata>', 4 => '<metadata><Startdate>1310504000</Startdate><Enddate>1310509000</Enddate><MyNumber>4</MyNumber><MyNumber2>4</MyNumber2><MyNumber3>4</MyNumber3><MyTextList>a1</MyTextList><MyTest>myTest</MyTest></metadata>');
     KalturaGlobalData::setData("@METADATA_TEST_XML@", $xmlData[0]);
     $entry = new KalturaMediaEntry();
     for ($i = 0; $i < count($xmlData); $i++) {
         $entry->id = null;
         $entry->name = 'Entry For metadataSearch ' . $i;
         $entry->type = KalturaEntryType::MEDIA_CLIP;
         $entry->mediaType = KalturaMediaType::VIDEO;
         $newEntry = $client->media->add($entry, KalturaEntryType::MEDIA_CLIP);
         $contentResource = new KalturaUrlResource();
         $contentResource->url = "http://sites.google.com/site/demokmc/Home/titanicin5seconds.flv";
         $client->media->addContent($newEntry->id, $contentResource);
         //add metadata
         sleep(1);
         //sync with sphinx
         $entries[$i] = $newEntry->id;
         $metadataClient->metadata->add($metadataProfile->id, KalturaMetadataObjectType::ENTRY, $newEntry->id, $xmlData[$i]);
     }
     $expectedResults = $entries[4] . ',' . $entries[3];
     KalturaGlobalData::setData("@METADATA_SEARCH_ENTRIES_IDS@", $expectedResults);
 }
 /**
  * Sync target objects
  * @param KalturaDistributionJobData $jobData
  * @param CrossKalturaEntryObjectsContainer $targetObjects
  */
 protected function sync(KalturaDistributionJobData $jobData, CrossKalturaEntryObjectsContainer $targetObjects)
 {
     $syncedObjects = new CrossKalturaEntryObjectsContainer();
     $targetEntryId = $jobData->remoteId;
     // add/update entry
     if ($targetEntryId) {
         // update entry
         KalturaLog::info('Updating target entry id [' . $targetEntryId . ']');
         $syncedObjects->entry = $this->targetClient->baseEntry->update($targetEntryId, $targetObjects->entry);
     } else {
         // add entry
         $syncedObjects->entry = $this->targetClient->baseEntry->add($targetObjects->entry);
         $targetEntryId = $syncedObjects->entry->id;
         KalturaLog::info('New target entry added with id [' . $targetEntryId . ']');
     }
     $this->targetEntryId = $targetEntryId;
     // sync metadata objects
     foreach ($targetObjects->metadataObjects as $metadataObj) {
         /* @var $metadataObj KalturaMetadata */
         $metadataObj->objectId = $targetEntryId;
     }
     $targetMetadataClient = KalturaMetadataClientPlugin::get($this->targetClient);
     $syncedObjects->metadataObjects = $this->syncTargetEntryObjects($targetMetadataClient->metadata, $targetObjects->metadataObjects, $this->sourceObjects->metadataObjects, $jobData->providerData->distributedMetadata, $targetEntryId, 'getMetadataAddArgs', 'getMetadataUpdateArgs');
     // sync flavor assets
     $syncedObjects->flavorAssets = $this->syncTargetEntryObjects($this->targetClient->flavorAsset, $targetObjects->flavorAssets, $this->sourceObjects->flavorAssets, $jobData->providerData->distributedFlavorAssets, $targetEntryId);
     // sync flavor content
     $this->syncAssetsContent($this->targetClient->flavorAsset, $targetObjects->flavorAssetsContent, $syncedObjects->flavorAssets, $jobData->providerData->distributedFlavorAssets, $this->sourceObjects->flavorAssets);
     // sync thumbnail assets
     $syncedObjects->thumbAssets = $this->syncTargetEntryObjects($this->targetClient->thumbAsset, $targetObjects->thumbAssets, $this->sourceObjects->thumbAssets, $jobData->providerData->distributedThumbAssets, $targetEntryId);
     // sync thumbnail content
     $this->syncAssetsContent($this->targetClient->thumbAsset, $targetObjects->thumbAssetsContent, $syncedObjects->thumbAssets, $jobData->providerData->distributedThumbAssets, $this->sourceObjects->thumbAssets);
     // sync caption assets
     if ($this->distributeCaptions) {
         $targetCaptionClient = KalturaCaptionClientPlugin::get($this->targetClient);
         $syncedObjects->captionAssets = $this->syncTargetEntryObjects($targetCaptionClient->captionAsset, $targetObjects->captionAssets, $this->sourceObjects->captionAssets, $jobData->providerData->distributedCaptionAssets, $targetEntryId);
         // sync caption content
         $this->syncAssetsContent($targetCaptionClient->captionAsset, $targetObjects->captionAssetsContent, $syncedObjects->captionAssets, $jobData->providerData->distributedCaptionAssets, $this->sourceObjects->captionAssets);
     }
     // sync cue points
     if ($this->distributeCuePoints) {
         foreach ($targetObjects->cuePoints as $cuePoint) {
             /* @var $cuePoint KalturaCuePoint */
             $cuePoint->entryId = $targetEntryId;
         }
         $targetCuePointClient = KalturaCuePointClientPlugin::get($this->targetClient);
         $syncedObjects->cuePoints = $this->syncTargetEntryObjects($targetCuePointClient->cuePoint, $targetObjects->cuePoints, $this->sourceObjects->cuePoints, $jobData->providerData->distributedCuePoints, $targetEntryId, 'getCuePointAddArgs');
     }
     return $syncedObjects;
 }
$partnerId = $argv[1];
$secret = $argv[2];
$type = KalturaSessionType::ADMIN;
$config = new KalturaConfiguration($partnerId);
$config->serviceUrl = $argv[3];
$client = new KalturaClient($config);
$ks = $client->session->start($secret, $userId, $type, $partnerId, $expiry, $privileges);
$client->setKs($ks);
$pager = null;
$filter = new KalturaMetadataProfileFilter();
$profile_name = METADATA_SYSTEM_NAME;
$filter->systemNameEqual = $profile_name;
$results = $client->metadataProfile->listAction($filter, $pager);
if ($results->totalCount) {
    $metadata_prof_id = $results->objects[0]->id;
    $metadataPlugin = KalturaMetadataClientPlugin::get($client);
    $result = $metadataPlugin->metadataProfile->listFields($metadata_prof_id);
    echo "Found {$profile_name}, ID {$metadata_prof_id}.\n";
} else {
    echo "Could not find {$profile_name}. Exiting.\n";
    exit(1);
}
$filter = new KalturaMediaEntryFilter();
$filterAdvancedSearch = new KalturaMetadataSearchItem();
$filterAdvancedSearch->metadataProfileId = $metadata_prof_id;
$filterAdvancedSearchItems = new KalturaSearchCondition();
$filterAdvancedSearchItems->field = "/*[local-name()='metadata']/*[local-name()='ProcessOCR']";
$filterAdvancedSearchItems->value = 'Yes';
$filterAdvancedSearch->items = array($filterAdvancedSearchItems);
$filter->advancedSearch = $filterAdvancedSearch;
//$filter=null;
Exemplo n.º 9
0
 protected function createCategoryAssociations(KalturaDropFolder $folder, $userId, $entryId)
 {
     if ($folder->metadataProfileId && $folder->categoriesMetadataFieldName) {
         $filter = new KalturaMetadataFilter();
         $filter->metadataProfileIdEqual = $folder->metadataProfileId;
         $filter->objectIdEqual = $userId;
         $filter->metadataObjectTypeEqual = KalturaMetadataObjectType::USER;
         try {
             $metadataPlugin = KalturaMetadataClientPlugin::get(KBatchBase::$kClient);
             //Expect only one result
             $res = $metadataPlugin->metadata->listAction($filter, new KalturaFilterPager());
             $metadataObj = $res->objects[0];
             $xmlElem = new SimpleXMLElement($metadataObj->xml);
             $categoriesXPathRes = $xmlElem->xpath($folder->categoriesMetadataFieldName);
             $categories = array();
             foreach ($categoriesXPathRes as $catXPath) {
                 $categories[] = strval($catXPath);
             }
             $categoryFilter = new KalturaCategoryFilter();
             $categoryFilter->idIn = implode(',', $categories);
             $categoryListResponse = KBatchBase::$kClient->category->listAction($categoryFilter, new KalturaFilterPager());
             if ($categoryListResponse->objects && count($categoryListResponse->objects)) {
                 if (!$folder->enforceEntitlement) {
                     //easy
                     $this->createCategoryEntriesNoEntitlement($categoryListResponse->objects, $entryId);
                 } else {
                     //write your will
                     $this->createCategoryEntriesWithEntitlement($categoryListResponse->objects, $entryId, $userId);
                 }
             }
         } catch (Exception $e) {
             KalturaLog::err('Error encountered. Code: [' . $e->getCode() . '] Message: [' . $e->getMessage() . ']');
         }
     }
 }