Пример #1
0
 /**
  * Adds the supplied XML object to the instance pool.
  *
  * @param string $entryId
  * @param SimpleXMLElement $xml
  */
 protected static function addInstanceToPool($entryId, SimpleXMLElement $xml)
 {
     if (self::isInstancePoolingEnabled()) {
         self::$instancesPool[$entryId] = $xml;
         kMemoryManager::registerPeer('kMrssManager');
     }
 }
 /**
  * @action getFeed
  * @disableTags TAG_WIDGET_SESSION,TAG_ENTITLEMENT_ENTRY,TAG_ENTITLEMENT_CATEGORY
  * @param int $distributionProfileId
  * @param string $hash
  * @return file
  */
 public function getFeedAction($distributionProfileId, $hash)
 {
     if (!$this->getPartnerId() || !$this->getPartner()) {
         throw new KalturaAPIException(KalturaErrors::INVALID_PARTNER_ID, $this->getPartnerId());
     }
     $profile = DistributionProfilePeer::retrieveByPK($distributionProfileId);
     if (!$profile || !$profile instanceof SynacorHboDistributionProfile) {
         throw new KalturaAPIException(ContentDistributionErrors::DISTRIBUTION_PROFILE_NOT_FOUND, $distributionProfileId);
     }
     if ($profile->getStatus() != KalturaDistributionProfileStatus::ENABLED) {
         throw new KalturaAPIException(ContentDistributionErrors::DISTRIBUTION_PROFILE_DISABLED, $distributionProfileId);
     }
     if ($profile->getUniqueHashForFeedUrl() != $hash) {
         throw new KalturaAPIException(SynacorHboDistributionErrors::INVALID_FEED_URL);
     }
     // "Creates advanced filter on distribution profile
     $distributionAdvancedSearch = new ContentDistributionSearchFilter();
     $distributionAdvancedSearch->setDistributionProfileId($profile->getId());
     $distributionAdvancedSearch->setDistributionSunStatus(EntryDistributionSunStatus::AFTER_SUNRISE);
     $distributionAdvancedSearch->setEntryDistributionStatus(EntryDistributionStatus::READY);
     $distributionAdvancedSearch->setEntryDistributionFlag(EntryDistributionDirtyStatus::NONE);
     $distributionAdvancedSearch->setHasEntryDistributionValidationErrors(false);
     //Creates entry filter with advanced filter
     $entryFilter = new entryFilter();
     $entryFilter->setStatusEquel(entryStatus::READY);
     $entryFilter->setModerationStatusNot(entry::ENTRY_MODERATION_STATUS_REJECTED);
     $entryFilter->setPartnerSearchScope($this->getPartnerId());
     $entryFilter->setAdvancedSearch($distributionAdvancedSearch);
     $baseCriteria = KalturaCriteria::create(entryPeer::OM_CLASS);
     $baseCriteria->add(entryPeer::DISPLAY_IN_SEARCH, mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM, Criteria::NOT_EQUAL);
     $entryFilter->attachToCriteria($baseCriteria);
     $entries = entryPeer::doSelect($baseCriteria);
     $feed = new SynacorHboFeed('synacor_hbo_feed_template.xml');
     $feed->setDistributionProfile($profile);
     $counter = 0;
     foreach ($entries as $entry) {
         /* @var $entry entry */
         $entryDistribution = EntryDistributionPeer::retrieveByEntryAndProfileId($entry->getId(), $profile->getId());
         if (!$entryDistribution) {
             KalturaLog::err('Entry distribution was not found for entry [' . $entry->getId() . '] and profile [' . $profile->getId() . ']');
             continue;
         }
         $fields = $profile->getAllFieldValues($entryDistribution);
         $flavorAssets = assetPeer::retrieveByIds(explode(',', $entryDistribution->getFlavorAssetIds()));
         $thumbAssets = assetPeer::retrieveByIds(explode(',', $entryDistribution->getThumbAssetIds()));
         $additionalAssets = assetPeer::retrieveByIds(explode(',', $entryDistribution->getAssetIds()));
         $feed->addItem($fields, $entry, $flavorAssets, $thumbAssets, $additionalAssets);
         $counter++;
         //to avoid the cache exceeding the memory size
         if ($counter >= 100) {
             kMemoryManager::clearMemory();
             $counter = 0;
         }
     }
     header('Content-Type: text/xml');
     echo $feed->getXml();
     die;
 }
