Skip to content

Instantly share code, notes, and snippets.

View matthewpoer's full-sized avatar

Matthew Poer matthewpoer

View GitHub Profile
@matthewpoer
matthewpoer / gist:1076786
Created July 11, 2011 21:01
.gitignore and git status output
$ cat .gitignore
.idea/
wp-config.php
wordpress_prod.sql# On branch dev
$ git status
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
@matthewpoer
matthewpoer / MLCMI Meeting Cleanup
Created June 11, 2013 04:18
System had some dramatic Meeting record duplication after using the Outlook plugin plus and an Exchange integration at the same time. Luckily, the duplicate records seem to match exactly on the name and date_start, so we have something solid to merge off of.
-- create a temp table to house dup'd ids
create table `meetings_dup_ids` (
`id` varchar(36) NOT NULL,
PRIMARY KEY (`id`)
);
-- copy the dup IDs into the temp table...
insert into meetings_dup_ids(id)
select distinct(one.id) from meetings one
join meetings two on one.name = two.name and one.date_start=two.date_start
@matthewpoer
matthewpoer / Opportunities DuDup
Last active December 18, 2015 08:49
I wrote a script that created new Opportunities, but I set the timing wrong and it ran every hour instead of once a day. This created a bit of a mess... here's how I cleaned it up.
-- setup temp table
create table `opp_dups` (
`id` varchar(36) NOT NULL,
PRIMARY KEY (`id`)
);
-- copy the dup IDs into the temp table...
insert into opp_dups(id)
select distinct(opp1.id) from opportunities opp1
join opportunities opp2 on opp1.name=opp2.name and opp1.id <> opp2.id
@matthewpoer
matthewpoer / MLCMI Account to Contact Swap
Created June 21, 2013 02:29
Customer custom module has a relate field to Account. Need to swap that for a one:many relationship to contacts and maintain as much data as possible.
truncate contacts_campa_campaigncommittee_1_c;
select * from contacts_campa_campaigncommittee_1_c;
-- Copy all of the data, using account_id for contact_id even though it's wrong
insert into contacts_campa_campaigncommittee_1_c
(id,date_modified,deleted,
contacts_campa_campaigncommittee_1contacts_ida,
contacts_campa_campaigncommittee_1campa_campaigncommittee_idb)
select campa_campaigncommittee_cstm.id_c,now(),0,
campa_campaigncommittee_cstm.account_id_c,
@matthewpoer
matthewpoer / Reset Scheduler Log
Created July 24, 2013 16:35
Sometimes you want to make that scheduler run again, damnit. You need to clear the log and pretend that the scheduler hasn't run ever/in a long time. So throw this at your database, replacing the ID with that of the Scheduler you're working on.
delete from job_queue
where scheduler_id = '6b867112-a876-a867-2df1-5088b60bb6d2';
update schedulers set last_run = subdate(now(),360)
where id = '6b867112-a876-a867-2df1-5088b60bb6d2';
@matthewpoer
matthewpoer / gist:6342398
Created August 26, 2013 15:03
Update Contact records to match the User Assignment (assigned_user_id) of their related Account
-- Find the Contacts whose User Assignments do not match that of parent Accounts
select
contacts.last_name,contacts.assigned_user_id,
accounts.name,accounts.assigned_user_id
from contacts
join accounts_contacts on contacts.id = accounts_contacts.contact_id
join accounts on accounts.id = accounts_contacts.account_id
where contacts.deleted=0 and accounts_contacts.deleted=0 and accounts.deleted=0
and contacts.assigned_user_id <> accounts.assigned_user_id;
@matthewpoer
matthewpoer / gist:6355610
Created August 27, 2013 16:10
Monthly Opps report for CE
select sum(amount),month(date_closed) from opportunities where sales_stage in ('Closed Won','Closed_in_Development') group by year(date_closed),month(date_closed) order by date_closed;
@matthewpoer
matthewpoer / SugarFieldPhone.php
Last active April 17, 2021 19:06
SugarCRM Phone Number Formatting. Store only the phone number integers and use only that in the EditView, but DetailView and ListView show a pretty format like 1 (123) 123-1234. Does not format for Reports.
<?php
// custom/include/SugarFields/Fields/Phone/SugarFieldPhone.php
require_once('include/SugarFields/Fields/Phone/SugarFieldPhone.php');
class CustomSugarFieldPhone extends SugarFieldPhone{
private $replacement_chars = array(' ','-','(',')','x','X','.','+','#','!');
/**
* Remove any special characters to sanitize input, storing only ints
* @see parent::save
@matthewpoer
matthewpoer / selfie
Created September 20, 2013 16:00
In response to the idea of using "selfie" as programming/PHP slang... https://twitter.com/dabeaz/status/381014108906074113
<?php
class SomeClass{
public static function selfie(){
return new self();
}
}
@matthewpoer
matthewpoer / manifest.php
Created September 24, 2013 11:57
Example SugarCRM package's manifest using layoutfields to add a new custom field to the existing layout
<?php
$manifest = array(
'acceptable_sugar_versions' => array(),
'acceptable_sugar_flavors' => array(),
'readme' => '',
'key' => 'PSI',
'author' => 'Profiling Solutions',
'description' => ' Provide example manifest with layoutfields array ',
'icon' => '',
'is_uninstallable' => true,