/**
  * Add new Syndication Feed
  * 
  * @action add
  * @param KalturaBaseSyndicationFeed $syndicationFeed
  * @return KalturaBaseSyndicationFeed 
  */
 public function addAction(KalturaBaseSyndicationFeed $syndicationFeed)
 {
     $syndicationFeed->validatePlaylistId();
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $syndicationFeed->validateXslt();
         $syndicationFeedDB = new genericSyndicationFeed();
         $syndicationFeedDB->setVersion(1);
     } else {
         $syndicationFeedDB = new syndicationFeed();
     }
     $syndicationFeed->partnerId = $this->getPartnerId();
     $syndicationFeed->status = KalturaSyndicationFeedStatus::ACTIVE;
     $syndicationFeed->toObject($syndicationFeedDB);
     $syndicationFeedDB->save();
     if ($syndicationFeed->addToDefaultConversionProfile) {
         $partner = PartnerPeer::retrieveByPK($this->getPartnerId());
         $c = new Criteria();
         $c->addAnd(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $partner->getDefaultConversionProfileId());
         $c->addAnd(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $syndicationFeed->flavorParamId);
         $is_exist = flavorParamsConversionProfilePeer::doCount($c);
         if (!$is_exist || $is_exist === 0) {
             $fpc = new flavorParamsConversionProfile();
             $fpc->setConversionProfileId($partner->getDefaultConversionProfileId());
             $fpc->setFlavorParamsId($syndicationFeed->flavorParamId);
             $fpc->save();
         }
     }
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $key = $syndicationFeedDB->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
         kFileSyncUtils::file_put_contents($key, $syndicationFeed->xslt);
     }
     $syndicationFeed->fromObject($syndicationFeedDB);
     return $syndicationFeed;
 }
 /**
  * Add new Syndication Feed
  * 
  * @action add
  * @param KalturaBaseSyndicationFeed $syndicationFeed
  * @return KalturaBaseSyndicationFeed 
  */
 public function addAction(KalturaBaseSyndicationFeed $syndicationFeed)
 {
     $syndicationFeed->validatePlaylistId();
     $syndicationFeed->validateStorageId($this->getPartnerId());
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $syndicationFeed->validatePropertyNotNull('xslt');
         $syndicationFeedDB = new genericSyndicationFeed();
         $syndicationFeedDB->incrementVersion();
     } else {
         $syndicationFeedDB = new syndicationFeed();
     }
     $syndicationFeed->toInsertableObject($syndicationFeedDB);
     $syndicationFeedDB->setPartnerId($this->getPartnerId());
     $syndicationFeedDB->setStatus(KalturaSyndicationFeedStatus::ACTIVE);
     $syndicationFeedDB->save();
     if ($syndicationFeed->addToDefaultConversionProfile) {
         $partner = PartnerPeer::retrieveByPK($this->getPartnerId());
         $c = new Criteria();
         $c->addAnd(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $partner->getDefaultConversionProfileId());
         $c->addAnd(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $syndicationFeed->flavorParamId);
         $is_exist = flavorParamsConversionProfilePeer::doCount($c);
         if (!$is_exist || $is_exist === 0) {
             $assetParams = assetParamsPeer::retrieveByPK($syndicationFeed->flavorParamId);
             $fpc = new flavorParamsConversionProfile();
             $fpc->setConversionProfileId($partner->getDefaultConversionProfileId());
             $fpc->setFlavorParamsId($syndicationFeed->flavorParamId);
             if ($assetParams) {
                 $fpc->setReadyBehavior($assetParams->getReadyBehavior());
                 $fpc->setSystemName($assetParams->getSystemName());
                 if ($assetParams->hasTag(assetParams::TAG_SOURCE) || $assetParams->hasTag(assetParams::TAG_INGEST)) {
                     $fpc->setOrigin(assetParamsOrigin::INGEST);
                 } else {
                     $fpc->setOrigin(assetParamsOrigin::CONVERT);
                 }
             }
             $fpc->save();
         }
     }
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $key = $syndicationFeedDB->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
         kFileSyncUtils::file_put_contents($key, $syndicationFeed->xslt);
     }
     $syndicationFeed->fromObject($syndicationFeedDB, $this->getResponseProfile());
     return $syndicationFeed;
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      flavorParamsConversionProfile $value A flavorParamsConversionProfile object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(flavorParamsConversionProfile $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
 /**
  * Adds the relation of flavorParams <> conversionProfile2
  * 
  * @param conversionProfile2 $conversionProfileDb
  * @param $flavorParamsIds
  */
 protected function addFlavorParamsRelation(conversionProfile2 $conversionProfileDb, $flavorParamsIds)
 {
     $existingIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfileDb->getId());
     $assetParamsObjects = assetParamsPeer::retrieveByPKs($flavorParamsIds);
     foreach ($assetParamsObjects as $assetParams) {
         /* @var $assetParams assetParams */
         if (in_array($assetParams->getId(), $existingIds)) {
             continue;
         }
         $fpc = new flavorParamsConversionProfile();
         $fpc->setConversionProfileId($conversionProfileDb->getId());
         $fpc->setFlavorParamsId($assetParams->getId());
         $fpc->setReadyBehavior($assetParams->getReadyBehavior());
         $fpc->setSystemName($assetParams->getSystemName());
         $fpc->setForceNoneComplied(false);
         if ($assetParams->hasTag(assetParams::TAG_SOURCE)) {
             $fpc->setOrigin(assetParamsOrigin::INGEST);
         } else {
             $fpc->setOrigin(assetParamsOrigin::CONVERT);
         }
         $fpc->save();
     }
 }
 /**
  * Adds the relation of flavorParams <> conversionProfile2
  * 
  * @param conversionProfile2 $conversionProfileDb
  * @param $flavorParamsIds
  * 
  * @throws KalturaErrors::ASSET_PARAMS_INVALID_TYPE
  */
 protected function addFlavorParamsRelation(conversionProfile2 $conversionProfileDb, $flavorParamsIds)
 {
     $existingIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfileDb->getId());
     $assetParamsObjects = assetParamsPeer::retrieveByPKs($flavorParamsIds);
     foreach ($assetParamsObjects as $assetParams) {
         /* @var $assetParams assetParams */
         if (in_array($assetParams->getId(), $existingIds)) {
             continue;
         }
         if ($conversionProfileDb->getType() == ConversionProfileType::LIVE_STREAM && $assetParams->getType() != assetType::LIVE) {
             throw new KalturaAPIException(KalturaErrors::ASSET_PARAMS_INVALID_TYPE, $assetParams->getId(), $assetParams->getType());
         }
         $fpc = new flavorParamsConversionProfile();
         $fpc->setConversionProfileId($conversionProfileDb->getId());
         $fpc->setFlavorParamsId($assetParams->getId());
         $fpc->setReadyBehavior($assetParams->getReadyBehavior());
         $fpc->setSystemName($assetParams->getSystemName());
         $fpc->setForceNoneComplied(false);
         if ($assetParams->hasTag(assetParams::TAG_SOURCE) || $assetParams->hasTag(assetParams::TAG_INGEST)) {
             $fpc->setOrigin(assetParamsOrigin::INGEST);
         } else {
             $fpc->setOrigin(assetParamsOrigin::CONVERT);
         }
         $fpc->save();
     }
 }
 /**
  * Adds the relation of flavorParams <> conversionProfile2
  * 
  * @param conversionProfile2 $conversionProfileDb
  * @param $flavorParamsIds
  */
 protected function addFlavorParamsRelation(conversionProfile2 $conversionProfileDb, $flavorParamsIds)
 {
     foreach ($flavorParamsIds as $flavorParamsId) {
         $fpc = new flavorParamsConversionProfile();
         $fpc->setConversionProfileId($conversionProfileDb->getId());
         $fpc->setFlavorParamsId($flavorParamsId);
         $fpc->save();
     }
 }
 /**
  * Will return for each OLD ConversionProfile a new one, IF NEEDED.
  * The old conversionProfile will hold a reference to the new one, so if already created a new one, it will be re-used.
  * All the necessary flavorParams will be added too to fit the old conversion params.
  *  
  * @param ConversionProfile $conversion_profile
  * @return conversionProfile2
  */
 public static function createConversionProfile2FromConversionProfile(ConversionProfile $old_conversion_profile)
 {
     if (!$old_conversion_profile) {
         throw new Exception("Cannot create new conversionProfile2 for null");
     }
     if ($old_conversion_profile->getConversionProfile2Id()) {
         $new_profile = conversionProfile2Peer::retrieveByPK($old_conversion_profile->getConversionProfile2Id());
         if ($new_profile) {
             // found a valid new profile - return it
             return $new_profile;
         }
     }
     // whether there was no id or no profile - create on now and set it to be the conversionProfile2Id
     $new_profile = new conversionProfile2();
     $new_profile->setPartnerId($old_conversion_profile->getPartnerId());
     $new_name = $old_conversion_profile->getName();
     $new_name = $new_name ? $new_name : "From [{$old_conversion_profile->getId()}]";
     $new_profile->setName($new_name . " " . $old_conversion_profile->getProfileType());
     if ($old_conversion_profile->getBypassFlv()) {
         $new_profile->setCreationMode(conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV);
         $map = flavorParams::TAG_WEB . "," . flavorParams::TAG_MBR;
     } else {
         $new_profile->setCreationMode(conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC);
         $map = flavorParams::TAG_WEB;
     }
     $new_profile->setInputTagsMap($map);
     // use the OLD code to simulate what was performed on the old_conversion_profile to retrieve the old_conversion_params list
     $conv_client = new kConversionClientBase("", "", "", "");
     $old_conversion_command = $conv_client->createConversionCommandFromConverionProfile("src", "target", $old_conversion_profile);
     $description = '';
     foreach ($old_conversion_command->conversion_params_list as $old_conversion_params) {
         // use the helper utility to fill the gaps
         $desc = '';
         self::fixDimensionsByAspectRatio($old_conversion_params, $desc);
         $description .= $desc;
     }
     $new_profile->setDescription($description);
     $new_profile->save();
     // at this point - the all $old_conversion_params are filled with the values used by the old conversion servers
     // transform from old to new ...
     // create the flavorParams and the flavorParamsConversionParams table
     foreach ($old_conversion_command->conversion_params_list as $old_conversion_params) {
         $new_flavor_params = new flavorParams();
         // set all the properties for the new flavor_params
         $new_flavor_params->setPartnerId($old_conversion_profile->getPartnerId());
         $new_flavor_params->setCreationMode(flavorParams::FLAVOR_PARAMS_CREATION_MODE_AUTOMATIC);
         $audio_bitrate = $old_conversion_params->audio_bitrate;
         if (!$audio_bitrate) {
             $audio_bitrate = 96;
         }
         // if empty - hard-code 96
         $new_flavor_params->setAudioBitrate($audio_bitrate);
         // default
         $new_flavor_params->setAudioChannels(0);
         // default
         $new_flavor_params->setAudioResolution(0);
         $new_flavor_params->setAudioSampleRate(0);
         if ($old_conversion_profile->getCommercialTranscoder()) {
             // first comes ON2...
             $new_flavor_params->setConversionEngines(conversionEngineType::ON2 . "," . conversionEngineType::ENCODING_COM . "," . conversionEngineType::FFMPEG . "," . conversionEngineType::FFMPEG_AUX . "," . conversionEngineType::MENCODER);
             //
             $new_flavor_params->setConversionEnginesExtraParams($old_conversion_params->flix_params . "|" . $old_conversion_params->flix_params . "|" . $old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->mencoder_params);
         } else {
             // first comes ffmpeg ...
             $new_flavor_params->setConversionEngines(conversionEngineType::FFMPEG . "," . conversionEngineType::FFMPEG_AUX . "," . conversionEngineType::MENCODER . "," . conversionEngineType::ON2 . "," . conversionEngineType::ENCODING_COM, ",");
             //
             $new_flavor_params->setConversionEnginesExtraParams($old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->mencoder_params . "|" . $old_conversion_params->flix_params . "|" . $old_conversion_params->flix_params);
         }
         $target_format = "flv";
         // this code will always be called for flv files
         // the format can be flv | mp4 | mov | avi | mp3
         // IMPORTANT:
         // except for the FLV videos, none of the formats should be assumed WEB - they are not supposed to be played using our player at first stage.
         switch ($target_format) {
             case "mp3":
                 $new_flavor_params->setFormat("flv");
                 $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_MP3);
                 // set default mp3
                 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_VP6);
                 /* $new_flavor_params->setTags ( flavorParams::TAG_WEB ); */
                 break;
             case "mp4":
                 $new_flavor_params->setFormat($target_format);
                 $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_AAC);
                 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_H264);
                 $new_flavor_params->setTags(',mp4_export');
                 break;
             case "mov":
                 $new_flavor_params->setFormat($target_format);
                 $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_AAC);
                 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_H264);
                 $new_flavor_params->setTags('mov_export');
                 break;
             case "avi":
                 $new_flavor_params->setFormat($target_format);
                 $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_MP3);
                 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_H264);
                 $new_flavor_params->setTags('avi_export');
                 break;
             case "flv":
                 $new_flavor_params->setFormat($target_format);
                 $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_MP3);
                 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_VP6);
                 $new_flavor_params->setTags(flavorParams::TAG_WEB . "," . flavorParams::TAG_MBR);
                 break;
         }
         $new_flavor_params->setName($new_name);
         $new_flavor_params->setFrameRate(0);
         // DONT set the framerate $old_conversion_params->framerate );
         if ($old_conversion_params->gop_size == 5) {
             $new_flavor_params->setGopSize(5);
             $new_flavor_params->removeTag(flavorParams::TAG_MBR);
             $new_flavor_params->addTag(flavorParams::TAG_EDIT);
         } else {
             $new_flavor_params->setGopSize(0);
             // 0 will automatically allow default gopsize
         }
         $new_flavor_params->setWidth($old_conversion_params->width);
         $new_flavor_params->setHeight($old_conversion_params->height);
         $new_flavor_params->setVersion(1);
         $new_flavor_params->setReadyBehavior(flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL);
         $new_flavor_params->setVideoBitrate($old_conversion_params->bitrate ? $old_conversion_params->bitrate : "");
         // TODO - fill the rest ...
         $new_flavor_params->save();
         // add to the 1-to-many table
         $flavor_params_conversion_profile = new flavorParamsConversionProfile();
         $flavor_params_conversion_profile->setConversionProfileId($new_profile->getId());
         $flavor_params_conversion_profile->setFlavorParamsId($new_flavor_params->getId());
         $flavor_params_conversion_profile->setReadyBehavior($new_flavor_params->getReadyBehavior());
         $flavor_params_conversion_profile->save();
     }
     // always add to the *source* flavotParams to the 1-to-many table
     $flavor_params_conversion_profile = new flavorParamsConversionProfile();
     $flavor_params_conversion_profile->setConversionProfileId($new_profile->getId());
     $flavor_params_conversion_profile->setFlavorParamsId(flavorParams::SOURCE_FLAVOR_ID);
     $flavor_params_conversion_profile->save();
     // point to the new profile and save the old one
     $old_conversion_profile->setConversionProfile2Id($new_profile->getId());
     $old_conversion_profile->save();
     return $new_profile;
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      flavorParamsConversionProfile $value A flavorParamsConversionProfile object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(flavorParamsConversionProfile $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) {
             self::$instances[$key] = $obj;
             kMemoryManager::registerPeer('flavorParamsConversionProfilePeer');
         }
     }
 }