Пример #3
0
 public static function clearMemory()
 {
     foreach (self::$peerNames as $peerName => $dontCare) {
         call_user_func(array($peerName, 'clearInstancePool'));
     }
     self::$peerNames = array();
     $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaMemoryCleaner');
     foreach ($pluginInstances as $pluginInstance) {
         $pluginInstance->cleanMemory();
     }
     if (function_exists('gc_collect_cycles')) {
         // php 5.3 and above
         gc_collect_cycles();
     }
 }
 /**
  * updates entry distribution sun status in the search engine
  *
  * @action updateSunStatus
  */
 function updateSunStatusAction()
 {
     $updatedEntries = array();
     // serach all records that their sun status changed to after sunset
     $criteria = KalturaCriteria::create(EntryDistributionPeer::OM_CLASS);
     $criteria->add(EntryDistributionPeer::STATUS, EntryDistributionStatus::READY);
     $criteria->add(EntryDistributionPeer::SUN_STATUS, EntryDistributionSunStatus::AFTER_SUNSET, Criteria::NOT_EQUAL);
     $crit1 = $criteria->getNewCriterion(EntryDistributionPeer::SUNSET, time(), Criteria::LESS_THAN);
     $criteria->add($crit1);
     $entryDistributions = EntryDistributionPeer::doSelect($criteria);
     foreach ($entryDistributions as $entryDistribution) {
         /* @var $entryDistribution EntryDistribution */
         $entryId = $entryDistribution->getEntryId();
         if (isset($updatedEntries[$entryId])) {
             continue;
         }
         $updatedEntries[$entryId] = true;
         kEventsManager::raiseEvent(new kObjectUpdatedEvent($entryDistribution));
         // raise the updated events to trigger index in search engine (sphinx)
         kEventsManager::flushEvents();
         // save entry changes to sphinx
         kMemoryManager::clearMemory();
     }
     $updatedEntries = array();
     // serach all records that their sun status changed to after sunrise
     $criteria = KalturaCriteria::create(EntryDistributionPeer::OM_CLASS);
     $criteria->add(EntryDistributionPeer::STATUS, EntryDistributionStatus::QUEUED);
     $criteria->add(EntryDistributionPeer::SUN_STATUS, EntryDistributionSunStatus::BEFORE_SUNRISE);
     $criteria->add(EntryDistributionPeer::SUNRISE, time(), Criteria::LESS_THAN);
     $entryDistributions = EntryDistributionPeer::doSelect($criteria);
     foreach ($entryDistributions as $entryDistribution) {
         /* @var $entryDistribution EntryDistribution */
         $entryId = $entryDistribution->getEntryId();
         if (isset($updatedEntries[$entryId])) {
             continue;
         }
         $updatedEntries[$entryId] = true;
         kEventsManager::raiseEvent(new kObjectUpdatedEvent($entryDistribution));
         // raise the updated events to trigger index in search engine (sphinx)
         kEventsManager::flushEvents();
         // save entry changes to sphinx
         kMemoryManager::clearMemory();
     }
 }
 /**
  * @action getFeed
  * @disableTags TAG_WIDGET_SESSION,TAG_ENTITLEMENT_ENTRY,TAG_ENTITLEMENT_CATEGORY
  * @param int $distributionProfileId
  * @param string $hash
  * @return file
  */
 public function getFeedAction($distributionProfileId, $hash)
 {
     if (!$this->getPartnerId() || !$this->getPartner()) {
         throw new KalturaAPIException(KalturaErrors::INVALID_PARTNER_ID, $this->getPartnerId());
     }
     $profile = DistributionProfilePeer::retrieveByPK($distributionProfileId);
     if (!$profile || !$profile instanceof AttUverseDistributionProfile) {
         throw new KalturaAPIException(ContentDistributionErrors::DISTRIBUTION_PROFILE_NOT_FOUND, $distributionProfileId);
     }
     if ($profile->getStatus() != KalturaDistributionProfileStatus::ENABLED) {
         throw new KalturaAPIException(ContentDistributionErrors::DISTRIBUTION_PROFILE_DISABLED, $distributionProfileId);
     }
     if ($profile->getUniqueHashForFeedUrl() != $hash) {
         throw new KalturaAPIException(AttUverseDistributionErrors::INVALID_FEED_URL);
     }
     // "Creates advanced filter on distribution profile
     $distributionAdvancedSearch = new ContentDistributionSearchFilter();
     $distributionAdvancedSearch->setDistributionProfileId($profile->getId());
     $distributionAdvancedSearch->setDistributionSunStatus(EntryDistributionSunStatus::AFTER_SUNRISE);
     $distributionAdvancedSearch->setEntryDistributionStatus(EntryDistributionStatus::READY);
     $distributionAdvancedSearch->setEntryDistributionFlag(EntryDistributionDirtyStatus::NONE);
     $distributionAdvancedSearch->setHasEntryDistributionValidationErrors(false);
     //Creates entry filter with advanced filter
     $entryFilter = new entryFilter();
     $entryFilter->setStatusEquel(entryStatus::READY);
     $entryFilter->setModerationStatusNot(entry::ENTRY_MODERATION_STATUS_REJECTED);
     $entryFilter->setPartnerSearchScope($this->getPartnerId());
     $entryFilter->setAdvancedSearch($distributionAdvancedSearch);
     $baseCriteria = KalturaCriteria::create(entryPeer::OM_CLASS);
     $baseCriteria->add(entryPeer::DISPLAY_IN_SEARCH, mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM, Criteria::NOT_EQUAL);
     $entryFilter->attachToCriteria($baseCriteria);
     $entries = entryPeer::doSelect($baseCriteria);
     $feed = new AttUverseDistributionFeedHelper('feed_template.xml', $profile);
     $channelTitle = $profile->getChannelTitle();
     $counter = 0;
     foreach ($entries as $entry) {
         /* @var $entry entry */
         /* @var $entryDistribution Entrydistribution */
         $entryDistribution = EntryDistributionPeer::retrieveByEntryAndProfileId($entry->getId(), $profile->getId());
         if (!$entryDistribution) {
             KalturaLog::err('Entry distribution was not found for entry [' . $entry->getId() . '] and profile [' . $profile->getId() . ']');
             continue;
         }
         $fields = $profile->getAllFieldValues($entryDistribution);
         //flavors assets and remote flavor asset file urls
         $flavorAssets = assetPeer::retrieveByIds(explode(',', $entryDistribution->getFromCustomData(AttUverseEntryDistributionCustomDataField::DISTRIBUTED_FLAVOR_IDS)));
         $remoteAssetFileUrls = unserialize($entryDistribution->getFromCustomData(AttUverseEntryDistributionCustomDataField::REMOTE_ASSET_FILE_URLS));
         //thumb assets and remote thumb asset file urls
         $thumbAssets = assetPeer::retrieveByIds(explode(',', $entryDistribution->getFromCustomData(AttUverseEntryDistributionCustomDataField::DISTRIBUTED_THUMBNAIL_IDS)));
         $remoteThumbailFileUrls = unserialize($entryDistribution->getFromCustomData(AttUverseEntryDistributionCustomDataField::REMOTE_THUMBNAIL_FILE_URLS));
         //thumb assets and remote thumb asset file urls
         $captionAssets = assetPeer::retrieveByIds(explode(',', $entryDistribution->getFromCustomData(AttUverseEntryDistributionCustomDataField::DISTRIBUTED_CAPTION_IDS)));
         $feed->addItem($fields, $flavorAssets, $remoteAssetFileUrls, $thumbAssets, $remoteThumbailFileUrls, $captionAssets);
         $counter++;
         //to avoid the cache exceeding the memory size
         if ($counter >= 100) {
             kMemoryManager::clearMemory();
             $counter = 0;
         }
     }
     //set channel title
     if (isset($fields)) {
         $channelTitle = $fields[AttUverseDistributionField::CHANNEL_TITLE];
     }
     $feed->setChannelTitle($channelTitle);
     header('Content-Type: text/xml');
     echo str_replace('&', '&', html_entity_decode($feed->getXml(), ENT_QUOTES, 'UTF-8'));
     die;
 }
 /**
  * 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      LiveChannelSegment $value A LiveChannelSegment object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(LiveChannelSegment $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
         kMemoryManager::registerPeer('LiveChannelSegmentPeer');
     }
 }
Пример #7
0
 /**
  * Returns the log file for bulk upload job
  * @param BatchJob $batchJob bulk upload batchjob
  */
 public static function writeBulkUploadLogFile($batchJob)
 {
     if ($batchJob->getJobSubType() && $batchJob->getJobSubType() != self::getBulkUploadTypeCoreValue(BulkUploadCsvType::CSV)) {
         return;
     }
     header("Content-Type: text/plain; charset=UTF-8");
     $criteria = new Criteria();
     $criteria->add(BulkUploadResultPeer::BULK_UPLOAD_JOB_ID, $batchJob->getId());
     $criteria->addAscendingOrderByColumn(BulkUploadResultPeer::LINE_INDEX);
     $criteria->setLimit(100);
     $bulkUploadResults = BulkUploadResultPeer::doSelect($criteria);
     if (!count($bulkUploadResults)) {
         die("Log file is not ready");
     }
     $STDOUT = fopen('php://output', 'w');
     $data = $batchJob->getData();
     /* @var $data kBulkUploadJobData */
     //Add header row to the output CSV only if partner level permission for it exists
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     if (PermissionPeer::isValidForPartner(self::FEATURE_CSV_HEADER_ROW, $partnerId)) {
         $headerRow = $data->getColumns();
         $headerRow[] = "resultStatus";
         $headerRow[] = "objectId";
         $headerRow[] = "objectStatus";
         $headerRow[] = "errorDescription";
         fputcsv($STDOUT, $headerRow);
     }
     $handledResults = 0;
     while (count($bulkUploadResults)) {
         $handledResults += count($bulkUploadResults);
         foreach ($bulkUploadResults as $bulkUploadResult) {
             /* @var $bulkUploadResult BulkUploadResult */
             $values = str_getcsv($bulkUploadResult->getRowData());
             //		    switch ($bulkUploadResult->getObjectType())
             //		    {
             //		        case BulkUploadObjectType::ENTRY:
             //		            $values = self::writeEntryBulkUploadResults($bulkUploadResult, $data);
             //		            break;
             //		        case BulkUploadObjectType::CATEGORY:
             //		            $values = self::writeCategoryBulkUploadResults($bulkUploadResult, $data);
             //		            break;
             //		        case BulkUploadObjectType::CATEGORY_USER:
             //		            $values = self::writeCategoryUserBulkUploadResults($bulkUploadResult, $data);
             //		            break;
             //		        case BulkUploadObjectType::USER:
             //		            $values = self::writeUserBulkUploadResults($bulkUploadResult, $data);
             //		            break;
             //		        default:
             //
             //		            break;
             //		    }
             $values[] = $bulkUploadResult->getStatus();
             $values[] = $bulkUploadResult->getObjectId();
             $values[] = $bulkUploadResult->getObjectStatus();
             $values[] = preg_replace('/[\\n\\r\\t]/', ' ', $bulkUploadResult->getErrorDescription());
             fputcsv($STDOUT, $values);
         }
         if (count($bulkUploadResults) < $criteria->getLimit()) {
             break;
         }
         kMemoryManager::clearMemory();
         $criteria->setOffset($handledResults);
         $bulkUploadResults = BulkUploadResultPeer::doSelect($criteria);
     }
     fclose($STDOUT);
     kFile::closeDbConnections();
     exit;
 }
