Skip to content

Commit

Permalink
Merge pull request kaltura#5583 from kaltura/Lynx-12.16.0-PS-3045
Browse files Browse the repository at this point in the history
Lynx 12.16.0 ps 3045
  • Loading branch information
shpiNi authored May 22, 2017
2 parents 2c2c69f + 47ec418 commit fab242c
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 2 deletions.
35 changes: 34 additions & 1 deletion alpha/lib/model/conversionProfile2.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class conversionProfile2 extends BaseconversionProfile2 implements ISyncableFile
const CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV = 4;

const FILE_SYNC_MRSS_XSL = 1;
const FILE_SYNC_MEDIAINFO_XSL = 2;

private $xsl;
private $mediaInfoXsl;

protected $isDefault;

Expand Down Expand Up @@ -52,6 +54,7 @@ private static function validateFileSyncSubType($sub_type)
{
$valid_sub_types = array(
self::FILE_SYNC_MRSS_XSL,
self::FILE_SYNC_MEDIAINFO_XSL,
);

if(! in_array($sub_type, $valid_sub_types))
Expand All @@ -65,7 +68,12 @@ public function getSyncKey($sub_type, $version = null)
{
self::validateFileSyncSubType($sub_type);
if(!$version)
$version = $this->getVersion();
{
if($sub_type == self::FILE_SYNC_MRSS_XSL)
$version = $this->getVersion();
else
$version = $this->getMediaInfoXslVersion();
}

$key = new FileSyncKey();
$key->object_type = FileSyncObjectType::CONVERSION_PROFILE;
Expand Down Expand Up @@ -94,13 +102,25 @@ public function getVersion()
return $this->getFromCustomData("xslVersion", null, 0);
}

public function getMediaInfoXslVersion()
{
return $this->getFromCustomData("mediaInfoXslVersion", null, 0);
}

public function incrementXslVersion()
{
$newVersion = kFileSyncUtils::calcObjectNewVersion($this->getId(), $this->getVersion(), FileSyncObjectType::CONVERSION_PROFILE, self::FILE_SYNC_MRSS_XSL);

$this->putInCustomData("xslVersion", $newVersion);
}

public function incrementMediaInfoXslVersion()
{
$newVersion = kFileSyncUtils::calcObjectNewVersion($this->getId(), $this->getMediaInfoXslVersion(), FileSyncObjectType::CONVERSION_PROFILE, self::FILE_SYNC_MEDIAINFO_XSL);

$this->putInCustomData("mediaInfoXslVersion", $newVersion);
}

/**
* (non-PHPdoc)
* @see lib/model/ISyncableFile#generateFilePathArr()
Expand Down Expand Up @@ -130,6 +150,19 @@ public function getXsl()
$this->xsl = kFileSyncUtils::file_get_contents($key, true, false);
return $this->xsl;
}

/**
* @return string
*/
public function getMediaInfoXslTransformation()
{
if (!is_null($this->mediaInfoXsl))
return $this->mediaInfoXsl;

$key = $this->getSyncKey(self::FILE_SYNC_MEDIAINFO_XSL);
$this->mediaInfoXsl = kFileSyncUtils::file_get_contents($key, true, false);
return $this->mediaInfoXsl;
}

/* (non-PHPdoc)
* @see BaseconversionProfile2::setDeletedAt()
Expand Down
44 changes: 44 additions & 0 deletions alpha/lib/model/mediaInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,48 @@ public function getComplexityValue() {return $this->getFromCustomData('Complexit

public function setMaxGOP($v) {$this->putInCustomData('MaxGOP', $v);}
public function getMaxGOP() {return $this->getFromCustomData('MaxGOP', null, null);}

public function getRawDataXml()
{
$rawData = $this->getRawData();
$tokenizer = new KStringTokenizer ( $rawData, "\t\n" );

$rawDataXml = new DOMDocument();
$rootNode = $rawDataXml->createElement("RawData");
$root = $rawDataXml->appendChild($rootNode);
while($tokenizer->hasMoreTokens())
{
$rawDataLine = trim($tokenizer->nextToken());
if(!$rawDataLine)
continue;

if(strpos($rawDataLine, ":") === false)
{
$key = $rawDataLine;
$value = "";
}
else
{
list($key, $value) = explode(":", $rawDataLine);
}
$key = str_replace(" ", "",$key);
$key = preg_replace('/[^A-Za-z0-9]/', '_', $key);

if (!$value)
{
$parentNode = $rawDataXml->createElement($key);
$root->appendChild($parentNode);
}
else
{
$value = trim($value);
$node = $rawDataXml->createElement($key);
$value = $rawDataXml->createTextNode (htmlspecialchars($value));
$node->appendChild($value);
$parentNode->appendChild($node);
}
}

return $rawDataXml->saveXML();
}
}
12 changes: 12 additions & 0 deletions api_v3/lib/types/conversionProfile/KalturaConversionProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ class KalturaConversionProfile extends KalturaObject implements IRelatedFilterab
*/
public $detectGOP;

/**
* XSL to transform ingestion Media Info XML
*
* @var string
*/
public $mediaInfoXslTransformation;

private static $map_between_objects = array
(
"id",
Expand Down Expand Up @@ -218,6 +225,11 @@ public function doFromObject($sourceObject, KalturaDetachedResponseProfile $resp
$this->cropDimensions = new KalturaCropDimensions();
$this->cropDimensions->fromObject($sourceObject);
}

if($this->shouldGet('mediaInfoXslTransformation', $responseProfile))
{
$this->mediaInfoXslTransformation = $sourceObject->getMediaInfoXslTransformation();
}
}

public function toObject($objectToFill = null , $propsToSkip = array())
Expand Down
20 changes: 20 additions & 0 deletions api_v3/services/ConversionProfileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public function addAction(KalturaConversionProfile $conversionProfile)

if($conversionProfile->xslTransformation)
$conversionProfileDb->incrementXslVersion();

if($conversionProfile->mediaInfoXslTransformation)
$conversionProfileDb->incrementMediaInfoXslVersion();

$conversionProfileDb->save();

Expand All @@ -119,6 +122,13 @@ public function addAction(KalturaConversionProfile $conversionProfile)
kFileSyncUtils::file_put_contents($key, $xsl);
}

