/** * @param BaseObject $object */ protected function setRelatedObject(AuditTrail $auditTrail, BaseObject $object) { if (class_exists('Metadata') && $object instanceof Metadata) { $auditTrail->setRelatedObjectType(AuditTrailObjectType::METADATA_PROFILE); $auditTrail->setRelatedObjectId($object->getMetadataProfileId()); } if ($auditTrail->getAction() == AuditTrail::AUDIT_TRAIL_ACTION_FILE_SYNC_CREATED) { $peer = $object->getPeer(); $objectType = $peer->getOMClass(false, null); $auditTrail->setRelatedObjectType($objectType); $auditTrail->setRelatedObjectId($object->getId()); } if ($object instanceof FileSync) { switch ($object->getObjectType()) { case FileSyncObjectType::ENTRY: $auditTrail->setRelatedObjectType(AuditTrailObjectType::ENTRY); $auditTrail->setRelatedObjectId($object->getObjectId()); $auditTrail->setEntryId($object->getObjectId()); break; case FileSyncObjectType::UICONF: $auditTrail->setRelatedObjectType(AuditTrailObjectType::UI_CONF); $auditTrail->setRelatedObjectId($object->getObjectId()); break; case FileSyncObjectType::BATCHJOB: $auditTrail->setRelatedObjectType(AuditTrailObjectType::BATCH_JOB); $auditTrail->setRelatedObjectId($object->getObjectId()); $batchJob = BatchJobPeer::retrieveByPK($object->getObjectId()); if ($batchJob) { $auditTrail->setEntryId($batchJob->getEntryId()); } break; case FileSyncObjectType::FLAVOR_ASSET: $auditTrail->setRelatedObjectType(AuditTrailObjectType::FLAVOR_ASSET); $auditTrail->setRelatedObjectId($object->getObjectId()); $flavorAsset = flavorAssetPeer::retrieveById($object->getObjectId()); if ($flavorAsset) { $auditTrail->setEntryId($flavorAsset->getEntryId()); } break; case FileSyncObjectType::METADATA: $auditTrail->setRelatedObjectType(AuditTrailObjectType::METADATA); $auditTrail->setRelatedObjectId($object->getObjectId()); if (class_exists('Metadata')) { $metadata = MetadataPeer::retrieveByPK($object->getObjectId()); if ($metadata && $metadata->getObjectType() == Metadata::TYPE_ENTRY) { $auditTrail->setEntryId($metadata->getObjectId()); } } break; case FileSyncObjectType::METADATA_PROFILE: $auditTrail->setRelatedObjectType(AuditTrailObjectType::METADATA_PROFILE); $auditTrail->setRelatedObjectId($object->getObjectId()); break; } } }
public static function setByArray(BaseObject $model, $values) { $peer = $model->getPeer(); $columns = array_flip($peer::getFieldNames(BasePeer::TYPE_FIELDNAME)); foreach ($values as $name => $value) { if (isset($columns[$name])) { $phpName = $peer::translateFieldName($name, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); $method = 'set' . $phpName; if ($value === '') { $value = null; } $model->{$method}($value); } } }
/** * * Compares two propel objects and notifies the PHPUnit / Kaltura's listeners * @param BaseObject $outputReference * @param BaseObject $newResult * @return array<> $newErrors, if the objects are equal */ public function comparePropelObjectsByFields($outputReference, $newResult, $validErrorFields) { //Gets the data peer of the object (used to geting all the obejct feilds) $dataPeer = $outputReference->getPeer(); $outputReferenceId = $outputReference->getId(); $newResultId = $newResult->getId(); //Gets all object feilds $fields = call_user_func(array($dataPeer, "getFieldNames"), BasePeer::TYPE_PHPNAME); $newErrors = array(); //Create the xml elements by all fields and their values foreach ($fields as $field) { PHP_Timer::start(); //If the field is in the valid failure list then we skip him if (in_array($field, $validErrorFields)) { continue; } else { $expectedValue = $outputReference->getByName($field); $actualValue = $newResult->getByName($field); //if this is an array we need to change it to a string $this->compareOnField($field, $actualValue, $expectedValue, "assertEquals"); } } return $newErrors; }
/** * Function which checks the object tags agains DB * and returns an array of tags ids which need to be deleted. * @param BaseObject $object * @return array */ protected function checkExistForDelete(BaseObject $object, $tagsToCheck = null) { $objectTags = $tagsToCheck ? $this->trimObjectTags($tagsToCheck) : $this->trimObjectTags($object->getTags()); $objectTags = str_replace(self::$specialCharacters, self::$specialCharactersReplacement, $objectTags); $tagsToKeep = array(); foreach ($objectTags as $objectTag) { $peer = $object->getPeer(); $c = KalturaCriteria::create(get_class($object)); $c->addAnd(self::PARTNER_ID_FIELD, $object->getPartnerId(), KalturaCriteria::EQUAL); $c->addAnd($peer::TAGS, $objectTag, KalturaCriteria::LIKE); $c->addAnd($peer::ID, array($object->getId()), KalturaCriteria::NOT_IN); $selectResults = $peer->doSelect($c); foreach ($selectResults as $selectResult) { $resultTags = $this->trimObjectTags($selectResult->getTags()); if (in_array($objectTag, $resultTags)) { // if(isset($tagsToKeep[$objectTag])) // $tagsToKeep[$objectTag]++; // else // $tagsToKeep[$objectTag] = 1; if (!in_array($objectTag, $tagsToKeep)) { $tagsToKeep[] = $objectTag; } } } } KalturaLog::debug("tags to keep: " . print_r($tagsToKeep, true)); if (count($tagsToKeep)) { //Decrement instance count for the tags that we keep $c = self::getTagObjectsByTagStringsCriteria($tagsToKeep, $this->getObjectIdByClassName(get_class($object)), $object->getPartnerId()); $tagsToKeepObjects = TagPeer::doSelect($c); foreach ($tagsToKeepObjects as $tagToKeepObject) { /* @var $tagToKeepObject Tag */ $tagToKeepObject->decrementInstanceCount(); } } //Return the IDs of the rest of the tags for removal. $tagsToRemove = array_diff($objectTags, $tagsToKeep); KalturaLog::debug("tags to delete: " . print_r($tagsToRemove, true)); if ($tagsToRemove) { $c = self::getTagObjectsByTagStringsCriteria($tagsToRemove, $this->getObjectIdByClassName(get_class($object)), $object->getPartnerId()); $c->applyFilters(); $recordsToRemove = $c->getRecordsCount(); return $c->getFetchedIds(); } return array(); }
/** * Returns queries needed to update tree. * * @param BaseObject $node * @param integer $dest_left * * @return array */ private static function getUpdateTreeQueries(BaseObject $node, $dest_left) { $statements = array(); $peer_name = get_class($node->getPeer()); $left = $node->getLeftValue(); $right = $node->getRightValue(); $tree_size = $right - $left + 1; $statements = array_merge($statements, self::shiftRLValues($peer_name, $dest_left, $tree_size, $node->getScopeIdValue())); if ($left >= $dest_left) { $left += $tree_size; $right += $tree_size; } $statements = array_merge($statements, self::shiftRLRange($peer_name, $left, $right, $dest_left - $left, $node->getScopeIdValue())); $statements = array_merge($statements, self::shiftRLValues($peer_name, $right + 1, -$tree_size, $node->getScopeIdValue())); return $statements; }
/** * File fields processing * * @example <i:field label="File" name="file" type="file"> * <i:value type="orm"> * <i:class>ModelCriteriaFetcher</i:class> * <i:method name="configureFileField"> * <i:param name="fields">[path:file_path_field]</i:param> * </i:method> * </i:value> * </i:field> * * if multiple files for table should be added <i:param name="glue_model">ForeignModelName</i:param> * * @param BaseObject $model * @return void * @author Sergey Startsev */ public function processFileFields(BaseObject $model) { $model_name = $this->object->getPeer()->getOMClass(false); $upload_dir = sfConfig::get('sf_upload_dir'); $web_upload_dir = str_replace(sfConfig::get('sf_web_dir'), '', $upload_dir); if (!file_exists($upload_dir)) { mkdir($upload_dir); } foreach ($this->dom_xml_xpath->query('//i:fields/i:field[@type="file"]') as $field) { $name = $field->getAttribute('name'); $params = array(); $class = $field->getElementsByTagName('class'); $method = $field->getElementsByTagName('method'); if (!$class || !$method) { continue; } $classNode = $class->item(0); $methodNode = $method->item(0); if ($classNode->nodeValue != 'ModelCriteriaFetcher' || $methodNode->getAttribute('name') != 'configureFileField') { continue; } foreach ($methodNode->getElementsByTagName('param') as $param) { $params[$param->getAttribute('name')] = $param->nodeValue; } $is_foreign = false; $hashes = array(); if (!array_key_exists('fields', $params)) { continue; } foreach (explode(',', str_replace(array('[', ']'), '', $params['fields'])) as $def) { list($key, $value) = explode(':', $def); $hashes[$key] = $value; } if (array_key_exists('glue_model', $params)) { $glue_model = $params['glue_model']; $is_foreign = true; } if (array_key_exists('upload_dir', $params)) { $web_upload_dir = '/' . trim($params['upload_dir'], '/'); $upload_dir = sfConfig::get('sf_web_dir') . $web_upload_dir; if (!file_exists($upload_dir)) { @mkdir($upload_dir, 0775, true); } } if (!isset($_FILES['edit']['name']['0'][$name]) || !$_FILES['edit']['size']['0'][$name]) { continue; } $file_native_name = $_FILES['edit']['name']['0'][$name]; $file_size = $_FILES['edit']['size']['0'][$name]; $file_name = Util::makeRandomKey() . '.' . pathinfo($file_native_name, PATHINFO_EXTENSION); $file_path = "{$upload_dir}/{$file_name}"; $tmp_name = $_FILES['edit']['tmp_name']['0'][$name]; if (!move_uploaded_file($tmp_name, $file_path)) { continue; } if ($is_foreign) { $glue = new $glue_model(); call_user_func(array($glue, "set" . get_class($model)), $model); } else { $glue = $model; } if (array_key_exists('path', $hashes)) { $glue->setByName($hashes['path'], "{$web_upload_dir}/{$file_name}", BasePeer::TYPE_FIELDNAME); } if (array_key_exists('original_name', $hashes)) { $glue->setByName($hashes['original_name'], $file_native_name, BasePeer::TYPE_FIELDNAME); } if (array_key_exists('name', $hashes)) { $glue->setByName($hashes['name'], $file_name, BasePeer::TYPE_FIELDNAME); } if (array_key_exists('size', $hashes)) { $glue->setByName($hashes['size'], $file_size, BasePeer::TYPE_FIELDNAME); } $glue->save(); } }
/** * Finder fluid method to restrict results to a related object * Examples: * $commentFinder->relatedTo($article) * => $c->add(CommentPeer::ARTICLE_ID, $article->getId()) * * @param BaseObject $object The related object to restrict to * @return sfPropelFinder the current finder object */ public function relatedTo($object) { // looking for a 1-n relationship $relatedObjectTableName = $object->getPeer()->getTableMap()->getName(); foreach (sfPropelFinderUtils::getColumnsForPeerClass($this->peerClass) as $c) { if ($c->getRelatedTableName() == $relatedObjectTableName) { $this->addCondition('and', $c->getFullyQualifiedName(), $object->getByName($c->getRelatedName(), BasePeer::TYPE_COLNAME), Criteria::EQUAL); return $this; } } // looking for a n-1 relationship $localObjectTableName = $this->object->getPeer()->getTableMap()->getName(); foreach (sfPropelFinderUtils::getColumnsForPeerClass(get_class($object->getPeer())) as $c) { if ($c->getRelatedTableName() == $localObjectTableName) { $this->addCondition('and', $c->getRelatedName(), $object->getByName($c->getFullyQualifiedName(), BasePeer::TYPE_COLNAME), Criteria::EQUAL); return $this; } } throw new Exception('Could not find a relation with object of class ' . get_class($object)); }
/** * Add description of an error to the BulkUploadResult of the object in question * @param BaseObject $object * @param string $bulkUploadId * @param string $description */ protected static function addBulkUploadResultDescription(BaseObject $object, $bulkUploadId, $description) { $objectPeerClass = get_class($object->getPeer()); $objectType = strtoupper(constant("{$objectPeerClass}::OM_CLASS")); if ($objectType == 'KUSER') { $objectType = 'USER'; } $bulkUploadResult = BulkUploadResultPeer::retrieveByObjectId($object->getId(), constant("BulkUploadObjectType::{$objectType}"), $bulkUploadId); if (!$bulkUploadResult) { KalturaLog::err("Bulk upload results not found for object [{$object->getId()}]"); return; } $msg = $bulkUploadResult->getErrorDescription(); if ($msg) { $msg .= "\n"; } $msg .= $description; $bulkUploadResult->setErrorDescription($msg); $bulkUploadResult->save(); }
/** * Returns getter / setter name for requested column. * * @param BaseObject $resource * @param string $prefix Usually 'get' or 'set' * @param string $column uuid|version */ private static function forgeMethodName($resource, $prefix, $column) { $method_name = sprintf('%s%s', $prefix, $resource->getPeer()->translateFieldName(self::getColumnConstant(get_class($resource), $column), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME)); return $method_name; }
public function objectChanged(BaseObject $object, array $modifiedColumns) { $privacyContexts = null; if ($object instanceof entry) { $criteria = new Criteria(); $criteria->add(categoryEntryPeer::ENTRY_ID, $object->getId()); $categoryEntries = categoryEntryPeer::doSelect($criteria); $privacyContexts = array(self::NULL_PC); if (count($categoryEntries)) { foreach ($categoryEntries as $categoryEntry) { /* @var $categoryEntry categoryEntry */ if ($categoryEntry->getPrivacyContext() != "") { $privacyContexts = array_merge($privacyContexts, self::trimObjectTags($categoryEntry->getPrivacyContext())); } else { $privacyContexts[] = kEntitlementUtils::DEFAULT_CONTEXT; } } $privacyContexts = array_unique($privacyContexts); } } $oldTags = $object->getColumnsOldValue(self::getClassConstValue(get_class($object->getPeer()), self::TAGS_FIELD_NAME)); $newTags = $object->getTags(); $tagsForDelete = implode(',', array_diff(explode(',', $oldTags), explode(',', $newTags))); $tagsForUpdate = implode(',', array_diff(explode(',', $newTags), explode(',', $oldTags))); if ($oldTags && $oldTags != "") { self::decrementExistingTagsInstanceCount($tagsForDelete, $object->getPartnerId(), get_class($object), $privacyContexts); } self::addOrIncrementTags($tagsForUpdate, $object->getPartnerId(), get_class($object), $privacyContexts); }
/** * @param BaseObject $object */ public function setObject(BaseObject $object) { $this->peer = get_class($object->getPeer()); $this->primaryKey = $object->getPrimaryKey(); }