Пример #8
0
 public function handleMultiRequest()
 {
     // arrange the parameters by request index
     $commonParams = array();
     $listOfRequests = array();
     $dependencies = array();
     $allDependencies = array();
     $pastResults = array();
     foreach ($this->params as $paramName => $paramValue) {
         $explodedName = explode(':', $paramName, 2);
         if (count($explodedName) <= 1 || !is_numeric($explodedName[0])) {
             $commonParams[$paramName] = $paramValue;
             continue;
         }
         $requestIndex = (int) $explodedName[0];
         $paramName = $explodedName[1];
         if (!array_key_exists($requestIndex, $listOfRequests)) {
             $listOfRequests[$requestIndex] = array();
         }
         $listOfRequests[$requestIndex][$paramName] = $paramValue;
         $matches = array();
         if (preg_match('/\\{([0-9]*)\\:result\\:?(.*)?\\}/', $paramValue, $matches)) {
             $pastResultsIndex = $matches[0];
             $resultIndex = $matches[1];
             $resultKey = $matches[2];
             if (!isset($dependencies[$requestIndex][$pastResultsIndex])) {
                 $dependencies[$resultIndex][$pastResultsIndex] = $resultKey;
             }
             $allDependencies[$pastResultsIndex] = true;
         }
     }
     // process the requests
     $results = array();
     for ($i = 1; isset($listOfRequests[$i]); $i++) {
         $currentParams = $listOfRequests[$i];
         if (!isset($currentParams["service"]) || !isset($currentParams["action"])) {
             break;
         }
         kCurrentContext::$multiRequest_index = $i;
         $currentService = $currentParams["service"];
         $currentAction = $currentParams["action"];
         // copy derived common params to current params
         if (isset($commonParams['clientTag']) && !isset($currentParams['clientTag'])) {
             $currentParams['clientTag'] = $commonParams['clientTag'];
         }
         if (isset($commonParams['ks']) && !isset($currentParams['ks'])) {
             $currentParams['ks'] = $commonParams['ks'];
         }
         if (isset($commonParams['partnerId']) && !isset($currentParams['partnerId'])) {
             $currentParams['partnerId'] = $commonParams['partnerId'];
         }
         // check if we need to replace params with prev results
         foreach ($currentParams as $key => &$val) {
             if (isset($pastResults[$val])) {
                 $val = $pastResults[$val];
             } else {
                 if (isset($allDependencies[$val])) {
                     $val = null;
                 }
             }
         }
         // cached parameters should be different when the request is part of a multirequest
         // as part of multirequest - the cached data is a serialized php object
         // when not part of multirequest - the cached data is the actual response
         $currentParams['multirequest'] = true;
         unset($currentParams['format']);
         $cache = new KalturaResponseCacher($currentParams);
         $success = true;
         $errorCode = null;
         $this->onRequestStart($currentService, $currentAction, $currentParams, $i, true);
         $cachedResult = $cache->checkCache('X-Kaltura-Part-Of-MultiRequest');
         if ($cachedResult) {
             $currentResult = unserialize($cachedResult);
         } else {
             if ($i != 1) {
                 kMemoryManager::clearMemory();
                 KalturaCriterion::clearTags();
             }
             try {
                 $currentResult = $this->dispatcher->dispatch($currentService, $currentAction, $currentParams);
             } catch (Exception $ex) {
                 $success = false;
                 $errorCode = $ex->getCode();
                 $currentResult = $this->getExceptionObject($ex, $currentService, $currentAction);
             }
             $cache->storeCache($currentResult, "", true);
         }
         $this->onRequestEnd($success, $errorCode, $i);
         if (isset($dependencies[$i])) {
             foreach ($dependencies[$i] as $currentDependency => $dependencyName) {
                 if (strlen(trim($dependencyName)) > 0) {
                     $resultPathArray = explode(":", $dependencyName);
                 } else {
                     $resultPathArray = array();
                 }
                 $currValue = $this->getValueFromObject($currentResult, $resultPathArray);
                 $pastResults[$currentDependency] = $currValue;
             }
         }
         $results[$i] = $this->serializer->serialize($currentResult);
         // in case a serve action is included in a multirequest, return only the result of the serve action
         // in order to avoid serializing the kRendererBase object and returning the internal server paths to the client
         if ($currentResult instanceof kRendererBase) {
             return $currentResult;
         }
     }
     return $results;
 }
 public function execute()
 {
     $jobId = $this->getRequestParameter("id");
     $partnerId = $this->getRequestParameter("pid");
     $type = $this->getRequestParameter("type");
     $c = new Criteria();
     $c->addAnd(BatchJobPeer::ID, $jobId);
     $c->addAnd(BatchJobPeer::PARTNER_ID, $partnerId);
     $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD);
     $batchJob = BatchJobPeer::doSelectOne($c);
     if (!$batchJob) {
         die("File not found");
     }
     header("Content-Type: text/plain; charset=UTF-8");
     if ($type == "log") {
         $criteria = new Criteria();
         $criteria->add(BulkUploadResultPeer::BULK_UPLOAD_JOB_ID, $jobId);
         $criteria->addAscendingOrderByColumn(BulkUploadResultPeer::LINE_INDEX);
         $criteria->setLimit(100);
         $bulkUploadResults = BulkUploadResultPeer::doSelect($criteria);
         if (!count($bulkUploadResults)) {
             die("Log file is not ready");
         }
         $STDOUT = fopen('php://output', 'w');
         $data = $batchJob->getData();
         $handledResults = 0;
         while (count($bulkUploadResults)) {
             $handledResults += count($bulkUploadResults);
             foreach ($bulkUploadResults as $bulkUploadResult) {
                 $values = array($bulkUploadResult->getTitle(), $bulkUploadResult->getDescription(), $bulkUploadResult->getTags(), $bulkUploadResult->getUrl(), $bulkUploadResult->getContentType());
                 if ($data instanceof kBulkUploadCsvJobData && $data->getCsvVersion() > 1) {
                     $values[] = $bulkUploadResult->getConversionProfileId();
                     $values[] = $bulkUploadResult->getAccessControlProfileId();
                     $values[] = $bulkUploadResult->getCategory();
                     $values[] = $bulkUploadResult->getScheduleStartDate('Y-m-d\\TH:i:s');
                     $values[] = $bulkUploadResult->getScheduleEndDate('Y-m-d\\TH:i:s');
                     $values[] = $bulkUploadResult->getThumbnailUrl();
                     $values[] = $bulkUploadResult->getPartnerData();
                 }
                 $values[] = $bulkUploadResult->getEntryId();
                 $values[] = $bulkUploadResult->getEntryStatus();
                 $values[] = $bulkUploadResult->getErrorDescription();
                 fputcsv($STDOUT, $values);
             }
             if (count($bulkUploadResults) < $criteria->getLimit()) {
                 break;
             }
             kMemoryManager::clearMemory();
             $criteria->setOffset($handledResults);
             $bulkUploadResults = BulkUploadResultPeer::doSelect($criteria);
         }
         fclose($STDOUT);
     } else {
         $syncKey = $batchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD);
         if (kFileSyncUtils::file_exists($syncKey, true)) {
             $content = kFileSyncUtils::file_get_contents($syncKey, true);
             echo $content;
             die;
         } else {
             die("File not found");
         }
     }
     die;
     //  no template needed
 }
