Skip to content

Instantly share code, notes, and snippets.

View matthewpoer's full-sized avatar

Matthew Poer matthewpoer

View GitHub Profile
@matthewpoer
matthewpoer / JobQueueStatusCheck.sql
Created March 20, 2015 15:03
Show the number of job_queue records in various status for each name/type of job
select count(*), status, name from job_queue group by name, status;
@matthewpoer
matthewpoer / sugarfield_.sh
Created March 9, 2015 03:40
For every file in this directory, create a new file of the exact same name but prefixed by sugarfield_
find *php -exec touch sugarfield_{} \;
@matthewpoer
matthewpoer / ProductTemplateExpiration.php
Last active August 29, 2015 14:16
SugarCRM Scheduler example shows a DO and DON'T way of updating records. The DO includes proper code annotation, using SugarQuery to pull records, and updating the found records without changing the record's modification metadata. These files should reside in custom/Extension/modules/Schedulers/Ext/ScheduledTasks/
<?php
array_push($job_strings, 'UpdateProductTemplatesExpiration');
function UpdateProductTemplatesExpiration(){
$product_bean = new ProductTemplate();
if(isset($product_bean->field_defs['end_date_c']) && isset($product_bean->field_defs['is_expired_c'])
&& $product_bean->field_defs['end_date_c']['source'] == 'custom_fields'
&& $product_bean->field_defs['is_expired_c']['source'] == 'custom_fields'){
$query = "update product_templates_cstm set is_expired_c = if(datediff(utc_timestamp(), end_date_c)>0, 'yes' , 'no') ";
$db = DBManagerFactory::getInstance();
@matthewpoer
matthewpoer / account_team_info
Created February 19, 2015 20:13
Queries to reveal an Account record's Teams and Users through the Team Set (team_set_id)
-- Reference: Query to fetch information for a specific Account's teams
-- (ignores team_id, focus on team_set_id)
select accounts.id, accounts.name, accounts.team_id, accounts.team_set_id,
teams.id, teams.name, teams.description
from accounts
join team_sets on accounts.team_set_id = team_sets.id and team_sets.deleted=0
join team_sets_teams on team_sets_teams.team_set_id = team_sets.id and team_sets_teams.deleted=0
join teams on teams.id = team_sets_teams.team_id and teams.deleted=0
where accounts.id = 'SOMEACCOUNTID' and accounts.deleted=0;
@matthewpoer
matthewpoer / sync_all_to_outlook.sql
Created October 31, 2014 06:33
SugarCRM 6/7 customization to automatically check the Sync to Outlook checkbox for all Contacts and Users in the system. Skips inactive/reserved users (e.g. SNIP User) and any deleted records.
delete from contacts_users;
insert into contacts_users
(id,contact_id,user_id,date_modified,deleted)
select UUID(), contacts.id, users.id, now(), 0
from contacts, users
where users.deleted=0 and contacts.deleted=0
and users.status='Active';
@matthewpoer
matthewpoer / aos_to_sugar_quotes.md
Created September 5, 2014 07:47
Advance Open Sales Quotes to SugarCRM Quotes

Quote Conversion

The following scripts and commentary are a general guide that I created while migrating a customer from SugarCRM Community Edition with the Advanced OpenSales plugin to SugarCRM Professional using the built-in Quotes and Products modules. It's not perfect, and your mileage may very, but I hope it assists someone else as a solid starting point for a similar migration from AOS/SuiteCRM back to SugarCRM Pro.

These scripts ignore the PDF Template and Contract functionality from AOS. These were not relevant to my project, so I have no reason to attempt them.

populate product catalog

insert into product_templates

(id, deleted, date_entered, date_modified, modified_user_id, created_by, type_id, manufacturer_id, category_id, name, mft_part_num, vendor_part_num, date_cost_price, cost_price, discount_price, list_price, cost_usdollar, discount_usdollar, list_usdollar, currency_id, currency, status, tax_class, date_available, website, weight, qty_in_stock, description, support_name, supp

@matthewpoer
matthewpoer / gist:14a322fae54d5c6c6d8f
Created August 25, 2014 14:03
Regex to match lines that *do not* contain a string "name"
^((?!name).).+
<?php
$dictionary['Opportunity']['fields']['loc_completed_approved_by_id']['name'] = 'loc_completed_approved_by_id';
$dictionary['Opportunity']['fields']['loc_completed_approved_by_id']['vname'] = 'LBL_COMPLETED_APPROVED_BY_ID';
$dictionary['Opportunity']['fields']['loc_completed_approved_by_id']['type'] = 'id';
$dictionary['Opportunity']['fields']['loc_completed_approved_by']['name'] = 'loc_completed_approved_by';
$dictionary['Opportunity']['fields']['loc_completed_approved_by']['vname'] = 'LBL_COMPLETED_APPROVED_BY';
$dictionary['Opportunity']['fields']['loc_completed_approved_by']['type'] = 'relate';
$dictionary['Opportunity']['fields']['loc_completed_approved_by']['source'] = 'non-db';
$dictionary['Opportunity']['fields']['loc_completed_approved_by']['id_name'] = 'loc_completed_approved_by_id';
@matthewpoer
matthewpoer / notes_from_act.sql
Created August 11, 2014 15:18
Import from CSV to MySQL table using "load data local" and the CSV has damn newlines in the data. Make sure all fields are enclosed correctly in quotes.
load data local infile '/Users/MKP01/Documents/Studio Center/Matt Import/notes_csv_fixed_quote/note.csv'
into table notes
fields terminated by ','
enclosed by '"'
-- lines terminated by '\n'
ignore 1 lines
(contact_id,@date_entered,@created_by,@date_modified,modified_user_id,description,@bad_id,name)
set id = UUID(),
date_entered = STR_TO_DATE(@date_entered,'%m/%e/%Y %H:%i'),
@matthewpoer
matthewpoer / fix
Created July 18, 2014 12:17
fix for that damn wordpress bug I keep getting hit by
grep -rl '<?php $yquvlqbrgv' . | xargs sed -i '1 s/^.*$/<?php/g'