Last active
March 21, 2016 10:26
-
-
Save cAstraea/ecf84a7e380b57222c2b to your computer and use it in GitHub Desktop.
update dropdown list with option from module, after_save and after_delete logic hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); | |
require_once('include/entryPoint.php'); | |
require_once('modules/Administration/QuickRepairAndRebuild.php'); | |
class Visite_Hook | |
{ | |
function update_self($bean, $event, $arguments) | |
{ | |
//logic | |
$dropdownlistsRebuild = $GLOBALS['app_list_strings']['NEWLIST_list']; | |
require_once('modules/Studio/DropDowns/DropDownHelper.php'); | |
$drop = new DropDownHelper; | |
$count = 0; | |
$sq = new SugarQuery(); | |
$sq->select(array('name')); | |
$sq->from(BeanFactory::getBean('DP_visiteobj')); | |
$sq->orderBy('date_entered', 'ASC'); | |
$result = $sq->execute(); | |
$params['dropdown_name'] = 'NEWLIST_list'; | |
$params['dropdown_lang'] = 'fr_FR'; | |
foreach((array) $result as $row) | |
{ | |
$aTmp1[] = $row['name']; // flatten the array get only the name for comparison between records in the module and our objective list | |
$params['slot_' . $count] = $count; | |
$params['key_' . $count] = $count;//using the count for the list key to allow editing of dependent fields. | |
//$params['key_' . $count] = $row['id']; | |
$params['value_' . $count] = $row['name']; | |
$count++; | |
} | |
$compare = array_diff($aTmp1,$dropdownlistsRebuild); | |
// $GLOBALS['log']->fatal($dropdownlistsRebuild); | |
if (!$compare) | |
{ | |
$GLOBALS['log']->fatal('>>>No changes detected in objective list ' . print_r($compare, true)); | |
} | |
else | |
{ | |
$GLOBALS['log']->fatal('>>>Changes detected in objective list ' . print_r($compare, true)); | |
if ($count != 0 ){ | |
global $sugar_config; | |
global $locale; | |
try { | |
$drop->saveDropDown($params); //save the new list | |
//If the exception is thrown, this text will not be shown | |
// $GLOBALS['log']->fatal($params); | |
} | |
catch(Exception $e) { | |
$GLOBALS['log']->fatal($e->getMessage()); | |
} | |
global $current_user; | |
//get current user to allow non-admin to run the logic hook | |
$current_user = new User(); | |
$current_user->getSystemUser(); | |
global $moduleList; | |
$repair= new RepairAndClear(); | |
$repair->repairAndClearAll(array('repairMetadataAPICache'),array(translate('DP_visiteobj')), true,false); | |
$exit_on_cleanup = true; | |
sugar_cleanup(false); | |
if(class_exists('DBManagerFactory')) { | |
$db = DBManagerFactory::getInstance(); | |
$db->disconnect(); | |
} | |
if($exit_on_cleanup) exit;// not needed on sugar 7 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment