Skip to content

Instantly share code, notes, and snippets.

@jmertic
jmertic / gist:6294266
Created August 21, 2013 13:10
Silent install a package on an instance from the command line in SugarCRM with this script
#!/usr/bin/env php
<?php
function usage()
{
print("usage: -i /path/to/instance -p /path/to/expanded/module -z /path/to/zipfile\n");
exit(1);
}
$opts = getopt('i:p:z:');
<?php
function process()
{
// Custom SQL
$lvsParams = array(
'custom_select' => ',calls.id AS call_id',
'custom_from' => ' LEFT JOIN calls ON calls.parent_id = accounts.id',
'custom_where' => ' AND (calls.id IS NULL)',
'distinct' => true
<?php
function getRelationshipByModules ($m1, $m2)
{
global $db,$dictionary,$beanList;
$rel = new Relationship;
if($rel_info = $rel->retrieve_by_sides($m1, $m2, $db)){
$bean = BeanFactory::getBean($m1);
$rel_name = $rel_info['relationship_name'];
foreach($bean->field_defs as $field=>$def){
<script type="text/javascript">
<!--
function setCookie(name, value, days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + value + expires;
}
var query = window.location.search.substr(1);
if (empty($bean->fetched_row['id']) {
// Do custom logic for only a newly created record
}
<?php
class FieldChangeHook
{
protected static $fetchedRow = array();
/**
* Called as before_save logic hook to grab the fetched_row values
*/
public function saveFetchedRow($bean, $event, $arguments)
@jmertic
jmertic / gist:5730287
Last active November 14, 2017 13:22
Sample PHP script for connecting to the new RESTful SugarCRM REST API in 6.7 and later.
<?php
// specify the REST web service to interact with
$baseurl = '<<instanceurl>>/rest/v10';
/**
* Authenicate and get back token
*/
$curl = curl_init($baseurl . "/oauth2/token");
curl_setopt($curl, CURLOPT_POST, true);
<?php
require_once('include/MVC/View/views/view.list.php');
class CustomAccountsViewList extends ViewList
{
/**
* @see ViewList::preDisplay()
*/
public function preDisplay()
<?php
class CustomAccountsController extends SugarController
{
public function action_displaypassedids() {
if ( !empty($_REQUEST['uid']) ) {
$recordIds = explode(',',$_REQUEST['uid']);
foreach ( $recordIds as $recordId ) {
$bean = SugarModule::get($_REQUEST['module'])-&gt;loadBean();
$bean->retrieve($recordId);
@jmertic
jmertic / gist:5844627
Last active August 4, 2017 04:45
Sample Java code using Jersey and JSONObject for connecting to the new RESTful SugarCRM REST API in 6.7 and later.
package com.sugarcrm.client;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import net.sf.json.JSONObject;
public class JerseyClientPost {
public static void main(String[] args) {