/**
  * @param Partner $fromPartner
  * @param Partner $toPartner
  */
 protected function copyEventNotificationTemplates(Partner $fromPartner, Partner $toPartner, $permissionRequiredOnly = false)
 {
     $fromPartnerId = $fromPartner->getId();
     $toPartnerId = $toPartner->getId();
     KalturaLog::debug("Copy event-notification templates from [{$fromPartnerId}] to [{$toPartnerId}]");
     $c = new Criteria();
     $c->add(EventNotificationTemplatePeer::PARTNER_ID, $fromPartnerId);
     $systemNameCriteria = new Criteria();
     $systemNameCriteria->add(EventNotificationTemplatePeer::PARTNER_ID, $toPartnerId);
     $systemNameCriteria->add(EventNotificationTemplatePeer::STATUS, EventNotificationTemplateStatus::ACTIVE);
     $eventNotificationTemplates = EventNotificationTemplatePeer::doSelect($c);
     foreach ($eventNotificationTemplates as $eventNotificationTemplate) {
         /* @var $eventNotificationTemplate EventNotificationTemplate */
         if ($permissionRequiredOnly && !count($eventNotificationTemplate->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if (!myPartnerUtils::isPartnerPermittedForCopy($toPartner, $eventNotificationTemplate->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if ($eventNotificationTemplate->getSystemName()) {
             $c = clone $systemNameCriteria;
             $c->add(EventNotificationTemplatePeer::SYSTEM_NAME, $eventNotificationTemplate->getSystemName());
             if (EventNotificationTemplatePeer::doCount($c)) {
                 continue;
             }
         }
         $newEventNotificationTemplate = $eventNotificationTemplate->copy();
         $newEventNotificationTemplate->setPartnerId($toPartnerId);
         $newEventNotificationTemplate->save();
     }
 }
 /**
  * @param Partner $fromPartner
  * @param Partner $toPartner
  */
 protected function copyMetadataProfiles(Partner $fromPartner, Partner $toPartner, $permissionRequiredOnly = false)
 {
     $fromPartnerId = $fromPartner->getId();
     $toPartnerId = $toPartner->getId();
     KalturaLog::debug("Copy metadata profiles from [{$fromPartnerId}] to [{$toPartnerId}]");
     $c = new Criteria();
     $c->add(MetadataProfilePeer::PARTNER_ID, $fromPartnerId);
     $systemNameCriteria = new Criteria();
     $systemNameCriteria->add(MetadataProfilePeer::PARTNER_ID, $toPartnerId);
     $systemNameCriteria->add(MetadataProfilePeer::STATUS, MetadataProfile::STATUS_ACTIVE);
     $metadataProfiles = MetadataProfilePeer::doSelect($c);
     foreach ($metadataProfiles as $metadataProfile) {
         /* @var $metadataProfile MetadataProfile */
         if ($permissionRequiredOnly && !count($metadataProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if (!myPartnerUtils::isPartnerPermittedForCopy($toPartner, $metadataProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if ($metadataProfile->getSystemName()) {
             $c = clone $systemNameCriteria;
             $c->add(MetadataProfilePeer::SYSTEM_NAME, $metadataProfile->getSystemName());
             if (MetadataProfilePeer::doCount($c)) {
                 continue;
             }
         }
         $newMetadataProfile = $metadataProfile->copy();
         $newMetadataProfile->setPartnerId($toPartnerId);
         $newMetadataProfile->save();
         kFileSyncUtils::createSyncFileLinkForKey($newMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION), $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION));
         kFileSyncUtils::createSyncFileLinkForKey($newMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS), $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS));
         kFileSyncUtils::createSyncFileLinkForKey($newMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_XSLT), $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_XSLT));
         $metadataProfileFields = MetadataProfileFieldPeer::retrieveByMetadataProfileId($metadataProfile->getId());
         foreach ($metadataProfileFields as $metadataProfileField) {
             $newMetadataProfileField = $metadataProfileField->copy();
             $newMetadataProfileField->setMetadataProfileId($newMetadataProfile->getId());
             $newMetadataProfileField->setPartnerId($toPartnerId);
             $newMetadataProfileField->save();
         }
     }
 }