Logichook on copying bean ?

Hello everybody,

Is there a clean way within a before_save logichook to determine if the bean is being copied or "classically" modified ? 

I heritated such a code : 

if (!$arguments['isUpdate'] && preg_match('/picture_duplicateBeanId/', $_SERVER['QUERY_STRING'])){
	// $GLOBALS['log']->fatal("Copying an SLA Report :: ".$_SERVER['QUERY_STRING']);
    $split = explode('&',$_SERVER['QUERY_STRING']);
	$id = null;

    foreach($split as $k) {
		if (preg_match('/picture_duplicateBeanId/', $k)) {
            $aid = explode('=',$k);
            $id = $aid[1];
            continue;
		}
    }
}

The guy before me checked the query_string from the server global value, but is there a better way to do that ? 

Best regards and nice week to all :-)

Enes

Parents Reply Children
  • Hello Dmytro,

    In fact I need to get the objects linked to the original to copy them to the new one : 

    $originalSlaReport = BeanFactory::retrieveBean('SLARE_c', $id);
    
    if ($originalSlaReport->load_relationship('slare_c_slait_c_1')) {
    	$bean->load_relationship('slare_c_slait_c_1');
    	foreach ($originalSlaReport->slare_c_slait_c_1->getBeans() as $slaItem) {
    		$copySlaItem = BeanFactory::newBean('SLAIT_c');
    		$copySlaItem->name = $slaItem->name;
    		$copySlaItem->active_c = $slaItem->active_c;
    		$copySlaItem->realized_c = $slaItem->realized_c;
    		$copySlaItem->objective_c = $slaItem->objective_c;
    		$copySlaItem->gap_c = $slaItem->gap_c;
    		$copySlaItem->penalty_c = $slaItem->penalty_c;
    		$copySlaItem->description = $slaItem->description;
    		$copySlaItem->target_c = $slaItem->target_c;
    		$copySlaItem->save();
    		$bean->slare_c_slait_c_1->add($copySlaItem);
    	}
    }

    where $id comes from the code I copied on my original post.

    The trick could be that I create my own button to copy the initial object and their childs ...

    If you have an idea to do it smartly, I'll take it.

    Best regards,

    Enes