コード例 #1
0
ファイル: kMetadataManager.php プロジェクト: AdiTal/server
 /**
  * Returns values from the metadata object according to the xPath
  * @param Metadata $metadata
  * @param string $xPathPattern
  * @return array
  */
 public static function parseMetadataValues(Metadata $metadata, $xPathPattern, $version = null)
 {
     $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA, $version);
     $source = kFileSyncUtils::file_get_contents($key, true, false);
     if (!$source) {
         KalturaLog::notice("Metadata key {$key} not found.");
         return null;
     }
     $xml = new KDOMDocument();
     $xml->loadXML($source);
     if (preg_match('/^\\w[\\w\\d]*$/', $xPathPattern)) {
         $xPathPattern = "//{$xPathPattern}";
     }
     $matches = null;
     if (preg_match_all('/\\/(\\w[\\w\\d]*)/', $xPathPattern, $matches)) {
         if (count($matches) == 2 && implode('', $matches[0]) == $xPathPattern) {
             $xPathPattern = '';
             foreach ($matches[1] as $match) {
                 $xPathPattern .= "/*[local-name()='{$match}']";
             }
         }
     }
     KalturaLog::debug("Metadata xpath [{$xPathPattern}]");
     $xPath = new DOMXPath($xml);
     $elementsList = $xPath->query($xPathPattern);
     $values = array();
     foreach ($elementsList as $element) {
         /* @var $element DOMNode */
         $values[] = $element->textContent;
     }
     return $values;
 }
コード例 #2
0
ファイル: FiltersGenerator.php プロジェクト: DBezemer/server
 private function writeFilterForType(KalturaTypeReflector $type)
 {
     $map = KAutoloader::getClassMap();
     if (!isset($map[$type->getType()])) {
         return;
     }
     $filterClassName = $type->getType() . "Filter";
     $filterBaseClassName = $type->getType() . "BaseFilter";
     $filterPath = dirname($map[$type->getType()]) . "/filters/{$filterClassName}.php";
     if (file_exists($filterPath)) {
         KalturaLog::notice("Filter already exists [{$filterPath}]");
         return;
     }
     $this->_txt = "";
     $parentType = $type;
     while (1) {
         $parentType = $parentType->getParentTypeReflector();
         if ($parentType === null || $parentType->isFilterable()) {
             break;
         }
     }
     $partnetClassName = $parentType ? $parentType->getType() . "Filter" : "KalturaFilter";
     $subpackage = ($type->getPackage() == 'api' ? '' : 'api.') . 'filters';
     $this->appendLine("<?php");
     $this->appendLine("/**");
     $this->appendLine(" * @package " . $type->getPackage());
     $this->appendLine(" * @subpackage {$subpackage}");
     $this->appendLine(" */");
     $this->appendLine("class {$filterClassName} extends {$filterBaseClassName}");
     $this->appendLine("{");
     $this->appendLine("}");
     $this->writeToFile($filterPath, $this->_txt);
 }
コード例 #3
0
 protected function scan(KalturaBatchJob $job, KalturaVirusScanJobData $data)
 {
     KalturaLog::debug("scan({$job->id})");
     try {
         $engine = VirusScanEngine::getEngine($job->jobSubType);
         if (!$engine) {
             KalturaLog::err('Cannot create VirusScanEngine of type [' . $job->jobSubType . ']');
             $this->closeJob($job, KalturaBatchJobErrorTypes::APP, null, 'Error: Cannot create VirusScanEngine of type [' . $job->jobSubType . ']', KalturaBatchJobStatus::FAILED);
             return $job;
         }
         // configure engine
         if (!$engine->config(self::$taskConfig->params)) {
             KalturaLog::err('Cannot configure VirusScanEngine of type [' . $job->jobSubType . ']');
             $this->closeJob($job, KalturaBatchJobErrorTypes::APP, null, 'Error: Cannot configure VirusScanEngine of type [' . $job->jobSubType . ']', KalturaBatchJobStatus::FAILED);
             return $job;
         }
         $cleanIfInfected = $data->virusFoundAction == KalturaVirusFoundAction::CLEAN_NONE || $data->virusFoundAction == KalturaVirusFoundAction::CLEAN_DELETE;
         $errorDescription = null;
         $output = null;
         // execute scan
         $data->scanResult = $engine->execute($data->srcFilePath, $cleanIfInfected, $output, $errorDescription);
         if (!$output) {
             KalturaLog::notice('Virus scan engine [' . get_class($engine) . '] did not return any log for file [' . $data->srcFilePath . ']');
             $output = 'Virus scan engine [' . get_class($engine) . '] did not return any log';
         }
         try {
             self::$kClient->batch->logConversion($data->flavorAssetId, $output);
         } catch (Exception $e) {
             KalturaLog::err("Log conversion: " . $e->getMessage());
         }
         // check scan results
         switch ($data->scanResult) {
             case KalturaVirusScanJobResult::SCAN_ERROR:
                 $this->closeJob($job, KalturaBatchJobErrorTypes::APP, null, "Error: " . $errorDescription, KalturaBatchJobStatus::RETRY, $data);
                 break;
             case KalturaVirusScanJobResult::FILE_IS_CLEAN:
                 $this->closeJob($job, null, null, "Scan finished - file was found to be clean", KalturaBatchJobStatus::FINISHED, $data);
                 break;
             case KalturaVirusScanJobResult::FILE_WAS_CLEANED:
                 $this->closeJob($job, null, null, "Scan finished - file was infected but scan has managed to clean it", KalturaBatchJobStatus::FINISHED, $data);
                 break;
             case KalturaVirusScanJobResult::FILE_INFECTED:
                 $this->closeJob($job, null, null, "File was found INFECTED and wasn't cleaned!", KalturaBatchJobStatus::FINISHED, $data);
                 break;
             default:
                 $data->scanResult = KalturaVirusScanJobResult::SCAN_ERROR;
                 $this->closeJob($job, KalturaBatchJobErrorTypes::APP, null, "Error: Emtpy scan result returned", KalturaBatchJobStatus::RETRY, $data);
                 break;
         }
     } catch (Exception $ex) {
         $data->scanResult = KalturaVirusScanJobResult::SCAN_ERROR;
         $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $ex->getCode(), "Error: " . $ex->getMessage(), KalturaBatchJobStatus::FAILED, $data);
     }
     return $job;
 }
コード例 #4
0
 protected function provision(KalturaBatchJob $job, KalturaProvisionJobData $data)
 {
     KalturaLog::notice("Provision entry");
     $job = $this->updateJob($job, null, KalturaBatchJobStatus::QUEUED, 1);
     $engine = KProvisionEngine::getInstance($job->jobSubType, $this->taskConfig);
     if ($engine == null) {
         $err = "Cannot find provision engine [{$job->jobSubType}] for job id [{$job->id}]";
         return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::ENGINE_NOT_FOUND, $err, KalturaBatchJobStatus::FAILED);
     }
     KalturaLog::info("Using engine: " . $engine->getName());
     $results = $engine->delete($job, $data);
     if ($results->status == KalturaBatchJobStatus::FINISHED) {
         return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::FINISHED, $results->data);
     }
     return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, null, $results->errMessage, $results->status, $results->data);
 }
コード例 #5
0
ファイル: kEventsManager.php プロジェクト: richhl/kalturaCE
 public static function raiseEvent(KalturaEvent $event)
 {
     $consumerInterface = $event->getConsumerInterface();
     KalturaLog::debug("Event [" . get_class($event) . "] raised looking for consumers [{$consumerInterface}]");
     $consumers = self::getConsumers($consumerInterface);
     foreach ($consumers as $consumerClass) {
         //			KalturaLog::debug("Event consumer [$consumerClass] called");
         $continue = $event->consume(new $consumerClass());
         if (!$continue) {
             if ($event instanceof IKalturaCancelableEvent) {
                 KalturaLog::notice("Event [" . get_class($event) . "] paused by consumer [{$consumerClass}]");
                 break;
             } else {
                 KalturaLog::debug("Event [" . get_class($event) . "] is not cancelable event");
             }
         }
     }
 }
