public function replace(Node $node)
 {
     if (!$node->getNodeRef()->isFullyQualified()) {
         return $this->add($node);
     }
     if ($this->refExists($node->getNodeRef())) {
         return $this->edit($node);
     } else {
         return $this->add($node);
     }
 }
 public function loadAudioTagsCms($nothing, $nothing, Node $node)
 {
     if ($node->getNodePartials()->getOutPartials() != "") {
         $tagDefs = $node->getNodeRef()->getElement()->Schema->getTagDefs();
         foreach ($tagDefs as $k => $tagDef) {
             if ($tagDef->Partial->TagAspect == 'audio') {
                 $node->getNodePartials()->increaseOutPartials('#' . $tagDef->Partial->TagRole . '.#original.#url');
             }
         }
     }
 }
 public function loadImageTagsThumbnailsCms($nothing, $nothing, Node $node)
 {
     return;
     if ($node->getNodePartials()->getOutPartials() != "") {
         $tagDefs = $node->getNodeRef()->getElement()->Schema->getTagDefs();
         foreach ($tagDefs as $k => $tagDef) {
             if ($tagDef->Partial->TagAspect == 'images') {
                 $node->getNodePartials()->increaseOutPartials('#' . $tagDef->Partial->TagRole . '.#thumbnails.#url,#' . $tagDef->Partial->TagRole . '.#thumbnails.#width,#' . $tagDef->Partial->TagRole . '.#thumbnails.#height');
             }
         }
     }
 }
 public function edit(Node $node)
 {
     $existingNode = $this->getByNodeRef($node->getNodeRef());
     $this->NodePermissions->checkThrow(__FUNCTION__, $node->getNodeRef(), $node, false);
     if ($node->getNodeRef()->getSlug() != $node->getSlug()) {
         $newNodeRef = new NodeRef($node->getNodeRef()->getElement(), $node->getSlug());
         $this->NodePermissions->checkThrow('rename', $node->getNodeRef(), $newNodeRef, false);
     }
     if ($existingNode->Status == 'deleted' && $node->Status != 'deleted') {
         return $this->undelete($node->getNodeRef());
     }
     if ($existingNode->Status != 'deleted' && $node->Status == 'deleted') {
         return $this->delete($node->getNodeRef());
     }
     if ($existingNode->Status != 'published' && $node->Status == 'published') {
         $this->NodePermissions->checkThrow('publish', $node->getNodeRef(), $node, false);
     }
     if ($existingNode->Status == 'published' && $node->Status != 'published') {
         $this->NodePermissions->checkThrow('unpublish', $node->getNodeRef(), $node, false);
     }
     return parent::edit($node);
 }