Пример #10
0
 protected static function deleteOldVersionedFileSyncs($objectType, $objectSubType)
 {
     if (!isset(self::$oldVersionsStartUpdatedAt[$objectType])) {
         self::$oldVersionsStartUpdatedAt[$objectType] = 0;
     }
     if (!isset(self::$oldVersionsEndUpdatedAt[$objectType])) {
         self::$oldVersionsEndUpdatedAt[$objectType] = 0;
     }
     $criteria = new Criteria();
     switch ($objectType) {
         case FileSyncObjectType::ASSET:
             if ($objectSubType != asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET) {
                 return array();
             }
             $join = new Join();
             $join->addCondition(FileSyncPeer::OBJECT_ID, assetPeer::ID);
             $join->addCondition(FileSyncPeer::VERSION, assetPeer::VERSION, Criteria::NOT_EQUAL);
             $join->setJoinType(Criteria::LEFT_JOIN);
             $criteria->addJoinObject($join);
             $criteria->add(assetPeer::VERSION, null, Criteria::ISNOTNULL);
             break;
         case FileSyncObjectType::UICONF:
             $join = new Join();
             $join->addCondition(FileSyncPeer::OBJECT_ID, uiConfPeer::ID);
             $join->addCondition(FileSyncPeer::VERSION, uiConfPeer::VERSION, Criteria::NOT_EQUAL);
             $join->setJoinType(Criteria::LEFT_JOIN);
             $criteria->addJoinObject($join);
             $criteria->add(uiConfPeer::VERSION, null, Criteria::ISNOTNULL);
             break;
         case FileSyncObjectType::ENTRY:
             $join = new Join();
             $join->addCondition(FileSyncPeer::OBJECT_ID, entryPeer::ID);
             switch ($objectSubType) {
                 case entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB:
                     $join->addCondition(FileSyncPeer::VERSION, entryPeer::THUMBNAIL, Criteria::NOT_EQUAL);
                     $criteria->add(entryPeer::THUMBNAIL, null, Criteria::ISNOTNULL);
                     break;
                 case entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA:
                 case entry::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD:
                     $join->addCondition(FileSyncPeer::VERSION, entryPeer::DATA, Criteria::NOT_EQUAL);
                     $criteria->add(entryPeer::DATA, null, Criteria::ISNOTNULL);
                     break;
                 default:
                     return array();
             }
             $join->setJoinType(Criteria::LEFT_JOIN);
             $criteria->addJoinObject($join);
             break;
         case FileSyncObjectType::METADATA:
             $join = new Join();
             $join->addCondition(FileSyncPeer::OBJECT_ID, MetadataPeer::ID);
             $join->addCondition(FileSyncPeer::VERSION, MetadataPeer::VERSION, Criteria::NOT_EQUAL);
             $join->setJoinType(Criteria::LEFT_JOIN);
             $criteria->addJoinObject($join);
             $criteria->add(MetadataPeer::VERSION, null, Criteria::ISNOTNULL);
             break;
         case FileSyncObjectType::METADATA_PROFILE:
             $join = new Join();
             $join->addCondition(FileSyncPeer::OBJECT_ID, MetadataProfilePeer::ID);
             switch ($objectSubType) {
                 case MetadataProfile::FILE_SYNC_METADATA_DEFINITION:
                     $join->addCondition(FileSyncPeer::VERSION, MetadataProfilePeer::FILE_SYNC_VERSION, Criteria::NOT_EQUAL);
                     $criteria->add(MetadataProfilePeer::FILE_SYNC_VERSION, null, Criteria::ISNOTNULL);
                     break;
                 case MetadataProfile::FILE_SYNC_METADATA_VIEWS:
                     $join->addCondition(FileSyncPeer::VERSION, MetadataProfilePeer::VIEWS_VERSION, Criteria::NOT_EQUAL);
                     $criteria->add(MetadataProfilePeer::VIEWS_VERSION, null, Criteria::ISNOTNULL);
                     break;
                 default:
                     return array();
             }
             $join->setJoinType(Criteria::LEFT_JOIN);
             $criteria->addJoinObject($join);
             break;
         default:
             return array();
     }
     $criteria->add(FileSyncPeer::DC, kDataCenterMgr::getCurrentDcId());
     $criteria->add(FileSyncPeer::OBJECT_TYPE, $objectType);
     $criteria->add(FileSyncPeer::OBJECT_SUB_TYPE, $objectSubType);
     $criteria->add(FileSyncPeer::STATUS, array(FileSync::FILE_SYNC_STATUS_DELETED, FileSync::FILE_SYNC_STATUS_PURGED), Criteria::NOT_IN);
     $nextCriteria = clone $criteria;
     $criteria->add(FileSyncPeer::UPDATED_AT, self::$oldVersionsStartUpdatedAt[$objectType], Criteria::GREATER_EQUAL);
     $criteria->addAnd(FileSyncPeer::UPDATED_AT, self::$oldVersionsEndUpdatedAt[$objectType], Criteria::LESS_EQUAL);
     $criteria->addAscendingOrderByColumn(FileSyncPeer::UPDATED_AT);
     $criteria->setLimit(self::$queryLimit);
     $fileSyncs = FileSyncPeer::doSelect($criteria);
     if (count($fileSyncs)) {
         foreach ($fileSyncs as $fileSync) {
             /* @var $fileSync FileSync */
             self::deleteFileSync($fileSync);
             if ($fileSync->getUpdatedAt(null)) {
                 self::$oldVersionsNextStartUpdatedAt[$objectType] = $fileSync->getUpdatedAt(null);
             }
         }
     } else {
         self::$oldVersionsNextStartUpdatedAt[$objectType] = self::$oldVersionsStartUpdatedAt[$objectType];
         $nextCriteria->add(FileSyncPeer::UPDATED_AT, self::$oldVersionsStartUpdatedAt[$objectType], Criteria::GREATER_THAN);
         $nextCriteria->addSelectColumn('UNIX_TIMESTAMP(MIN(' . FileSyncPeer::UPDATED_AT . '))');
         $stmt = FileSyncPeer::doSelectStmt($nextCriteria);
         $mins = $stmt->fetchAll(PDO::FETCH_COLUMN);
         if (count($mins)) {
             $oldVersionsNextStartUpdatedAt = reset($mins);
             if (!is_null($oldVersionsNextStartUpdatedAt)) {
                 self::$oldVersionsNextStartUpdatedAt[$objectType] = $oldVersionsNextStartUpdatedAt;
             }
         }
     }
     kMemoryManager::clearMemory();
 }
