/** * Queue a node to have its meta decremented * * @param NodeRef $nodeRef * @param NodeRef $extNodeRef * @param $tag */ public function decrement(NodeRef $nodeRef, NodeRef $extNodeRef, $tag) { $nodeRefUrl = $nodeRef->getRefURL(); if (!isset($this->NodeCounts[$nodeRefUrl])) { $this->NodeCounts[$nodeRefUrl] = 0; } $this->NodeCounts[$nodeRefUrl]--; $this->Logger->debug(__FUNCTION__ . "-> Decrement " . $this->getMetaID() . " for: {$nodeRefUrl}"); }
public function deleteOrphanedFile(NodeRef &$originNodeRef, NodeRef &$inboundNodeRef) { if ($inboundNodeRef->getElement()->hasAspect('@media')) { if (in_array("" . $originNodeRef, $this->currentlyDeleting)) { return; } $this->currentlyDeleting[] = "" . $originNodeRef; $this->bindToShutdown(); $this->NodeService->delete($originNodeRef); } }
public function requirePrimaryImage(Errors &$errors, NodeRef $nodeRef, Node &$node) { $element = $nodeRef->getElement(); $schema = $element->getSchema(); if (!PartialUtils::isTagRoleInOutTagsScope($schema, $node->getNodePartials(), '#primary-image')) { // this should only occur during bulk cms actions return; } if ($schema->hasTagDef('#primary-image')) { $primaryImageTag = $node->getOutTag('#primary-image'); $errors->rejectIfEmpty('#primary-image', 'tag', 'Primary Image', $primaryImageTag); } }
public function loadAudioTags(NodeRef $nodeRef, NodePartials &$nodePartials = null) { if (!is_null($nodePartials)) { if ($nodePartials->getOutPartials() != "") { $tagDefs = $nodeRef->getElement()->Schema->getTagDefs(); foreach ($tagDefs as $k => $tagDef) { if ($tagDef->Partial->TagAspect == 'audio') { $nodePartials->increaseOutPartials('#' . $tagDef->Partial->TagRole . '.#original.#url'); } } } } }
protected function checkInternal($action, NodeRef &$nodeRef, &$newData = null, $throw = true, $isRead = false) { $obj = new Transport(); $obj->Permitted = true; $obj->CachePermission = true; $checkedCache = false; $elementSlug = $nodeRef->getElement()->getSlug(); if (array_key_exists($elementSlug, $this->byElementPermissions) && array_key_exists($action, $this->byElementPermissions[$elementSlug])) { $obj->Permitted = $this->byElementPermissions[$nodeRef->getElement()->getSlug()][$action]; $checkedCache = true; } if (!$checkedCache) { // if(!$isRead) // $this->Events->trigger('Node.permit.write', $obj, $nodeRef, $newData); // // if ($obj->isPermitted()) { // $this->Events->trigger('Node.permit.'.$action, $obj, $nodeRef, $newData); // } // if ($obj->isPermitted()) foreach ((array) $nodeRef->getElement()->getAspects() as $aspect) { if (!$isRead) { $this->Events->trigger('Node.@' . $aspect->Slug . '.permit.write', $obj, $nodeRef, $newData); } if (!$obj->isPermitted()) { break; } $this->Events->trigger('Node.@' . $aspect->Slug . '.permit.' . $action, $obj, $nodeRef, $newData); if (!$obj->isPermitted()) { break; } } if ($obj->isCachePermission()) { if (!array_key_exists($elementSlug, $this->byElementPermissions)) { $this->byElementPermissions[$elementSlug] = array(); } $this->byElementPermissions[$elementSlug][$action] = $obj->Permitted; } } if (!$obj->isPermitted() && $throw) { throw new PermissionsException('Permission denied to ' . $action . ' ' . $nodeRef->getElement()->getName()); } return $obj->isPermitted(); }
public function delete(NodeRef $nodeRef) { if (!$nodeRef->isFullyQualified()) { throw new Exception('Cannot delete node from index without fully-qualified NodeRef'); } if (substr($this->Elements, 0, 1) == '@') { if (!$nodeRef->getElement()->hasAspect($this->Elements)) { return; } } else { if (!in_array($nodeRef->getElement()->getSlug(), StringUtils::smartExplode($this->Elements))) { return; } } if (array_key_exists('' . $nodeRef, $this->markedForReindex)) { unset($this->markedForReindex['' . $nodeRef]); } if (array_key_exists('' . $nodeRef, $this->markedForDeletion)) { return; } $this->markedForDeletion['' . $nodeRef] = $nodeRef; $this->bindReindex(); }
public function copy(NodeRef $nodeRef, Element $newNodeElement) { $node = $this->NodeLookupDAO->getByNodeRef($nodeRef, new NodePartials('all', 'all', 'all'), true); $newNodeRef = new NodeRef($newNodeElement, $node->Slug); $newNode = $newNodeRef->generateNode(); $cFields = array_intersect_key($node->toArray(), array_flip($this->NodeDBMeta->getPersistentFields())); $newNode->setFromArray($cFields); $newNode->setNodePartials($node->getNodePartials()); $schema = $newNodeElement->getSchema(); foreach ($schema->getTagDefs() as $tagDef) { // echo "Tag [{$tagDef->Direction}]: {$tagDef->Id}\n"; if ($tagDef->Direction == 'in') { $newNode->replaceInTags($tagDef->Id, $node->getInTags($tagDef->Id)); } else { $newNode->replaceOutTags($tagDef->Id, $node->getOutTags($tagDef->Id)); } } foreach ($schema->getMetaDefs() as $metaDef) { $newNode->updateMeta($metaDef->Id, $node->getMetaValue($metaDef->Id)); } return $this->add($newNode); }
public function resolveField(NodeRef $nodeRef, $fieldId) { $fields = array($nodeRef->getElement()->getSlug()); $fields[] = $fieldId; return join($fields, '.'); }
/** * Changes our NodeRef * * @param NodeRef $newNodeRef */ public function setNodeRef($newNodeRef) { $this->fields['NodeRef'] = $newNodeRef; $this->fields['Slug'] = $newNodeRef->isFullyQualified() ? $newNodeRef->getSlug() : ''; }
protected function check($perm, Transport &$permitted, NodeRef $nodeRef) { $permitted->Permitted = $this->Permissions->checkPermission($perm, $nodeRef->getSite()->getSlug()); }
/** * @param NodeRef $nodeRef * @param null $title * @param bool $useTime * @return NodeRef * @throws NodeException * @events slugUniquing validation event with $slugTransporter as param2 */ public function generateUniqueNodeRef(NodeRef $nodeRef, $title = null, $useTime = false) { $slug = $nodeRef->getSlug(); $slugTransporter = new Transport(); $slugTransporter->Slug = $slug; $errors = new Errors(); $this->NodeEvents->fireValidationEvents('slugUniquing', $errors, $nodeRef, $slugTransporter); $slug = $slugTransporter->Slug; $nodeRef = new NodeRef($nodeRef->getElement(), $slug); $errors->throwOnError(); if (empty($slug)) { if (empty($title)) { throw new NodeException('Cannot generate unique NodeRef without title'); } if ($useTime) { $slug = SlugUtils::createSlug(substr($title, 0, 237) . '-' . floor(microtime(true) * 100), $nodeRef->getElement()->isAllowSlugSlashes()); } else { $slug = SlugUtils::createSlug(substr($title, 0, 255), $nodeRef->getElement()->isAllowSlugSlashes()); } $nodeRef = new NodeRef($nodeRef->getElement(), $slug); } else { if ($useTime) { $title = substr($slug, 0, 237) . '-' . floor(microtime(true) * 100); } else { $title = substr($slug, 0, 255); } $nodeRef = new NodeRef($nodeRef->getElement(), SlugUtils::createSlug($title, $nodeRef->getElement()->isAllowSlugSlashes())); } $i = 0; while ($this->refExists($nodeRef)) { // Generate a unique slug $slug = SlugUtils::createSlug(substr($title, 0, 250) . " " . ++$i, $nodeRef->getElement()->isAllowSlugSlashes()); $nodeRef = new NodeRef($nodeRef->getElement(), $slug); } return $nodeRef; }
protected function findTags($direction, $db, NodeRef $originNodeRef, $ids, $partials = 'fields', $forceReadWrite = false, $checkJumpPermissions = false, $restrictedPartials, $resolveLinkedRecords = true, $existingRows = null) { if (!is_null($db) && !$db instanceof DatabaseInterface) { throw new NodeException('Argument 2 passed to NodeTagsDAO::findTags() must implement interface DatabaseInterface'); } $results = array(); if (empty($partials)) { return $results; } $returnOne = false; if (!is_array($ids)) { $returnOne = $ids; $ids = array($originNodeRef->getRefURL() => $ids); } $fixedId = false; if (!is_null($existingRows)) { $fixedId = 1; $returnOne = 1; } $tagFields = $this->tagFields; $this->Logger->debug('findTags [' . $direction . '] with partials [' . $partials . '] restrict [' . $restrictedPartials . ']'); if ($direction == 'out') { $table = $this->NodeDBMeta->getOutTagsTable($originNodeRef); $partials = PartialUtils::unserializeOutPartials($partials); $restrictedPartials = PartialUtils::unserializeOutPartials($restrictedPartials); } else { $table = $this->NodeDBMeta->getInTagsTable($originNodeRef); $partials = PartialUtils::unserializeInPartials($partials); $restrictedPartials = PartialUtils::unserializeInPartials($restrictedPartials); // $tagFields[] = 'TagOutID'; } // $this->Logger->debug($partials); $tableid = $this->NodeDBMeta->getPrimaryKey($originNodeRef); $now = $this->DateFactory->newLocalDate(); $rows = array(); $fieldlikePartials = array(); $childexprPartials = array(); $addlParams = array(); $jumpParams = array(); $fieldlikeRoles = array(); $nonfieldlikeRoles = array(); $outRoles = array(); $all = false; $allfieldlike = false; $tagDefs = array(); if ($partials == 'all' || ($x = array_search('all', $partials)) !== false) { $all = true; $partials = array(); } else { if (($x = array_search('fields', $partials)) !== false) { $allfieldlike = true; unset($partials[$x]); } } if ($restrictedPartials == 'all' || ($x = array_search('all', $restrictedPartials)) !== false) { return array(); } $tagDefs = $originNodeRef->getElement()->getSchema()->getTagDefs(); foreach ($originNodeRef->getElement()->getSchema()->getTagDefs() as $role => $tagDef) { if ($tagDef->isFieldlike() && strtolower($tagDef->Direction) == $direction) { $fieldlikeRoles[] = $role; } if ($tagDef->Direction == 'out') { $outRoles[] = $role; } } foreach ($partials as $x => $outPartial) { if ($outPartial['TagRole'] == false) { throw new TagException('Tag partials must specify a role when retrieving tags'); } if (in_array($outPartial['TagRole'], $fieldlikeRoles)) { $fieldlikePartials[] = $outPartial; unset($partials[$x]); } if ($resolveLinkedRecords && $outPartial->hasChildPartials()) { $childexprPartials[$outPartial['TagRole']][] = $outPartial; } } // tags passed to us, no need to query database if (is_null($existingRows)) { if ($allfieldlike == true || !empty($fieldlikePartials)) { $cachedIds = array(); // read from cache list($cachedIds, $rows) = $this->NodeCache->getTags($direction, $ids, $forceReadWrite); $remainingIds = array_diff($ids, $cachedIds); if (!empty($remainingIds)) { $dbToCacheRows = array(); if (!empty($fieldlikeRoles)) { $q = new Query(); $q->SELECT($tableid . ' as ID'); $q->SELECT($tagFields); // Commented out on 2/1/2010 by Craig .. Mysql seems to be using the right indexes without this. // $q->FROM($db->quoteIdentifier($table).' FORCE INDEX(RoleOnly)'); $q->FROM($db->quoteIdentifier($table)); $q->WHERE("{$tableid} IN ({$db->joinQuote((array) $remainingIds)})"); $q->WHERE("Role IN ({$db->joinQuote((array) $fieldlikeRoles)})"); $dbRows = $this->getConnectionForWrite($originNodeRef)->readAll($q); foreach ($dbRows as $row) { $dbToCacheRows[$row['ID']][] = $row; $rows[] = $row; } } $this->NodeCache->putTags($direction, $remainingIds, $dbToCacheRows, $forceReadWrite); } } if ($all) { $q = new Query(); // if($forceReadWrite) // $q->forUpdate(); $q->SELECT($tableid . ' as ID'); $q->SELECT($tagFields); $q->FROM($db->quoteIdentifier($table)); $q->WHERE("{$tableid} IN ({$db->joinQuote((array) $ids)})"); // $q->WHERE("SectionID = 0"); $rows = $db->readAll($q); } else { $runPartials = array(); // perform a SQL statement per partial foreach ($partials as $outPartial) { if (in_array($outPartial->toString(), $runPartials)) { continue; } if ($outPartial['TagRole'] == false) { throw new TagException('Tag partials must specify a role when retrieving tags'); } if ($direction == 'out' && !in_array($outPartial['TagRole'], $outRoles)) { continue; } $unions = array(); foreach ((array) $ids as $id) { $q = new Query(); $q->SELECT($tableid . ' as ID'); $q->SELECT($tagFields); $q->FROM($db->quoteIdentifier($table)); // $q->WHERE("$tableid IN ({$db->joinQuote((array)$ids)})"); $q->WHERE("{$tableid} = {$db->quote($id)}"); // $q->WHERE("SectionID = 0"); if ($direction == 'out') { $q->WHERE($this->getOutTagPartialClause($outPartial, $db, $db->quoteIdentifier($table))); } else { $q->WHERE($this->getInTagPartialClause($outPartial, $originNodeRef->getElement(), $db, $db->quoteIdentifier($table))); } if (!$forceReadWrite && $this->nodeDatabaseTagMergeLimit > 0) { $q->LIMIT($this->nodeDatabaseTagMergeLimit); } $unions[] = '(' . (string) $q . ')'; } $sql = implode(' UNION ALL ', $unions); $rows = array_merge($rows, $db->readAll($sql)); $nonfieldlikeRoles[] = $outPartial['TagRole']; $runPartials[] = $outPartial->toString(); } } } else { $rows = $existingRows; } // if no rows, return empty array if (empty($rows)) { return $rows; } $sortKeys = array(); foreach ($rows as $k => $row) { $sortKeys[$k] = $row['TagSortOrder']; } array_multisort($sortKeys, SORT_ASC, $rows); // gather linked NodeRefs $tagNodeRefs = array(); // $strTagNodeRefs = array(); // $this->Logger->debug('FIELD LIKE PARTIALS'); // $this->Logger->debug($fieldlikePartials); // $this->Logger->debug('NON FIELD LIKE PARTIALS'); // $this->Logger->debug($partials); $existingTagsPerNode = array(); $newrows = array(); $deletedTags = array(); // filter out bogus rows foreach ($rows as $k => $row) { // $rowElement = $this->ElementService->getByID($row['TagElementID']); if (!empty($row['TagElement'])) { $rowElement = $this->ElementService->getBySlug($row['TagElement']); } else { $rowElement = $this->ElementService->getByID($row['TagElementID']); } // element doesn't exist anymore if (empty($rowElement)) { continue; } // error_log($nodeRef); if (!array_key_exists($row['TagRole'], $tagDefs)) { if ($direction == 'in' && $rowElement->getSchema()->hasTagDef($row['TagRole'])) { $row['TagDef'] = $rowElement->getSchema()->getTagDef($row['TagRole']); } else { continue; } // tag definition does not exist } else { $row['TagDef'] = $tagDefs[$row['TagRole']]; } $row['TagElement'] = $rowElement->getSlug(); $row['TagRoleDisplay'] = $row['TagDef']['Title']; $row['TagDirection'] = $direction; //$row['TagLinkRefURL'] = $nodeRef->getRefURL(); // $row['TagSite'] = $nodeRef->getSite()->getSlug(); if (!empty($restrictedPartials)) { foreach ($restrictedPartials as $partial) { if ($this->TagsHelper->matchPartial($partial, $row)) { continue 2; } } } if ($all == false && $allfieldlike == false && !empty($fieldlikePartials) && in_array($row['TagRole'], $fieldlikeRoles)) { // error_log('matching fieldlike'); // error_log(print_r($fieldlikePartials, true)); $found = false; foreach ($fieldlikePartials as $partial) { // error_log('test '.$partial->toString()); if ($this->TagsHelper->matchPartial($partial, $row)) { // error_log('match'); $found = true; break; } } if (!$found) { continue; } } if ($all == false && !empty($partials) && in_array($row['TagRole'], $nonfieldlikeRoles)) { // error_log('matching fieldlike'); $found = false; foreach ($partials as $partial) { // error_log('test '.$partial->toString()); if ($this->TagsHelper->matchPartial($partial, $row)) { // error_log('match'); $found = true; break; } } if (!$found) { continue; } } $nodeRef = new NodeRef($rowElement, $row['TagSlug']); $row['TagLinkNodeRef'] = $nodeRef; $row['NoValidation'] = true; $tag = new Tag($row); if (isset($existingTagsPerNode[$row['ID']]) && array_key_exists($tag->toString(), $existingTagsPerNode[$row['ID']])) { $tagIDToDelete = $existingTagsPerNode[$row['ID']][$tag->toString()]; if ($tagIDToDelete != $tag->TagID) { if ($tag->TagID > $tagIDToDelete) { $tagIDToDelete = $tag->TagID; // If the current tag is being deleted, mark it as deleted so that we can skip the rest of // the processing once it's deleted from the db. $tag->Deleted = true; } else { // We're deleting a tag that was already added to the results array. Therefore just keep track of // it so that we can remove it from the results array later. if ($fixedId) { $deletedTags[$fixedId][] = $tagIDToDelete; } else { $deletedTags[$row['ID']][] = $tagIDToDelete; } } // read repair $this->Logger->debug("Delete {$tag->getTagDirection()} tag: {$tag->toString()}"); $affectedRows = $this->getConnectionForWrite($originNodeRef)->write("DELETE FROM {$db->quoteIdentifier($table)} WHERE TagID = {$db->quote($tagIDToDelete)}"); if ($affectedRows > 0) { $this->NodeEvents->fireTagEvents($direction . 'tags', 'remove', $originNodeRef, $nodeRef, $tag); } // If the current tag is the one that got deleted, we're done processing this tag and can move to // the next. This tag will not get added to the results. if ($tag->Deleted) { continue; } } } $existingTagsPerNode[$row['ID']][$tag->toString()] = $tag->TagID; if ($resolveLinkedRecords) { $tagNodeRefs[] = $nodeRef; // $strTagNodeRefs[$k] = (string)$nodeRef; // if need to merge more tags in if (array_key_exists($row['TagRole'], $childexprPartials)) { // TODO: check partial matches $rowRefKey = $rowElement->getSlug(); $outPartials = $childexprPartials[$row['TagRole']]; foreach ($outPartials as $outPartial) { $expressions = StringUtils::smartSplit($outPartial->getChildPartials(), ".", '"', '\\"', 2); $firstExpression = array_shift($expressions); if (strtolower($firstExpression) == 'meta') { $addlParams[$rowRefKey]['Meta.select'][] = 'all'; } elseif (strtolower($firstExpression) == 'fields') { $addlParams[$rowRefKey]['Meta.select'][] = 'all'; $addlParams[$rowRefKey]['OutTags.select'][] = 'fields'; $addlParams[$rowRefKey]['InTags.select'][] = 'fields'; } else { unset($schemaDef); $isTag = true; try { $jPartial = new TagPartial($firstExpression); $role = $jPartial->getTagRole(); if ($nodeRef->getElement()->getSchema()->hasTagDef($role)) { $schemaDef = $nodeRef->getElement()->getSchema()->getTagDef($role); } else { if ($nodeRef->getElement()->getSchema()->hasMetaDef($role)) { $jPartial = new MetaPartial($firstExpression); $schemaDef = $nodeRef->getElement()->getSchema()->getMetaDef($role); $isTag = false; } } } catch (Exception $e) { $jPartial = new MetaPartial($firstExpression); $role = $jPartial->getMetaName(); if ($nodeRef->getElement()->getSchema()->hasMetaDef($role)) { $schemaDef = $nodeRef->getElement()->getSchema()->getMetaDef($role); } $isTag = false; } if (empty($schemaDef)) { continue; } //throw new NodeException('Cannot retrieve additional nodes for role ['.$role.'], no schema def found on element ['.$rowElement->getSlug().']'); if ($isTag) { $newPartials = $schemaDef->getDirection() == 'out' ? 'OutTags.select' : 'InTags.select'; $jPartial = $jPartial->getTagRole(); } else { $newPartials = 'Meta.select'; $jPartial = $jPartial->getMetaName(); } $new = $firstExpression; if (!empty($expressions[0])) { $new .= '.' . $expressions[0]; } $addlParams[$rowRefKey][$newPartials][] = $new; $jumpParams[$row['TagRole']][$newPartials][] = $jPartial; } } } $newrows[] = $tag; } else { if ($fixedId) { $results[$fixedId][] = $row; } else { $results[$row['ID']][] = $tag; } } } if ($resolveLinkedRecords) { // error_log('PRE NODE RETRIEVE'); // find the corresponding records $nodeRows = array(); $connectionCouplets = $this->getResolvedConnectionCouplets($tagNodeRefs, $forceReadWrite); foreach ($connectionCouplets as $connectionCouplet) { $db = $connectionCouplet->getConnection(); $tableToSlugs = $connectionCouplet->getAttribute('tablesToSlugs'); foreach ($tableToSlugs as $table => $tableInfo) { extract($tableInfo); $rowRefKey = $element->getSlug(); $partialJump = false; $newNodePartials = null; if (array_key_exists($rowRefKey, $addlParams)) { $partialJump = true; $addl = $addlParams[$rowRefKey]; $newNodePartials = new NodePartials(); if (array_key_exists('OutTags.select', $addl)) { $newNodePartials->setOutPartials(implode(',', array_unique($addl['OutTags.select']))); } if (array_key_exists('InTags.select', $addl)) { $newNodePartials->setInPartials(implode(',', array_unique($addl['InTags.select']))); } if (array_key_exists('Meta.select', $addl)) { $newNodePartials->setMetaPartials(implode(',', array_unique($addl['Meta.select']))); } } if ($checkJumpPermissions && !$this->NodePermissions->check('get', $tableNodeRef, $newNodePartials, true)) { continue; } $foundRows = $this->multiGetFromDB($db, $tableid, $table, $tableNodeRef, $slugs, false, $forceReadWrite, false); if ($partialJump && !empty($foundRows)) { $this->Logger->debug('Partials jump on ' . $tableNodeRef->getElement()->getName()); $aoutTags = array(); $ainTags = array(); $ameta = array(); $this->Benchmark->start('partial-jump'); $idField = 'ID'; $pids = ArrayUtils::arrayMultiColumn($foundRows, $idField); if ($newNodePartials->hasOutPartials()) { $aoutTags = $this->findOutTags($db, $tableNodeRef, $pids, $newNodePartials->getOutPartials(), false, false, $checkJumpPermissions); } if ($newNodePartials->hasInPartials()) { $ainTags = $this->findInTags($db, $tableNodeRef, $pids, $newNodePartials->getInPartials(), false, false, $checkJumpPermissions); } if ($newNodePartials->hasMetaPartials()) { $ameta = $this->NodeMetaDAO->findMeta($db, $tableNodeRef, $pids, $newNodePartials->getMetaPartials(), false); } foreach ($foundRows as $nodeRefString => &$nrow) { $nrow->setNodePartials($newNodePartials); $nrow->setMetas(isset($ameta[$nrow[$idField]]) ? $ameta[$nrow[$idField]] : array()); $nrow->setOutTags(isset($aoutTags[$nrow[$idField]]) ? $aoutTags[$nrow[$idField]] : array()); $nrow->setInTags(isset($ainTags[$nrow[$idField]]) ? $ainTags[$nrow[$idField]] : array()); } $this->Benchmark->end('partial-jump'); } $nodeRows = array_merge($nodeRows, $foundRows); } } foreach ($newrows as $row) { // $id = $row['ID']; // unset($row['ID']); // error_log(print_r($row, true)); if ($resolveLinkedRecords) { $nodeRef = $row['TagLinkNodeRef']; if (!array_key_exists((string) $nodeRef, $nodeRows)) { continue; } $tagNode = $nodeRows[(string) $nodeRef]; // if need to filter out jump partials if (array_key_exists($row['TagRole'], $jumpParams)) { $outPartials = $jumpParams[$row['TagRole']]; foreach ($outPartials as $key => $kPartials) { if ($key == 'Meta.select') { foreach ($tagNode->getMetas() as $meta) { if (!in_array($meta->MetaName, $kPartials)) { $tagNode->removeMeta($meta->MetaName); } } } else { if ($key == 'InTags.select') { foreach ($tagNode->getInTags() as $tag) { if (!in_array($tag->TagRole, $kPartials)) { $tagNode->removeInTags($tag->TagRole); } } } else { if ($key == 'OutTags.select') { foreach ($tagNode->getOutTags() as $tag) { if (!in_array($tag->TagRole, $kPartials)) { $tagNode->removeOutTags($tag->TagRole); } } } } } } } // ignore deleted records //if($tagNode['Status'] == 'deleted') // continue; $row['TagLinkNode'] = $tagNode; $row['TagLinkTitle'] = $tagNode['Title']; $row['TagLinkID'] = $tagNode['ID']; $row['TagLinkStatus'] = $tagNode['Status']; $row['TagLinkActiveDate'] = $tagNode['ActiveDate']; $row['TagLinkSortOrder'] = $tagNode['SortOrder']; // only populate TagLinkURL if the record is active if ($tagNode['Status'] == 'published' && $tagNode['ActiveDateUnix'] < $now->toUnix()) { $row['TagLinkIsActive'] = true; $row['TagLinkURL'] = $nodeRef->getRecordLink(); $row['TagLinkURI'] = $nodeRef->getRecordLinkURI(); } else { $row['TagLinkURL'] = ''; } $row['TagLinkURI'] = ''; } if ($fixedId) { $results[$fixedId][] = $row; } else { $results[$row['ID']][] = $row; } } } // If tags were deleted during the 'read repair' they need to be removed from the results array // Go through the nodes that have had tags deleted. If those nodes exist in the results array, go // through the tags being returned. If the tag exists in the 'deleted' array for the node, remove it from // the result set. if (!empty($deletedTags)) { foreach ($deletedTags as $rowId => $rowDeletedTags) { if (isset($results[$rowId]) && !empty($results[$rowId])) { foreach ($results[$rowId] as $resultKey => $rowResults) { if (in_array($rowResults->TagID, $rowDeletedTags)) { unset($results[$rowId][$resultKey]); } } } } } if ($returnOne) { return isset($results[$returnOne]) ? $results[$returnOne] : array(); } return $results; }
protected function getRecordIDFromNodeRef(NodeRef $nodeRef) { if (!$nodeRef->isFullyQualified()) { throw new NodeException('Cannot retrieve record ID without fully-qualified NodeRef'); } $db = $this->getConnectionForWrite($nodeRef); $tableid = $this->NodeDBMeta->getPrimaryKey($nodeRef); $nodes = $this->multiGetFromDB($db, $tableid, $this->NodeDBMeta->getTableName($nodeRef), $nodeRef, (array) $nodeRef->getSlug(), false, true, true); if (empty($nodes)) { throw new NodeException('Node not found for NodeRef: ' . $nodeRef); } $node = current($nodes); return $node['ID']; }
public function findMeta(DatabaseInterface $db, NodeRef $originNodeRef, $ids, $metaPartials = 'fields', $forceReadWrite = false, $restrictedPartials = '') { $results = array(); if (empty($metaPartials)) { return $results; } $this->Logger->debug('findMeta with partials [' . $metaPartials . '] restrict [' . $restrictedPartials . ']'); $returnOne = false; if (!is_array($ids)) { $returnOne = $ids; $ids = array($originNodeRef->getRefURL() => $ids); } $partials = PartialUtils::unserializeMetaPartials($metaPartials); $restrictedPartials = PartialUtils::unserializeMetaPartials($restrictedPartials); if ($restrictedPartials == 'all' || ($x = array_search('all', $restrictedPartials)) !== false) { return array(); } $tableid = $this->NodeDBMeta->getPrimaryKey($originNodeRef); $now = $this->DateFactory->newLocalDate(); $metaPartials = array(); $all = false; $metaDefs = $originNodeRef->getElement()->getSchema()->getMetaDefs(); $metaSchemas = $originNodeRef->getElement()->getSchema()->getMetaStorageDatatypes(); if ($partials == 'all' || ($x = array_search('all', $partials)) !== false) { if ($partials == 'all' || isset($x) && $x !== false) { $all = true; if (is_array($partials)) { unset($partials[$x]); } else { $partials = array(); } } } foreach ($partials as $z => $metaPartial) { if (!array_key_exists($metaPartial->getMetaName(), $metaDefs)) { unset($partials[$z]); continue; } $metaPartials[] = $metaPartial; } $rows = array(); $cachedIds = array(); // retrieve from cache list($cachedIds, $rows) = $this->NodeCache->getMeta('', $ids, $forceReadWrite); $remainingIds = array_diff($ids, $cachedIds); if (!empty($remainingIds)) { $dbToCacheRows = array(); // perform a SQL statement per partial foreach ($metaSchemas as $datatype) { $table = $this->NodeDBMeta->getMetaTable($originNodeRef, $datatype); $q = new Query(); $q->SELECT($tableid . ' as ID'); $q->SELECT(array('Name as MetaName')); if (($datatypeCol = $this->NodeDBMeta->getMetaDatatypeColumn($datatype)) != null) { $q->SELECT("{$datatypeCol}Value as MetaValue"); } $q->FROM($db->quoteIdentifier($table)); $q->WHERE("{$tableid} IN ({$db->joinQuote((array) $remainingIds)})"); $dbRows = $this->getConnectionForWrite($originNodeRef)->readAll($q); foreach ($dbRows as $row) { $dbToCacheRows[$row['ID']][] = $row; $rows[] = $row; } unset($dbRows); unset($datatype); unset($q); unset($table); } $this->NodeCache->putMeta('', $remainingIds, $dbToCacheRows, $forceReadWrite); unset($dbToCacheRows); unset($remainingIds); unset($metaSchemas); } foreach ($rows as $row) { $id = $row['ID']; unset($row['ID']); if (!array_key_exists($row['MetaName'], $metaDefs)) { continue; } foreach ($restrictedPartials as $dPartial) { if (strcmp($dPartial->getMetaName(), $row['MetaName']) === 0) { continue 2; } } if (!$all) { $found = false; foreach ($metaPartials as $dPartial) { if (strcmp($dPartial->getMetaName(), $row['MetaName']) === 0) { $found = true; break; } } if (!$found) { continue; } } $metaDef = $metaDefs[$row['MetaName']]; $row['MetaTitle'] = $metaDef->Title; $row['MetaStorageDatatype'] = (string) $metaDef->Datatype; $row['MetaValidationDatatype'] = $metaDef->Validation->getDatatype(); if ($row['MetaValidationDatatype'] == 'date') { $row['MetaValue'] = $this->TypeConverter->convertFromString($metaDef->Validation, $row['MetaValue'], null, true); } else { if ($row['MetaStorageDatatype'] == 'flag') { $row['MetaValue'] = 1; } } $row['NoValidation'] = true; $results[$id][$row['MetaName']] = new Meta($row); } if ($returnOne) { return isset($results[$returnOne]) ? $results[$returnOne] : array(); } return $results; }
public function rename(NodeRef $nodeRef, $newSlug) { $newNodeRef = new NodeRef($nodeRef->getElement(), $node->getSlug()); $this->NodePermissions->checkThrow(__FUNCTION__, $nodeRef, $newNodeRef, false); return parent::rename($nodeRef, $newSlug); }
/** * {@inheritdoc} */ public function deleteTags($direction, NodeRef $nodeRef, NodeRef $nodeRef2, $localOnly = false) { $oppositeTagDirection = $direction == 'out' ? 'in' : 'out'; $this->delete('node-' . $direction . '-tags-' . $nodeRef->getRefURL(), $localOnly); $this->delete('node-' . $oppositeTagDirection . '-tags-' . $nodeRef2->getRefURL(), $localOnly); $this->keysToDelete[] = 'node-' . $direction . '-tags-' . $nodeRef->getRefURL(); $this->keysToDelete[] = 'node-' . $oppositeTagDirection . '-tags-' . $nodeRef2->getRefURL(); }
public function replace() { $this->checkNonce(); if (empty($this->params['Title'])) { throw new Exception('Title parameter is required', 210); } if (empty($this->params['ElementSlug'])) { throw new Exception('ElementSlug parameter is required', 220); } $title = $this->params['Title']; $slug = SlugUtils::createSlug($title); $noderef = new NodeRef($this->ElementService->getBySlug($this->Request->getParameter('ElementSlug')), $slug); // create node $node = $noderef->generateNode(); $this->NodeMapper->defaultsOnNode($node); $node->Title = $title; $node->Slug = $slug; $this->getErrors()->throwOnError(); // edit existing record if ($this->RegulatedNodeService->refExists($noderef)) { $existing = $this->RegulatedNodeService->getByNodeRef($noderef); $existing->setNodePartials($node->getNodePartials()); $existing->setMetas($node->getMetas()); $existing->setOutTags($node->getOutTags()); $node = $this->RegulatedNodeService->edit($node); //create new record } else { $node = $this->RegulatedNodeService->quickAdd($node); } $node = $this->RegulatedNodeService->getByNodeRef($node->getNodeRef(), new NodePartials()); $this->bindToActionDatasource(array($node)); return new View($this->successView()); }
public function generateNodeRef(NodeRef $nodeRef, $title = null, $useTime = false) { if (is_null($nodeRef)) { throw new NodeException('Cannot generate NodeRef, $nodeRef is null'); } $slug = $nodeRef->getSlug(); if (empty($slug)) { if (empty($title)) { throw new NodeException('Cannot generate NodeRef without title'); } if ($useTime) { $slug = SlugUtils::createSlug(substr($title, 0, 237) . '-' . floor(microtime(true) * 100), $nodeRef->getElement()->isAllowSlugSlashes()); } else { $slug = SlugUtils::createSlug(substr($title, 0, 255), $nodeRef->getElement()->isAllowSlugSlashes()); } $nodeRef = new NodeRef($nodeRef->getElement(), $slug); } else { if ($useTime) { $title = substr($slug, 0, 237) . '-' . floor(microtime(true) * 100); } else { $title = substr($slug, 0, 255); } $nodeRef = new NodeRef($nodeRef->getElement(), SlugUtils::createSlug($title, $nodeRef->getElement()->isAllowSlugSlashes())); } return $nodeRef; }
public function getPrimaryKey(NodeRef $nodeRef) { return 'Table' . StringUtils::camelize($nodeRef->getElement()->Slug . 'ID'); }
public function migrateInTags(NodeRef $sourceRef, $mergeSlug, $limit = null) { $targetRef = new NodeRef($sourceRef->getElement(), $mergeSlug); $sourceNode = $this->NodeService->getByNodeRef($sourceRef, new NodePartials('', '', 'all')); $batchSize = 1000; $inTags = $sourceNode->getInTags(); //Get the schema to ensure tags are removed from the element in which they were defined. $schema = $sourceRef->getElement()->getSchema(); $tagsMigrated = 0; while ($inTags && ($limit === null || $tagsMigrated < $limit)) { //while array is not empty $inTag = array_pop($inTags); if ($schema->hasTagDef($inTag->TagRole)) { // If the InTag exists in the source element schema // remove it from the source node and tag add it to the target node $this->NodeService->removeInTag($sourceRef, $inTag); $this->NodeService->addInTag($targetRef, $inTag); } else { // If the InTag does not exist in the source element schema // its converse OutTag must exist in the tagged node element schema // Remove OutTag from the tagged node and create a new OutTag to the targetNode $taggedNodeRef = $inTag->TagLinkNode->getNodeRef(); $outTag = new Tag($sourceRef, $sourceRef->getSlug(), $inTag->TagRole); $this->NodeService->removeOutTag($taggedNodeRef, $outTag); $mergeOutTag = new Tag($targetRef, $targetRef->getSlug(), $inTag->TagRole); $this->NodeService->addOutTag($taggedNodeRef, $mergeOutTag); } $tagsMigrated++; if ($tagsMigrated % $batchSize == 0) { $this->TransactionManager->commit()->begin(); } } $this->TransactionManager->commit()->begin(); return $tagsMigrated; }