Jackalope\ObjectManager::refresh PHP Method

refresh() public method

Refresh cached items from the backend.
See also: Session::refresh()
public refresh ( boolean $keepChanges )
$keepChanges boolean whether to keep local changes or discard them.
    public function refresh($keepChanges)
    {
        if (!$keepChanges) {
            // revert all scheduled add, remove and move operations
            $this->operationsLog = array();
            foreach ($this->nodesAdd as $path => $operation) {
                if (!$operation->skip) {
                    $operation->node->setDeleted();
                    unset($this->objectsByPath['Node'][$path]);
                    // did you see anything? it never existed
                }
            }
            $this->nodesAdd = array();
            // the code below will set this to dirty again. but it must not
            // be in state deleted or we will fail the sanity checks
            foreach ($this->propertiesRemove as $path => $operation) {
                $operation->property->setClean();
            }
            $this->propertiesRemove = array();
            foreach ($this->nodesRemove as $path => $operation) {
                $operation->node->setClean();
                $this->objectsByPath['Node'][$path] = $operation->node;
                // back in glory
                $parentPath = PathHelper::getParentPath($path);
                if (array_key_exists($parentPath, $this->objectsByPath['Node'])) {
                    // tell the parent about its restored child
                    $this->objectsByPath['Node'][$parentPath]->addChildNode($operation->node, false);
                }
            }
            $this->nodesRemove = array();
            foreach (array_reverse($this->nodesMove) as $operation) {
                if (isset($this->objectsByPath['Node'][$operation->dstPath])) {
                    // not set if we moved twice
                    $item = $this->objectsByPath['Node'][$operation->dstPath];
                    $item->setPath($operation->srcPath);
                }
                $parentPath = PathHelper::getParentPath($operation->dstPath);
                if (array_key_exists($parentPath, $this->objectsByPath['Node'])) {
                    // tell the parent about its restored child
                    $this->objectsByPath['Node'][$parentPath]->unsetChildNode(PathHelper::getNodeName($operation->dstPath), false);
                }
                // TODO: from in a two step move might fail. we should merge consecutive moves
                $parentPath = PathHelper::getParentPath($operation->srcPath);
                if (array_key_exists($parentPath, $this->objectsByPath['Node']) && isset($item) && $item instanceof Node) {
                    // tell the parent about its restored child
                    $this->objectsByPath['Node'][$parentPath]->addChildNode($item, false);
                }
                // move item to old location
                $this->objectsByPath['Node'][$operation->srcPath] = $this->objectsByPath['Node'][$operation->dstPath];
                unset($this->objectsByPath['Node'][$operation->dstPath]);
            }
            $this->nodesMove = array();
        }
        $this->objectsByUuid = array();
        /** @var $node Node */
        foreach ($this->objectsByPath['Node'] as $node) {
            if (!$keepChanges || !($node->isDeleted() || $node->isNew())) {
                // if we keep changes, do not restore a deleted item
                $this->objectsByUuid[$node->getIdentifier()] = $node->getPath();
                $node->setDirty($keepChanges);
            }
        }
    }

Usage Example

コード例 #1
0
ファイル: Session.php プロジェクト: frogriotcom/jackalope
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function refresh($keepChanges)
 {
     $this->objectManager->refresh($keepChanges);
 }