Detaches this model from its old parent
and attaches to the new one.
@param AuthItem $oldParent item
@param AuthItem $newParent item
@return boolean whether model has been moved.
556471
public function move($oldParent, $newParent)
    {
        return $oldParent->removeChild($this)
            ? $newParent->addChild($this)
            : false;
    }
239509
protected void setParent(Node newParent, boolean removeDep) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "setParent entry: new parent will be: " + newParent + " for node: " + this);
        }

        Node oldParent = parent;

        parent = newParent;
        if (newParent != null) {
            parent.addDependent(this);
        }

        // removing dependents can cause ConcurrentModificationException if calling is iterating over a list of dependent nodes
        // therefore removeDep should be false if setParent is being called while iterating or looping over a list of
        // dependent nodes.
        if (removeDep) {
            // remove this node from the old parents list of dependents.
            if (oldParent != null) {
                if (newParent == null) {
                    oldParent.removeDependent(this);
                } else if (oldParent.getStreamID() != parent.getStreamID()) {
                    oldParent.removeDependent(this);
                }
            }
        }
    }
1362288
public function handle($old, $new)
    {
        if ( ! $this->canHandle($old) || ! $this->canHandle($new)) {
            return null;
        }

        if (((string) $new->getReturnType())) {
            return false;
        }

        if (((string) $new->getReturnType()) == ((string) $old->getReturnType())) {
            return false;
        }

        $this->lastException = new FailedConstraint(
            sprintf(
                '%s::%s() return type "%s" were removed',
                $old->getAttribute('parent')->namespacedName,
                $old->name,
                $old->getReturnType(),
                $new->getReturnType()
            )
        );

        return true;
    }
1224936
public function compareChecks(Check $oldCheck, Check $newCheck)
    {
        return ($oldCheck->getName() !== $newCheck->getName())
            || ($oldCheck->getDefinition() !== $newCheck->getDefinition());
    }
