2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
38 class SugarTestTrackerUtility
40 private static $_trackerSettings = array();
41 private static $_monitorId = '';
43 private function __construct() {}
45 public static function setup()
47 require('modules/Trackers/config.php');
48 foreach($tracker_config as $entry) {
49 if(isset($entry['bean'])) {
50 $GLOBALS['tracker_' . $entry['name']] = false;
54 $result = $GLOBALS['db']->query("SELECT category, name, value from config WHERE category = 'tracker' and name != 'prune_interval'");
55 while($row = $GLOBALS['db']->fetchByAssoc($result)){
56 self::$_trackerSettings[$row['name']] = $row['value'];
57 $GLOBALS['db']->query("DELETE FROM config WHERE category = 'tracker' AND name = '{$row['name']}'");
61 public static function restore()
63 foreach(self::$_trackerSettings as $name=>$value) {
64 $GLOBALS['db']->query("INSERT INTO config (category, name, value) VALUES ('tracker', '{$name}', '{$value}')");
68 public static function insertTrackerEntry($bean, $action)
70 require_once('modules/Trackers/TrackerManager.php');
71 $trackerManager = TrackerManager::getInstance();
72 $timeStamp = gmdate($GLOBALS['timedate']->get_db_date_time_format());
73 $_REQUEST['action'] = $action;
74 if($monitor = $trackerManager->getMonitor('tracker'))
76 $monitor->setValue('action', $action);
77 $monitor->setValue('user_id', $GLOBALS['current_user']->id);
78 $monitor->setValue('module_name', $bean->module_dir);
79 $monitor->setValue('date_modified', $timeStamp);
80 $monitor->setValue('visible', (($action == 'detailview') || ($action == 'editview')
83 if (!empty($bean->id))
85 $monitor->setValue('item_id', $bean->id);
86 $monitor->setValue('item_summary', $bean->get_summary_text());
89 //If visible is true, but there is no bean, do not track (invalid/unauthorized reference)
90 //Also, do not track save actions where there is no bean id
91 if($monitor->visible && empty($bean->id))
93 $trackerManager->unsetMonitor($monitor);
96 $trackerManager->saveMonitor($monitor, true, true);
97 if(empty(self::$_monitorId))
99 self::$_monitorId = $monitor->monitor_id;
104 public static function removeAllTrackerEntries()
106 if(!empty(self::$_monitorId))
108 $GLOBALS['db']->query("DELETE FROM tracker WHERE monitor_id = '".self::$_monitorId."'");