LoggerManager::getLogger()->fatal('');
dump_slow_queries @see include/database/DBManager.php
//For example a new account bean:
$accountBean = BeanFactory::newBean('Accounts');
// retrieve account by id
$account_x = BeanFactory::getBean('Accounts', $beanId);
$account_x->get_list( // paginated
$order_by = "",
$where = "",
$row_offset = 0,
$limit=-1,
$max=-1,
$show_deleted = 0);
$beanList = $accountBean->get_full_list(
$order_by='name',
$where = "accounts.industry = 'Media'"
);
//Get the Name field on account bean
$accountBean->name;
//Get a custom field on a case
$caseBean->third_party_code_c;
//Set the name of a case
$caseBean->name = 'New Case name';
$accountBean->save();
// linked beans
$accountBean->get_linked_beans(..)
//Load the relationship
$accountBean->load_relationships();
$accountBean->load_relationship('contacts');
//Can now call methods on the relationship object:
$contactIds = $accountBean->contacts->get();
//saving a related bean
$accountBean->load_relationship('contacts');
//Create a new demo contact
$contactBean = BeanFactory::newBean();
$contactBean->first_name = 'Jim';
$contactBean->last_name = 'Mackin';
$contactBean->save();
//Link the bean to $accountBean
$accountBean->contacts->add($contactBean);
// delete the relationship
$accountBean->contacts->delete($accountBean->id, $contactBean);
// direct query
$db = DBManagerFactory::getInstance();
$db->quote($xxx);
$result = $db->query($query);
$i = -1;
while (($row = $db->fetchByAssoc($result)) != null) { $i++; $rows[$i] = $row; }
original record:
$anagrafica_CRM->fetched_row
$sea = new SugarEmailAddress();
$sea->addAddress($ew_email,
$primary = true,
$replyTo = true,
$invalid = false,
$optOut = false,
$email_id = null,
$optIn = false
);
// save, with relationship to account
$sea->save($bean_id = $anagrafica_CRM->id, $module_name = 'Accounts');
// retrieve primary
echo "primary addr:" . $sea->getPrimaryAddress($anagrafica_CRM) . "<br />\n";
// tutti gli indirizzi con vari flags
$addresses = $sea->getAddressesByGUID($bean_id = $anagrafica_CRM->id, $module_name = 'Accounts');
foreach ($addresses as $address) {
echo 'get addr:' . $address->email_address . "<br />\n";
}
// alt.
// see $anagrafica_CRM->get_linked_fields()
$anagrafica_CRM->load_relationship($field = 'email_addresses');
foreach ($anagrafica_CRM->emailAddress->addresses as $p) {
echo 'addresses:' . $p['email_address'];
}
$sql = "SELECT eabr.bean_id
FROM email_addr_bean_rel eabr JOIN email_addresses ea
ON (ea.id = eabr.email_address_id)
WHERE eabr.deleted=0 AND ea.email_address = 'foo@bar.com' ";
activerecord models require_once 'data/SugarBean.php'; => implements CRUD
class Tracker extends SugarBean {}
- Dictionary:
VardefManager::loadVardef($this->module_dir, $this->object_name);
Example code creating a relationship from a new Contact to an Account: // get Bean for pre-existing Accountt: $account = BeanFactory::getBean(‘Accounts’)->retrieve_by_string_fields(array(‘name’=> ‘SomeAccount’)); $someContact->load_relationship(‘accounts’); $someContact->accounts->add($account->id);
sugar_cache_put($key, $value);
Views can be found in modules/
{php}
global $foo, $bar;
if($foo == $bar){
echo 'This will be sent to browser';
}
// assign a variable to Smarty
$this->assign('varX','Toffee');
{/php}
{* output the variable *}
<strong>{$varX}</strong>
defined by: custom/module/MODULE_NAME/metadata/editviewdefs.php
adding "customCode" key in the edit view to field.
array (
'name' => 'vehicle_origin,
'label' => 'LBL_VEHICLE_ORIGIN',
'customCode' => '
<input type="text" name="vehicle_origin" class="myclass" id="vehicle_origin" value="{$fields.vehicle_origin.value}">',
),
$GLOBALS['logic_hook']->call_custom_logic('', 'after_ui_footer');
sudo crontab -e -u www-data ## and add the following line to the crontab file: * * * * * cd /var/www_test/SuiteCRM-7.11.18; php -f cron.php > /dev/null 2>&1
writing a scheduled task:
touch custom/Extension/modules/Schedulers/Ext/ScheduledTasks/_same_as_function_name_.php
<?php
array_push($GLOBALS['job_strings'], 'update_user_day_count');
function update_user_day_count() {
// ... your business Logic
return true;
}
touch /custom/Extension/modules/Schedulers/Ext/Language/it_IT._same_as_function_name_.php
<?php
$mod_strings['LBL_UPDATE_USER_DAY_COUNT'] = 'yor function descriptive name';
check running info for the task:
SELECT * FROM job_queue ORDER BY date_entered DESC LIMIT 0,10
inDeveloperMode()
$GLOBALS['current_user']