1106203
protected function move($position = null, $siblings = [], $oldParentId)
    {
        $class = $this->className;
        if (null === $oldParent = $class::findOne($oldParentId)) {
            return ['error' => Yii::t('jstw', "Old parent with id '{id}' not found!", ['id' => $oldParentId])];
        }
        $nodeCountCondition = [
            'and',
            ['>=', $this->leftAttribute, $this->node{$this->leftAttribute}],
            ['<=', $this->rightAttribute, $this->node{$this->rightAttribute}]
        ];
        $this->applyRootCondition($nodeCountCondition);
        $nodeChildren = $this->getChildIds($nodeCountCondition);
        $siblingsDelta = count($nodeChildren) * 2;
        if ($position == 0) {
            $compareRight = $this->parent->{$this->leftAttribute} + 1;
        } else {
            if (false === isset($siblings[$position - 1])) {
                return ['error' => Yii::t('jstw', 'New previous sibling does not exist')];
            }
            $newPrevSiblingId = $siblings[$position - 1];
            $newPrevSiblingData = $this->getLr($newPrevSiblingId);
            $compareRight = $newPrevSiblingData[$newPrevSiblingId][$this->rightAttribute];
        }
        if ($this->node->{$this->leftAttribute} > $compareRight) {
            //move node up
            if ($position == 0) {
                $leftFrom = $compareRight;
            } else {
                $leftFrom = $compareRight + 1;
            }
            $rightTo = $this->node->{$this->leftAttribute};
            $nodeDelta = $this->node->{$this->leftAttribute} - $leftFrom;
            $nodeOperator = '-';
            $parentOperator = $siblingsOperator = '+';
            $newParentUpdateField = $this->rightAttribute;
            $oldParentUpdateField = $this->leftAttribute;
        } else if ($this->node->{$this->leftAttribute} < $compareRight) {
            //move node down
            $leftFrom = $this->node->{$this->rightAttribute};
            if ($position == 0) {
                $rightTo = $compareRight - 1;
            } else {
                $rightTo = $compareRight;
            }
            $nodeOperator = '+';
            $parentOperator = $siblingsOperator = '-';
            $nodeDelta = $rightTo - $siblingsDelta + 1 - $this->node->{$this->leftAttribute};
            $newParentUpdateField = $this->leftAttribute;
            $oldParentUpdateField = $this->rightAttribute;
        } else {
            return ['error' => Yii::t('jstw', 'There are two nodes with same "left" value. This should not be.')];
        }
        $siblingsCondition = [
            'and',
            ['>=', $this->leftAttribute, $leftFrom],
            ['<=', $this->rightAttribute, $rightTo]
        ];
        $this->applyRootCondition($siblingsCondition);
        $db = Yii::$app->getDb();
        $transaction = $db->beginTransaction();
        $oldParentDepth = $oldParent->{$this->depthAttribute};
        $newParentDepth = $this->parent->{$this->depthAttribute};
        if ($newParentDepth < $oldParentDepth) {
            $depthOperator = '-';
            $depthDelta = $oldParentDepth - $newParentDepth;
        } else {
            $depthOperator = '+';
            $depthDelta = $newParentDepth - $oldParentDepth;
        }
        $commonParentsCondition = [
            'and',
            ['<', $this->leftAttribute, $leftFrom],
            ['>', $this->rightAttribute, $rightTo]
        ];
        $this->applyRootCondition($commonParentsCondition);
        $commonParentsIds = $class::find()->select('id')->where($commonParentsCondition)->column();
        $commonCondition = [
            ['!=', $this->depthAttribute, 0],
            ['not in', 'id', $commonParentsIds],
        ];
        $this->applyRootCondition($commonCondition);
        $newParentCondition = array_merge([
            'and',
            ['<=', $this->leftAttribute, $this->parent->{$this->leftAttribute}],
            ['>=', $this->rightAttribute, $this->parent->{$this->rightAttribute}],
        ], $commonCondition);
        $oldParentsCondition = array_merge([
            'and',
            ['<', $this->leftAttribute, $this->node->{$this->leftAttribute}],
            ['>', $this->rightAttribute, $this->node->{$this->rightAttribute}],
        ], $commonCondition);
        try {
            //updating necessary node siblings
            $db->createCommand()->update(
                $class::tableName(),
                [
                    $this->leftAttribute => new Expression($this->leftAttribute . sprintf('%s%d', $siblingsOperator, $siblingsDelta)),
                    $this->rightAttribute => new Expression($this->rightAttribute . sprintf('%s%d', $siblingsOperator, $siblingsDelta)),
                ],
                $siblingsCondition
            )->execute();
            //updating old parents
            $db->createCommand()->update(
                $class::tableName(),
                [
                    //down - right
                    $oldParentUpdateField => new Expression($oldParentUpdateField . sprintf('%s%d', $parentOperator, $siblingsDelta)),
                ],
                $oldParentsCondition
            )->execute();
            //updating new parents
            $db->createCommand()->update(
                $class::tableName(),
                [
                    //down - left
                    $newParentUpdateField => new Expression($newParentUpdateField . sprintf('%s%d', $parentOperator, $siblingsDelta)),
                ],
                $newParentCondition
            )->execute();
            //updating node with children
            $db->createCommand()->update(
                $class::tableName(),
                [
                    $this->leftAttribute => new Expression($this->leftAttribute . sprintf('%s%d', $nodeOperator, $nodeDelta)),
                    $this->rightAttribute => new Expression($this->rightAttribute . sprintf('%s%d', $nodeOperator, $nodeDelta)),
                    $this->depthAttribute => new Expression($this->depthAttribute . sprintf('%s%d', $depthOperator, $depthDelta)),
                ],
                ['id' => $nodeChildren]
            )->execute();
            $transaction->commit();
        } catch (\Exception $e) {
            $transaction->rollBack();
            return ['error' => $e->getMessage()];
        }
        return true;
    }
809915
public function removeParent(ItemAbstract $pItem)
    {
        if (! $pItem->getId()) {
            throw new Exception("addParent: Parent must exist in database");
        }

        $parentsValue = $this->getFieldValue($pItem->getIdField(), true);
        if (! $parentsValue) {
            $parents = array();
        } else {
            $parents = explode(',', $parentsValue);
        }

        $key = array_search($pItem->getId()->getOrig(), $parents);
        if ($key !== false) {
            unset($parents[$key]);
        }

        if (empty($parents)) {
            $this->_fields[$pItem->getIdField()] = NULL;
        } else {
            $this->_fields[$pItem->getIdField()] = implode(',', $parents);
        }

        return $this;
    }
