Skip to content

Instantly share code, notes, and snippets.

Avatar

Enrico Simonetti esimonetti

View GitHub Profile
@esimonetti
esimonetti / SugarACLLock.php
Last active May 2, 2020
SugarCRM v7 - Conditional record locking through ACL's customisation
View SugarACLLock.php
<?php
//
// Enrico Simonetti
// enricosimonetti.com
//
// 2016-05-08 on Sugar 7.7.0.0
// file: custom/data/acl/SugarACLLock.php
//
// ACL to lock record in certain conditions. Always allow admin users and specific user ids
@esimonetti
esimonetti / custominitsystem.php
Last active Apr 20, 2020
Add on SugarDockerized data/app/custominitsystem.php
View custominitsystem.php
<?php
// Enrico Simonetti
// enricosimonetti.com
// settings
$set = [
'email-admin' => 'my@email.com',
'email-user' => 'my-second@email.com',
'tzone' => 'Australia/Sydney',
View mysql_tables_optimize.php
<?php
// Enrico Simonetti
// enricosimonetti.com
//
// 2018-09-20 on Sugar 8.0.0
//
// CLI script to optimize Sugar mysql tables
ini_set('memory_limit', '64M');
@esimonetti
esimonetti / repair.php
Last active Feb 28, 2020
Sugar CLI Repair - Instance as script argument - USE TOOTHPASTE INSTEAD! https://github.com/esimonetti/toothpaste
View repair.php
<?php
// Enrico Simonetti
// enricosimonetti.com
//
// 2017-11-01 on Sugar 7.9.2.0
function usage($error = '') {
if (!empty($error)) print(PHP_EOL . 'Error: ' . $error . PHP_EOL);
print(' php ' . __FILE__ . ' --instance /full/path' . PHP_EOL);
@esimonetti
esimonetti / config_override_custom.php
Last active Feb 6, 2020
Add on SugarDockerized data/app/configs/config_override_custom.php
View config_override_custom.php
<?php
$config_override = [];
$config_override['passwordsetting']['minpwdlength'] = 1;
$config_override['passwordsetting']['oneupper'] = 0;
$config_override['passwordsetting']['onelower'] = 0;
$config_override['passwordsetting']['onenumber'] = 0;
$config_override['passwordsetting']['onespecial'] = 0;
$config_override['passwordsetting']['SystemGeneratedPasswordON'] = 0;
$config_override['passwordsetting']['forgotpasswordON'] = 0;
$config_override['moduleInstaller']['packageScan'] = true;
View config_override.php
<?php
$sugar_config['metrics_enabled'] = 1;
$sugar_config['metric_providers']['SugarMetric_Provider_Newrelic'] = 'include/SugarMetric/Provider/Newrelic.php';
$sugar_config['metric_settings']['SugarMetric_Provider_Newrelic']['applicationname'] = 'Sugar';
@esimonetti
esimonetti / csv_to_sugar_php_dropdown.php
Created Dec 2, 2019
Script to convert a csv file into Sugar php dropdowns
View csv_to_sugar_php_dropdown.php
<?php
// example dropdowns.csv content
// "ddname","key1","value1"
// "ddname","key2","value2"
$fileName = 'dropdowns.csv';
if (file_exists($fileName)) {
$file = fopen($fileName, 'r');
$dd = [];
@esimonetti
esimonetti / sugar-cli-fus.txt
Last active Nov 14, 2019
Useful sugar file system commands to analyse an instance
View sugar-cli-fus.txt
# Quick way to tell the difference of the modules dir of two instances
# 1 - from within the vanilla system module's dir
cd modules
ls -la | awk '{ print $9 }' | grep -v '\.' | grep -v '\.\.' > ~/core_modules_dir.txt
# 2 - from within the customer system module's dir
cd modules
ls -la | awk '{ print $9 }' | grep -v '\.' | grep -v '\.\.' > ~/customer.txt
# 3 - diff the twos and do some fus to get the actual differences
diff -auNw ~/core_modules_dir.txt ~/customer.txt | grep + | grep -v "@" | cut -c 2- | grep -v "\+\+" | grep -v "\-\-"
@esimonetti
esimonetti / cacheOnSugar.php
Last active Nov 13, 2019
With the new PSR-16 compatible caching engine we introduced recently, the new way to get the caching object is with something like this sample code
View cacheOnSugar.php
<?php
// remember to set redis on config_override.php
/*
$sugar_config['external_cache_disabled'] = false;
$sugar_config['external_cache_disabled_redis'] = false;
$sugar_config['external_cache']['redis']['host'] = 'sugar-redis';
*/
// to test the simplest standalone script
@esimonetti
esimonetti / table_record_counter.php
Last active Oct 30, 2019
Count records per Sugar table and output in json and csv format for reporting purposes - USE TOOTHPASTE INSTEAD! https://github.com/esimonetti/toothpaste
View table_record_counter.php
<?php
// Enrico Simonetti
// enricosimonetti.com
//
// 2018-09-19 on Sugar 8.0.0
//
// CLI script to output the current record count per SQL table, in json and csv format
ini_set('memory_limit', '64M');
You can’t perform that action at this time.