Пример #11
0
 /**
  * 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      PartnerLoad $value A PartnerLoad object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(PartnerLoad $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = serialize(array((string) $obj->getJobType(), (string) $obj->getJobSubType(), (string) $obj->getPartnerId(), (string) $obj->getDc()));
         }
         if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) {
             self::$instances[$key] = $obj;
             kMemoryManager::registerPeer('PartnerLoadPeer');
         }
     }
 }
Пример #12
0
 /**
  * Returns the log file for bulk upload job
  * @param BatchJob $batchJob bulk upload batchjob
  * @return SimpleXMLElement
  */
 public static function getBulkUploadMrssXml($batchJob)
 {
     $actionsMap = array(BulkUploadAction::ADD => 'add', BulkUploadAction::UPDATE => 'update', BulkUploadAction::DELETE => 'delete');
     $criteria = new Criteria();
     $criteria->add(BulkUploadResultPeer::BULK_UPLOAD_JOB_ID, $batchJob->getId());
     $criteria->addAscendingOrderByColumn(BulkUploadResultPeer::LINE_INDEX);
     $criteria->setLimit(100);
     $bulkUploadResults = BulkUploadResultPeer::doSelect($criteria);
     if (!count($bulkUploadResults)) {
         return null;
     }
     header("Content-Type: text/xml; charset=UTF-8");
     $data = $batchJob->getData();
     $xmlElement = new SimpleXMLElement('<mrss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>');
     $xmlElement->addAttribute('version', '2.0');
     $channel = $xmlElement->addChild('channel');
     $handledResults = 0;
     while (count($bulkUploadResults)) {
         $handledResults += count($bulkUploadResults);
         //		insert all entries to instance pool
         $pks = array();
         foreach ($bulkUploadResults as $bulkUploadResult) {
             /* @var $bulkUploadResult BulkUploadResult */
             $pks[] = $bulkUploadResult->getEntryId();
         }
         entryPeer::retrieveByPKs($pks);
         foreach ($bulkUploadResults as $bulkUploadResult) {
             /* @var $bulkUploadResult BulkUploadResult */
             $item = $channel->addChild('item');
             $result = $item->addChild('result');
             $result->addChild('errorDescription', self::stringToSafeXml($bulkUploadResult->getErrorDescription()));
             //			$result->addChild('entryStatus', self::stringToSafeXml($bulkUploadResult->getEntryStatus()));
             //			$result->addChild('entryStatusName', self::stringToSafeXml($title));
             $action = isset($actionsMap[$bulkUploadResult->getAction()]) ? $actionsMap[$bulkUploadResult->getAction()] : $actionsMap[BulkUploadAction::ADD];
             $item->addChild('action', $action);
             $entry = $bulkUploadResult->getObject();
             if (!$entry) {
                 continue;
             }
             kMrssManager::getEntryMrssXml($entry, $item);
         }
         if (count($bulkUploadResults) < $criteria->getLimit()) {
             break;
         }
         kMemoryManager::clearMemory();
         $criteria->setOffset($handledResults);
         $bulkUploadResults = BulkUploadResultPeer::doSelect($criteria);
     }
     return $xmlElement;
 }
Пример #13
0
 /**
  * batch updateBulkUploadResults action adds KalturaBulkUploadResult to the DB
  *
  * @action updateBulkUploadResults
  * @param int $bulkUploadJobId The id of the bulk upload job
  * @return int the number of unclosed entries
  */
 function updateBulkUploadResultsAction($bulkUploadJobId)
 {
     $unclosedEntriesCount = 0;
     $errorObjects = 0;
     $unclosedEntries = array();
     $criteria = new Criteria();
     $criteria->add(BulkUploadResultPeer::BULK_UPLOAD_JOB_ID, $bulkUploadJobId);
     $criteria->addAscendingOrderByColumn(BulkUploadResultPeer::LINE_INDEX);
     $criteria->setLimit(100);
     $bulkUpload = BatchJobPeer::retrieveByPK($bulkUploadJobId);
     if ($bulkUpload) {
         $handledResults = 0;
         $bulkUploadResults = BulkUploadResultPeer::doSelect($criteria);
         while (count($bulkUploadResults)) {
             $handledResults += count($bulkUploadResults);
             foreach ($bulkUploadResults as $bulkUploadResult) {
                 /* @var $bulkUploadResult BulkUploadResult */
                 $status = $bulkUploadResult->updateStatusFromObject();
                 if ($status == BulkUploadResultStatus::IN_PROGRESS) {
                     $unclosedEntriesCount++;
                 }
                 if ($status == BulkUploadResultStatus::ERROR) {
                     $errorObjects++;
                 }
             }
             if (count($bulkUploadResults) < $criteria->getLimit()) {
                 break;
             }
             kMemoryManager::clearMemory();
             $criteria->setOffset($handledResults);
             $bulkUploadResults = BulkUploadResultPeer::doSelect($criteria);
         }
         $data = $bulkUpload->getData();
         if ($data && $data instanceof kBulkUploadJobData) {
             //TODO: find some better alternative, find out why the bulk upload result which reports error is
             // returning objectId "null" for failed entry assets, rather than the entryId to which they pertain.
             //$data->setNumOfEntries(BulkUploadResultPeer::countWithEntryByBulkUploadId($bulkUploadJobId));
             $data->setNumOfObjects(BulkUploadResultPeer::countWithObjectTypeByBulkUploadId($bulkUploadJobId, $data->getBulkUploadObjectType()));
             $data->setNumOfErrorObjects($errorObjects);
             $bulkUpload->setData($data);
             $bulkUpload->save();
         }
     }
     return $unclosedEntriesCount;
 }
 public function handleMultiRequest()
 {
     $listOfRequests = array();
     $results = array();
     $found = true;
     $i = 1;
     while ($found) {
         $currentService = isset($this->params[$i . ":service"]) ? $this->params[$i . ":service"] : null;
         $currentAction = isset($this->params[$i . ":action"]) ? $this->params[$i . ":action"] : null;
         $found = $currentAction && $currentService;
         if ($found) {
             $listOfRequests[$i]["service"] = $currentService;
             $listOfRequests[$i]["action"] = $currentAction;
             // find all the parameters for this request
             foreach ($this->params as $key => $val) {
                 // the key "1:myparam" mean that we should input value of this key to request "1", for param "myparam"
                 $keyArray = explode(":", $key);
                 if ($keyArray[0] == $i) {
                     array_shift($keyArray);
                     // remove the request number
                     $requestKey = implode(":", $keyArray);
                     /* remarked by Dor - 13/10/2010
                         * There is no need to remove service and action from the params in case of multirequest
                         * while they are needed in KalturaResponseCacher
                         
                        if (in_array($requestKey, array("service", "action"))) // don't add service name and action name to the params
                            continue;
                        
                        */
                     $listOfRequests[$i]["params"][$requestKey] = $val;
                     // store the param
                 }
             }
             // clientTag param might be used in KalturaResponseCacher
             if (isset($this->params['clientTag']) && !isset($listOfRequests[$i]["params"]['clientTag'])) {
                 $listOfRequests[$i]["params"]['clientTag'] = $this->params['clientTag'];
             }
             // if ks is not set for a specific request, copy the ks from the top params
             $currentKs = isset($listOfRequests[$i]["params"]["ks"]) ? $listOfRequests[$i]["params"]["ks"] : null;
             if (!$currentKs) {
                 $mainKs = isset($this->params["ks"]) ? $this->params["ks"] : null;
                 if ($mainKs) {
                     $listOfRequests[$i]["params"]["ks"] = $mainKs;
                 }
             }
             $currentPartner = isset($listOfRequests[$i]["params"]["partnerId"]) ? $listOfRequests[$i]["params"]["partnerId"] : null;
             if (!$currentPartner) {
                 $mainPartner = isset($this->params["partnerId"]) ? $this->params["partnerId"] : null;
                 if ($mainPartner) {
                     $listOfRequests[$i]["params"]["partnerId"] = $mainPartner;
                 }
             }
             $i++;
         } else {
             // will break the loop
         }
     }
     $i = 1;
     foreach ($listOfRequests as $currentRequest) {
         kCurrentContext::$multiRequest_index = $i;
         $currentService = $currentRequest["service"];
         $currentAction = $currentRequest["action"];
         $currentParams = $currentRequest["params"];
         // check if we need to replace params with prev results
         foreach ($currentParams as $key => &$val) {
             $matches = array();
             // keywords: multirequest, result, depend, pass
             // figuring out if requested params should be extracted from previous result
             // example: if you want to use KalturaPlaylist->playlistContent result from the first request
             // in your second request, the second request will contain the following value:
             // {1:result:playlistContent}
             if (preg_match('/\\{([0-9]*)\\:result\\:?(.*)?\\}/', $val, $matches)) {
                 $resultIndex = $matches[1];
                 $resultKey = $matches[2];
                 if (count($results) >= $resultIndex) {
                     if (strlen(trim($resultKey)) > 0) {
                         $resultPathArray = explode(":", $resultKey);
                     } else {
                         $resultPathArray = array();
                     }
                     $val = $this->getValueFromObject($results[$resultIndex], $resultPathArray);
                 }
             }
         }
         // cached parameters should be different when the request is part of a multirequest
         // as part of multirequest - the cached data is a serialized php object
         // when not part of multirequest - the cached data is the actual response
         $currentParams['multirequest'] = true;
         unset($currentParams['format']);
         $cache = new KalturaResponseCacher($currentParams);
         if (!isset($currentParams['ks']) && kCurrentContext::$ks) {
             $cache->setKS(kCurrentContext::$ks);
         }
         $success = true;
         $errorCode = null;
         $this->onRequestStart($currentService, $currentAction, $currentParams, $i, true);
         $cachedResult = $cache->checkCache('X-Kaltura-Part-Of-MultiRequest');
         if ($cachedResult) {
             $currentResult = unserialize($cachedResult);
         } else {
             if ($i != 1) {
                 kMemoryManager::clearMemory();
                 KalturaCriterion::clearTags();
             }
             try {
                 $currentResult = $this->dispatcher->dispatch($currentService, $currentAction, $currentParams);
             } catch (Exception $ex) {
                 $success = false;
                 $errorCode = $ex->getCode();
                 $currentResult = $this->getExceptionObject($ex);
             }
             $cache->storeCache($currentResult, "", true);
         }
         $this->onRequestEnd($success, $errorCode, $i);
         $results[$i] = $currentResult;
         $i++;
     }
     return $results;
 }