コード例 #6
0
ファイル: kBusinessConvertDL.php プロジェクト: dozernz/server
 public static function checkForPendingLiveClips(entry $entry)
 {
     if ($entry->getSource() != EntrySourceType::RECORDED_LIVE) {
         KalturaLog::notice("Entry [" . $entry->getId() . "] is not a recorded live");
         return;
     }
     $liveEntry = entryPeer::retrieveByPKNoFilter($entry->getRootEntryId());
     if (!$liveEntry || $liveEntry->getStatus() == entryStatus::DELETED || !$liveEntry instanceof LiveEntry) {
         KalturaLog::notice("Entry root [" . $entry->getRootEntryId() . "] is not a valid live entry");
         return;
     }
     /* @var $liveEntry LiveEntry */
     $pendingMediaEntries = $liveEntry->getAttachedPendingMediaEntries();
     foreach ($pendingMediaEntries as $pendingMediaEntry) {
         /* @var $pendingMediaEntry kPendingMediaEntry */
         if ($pendingMediaEntry->getRequiredDuration() && $pendingMediaEntry->getRequiredDuration() > $entry->getLengthInMsecs()) {
             KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] required duration [" . $pendingMediaEntry->getRequiredDuration() . "] while entry duration [" . $entry->getLengthInMsecs() . "] is too short");
             continue;
         }
         $liveEntry->dettachPendingMediaEntry($pendingMediaEntry->getEntryId());
         $pendingEntry = entryPeer::retrieveByPK($pendingMediaEntry->getEntryId());
         if (!$pendingEntry) {
             KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] not found");
             continue;
         }
         $sourceAsset = assetPeer::retrieveOriginalByEntryId($entry->getId());
         if (!$sourceAsset) {
             $sourceAssets = assetPeer::retrieveReadyFlavorsByEntryId($entry->getId());
             $sourceAsset = array_pop($sourceAssets);
         }
         if (!$sourceAsset) {
             KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] source asset not found");
             continue;
         }
         /* @var $sourceAsset flavorAsset */
         $operationAttributes = new kClipAttributes();
         $operationAttributes->setOffset($pendingMediaEntry->getOffset());
         $operationAttributes->setDuration($pendingMediaEntry->getDuration());
         $targetAsset = assetPeer::retrieveOriginalByEntryId($pendingMediaEntry->getEntryId());
         if (!$targetAsset) {
             $targetAsset = kFlowHelper::createOriginalFlavorAsset($entry->getPartnerId(), $pendingMediaEntry->getEntryId());
         }
         $targetAsset->setFileExt($sourceAsset->getFileExt());
         $targetAsset->save();
         $sourceSyncKey = $sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         $targetSyncKey = $targetAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         kFileSyncUtils::createSyncFileLinkForKey($targetSyncKey, $sourceSyncKey);
         $errDescription = '';
         kBusinessPreConvertDL::decideAddEntryFlavor(null, $pendingMediaEntry->getEntryId(), $operationAttributes->getAssetParamsId(), $errDescription, $targetAsset->getId(), array($operationAttributes));
     }
     $liveEntry->save();
 }
