2 class SugarTestTrackerUtility
4 private static $_trackerSettings = array();
5 private static $_monitorId = '';
7 private function __construct() {}
9 public static function setup()
11 require('modules/Trackers/config.php');
12 foreach($tracker_config as $entry) {
13 if(isset($entry['bean'])) {
14 $GLOBALS['tracker_' . $entry['name']] = false;
18 $result = $GLOBALS['db']->query("SELECT category, name, value from config WHERE category = 'tracker' and name != 'prune_interval'");
19 while($row = $GLOBALS['db']->fetchByAssoc($result)){
20 self::$_trackerSettings[$row['name']] = $row['value'];
21 $GLOBALS['db']->query("DELETE FROM config WHERE category = 'tracker' AND name = '{$row['name']}'");
25 public static function restore()
27 foreach(self::$_trackerSettings as $name=>$value) {
28 $GLOBALS['db']->query("INSERT INTO config (category, name, value) VALUES ('tracker', '{$name}', '{$value}')");
32 public static function insertTrackerEntry($bean, $action)
34 require_once('modules/Trackers/TrackerManager.php');
35 $trackerManager = TrackerManager::getInstance();
36 $timeStamp = gmdate($GLOBALS['timedate']->get_db_date_time_format());
37 $_REQUEST['action'] = $action;
38 if($monitor = $trackerManager->getMonitor('tracker'))
40 $monitor->setValue('action', $action);
41 $monitor->setValue('user_id', $GLOBALS['current_user']->id);
42 $monitor->setValue('module_name', $bean->module_dir);
43 $monitor->setValue('date_modified', $timeStamp);
44 $monitor->setValue('visible', (($action == 'detailview') || ($action == 'editview')
45 || ($action == 'wirelessdetail') || ($action == 'wirelessedit')
48 if (!empty($bean->id))
50 $monitor->setValue('item_id', $bean->id);
51 $monitor->setValue('item_summary', $bean->get_summary_text());
54 //If visible is true, but there is no bean, do not track (invalid/unauthorized reference)
55 //Also, do not track save actions where there is no bean id
56 if($monitor->visible && empty($bean->id))
58 $trackerManager->unsetMonitor($monitor);
61 $trackerManager->saveMonitor($monitor, true, true);
62 if(empty(self::$_monitorId))
64 self::$_monitorId = $monitor->monitor_id;
69 public static function removeAllTrackerEntries()
71 if(!empty(self::$_monitorId))
73 $GLOBALS['db']->query("DELETE FROM tracker WHERE monitor_id = '".self::$_monitorId."'");