Adding a custom entry to the custom/include/MVC/Controller/entry_point_registry.php by simply copying the file during install will cause issues if a previously installed module also makes use of the file. To add and remove just yours during install add the following files to your module zip (NOTE: this can be cleaned up and better generalized):
scripts/pre_install.php:
scripts/pre_uninstall.php:PHP Code:<?php
if (! defined('sugarEntry') || ! sugarEntry)
die('Not A Valid Entry Point');
function pre_install() {
/** add following:
$entry_point_registry['CustomEntryPointOne'] = array('file' => 'custom/modules/MyCustomEntry/CustomEntryPointOne.php', 'auth' => true);
$entry_point_registry['CustomEntryPointTwo'] = array('file' => 'custom/modules/MyCustomEntry/CustomEntryPointTwo.php', 'auth' => true);
*/
$add_entry_point = false;
$new_contents = "";
$entry_point_registry = null;
if(file_exists("custom/include/MVC/Controller/entry_point_registry.php")){
// This will load an array of the hooks to process
include("custom/include/MVC/Controller/entry_point_registry.php");
if(!isset($entry_point_registry['CustomEntryPointOne'])) {
$add_entry_point = true;
$entry_point_registry['CustomEntryPointOne'] = array('file' => 'custom/modules/MyCustomEntry/CustomEntryPointOne.php', 'auth' => true);
}
if(!isset($entry_point_registry['CustomEntryPointTwo'])) {
$add_entry_point = true;
$entry_point_registry['CustomEntryPointTwo'] = array('file' => 'custom/modules/MyCustomEntry/CustomEntryPointTwo.php', 'auth' => true);
}
} else {
$add_entry_point = true;
$entry_point_registry['CustomEntryPointOne'] = array('file' => 'custom/modules/MyCustomEntry/CustomEntryPointOne.php', 'auth' => true);
$entry_point_registry['CustomEntryPointTwo'] = array('file' => 'custom/modules/MyCustomEntry/CustomEntryPointTwo.php', 'auth' => true);
}
if($add_entry_point == true){
require_once('include/utils/array_utils.php');
require_once('include/utils/sugar_file_utils.php');
foreach($entry_point_registry as $entryPoint => $epArray){
$new_contents .= "\$entry_point_registry['".$entryPoint."'] = array('file' => '".$epArray['file']."' , 'auth' => '".$epArray['auth']."'); \n";
}
$new_contents = "<?php\n$new_contents\n?>";
$file = 'custom/include/MVC/Controller/entry_point_registry.php';
$paths = explode('/',$file);
$dir = '';
for($i = 0; $i < sizeof($paths) - 1; $i++)
{
if($i > 0) $dir .= '/';
$dir .= $paths[$i];
if(!file_exists($dir))
{
sugar_mkdir($dir, 0755);
}
}
$fp = sugar_fopen($file, 'wb');
fwrite($fp,$new_contents);
fclose($fp);
}
}
?>
PHP Code:Running pre_uninstall...
<?php
if (! defined('sugarEntry') || ! sugarEntry)
die('Not A Valid Entry Point');
function pre_uninstall() {
/** remove following:
$entry_point_registry['CustomEntryPointOne'] = array('file' => 'custom/modules/MyCustomEntry/CustomEntryPointOne.php', 'auth' => true);
$entry_point_registry['CustomEntryPointTwo'] = array('file' => 'custom/modules/MyCustomEntry/CustomEntryPointTwo.php', 'auth' => true);
*/
$remove_entry_point = false;
$new_contents = "";
$entry_point_registry = null;
if(file_exists("custom/include/MVC/Controller/entry_point_registry.php")){
include("custom/include/MVC/Controller/entry_point_registry.php");
if(isset($entry_point_registry['CustomEntryPointOne'])) {
$remove_entry_point = true;
unset($entry_point_registry['CustomEntryPointOne']);
}
if(isset($entry_point_registry['CustomEntryPointTwo'])) {
$remove_entry_point = true;
unset($entry_point_registry['CustomEntryPointTwo']);
}
if($remove_entry_point == true){
require_once('include/utils/array_utils.php');
require_once('include/utils/sugar_file_utils.php');
foreach($entry_point_registry as $entryPoint => $epArray){
$new_contents .= "\$entry_point_registry['".$entryPoint."'] = array('file' => '".$epArray['file']."' , 'auth' => '".$epArray['auth']."'); \n";
}
$new_contents = "<?php\n$new_contents\n?>";
$file = 'custom/include/MVC/Controller/entry_point_registry.php';
$fp = sugar_fopen($file, 'wb');
fwrite($fp,$new_contents);
fclose($fp);
}
}
}
?>


LinkBack URL
About LinkBacks





Reply With Quote

Bookmarks