コード例 #7
0
    public function operate(kOperator $operator = null, $inFilePath, $configFilePath = null)
    {
        KalturaLog::debug("document : operator [" . print_r($operator, true) . "] inFilePath [{$inFilePath}]");
        if ($configFilePath) {
            $configFilePath = realpath($configFilePath);
        }
        // bypassing PDF Creator for source PDF files
        $inputExtension = strtolower(pathinfo($inFilePath, PATHINFO_EXTENSION));
        if ($inputExtension == 'pdf' && !$this->data->flavorParamsOutput->readonly) {
            KalturaLog::notice('Bypassing PDF Creator for source PDF files');
            if (!@copy($inFilePath, $this->outFilePath)) {
                $error = '';
                if (function_exists('error_get_last')) {
                    $error = error_get_last();
                }
                throw new KOperationEngineException('Cannot copy PDF file [' . $this->inFilePath . '] to [' . $this->outFilePath . '] - [' . $error . ']');
            } else {
                // PDF input file copied as is to output file
                return true;
            }
        }
        // renaming with unique name to allow conversion 2 conversions of same input file to be done together (PDF+SWF)
        $tmpUniqInFilePath = dirname($inFilePath) . '/' . uniqid() . '_' . basename($inFilePath);
        $realInFilePath = '';
        $uniqueName = false;
        if (@copy($inFilePath, $tmpUniqInFilePath)) {
            $realInFilePath = realpath($tmpUniqInFilePath);
            $uniqueName = true;
        } else {
            KalturaLog::notice('Could not rename input file [' . $inFilePath . '] with a unique name [' . $tmpUniqInFilePath . ']');
            $realInFilePath = realpath($inFilePath);
        }
        $filePrefix = file_get_contents($realInFilePath, false, null, 0, strlen(self::OLD_OFFICE_SIGNATURE));
        $path_info = pathinfo($realInFilePath);
        $ext = $path_info['extension'];
        $newOfficeExtensions = array('pptx', 'docx', 'xlsx');
        $ext = strtolower($ext);
        //checks if $realInFilePath is an old office document with a new extension ('pptx|docx|xlsx')
        //if $realInFilePath is not the fileSync itself ($uniqueName = true) , rename the file by removing the 'x' from the extension.
        if ($uniqueName && in_array($ext, $newOfficeExtensions) && $filePrefix == self::OLD_OFFICE_SIGNATURE) {
            $RealInFilePathWithoutX = substr($realInFilePath, 0, -1);
            if (rename($realInFilePath, $RealInFilePathWithoutX)) {
                KalturaLog::notice("renamed file [{$realInFilePath}] to [{$RealInFilePathWithoutX}]");
                $realInFilePath = $RealInFilePathWithoutX;
            }
        }
        $finalOutputPath = $this->outFilePath;
        if ($inputExtension == 'pdf' && $this->data->flavorParamsOutput->readonly == true) {
            $tmpFile = $this->outFilePath . '.pdf';
        } else {
            $tmpFile = kFile::replaceExt(basename($realInFilePath), 'pdf');
            $tmpFile = dirname($this->outFilePath) . '/' . $tmpFile;
        }
        $this->outFilePath = $tmpFile;
        // Create popups log file
        $killPopupsPath = $this->getKillPopupsPath();
        if (file_exists($killPopupsPath)) {
            unlink($killPopupsPath);
        }
        // Test file type
        $errorMsg = $this->checkFileType($realInFilePath, $this->SUPPORTED_FILE_TYPES);
        if (!is_null($errorMsg)) {
            $this->data->engineMessage = $errorMsg;
        }
        parent::operate($operator, $realInFilePath, $configFilePath);
        $this->outFilePath = $finalOutputPath;
        if ($uniqueName) {
            @unlink($tmpUniqInFilePath);
        }
        $sleepTimes = KBatchBase::$taskConfig->fileExistReties;
        if (!$sleepTimes) {
            $sleepTimes = self::DEFAULT_SLEEP_TIMES;
        }
        $sleepSeconds = KBatchBase::$taskConfig->fileExistInterval;
        if (!$sleepSeconds) {
            $sleepSeconds = self::DEFAULT_SLEEP_SECONDS;
        }
        // sleeping while file not ready, since PDFCreator exists a bit before the file is actually ready
        while (!file_exists(realpath($tmpFile)) && $sleepTimes > 0) {
            sleep($sleepSeconds);
            $sleepTimes--;
            clearstatcache();
        }
        // Read popup log file
        if (file_exists($killPopupsPath)) {
            $data = file_get_contents($killPopupsPath);
            $data = trim($data);
            if (!empty($data)) {
                KalturaLog::notice("Convert popups warnings - " . $data);
                if (is_null($this->message)) {
                    $this->message = $data;
                } else {
                    $this->message .= $data;
                }
            }
            unlink($killPopupsPath);
        }
        if (!file_exists(realpath($tmpFile))) {
            throw new kTemporaryException('Temp PDF Creator file not found [' . $tmpFile . '] output file [' . $this->outFilePath . '] 
					Convert Engine message [' . $this->message . ']');
        } else {
            KalturaLog::notice('document temp  found [' . $tmpFile . '] output file [' . $this->outFilePath . ']');
        }
        $this->validateOutput($inFilePath, realpath($tmpFile));
        $fileUnlockRetries = KBatchBase::$taskConfig->params->fileUnlockRetries;
        if (!$fileUnlockRetries) {
            $fileUnlockRetries = self::DEFAULT_FILE_UNLOCK_RETRIES;
        }
        $fileUnlockInterval = KBatchBase::$taskConfig->params->fileUnlockInterval;
        if (!$fileUnlockInterval) {
            $fileUnlockInterval = self::DEFAULT_FILE_UNLOCK_INTERVAL;
        }
        $tmpFile = realpath($tmpFile);
        while (!rename($tmpFile, $this->outFilePath) && $fileUnlockRetries > 0) {
            sleep($fileUnlockInterval);
            $fileUnlockRetries--;
            clearstatcache();
        }
        if (!file_exists($this->outFilePath)) {
            $error = '';
            if (function_exists('error_get_last')) {
                $error = error_get_last();
            }
            throw new KOperationEngineException('Cannot rename file [' . $tmpFile . '] to [' . $this->outFilePath . '] - [' . $error . ']');
        }
        return true;
    }
 /**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @param bool $submitWhenReady
  * @return BatchJob
  */
 public static function submitAddEntryDistribution(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile, $submitWhenReady = true)
 {
     if ($distributionProfile->getStatus() != DistributionProfileStatus::ENABLED || $distributionProfile->getSubmitEnabled() == DistributionProfileActionStatus::DISABLED) {
         KalturaLog::debug("Submission is not enabled");
         return null;
     }
     $validStatus = array(EntryDistributionStatus::ERROR_DELETING, EntryDistributionStatus::ERROR_SUBMITTING, EntryDistributionStatus::ERROR_UPDATING, EntryDistributionStatus::IMPORT_SUBMITTING, EntryDistributionStatus::PENDING, EntryDistributionStatus::QUEUED, EntryDistributionStatus::READY, EntryDistributionStatus::REMOVED);
     if (!in_array($entryDistribution->getStatus(), $validStatus)) {
         KalturaLog::notice("Wrong entry distribution status [" . $entryDistribution->getStatus() . "]");
         return null;
     }
     $returnValue = false;
     $validationErrors = $entryDistribution->getValidationErrors();
     if (!count($validationErrors)) {
         KalturaLog::debug("No validation errors found");
         $returnValue = true;
         $sunrise = $entryDistribution->getSunrise(null);
         if ($sunrise) {
             KalturaLog::debug("Applying sunrise [{$sunrise}]");
             $distributionProvider = $distributionProfile->getProvider();
             if (!$distributionProvider->isScheduleUpdateEnabled() && !$distributionProvider->isAvailabilityUpdateEnabled()) {
                 $sunrise -= $distributionProvider->getJobIntervalBeforeSunrise();
                 if ($sunrise > time()) {
                     KalturaLog::log("Will be sent on exact time [{$sunrise}] for sunrise time [" . $entryDistribution->getSunrise() . "]");
                     $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::SUBMIT_REQUIRED);
                     $entryDistribution->save();
                     $returnValue = null;
                 }
             }
         }
         if ($returnValue) {
             $returnValue = self::addSubmitAddJob($entryDistribution, $distributionProfile);
         }
     }
     if (!$returnValue && $submitWhenReady && $entryDistribution->getStatus() != EntryDistributionStatus::QUEUED) {
         $entryDistribution->setStatus(EntryDistributionStatus::QUEUED);
         $entryDistribution->save();
         KalturaLog::debug("Will be submitted when ready");
     }
     if (!count($validationErrors)) {
         return $returnValue;
     }
     KalturaLog::log("Validation errors found");
     $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId());
     if (!$entry) {
         KalturaLog::err("Entry [" . $entryDistribution->getEntryId() . "] not found");
         return null;
     }
     $autoCreateFlavors = $distributionProfile->getAutoCreateFlavorsArray();
     $autoCreateThumbs = $distributionProfile->getAutoCreateThumbArray();
     foreach ($validationErrors as $validationError) {
         if ($validationError->getErrorType() == DistributionErrorType::MISSING_FLAVOR && in_array($validationError->getData(), $autoCreateFlavors)) {
             $errDescription = null;
             KalturaLog::log("Adding flavor [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]");
             kBusinessPreConvertDL::decideAddEntryFlavor(null, $entryDistribution->getEntryId(), $validationError->getData(), $errDescription);
             if ($errDescription) {
                 KalturaLog::log($errDescription);
             }
         }
         if ($validationError->getErrorType() == DistributionErrorType::MISSING_THUMBNAIL && count($autoCreateThumbs)) {
             list($requiredWidth, $requiredHeight) = explode('x', $validationError->getData());
             $foundThumbParams = false;
             $thumbParamsObjects = assetParamsPeer::retrieveByPKs($autoCreateThumbs);
             foreach ($thumbParamsObjects as $thumbParams) {
                 /* @var $thumbParams thumbParams */
                 if ($thumbParams->getWidth() == intval($requiredWidth) && $thumbParams->getHeight() == intval($requiredHeight)) {
                     $foundThumbParams = true;
                     KalturaLog::log("Adding thumbnail [" . $thumbParams->getId() . "] to entry [" . $entryDistribution->getEntryId() . "]");
                     kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams);
                     break;
                 }
             }
             if (!$foundThumbParams) {
                 KalturaLog::err("Required thumbnail params not found [" . $validationError->getData() . "]");
             }
         }
     }
     return null;
 }
コード例 #9
0
ファイル: kFlowHelper.php プロジェクト: richhl/kalturaCE
 /**
  * @param BatchJob $parentJob
  * @param int $srcParamsId
  */
 public static function generateThumbnailsFromFlavor($entryId, BatchJob $parentJob = null, $srcParamsId = null)
 {
     $profile = null;
     try {
         $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     } catch (Exception $e) {
         KalturaLog::err('getConversionProfile2ForEntry Error: ' . $e->getMessage());
     }
     if (!$profile) {
         KalturaLog::notice("Profile not found for entry id [{$entryId}]");
         return;
     }
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         KalturaLog::notice("Entry id [{$entryId}] not found");
         return;
     }
     $assetParamsIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($profile->getId());
     if (!count($assetParamsIds)) {
         KalturaLog::notice("No asset params objects found for profile id [" . $profile->getId() . "]");
         return;
     }
     // the alternative is the source or the highest bitrate if source not defined
     $alternateFlavorParamsId = null;
     if (is_null($srcParamsId)) {
         $flavorParamsObjects = flavorParamsPeer::retrieveByPKs($assetParamsIds);
         foreach ($flavorParamsObjects as $flavorParams) {
             if ($flavorParams->hasTag(flavorParams::TAG_SOURCE)) {
                 $alternateFlavorParamsId = $flavorParams->getId();
             }
         }
         if (is_null($alternateFlavorParamsId)) {
             $srcFlavorAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entryId);
             $alternateFlavorParamsId = $srcFlavorAsset->getFlavorParamsId();
         }
         if (is_null($alternateFlavorParamsId)) {
             KalturaLog::notice("No source flavor params object found for entry id [{$entryId}]");
             return;
         }
     }
     // create list of created thumbnails
     $thumbAssetsList = array();
     $thumbAssets = thumbAssetPeer::retrieveByEntryId($entryId);
     if (count($thumbAssets)) {
         foreach ($thumbAssets as $thumbAsset) {
             if (!is_null($thumbAsset->getFlavorParamsId())) {
                 $thumbAssetsList[$thumbAsset->getFlavorParamsId()] = $thumbAsset;
             }
         }
     }
     $thumbParamsObjects = thumbParamsPeer::retrieveByPKs($assetParamsIds);
     foreach ($thumbParamsObjects as $thumbParams) {
         // check if this thumbnail already created
         if (isset($thumbAssetsList[$thumbParams->getId()])) {
             continue;
         }
         if (is_null($srcParamsId) && is_null($thumbParams->getSourceParamsId())) {
             // alternative should be used
             $thumbParams->setSourceParamsId($alternateFlavorParamsId);
         } elseif ($thumbParams->getSourceParamsId() != $srcParamsId) {
             // only thumbnails that uses srcParamsId should be generated for now
             continue;
         }
         kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams, $parentJob);
     }
 }