Пример #15
0
 /**
  * Returns the log file for bulk upload job
  * @param BatchJob $batchJob bulk upload batchjob
  */
 public static function writeBulkUploadLogFile($batchJob)
 {
     if ($batchJob->getJobSubType() && $batchJob->getJobSubType() != self::getBulkUploadTypeCoreValue(BulkUploadFilterType::FILTER)) {
         return;
     }
     //TODO:
     header("Content-Type: text/plain; charset=UTF-8");
     $criteria = new Criteria();
     $criteria->add(BulkUploadResultPeer::BULK_UPLOAD_JOB_ID, $batchJob->getId());
     $criteria->addAscendingOrderByColumn(BulkUploadResultPeer::LINE_INDEX);
     $criteria->setLimit(100);
     $bulkUploadResults = BulkUploadResultPeer::doSelect($criteria);
     if (!count($bulkUploadResults)) {
         die("Log file is not ready");
     }
     $STDOUT = fopen('php://output', 'w');
     $data = $batchJob->getData();
     /* @var $data kBulkUploadFilterJobData */
     $handledResults = 0;
     while (count($bulkUploadResults)) {
         $handledResults += count($bulkUploadResults);
         foreach ($bulkUploadResults as $bulkUploadResult) {
             $values = array();
             $values['bulkUploadResultStatus'] = $bulkUploadResult->getStatus();
             $values['objectId'] = $bulkUploadResult->getObjectId();
             $values['objectStatus'] = $bulkUploadResult->getObjectStatus();
             $values['errorDescription'] = preg_replace('/[\\n\\r\\t]/', ' ', $bulkUploadResult->getErrorDescription());
             fwrite($STDOUT, print_r($values, true));
         }
         if (count($bulkUploadResults) < $criteria->getLimit()) {
             break;
         }
         kMemoryManager::clearMemory();
         $criteria->setOffset($handledResults);
         $bulkUploadResults = BulkUploadResultPeer::doSelect($criteria);
     }
     fclose($STDOUT);
     kFile::closeDbConnections();
     exit;
 }
