Skip to content

Instantly share code, notes, and snippets.

@sugarknowledge
Created August 2, 2012 16:50
Show Gist options
  • Select an option

  • Save sugarknowledge/3238621 to your computer and use it in GitHub Desktop.

Select an option

Save sugarknowledge/3238621 to your computer and use it in GitHub Desktop.
Module Loader Restriction Workarounds
<?php
//require utils
require_once("include/utils.php");
$check_path = "modules/Accounts/logic_hooks.php";
//if the $check_path exists in custom, $path will be returned as "custom/{$check_path}", otherwise $check_path will be returned
$path = get_custom_file_if_exists("modules/Accounts/logic_hooks.php");
if ($check_path != $path)
{
//file exists in custom
}
<?php
$check_path = "custom/modules/Accounts/logic_hooks.php";
if (file_exists($check_path))
{
//file exists
}
<?php
require_once('include/utils/sugar_file_utils.php');
$file = '/path/to/myFile.php';
$contents = sugar_file_get_contents($file);
<?php
$file = '/path/to/myFile.php';
if(is_readable($file))
{
$contents = file_get_contents($file);
}
<?php
require_once('include/utils/sugar_file_utils.php');
$file = '/path/to/myFile.php';
if (sugar_file_get_contents($file) !== false)
{
//file is readable
}
<?php
$file = '/path/to/myFile.php';
if(is_readable($file))
{
//file is readable
}
<?php
//Adding a logic hook
require_once("include/utils.php");
check_logic_hook_file("Accounts", "before_save", Array(999, 'Example Logic Hook', 'custom/modules/<module>/my_hook.php', 'my_hook_class', 'my_hook_function'));
<?php
//Removing a logic hook
require_once("include/utils.php");
remove_logic_hook("Accounts", "before_save", Array(999, 'Example Logic Hook', 'custom/modules/<module>/my_hook.php', 'my_hook_class', 'my_hook_function'));
<?php
$module = "Accounts";
$id = "6468238c-da75-fd9a-406b-50199fe6b5f8";
//creating a new bean
$focus = BeanFactory::newBean($module);
//or creating a new bean and retrieving a specific record
$focus = BeanFactory::getBean($module, $id);
<?php
$module = "Account";
$id = "6468238c-da75-fd9a-406b-50199fe6b5f8";
//creating a new bean
$focus = new $module()
//retrieving a specific record
$focus->retrieve($id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment