Skip to content

Instantly share code, notes, and snippets.

View chadhutchins's full-sized avatar

Chad Hutchins chadhutchins

View GitHub Profile
<?php
// given a proper $token and $consumer...
require_once('include/api/RestService.php');
require_once('clients/base/api/OAuth2Api.php');
$service = new RestService();
$api = new OAuth2Api();
client = ZAFClient.init();
var settings = {
url: '{{setting.sugarUrl}}',
headers: {'oauth-token': '{{setting.sugarOauthAccessToken}}'},
secure: true,
type: 'GET',
dataType: 'json',
contentType: 'application/json',
};
client.request(settings).then(function(data){console.log(data);});
-- works in MySQL, fails in MSSQL
SELECT * FROM contacts WHERE IFNULL(title,’’)=’CEO’;
-- works in MSSQL
SELECT * FROM contacts WHERE ISNULL(title,’’)=’CEO’;
-- works in MySQL, fails in MSSQL
SELECT * FROM contacts WHERE title=’CEO’ && title=’CTO’;
-- works in both MySQL and MSSQL
SELECT * FROM contacts WHERE title=’CEO’ AND title=’CTO’;
<?php
global $db;
echo $db->dbType;
if ($db->dbType == ‘mysql’) echo “MySQL is being used”;
if ($db->dbType == ‘mssql’) echo “MSSQL is being used”;
<?php
// notice the upper-case letter ‘m’
require_once(‘modules/MyModule/MyModule.php’);
@chadhutchins
chadhutchins / mailchimp-v3-batch-updates.php
Created December 4, 2015 17:35
This script shows how to use the MailChimp v3 API to re-subscribe a large group of mistakingly unsubscribed email addresses in a MailChimp List. There are a couple examples commented out that can be used. The first shows how to look up the status of a batch API call sent to MailChimp. And the second shows how to make a batch API call to re-subsc…
<?php
// replace this with your mailchimp api key
$mailchimp_apikey = "mailchimp-api-key-goes-here";
// create mailchimp api object that is used later to make api calls
$mcapi = new MailChimp_API($mailchimp_apikey);
/**
// Use the following code if you want to look up the status of a batch call
@chadhutchins
chadhutchins / proxy.php
Last active December 6, 2019 18:00
Proxy Script to allow Sugar to Receive MailChimp Webhooks using SugarChimp
<?php
/**
If you want to keep your SugarCRM server non-accessible from the outside web
But you still want to receive MailChimp updates with SugarChimp, this script will help you do so
You need to make this script accessible from the outside web and it will allow MailChimp to connect to Sugar through the SuagrChimpWebhook entrypoint
All other Sugar requests will get ignored
Be sure to change the $sugar_url variable to the path of your index.php script inside your Sugar folder
*/
@chadhutchins
chadhutchins / gist:2fe3dd0bce97413b2c5b
Created April 21, 2015 21:04
Classes for creating your own custom queue table to run on Sugar's On-demand Scheduler
<?php
$job_strings[] = 'YourJobQueue';
function YourJobQueue()
{
$queues_to_process = array(
'FirstQueue',
'SecondQueue',
'ThirdQueue',
<?php
/**
* Put this immediately before line 92 in SugarModules/modules/off_Dynamic_Target_List/dynamic_AddJobsHere.php
**/
// check if sugarchimp table exists and the list has a synced mailchimp list id
if (!empty($obj_custom->mailchimp_list_name_c) && $db->getRowCount($db->query("SHOW TABLES LIKE 'sugarchimp'"))==1)
{
// insert 'remove mailchimp subscriber' jobs for each record that is getting removed from the prospect_lists_prospects table