]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/SugarTestTrackerUtility.php
Release 6.2.0
[Github/sugarcrm.git] / tests / SugarTestTrackerUtility.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37  
38 class SugarTestTrackerUtility
39 {
40     private static $_trackerSettings = array();
41     private static $_monitorId = '';
42     
43     private function __construct() {}
44     
45     public static function setup()
46     {
47         require('modules/Trackers/config.php');
48         foreach($tracker_config as $entry) {
49             if(isset($entry['bean'])) {
50                 $GLOBALS['tracker_' . $entry['name']] = false;
51             } //if
52         } //foreach
53         
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']}'");
58         }
59     }
60     
61     public static function restore()
62     {
63         foreach(self::$_trackerSettings as $name=>$value) {
64             $GLOBALS['db']->query("INSERT INTO config (category, name, value) VALUES ('tracker', '{$name}', '{$value}')");
65         }
66     }
67     
68     public static function insertTrackerEntry($bean, $action)
69     {
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'))
75         {
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')
81                                             ) ? 1 : 0);
82
83             if (!empty($bean->id))
84             {
85                 $monitor->setValue('item_id', $bean->id);
86                 $monitor->setValue('item_summary', $bean->get_summary_text());
87             }
88
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))
92             {
93                $trackerManager->unsetMonitor($monitor);
94                return false;
95             }
96             $trackerManager->saveMonitor($monitor, true, true);
97             if(empty(self::$_monitorId))
98             {
99                 self::$_monitorId = $monitor->monitor_id;
100             }
101         }
102     }
103     
104     public static function removeAllTrackerEntries()
105     {
106         if(!empty(self::$_monitorId))
107         {
108             $GLOBALS['db']->query("DELETE FROM tracker WHERE monitor_id = '".self::$_monitorId."'");
109         }
110     }
111 }
112 ?>