Ejemplo n.º 1
0
 /**
  * @param Project $project
  * @param PFUser $user
  * @param string $template_content
  * @param int $template_id
  * @return void
  */
 public function updateTemplate(Project $project, PFUser $user, $template_content, $template_id)
 {
     if ($project->isError() || !$this->checkUserIsAdmin($project, $user)) {
         $GLOBALS['Response']->addFeedback(Feedback::ERROR, $GLOBALS['Language']->getText('plugin_git', 'view_admin_template_invalid_project'));
         return;
     }
     if (!$template_id) {
         $GLOBALS['Response']->addFeedback(Feedback::ERROR, $GLOBALS['Language']->getText('plugin_git', 'view_admin_template_invalid_template_id'));
         return;
     }
     try {
         $template = $this->template_factory->getTemplate($template_id);
     } catch (Exception $e) {
         $GLOBALS['Response']->addFeedback(Feedback::ERROR, $GLOBALS['Language']->getText('plugin_git', 'Unable to update template'));
         return;
     }
     if (!$template->belongsToProject($project->getID())) {
         $GLOBALS['Response']->addFeedback(Feedback::ERROR, $GLOBALS['Language']->getText('plugin_git', 'view_admin_template_invalid_template_id'));
         return;
     }
     $template->setContent($template_content);
     if ($this->template_factory->updateTemplate($template)) {
         $GLOBALS['Response']->addFeedback(Feedback::INFO, $GLOBALS['Language']->getText('plugin_git', 'view_admin_template_updated'));
     } else {
         $GLOBALS['Response']->addFeedback(Feedback::ERROR, $GLOBALS['Language']->getText('plugin_git', 'Unable to update template'));
     }
 }
Ejemplo n.º 2
0
 private function applyTemplateIfAnySelected($template_id, GitRepository $repository)
 {
     if ($this->noFurtherPermissionsToApply($template_id)) {
         return;
     }
     $this->applyTemplate($this->template_factory->getTemplate($template_id, $repository), $repository);
 }