public function __construct($repositoryPath) { $pathString = $repositoryPath; if (!StringUtils::startsWith($pathString, '/')) { throw new \Exception('Repository Path must be absolute'); } if (!StringUtils::endsWith($pathString, '/')) { $pathString .= '/'; } $this->repositoryPath = DirectoryPath::parse($pathString); }
protected function targetUrlExists($url) { try { $urlParts = parse_url($url); $urlPath = $urlParts['path']; $path = null; if (StringUtils::startsWith($urlPath, '/')) { /* Absolute paths won't work */ return false; } else { $directoryPath = $this->path->getParentPath(); $path = $directoryPath->appendPathString($urlPath); } $fileExists = $this->repository->exists($path); $this->linkedPaths[] = $path; return $fileExists; } catch (\Exception $e) { } return true; }
/** * @param Request $request * @param string $path * * @throws AccessDeniedHttpException */ protected function checkPreconditions(Request $request, $path) { if (StringUtils::startsWith($path, '/.git')) { throw new AccessDeniedHttpException(); } }
/** * @param User $user * @param FilePath $relativeOldFilePath * @param FilePath $relativeNewFilePath * @param string $commitMessage * * @throws FileExistsException * @throws \Exception */ public function renameFile(User $user, FilePath $relativeOldFilePath, FilePath $relativeNewFilePath, $commitMessage) { if ($this->gitRepository->exists($relativeNewFilePath)) { throw new FileExistsException('File ' . $relativeNewFilePath->toRelativeFileString() . ' already exists'); } if (empty($commitMessage)) { throw new \Exception('Commit message must not be empty'); } $oldLockPath = $this->getLockPath($relativeOldFilePath); $this->assertHasLock($user, $oldLockPath); $this->createLock($user, $relativeNewFilePath); $this->gitRepository->moveAndCommit($this->getAuthor($user), $commitMessage, $relativeOldFilePath, $relativeNewFilePath); $this->removeLock($user, $relativeOldFilePath); $this->removeLock($user, $relativeNewFilePath); if (StringUtils::endsWith($relativeOldFilePath->getName(), '.md')) { $this->eventDispatcher->dispatch('ddr.gitki.wiki.markdown_document.deleted', new MarkdownDocumentDeletedEvent($relativeOldFilePath, $user->getRealName(), time(), $commitMessage)); } if (StringUtils::endsWith($relativeNewFilePath->getName(), '.md')) { $content = $this->getContent($relativeNewFilePath); $parsedMarkdownDocument = $this->markdownService->parse($relativeNewFilePath, $content); $this->eventDispatcher->dispatch('ddr.gitki.wiki.markdown_document.saved', new MarkdownDocumentSavedEvent($relativeNewFilePath, $user->getEmail(), time(), $parsedMarkdownDocument, $commitMessage)); } }