[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/include/ -> class.scm.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */
   3  // +----------------------------------------------------------------------+
   4  // | Eventum - Issue Tracking System                                      |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB                  |
   7  // |                                                                      |
   8  // | This program is free software; you can redistribute it and/or modify |
   9  // | it under the terms of the GNU General Public License as published by |
  10  // | the Free Software Foundation; either version 2 of the License, or    |
  11  // | (at your option) any later version.                                  |
  12  // |                                                                      |
  13  // | This program is distributed in the hope that it will be useful,      |
  14  // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  15  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  16  // | GNU General Public License for more details.                         |
  17  // |                                                                      |
  18  // | You should have received a copy of the GNU General Public License    |
  19  // | along with this program; if not, write to:                           |
  20  // |                                                                      |
  21  // | Free Software Foundation, Inc.                                       |
  22  // | 59 Temple Place - Suite 330                                          |
  23  // | Boston, MA 02111-1307, USA.                                          |
  24  // +----------------------------------------------------------------------+
  25  // | Authors: João Prado Maia <jpm@mysql.com>                             |
  26  // +----------------------------------------------------------------------+
  27  //
  28  // @(#) $Id: class.scm.php 3246 2007-02-09 09:10:12Z glen $
  29  //
  30  
  31  require_once (APP_INC_PATH . "class.error_handler.php");
  32  require_once (APP_INC_PATH . "class.misc.php");
  33  require_once (APP_INC_PATH . "class.issue.php");
  34  require_once (APP_INC_PATH . "class.auth.php");
  35  require_once (APP_INC_PATH . "class.user.php");
  36  require_once (APP_INC_PATH . "class.history.php");
  37  require_once (APP_INC_PATH . "class.date.php");
  38  require_once (APP_INC_PATH . "class.setup.php");
  39  
  40  /**
  41   * Class to handle the business logic related to the source control management
  42   * integration features of the application.
  43   *
  44   * @version 1.0
  45   * @author João Prado Maia <jpm@mysql.com>
  46   */
  47  
  48  class SCM
  49  {
  50      /**
  51       * Method used to remove all checkins associates with a list of issues.
  52       *
  53       * @access  public
  54       * @param   array $ids The list of issues
  55       * @return  boolean
  56       */
  57      function removeByIssues($ids)
  58      {
  59          $items = implode(", ", Misc::escapeInteger($ids));
  60          $stmt = "DELETE FROM
  61                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_checkin
  62                   WHERE
  63                      isc_iss_id IN ($items)";
  64          $res = $GLOBALS["db_api"]->dbh->query($stmt);
  65          if (PEAR::isError($res)) {
  66              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  67              return false;
  68          } else {
  69              return true;
  70          }
  71      }
  72  
  73  
  74      /**
  75       * Method used to remove a specific list of checkins
  76       *
  77       * @access  public
  78       * @return  integer 1 if the update worked, -1 otherwise
  79       */
  80      function remove()
  81      {
  82          $items = implode(", ", Misc::escapeInteger($_POST["item"]));
  83          $stmt = "SELECT
  84                      isc_iss_id
  85                   FROM
  86                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_checkin
  87                   WHERE
  88                      isc_id IN ($items)";
  89          $issue_id = $GLOBALS["db_api"]->dbh->getOne($stmt);
  90  
  91          $stmt = "DELETE FROM
  92                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_checkin
  93                   WHERE
  94                      isc_id IN ($items)";
  95          $res = $GLOBALS["db_api"]->dbh->query($stmt);
  96          if (PEAR::isError($res)) {
  97              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  98              return -1;
  99          } else {
 100              // need to mark this issue as updated
 101              Issue::markAsUpdated($issue_id);
 102              // need to save a history entry for this
 103              History::add($issue_id, Auth::getUserID(), History::getTypeID('scm_checkin_removed'), ev_gettext('SCM Checkins removed by %1$s', User::getFullName(Auth::getUserID())));
 104              return 1;
 105          }
 106      }
 107  
 108  
 109      /**
 110       * Method used to parse an user provided URL and substitute a known set of
 111       * placeholders for the appropriate information.
 112       *
 113       * @access  public
 114       * @param   string $url The user provided URL
 115       * @return  string The parsed URL
 116       */
 117      function parseURL($url, $info)
 118      {
 119          $url = str_replace('{MODULE}', $info["isc_module"], $url);
 120          $url = str_replace('{FILE}', $info["isc_filename"], $url);
 121          $url = str_replace('{OLD_VERSION}', $info["isc_old_version"], $url);
 122          $url = str_replace('{NEW_VERSION}', $info["isc_new_version"], $url);
 123          return $url;
 124      }
 125  
 126  
 127      /**
 128       * Method used to get the full list of checkins associated with an issue.
 129       *
 130       * @access  public
 131       * @param   integer $issue_id The issue ID
 132       * @return  array The list of checkins
 133       */
 134      function getCheckinList($issue_id)
 135      {
 136          $setup = Setup::load();
 137          $stmt = "SELECT
 138                      *
 139                   FROM
 140                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_checkin
 141                   WHERE
 142                      isc_iss_id=" . Misc::escapeInteger($issue_id) . "
 143                   ORDER BY
 144                      isc_created_date ASC";
 145          $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
 146          if (PEAR::isError($res)) {
 147              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 148              return "";
 149          } else {
 150              if (empty($res)) {
 151                  return "";
 152              } else {
 153                  for ($i = 0; $i < count($res); $i++) {
 154                      $res[$i]["isc_commit_msg"] = Link_Filter::processText(Issue::getProjectID($issue_id), nl2br(htmlspecialchars($res[$i]["isc_commit_msg"])));
 155                      @$res[$i]["checkout_url"] = SCM::parseURL($setup["checkout_url"], $res[$i]);
 156                      @$res[$i]["diff_url"] = SCM::parseURL($setup["diff_url"], $res[$i]);
 157                      $res[$i]["isc_created_date"] = Date_API::getFormattedDate($res[$i]["isc_created_date"]);
 158                  }
 159                  return $res;
 160              }
 161          }
 162      }
 163  
 164  
 165      /**
 166       * Method used to associate a new checkin with an existing issue
 167       *
 168       * @access  public
 169       * @param   integer $issue_id The issue ID
 170       * @param   integer $i The offset of the file that was changed
 171       * @return  integer 1 if the update worked, -1 otherwise
 172       */
 173      function logCheckin($issue_id, $i)
 174      {
 175          $stmt = "INSERT INTO
 176                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_checkin
 177                   (
 178                      isc_iss_id,
 179                      isc_module,
 180                      isc_filename,
 181                      isc_old_version,
 182                      isc_new_version,
 183                      isc_created_date,
 184                      isc_username,
 185                      isc_commit_msg
 186                   ) VALUES (
 187                      $issue_id,
 188                      '" . Misc::escapeString($_GET["module"]) . "',
 189                      '" . Misc::escapeString($_GET["files"][$i]) . "',
 190                      '" . Misc::escapeString($_GET["old_versions"][$i]) . "',
 191                      '" . Misc::escapeString($_GET["new_versions"][$i]) . "',
 192                      '" . Date_API::getCurrentDateGMT() . "',
 193                      '" . Misc::escapeString($_GET["username"]) . "',
 194                      '" . Misc::escapeString($_GET["commit_msg"]) . "'
 195                   )";
 196          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 197          if (PEAR::isError($res)) {
 198              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 199              return -1;
 200          } else {
 201              // need to mark this issue as updated
 202              Issue::markAsUpdated($issue_id, 'scm checkin');
 203              // need to save a history entry for this
 204              History::add($issue_id, APP_SYSTEM_USER_ID, History::getTypeID('scm_checkin_associated'),
 205                              ev_gettext("SCM Checkins associated by SCM user '") . $_GET["username"] . '\'.');
 206              return 1;
 207          }
 208      }
 209  }
 210  
 211  // benchmarking the included file (aka setup time)
 212  if (APP_BENCHMARK) {
 213      $GLOBALS['bench']->setMarker('Included SCM Class');
 214  }


Generated: Wed Dec 19 21:21:33 2007 Cross-referenced by PHPXref 0.7