diff --git a/alpha/lib/model/entry.php b/alpha/lib/model/entry.php index 0cd95626c45..8377573f70d 100644 --- a/alpha/lib/model/entry.php +++ b/alpha/lib/model/entry.php @@ -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); } diff --git a/api_v3/lib/KalturaEntryService.php b/api_v3/lib/KalturaEntryService.php index d891f865dee..f51aa40ea10 100644 --- a/api_v3/lib/KalturaEntryService.php +++ b/api_v3/lib/KalturaEntryService.php @@ -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()); @@ -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); @@ -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 @@ -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(); diff --git a/api_v3/services/BaseEntryService.php b/api_v3/services/BaseEntryService.php index b523f01bf30..ec4e30201ba 100644 --- a/api_v3/services/BaseEntryService.php +++ b/api_v3/services/BaseEntryService.php @@ -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); diff --git a/api_v3/services/MediaService.php b/api_v3/services/MediaService.php index ca8e16f0ec7..bbfdb3d0f38 100644 --- a/api_v3/services/MediaService.php +++ b/api_v3/services/MediaService.php @@ -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);