コード例 #10
0
 $new_login_data = new UserLoginData();
 $partner = PartnerPeer::retrieveByPK($user->getPartnerId());
 if (!$partner) {
     KalturaLog::alert('!!! ERROR - Partner ID [' . $user->getPartnerId() . '] not found on DB but set for admin user id [' . $lastUser . '] !!!');
     echo '!!! ERROR - Partner ID [' . $user->getPartnerId() . '] not found on DB but set for admin user id [' . $lastUser . '] !!!';
     continue;
 }
 list($firstName, $lastName) = kString::nameSplit($user->getFullName());
 $c = new Criteria();
 $c->addAnd(UserLoginDataPeer::LOGIN_EMAIL, $user->getEmail());
 $existing_login_data = UserLoginDataPeer::doSelectOne($c);
 if ($existing_login_data) {
     if ($user->getPartnerId() === $existing_login_data->getConfigPartnerId()) {
         $checkKuser = kuserPeer::getByLoginDataAndPartner($existing_login_data->getId(), $user->getPartnerId());
         if ($checkKuser && $checkKuser->getIsAdmin()) {
             KalturaLog::notice('!!! NOTICE - Existing ADMIN login data found with id [' . $existing_login_data->getId() . '] partner [' . $existing_login_data->getConfigPartnerId() . '] - skipping user id [' . $lastUser . '] of partner [' . $user->getPartnerId() . '] since this was probably caused by a bug');
             echo '!!! NOTICE - Existing ADMIN login data found with id [' . $existing_login_data->getId() . '] partner [' . $existing_login_data->getConfigPartnerId() . '] - skipping user id [' . $lastUser . '] of partner [' . $user->getPartnerId() . '] since this was probably caused by a bug';
             continue;
         }
     }
     KalturaLog::alert('!!! ERROR - Existing login data found with id [' . $existing_login_data->getId() . '] partner [' . $existing_login_data->getConfigPartnerId() . '] - skipping user id [' . $lastUser . '] of partner [' . $user->getPartnerId() . '] !!!!');
     echo '!!! ERROR - Existing login data found with id [' . $existing_login_data->getId() . '] partner [' . $existing_login_data->getConfigPartnerId() . '] - skipping user id [' . $lastUser . '] of partner [' . $user->getPartnerId() . '] !!!!';
     continue;
 }
 $new_login_data->setConfigPartnerId($user->getPartnerId());
 $new_login_data->setLoginEmail($user->getEmail());
 $new_login_data->setFirstName($firstName);
 $new_login_data->setLastName($lastName);
 $new_login_data->setSalt($user->getSalt());
 $new_login_data->setSha1Password($user->getSha1Password());
 $new_login_data->setCreatedAt($user->getCreatedAt());
 /**
  * Function which creates KalturaCategoryEntry objects for the entry which was added 
  * via the bulk upload CSV.
  * @param string $entryId
  * @param string $categories
  * @param KalturaBulkUploadResultEntry $bulkuploadResult
  */
 private function createCategoryAssociations($entryId, $categories, KalturaBulkUploadResultEntry $bulkuploadResult)
 {
     if (!$categories) {
         // skip this prcoess if no categories are present
         KalturaLog::notice("No categories found for entry ID [{$entryId}], skipping association creating");
         return;
     }
     $this->impersonate();
     $categoriesArr = explode(",", $categories);
     $ret = array();
     foreach ($categoriesArr as $categoryName) {
         $categoryFilter = new KalturaCategoryFilter();
         $categoryFilter->fullNameEqual = $categoryName;
         $res = $this->kClient->category->listAction($categoryFilter, new KalturaFilterPager());
         if (!count($res->objects)) {
             $res = $this->createCategoryByPath($categoryName);
             if (!$res instanceof KalturaCategory) {
                 $bulkuploadResult->errorDescription .= $res;
                 continue;
             }
             $category = $res;
         } else {
             $category = $res->objects[0];
         }
         $categoryEntry = new KalturaCategoryEntry();
         $categoryEntry->categoryId = $category->id;
         $categoryEntry->entryId = $entryId;
         try {
             $this->kClient->categoryEntry->add($categoryEntry);
         } catch (Exception $e) {
             $bulkuploadResult->errorDescription .= $e->getMessage();
         }
     }
     $this->unimpersonate();
     return;
 }
コード例 #12
0
 public function run($jobs = null)
 {
     KalturaLog::notice("Convert collection batch is running");
     return parent::run($jobs);
 }
コード例 #13
0
ファイル: kFlowHelper.php プロジェクト: GElkayam/server
 /**
  * @param BatchJob $dbBatchJob
  * @param kStorageExportJobData $data
  * @return BatchJob
  */
 public static function handleStorageExportFailed(BatchJob $dbBatchJob, kStorageExportJobData $data)
 {
     if ($dbBatchJob->getErrType() == BatchJobErrorTypes::APP && $dbBatchJob->getErrNumber() == BatchJobAppErrors::FILE_ALREADY_EXISTS) {
         KalturaLog::notice("remote file already exists");
         return $dbBatchJob;
     }
     $fileSync = FileSyncPeer::retrieveByPK($data->getSrcFileSyncId());
     if (!$fileSync) {
         KalturaLog::err("FileSync [" . $data->getSrcFileSyncId() . "] not found");
         return $dbBatchJob;
     }
     $fileSync->setStatus(FileSync::FILE_SYNC_STATUS_ERROR);
     $fileSync->save();
     // if an asset was exported - check if should set its status to ERROR
     $asset = assetPeer::retrieveByFileSync($fileSync);
     if ($asset && $asset->getStatus() == asset::ASSET_STATUS_EXPORTING) {
         $asset->setStatus(asset::ASSET_STATUS_ERROR);
         $asset->save();
         if ($asset instanceof flavorAsset) {
             $flavorParamsOutput = $asset->getFlavorParamsOutput();
             $flavorParamsOutputId = $flavorParamsOutput ? $flavorParamsOutput->getId() : null;
             $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($asset->getId());
             $mediaInfoId = $mediaInfo ? $mediaInfo->getId() : null;
             kBusinessPostConvertDL::handleConvertFailed($dbBatchJob, null, $asset->getId(), $flavorParamsOutputId, $mediaInfoId);
         }
     }
     return $dbBatchJob;
 }
コード例 #14
0
                    $partner->setAlwaysAllowedPermissionNames($currentPerms);
                    $partner->save();
                }
                // check if partner group is set for the action
                $partnerGroup = $serviceConfig->getPartnerGroup();
                if ($partnerGroup) {
                    // partner group is set - add a special partner group permission to all relevant partners and add current permission item to it
                    $partnerGroupPermission = getOrCreatePartnerGroupPermission($partner->getId(), $partnerGroup);
                    $partnerGroupPermission->addPermissionItem($permissionItem->getId(), true);
                }
            }
        }
    }
}
$msg = 'Done!';
KalturaLog::notice($msg);
echo $msg . PHP_EOL;
// -- helper functions ------------------------------------------
/**
 * Return all partners with $file set as their SERVICE_CONFIG_ID
 * @param string $file file name
 * @return array of Partner objects
 */
