示例#1
0
 /**
  * @param Request  $request
  * @param FilePath $path
  *
  * @return Response
  * @throws \Exception
  * @throws GitException
  * @throws HttpException
  */
 public function editPageAction(Request $request, FilePath $path)
 {
     $this->assertRole('ROLE_COMMITTER');
     if (!StringUtils::endsWith($path->getName(), '.md')) {
         throw new HttpException(500, 'Only editing of markdown files is supported');
     }
     $user = $this->getUser();
     try {
         $this->getWikiService()->createLock($user, $path);
     } catch (PageLockedException $e) {
         $renderedView = $this->renderView('DdrGitkiBaseBundle:Wiki:page.locked.html.twig', array('path' => $path, 'lockedBy' => $e->getLockedBy()));
         return new Response($renderedView, 409);
     }
     $form = $this->createFormBuilder()->add('content', 'textarea')->add('commitMessage', 'text', array('label' => 'Commit Message', 'required' => true))->add('actions', 'form_actions', array('buttons' => array('save' => array('type' => 'submit', 'options' => array('label' => 'Save')), 'cancel' => array('type' => 'submit', 'options' => array('label' => 'Cancel', 'button_class' => 'default')))))->getForm();
     $form->handleRequest($request);
     /** @var SubmitButton $cancelButton */
     $cancelButton = $form->get('actions')->get('cancel');
     if ($cancelButton->isClicked()) {
         $this->getWikiService()->removeLock($user, $path);
         return $this->redirect($this->generateUrl('ddr_gitki_wiki_file', array('path' => $path)));
     }
     if ($form->isValid()) {
         $content = $form->get('content')->getData();
         $commitMessage = $form->get('commitMessage')->getData();
         try {
             $this->getWikiService()->savePage($user, $path, $content, $commitMessage);
             $this->getWikiService()->removeLock($user, $path);
             return $this->redirect($this->generateUrl('ddr_gitki_wiki_file', array('path' => $path)));
         } catch (GitException $e) {
             throw $e;
         }
     } else {
         $content = null;
         if ($this->getWikiService()->exists($path)) {
             $content = $this->getWikiService()->getContent($path);
         } else {
             $title = $request->query->get('title');
             if (!empty($title)) {
                 $content = $title . "\n";
                 for ($i = 0; $i < strlen($title); $i++) {
                     $content .= '=';
                 }
                 $content .= "\n\n";
             }
         }
         if (!$form->isSubmitted()) {
             $form->setData(array('content' => $content, 'commitMessage' => 'Editing ' . $path->toAbsoluteUrlString()));
         }
     }
     return $this->render('DdrGitkiBaseBundle:Wiki:page.edit.html.twig', array('form' => $form->createView(), 'path' => $path));
 }
示例#2
0
 /**
  * @param FilePath $relativeFilePath
  *
  * @return FilePath
  */
 protected function getLockPath(FilePath $relativeFilePath)
 {
     $name = $relativeFilePath->getName();
     $relativeLockPath = $relativeFilePath->getParentPath()->appendFile($name . '.lock');
     return $relativeLockPath;
 }