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-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
43 require_once('modules/Trackers/TrackerUtility.php');
45 require_once('install/UserDemoData.php');
47 class populateSeedData {
49 var $monitorIds = 500;
52 var $modules = array('Accounts', 'Calls', 'Contacts', 'Leads', 'Meetings', 'Notes', 'Opportunities', 'Users');
53 var $actions = array('authenticate', 'detailview', 'editview', 'index', 'save', 'settimezone');
55 var $beanIdMap = array();
56 var $userSessions = array();
60 $this->db = DBManagerFactory::getInstance();
61 $this->userDemoData = new UserDemoData($this->user, false);
62 $this->trackerManager = TrackerManager::getInstance();
64 foreach($this->modules as $mod) {
65 $query = "select id from $mod";
66 $result = $this->db->limitQuery($query, 0, 50);
68 while(($row = $this->db->fetchByAssoc($result))) {
71 $this->beanIdMap[$mod] = $ids;
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();
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
102 function randomTimestamp() {
104 // 1201852800 is 1 Feb 2008
105 return $timedate->fromTimestamp(rand(1201852800, $timedate->getNow()->ts))->asDb();
108 function getSessionId() {
109 if(isset($this->userSessions[$this->user])) {
110 return $this->userSessions[$this->user];
112 $this->userSessions[$this->user] = $this->monitorId;
113 return $this->monitorId;
118 $test = new populateSeedData();