]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Trackers/populateSeedData.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Trackers / populateSeedData.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
40
41
42
43 require_once('modules/Trackers/TrackerUtility.php');
44
45 require_once('install/UserDemoData.php');
46
47 class populateSeedData {
48
49 var $monitorIds = 500;
50 var $user = 1;
51 var $userDemoData;
52 var $modules = array('Accounts', 'Calls', 'Contacts', 'Leads', 'Meetings', 'Notes', 'Opportunities', 'Users');
53 var $actions = array('authenticate', 'detailview', 'editview', 'index', 'save', 'settimezone');
54 var $db;
55 var $beanIdMap = array();
56 var $userSessions = array();
57 var $trackerManager;
58
59 function start() {
60     $this->db = DBManagerFactory::getInstance();
61     $this->userDemoData = new UserDemoData($this->user, false);
62     $this->trackerManager = TrackerManager::getInstance();
63
64         foreach($this->modules as $mod) {
65                 $query = "select id from $mod";
66                 $result = $this->db->limitQuery($query, 0, 50);
67                 $ids = array();
68                 while(($row = $this->db->fetchByAssoc($result))) {
69                            $ids[] = $row['id'];
70                 } //while
71                 $this->beanIdMap[$mod] = $ids;
72         }
73
74         while($this->monitorIds-- > 0) {
75                 $this->monitorId = create_guid();
76                 $this->trackerManager->setMonitorId($this->monitorId);
77                 $this->user = $this->userDemoData->guids[array_rand($this->userDemoData->guids)];
78                 $this->module = $this->modules[array_rand($this->modules)];
79             $this->action = $this->actions[array_rand($this->actions)];
80             $this->date = $this->randomTimestamp();
81                 $this->populate_tracker();
82                 $this->trackerManager->save();
83         }
84 }
85
86 function populate_tracker() {
87     if($monitor = $this->trackerManager->getMonitor('tracker')){
88             $monitor->setValue('user_id', $this->user);
89             $monitor->setValue('module_name', $this->module);
90             $monitor->setValue('action', $this->action);
91             $monitor->setValue('visible', (($monitor->action == 'detailview') || ($monitor->action == 'editview')) ? 1 : 0);
92             $monitor->setValue('date_modified', $this->randomTimestamp());
93             $monitor->setValue('session_id', $this->getSessionId());
94             if($this->action != 'settimezone' && isset($this->beanIdMap[$this->module][array_rand($this->beanIdMap[$this->module])])) {
95                $monitor->setValue('item_id', $this->beanIdMap[$this->module][array_rand($this->beanIdMap[$this->module])]);
96                $monitor->setValue('item_summary', 'random stuff'); //don't really need this
97             }
98         }
99 }
100
101
102 function randomTimestamp() {
103    global $timedate;
104    // 1201852800 is 1 Feb 2008
105    return $timedate->fromTimestamp(rand(1201852800, $timedate->getNow()->ts))->asDb();
106 }
107
108 function getSessionId() {
109    if(isset($this->userSessions[$this->user])) {
110           return $this->userSessions[$this->user];
111    }
112    $this->userSessions[$this->user] = $this->monitorId;
113    return $this->monitorId;
114 }
115
116 }
117
118 $test = new populateSeedData();
119 $test->start();
120
121 ?>