$partners = PartnerPeer::doSelect($partnerCriteria);
foreach ($partners as $partner) {
    /* @var $partner Partner */
    $profileCriteria = new Criteria();
    $profileCriteria->add(conversionProfile2Peer::PARTNER_ID, $partner->getId());
    $profileCriteria->add(conversionProfile2Peer::TYPE, $conversionProfileType);
    $profileCriteria->add(conversionProfile2Peer::STATUS, ConversionProfileStatus::DELETED, Criteria::NOT_EQUAL);
    $profiles = conversionProfile2Peer::doSelect($profileCriteria);
    foreach ($profiles as $profile) {
        /* @var $profile conversionProfile2 */
        $flavorParamsConversionProfileIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($profile->getId());
        foreach ($additioalFlavorParamsObjects as $additioalFlavorParamsId => $additioalFlavorParamsObject) {
            if (in_array($additioalFlavorParamsId, $flavorParamsConversionProfileIds)) {
                continue;
            }
            $flavorParamsConversionProfile = new flavorParamsConversionProfile();
            $flavorParamsConversionProfile->setConversionProfileId($profile->getId());
            $flavorParamsConversionProfile->setFlavorParamsId($additioalFlavorParamsId);
            $flavorParamsConversionProfile->setReadyBehavior($additioalFlavorParamsObject->getReadyBehavior());
            $flavorParamsConversionProfile->setSystemName($additioalFlavorParamsObject->getSystemName());
            $flavorParamsConversionProfile->setForceNoneComplied(false);
            if ($additioalFlavorParamsObject->hasTag(assetParams::TAG_SOURCE) || $additioalFlavorParamsObject->hasTag(assetParams::TAG_INGEST)) {
                $flavorParamsConversionProfile->setOrigin(assetParamsOrigin::INGEST);
            } else {
                $flavorParamsConversionProfile->setOrigin(assetParamsOrigin::CONVERT);
            }
            $flavorParamsConversionProfile->save();
        }
    }
}
exit(0);