/**
  * Get Flavor Asset with the relevant Flavor Params (Flavor Params can exist without Flavor Asset & vice versa)
  * 
  * @action getFlavorAssetsWithParams
  * @param string $entryId
  * @return KalturaFlavorAssetWithParamsArray
  */
 public function getFlavorAssetsWithParamsAction($entryId)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     // get all the flavor params of partner 0 and the current partner (note that partner 0 is defined as partner group in service.ct)
     $flavorParamsDb = flavorParamsPeer::doSelect(new Criteria());
     // get the flavor assets for this entry
     $c = new Criteria();
     $c->add(flavorAssetPeer::ENTRY_ID, $entryId);
     $c->add(flavorAssetPeer::STATUS, array(flavorAsset::FLAVOR_ASSET_STATUS_DELETED, flavorAsset::FLAVOR_ASSET_STATUS_TEMP), Criteria::NOT_IN);
     $flavorAssetsDb = flavorAssetPeer::doSelect($c);
     // find what flavot params are required
     $requiredFlavorParams = array();
     foreach ($flavorAssetsDb as $item) {
         $requiredFlavorParams[$item->getFlavorParamsId()] = true;
     }
     // now merge the results, first organize the flavor params in an array with the id as the key
     $flavorParamsArray = array();
     foreach ($flavorParamsDb as $item) {
         $flavorParams = $item->getId();
         $flavorParamsArray[$flavorParams] = $item;
         if (isset($requiredFlavorParams[$flavorParams])) {
             unset($requiredFlavorParams[$flavorParams]);
         }
     }
     // adding missing required flavors params to the list
     if (count($requiredFlavorParams)) {
         $flavorParamsDb = flavorParamsPeer::retrieveByPKsNoFilter(array_keys($requiredFlavorParams));
         foreach ($flavorParamsDb as $item) {
             $flavorParamsArray[$item->getId()] = $item;
         }
     }
     $usedFlavorParams = array();
     // loop over the flavor assets and add them, if it has flavor params add them too
     $flavorAssetWithParamsArray = new KalturaFlavorAssetWithParamsArray();
     foreach ($flavorAssetsDb as $flavorAssetDb) {
         $flavorParamsId = $flavorAssetDb->getFlavorParamsId();
         $flavorAssetWithParams = new KalturaFlavorAssetWithParams();
         $flavorAssetWithParams->entryId = $entryId;
         $flavorAsset = new KalturaFlavorAsset();
         $flavorAsset->fromObject($flavorAssetDb);
         $flavorAssetWithParams->flavorAsset = $flavorAsset;
         if (isset($flavorParamsArray[$flavorParamsId])) {
             $flavorParamsDb = $flavorParamsArray[$flavorParamsId];
             $flavorParams = KalturaFlavorParamsFactory::getFlavorParamsInstance($flavorParamsDb->getType());
             $flavorParams->fromObject($flavorParamsDb);
             $flavorAssetWithParams->flavorParams = $flavorParams;
             // we want to log which flavor params are in use, there could be more
             // than one flavor asset using same params
             $usedFlavorParams[$flavorParamsId] = $flavorParamsId;
         }
         //			else if ($flavorAssetDb->getIsOriginal())
         //			{
         //				// create a dummy flavor params
         //				$flavorParams = new KalturaFlavorParams();
         //				$flavorParams->name = "Original source";
         //				$flavorAssetWithParams->flavorParams = $flavorParams;
         //			}
         $flavorAssetWithParamsArray[] = $flavorAssetWithParams;
     }
     // copy the remaining params
     foreach ($flavorParamsArray as $flavorParamsId => $flavorParamsDb) {
         if (isset($usedFlavorParams[$flavorParamsId])) {
             // flavor params already exists for a flavor asset, not need
             // to list it one more time
             continue;
         }
         $flavorParams = KalturaFlavorParamsFactory::getFlavorParamsInstance($flavorParamsDb->getType());
         $flavorParams->fromObject($flavorParamsDb);
         $flavorAssetWithParams = new KalturaFlavorAssetWithParams();
         $flavorAssetWithParams->entryId = $entryId;
         $flavorAssetWithParams->flavorParams = $flavorParams;
         $flavorAssetWithParamsArray[] = $flavorAssetWithParams;
     }
     return $flavorAssetWithParamsArray;
 }
DbManager::setConfig($dbConf);
DbManager::initialize();
if (count($argv) !== 2) {
    die('pleas provide partner id as input' . PHP_EOL . 'to run script: ' . basename(__FILE__) . ' X' . PHP_EOL . 'whereas X is partner id' . PHP_EOL);
}
$partner_id = @$argv[1];
$partner = PartnerPeer::retrieveByPK($partner_id);
if (!$partner) {
    die('no such partner.' . PHP_EOL);
}
$c = new Criteria();
$c->add(flavorAssetPeer::PARTNER_ID, $partner_id);
$c->add(flavorAssetPeer::IS_ORIGINAL, true);
$c->add(flavorAssetPeer::STATUS, flavorAsset::FLAVOR_ASSET_STATUS_READY);
$con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2);
$flavorAssets = flavorAssetPeer::doSelect($c, $con);
$changedEntriesCounter = 0;
foreach ($flavorAssets as $flavorAsset) {
    $flavorSyncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
    try {
        if (!kFileSyncUtils::file_exists($flavorSyncKey, true)) {
            echo 'changed source flavor asset to status deleted for entry: ' . $flavorAsset->getEntryId() . ' and for flavor id ' . $flavorAsset->getId() . PHP_EOL;
            // set the status of the flavor asset to deleted and set deleted time (taken from flavorAssetService)
            $entry = $flavorAsset->getEntry();
            if ($entry) {
                $entry->removeFlavorParamsId($flavorAsset->getFlavorParamsId());
                $entry->save();
            }
            $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
            $flavorAsset->setDeletedAt(time());
            $flavorAsset->save();