Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orion 15.2.0 psvamb 6815 #8852

Merged
merged 5 commits into from Nov 1, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -9,7 +9,7 @@ class KFeedDropFolderEngine extends KDropFolderEngine
/**
* @var array
*/
protected $feedNamespaces;
protected $feedNamespaces = array();

protected $handledUniqueIds = array();

@@ -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)
@@ -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
@@ -362,6 +369,7 @@ protected function fetchFeedContent ($url)
{
KalturaLog::info("For URL [$url], the curl result is: " . substr($res, 0, 1000));
}

return $res;
}

@@ -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');

This comment has been minimized.

Copy link
@MosheMaorKaltura

MosheMaorKaltura Nov 3, 2019

Contributor

Use const

}
if ($baseEnumName == 'DropFolderType')

This comment has been minimized.

Copy link
@MosheMaorKaltura

MosheMaorKaltura Nov 3, 2019

Contributor
  1. Use === for string match
  2. For 'DropFolderType' use KalturaDropFolderType::getEnumClass()

This comment has been minimized.

Copy link
@hilak

hilak Nov 4, 2019

Author Contributor

@MosheMaorKaltura the reason this is done this way (in all of our plugins - not just this one) is because the IKalturaEnumerator::getEnums method is called from several endpoints - admin console, batch and generator. Each context has a different classmap loaded and in some cases this method is called in order to build the class map. In order to reference this value as a class enum, the class defining the enum needs to be part of the classmap, leading to an exception being thrown.

{
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;

This comment has been minimized.

Copy link
@MosheMaorKaltura

MosheMaorKaltura Nov 3, 2019

Contributor

What should be the default behaviour of this switch case? should it print an message? throw exception do-nothing?
Please add default to the switch.

This comment has been minimized.

Copy link
@hilak

hilak Nov 4, 2019

Author Contributor

@MosheMaorKaltura there is no default on any of the plugin classes that implement the loadObject through a switch case. The reason is that this method is being called from the KalturaPluginManager, which iterates over all the plugins that implement the loadObject function. If all plugins had a default logging a message, you would see several KalturaLog messages all reading "Plugin xyz doesn't handle this class". If you threw an exception, you would prevent the PluginManager from processing the next plugin class which might be the correct one. Any logic added in a default case would be bad here so there is no default.

}
}

/**
* 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';

This comment has been minimized.

Copy link
@MosheMaorKaltura

MosheMaorKaltura Nov 3, 2019

Contributor

Use const values

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');
}

}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.