[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/include/ -> class.workflow.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: Bryan Alsdorf <bryan@mysql.com>                             |
  26  // +----------------------------------------------------------------------+
  27  //
  28  
  29  class Workflow
  30  {
  31      /**
  32       * Returns a list of backends available
  33       *
  34       * @access  public
  35       * @return  array An array of workflow backends
  36       */
  37      function getBackendList()
  38      {
  39          $files = Misc::getFileList(APP_INC_PATH . "workflow");
  40          $list = array();
  41          for ($i = 0; $i < count($files); $i++) {
  42              // display a prettyfied backend name in the admin section
  43              if (preg_match('/^class\.(.*)\.php$/', $files[$i], $matches)) {
  44                  if ($matches[1] == 'abstract_workflow_backend') {
  45                      continue;
  46                  }
  47                  $name = ucwords(str_replace('_', ' ', $matches[1]));
  48                  $list[$files[$i]] = $name;
  49              }
  50          }
  51          return $list;
  52      }
  53  
  54  
  55      /**
  56       * Returns the name of the workflow backend for the specified project.
  57       *
  58       * @access  public
  59       * @param   integer $prj_id The id of the project to lookup.
  60       * @return  string The name of the customer backend.
  61       */
  62      function _getBackendNameByProject($prj_id)
  63      {
  64          static $backends;
  65  
  66          if (isset($backends[$prj_id])) {
  67              return $backends[$prj_id];
  68          }
  69  
  70          $stmt = "SELECT
  71                      prj_id,
  72                      prj_workflow_backend
  73                   FROM
  74                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project
  75                   ORDER BY
  76                      prj_id";
  77          $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
  78          if (PEAR::isError($res)) {
  79              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  80              return '';
  81          } else {
  82              $backends = $res;
  83              return @$backends[$prj_id];
  84          }
  85      }
  86  
  87  
  88      /**
  89       * Includes the appropriate workflow backend class associated with the
  90       * given project ID, instantiates it and returns the class.
  91       *
  92       * @access  public
  93       * @param   integer $prj_id The project ID
  94       * @return  boolean
  95       */
  96      function &_getBackend($prj_id)
  97      {
  98          static $setup_backends;
  99  
 100          if (empty($setup_backends[$prj_id])) {
 101              $backend_class = Workflow::_getBackendNameByProject($prj_id);
 102              if (empty($backend_class)) {
 103                  return false;
 104              }
 105              $file_name_chunks = explode(".", $backend_class);
 106              $class_name = $file_name_chunks[1] . "_Workflow_Backend";
 107  
 108              require_once(APP_INC_PATH . "workflow/$backend_class");
 109  
 110              $setup_backends[$prj_id] = new $class_name;
 111          }
 112          return $setup_backends[$prj_id];
 113      }
 114  
 115  
 116      /**
 117       * Checks whether the given project ID is setup to use workflow integration
 118       * or not.
 119       *
 120       * @access  public
 121       * @param   integer integer $prj_id The project ID
 122       * @return  boolean
 123       */
 124      function hasWorkflowIntegration($prj_id)
 125      {
 126          $backend = Workflow::_getBackendNameByProject($prj_id);
 127          if (empty($backend)) {
 128              return false;
 129          } else {
 130              return true;
 131          }
 132      }
 133  
 134  
 135      /**
 136       * Is called when an issue is updated.
 137       *
 138       * @param   integer $prj_id The project ID.
 139       * @param   integer $issue_id The ID of the issue.
 140       * @param   integer $usr_id The ID of the user.
 141       * @param   array $old_details The old details of the issues.
 142       * @param   array $changes The changes that were applied to this issue (the $_POST)
 143       */
 144      function handleIssueUpdated($prj_id, $issue_id, $usr_id, $old_details, $changes)
 145      {
 146          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 147              return;
 148          }
 149          $backend =& Workflow::_getBackend($prj_id);
 150          return $backend->handleIssueUpdated($prj_id, $issue_id, $usr_id, $old_details, $changes);
 151      }
 152  
 153  
 154      /**
 155       * Called when an issue is assigned.
 156       *
 157       * @param   integer $prj_id The project ID
 158       * @param   integer $issue_id The ID of the issue.
 159       * @param   integer $usr_id The id of the user who assigned the issue.
 160       */
 161      function handleAssignment($prj_id, $issue_id, $usr_id)
 162      {
 163          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 164              return;
 165          }
 166          $backend =& Workflow::_getBackend($prj_id);
 167          return $backend->handleAssignment($prj_id, $issue_id, $usr_id);
 168      }
 169  
 170  
 171      /**
 172       * Called when a file is attached to an issue..
 173       *
 174       * @param   integer $prj_id The project ID
 175       * @param   integer $issue_id The ID of the issue.
 176       * @param   integer $usr_id The id of the user who locked the issue.
 177       */
 178      function handleAttachment($prj_id, $issue_id, $usr_id)
 179      {
 180          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 181              return;
 182          }
 183          $backend =& Workflow::_getBackend($prj_id);
 184          return $backend->handleAttachment($prj_id, $issue_id, $usr_id);
 185      }
 186  
 187  
 188      /**
 189       * Called when the priority of an issue changes.
 190       *
 191       * @param   integer $prj_id The project ID
 192       * @param   integer $issue_id The ID of the issue.
 193       * @param   integer $usr_id The id of the user who locked the issue.
 194       * @param   array $old_details The old details of the issue.
 195       * @param   array $changes The changes that were applied to this issue (the $_POST)
 196       */
 197      function handlePriorityChange($prj_id, $issue_id, $usr_id, $old_details, $changes)
 198      {
 199          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 200              return;
 201          }
 202          $backend =& Workflow::_getBackend($prj_id);
 203          return $backend->handlePriorityChange($prj_id, $issue_id, $usr_id, $old_details, $changes);
 204      }
 205  
 206  
 207      /**
 208       * Called when an email is blocked.
 209       *
 210       * @param   integer $prj_id The project ID
 211       * @param   integer $issue_id The ID of the issue.
 212       * @param   array $email_details Details of the issue
 213       * @param   string $type What type of blocked email this is.
 214       */
 215      function handleBlockedEmail($prj_id, $issue_id, $email_details, $type)
 216      {
 217          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 218              return;
 219          }
 220          $backend =& Workflow::_getBackend($prj_id);
 221          return $backend->handleBlockedEmail($prj_id, $issue_id, $email_details, $type);
 222      }
 223  
 224  
 225      /**
 226       * Called when the assignment on an issue changes.
 227       *
 228       * @param   integer $prj_id The project ID
 229       * @param   integer $issue_id The ID of the issue.
 230       * @param   integer $usr_id The id of the user who locked the issue.
 231       * @param   array $issue_details The old details of the issue.
 232       * @param   array $new_assignees The new assignees of this issue.
 233       * @param   boolean $remote_assignment If this issue was remotely assigned.
 234       */
 235      function handleAssignmentChange($prj_id, $issue_id, $usr_id, $issue_details, $new_assignees, $remote_assignment = false)
 236      {
 237          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 238              return;
 239          }
 240          $backend =& Workflow::_getBackend($prj_id);
 241          return $backend->handleAssignmentChange($prj_id, $issue_id, $usr_id, $issue_details, $new_assignees, $remote_assignment);
 242      }
 243  
 244  
 245      /**
 246       * Called when a new issue is created.
 247       *
 248       * @param   integer $prj_id The project ID
 249       * @param   integer $issue_id The ID of the issue.
 250       * @param   boolean $has_TAM If this issue has a technical account manager.
 251       * @param   boolean $has_RR If Round Robin was used to assign this issue.
 252       */
 253      function handleNewIssue($prj_id, $issue_id, $has_TAM, $has_RR)
 254      {
 255          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 256              return;
 257          }
 258          $backend =& Workflow::_getBackend($prj_id);
 259          return $backend->handleNewIssue($prj_id, $issue_id, $has_TAM, $has_RR);
 260      }
 261  
 262  
 263      /**
 264       * Called when an email is recieved.
 265       *
 266       * @param   integer $prj_id The project ID
 267       * @param   integer $issue_id The ID of the issue.
 268       * @param   object $message An object containing the new email
 269       * @param   array $row The array of data that was inserted into the database.
 270       * @param   boolean $closing If we are closing the issue.
 271       */
 272      function handleNewEmail($prj_id, $issue_id, $message, $row = FALSE, $closing = false)
 273      {
 274          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 275              return;
 276          }
 277          $backend =& Workflow::_getBackend($prj_id);
 278          return $backend->handleNewEmail($prj_id, $issue_id, $message, $row, $closing);
 279      }
 280  
 281  
 282      /**
 283       * Called when an email is manually associated with an existing issue.
 284       *
 285       * @param   integer $prj_id The project ID
 286       * @param   integer $issue_id The ID of the issue.
 287       */
 288      function handleManualEmailAssociation($prj_id, $issue_id)
 289      {
 290          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 291              return;
 292          }
 293          $backend =& Workflow::_getBackend($prj_id);
 294          return $backend->handleManualEmailAssociation($prj_id, $issue_id);
 295      }
 296  
 297  
 298      /**
 299       * Called when a note is routed.
 300       *
 301       * @param   integer $prj_id The project ID
 302       * @param   integer $issue_id The ID of the issue.
 303       * @param   integer $usr_id The user ID of the person posting this new note
 304       * @param   boolean $closing If the issue is being closed
 305       * @param   integer $note_id The ID of the new note
 306       */
 307      function handleNewNote($prj_id, $issue_id, $usr_id, $closing = false, $note_id = false)
 308      {
 309          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 310              return;
 311          }
 312          $backend =& Workflow::_getBackend($prj_id);
 313          return $backend->handleNewNote($prj_id, $issue_id, $usr_id, $closing, $note_id);
 314      }
 315  
 316  
 317      /**
 318       * Method is called to return the list of statuses valid for a specific issue.
 319       *
 320       * @param   integer $prj_id The project ID
 321       * @param   integer $issue_id The ID of the issue.
 322       * @return  array An associative array of statuses valid for this issue.
 323       */
 324      function getAllowedStatuses($prj_id, $issue_id)
 325      {
 326          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 327              return;
 328          }
 329          $backend =& Workflow::_getBackend($prj_id);
 330          return $backend->getAllowedStatuses($prj_id, $issue_id);
 331      }
 332  
 333  
 334      /**
 335       * Called when issue is closed.
 336       *
 337       * @param   integer $prj_id The project ID
 338       * @param   integer $issue_id The ID of the issue.
 339       * @param   boolean $send_notification Whether to send a notification about this action or not
 340       * @param   integer $resolution_id The resolution ID
 341       * @param   integer $status_id The status ID
 342       * @param   string $reason The reason for closing this issue
 343       * @return  void
 344       */
 345      function handleIssueClosed($prj_id, $issue_id, $send_notification, $resolution_id, $status_id, $reason)
 346      {
 347          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 348              return;
 349          }
 350          $backend =& Workflow::_getBackend($prj_id);
 351          $backend->handleIssueClosed($prj_id, $issue_id, $send_notification, $resolution_id, $status_id, $reason);
 352      }
 353  
 354  
 355      /**
 356       * Called when custom fields are updated
 357       *
 358       * @param   integer $prj_id The project ID
 359       * @param   integer $issue_id The ID of the issue
 360       * @param   array $old The custom fields before the update.
 361       * @param   array $new The custom fields after the update.
 362       */
 363      function handleCustomFieldsUpdated($prj_id, $issue_id, $old, $new)
 364      {
 365          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 366              return;
 367          }
 368          $backend =& Workflow::_getBackend($prj_id);
 369          return $backend->handleCustomFieldsUpdated($prj_id, $issue_id, $old, $new);
 370      }
 371  
 372  
 373      /**
 374       * Called when an attempt is made to add a user or email address to the
 375       * notification list.
 376       *
 377       * @param   integer $prj_id The project ID
 378       * @param   integer $issue_id The ID of the issue.
 379       * @param   integer $subscriber_usr_id The ID of the user to subscribe if this is a real user (false otherwise).
 380       * @param   string $email The email address  to subscribe (if this is not a real user).
 381       * @param   array $types The action types.
 382       * @return  mixed An array of information or true to continue unchanged or false to prevent the user from being added.
 383       */
 384      function handleSubscription($prj_id, $issue_id, &$subscriber_usr_id, &$email, &$types)
 385      {
 386          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 387              return;
 388          }
 389          $backend =& Workflow::_getBackend($prj_id);
 390          return $backend->handleSubscription($prj_id, $issue_id, $subscriber_usr_id, $email, $types);
 391      }
 392  
 393  
 394      /**
 395       * Called when SCM checkin is associated.
 396       *
 397       * @param   integer $prj_id The project ID.
 398       * @param   integer $issue_id The ID of the issue.
 399       * @param   string $module The SCM module commit was made.
 400       * @param   array $files File list with their version numbers changes made on.
 401       * @param   string $username SCM user doing the checkin.
 402       * @param   string $commit_msg Message associated with the SCM commit.
 403       * @return  void
 404       */
 405      function handleSCMCheckins($prj_id, $issue_id, $module, $files, $username, $commit_msg)
 406      {
 407          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 408              return;
 409          }
 410          $backend =& Workflow::_getBackend($prj_id);
 411          return $backend->handleSCMCheckins($prj_id, $issue_id, $module, $files, $username, $commit_msg);
 412      }
 413  
 414  
 415      /**
 416       * Determines if the address should should be emailed.
 417       *
 418       * @param   integer $prj_id The project ID.
 419       * @param   string $address The email address to check
 420       * @return  boolean
 421       */
 422      function shouldEmailAddress($prj_id, $address, $issue_id = false, $type = false)
 423      {
 424          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 425              return true;
 426          }
 427          $backend =& Workflow::_getBackend($prj_id);
 428          return $backend->shouldEmailAddress($prj_id, $address, $issue_id, $type);
 429      }
 430  
 431  
 432      /**
 433       * Returns additional email addresses that should be notified for a specific event..
 434       *
 435       * @param   integer $prj_id The project ID.
 436       * @param   integer $issue_id The ID of the issue.
 437       * @param   string  $event The event to return additional email addresses for. Currently only "new_issue" is supported.
 438       * @param   array   $extra Extra information, contains different info depending on where it is called from
 439       * @return  array   An array of email addresses to be notified.
 440       */
 441      function getAdditionalEmailAddresses($prj_id, $issue_id, $event, $extra = false)
 442      {
 443          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 444              return array();
 445          }
 446          $backend =& Workflow::_getBackend($prj_id);
 447          return $backend->getAdditionalEmailAddresses($prj_id, $issue_id, $event, $extra);
 448      }
 449  
 450  
 451      /**
 452       * Indicates if the the specified email address can email the issue. Can be
 453       * used to disable email blocking by always returning true.
 454       *
 455       * @param   integer $prj_id The project ID.
 456       * @param   integer $issue_id The ID of the issue
 457       * @param   string The email address that is trying to send an email
 458       * @return  boolean true if the sender can email the issue, false if the sender
 459       *          should not email the issue and null if the default rules should be used.
 460       */
 461      function canEmailIssue($prj_id, $issue_id, $email)
 462      {
 463          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 464              return null;
 465          }
 466          $backend =& Workflow::_getBackend($prj_id);
 467          return $backend->canEmailIssue($prj_id, $issue_id, $email);
 468      }
 469  
 470  
 471      /**
 472       * Handles when an authorized replier is added
 473       *
 474       * @param   integer $prj_id The project ID
 475       * @param   integer $issue_id The ID of the issue
 476       * @param   string  $email The email address added
 477       * @return  boolean
 478       */
 479      function handleAuthorizedReplierAdded($prj_id, $issue_id, &$email)
 480      {
 481          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 482              return null;
 483          }
 484          $backend =& Workflow::_getBackend($prj_id);
 485          return $backend->handleAuthorizedReplierAdded($prj_id, $issue_id, $email);
 486      }
 487  
 488  
 489      /**
 490       * Called at the begining of the email download process. If it returns true, the
 491       * rest of the email code will not be executed.
 492       *
 493       * @param   integer $prj_id The project ID
 494       * @param   array $info An array containing the information on the email account.
 495       * @param   resource $mbox The imap connection resource
 496       * @param   integer $num The sequential email number
 497       * @param   string $message The complete email message
 498       * @param   object $email An object containing the decoded email
 499       * @return  mixed null by default, -1 if the rest of the email script should not be processed.
 500       */
 501      function preEmailDownload($prj_id, $info, $mbox, $num, &$message, &$email)
 502      {
 503          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 504              return null;
 505          }
 506          $backend =& Workflow::_getBackend($prj_id);
 507          return $backend->preEmailDownload($prj_id, $info, $mbox, $num, $message, $email);
 508      }
 509  
 510  
 511      /**
 512       * Indicates if the email addresses should automatically be added to the NL from notes and emails.
 513       *
 514       * @param   integer $prj_id The project ID.
 515       * @return  boolean
 516       */
 517      function shouldAutoAddToNotificationList($prj_id)
 518      {
 519          if (!Workflow::hasWorkflowIntegration($prj_id)) {
 520              return true;
 521          }
 522          $backend =& Workflow::_getBackend($prj_id);
 523          return $backend->shouldAutoAddToNotificationList($prj_id);
 524      }
 525  }


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