if($conversionProfile->mediaInfoXslTransformation)
{
$xsl = html_entity_decode($conversionProfile->mediaInfoXslTransformation);
$key = $conversionProfileDb->getSyncKey(conversionProfile2::FILE_SYNC_MEDIAINFO_XSL);
kFileSyncUtils::file_put_contents($key, $xsl);
}

$conversionProfile->fromObject($conversionProfileDb, $this->getResponseProfile());

// load flavor params id with the same connection (master connection) that was used for insert
Expand Down Expand Up @@ -171,6 +181,9 @@ public function updateAction($id, KalturaConversionProfile $conversionProfile)

if($conversionProfile->xslTransformation)
$conversionProfileDb->incrementXslVersion();

if($conversionProfile->mediaInfoXslTransformation)
$conversionProfileDb->incrementMediaInfoXslVersion();

$conversionProfileDb->save();

Expand All @@ -191,6 +204,13 @@ public function updateAction($id, KalturaConversionProfile $conversionProfile)
kFileSyncUtils::file_put_contents($key, $xsl);
}

if($conversionProfile->mediaInfoXslTransformation)
{
$xsl = html_entity_decode($conversionProfile->mediaInfoXslTransformation);
$key = $conversionProfileDb->getSyncKey(conversionProfile2::FILE_SYNC_MEDIAINFO_XSL);
kFileSyncUtils::file_put_contents($key, $xsl);
}