function getPartners($file)
{
    $file = substr($file, 3);
    PartnerPeer::clearInstancePool();
    $c = new Criteria();
    $c->addAnd(PartnerPeer::SERVICE_CONFIG_ID, $file, Criteria::EQUAL);
    $partners = PartnerPeer::doSelect($c);
    return $partners;
コード例 #15
0
ファイル: KBulkUploadEngine.php プロジェクト: DBezemer/server
 /**
  * 
  * Gets the start line number for the given job id
  * @return int - the start line for the job id
  */
 protected function getStartIndex()
 {
     try {
         $result = KBatchBase::$kClient->batch->getBulkUploadLastResult($this->job->id);
         if ($result) {
             return $result->lineIndex;
         }
     } catch (Exception $e) {
         KalturaLog::notice("getBulkUploadLastResult: " . $e->getMessage());
     }
     return 0;
 }
コード例 #16
0
ファイル: testLibSec.php プロジェクト: DBezemer/server
        } catch (Exception $e) {
            KalturaLog::err("Import Batch Job [{$batchJobPartnerId}::{$batchJobId}] login failed: " . $e->getMessage());
            if (file_exists($publicKeyFile)) {
                unlink($publicKeyFile);
            }
            if (file_exists($privateKeyFile)) {
                unlink($privateKeyFile);
            }
            continue;
        }
        try {
            $fileExists = $sftp->fileExists($remotePath);
            if (!$fileExists) {
                KalturaLog::err("Import Batch Job [{$batchJobPartnerId}::{$batchJobId}] remote file [{$remotePath}] does not exist");
                continue;
            }
        } catch (Exception $e) {
            KalturaLog::err("Import Batch Job [{$batchJobPartnerId}::{$batchJobId}] remote file [{$remotePath}] existance check failed: " . $e->getMessage());
            continue;
        }
        try {
            $fileSize = $sftp->fileSize($remotePath);
        } catch (Exception $e) {
            KalturaLog::err("Import Batch Job [{$batchJobPartnerId}::{$batchJobId}] remote file [{$remotePath}] size check failed: " . $e->getMessage());
            continue;
        }
        KalturaLog::notice("Import Batch Job [{$batchJobPartnerId}::{$batchJobId}] passed");
    }
    $batchJobCriteria->add(BatchJobPeer::ID, $batchJobId, Criteria::LESS_THAN);
}
KalturaLog::debug("Done");
コード例 #17
0
 /**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @param bool $submitWhenReady
  * @return BatchJob
  */
 public static function submitAddEntryDistribution(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile, $submitWhenReady = true)
 {
     if ($distributionProfile->getStatus() != DistributionProfileStatus::ENABLED || $distributionProfile->getSubmitEnabled() == DistributionProfileActionStatus::DISABLED) {
         return null;
     }
     $validStatus = array(EntryDistributionStatus::ERROR_DELETING, EntryDistributionStatus::ERROR_SUBMITTING, EntryDistributionStatus::ERROR_UPDATING, EntryDistributionStatus::PENDING, EntryDistributionStatus::QUEUED, EntryDistributionStatus::READY, EntryDistributionStatus::REMOVED);
     if (!in_array($entryDistribution->getStatus(), $validStatus)) {
         KalturaLog::notice("wrong entry distribution status [" . $entryDistribution->getStatus() . "]");
         return null;
     }
     if ($submitWhenReady && $entryDistribution->getStatus() != EntryDistributionStatus::QUEUED) {
         $entryDistribution->setStatus(EntryDistributionStatus::QUEUED);
         $entryDistribution->save();
     }
     $validationErrors = $entryDistribution->getValidationErrors();
     if (!count($validationErrors)) {
         $sunrise = $entryDistribution->getSunrise(null);
         if ($sunrise) {
             $distributionProvider = $distributionProfile->getProvider();
             if (!$distributionProvider->isScheduleUpdateEnabled() && !$distributionProvider->isAvailabilityUpdateEnabled()) {
                 $sunrise -= $distributionProvider->getJobIntervalBeforeSunrise();
                 if ($sunrise > time()) {
                     KalturaLog::log("Will be sent on exact time [{$sunrise}] for sunrise time [" . $entryDistribution->getSunrise() . "]");
                     $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::SUBMIT_REQUIRED);
                     $entryDistribution->save();
                     return null;
                 }
             }
         }
         return self::addSubmitAddJob($entryDistribution, $distributionProfile);
     }
     KalturaLog::log("Validation errors found");
     $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId());
     if (!$entry) {
         KalturaLog::err("Entry [" . $entryDistribution->getEntryId() . "] not found");
         return null;
     }
     $autoCreateFlavors = $distributionProfile->getAutoCreateFlavorsArray();
     $autoCreateThumbs = $distributionProfile->getAutoCreateThumbArray();
     foreach ($validationErrors as $validationError) {
         if ($validationError->getErrorType() == DistributionErrorType::MISSING_FLAVOR && in_array($validationError->getData(), $autoCreateFlavors)) {
             $errDescription = null;
             KalturaLog::log("Adding flavor [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]");
             kBusinessPreConvertDL::decideAddEntryFlavor(null, $entryDistribution->getEntryId(), $validationError->getData(), $errDescription);
             if ($errDescription) {
                 KalturaLog::log($errDescription);
             }
         }
         if ($validationError->getErrorType() == DistributionErrorType::MISSING_THUMBNAIL && in_array($validationError->getData(), $autoCreateThumbs)) {
             $destThumbParams = thumbParamsPeer::retrieveByPK($validationError->getData());
             if ($destThumbParams) {
                 KalturaLog::log("Adding thumbnail [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]");
                 kBusinessPreConvertDL::decideThumbGenerate($entry, $destThumbParams);
             } else {
                 KalturaLog::err("Required thumbnail params not found [" . $validationError->getData() . "]");
             }
         }
     }
     return null;
 }
コード例 #18
0
ファイル: Permission.php プロジェクト: AdiTal/server
 /**
  * Remove the given permission item from the current permission
  * @param int $permissionItemId
  */
 public function removePermissionItem($permissionItemId)
 {
     // check if item is already associated to the permission
     $itemIds = $this->getPermissionItemIds();
     if (!in_array($permissionItemId, $itemIds)) {
         KalturaLog::notice('Permission with name [' . $this->getName() . '] does not contain permission item with id [' . $permissionItemId . ']');
         return true;
     }
     unset($this->permissionItemIds[$permissionItemId]);
     $this->permissionItemIdsChanged = true;
 }
