Skip to content

Instantly share code, notes, and snippets.

View matthewpoer's full-sized avatar

Matthew Poer matthewpoer

View GitHub Profile
@matthewpoer
matthewpoer / account_children.sql
Created April 15, 2014 13:09
Select an Account and its Member Accounts (children)
-- select an account and its children
select parent.id,parent.name,child.parent_id,child.id,child.name from accounts parent
left join accounts child on child.parent_id=parent.id
where parent.deleted=0 and (child.deleted=0 or child.deleted is null)
order by parent.name;
@matthewpoer
matthewpoer / sugarcrm_gen_email_link.php
Created April 21, 2014 12:37
SugarCRM Email Link Generation, mailto or Sugar Email Client popup (JavaScript)
@matthewpoer
matthewpoer / .bashrc
Created April 27, 2014 02:27
Mange your music ripping from CLI/Bash (Linux Shell) with two quick functions: 'flacthiscd' will create a lossless FLAC format rip of the cd in your primary optical drive. Once that's complete, run 'mp3theseflacs' from the same directory to duplicate the files, but as lossy MP3 files (for your iPod, etc.)
# aptitude install abcde lame
# from inspired by http://pinehead.tv/linux/solution-converting-flac-to-mp3/
alias mp3theseflacs='mkdir mp3;for file in *.flac; do flac -cd "$file" | lame -h - mp3/"${file%.flac}.mp3"; done'
alias flacthiscd='abcde -o "flac" -q "high"'
@matthewpoer
matthewpoer / contact_copy_parent_account_assignment.sql
Created April 28, 2014 20:29
SugarCRM: MySQL Script will Update Contacts' Assigned User and Teams to copy from their parent Accounts.
update contacts
join (
select accounts.id as accounts_id,accounts.assigned_user_id as accounts_assigned_user_id,
accounts.team_id as accounts_team_id,accounts.team_set_id as accounts_team_set_id,
contacts.id as contact_id,contacts.assigned_user_id as contacts_assigned_user_id,
contacts.team_id as contacts_team_id,contacts.team_set_id as contacts_team_set_id
from accounts
join accounts_contacts on accounts.id = accounts_contacts.account_id
join contacts on contacts.id = accounts_contacts.contact_id
where accounts.deleted=0 and contacts.deleted=0 and accounts_contacts.deleted=0
@matthewpoer
matthewpoer / sugar_account_contact_address_matching.sql
Last active August 29, 2015 14:01
SugarCRM: MySQL script to update Account-Contact Relationships based on exact address match (i.e. Contact Primary Address fields match the Account Shipping Address perfectly)
-- remove existing account/contact relationships for all records that we might update
update accounts_contacts ac
join (
select contacts.id as contact_id,accounts.id as account_id from contacts
join accounts on contacts.primary_address_street = accounts.shipping_address_street and
contacts.primary_address_city = accounts.shipping_address_city and
contacts.primary_address_state = accounts.shipping_address_state and
contacts.primary_address_postalcode = accounts.shipping_address_postalcode
where contacts.deleted=0 and accounts.deleted=0)
as tmp on tmp.account_id = ac.account_id and tmp.contact_id = ac.contact_id
@matthewpoer
matthewpoer / SugarCRMAccountInformation.php
Last active August 29, 2015 14:01
As a SugarCRM Business Partner, we may need to obtain subscription data from the partner portal. Here's how to invoke the Partner Portal's API using cookies from your web browser, then generate a CSV with the data required.
<?php
/*
* You Need to set the $cookie param. Do so by logging into the partner portal
* at https://partners.sugarcrm.com, then log in. Then visit a the API page at
* https://partners.sugarcrm.com/account/list/5/5 with your Dev Console open.
* If you review your Resources, you can find the cookie that the portal gave
* your browser. Just copy-paste the entire set of cookies from the Request.
*/
$cookie = "";
@matthewpoer
matthewpoer / install_hack_utils.php
Last active August 29, 2015 14:01
SugarCRM 7 is only approved for PHP Version 5.3. If you run PHP 5.4 or 5.5 in your development system and need to install Sugar, you'll have to hack a core file to get it to run. Note that SugarCRM is not officially supported on PHP 5.4 or 5.5, but in my experience, it seems to run well enough.
<?php
# /include/utils.php
# line 2980 opens function check_php_version
# just make it return 1
function check_php_version($sys_php_version = '')
{
return '1';
...
}
<cfset data ={
'application' : 'myCFMapp',
'user_auth' : {
'user_name' : 'admin',
'password' : '#hash("admin")#'
},
'name_value_list' :
{
'name' : 'notifyonsave'
}
@matthewpoer
matthewpoer / SugarCRM_Rest_v4_1.md
Created June 4, 2014 20:27
This document is intended to provide a language-neutral guide of using the SugarCRM Rest API v4_1 by displaying the HTTP POSTs used to send and request data. I believe that these POSTs are the best way to understand how these API calls work, since some information is carried in the POST and some as JSON-encoded arrays.

SugarCRM REST API (v4_1)

This document is intended to provide a language-neutral guide of using the SugarCRM Rest API v4_1 by displaying the HTTP POSTs used to send and request data. I believe that these POSTs are the best way to understand how these API calls work, since some information is carried in the POST and some as JSON-encoded arrays.

Please also note that SugarCRM offers a newer version of it's REST API, dubbed

@matthewpoer
matthewpoer / before_save.php
Created July 4, 2014 12:32
SugarCRM: How to get a record's email address in Sugar7 API vs. legacy services (including web to lead form entrypoint)
class myClass{
public function myMethod($bean,$event,$arguments){
// if we are using a legacy API or web-to-lead form, email address is in email1
$GLOBALS['log']->fatal("email1 value: {$bean->email1}");
// but if we're on that sugar7 API or sugar7 interface (which uses said API...)
$sea = new SugarEmailAddress();
$email = $sea->getPrimaryAddress($bean);