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

Pass type to duplicateTemplateEntry #8526

Merged
merged 4 commits into from Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion alpha/lib/model/entry.php
Expand Up @@ -3259,7 +3259,7 @@ public function copyTemplate($copyPartnerId = false, $template)
$this->setEntitledPusersEdit($template->getEntitledPusersEdit());
$this->setEntitledPusersPublish($template->getEntitledPusersPublish());

if ($this->getType() == $template->getType())
if ($this instanceof $template)
{
$this->copyTypedDependentFieldFromTemplate($template);
}
Expand Down
25 changes: 13 additions & 12 deletions api_v3/lib/KalturaEntryService.php
Expand Up @@ -123,13 +123,9 @@ protected function replaceResourceByEntry($dbEntry, $resource, $tempMediaEntry)
throw new KalturaAPIException(KalturaErrors::ENTRY_REPLACEMENT_ALREADY_EXISTS);

$resource->validateEntry($dbEntry);

// create the temp db entry first and mark it as isTemporary == true
$entryType = kPluginableEnumsManager::apiToCore('entryType', $tempMediaEntry->type);
$class = entryPeer::getEntryClassByType($entryType);

KalturaLog::debug("Creating new entry of API type [{$tempMediaEntry->type}] core type [$entryType] class [$class]");
$tempDbEntry = new $class();
$tempDbEntry = self::getCoreEntry($tempMediaEntry->type);
$tempDbEntry->setIsTemporary(true);
$tempDbEntry->setDisplayInSearch(mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM);
$tempDbEntry->setReplacedEntryId($dbEntry->getId());
Expand Down Expand Up @@ -977,11 +973,7 @@ protected function prepareEntryForInsert(KalturaBaseEntry $entry, entry $dbEntry
// first copy all the properties to the db entry, then we'll check for security stuff
if(!$dbEntry)
{
$entryType = kPluginableEnumsManager::apiToCore('entryType', $entry->type);
$class = entryPeer::getEntryClassByType($entryType);

KalturaLog::debug("Creating new entry of API type [$entry->type] core type [$entryType] class [$class]");
$dbEntry = new $class();
$dbEntry = self::getCoreEntry($entry->type);
}

$dbEntry = $entry->toInsertableObject($dbEntry);
Expand All @@ -997,6 +989,15 @@ protected function prepareEntryForInsert(KalturaBaseEntry $entry, entry $dbEntry

return $dbEntry;
}

protected static function getCoreEntry($entryApiType)
{
$entryCoreType = kPluginableEnumsManager::apiToCore('entryType', $entryApiType);
$class = entryPeer::getEntryClassByType($entryCoreType);

KalturaLog::debug("Creating new entry of API type [$entryApiType] core type [$entryCoreType] class [$class]");
return new $class();
}

/**
* Adds entry
Expand All @@ -1006,7 +1007,7 @@ protected function prepareEntryForInsert(KalturaBaseEntry $entry, entry $dbEntry
*/
protected function add(KalturaBaseEntry $entry, $conversionProfileId = null)
{
$dbEntry = $this->duplicateTemplateEntry($conversionProfileId, $entry->templateEntryId);
$dbEntry = $this->duplicateTemplateEntry($conversionProfileId, $entry->templateEntryId, self::getCoreEntry($entry->type));
if ($dbEntry)
{
$dbEntry->save();
Expand Down
2 changes: 1 addition & 1 deletion api_v3/services/BaseEntryService.php
Expand Up @@ -275,7 +275,7 @@ function addFromUploadedFileAction(KalturaBaseEntry $entry, $uploadTokenId, $typ
$entry->name = $this->getPartnerId().'_'.time();

// first copy all the properties to the db entry, then we'll check for security stuff
$dbEntry = $this->duplicateTemplateEntry($entry->conversionProfileId, $entry->templateEntryId);
$dbEntry = $this->duplicateTemplateEntry($entry->conversionProfileId, $entry->templateEntryId, self::getCoreEntry($entry->type));
$dbEntry = $entry->toInsertableObject($dbEntry);


Expand Down
2 changes: 1 addition & 1 deletion api_v3/services/MediaService.php
Expand Up @@ -1154,7 +1154,7 @@ protected function prepareEntryForInsert(KalturaBaseEntry $entry, entry $dbEntry
}

if ($dbEntry == null){
$dbEntry = $this->duplicateTemplateEntry($entry->conversionProfileId, $entry->templateEntryId);
$dbEntry = $this->duplicateTemplateEntry($entry->conversionProfileId, $entry->templateEntryId, self::getCoreEntry($entry->type));
}

$dbEntry = parent::prepareEntryForInsert($entry, $dbEntry);
Expand Down