コード例 #19
0
ファイル: kJobsManager.php プロジェクト: ace3535/server
 /**
  * @param BatchJob $batchJob
  * @param entry $entry
  * @param string $flavorAssetId
  * @param string $inputFileSyncLocalPath
  * @return BatchJob
  */
 public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath)
 {
     KalturaLog::debug("Parent job [" . ($parentJob ? $parentJob->getId() : 'none') . "] entry [" . $entry->getId() . "] flavor asset [{$flavorAssetId}] input file [{$inputFileSyncLocalPath}]");
     if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) {
         $entry->setStatus(entryStatus::PENDING);
         $entry->save();
         KalturaLog::notice('Entry should not be converted');
         return null;
     }
     $importingSources = false;
     // if file size is 0, do not create conversion profile and set entry status as error converting
     if (!file_exists($inputFileSyncLocalPath) || kFile::fileSize($inputFileSyncLocalPath) == 0) {
         KalturaLog::debug("Input file [{$inputFileSyncLocalPath}] does not exist");
         $partner = $entry->getPartner();
         $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entry->getId());
         // load the asset params to the instance pool
         $flavorIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfile->getId());
         assetParamsPeer::retrieveByPKs($flavorIds);
         $conversionRequired = false;
         $sourceFileRequiredStorages = array();
         $sourceIncludedInProfile = false;
         $flavorAsset = assetPeer::retrieveById($flavorAssetId);
         $flavors = flavorParamsConversionProfilePeer::retrieveByConversionProfile($conversionProfile->getId());
         KalturaLog::debug("Found flavors [" . count($flavors) . "] in conversion profile [" . $conversionProfile->getId() . "]");
         foreach ($flavors as $flavor) {
             /* @var $flavor flavorParamsConversionProfile */
             if ($flavor->getFlavorParamsId() == $flavorAsset->getFlavorParamsId()) {
                 KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] is ingested source");
                 $sourceIncludedInProfile = true;
                 continue;
             }
             $flavorParams = assetParamsPeer::retrieveByPK($flavor->getFlavorParamsId());
             if ($flavorParams instanceof liveParams || $flavor->getOrigin() == assetParamsOrigin::INGEST) {
                 KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] should be ingested");
                 continue;
             }
             if ($flavor->getOrigin() == assetParamsOrigin::CONVERT_WHEN_MISSING) {
                 $siblingFlavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor->getFlavorParamsId());
                 if ($siblingFlavorAsset) {
                     KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] already ingested");
                     continue;
                 }
             }
             $sourceFileRequiredStorages[] = $flavorParams->getSourceRemoteStorageProfileId();
             $conversionRequired = true;
             break;
         }
         if ($conversionRequired) {
             foreach ($sourceFileRequiredStorages as $storageId) {
                 if ($storageId == StorageProfile::STORAGE_KALTURA_DC) {
                     $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     list($syncFile, $local) = kFileSyncUtils::getReadyFileSyncForKey($key, true, false);
                     if ($syncFile && $syncFile->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL && $partner && $partner->getImportRemoteSourceForConvert()) {
                         KalturaLog::debug("Creates import job for remote file sync");
                         $url = $syncFile->getExternalUrl($entry->getId());
                         kJobsManager::addImportJob($parentJob, $entry->getId(), $partner->getId(), $url, $flavorAsset, null, null, true);
                         $importingSources = true;
                         continue;
                     }
                 } elseif ($flavorAsset->getExternalUrl($storageId)) {
                     continue;
                 }
                 kBatchManager::updateEntry($entry->getId(), entryStatus::ERROR_CONVERTING);
                 $flavorAsset = assetPeer::retrieveById($flavorAssetId);
                 $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                 $flavorAsset->setDescription('Entry of size 0 should not be converted');
                 $flavorAsset->save();
                 KalturaLog::err('Entry of size 0 should not be converted');
                 return null;
             }
         } else {
             if ($flavorAsset->getStatus() == asset::FLAVOR_ASSET_STATUS_QUEUED) {
                 if ($sourceIncludedInProfile) {
                     $flavorAsset->setStatusLocalReady();
                 } else {
                     $flavorAsset->setStatus(asset::FLAVOR_ASSET_STATUS_DELETED);
                     $flavorAsset->setDeletedAt(time());
                 }
                 $flavorAsset->save();
                 if ($sourceIncludedInProfile) {
                     kBusinessPostConvertDL::handleConvertFinished(null, $flavorAsset);
                 }
             }
             return null;
         }
     }
     if ($entry->getStatus() != entryStatus::READY) {
         $entry->setStatus(entryStatus::PRECONVERT);
     }
     $jobData = new kConvertProfileJobData();
     $jobData->setFlavorAssetId($flavorAssetId);
     $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath);
     $jobData->setExtractMedia(true);
     if ($entry->getType() != entryType::MEDIA_CLIP) {
         $jobData->setExtractMedia(false);
         $entry->setCreateThumb(false);
     }
     $entry->save();
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::CONVERT_PROFILE);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entry->getId());
         $batchJob->setPartnerId($entry->getPartnerId());
         $batchJob->setUseNewRoot(true);
     }
     $batchJob->setObjectId($entry->getId());
     $batchJob->setObjectType(BatchJobObjectType::ENTRY);
     if ($importingSources) {
         $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     }
     return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE);
 }
コード例 #20
0
 public function getFieldValue(kScope $scope)
 {
     $profileId = $this->profileId;
     if (!$profileId) {
         if (!$this->profileSystemName) {
             KalturaLog::err("No metadata profile id and system-name supplied");
             return null;
         }
         $profile = MetadataProfilePeer::retrieveBySystemName($this->profileSystemName, kCurrentContext::getCurrentPartnerId());
         if (!$profile) {
             KalturaLog::notice("Metadata profile with system-name [{$this->profileSystemName}] not found");
             return null;
         }
         $profileId = $profile->getId();
     }
     $metadata = null;
     if ($scope instanceof accessControlScope || $scope instanceof kStorageProfileScope) {
         $metadata = MetadataPeer::retrieveByObject($profileId, MetadataObjectType::ENTRY, $scope->getEntryId());
     } elseif ($scope instanceof kEventScope) {
         $object = $scope->getEvent()->getObject();
         if (kMetadataManager::isMetadataObject($object)) {
             $objectType = kMetadataManager::getTypeNameFromObject($object);
             $metadata = MetadataPeer::retrieveByObject($profileId, $objectType, $object->getId());
         } else {
             if ($object instanceof Metadata) {
                 $metadata = $object;
             } elseif ($scope->getEvent()->getObject() instanceof categoryEntry) {
                 $profileObject = kMetadataManager::getObjectTypeName($profile->getObjectType());
                 $getter = "get{$profileObject}Id";
                 KalturaLog::info("Using {$getter} in order to retrieve the metadata object ID");
                 $categoryEntry = $scope->getEvent()->getObject();
                 $objectId = $categoryEntry->{$getter}();
                 $metadata = MetadataPeer::retrieveByObject($profileId, $profile->getObjectType(), $objectId);
             } elseif ($object instanceof asset) {
                 $metadata = MetadataPeer::retrieveByObject($profileId, MetadataObjectType::ENTRY, $object->getEntryId());
             }
         }
     }
     if ($metadata) {
         return kMetadataManager::parseMetadataValues($metadata, $this->xPath);
     }
     KalturaLog::notice("Metadata object not found for scope [" . get_class($scope) . "]");
     return null;
 }
コード例 #21
0
ファイル: KalturaEntryService.php プロジェクト: AdiTal/server
 /**
  * General code that replaces given entry resource with a given resource, and mark the original
  * entry as replaced
  * @param KalturaEntry $dbEntry The original entry we'd like to replace
  * @param KalturaResource $resource The resource we'd like to attach
  * @param KalturaEntry $tempMediaEntry The replacing entry
  * @throws KalturaAPIException
  */
 protected function replaceResourceByEntry($dbEntry, $resource, $tempMediaEntry)
 {
     $partner = $this->getPartner();
     if (!$partner->getEnabledService(PermissionName::FEATURE_ENTRY_REPLACEMENT)) {
         KalturaLog::notice("Replacement is not allowed to the partner permission [FEATURE_ENTRY_REPLACEMENT] is needed");
         throw new KalturaAPIException(KalturaErrors::FEATURE_FORBIDDEN, PermissionName::FEATURE_ENTRY_REPLACEMENT);
     }
     if ($dbEntry->getReplacingEntryId()) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_REPLACEMENT_ALREADY_EXISTS);
     }
     $resource->validateEntry($dbEntry);
     $tempDbEntry = $this->prepareEntryForInsert($tempMediaEntry);
     $tempDbEntry->setDisplayInSearch(mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM);
     $tempDbEntry->setPartnerId($dbEntry->getPartnerId());
     $tempDbEntry->setReplacedEntryId($dbEntry->getId());
     $tempDbEntry->setIsTemporary(true);
     $tempDbEntry->save();
     $dbEntry->setReplacingEntryId($tempDbEntry->getId());
     $dbEntry->setReplacementStatus(entryReplacementStatus::NOT_READY_AND_NOT_APPROVED);
     if (!$partner->getEnabledService(PermissionName::FEATURE_ENTRY_REPLACEMENT_APPROVAL)) {
         $dbEntry->setReplacementStatus(entryReplacementStatus::APPROVED_BUT_NOT_READY);
     }
     $dbEntry->save();
     $kResource = $resource->toObject();
     $this->attachResource($kResource, $tempDbEntry);
 }