1332393
public function updateNodeAssignment($contentObjectId, $oldParent, $newParent, $opcode)
    {
        $query = $this->handler->createUpdateQuery();
        $query
            ->update($this->handler->quoteTable('eznode_assignment'))
            ->set(
                $this->handler->quoteColumn('parent_node'),
                $query->bindValue($newParent, null, \PDO::PARAM_INT)
            )
            ->set(
                $this->handler->quoteColumn('op_code'),
                $query->bindValue($opcode, null, \PDO::PARAM_INT)
            )
            ->where(
                $query->expr->lAnd(
                    $query->expr->eq(
                        $this->handler->quoteColumn('contentobject_id'),
                        $query->bindValue($contentObjectId, null, \PDO::PARAM_INT)
                    ),
                    $query->expr->eq(
                        $this->handler->quoteColumn('parent_node'),
                        $query->bindValue($oldParent, null, \PDO::PARAM_INT)
                    )
                )
            );
        $query->prepare()->execute();
    }
917409
public boolean insertBefore(final Node newNode, final Node oldNode) {
        if (oldNode == null || newNode == null) {
            return false;
        }

        int index = nodes.indexOf(oldNode);
        if (index != -1) {
            // Remove the parent from the new node if one exists
            if (newNode.getParent() != null) {
                newNode.removeParent();
            }
            newNode.setParent(this);
            // Add the node to the relevant list
            if (newNode instanceof Level) {
                levels.add((Level) newNode);
            } else if (newNode instanceof SpecTopic) {
                topics.add((SpecTopic) newNode);
            }
            // Insert the node
            if (index == 0) {
                nodes.addFirst(newNode);
            } else {
                nodes.add(index - 1, newNode);
            }
            return true;
        } else {
            return false;
        }
    }
197627
public function setParent($parent){

            $this->parent = $parent;

            if($this->parentCallback){
                call_user_func($this->parentCallback);
            }

            return $this;

        }
1009627
public function replace(DOMElement &$old, &$new)
    {
        // Check if the element has a parent node
        if (empty($old->parentNode)) {
            throw new DOMException('The current DOMItem has no parent.');
        }

        // Replace the element
        $old->parentNode->replaceChild($new, $old);

        return $new;
    }
161791
public function setParent($parent) {
		if (! is_object($parent)) {
			throw new WrongParent('Parent of a helper must be an object, "' . gettype($parent) . '" was given');
		}
		
		$this->_parent = $parent;
		
		return $this;
	}
941330
public function updateNodeAssignment($contentObjectId, $oldParent, $newParent, $opcode)
    {
        try {
            return $this->innerGateway->updateNodeAssignment($contentObjectId, $oldParent, $newParent, $opcode);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
28710
public function replaceReconstitutedEntity($oldEntity, $newEntity)
    {
        $this->reconstitutedEntities->detach($oldEntity);
        $this->reconstitutedEntities->attach($newEntity);
    }
1086609
public function handOffPrimary()
    {
        foreach (['child', 'parent'] as $role) {
            if (!$this->handlePrimary($role)) {
                continue;
            }
            if ($this->owner->isPrimary($role) || $this->owner->wasPrimary[$role]) {
                // assign a new primary
                $siblings = $this->getSiblings($role, false);
                if (!empty($siblings)) {
                    $sibling = array_shift($siblings);
                    $sibling->setPrimary($role);
                }
            }
        }

        return true;
    }
772774
public function update($old, $new): bool
    {
        if ($this->hasNot($old)) {
            return false;
        }

        $this->set($old, $new);

        return true;
    }
547506
protected function performMakeChildOf(Node $node, Node $newParent)
    {

        $parentIdName = $this->getParentIdName();
        $rootIdName = $this->getRootIdName();

        // The node is already a child of newParent
        if ( ($node->getParentId()== $newParent->getId()) && $node->exists ) {
            return $this;
        }

        // Copy foreign keys
        $node[$parentIdName] = $newParent->getId();
        $node[$rootIdName] = $newParent[$rootIdName];

        // Set in-memory relations
        $node->setParent($newParent);
        $newParent->addChild($node);

        return $this;

    }
1225356
public function getMoveEventChangeSet(Section $oldParent, $oldLeft, Section $newParent)
    {
        /* Create change set for move log event
         * If section's parent has changed, return old and new parent
         * Otherwise return old and new left to mark move up or down in the same parent
         */
        $newLeft = $this->getLeft();
        $changeSet = [
            'parentId' => [$oldParent->getId(), $newParent->getId()],
            'parentName' => [$oldParent->getActiveContribution()->getTitle(), $newParent->getActiveContribution()->getTitle()],
            'isParentRoot' => [$oldParent->isRoot(), $newParent->isRoot()],
            'left' => [$oldLeft, $newLeft],
        ];

        return $changeSet;
    }