[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/misc/ -> check_reminders.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: check_reminders.php 3266 2007-03-06 20:18:51Z glen $
  29  
  30  require_once(dirname(__FILE__) . "/../init.php");
  31  require_once (APP_INC_PATH . "db_access.php");
  32  require_once (APP_INC_PATH . "class.lock.php");
  33  require_once (APP_INC_PATH . "class.reminder.php");
  34  require_once (APP_INC_PATH . "class.reminder_action.php");
  35  require_once (APP_INC_PATH . "class.reminder_condition.php");
  36  
  37  // if requested, clear the lock
  38  if (in_array('--fix-lock', $argv)) {
  39      Lock::release('check_reminders');
  40      echo "The lock file was removed successfully.\n";
  41      exit;
  42  }
  43  
  44  // acquire a lock to prevent multiple scripts from 
  45  // running at the same time
  46  if (!Lock::acquire('check_reminders')) {
  47      echo "Error: Another instance of the script is still running. " . 
  48                  "If this is not accurate, you may fix it by running this script with '--fix-lock' " . 
  49                  "as the only parameter.\n";
  50      exit;
  51  }
  52  
  53  /*
  54  1 - Get list of reminders with all of its actions
  55  2 - Loop through each reminder level and build the SQL query
  56  3 - If query returns TRUE, then run the appropriate action
  57  4 - Get the list of actions
  58  5 - Calculate which action need to be performed, if any
  59  6 - Avoid repeating reminder actions, so first check if the last triggered action is the same one as "now"
  60  7 - Perform action
  61  8 - Continue to next reminder level
  62  **/
  63  $triggered_issues = array();
  64  
  65  $reminders = Reminder::getList();
  66  for ($i = 0; $i < count($reminders); $i++) {
  67      // if this is the weekend and this reminder isn't supposed to run on weekends skip
  68      if (($reminders[$i]['rem_skip_weekend'] == 1) && (in_array(date("w"), array(0,6)))) {
  69          if (Reminder::isDebug()) {
  70              echo "Skipping Reminder '" . $reminders[$i]['rem_title'] . "' due to weekend exclusion\n";
  71          }
  72          continue;
  73      }
  74      
  75      // for each action, get the conditions and see if it triggered any issues
  76      $found = 0;
  77      for ($y = 0; $y < count($reminders[$i]['actions']); $y++) {
  78          if (Reminder::isDebug()) {
  79              echo "Processing Reminder Action '" . $reminders[$i]['actions'][$y]['rma_title'] . "'\n";
  80          }
  81          $conditions = Reminder_Condition::getList($reminders[$i]['actions'][$y]['rma_id']);
  82          if (count($conditions) == 0) {
  83              if (Reminder::isDebug()) {
  84                  echo "  - Skipping Reminder because there were no reminder conditions found\n";
  85              }
  86              continue;
  87          }
  88          $issues = Reminder::getTriggeredIssues($reminders[$i], $conditions);
  89          // avoid repeating reminder actions, so get the list of issues 
  90          // that were last triggered with this reminder action ID
  91          $repeat_issues = Reminder_Action::getRepeatActions($issues, $reminders[$i]['actions'][$y]['rma_id']);
  92          if (count($repeat_issues) > 0) {
  93              // add the repeated issues to the list of already triggered 
  94              // issues, so they get ignored for the next reminder actions
  95              for ($w = 0; $w < count($repeat_issues); $w++) {
  96                  if (Reminder::isDebug()) {
  97                      echo "  - Adding repeated issue '" . $repeat_issues[$w] . "' to the list of already triggered issues\n";
  98                  }
  99                  $triggered_issues[] = $repeat_issues[$w];
 100              }
 101          }
 102          if (count($issues) > 0) {
 103              for ($z = 0; $z < count($issues); $z++) {
 104                  if (Reminder::isDebug()) {
 105                      echo "  - Processing issue '" . $issues[$z] . "'\n";
 106                  }
 107                  // only perform one action per issue id
 108                  if (in_array($issues[$z], $triggered_issues)) {
 109                      if (Reminder::isDebug()) {
 110                          echo "  - Ignoring issue '" . $issues[$z] . "' because it was found in the list of already triggered issues\n";
 111                      }
 112                      continue;
 113                  }
 114                  $triggered_issues[] = $issues[$z];
 115                  if (Reminder::isDebug()) {
 116                      echo "  - Triggered Action '" . $reminders[$i]['actions'][$y]['rma_title'] . "' for issue #" . $issues[$z] . "\n";
 117                  }
 118                  Reminder_Action::perform($issues[$z], $reminders[$i], $reminders[$i]['actions'][$y]);
 119              }
 120          } else {
 121              if (Reminder::isDebug()) {
 122                  echo "  - No triggered issues for action '" . $reminders[$i]['actions'][$y]['rma_title'] . "'\n";
 123              }
 124          }
 125      }
 126  }
 127  
 128  // release the lock
 129  Lock::release('check_reminders');


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