コード例 #22
0
 /**
  * Add a partner group permission to the local map for the given action
  * @param array $map map to fill
  * @param Permission $permission partner group permission object
  */
 private static function addPartnerGroupAction(array &$map, Permission $permission)
 {
     $partnerGroup = $permission->getPartnerGroup();
     if (!$permission->getPartnerGroup()) {
         KalturaLog::notice('No partner group defined for permission id [' . $permission->getId() . '] with type partner group [' . $permission->getType() . ']');
         return;
     }
     $partnerGroup = explode(',', trim($partnerGroup, ','));
     $permissionItems = $permission->getPermissionItems();
     foreach ($permissionItems as $item) {
         if ($item->getType() != PermissionItemType::API_ACTION_ITEM) {
             KalturaLog::notice('Permission item id [' . $item->getId() . '] is not of type PermissionItemType::API_ACTION_ITEM but still defined in partner group permission id [' . $permission->getId() . ']');
             continue;
         }
         $service = strtolower($item->getService());
         $action = strtolower($item->getAction());
         if (!isset($map[self::PARTNER_GROUP_ARRAY_NAME][$service])) {
             $map[self::PARTNER_GROUP_ARRAY_NAME][$service] = array();
             $map[self::PARTNER_GROUP_ARRAY_NAME][$service][$action] = array();
         } else {
             if (!isset($map[self::PARTNER_GROUP_ARRAY_NAME][$service][$action])) {
                 $map[self::PARTNER_GROUP_ARRAY_NAME][$service][$action] = array();
             }
         }
         $map[self::PARTNER_GROUP_ARRAY_NAME][$service][$action] = array_merge($map[self::PARTNER_GROUP_ARRAY_NAME][$service][$action], $partnerGroup);
     }
 }
 /**
  * @param BatchJob $dbBatchJob
  * @param kImportJobData $data
  * @param BatchJob $twinJob
  * @return BatchJob
  */
 public static function onImportJobFinished(BatchJob $dbBatchJob, kImportJobData $data, BatchJob $twinJob = null)
 {
     $statuses = array(EntryDistributionStatus::IMPORT_SUBMITTING, EntryDistributionStatus::IMPORT_UPDATING);
     $entryDistributions = EntryDistributionPeer::retrieveByEntryAndStatuses($dbBatchJob->getEntryId(), $statuses);
     foreach ($entryDistributions as $entryDistribution) {
         /* @var $entryDistribution EntryDistribution */
         $distributionProfile = DistributionProfilePeer::retrieveByPK($entryDistribution->getDistributionProfileId());
         if ($entryDistribution->getStatus() == EntryDistributionStatus::IMPORT_SUBMITTING) {
             KalturaLog::notice("Submitting add entry distribution [" . $entryDistribution->getId() . "]");
             kContentDistributionManager::submitAddEntryDistribution($entryDistribution, $distributionProfile, true);
         } elseif ($entryDistribution->getStatus() == EntryDistributionStatus::IMPORT_UPDATING) {
             KalturaLog::notice("Submitting update entry distribution [" . $entryDistribution->getId() . "]");
             kContentDistributionManager::submitUpdateEntryDistribution($entryDistribution, $distributionProfile);
         }
     }
 }
コード例 #24
0
 public function operate(kOperator $operator = null, $inFilePath, $configFilePath = null)
 {
     KalturaLog::debug("document : operator [" . print_r($operator, true) . "] inFilePath [{$inFilePath}]");
     if ($configFilePath) {
         $configFilePath = realpath($configFilePath);
     }
     // bypassing PDF Creator for source PDF files
     $inputExtension = strtolower(pathinfo($inFilePath, PATHINFO_EXTENSION));
     if ($inputExtension == 'pdf' && !$this->flavorParamsOutput->readonly) {
         KalturaLog::notice('Bypassing PDF Creator for source PDF files');
         if (!@copy($inFilePath, $this->outFilePath)) {
             $error = '';
             if (function_exists('error_get_last')) {
                 $error = error_get_last();
             }
             throw new KOperationEngineException('Cannot copy PDF file [' . $this->inFilePath . '] to [' . $this->outFilePath . '] - [' . $error . ']');
         } else {
             // PDF input file copied as is to output file
             return;
         }
     }
     // renaming with unique name to allow conversion 2 conversions of same input file to be done together (PDF+SWF)
     $tmpUniqInFilePath = dirname($inFilePath) . '/' . uniqid() . '_' . basename($inFilePath);
     $realInFilePath = '';
     $uniqueName = false;
     if (@copy($inFilePath, $tmpUniqInFilePath)) {
         $realInFilePath = realpath($tmpUniqInFilePath);
         $uniqueName = true;
     } else {
         KalturaLog::notice('Could not rename input file [' . $inFilePath . '] with a unique name [' . $tmpUniqInFilePath . ']');
         $realInFilePath = realpath($inFilePath);
     }
     parent::operate($operator, $realInFilePath, $configFilePath);
     if ($uniqueName) {
         @unlink($tmpUniqInFilePath);
     }
     //TODO: RENAME - will not be needed once PDFCreator can work with a configurations file
     if ($inputExtension == 'pdf' && $this->flavorParamsOutput->readonly == true) {
         $tmpFile = $this->outFilePath . '.pdf';
     } else {
         $tmpFile = kFile::replaceExt(basename($realInFilePath), 'pdf');
         $tmpFile = dirname($this->outFilePath) . '/' . $tmpFile;
     }
     // sleeping while file not ready, since PDFCreator exists a bit before the file is actually ready
     $sleepTimes = 50;
     $sleepSeconds = 3;
     while (!file_exists(realpath($tmpFile)) && $sleepTimes > 0) {
         sleep($sleepSeconds);
         $sleepTimes--;
         clearstatcache();
     }
     if (!file_exists(realpath($tmpFile))) {
         throw new kTemporaryException('Temp PDF Creator file not found [' . $tmpFile . '] output file [' . $this->outFilePath . ']');
     } else {
         KalturaLog::notice('document temp  found [' . $tmpFile . '] output file [' . $this->outFilePath . ']');
     }
     //TODO: RENAME - will not be needed once PDFCreator can work with a configurations file
     $tmpFile = realpath($tmpFile);
     while (!rename($tmpFile, $this->outFilePath) && $sleepTimes > 0) {
         sleep($sleepSeconds);
         $sleepTimes--;
         clearstatcache();
     }
     if (!file_exists($this->outFilePath)) {
         $error = '';
         if (function_exists('error_get_last')) {
             $error = error_get_last();
         }
         throw new KOperationEngineException('Cannot rename file [' . $tmpFile . '] to [' . $this->outFilePath . '] - [' . $error . ']');
     }
 }
コード例 #25
0
ファイル: kEventsManager.php プロジェクト: kubrickfr/server
 public static function raiseEvent(KalturaEvent $event)
 {
     if (self::$deferredEventsEnabled && self::$forceDeferredEvents) {
         return self::raiseEventDeferred($event);
     }
     $consumerInterface = $event->getConsumerInterface();
     $consumers = self::getConsumers($consumerInterface);
     foreach ($consumers as $consumerClass) {
         if (!class_exists($consumerClass)) {
             continue;
         }
         if ($event->consume(new $consumerClass()) || !$event instanceof IKalturaCancelableEvent) {
             continue;
         }
         KalturaLog::notice("Event [" . get_class($event) . "] paused by consumer [{$consumerClass}]");
         break;
     }
 }