$conversionProfile->fromObject($conversionProfileDb, $this->getResponseProfile());
// load flavor params id with the same connection (master connection) that was used for insert
$con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_MASTER);
Expand Down
9 changes: 8 additions & 1 deletion plugins/bulk_upload/xml/BulkUploadXmlPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
/**
* @package plugins.bulkUploadXml
*/
class BulkUploadXmlPlugin extends KalturaPlugin implements IKalturaBulkUpload, IKalturaVersion, IKalturaSchemaDefiner, IKalturaPending
class BulkUploadXmlPlugin extends KalturaPlugin implements IKalturaBulkUpload, IKalturaVersion, IKalturaSchemaDefiner, IKalturaPending, IKalturaEventConsumers
{
const PLUGIN_NAME = 'bulkUploadXml';
const PLUGIN_VERSION_MAJOR = 1;
const PLUGIN_VERSION_MINOR = 1;
const PLUGIN_VERSION_BUILD = 0;

const BULKUPLOAD_XML_FLOW_MANAGER = "kBulkUploadXmlFlowManager";

/* (non-PHPdoc)
* @see IKalturaPlugin::getPluginName()
*/
Expand Down Expand Up @@ -245,4 +247,9 @@ public static function getApiValue($valueName)
{
return self::getPluginName() . IKalturaEnumerator::PLUGIN_VALUE_DELIMITER . $valueName;
}

public static function getEventConsumers()
{
return array(self::BULKUPLOAD_XML_FLOW_MANAGER);
}
}
71 changes: 71 additions & 0 deletions plugins/bulk_upload/xml/lib/kBulkUploadXmlFlowManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

class kBulkUploadXmlFlowManager implements kBatchJobStatusEventConsumer
{
/**
* @param BatchJob $dbBatchJob
* @return bool true if should continue to the next consumer
*/
public function updatedJob(BatchJob $dbBatchJob)
{
KalturaLog::debug("Handling finished ExtractMedia job!");

$profile = myPartnerUtils::getConversionProfile2ForEntry($dbBatchJob->getEntryId());
$mediaInfoXslt = $profile->getMediaInfoXslTransformation();
if (!$mediaInfoXslt)
{
return true;
}

$mediaInfo = mediaInfoPeer::retrieveByPk($dbBatchJob->getData()->getMediaInfoId());
$mediaInfoRawData = $mediaInfo->getRawDataXml();

$transformedXml = kXml::transformXmlUsingXslt($mediaInfoRawData, $mediaInfoXslt, array("entryId" => $dbBatchJob->getEntryId()));
$xml = new KDOMDocument();
if(!$xml->loadXML($transformedXml))
{
KalturaLog::err("Could not load xml string");
return true;
}

if(!$xml->getElementsByTagName("entryId")->item(0))
{
KalturaLog::err("XML structure is incorrect - must contain tag entry ID");
return true;
}
$transformedXml = $xml->saveXML();

//Save the file to a shared temporary location
$tmpSharedFolder = myContentStorage::getFSContentRootPath() . "/tmp/bulkupload/";
$fileName = $dbBatchJob->getEntryId() . '_update_' . time() . ".xml";
$filePath = $tmpSharedFolder . DIRECTORY_SEPARATOR. $fileName;
$res = file_put_contents($filePath, $transformedXml);
chmod($filePath, 0640);

$jobData = new kBulkUploadXmlJobData();
$jobData->setFileName($fileName);
$jobData->setFilePath($filePath);
$jobData->setBulkUploadObjectType(BulkUploadObjectType::ENTRY);
$jobData->setObjectData(new kBulkUploadEntryData());
$bulkUploadCoreType = BulkUploadXmlPlugin::getBulkUploadTypeCoreValue(BulkUploadXmlType::XML);

kJobsManager::addBulkUploadJob($dbBatchJob->getPartner(), $jobData, $bulkUploadCoreType);

return true;
}

/**
* @param BatchJob $dbBatchJob
* @return bool true if the consumer should handle the event
*/
public function shouldConsumeJobStatusEvent(BatchJob $dbBatchJob)
{
if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED && $dbBatchJob->getJobType() == BatchJobType::EXTRACT_MEDIA)
{
return true;
}

return false;
}

}

0 comments on commit fab242c

Please sign in to comment.