Marc Franquesa - 2012-06-25

Hi,

After some days working on it, I am near to complete the customizations on iTop to fit my needs, thanks as I learn a lot in the process.

One of last things is that I'm trying to customize the ticket management relations to allow Ticket to Ticket relations whatever the type of ticket (Request, problem, change, …).

For that, I created a lnkTicket class with attributes ticketA_id, ticketB_id and relation as string. (I thinks that the names are self-explaining). The problem I'm facing is that if I link ticket A to ticket B (creating a lnkTicket instance), I would like that automatically ticket B gets linked to ticket A too (automatically creating the reverse relation). To achieve this my plan is to implement the following methods:

        protected function AddReverse() {
                $reverse = new lnkTicket();
                $reverse->Set('ticketA_id',$this->Get('ticketB_id'));
                $reverse->Set('ticketB_id',$this->Get('ticketA_id'));
                $reverse->Set('relation',"(".$this->Get('relation').")");
                $reverse>DBInsert();
        }

        protected function DeleteReverse() {
                $iA = $this->GetOriginal('ticketA_id');
                $iB = $this->GetOriginal('ticketB_id');
                $reverse = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT lnkTicket AS reverse WHERE reverse.ticketA_id = $iB and reverse.ticketB_id = $iA"));
                $reverse->DBDelete();  // Will call this AfterDelete again on the reverse object ?
        }
     
        protected function AfterInsert()
        {
                $this->AddReverse();
                parent::AfterInsert();
        }

        protected function AfterUpdate()
        {
                $this->DeleteReverse();
                $this->AddReverse();
                parent::AfterUpdate();
        }

        protected function AfterDelete()
        {
                $this->DeleteReverse();
                parent::AfterDelete();
        }

I would like to know if this should be the correct method to implement this behavior and if I get some problem on 'cylic' deletion when a lnkTicket relation is deleted.

Thanks