Skip to content

Instantly share code, notes, and snippets.

@dmulvi
Last active November 17, 2015 21:23
Show Gist options
  • Select an option

  • Save dmulvi/8062d707953d4177c224 to your computer and use it in GitHub Desktop.

Select an option

Save dmulvi/8062d707953d4177c224 to your computer and use it in GitHub Desktop.
Push out dashboard to other users in SugarCRM 7.
<?php
/**
* SugarCRM 7 Intelligence Pane Pusher
* Make it possible to push dashboards out to users.
*
* Run this as an entryPoint.
*
* Here is a really long, ugly link (that probably won't work when
* you need it) that describes how to setup an entrypoint.
* http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Entry_Points/Creating_Custom_Entry_Points/index.html
*
* @author Epicom::DannyMulvihill()
*
* Be mindful that is runs direct db queries. You should always
* backup your database before running something like this. You
* only need to backup the dashboards table though.
*
* This has not been tested a lot. I only needed to push out
* dashboards for all users on a single module. I added options
* where it made sense, but did not test those scenarios.
*/
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $db;
/*****************************************************
**** CONFIGURATION
*****************************************************/
$dashboard_id = '5f03eb33-3392-0f67-778b-564a15dcba2a';
$module_name = 'Accounts';
$user_list = array(); // set manually or use a query to grab the user ids
$source_is_db = true; // if you manually fill array above set this to false
$delete_other = true; // this will remove other dashboards the user has for $module_name
/*****************************************************
**** CLEAR USER'S CURRENT MODULE DASHBOARDS
*****************************************************/
if ($delete_other) {
$sql = "UPDATE dashboards
SET deleted = 1,
date_modified = NOW(),
modified_user_id = '1'
WHERE dashboard_type = 'dashboard'
AND dashboard_module = '$module_name'";
if (!$source_is_db) {
$str = "'".implode("','", $user_list)."'";
$sql .= " AND assigned_user_id IN ($str)";
}
$db->query($sql);
}
/*****************************************************
**** SOURCE_IS_DB - GET THE USERS
*****************************************************/
if ($source_is_db) {
$sql = "SELECT id FROM users WHERE deleted = 0";
$res = $db->query($sql);
while ($row = $db->fetchByAssoc($res)) {
$user_list[] = $row['id'];
}
}
/*****************************************************
**** PUSH THE DASHBOARDS OUT TO SELECTED USERS
*****************************************************/
foreach ($user_list as $user_id) {
$sql = "INSERT INTO dashboards
SELECT
UUID(),
name,
NOW(),
NOW(),
'1',
'1',
'',
0,
'$user_id',
'$module_name',
'records',
metadata,
'dashboard'
FROM dashboards
WHERE id = '$dashboard_id'";
$db->query($sql);
}
/*****************************************************
**** MAKE IT LOOK PRETTY
*****************************************************/
$str = "'".implode("','", $user_list)."'";
$sql = "SELECT id, user_name, first_name, last_name
FROM users
WHERE id IN ($str)";
$res = $db->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Dashboard Pusher</title>
<style type="text/css">
body {padding: 20px; background: #000; color: #ccc; font-family: sans-serif;}
a:link,a:visited {color:#0086e3;text-decoration:none;}
</style>
</head>
<body>
<h3> Dashboards Pushed out Successfully for the following Users:</h3>
<?php while($user = $db->fetchByAssoc($res)) {
echo <<<HREF
<a href="/#bwc/index.php?module=Users&action=DetailView&record={$user['id']}">
{$user['first_name']} {$user['last_name']} ({$user['user_name']})
</a><br/>
HREF;
} ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment