Skip to content

Commit

Permalink
Merge pull request #8852 from kaltura/Orion-15.2.0-PSVAMB-6815
Browse files Browse the repository at this point in the history
Orion 15.2.0 psvamb 6815
  • Loading branch information
hilak committed Nov 1, 2019
2 parents a4c9c53 + 4bf1d46 commit b01d21f
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 36 deletions.
Expand Up @@ -9,7 +9,7 @@ class KFeedDropFolderEngine extends KDropFolderEngine
/**
* @var array
*/
protected $feedNamespaces;
protected $feedNamespaces = array();

protected $handledUniqueIds = array();

Expand Down Expand Up @@ -54,41 +54,7 @@ public function watchFolder(KalturaDropFolder $dropFolder) {
break;
}

/* @var $feedItem SimpleXMLElement */
$uniqueId = strval($this->getSingleXPathResult($this->dropFolder->feedItemInfo->itemUniqueIdentifierXPath, $feedItem));
if (is_null($uniqueId) || $uniqueId === '')
{
KalturaLog::err("No unique identifier for the current feed item! Skipping.");
continue;
}

//If we already encountered this uniqueId in this run- ignore subsequent iterations.
if (in_array ($uniqueId, $this->handledUniqueIds))
{
KalturaLog::err("The unique identifer value [$uniqueId] was encountered before during this scan of the feed. Ignoring.");
continue;
}

// The unique feed item identifier is the GUID, so that is what we set as the drop folder file name.
if (!array_key_exists($uniqueId, $existingDropFolderFilesMap))
{
//In this case, we are required to add this item as a new drop folder file
KalturaLog::info("Item not found in drop folder file list- adding as new drop folder file.");
$this->handleItemAdded ($uniqueId, $feedItem);
$counter++;
}
else
{
KalturaLog::info("Item found in drop folder file list- adding as existing drop folder file.");
$dropFolderFile = $existingDropFolderFilesMap[$uniqueId];
unset ($existingDropFolderFilesMap[$uniqueId]);
//if file exist in the folder remove it from the map
//all the files that are left in a map will be marked as PURGED
if ($this->handleExistingItem($dropFolderFile, $feedItem))
$counter++;
}

$this->handledUniqueIds[] = $uniqueId;
$counter += $this->watchProcessSingleItem($feedItem, $existingDropFolderFilesMap, $counter);
}

foreach ($existingDropFolderFilesMap as $existingDropFolderFile)
Expand All @@ -98,6 +64,47 @@ public function watchFolder(KalturaDropFolder $dropFolder) {

}

protected function watchProcessSingleItem (SimpleXMLElement $feedItem, array $existingDropFolderFilesMap)
{
$result = 0;

$uniqueId = strval($this->getSingleXPathResult($this->dropFolder->feedItemInfo->itemUniqueIdentifierXPath, $feedItem));
if (is_null($uniqueId) || $uniqueId === '')
{
KalturaLog::err("No unique identifier for the current feed item! Skipping.");
return $result;
}

//If we already encountered this uniqueId in this run- ignore subsequent iterations.
if (in_array ($uniqueId, $this->handledUniqueIds))
{
KalturaLog::err("The unique identifier value [$uniqueId] was encountered before during this scan of the feed. Ignoring.");
return $result;
}

// The unique feed item identifier is the GUID, so that is what we set as the drop folder file name.
if (!array_key_exists($uniqueId, $existingDropFolderFilesMap))
{
//In this case, we are required to add this item as a new drop folder file
KalturaLog::info("Item not found in drop folder file list- adding as new drop folder file.");
$this->handleItemAdded ($uniqueId, $feedItem);
$result = 1;
}
else
{
KalturaLog::info("Item found in drop folder file list- adding as existing drop folder file.");
$dropFolderFile = $existingDropFolderFilesMap[$uniqueId];
unset ($existingDropFolderFilesMap[$uniqueId]);
//if file exist in the folder remove it from the map
//all the files that are left in a map will be marked as PURGED
if ($this->handleExistingItem($dropFolderFile, $feedItem))
$result = 1;
}

$this->handledUniqueIds[] = $uniqueId;

return $result;
}