Example #5
0
 protected function editInternal(Node $node)
 {
     $existingNode = $this->NodeLookupDAO->getByNodeRef($node->getNodeRef());
     $this->Logger->debug('Editing node [' . $node->getNodeRef() . '] with partials [' . $node->getNodePartials() . ']');
     // update the record
     $primaryKey = $this->NodeDBMeta->getPrimaryKey($node->getNodeRef());
     $id = $existingNode->getID();
     $node->{$primaryKey} = $id;
     $node->ID = $id;
     $db = $this->getConnectionForWrite($node->getNodeRef());
     $oldArray = $this->NodeMapper->nodeToPersistentArray($existingNode);
     $newArray = $this->NodeMapper->nodeToPersistentArray($node);
     // save meta
     $changedMeta = $this->NodeMetaDAO->saveMeta($db, $node->getNodeRef(), $id, $node->getNodePartials()->getMetaPartials(), $node->getMetas(), $node->getNodePartials()->getRestrictedMetaPartials());
     // save the tags
     $changedOut = $this->NodeTagsDAO->saveOutTags($db, $node->getNodeRef(), $id, $node->getNodePartials()->getOutPartials(), $node->getOutTags(), $node->getNodePartials()->getRestrictedOutPartials());
     $changedIn = $this->NodeTagsDAO->saveInTags($db, $node->getNodeRef(), $id, $node->getNodePartials()->getInPartials(), $node->getInTags(), $node->getNodePartials()->getRestrictedInPartials());
     if (array_intersect_key($oldArray, $newArray) != $newArray) {
         $newArray['ModifiedDate'] = $this->DateFactory->newStorageDate();
         $node->ModifiedDate = $newArray['ModifiedDate'];
         $db->updateRecord($db->quoteIdentifier($this->NodeDBMeta->getTableName($node->getNodeRef())), $newArray, "{$primaryKey} = {$db->quote($id)}");
     }
 }
 protected function validateMetas(Node $node, Node $obj, NodeSchema $schema, $mode)
 {
     $processed_metas = array();
     $metas = $obj->getMetas();
     // Check all metas passed against the meta defs.
     foreach ($metas as $meta) {
         // Ensure the meta has a meta_def
         $meta_def = $schema->getMetaDef($meta->getMetaName());
         $this->getErrors()->rejectIfInvalid($this->resolveField($node->getNodeRef(), $meta->getMetaName(), $obj instanceof Section ? $obj : null), 'meta', $meta_def->Title, $meta->getValue(), $meta_def->Validation);
         $processed_metas[] = $meta->getMetaName();
     }
     $meta_defs = $schema->getMetaDefs();
     // Check all meta defs that haven't been processed
     // These meta defs must only match partials that we have.
     $meta_partials = PartialUtils::unserializeMetaPartials($node->getNodePartials()->getMetaPartials());
     $re_meta_partials = PartialUtils::unserializeMetaPartials($node->getNodePartials()->getRestrictedMetaPartials());
     foreach ($meta_defs as $meta_def) {
         if (in_array($meta_def->Id, $processed_metas)) {
             continue;
         }
         if ($mode == 'edit' && !$this->metaInScope($schema, new Meta($meta_def->Id, ''), $meta_partials, $re_meta_partials)) {
             continue;
         }
         // Validate the meta def with a null value
         $this->getErrors()->rejectIfInvalid($this->resolveField($node->getNodeRef(), $meta_def->Id, $obj instanceof Section ? $obj : null), 'meta', $meta_def->Title, null, $meta_def->Validation);
         $processed_metas[] = $meta_def->Id;
     }
 }
 public function defaultsOnNode(Node &$node)
 {
     foreach ($this->NodeDBMeta->getPersistentFields() as $key) {
         $default = $this->NodeDBMeta->getDefault($key);
         if ($default != null && !isset($node->{$key})) {
             $node->{$key} = $this->TypeConverter->convertFromString($this->NodeDBMeta->getValidationExpression($key), $default);
         }
     }
     $metaDefs = $node->getNodeRef()->getElement()->getSchema()->getMetaDefs();
     foreach ($metaDefs as $metaDef) {
         $default = $metaDef->Default;
         if ($default != null && !$node->hasMeta($metaDef->Id)) {
             $node->setMeta($metaDef->Id, $this->TypeConverter->convertFromString($metaDef->Validation, $default));
         }
     }
 }
 protected function convertMeta(Node $node, NodeSchema &$schema, Errors &$errors, $name, $value, $rawValue)
 {
     $meta_def = $schema->getMetaDef($name);
     $validation = $meta_def->Validation->getValidationArray();
     $key = $meta_def->Id;
     $fieldTitle = $meta_def->Title;
     try {
         $value = $this->TypeConverter->convertFromString($meta_def->Validation, $value, $rawValue);
     } catch (TypeConversionException $tce) {
         $errors->addFieldError('invalid', $this->NodeValidator->resolveField($node->getNodeRef(), $key), 'field', $fieldTitle, $value, $tce->getMessage());
     }
     return $value;
 }
 public function loadNonFieldLike($nothing, $nothing, Node &$node)
 {
     $tagDefs = $node->getNodeRef()->getElement()->Schema->getTagDefs();
     foreach ($tagDefs as $k => $tagDef) {
         if (!$tagDef->isFieldlike()) {
             $params = $this->Request->getParameters();
             $direction = ucfirst($tagDef->Direction);
             $tagsArray = array();
             $hashed = '#' . ltrim($tagDef->Id, '#');
             if (array_key_exists($direction . 'Tags', $params) && is_array($params[$direction . 'Tags']) && array_key_exists($hashed, $params[$direction . 'Tags']) && is_array($params[$direction . 'Tags'][$hashed])) {
                 $tags = $params[$direction . 'Tags'][$hashed];
                 foreach ((array) $tags as $key => $tag) {
                     $tagsArray[] = new Tag($tag);
                 }
             }
             if ($direction == 'In') {
                 foreach ($tagsArray as $tag) {
                     $node->addInTag($tag);
                 }
             } else {
                 foreach ($tagsArray as $tag) {
                     $node->addOutTag($tag);
                 }
             }
         }
     }
 }
 /**
  * Build Node JSON structure with thumbnail information.
  */
 protected function _buildNodeJSON(Node $node, $includeOriginal = false, $includeThumbnails = false)
 {
     $data = new stdClass();
     $data->slug = $node->Slug;
     $data->element = $node->Element->Slug;
     $data->title = $node->Title;
     $data->status = $node->Status;
     $data->activeDate = $node->ActiveDate;
     $data->recordLink = $node->RecordLink;
     $data->sortOrder = $node->SortOrder;
     if ($includeOriginal) {
         $nodeRef = $node->getNodeRef();
         if ($nodeRef->getElement()->hasAspect('images') || $nodeRef->getElement()->hasAspect('temporary-zipped-media')) {
             // Build the original and thumbnail info as well
             foreach (array('url', 'size', 'width', 'height') as $f) {
                 $data->{$f} = $node->jump("#original.#{$f}");
                 if (is_numeric($data->{$f})) {
                     $data->{$f} = intval($data->{$f});
                 }
             }
         } else {
             // Include the URL for non image media
             $data->url = $node->jump("#original.#url");
         }
     }
     $json = $node->getMetaValue('#thumbnails-json');
     if ($json != null) {
         $thumbnails = JSONUtils::decode($json);
         if ($includeThumbnails) {
             $data->thumbnails = $thumbnails;
             $data->thumbnailsPending = (array) $this->_getPendingThumbnails($node->getElement()->getSlug(), $thumbnails);
         }
         foreach ($thumbnails as $thmb) {
             if ($thmb->value == $this->imagesThumbnailCmsSize) {
                 $data->thumbnailUrl = $thmb->url;
                 break;
             }
         }
     }
     return $data;
 }
 /**
  * Replaces the file associated with the file node then updates the node.
  *
  * @param Node $fileNode
  * @param Element $parentElement
  * @param string $newFile Full path to the new file
  * @param string $newFileName the new desired filename
  * @return Node
  */
 protected function replaceNodeFile(Node $fileNode, Element $parentElement, $newFile, $newFileName)
 {
     // get storage facility
     $fileElement = $fileNode->getNodeRef()->getElement();
     list($storageFacility, $sfParams) = $this->deriveStorageFacility($fileElement);
     $oldId = $fileNode->Title;
     // add the new file
     $newId = $storageFacility->findUniqueFileID($sfParams, $this->buildFilename($newFileName));
     $file = new StorageFacilityFile($newId, $newFile);
     $file = $storageFacility->putFile($sfParams, $file);
     // set the new id as title
     $fileNode->Title = $file->getID();
     // get metrics
     list($width, $height) = ImageUtils::getImageDimensions($newFile);
     // and mime-type
     $mimetype = FileSystemUtils::getMimetype($file->getExtension());
     // update the meta fields
     $fileNode->setMeta('#url', $file->getURL());
     $fileNode->setMeta('#mimetype', $mimetype);
     $fileNode->setMeta('#size', filesize($newFile));
     $fileNode->setMeta('#width', $width);
     $fileNode->setMeta('#height', $height);
     $fileNode->setMeta('#parent-element', $parentElement->Slug);
     // do the update
     $this->RegulatedNodeService->edit($fileNode);
     // if different ID, we need to remove old file,
     // but first make sure new record is committed
     if ($oldId != $newId) {
         // force commit changes
         $this->TransactionManager->commit()->begin();
         // delete existing file
         $storageFacility->deleteFile($sfParams, $oldId);
     }
     return $fileNode;
 }
 public function resolveLinkedNodes(Node $node, NodePartials $nodePartials = null, $forceReadWrite = true, $checkJumpPermissions = false)
 {
     $node->OutTags = $this->NodeTagsDAO->findOutTags(null, $node->getNodeRef(), null, $nodePartials->getOutPartials(), $forceReadWrite, $checkJumpPermissions, $nodePartials->getRestrictedOutPartials(), true, $node->OutTags);
     $node->InTags = $this->NodeTagsDAO->findInTags(null, $node->getNodeRef(), null, $nodePartials->getInPartials(), $forceReadWrite, $checkJumpPermissions, $nodePartials->getRestrictedInPartials(), true, $node->InTags);
     return $node;
 }