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 : 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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
  • Hello Enes

    Could you explain from the business perspective what user behavior should be identified prior to record save ?

    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

Reply
  • Hello Enes

    Could you explain from the business perspective what user behavior should be identified prior to record save ?

    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

Children
  • Hello Dmytro,

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

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    $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);
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    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