Пример #16
0
 public function handleMultiRequest()
 {
     // arrange the parameters by request index
     $commonParams = array();
     $listOfRequests = array();
     $requestStartIndex = 1;
     $requestEndIndex = 1;
     foreach ($this->params as $paramName => $paramValue) {
         if (is_numeric($paramName)) {
             $paramName = intval($paramName);
             $requestStartIndex = min($requestStartIndex, $paramName);
             $requestEndIndex = max($requestEndIndex, $paramName);
             $listOfRequests[$paramName] = $paramValue;
             continue;
         }
         $explodedName = explode(':', $paramName, 2);
         if (count($explodedName) <= 1 || !is_numeric($explodedName[0])) {
             $commonParams[$paramName] = $paramValue;
             continue;
         }
         $requestIndex = (int) $explodedName[0];
         $requestStartIndex = min($requestStartIndex, $requestIndex);
         $requestEndIndex = max($requestEndIndex, $requestIndex);
         $paramName = $explodedName[1];
         if (!array_key_exists($requestIndex, $listOfRequests)) {
             $listOfRequests[$requestIndex] = array();
         }
         $listOfRequests[$requestIndex][$paramName] = $paramValue;
     }
     $multiRequestResultsPaths = $this->getMultiRequestResultsPaths($listOfRequests);
     // process the requests
     $results = array();
     kCurrentContext::$multiRequest_index = 0;
     for ($i = $requestStartIndex; $i <= $requestEndIndex; $i++) {
         $currentParams = $listOfRequests[$i];
         if (!isset($currentParams["service"]) || !isset($currentParams["action"])) {
             break;
         }
         kCurrentContext::$multiRequest_index++;
         $currentService = $currentParams["service"];
         $currentAction = $currentParams["action"];
         // copy derived common params to current params
         if (isset($commonParams['clientTag']) && !isset($currentParams['clientTag'])) {
             $currentParams['clientTag'] = $commonParams['clientTag'];
         }
         if (isset($commonParams['ks']) && !isset($currentParams['ks'])) {
             $currentParams['ks'] = $commonParams['ks'];
         }
         if (isset($commonParams['partnerId']) && !isset($currentParams['partnerId'])) {
             $currentParams['partnerId'] = $commonParams['partnerId'];
         }
         // cached parameters should be different when the request is part of a multirequest
         // as part of multirequest - the cached data is a serialized php object
         // when not part of multirequest - the cached data is the actual response
         $currentParams['multirequest'] = true;
         unset($currentParams['format']);
         $cache = new KalturaResponseCacher($currentParams);
         $success = true;
         $errorCode = null;
         $this->onRequestStart($currentService, $currentAction, $currentParams, kCurrentContext::$multiRequest_index, true);
         $cachedResult = $cache->checkCache('X-Kaltura-Part-Of-MultiRequest');
         if ($cachedResult) {
             $currentResult = unserialize($cachedResult);
         } else {
             if (kCurrentContext::$multiRequest_index != 1) {
                 kMemoryManager::clearMemory();
                 KalturaCriterion::clearTags();
             }
             try {
                 $currentResult = $this->dispatcher->dispatch($currentService, $currentAction, $currentParams);
             } catch (Exception $ex) {
                 $success = false;
                 $errorCode = $ex->getCode();
                 $currentResult = $this->getExceptionObject($ex, $currentService, $currentAction);
             }
             $cache->storeCache($currentResult, "", true);
         }
         $this->onRequestEnd($success, $errorCode, kCurrentContext::$multiRequest_index);
         for ($nextMultiRequestIndex = $i + 1; $nextMultiRequestIndex <= count($listOfRequests); $nextMultiRequestIndex++) {
             if (isset($multiRequestResultsPaths[$nextMultiRequestIndex])) {
                 $listOfRequests[$nextMultiRequestIndex] = $this->replaceMultiRequestResults(kCurrentContext::$multiRequest_index, $multiRequestResultsPaths[$nextMultiRequestIndex], $listOfRequests[$nextMultiRequestIndex], $currentResult);
             }
         }
         $results[kCurrentContext::$multiRequest_index] = $this->serializer->serialize($currentResult);
         // in case a serve action is included in a multirequest, return only the result of the serve action
         // in order to avoid serializing the kRendererBase object and returning the internal server paths to the client
         if ($currentResult instanceof kRendererBase) {
             return $currentResult;
         }
     }
     return $results;
 }
 protected function handleEntries($context, $feed, array $entries)
 {
     $protocol = infraRequestUtils::getProtocol();
     $cachePrefix = "dist_" . $this->profile->getId() . "/{$protocol}/entry_";
     $profileUpdatedAt = $this->profile->getUpdatedAt(null);
     $extendItems = $this->profile->getItemXpathsToExtend();
     $enableCache = empty($extendItems);
     $cacheStore = null;
     if ($enableCache) {
         $cacheStore = kCacheManager::getSingleLayerCache(kCacheManager::CACHE_TYPE_FEED_ENTRY);
         if (is_null($cacheStore)) {
             $enableCache = false;
         }
     }
     $counter = 0;
     foreach ($entries as $entry) {
         $xml = null;
         $cacheKey = $cachePrefix . str_replace("_", "-", $entry->getId());
         // replace _ with - so cache folders will be created with random entry id and not 0_/1_
         if ($enableCache) {
             $cacheTime = $cacheStore->get($cacheKey . self::CACHE_CREATION_TIME_SUFFIX);
             $updatedAt = max($profileUpdatedAt, $entry->getUpdatedAt(null));
             if ($updatedAt + self::CACHE_CREATION_MARGIN < $cacheTime) {
                 $xml = $cacheStore->get($cacheKey);
             }
         }
         if (!$xml) {
             $entryDistribution = EntryDistributionPeer::retrieveByEntryAndProfileId($entry->getId(), $this->profile->getId());
             if (!$entryDistribution) {
                 KalturaLog::err('Entry distribution was not found for entry [' . $entry->getId() . '] and profile [' . $this->profile->getId() . ']');
                 continue;
             }
             $xml = $this->handleEntry($context, $feed, $entry, $entryDistribution);
             if (!is_null($xml) && $enableCache) {
                 $cacheStore->set($cacheKey . self::CACHE_CREATION_TIME_SUFFIX, time());
                 $cacheStore->set($cacheKey, $xml);
             }
         }
         $feed->addItemXml($xml);
         $counter++;
         //to avoid the cache exceeding the memory size
         if ($counter % self::CACHE_SIZE == 0) {
             kMemoryManager::clearMemory();
         }
     }
 }
