Add an object if it does not exist.

@param string $alias
@param int $parent_id
@return int
771481
public function addObject($alias, $parent_id = null) {
        $query = array(
            'alias' => $alias,
            'parent_id' => $parent_id
        );

        $result = $this->find('first', array(
            'conditions' => $query
        ));

        if ($result) {
            return $result;
        }

        $this->create();

        if ($this->save($query)) {
            $this->deleteCache(array('RequestObject::hasAlias', $alias));

            return $this->getByAlias($alias);
        }

        return null;
    }
1307053
protected function addAlias($entity, $entity_id, $alias)
    {
        $this->alias->delete(array('entity' => $entity, 'entity_id' => $entity_id));

        $data = array(
            'alias' => $alias,
            'entity' => $entity,
            'entity_id' => $entity_id
        );

        return $this->alias->add($data);
    }
192394
public function setParent($parent_id = null): self
    {
        $parent_id = ((int) $parent_id > 0) ? (int) $parent_id : null;

        $this->setAttribute('parent_id', $parent_id);

        return $this;
    }
366646
public function update($parentId, $id, array $data)
    {
        $resource = $this->createPartialResourceUrlForView($parentId, $id);
        $data = $this->client->put($resource, [$this->getResourceName() => $data]);

        return $this->fromArray(reset($data));
    }
1017295
public function moveTo($id, $parent_id) {
        $pk = $this->getRepository()->getPrimaryKey();
        $node = $this->getNode($id);

        if (!$node || $node[$this->getConfig('parentField')] == $parent_id) {
            return false;
        }

        $left = $this->getConfig('leftField');
        $right = $this->getConfig('rightField');
        $data = [];

        // Remove the node and reset others
        $this->_removeNode($id, $node[$left]);

        // Insert into parent
        if ($parent_id && ($parentNode = $this->getNode($parent_id))) {
            $data = [
                $left => $parentNode[$right],
                $right => $parentNode[$right] + 1
            ];

        // Or the root
        } else if ($lastNode = $this->getLastNode()) {
            $data = [
                $left => $lastNode[$right] + 1,
                $right => $lastNode[$right] + 2
            ];
        }

        // Move it
        $this->_moveNode(function(Query $query) use ($pk, $id) {
            $query->where($pk, $id);
        }, $data + [
            $this->getConfig('parentField') => $parent_id
        ]);

        $this->_insertNode($id, $data[$left]);

        return true;
    }
147282
public function AddParent($parent)
    {
        $parent = str_replace("::", "\\", $parent);
        
        $this->parents[$parent] = $parent;
        $this->has_parent = true;
        
        return $this;
    }
181239
public function addRootTable($table, $alias = null)
    {
        $this->rootTables[] = $tableObject = $this->createTable($table, $alias);
        is_callable($table) && $table($tableObject);

        return $tableObject;
    }
1133704
public function add($parentId = null)
    {
        /** @var Page $page */
        $page = $this->Pages->newEntity();

        ThemeManager::theme(Wasabi::setting('Cms.Theme.id'));

        if ($this->request->is('post') && !empty($this->request->data)) {
            $this->request->data['parent_id'] = $parentId;

            /** @var Connection $conn */
            $conn = $this->Pages->connection();
            $conn->begin();
            $this->Pages->behaviors()->unload('Translate');
            $page = $this->Pages->newEntity([
                'name' => $this->request->data('name'),
                'parent_id' => $this->request->data('parent_id'),
                'layout' => $this->request->data('layout')
            ]);

            if ($this->Pages->save($page, ['associated' => false])) {
                $this->Pages->behaviors()->load('Translate', PagesTable::$translateOptions);

                $page = $this->Pages->patchEntity($page, $this->request->data);
                if ($this->Pages->save($page)) {
                    $conn->commit();
                    $this->Flash->success(__d('wasabi_cms', 'The page <strong>{0}</strong> has been created.', $page->name));
                    $this->redirect(['action' => 'index']);
                    return;
                } else {
                    $conn->rollback();
                    $this->Flash->error($this->formErrorMessage);
                }
            } else {
                $conn->rollback();
                $this->Flash->error($this->formErrorMessage);
            }
        } else {
            $page->layout = 'Default';
            $page->current = [
                (new Content())->set('content', json_encode($page->getLayout()->content()))
            ];
            $page->display_page_title_suffix = true;
        }

        if ($page->meta_robots_index === null) {
            $page->meta_robots_index = (bool)Configure::read('Settings.Cms.SEO.meta-robots-index');
        }

        if ($page->meta_robots_follow === null) {
            $page->meta_robots_follow = (bool)Configure::read('Settings.Cms.SEO.meta-robots-follow');
        }

        $this->set([
            'page' => $page,
            'layouts' => ThemeManager::theme()->getLayoutsForSelect(),
            'availableModules' => ModuleManager::getAvailableModules(),
            'attributes' => $page->getLayout()->attributes(),
            'changeAttributesUrl' => Router::url([
                'plugin' => 'Wasabi/Cms',
                'controller' => 'Pages',
                'action' => 'attributes'
            ])
        ]);
    }