/**
* Add a new item from the MRSS feed
Expand Down Expand Up @@ -362,6 +369,7 @@ protected function fetchFeedContent ($url)
{
KalturaLog::info("For URL [$url], the curl result is: " . substr($res, 0, 1000));
}

return $res;
}

Expand Down
@@ -0,0 +1,156 @@
<?php
/**
* @package plugins.ApFeedDropFolder
*/
class ApFeedDropFolderPlugin extends KalturaPlugin implements IKalturaPlugin, IKalturaPending, IKalturaObjectLoader, IKalturaEnumerator, IKalturaApplicationTranslations
{
const PLUGIN_NAME = 'ApFeedDropFolder';

const DROP_FOLDER_PLUGIN_NAME = 'dropFolder';
/**
* @return array
*/
public static function getTranslations($locale)
{
$array = array();

$langFilePath = __DIR__ . "/config/lang/$locale.php";
if(!file_exists($langFilePath))
{
$default = 'en';
$langFilePath = __DIR__ . "/config/lang/$default.php";
}

KalturaLog::info("Loading file [$langFilePath]");
$array = include($langFilePath);

return array($locale => $array);
}

/**
* Returns a list of enumeration class names that implement the baseEnumName interface.
* @param string $baseEnumName the base implemented enum interface, set to null to retrieve all plugin enums
* @return array<string> A string listing the enum class names that extend baseEnumName
*/
public static function getEnums($baseEnumName = null)
{
if (!$baseEnumName)
{
return array('ApFeedDropFolderType');
}
if ($baseEnumName == 'DropFolderType')
{
return array('ApFeedDropFolderType');
}

return array();
}

/**
* Returns an object that is known only to the plugin, and extends the baseClass.
*
* @param string $baseClass The base class of the loaded object
* @param string $enumValue The enumeration value of the loaded object
* @param array $constructorArgs The constructor arguments of the loaded object
* @return object
*/
public static function loadObject($baseClass, $enumValue, array $constructorArgs = null)
{
switch ($baseClass)
{
case 'KDropFolderEngine':
if ($enumValue == KalturaDropFolderType::AP_FEED)
{
return new KApFeedDropFolderEngine();
}
break;
case ('KalturaDropFolderFile'):
if ($enumValue == self::getDropFolderTypeCoreValue(ApFeedDropFolderType::AP_FEED) )
{
return new KalturaFeedDropFolderFile();
}
break;
case ('KalturaDropFolder'):
if ($enumValue == self::getDropFolderTypeCoreValue(ApFeedDropFolderType::AP_FEED) )
{
return new KalturaApFeedDropFolder();
}
break;
case 'kDropFolderXmlFileHandler':
if ($enumValue == self::getDropFolderTypeCoreValue(ApFeedDropFolderType::AP_FEED))
{
return new kDropFolderFeedXmlFileHandler();
}
break;
case 'Form_DropFolderConfigureExtend_SubForm':
if ($enumValue == Kaltura_Client_DropFolder_Enum_DropFolderType::AP_FEED)
{
return new Form_ApFeedDropFolderConfigureExtend_SubForm();
}
break;
case 'Kaltura_Client_DropFolder_Type_DropFolder':
if ($enumValue == Kaltura_Client_DropFolder_Enum_DropFolderType::AP_FEED)
{
return new Kaltura_Client_ApFeedDropFolder_Type_ApFeedDropFolder();
}
break;
}
}

/**
* Retrieves a class name that is defined by the plugin and is known only to the plugin, and extends the baseClass.
*
* @param string $baseClass The base class of the searched class
* @param string $enumValue The enumeration value of the searched class
* @return string The name of the searched object's class
*/
public static function getObjectClass($baseClass, $enumValue)
{
switch ($baseClass) {
case 'DropFolderFile':
if ($enumValue == self::getDropFolderTypeCoreValue(ApFeedDropFolderType::AP_FEED))
return 'FeedDropFolderFile';
break;

case 'DropFolder':
if ($enumValue == self::getDropFolderTypeCoreValue(ApFeedDropFolderType::AP_FEED))
return 'ApFeedDropFolder';
break;

}
}

/**
* Returns a Kaltura dependency object that defines the relationship between two plugins.
*
* @return array<KalturaDependency> The Kaltura dependency object
*/
public static function dependsOn()
{
$dropFolderDependency = new KalturaDependency(self::DROP_FOLDER_PLUGIN_NAME);

return array($dropFolderDependency);
}

/**
* @return string the name of the plugin
*/
public static function getPluginName()
{
return self::PLUGIN_NAME;
}

/**
* @return string external API value of dynamic enum.
*/
public static function getApiValue($valueName)
{
return self::getPluginName() . IKalturaEnumerator::PLUGIN_VALUE_DELIMITER . $valueName;
}

public static function getDropFolderTypeCoreValue($valueName)
{
$value = self::getPluginName() . IKalturaEnumerator::PLUGIN_VALUE_DELIMITER . $valueName;
return kPluginableEnumsManager::apiToCore('DropFolderType', $value);
}
}
@@ -0,0 +1,23 @@
<?php
/**
* @package plugins.dropFolder
* @subpackage Admin
*/
class Form_ApFeedDropFolderConfigureExtend_SubForm extends Form_FeedDropFolderConfigureExtend_SubForm
{
public function getTitle()
{
return 'Feed settings';
}

public function init()
{
$this->addElement('text', 'apApiKey', array(
'label' => 'AP Feed API Key:',
'filters' => array('StringTrim'),
));

$this->addSubForm(new Form_FeedItemInfoConfigureExtend(), 'feedItemInfo');
}

}

0 comments on commit b01d21f

Please sign in to comment.