Exemple #1
0
 /**
  * @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));
     }
 }