Пример #18
0
function handleFile($filePath)
{
    $con = Propel::getConnection(PartnerPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    $fileName = basename($filePath);
    KalturaLog::info("Handling file [{$fileName}]");
    list($order, $objectType, $fileExtension) = explode('.', $fileName, 3);
    $objectConfigurations = parse_ini_file($filePath, true);
    $object = new $objectType();
    /* @var $object BaseObject */
    $peer = $object->getPeer();
    $peerClass = get_class($peer);
    $newObjectType = "Insert{$objectType}";
    if (!class_exists($newObjectType)) {
        eval('
			class Insert' . $objectType . ' extends ' . $objectType . '
			{
				public function setId($v)
				{
					if(!$this->getId())
						parent::setId($v);
					
					return $this;
				}
				
				protected function doSave(PropelPDO $con)
				{
					$affectedRows = 0; // initialize var to track total num of affected rows
					if (!$this->alreadyInSave) {
						$this->alreadyInSave = true;
			
						$this->objectSaved = false;
						if ($this->isModified()) {
							if ($this->isNew()) {
								$pk = BasePeer::doInsert($this->buildCriteria(), $con);
								$affectedRows += 1;
								$this->setId($pk);  //[IMV] update autoincrement primary key
								$this->setNew(false);
								$this->objectSaved = true;
							} else {
								$affectedObjects = ' . $peerClass . '::doUpdate($this, $con);
								if($affectedObjects)
									$this->objectSaved = true;
									
								$affectedRows += $affectedObjects;
							}
			
							$this->resetModified(); // [HL] After being saved an object is no longer \'modified\'
						}
			
						$this->alreadyInSave = false;
					}
					return $affectedRows;
				}
			}
		');
    }
    $map = $peer->getTableMap();
    $primaryKeys = $map->getPrimaryKeys();
    foreach ($objectConfigurations as $objectConfiguration) {
        $object = new $newObjectType();
        /* @var $object BaseObject */
        $pk = null;
        $pkField = null;
        // New logic allowing to use other parameters as uique identifers for updates
        $identifierParam = null;
        $identifierColumn = null;
        $setters = array();
        foreach ($objectConfiguration as $attributeName => $value) {
            if ($attributeName == 'id') {
                $pk = $value;
            } elseif ($attributeName == 'identifierParam') {
                ${$attributeName} = $value;
                continue;
            }
            if (preg_match('/eval\\((?P<evalString>.+)\\)/', $value, $matches)) {
                $evalString = $matches["evalString"];
                $evaluator = new kEvalStringField();
                $evaluator->setScope(new kScope());
                $evaluator->setCode($evalString);
                $value = $evaluator->getValue();
                KalturaLog::info("Evaluated property value: {$value}");
            }
            $setter = "set{$attributeName}";
            if (!is_callable(array($object, $setter))) {
                throw new Exception("Attribute [{$attributeName}] not defined on object type [{$objectType}]");
            }
            if (preg_match('/^@[^@]+$/', $value)) {
                $valueFilePath = realpath(dirname($filePath) . '/' . substr($value, 1));
                if (!$valueFilePath || !is_file($valueFilePath)) {
                    throw new Exception("Attribute [{$attributeName}] file path [{$value}] not found");
                }
                $value = file_get_contents($valueFilePath);
            }
            if (preg_match('/^#[^#]+$/', $value)) {
                $value = kPluginableEnumsManager::genericApiToCore(substr($value, 1));
            }
            $setters[$setter] = $value;
        }
        $pkCriteria = null;
        $existingObject = null;
        if (!is_null($pk)) {
            $pkCriteria = new Criteria();
            $pkCriteria->add(constant(get_class($peer) . '::ID'), $pk);
            $existingObject = $peer->doSelectOne($pkCriteria, $con);
        } elseif (!is_null($identifierParam)) {
            // If we have some other form of identifier on the object
            $identifierColumn = $peer::translateFieldName($identifierParam, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME);
            $c = new Criteria();
            $c->add($identifierColumn, $objectConfiguration[$identifierParam]);
            $existingObject = $peer->doSelectOne($c, $con);
        }
        if ($existingObject) {
            KalturaLog::info('existing objects will not be re-written');
            continue;
        }
        foreach ($setters as $setter => $value) {
            $object->{$setter}($value);
        }
        $object->save();
        if (!is_null($pkCriteria)) {
            BasePeer::doUpdate($object->buildPkeyCriteria(), $pkCriteria, $con);
        }
        kMemoryManager::clearMemory();
    }
}
Пример #19
0
$criteria = new Criteria();
if (!is_null($partnerId)) {
    $criteria->addAnd(UserRolePeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
}
$criteria->addAnd(UserRolePeer::NAME, $roleName, Criteria::EQUAL);
$criteria->addAscendingOrderByColumn(UserRolePeer::ID);
$criteria->setLimit($page);
$userRoles = UserRolePeer::doSelect($criteria);
while (count($userRoles)) {
    KalturaLog::info("[" . count($userRoles) . "] user roles .");
    foreach ($userRoles as $userRole) {
        foreach ($parmissionNames as $parmissionName) {
            addPermissionsToRole($userRole, $parmissionName);
        }
    }
    kMemoryManager::clearMemory();
    $nextCriteria = clone $criteria;
    $nextCriteria->add(UserRolePeer::ID, $userRole->getId(), Criteria::GREATER_THAN);
    $userRoles = UserRolePeer::doSelect($nextCriteria);
    usleep(100);
}
KalturaLog::info("Done");
function addPermissionsToRole($role, $permissionList)
{
    $currentPermissions = $role->getPermissionNames(false, true);
    if (UserRole::ALL_PARTNER_PERMISSIONS_WILDCARD == $currentPermissions) {
        return;
    }
    $currentPermissionsArray = explode(',', $currentPermissions);
    $permissionsToAddArray = explode(',', $permissionList);
    $tempArray = array();
Пример #20
0
 /**
  * Restore deleted entry.
  *
  * @action restoreDeletedEntry
  * @param string $entryId
  * @return KalturaBaseEntry The restored entry
  */
 public function restoreDeletedEntryAction($entryId)
 {
     $deletedEntry = entryPeer::retrieveByPKNoFilter($entryId);
     if (!$deletedEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $fileSyncKeys = array();
     foreach (self::$fileSyncKeysToRestore as $key) {
         $fileSyncKeys[] = $deletedEntry->getSyncKey($key);
     }
     $c = new Criteria();
     $c->add(assetPeer::ENTRY_ID, $entryId, Criteria::EQUAL);
     assetPeer::setUseCriteriaFilter(false);
     $deletedAssets = assetPeer::doSelect($c);
     assetPeer::setUseCriteriaFilter(true);
     foreach ($deletedAssets as $deletedAsset) {
         array_push($fileSyncKeys, $deletedAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET), $deletedAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_CONVERT_LOG));
     }
     $fileSyncs = array();
     FileSyncPeer::setUseCriteriaFilter(false);
     foreach ($fileSyncKeys as $fileSyncKey) {
         $fileSyncs = array_merge($fileSyncs, FileSyncPeer::retrieveAllByFileSyncKey($fileSyncKey));
     }
     FileSyncPeer::setUseCriteriaFilter(true);
     if (!$this->validateEntryForRestoreDelete($deletedEntry, $fileSyncs, $deletedAssets)) {
         throw new KalturaAPIException(KalturaAdminConsoleErrors::ENTRY_ASSETS_WRONG_STATUS_FOR_RESTORE, $entryId);
     }
     $this->restoreFileSyncs($fileSyncs);
     //restore assets
     foreach ($deletedAssets as $deletedAsset) {
         $deletedAsset->setStatus(asset::ASSET_STATUS_READY);
         $deletedAsset->save();
     }
     //restore entry
     $deletedEntry->setStatusReady();
     $deletedEntry->setThumbnail($deletedEntry->getFromCustomData("deleted_original_thumb"), true);
     $deletedEntry->setData($deletedEntry->getFromCustomData("deleted_original_data"), true);
     //data should be resotred even if it's NULL
     $deletedEntry->save();
     kEventsManager::flushEvents();
     kMemoryManager::clearMemory();
     $entry = KalturaEntryFactory::getInstanceByType($deletedEntry->getType(), true);
     $entry->fromObject($deletedEntry, $this->getResponseProfile());
     return $entry;
 }
Пример #21
0
 /**
  * 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      MetadataProfile $value A MetadataProfile object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(MetadataProfile $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('MetadataProfilePeer');
         }
     }
 }
 private function fetchNextPage()
 {
     if ($this->executed && $this->staticPlaylist) {
         return;
     }
     $this->entriesCurrentPage = null;
     kMemoryManager::clearMemory();
     if ($this->currentCriteria) {
         if ($this->lastEntryCreatedAt) {
             $this->currentCriteria->add($this->getOrderByColumn(), $this->lastEntryCreatedAt, Criteria::LESS_EQUAL);
         }
         if (count($this->lastEntryIds)) {
             $this->currentCriteria->add(entryPeer::ID, $this->lastEntryIds, Criteria::NOT_IN);
         }
     } else {
         $this->currentCriteria = $this->getNextCriteria();
         if (!$this->currentCriteria) {
             return;
         }
     }
     $nextPage = entryPeer::doSelect($this->currentCriteria);
     if (!count($nextPage)) {
         $this->currentCriteria = $this->getNextCriteria();
         if (!$this->currentCriteria) {
             return;
         }
         $nextPage = entryPeer::doSelect($this->currentCriteria);
     }
     if (!count($nextPage)) {
         // finished all criterias and pages
         return;
     }
     if ($this->staticPlaylist) {
         //order the entries by static (AKA manual) entries order
         $nextPageEntries = array();
         foreach ($nextPage as $entry) {
             $nextPageEntries[$entry->getId()] = $entry;
         }
         $nextPage = array();
         foreach ($this->staticPlaylistEntriesIdsOrder as $entryId) {
             if (isset($nextPageEntries[$entryId])) {
                 $nextPage[] = $nextPageEntries[$entryId];
             }
         }
     }
     $this->entriesCurrentPage = $nextPage;
     reset($this->entriesCurrentPage);
 }