792398
public static function newRelation($alias = null, $table = null, $keys = null, $db = null)
    {
        $instance = new static($table, $keys, $db);

        return $instance->alias($alias);
    }
29351
public function parent($id = '')
    {
        // Return value
        if (empty($id)) {
            return $this->parent;
        }

        // Set value
        $this->parent = $id;

        return $this;
    }
168039
public function addAlias($index, $alias, $aliasParameters = [])
    {
        return (bool)$this->db->put([$index, '_alias', $alias], [], json_encode((object)$aliasParameters));
    }
165384
public function createInHierarchy( $parentId, $parentType, $rootId, $childId ) {

		$root = $this->getRoot( $rootId, $parentType );

		// Add Root
		if( !isset( $root ) ) {

			$model	= $this->getModelObject();

			$model->rootId		= $rootId;
			$model->parentType	= $parentType;
			$model->lValue		= CoreGlobal::HIERARCHY_VALUE_L;
			$model->rValue		= CoreGlobal::HIERARCHY_VALUE_R;

			// Create Model
			$model->save();
		}

		$model	= $this->getModelObject();

		$model->rootId		= $rootId;
		$model->parentType	= $parentType;

		$model->parentId	= $parentId;
		$model->childId		= $childId;

		// Create Model
		$model->save();
	}
876543
public function move(string $id, string $id_parent = null): bool
  {
    if ( $this->pref->move_bit($id, $id_parent) ){
      $this->delete_cache($this->get_id_menu($id));
      return true;
    }
    return false;
  }
873864
public function update($id, $name, $parentid = 1, $order = null)
    {
        $params = array(
                   'name'       => $name,
                   'parentid'   => $parentid,
                   'order'      => $order,
                   'id'         => $id
                );

        return $this->http->jsonPost(self::API_UPDATE, $params);
    }
943046
public static function queryByParent( $parentId, $parentType ) {

		$tableName = static::tableName();

		return self::queryWithModel()->where( "$tableName.parentId=:pid AND $tableName.parentType=:ptype", [ ':pid' => $parentId, ':ptype' => $parentType ] );
	}
604049
private function addServiceAlias($alias, $id)
    {
        if ($id->isPublic()) {
            return sprintf("    %s: '@%s'\n", $alias, $id);
        }

        return sprintf("    %s:\n        alias: %s\n        public: false\n", $alias, $id);
    }
677098
public static function add($parent = false)
    {
        $db = Database::connection();
        $treeNodeParentID = 0;
        $treeID = 0;
        $treeNodeDisplayOrder = 0;
        $inheritPermissionsFromTreeNodeID = 0;
        if (is_object($parent)) {
            $treeNodeParentID = $parent->getTreeNodeID();
            $treeID = $parent->getTreeID();
            $inheritPermissionsFromTreeNodeID = $parent->getTreeNodePermissionsNodeID();
            $treeNodeDisplayOrder = (int) $db->fetchColumn('select count(treeNodeDisplayOrder) from TreeNodes where treeNodeParentID = ?', [$treeNodeParentID]);
            $parent->updateDateModified();
        } else {
            $parent = null;
        }

        $treeNodeTypeHandle = uncamelcase(strrchr(get_called_class(), '\\'));

        $dateModified = Core::make('date')->toDB();
        $dateCreated = Core::make('date')->toDB();

        $type = TreeNodeType::getByHandle($treeNodeTypeHandle);
        $db->executeQuery(
            'insert into TreeNodes (treeNodeTypeID, treeNodeParentID, treeNodeDisplayOrder, inheritPermissionsFromTreeNodeID, dateModified, dateCreated, treeID) values (?, ?, ?, ?, ?, ?, ?)',
            [
                $type->getTreeNodeTypeID(),
                $treeNodeParentID,
                $treeNodeDisplayOrder,
                $inheritPermissionsFromTreeNodeID,
                $dateModified,
                $dateCreated,
                $treeID,
            ]
        );
        $id = $db->lastInsertId();
        $node = self::getByID($id);

        if (!$inheritPermissionsFromTreeNodeID) {
            $node->setTreeNodePermissionsToOverride();
        }

        if ($parent !== null && $parent->childNodesLoaded) {
            $parent->childNodes[] = $node;
        }

        return $node;
    }