private function assertCommitMessageCanBeModified(Project $project)
 {
     if (!$project->canChangeSVNLog()) {
         throw new Exception('Project forbid to change log messages');
     }
 }
Example #2
0
 /**
  * Put in place the svn post-commit hook for email notification
  * if not present (if the file does not exist it is created)
  * 
  * @param Project $project The project to work on
  * 
  * @return boolean true on success or false on failure
  */
 public function updateHooks(Project $project)
 {
     $unix_group_name = $project->getUnixNameMixedCase();
     // May contain upper-case letters
     $svn_dir = $project->getSVNRootPath();
     if ($project->isSVNTracked()) {
         $filename = "{$svn_dir}/hooks/post-commit";
         $update_hook = false;
         if (!is_file($filename)) {
             // File header
             $fp = fopen($filename, 'w');
             fwrite($fp, "#!/bin/sh\n");
             fwrite($fp, "# POST-COMMIT HOOK\n");
             fwrite($fp, "#\n");
             fwrite($fp, "# The post-commit hook is invoked after a commit.  Subversion runs\n");
             fwrite($fp, "# this hook by invoking a program (script, executable, binary, etc.)\n");
             fwrite($fp, "# named 'post-commit' (for which this file is a template) with the \n");
             fwrite($fp, "# following ordered arguments:\n");
             fwrite($fp, "#\n");
             fwrite($fp, "#   [1] REPOS-PATH   (the path to this repository)\n");
             fwrite($fp, "#   [2] REV          (the number of the revision just committed)\n\n");
             fclose($fp);
             $update_hook = true;
         } else {
             $file_array = file($filename);
             if (!in_array($this->block_marker_start, $file_array)) {
                 $update_hook = true;
             }
         }
         if ($update_hook) {
             $command = 'REPOS="$1"' . "\n";
             $command .= 'REV="$2"' . "\n";
             $command .= $GLOBALS['codendi_bin_prefix'] . '/commit-email.pl "$REPOS" "$REV" 2>&1 >/dev/null';
             $this->addBlock($filename, $command);
             $this->chown($filename, $this->getHTTPUser());
             $this->chgrp($filename, $unix_group_name);
             chmod("{$filename}", 0775);
         }
     } else {
         // Make sure that the Codendi blocks are removed
         $filename = "{$svn_dir}/hooks/post-commit";
         $update_hook = false;
         if (is_file($filename)) {
             $file_array = file($filename);
             if (in_array($this->block_marker_start, $file_array)) {
                 $this->removeBlock($filename);
             }
         }
     }
     // Put in place the Codendi svn pre-commit hook
     // if not present (if the file does not exist it is created)
     $filename = "{$svn_dir}/hooks/pre-commit";
     $update_hook = false;
     if (!is_file($filename)) {
         // File header
         $fp = fopen($filename, 'w');
         fwrite($fp, "#!/bin/sh\n\n");
         fwrite($fp, "# PRE-COMMIT HOOK\n");
         fwrite($fp, "#\n");
         fwrite($fp, "# The pre-commit hook is invoked before a Subversion txn is\n");
         fwrite($fp, "# committed.  Subversion runs this hook by invoking a program\n");
         fwrite($fp, "# (script, executable, binary, etc.) named 'pre-commit' (for which\n");
         fwrite($fp, "# this file is a template), with the following ordered arguments:\n");
         fwrite($fp, "#\n");
         fwrite($fp, "#   [1] REPOS-PATH   (the path to this repository)\n");
         fwrite($fp, "#   [2] TXN-NAME     (the name of the txn about to be committed)\n");
         $update_hook = true;
     } else {
         $file_array = file($filename);
         if (!in_array($this->block_marker_start, $file_array)) {
             $update_hook = true;
         }
     }
     if ($update_hook) {
         $command = 'REPOS="$1"' . "\n";
         $command .= 'TXN="$2"' . "\n";
         $command .= $GLOBALS['codendi_dir'] . '/src/utils/php-launcher.sh ' . $GLOBALS['codendi_bin_prefix'] . '/codendi_svn_pre_commit.php "$REPOS" "$TXN" || exit 1';
         $this->addBlock($filename, $command);
         $this->chown($filename, $this->getHTTPUser());
         $this->chgrp($filename, $unix_group_name);
         chmod("{$filename}", 0775);
     }
     if ($project->canChangeSVNLog()) {
         try {
             $this->enableCommitMessageUpdate($svn_dir);
         } catch (BackendSVNFileForSimlinkAlreadyExistsException $exception) {
             throw $exception;
         }
     } else {
         $this->disableCommitMessageUpdate($svn_dir);
     }
     return true;
 }
 public function svn_can_change_log()
 {
     return $this->project->canChangeSVNLog();
 }