/** * @param bool $accessChecks * @param bool $load * * @return bool|NodeModel */ public function findRoot($accessChecks = true, $load = true) { $node = new self(); if ($accessChecks === false) { $node->ignoreAccessControl = true; } $lastParent = $this->getPK(); $parent = $this->has('parent') ? $this->getParent(false) : false; while ($parent) { $lastParent = $parent; $node->loadByPK($parent); $parent = $node->has('parent') ? $node->getParent(false) : false; } if ($lastParent === $this->getPK()) { return $this; } else { if ($lastParent) { if ($load) { $root = new self(); if (!$accessChecks) { $root->ignoreAccessControl = true; } $root->loadByPK($lastParent); return $root; } else { return (string) $lastParent; } } } // TODO: we can never reach this? return false; }
/** * Create a symlink pointing to this directory * * @param Dir|string $dir Dir object or path * @param boolean $createPaths Create paths (if does not exist) * * @return $this * @throws \InvalidArgumentException */ public function symlink($dir, $createPaths = true) { if (!$this->exists()) { throw new \InvalidArgumentException(sprintf("Cannot create a link. Directory must exist: '%s'", $this->path)); } if (!$dir instanceof self) { $dir = new self($dir); } if ($dir->isLink()) { unlink($dir->getPath()); } $parent = $dir->getParent(); if ($createPaths) { if (!$this->exists()) { $this->create(); } if (!$parent->exists()) { $parent->create(); } } symlink($this->getAbsolutePath(), $parent->getAbsolutePath() . '/' . $dir->getName()); return $this; }