/** * Adds conditions, matches and where clauses to the query * @param IKalturaIndexQuery $query */ public function applyCondition(IKalturaDbQuery $query) { switch ($this->getComparison()) { case KalturaSearchConditionComparison::EQUAL: $comparison = ' = '; break; case KalturaSearchConditionComparison::GREATER_THAN: $comparison = ' > '; break; case KalturaSearchConditionComparison::GREATER_THAN_OR_EQUAL: $comparison = ' >= '; break; case KalturaSearchConditionComparison::LESS_THAN: $comparison = " < "; break; case KalturaSearchConditionComparison::LESS_THAN_OR_EQUAL: $comparison = " <= "; break; case KalturaSearchConditionComparison::NOT_EQUAL: $comparison = " <> "; break; default: KalturaLog::ERR("Missing comparison type"); return; } $field = $this->getField(); $value = $this->getValue(); $fieldValue = $this->getFieldValue($field); if (is_null($fieldValue)) { KalturaLog::err('Unknown field [' . $field . ']'); return; } $newCondition = $fieldValue . $comparison . KalturaCriteria::escapeString($value); $query->addCondition($newCondition); }
/** * batch getExclusiveFileSyncImportJob action allows to get a BatchJob of type FILESYNC_IMPORT * * @action getExclusiveFileSyncImportJobs * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism * @param int $maxExecutionTime The maximum time in seconds the job reguarly take. Is used for the locking mechanism when determining an unexpected termination of a batch-process. * @param int $numberOfJobs The maximum number of jobs to return. * @param KalturaBatchJobFilter $filter Set of rules to fetch only rartial list of jobs * @param int $maxOffset The maximum offset we accept for the distance from the best result. * @return KalturaBatchJobArray * * TODO remove the destFilePath from the job data and get it later using the api, then delete this method */ function getExclusiveFileSyncImportJobsAction(KalturaExclusiveLockKey $lockKey, $maxExecutionTime, $numberOfJobs, KalturaBatchJobFilter $filter = null, $maxOffset = null) { $coreJobs = $this->getExclusiveJobs($lockKey, $maxExecutionTime, $numberOfJobs, $filter, BatchJobType::FILESYNC_IMPORT, $maxOffset); $jobs = KalturaBatchJobArray::fromBatchJobArray($coreJobs); if ($jobs) { foreach ($jobs as $index => $job) { $data = $job->data; // try to get destination path from file sync $fileSyncId = $data->filesyncId; $fileSync = FileSyncPeer::retrieveByPK($fileSyncId); if (!$fileSync) { KalturaLog::err("Failed to load file sync [{$fileSyncId}] aborting job [{$job->id}]"); $dbJob = BatchJobPeer::retrieveByPK($job->id); $dbJob->setMessage("Failed to load file sync [{$fileSyncId}]"); kJobsManager::abortDbBatchJob($dbJob); unset($jobs[$index]); continue; } $fileSyncRoot = $fileSync->getFileRoot(); $fileSyncPath = $fileSync->getFilePath(); if ($fileSyncRoot && $fileSyncPath) { // destination path set on filesync $dest_path = $fileSyncRoot . $fileSyncPath; } else { // not set on filesync - get path from path manager $fileSyncKey = kFileSyncUtils::getKeyForFileSync($fileSync); list($file_root, $real_path) = kPathManager::getFilePathArr($fileSyncKey); $dest_path = $file_root . $real_path; // update filesync on database $fileSync->setFileRoot($file_root); $fileSync->setFilePath($real_path); $fileSync->save(); } // update job data with destination path if needed if (!$data->destFilePath) { $data->destFilePath = $dest_path; $job->data = $data; KalturaLog::log('Updating destination path for job id [$job->id]'); $this->updateJob($job); } if (!is_dir(dirname($dest_path)) && !@mkdir(dirname($dest_path), 0755, true)) { KalturaLog::ERR("Cannot create directory [{$dest_path}] - " . error_get_last()); } } } return $jobs; }
/** * Adds conditions, matches and where clauses to the query * @param IKalturaIndexQuery $query */ public function applyCondition(IKalturaDbQuery $query) { switch ($this->getComparison()) { case KalturaSearchConditionComparison::EQUAL: $comparison = ' = '; break; case KalturaSearchConditionComparison::GREATER_THAN: $comparison = ' > '; break; case KalturaSearchConditionComparison::GREATER_THAN_OR_EQUAL: $comparison = ' >= '; break; case KalturaSearchConditionComparison::LESS_THAN: $comparison = " < "; break; case KalturaSearchConditionComparison::LESS_THAN_OR_EQUAL: $comparison = " <= "; break; case KalturaSearchConditionComparison::NOT_EQUAL: $comparison = " <> "; break; default: KalturaLog::ERR("Missing comparison type"); return; } $field = $this->getField(); $value = $this->getValue(); $fieldValue = null; switch ($field) { case Criteria::CURRENT_DATE: $d = getdate(); $fieldValue = mktime(0, 0, 0, $d['mon'], $d['mday'], $d['year']); break; case Criteria::CURRENT_TIME: case Criteria::CURRENT_TIMESTAMP: $fieldValue = time(); break; default: KalturaLog::err('Unknown field [' . $field . ']'); return; } $newCondition = $fieldValue . $comparison . SphinxUtils::escapeString($value); $query->addCondition($newCondition); }
/** * batch getExclusiveFileSyncImportJob action allows to get a BatchJob of type FILESYNC_IMPORT * * @action getExclusiveFileSyncImportJobs * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism * @param int $maxExecutionTime The maximum time in seconds the job reguarly take. Is used for the locking mechanism when determining an unexpected termination of a batch-process. * @param int $numberOfJobs The maximum number of jobs to return. * @param KalturaBatchJobFilter $filter Set of rules to fetch only rartial list of jobs * @return KalturaBatchJobArray */ function getExclusiveFileSyncImportJobsAction(KalturaExclusiveLockKey $lockKey, $maxExecutionTime, $numberOfJobs, KalturaBatchJobFilter $filter = null) { $jobs = $this->getExclusiveJobsAction($lockKey, $maxExecutionTime, $numberOfJobs, $filter, BatchJobType::FILESYNC_IMPORT); if ($jobs) { foreach ($jobs as $job) { $data = $job->data; // try to get destination path from file sync $fileSyncId = $data->filesyncId; $fileSync = FileSyncPeer::retrieveByPK($fileSyncId); if (!$fileSync) { throw new KalturaAPIException(MultiCentersErrors::INVALID_FILESYNC_RECORD, $fileSyncId); } $fileSyncRoot = $fileSync->getFileRoot(); $fileSyncPath = $fileSync->getFilePath(); if ($fileSyncRoot && $fileSyncPath) { // destination path set on filesync $dest_path = $fileSyncRoot . $fileSyncPath; } else { // not set on filesync - get path from path manager $fileSyncKey = kFileSyncUtils::getKeyForFileSync($fileSync); list($file_root, $real_path) = kPathManager::getFilePathArr($fileSyncKey); $dest_path = $file_root . $real_path; // update filesync on database $fileSync->setFileRoot($file_root); $fileSync->setFilePath($real_path); $fileSync->save(); } // update job data with destination path if needed if (!$data->destFilePath) { $data->destFilePath = $dest_path; $job->data = $data; KalturaLog::log('Updating destination path for job id [$job->id]'); $this->updateJob($job); } if (!is_dir(dirname($dest_path)) && !@mkdir(dirname($dest_path), 0755, true)) { KalturaLog::ERR("Cannot create directory [{$dest_path}] - " . error_get_last()); } } } return $jobs; }
require_once "../../bootstrap.php"; KalturaLog::setContext("TESTME"); $service = $_GET["service"]; $action = $_GET["action"]; $bench_start = microtime(true); KalturaLog::INFO(">------- api_v3 testme [{$service}][{$action}]-------"); function toArrayRecursive(KalturaPropertyInfo $propInfo) { return $propInfo->toArray(); } $serviceMap = KalturaServicesMap::getMap(); $actionInfo = null; try { $serviceReflector = $serviceMap[strtolower($service)]; /* @var $serviceReflector KalturaServiceActionItem */ $actionReflector = new KalturaActionReflector($service, $action, $serviceReflector->actionMap[$action]); $actionParams = $actionReflector->getActionParams(); $actionInfo = $actionReflector->getActionInfo(); $actionInfo = array("actionParams" => array(), "description" => $actionInfo->description); foreach ($actionParams as $actionParam) { $actionInfo["actionParams"][] = toArrayRecursive($actionParam); } } catch (Exception $ex) { KalturaLog::ERR("<------- api_v3 testme [{$service}][{$action}\n" . $ex->__toString() . " " . " -------"); } //echo "<pre>"; //echo print_r($actionInfo); echo json_encode($actionInfo); $bench_end = microtime(true); KalturaLog::INFO("<------- api_v3 testme [{$service}][{$action}][" . ($bench_end - $bench_start) . "] -------");
/** * * @param string $field - xPath (metadataProfileField) */ protected function getMetadataSearchField($field = null, $xPaths = array(), &$fieldType = null) { $fieldType = null; if (!$field) { return MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPANDER_FIELD_DATA); } if (!count($xPaths)) { $profileFields = MetadataProfileFieldPeer::retrieveActiveByMetadataProfileId($this->metadataProfileId); foreach ($profileFields as $profileField) { $xPaths[$profileField->getXpath()] = $profileField; } } if (!isset($xPaths[$field])) { KalturaLog::ERR("Missing field: " . $field); return null; } $fieldType = $xPaths[$field]->getType(); switch ($xPaths[$field]->getType()) { case MetadataSearchFilter::KMC_FIELD_TYPE_DATE: case MetadataSearchFilter::KMC_FIELD_TYPE_INT: $metadataField = MetadataPlugin::SPHINX_DYNAMIC_ATTRIBUTES . "." . MetadataPlugin::getSphinxFieldName($xPaths[$field]->getId()); break; default: KalturaLog::ERR("Missing field type: " . $xPaths[$field]->getType()); return null; } return $metadataField; }
public function applyCondition(IKalturaDbQuery $query, $xPaths = null) { if (!$query instanceof IKalturaIndexQuery) { return; } $this->parentQuery = $query; if ($this->parentQuery instanceof MetadataSearchFilter || $this->parentQuery instanceof DynamicObjectSearchFilter) { $this->metadataProfileId = $this->parentQuery->getMetadataProfileId(); } if (!$this->metadataProfileId) { KalturaLog::err('Metadata profile id was not found on parent query, or parent query is not instance of MetadataSearchFilter/DynamicObjectSearchFilter'); return; } $field = $this->getField(); if (!isset($xPaths[$field])) { $this->addCondition('1 <> 1'); KalturaLog::ERR("Missing field: {$field} in xpath array: " . print_r($xPaths, true)); return; } /** @var MetadataProfileField $metadataProfileField */ $metadataProfileField = $xPaths[$field]; if ($metadataProfileField->getType() !== MetadataSearchFilter::KMC_FIELD_TYPE_METADATA_OBJECT) { KalturaLog::ERR("Field {$field} is not set as a dynamic object type"); return; } $pluginName = MetadataPlugin::PLUGIN_NAME; $fieldId = $metadataProfileField->getId(); $relatedMetadataProfileId = $metadataProfileField->getRelatedMetadataProfileId(); $innerXPaths = $this->loadFields($relatedMetadataProfileId); $prefix = "{$pluginName}_{$fieldId}"; $suffix = kMetadataManager::SEARCH_TEXT_SUFFIX . "_{$fieldId}"; $dataConditions = array(); foreach ($this->items as $item) { if ($item instanceof DynamicObjectSearchFilter) { $item->applyCondition($this, $innerXPaths); $dataConditions = $item->matchClause; } elseif ($item instanceof AdvancedSearchFilterCondition) { $innerField = $item->getField(); if (!isset($innerXPaths[$innerField])) { $this->addCondition('1 <> 1'); KalturaLog::ERR("Missing field: {$innerField} in inner xpath array: " . print_r($innerXPaths, true)); continue; } $innerValue = $item->getValue(); $innerFieldType = $innerXPaths[$innerField]->getType(); $innerFieldId = $innerXPaths[$innerField]->getId(); $innerPrefix = $pluginName . '_' . $innerFieldId; $innerSuffix = kMetadataManager::SEARCH_TEXT_SUFFIX . '_' . $innerFieldId; $dataCondition = "\"{$innerPrefix} {$innerValue} {$innerSuffix}\""; KalturaLog::debug("Inner condition: {$dataCondition}"); $dataConditions[] = $dataCondition; } } if (count($dataConditions)) { foreach ($dataConditions as &$dataCondition) { $dataCondition = "( {$prefix} ( {$dataCondition} ) {$suffix} )"; KalturaLog::debug("Wrapped condition: {$dataCondition}"); } $glue = $this->type == MetadataSearchFilter::SEARCH_AND ? ' ' : ' | '; $dataConditions = array_unique($dataConditions); $value = implode($glue, $dataConditions); KalturaLog::debug("Current {$value}"); $this->addMatch($value); } }
public function handleApplicationException(Exception $ex) { KalturaLog::ERR($ex); $this->getResponse()->setHttpResponseCode(500); $this->view->message = 'Application error'; }
$actionInfo = null; if (!array_key_exists(strtolower($service), $serviceMap)) { $msg = "<------- api_v3 testme [{$service}][{$action}] not found -------"; KalturaLog::ERR($msg); die($msg); } try { $serviceReflector = $serviceMap[strtolower($service)]; if (!array_key_exists($action, $serviceReflector->actionMap)) { $msg = "<------- api_v3 testme [{$service}][{$action}] not found -------"; KalturaLog::ERR($msg); die($msg); } /* @var $serviceReflector KalturaServiceActionItem */ $actionReflector = new KalturaActionReflector($service, $action, $serviceReflector->actionMap[$action]); $actionParams = $actionReflector->getActionParams(); $actionInfo = $actionReflector->getActionInfo(); $actionInfo = array("actionParams" => array(), "description" => $actionInfo->description); foreach ($actionParams as $actionParam) { $actionInfo["actionParams"][] = toArrayRecursive($actionParam); } } catch (Exception $ex) { $msg = "<------- api_v3 testme [{$service}][{$action}\n" . $ex->__toString() . " " . " -------"; KalturaLog::ERR($msg); die($msg); } //echo "<pre>"; //echo print_r($actionInfo); echo json_encode($actionInfo); $bench_end = microtime(true); KalturaLog::INFO("<------- api_v3 testme [{$service}][{$action}][" . ($bench_end - $bench_start) . "] -------");
/** * Clones an existing mix. * * @action clone * @param string $entryId Mix entry id to clone * @return KalturaMixEntry The new mix entry */ function cloneAction($entryId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::MIX) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $kshowId = $dbEntry->getKshowId(); $kshow = $dbEntry->getKshow(); if (!$kshow) { KalturaLog::CRIT("Kshow was not found for mix id [" . $entryId . "]"); throw new KalturaAPIException(KalturaErrors::INTERNAL_SERVERL_ERROR); } $newKshow = myKshowUtils::shalowCloneById($kshowId, $this->getKuser()->getId()); if (!$newKshow) { KalturaLog::ERR("Failed to clone kshow for mix id [" . $entryId . "]"); throw new KalturaAPIException(KalturaErrors::INTERNAL_SERVERL_ERROR); } $newEntry = $newKshow->getShowEntry(); $newMixEntry = new KalturaMixEntry(); $newMixEntry->fromObject($newEntry); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $newEntry); return $newMixEntry; }
} $subClasses = array(); try { KalturaTypeReflector::setClassInheritMapPath(KAutoloader::buildPath(kConf::get("cache_root_path"), "api_v3", "KalturaClassInheritMap.cache")); if (!KalturaTypeReflector::hasClassInheritMapCache()) { $config = new Zend_Config_Ini("../../config/testme.ini"); $indexConfig = $config->get('testme'); $include = $indexConfig->get("include"); $exclude = $indexConfig->get("exclude"); $excludePaths = $indexConfig->get("excludepaths"); $additional = $indexConfig->get("additional"); $clientGenerator = new DummyForDocsClientGenerator(); $clientGenerator->setIncludeOrExcludeList($include, $exclude, $excludePaths); $clientGenerator->setAdditionalList($additional); $clientGenerator->load(); $objects = $clientGenerator->getTypes(); KalturaTypeReflector::setClassMap(array_keys($objects)); } $subClassesNames = KalturaTypeReflector::getSubClasses($type); foreach ($subClassesNames as $subClassName) { $subClass = new KalturaPropertyInfo($subClassName); $subClasses[] = $subClass->toArray(); } } catch (Exception $ex) { KalturaLog::ERR("<------- api_v3 testme [{$type}]\n" . $ex->__toString() . " " . " -------"); } //echo "<pre>"; //echo print_r($actionInfo); echo json_encode($subClasses); $bench_end = microtime(true); KalturaLog::INFO("<------- api_v3 testme type [{$type}][" . ($bench_end - $bench_start) . "] -------");
/** * * @param string $field - xPath (metadataProfileField) */ public function getMetadataSearchField($field = null, $xPaths = array()) { if (!$field) { return MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPANDER_FIELD_DATA); } if (!count($xPaths)) { $profileFields = MetadataProfileFieldPeer::retrieveActiveByMetadataProfileId($this->metadataProfileId); foreach ($profileFields as $profileField) { $xPaths[$profileField->getXpath()] = $profileField; } } if (!isset($xPaths[$field])) { KalturaLog::ERR("Missing field: " . $field); return null; } if (is_null($xPaths[$field]->getSearchIndex())) { KalturaLog::ERR("Missing field search index: " . $field); return null; } switch ($xPaths[$field]->getType()) { case MetadataSearchFilter::KMC_FIELD_TYPE_DATE: case MetadataSearchFilter::KMC_FIELD_TYPE_INT: $metadataField = MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPENDER_FIELD_INT) . $xPaths[$field]->getSearchIndex(); break; default: KalturaLog::ERR("Missing field type: " . $xPaths[$field]->getType()); return null; } return $metadataField; }