コード例 #26
0
ファイル: kJobsManager.php プロジェクト: richhl/kalturaCE
 /**
  * @param BatchJob $batchJob
  * @param entry $entry
  * @param string $flavorAssetId
  * @param string $inputFileSyncLocalPath
  * @return BatchJob
  */
 public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath)
 {
     // if file size is 0, do not create conversion profile and set entry status as error converting
     if (filesize($inputFileSyncLocalPath) == 0) {
         $entry->setStatus(entryStatus::ERROR_CONVERTING);
         $entry->save();
         $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId);
         $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
         $flavorAsset->setDescription('Entry of size 0 should not be converted');
         $flavorAsset->save();
         KalturaLog::err('Entry of size 0 should not be converted');
         return null;
     }
     if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) {
         $entry->setStatus(entryStatus::PENDING);
         $entry->save();
         KalturaLog::notice('Entry should not be converted');
         return null;
     }
     if ($entry->getStatus() != entryStatus::READY) {
         $entry->setStatus(entryStatus::PRECONVERT);
         $entry->save();
     }
     $jobData = new kConvertProfileJobData();
     $jobData->setFlavorAssetId($flavorAssetId);
     $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath);
     $jobData->setExtractMedia(true);
     if ($entry->getType() != entryType::MEDIA_CLIP) {
         $jobData->setExtractMedia(false);
         $jobData->setCreateThumb(false);
     }
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild();
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entry->getId());
         $batchJob->setPartnerId($entry->getPartnerId());
     }
     return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE);
 }
コード例 #27
0
 /**
  * mark file as deleted, return deleted version
  * @param FileSyncKey $key
  * @param bool $strict
  * @param bool $fromKalturaDcsOnly
  * @return string
  */
 public static function deleteSyncFileForKey(FileSyncKey $key, $strict = false, $fromKalturaDcsOnly = false)
 {
     if (!$key) {
         if ($strict) {
             throw new Exception("Empty key");
         }
         return null;
     }
     //Retrieve all file sync for key
     $c = new Criteria();
     $c = FileSyncPeer::getCriteriaForFileSyncKey($key);
     if ($fromKalturaDcsOnly) {
         $c->add(FileSyncPeer::FILE_TYPE, FileSync::FILE_SYNC_FILE_TYPE_URL, Criteria::NOT_EQUAL);
     }
     $file_sync_list = FileSyncPeer::doSelect($c);
     foreach ($file_sync_list as $file_sync) {
         /* @var $fileSync FileSync */
         if ($file_sync->getLinkedId()) {
             $newStatus = FileSync::FILE_SYNC_STATUS_PURGED;
             self::decrementLinkCountForFileSync(FileSyncPeer::retrieveByPK($file_sync->getLinkedId()));
         } else {
             if ($file_sync->getLinkCount() == 0) {
                 $newStatus = FileSync::FILE_SYNC_STATUS_DELETED;
             } elseif ($file_sync->getLinkCount() > 100) {
                 KalturaLog::notice("The file sync [" . $file_sync->getId() . "] is associated with [" . $file_sync->getLinkCount() . "] links and won't be deleted");
                 return null;
             } else {
                 $newStatus = FileSync::FILE_SYNC_STATUS_PURGED;
                 self::convertLinksToFiles($file_sync);
             }
         }
         $file_sync->setStatus($newStatus);
         $file_sync->save();
     }
 }
コード例 #28
0
ファイル: KalturaObject.php プロジェクト: panigh/server
 public function loadRelatedObjects(KalturaDetachedResponseProfile $responseProfile)
 {
     $this->relatedObjects = new KalturaListResponseArray();
     foreach ($responseProfile->relatedProfiles as $relatedProfile) {
         /* @var $relatedProfile KalturaDetachedResponseProfile */
         if (!$relatedProfile->filter) {
             KalturaLog::notice("Related response-profile [{$relatedProfile->name}] has no filter and should not be used as nested profile");
             continue;
         }
         KalturaLog::debug("Loading related response-profile [{$relatedProfile->name}] with filter [" . get_class($relatedProfile->filter) . "]");
         $filter = clone $relatedProfile->filter;
         /* @var $filter KalturaRelatedFilter */
         if ($relatedProfile->mappings) {
             $applied = true;
             foreach ($relatedProfile->mappings as $mapping) {
                 /* @var $mapping KalturaResponseProfileMapping */
                 if (!$mapping->apply($filter, $this)) {
                     $applied = false;
                     break;
                 }
             }
             if (!$applied) {
                 KalturaLog::warning("Mappings could not be applied for response-profile [{$relatedProfile->name}]");
                 continue;
             }
         } else {
             KalturaLog::debug("No mappings defined in response-profile [{$relatedProfile->name}]");
         }
         $pager = $relatedProfile->pager;
         if (!$pager) {
             $pager = new KalturaFilterPager();
         }
         $this->relatedObjects[$relatedProfile->name] = $filter->getListResponse($pager, $relatedProfile);
     }
 }
コード例 #29
0
 private function killProcess()
 {
     KalturaLog::notice("About to kill process " . $this->processId);
     if ($this->processId) {
         if (function_exists('posix_kill')) {
             posix_kill($this->processId, 9);
         } else {
             // Make sure we kill the child process (the PHP)
             system("kill " . $this->processId, $rc);
         }
     }
 }
コード例 #30
0
 /**
  * @param KalturaResource $resource
  * @param entry $dbEntry
  * @param int $conversionProfileId
  */
 protected function replaceResource(KalturaResource $resource, entry $dbEntry, $conversionProfileId = null)
 {
     if (!$this->getPartner()->getWamsAccountName() || !$this->getPartner()->getWamsAccountKey()) {
         exit;
     }
     if ($dbEntry->getStatus() == KalturaEntryStatus::NO_CONTENT || $dbEntry->getMediaType() == KalturaMediaType::IMAGE) {
         $resource->validateEntry($dbEntry);
         if ($conversionProfileId) {
             $dbEntry->setConversionQuality($conversionProfileId);
             $dbEntry->save();
         }
         $kResource = $resource->toObject();
         $this->attachResource($kResource, $dbEntry);
     } else {
         $partner = $this->getPartner();
         if (!$partner->getEnabledService(PermissionName::FEATURE_ENTRY_REPLACEMENT)) {
             KalturaLog::notice("Replacement is not allowed to the partner permission [FEATURE_ENTRY_REPLACEMENT] is needed");
             throw new KalturaAPIException(KalturaErrors::FEATURE_FORBIDDEN, PermissionName::FEATURE_ENTRY_REPLACEMENT);
         }
         if ($dbEntry->getReplacingEntryId()) {
             throw new KalturaAPIException(KalturaErrors::ENTRY_REPLACEMENT_ALREADY_EXISTS);
         }
         $resource->validateEntry($dbEntry);
         $tempMediaEntry = new KalturaMediaEntry();
         $tempMediaEntry->type = $dbEntry->getType();
         $tempMediaEntry->mediaType = $dbEntry->getMediaType();
         $tempMediaEntry->conversionProfileId = $dbEntry->getConversionQuality();
         if ($conversionProfileId) {
             $tempMediaEntry->conversionProfileId = $conversionProfileId;
         }
         $tempDbEntry = $this->prepareEntryForInsert($tempMediaEntry);
         $tempDbEntry->setDisplayInSearch(mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM);
         $tempDbEntry->setPartnerId($dbEntry->getPartnerId());
         $tempDbEntry->setReplacedEntryId($dbEntry->getId());
         $tempDbEntry->save();
         $dbEntry->setReplacingEntryId($tempDbEntry->getId());
         $dbEntry->setReplacementStatus(entryReplacementStatus::NOT_READY_AND_NOT_APPROVED);
         if (!$partner->getEnabledService(PermissionName::FEATURE_ENTRY_REPLACEMENT_APPROVAL)) {
             $dbEntry->setReplacementStatus(entryReplacementStatus::APPROVED_BUT_NOT_READY);
         }
         $dbEntry->save();
         $kResource = $resource->toObject();
         $this->attachResource($kResource, $tempDbEntry);
     }
     $resource->entryHandled($dbEntry);
 }