Ejemplo n.º 1
0
 public function copyAction()
 {
     $triggerActionId = $this->_getParam('triggerActionId', null);
     if (is_null($triggerActionId)) {
         throw new Ot_Exception_Input('msg-error-triggerActionIdNotFound');
     }
     $action = new Ot_Model_DbTable_TriggerAction();
     $thisTriggerAction = $action->find($triggerActionId);
     if (is_null($thisTriggerAction)) {
         throw new Ot_Exception_Data('msg-error-noTriggerActionId');
     }
     $register = new Ot_Trigger_EventRegister();
     $thisTriggerEvent = $register->getTriggerEvent($thisTriggerAction->eventKey);
     if (is_null($thisTriggerEvent)) {
         throw new Ot_Exception_Data('msg-error-noTrigger');
     }
     $actionTypeRegister = new Ot_Trigger_ActionTypeRegister();
     $thisActionType = $actionTypeRegister->getTriggerActionType($thisTriggerAction->actionKey);
     if (is_null($thisActionType)) {
         throw new Ot_Exception_Data('msg-error-noTrigger');
     }
     $actionTypeData = $thisActionType->getDbTable()->find($triggerActionId);
     if (is_null($actionTypeData)) {
         throw new Ot_Exception_Data('Data not found for this trigger action');
     }
     if ($this->_request->isPost()) {
         $dba = $action->getAdapter();
         $dba->beginTransaction();
         $data = array('name' => 'Copy of ' . $thisTriggerAction->name, 'actionKey' => $thisTriggerAction->actionKey, 'eventKey' => $thisTriggerAction->eventKey);
         try {
             $triggerActionId = $action->insert($data);
             $actionTypeData = $actionTypeData->toArray();
             $actionTypeData['triggerActionId'] = $triggerActionId;
             $thisActionType->getDbTable()->insert($actionTypeData);
         } catch (Exception $e) {
             $dba->rollback();
             throw $e;
         }
         $dba->commit();
         $logOptions = array('attributeName' => 'triggerActionId', 'attributeId' => $triggerActionId);
         $this->_helper->log(Zend_Log::INFO, 'Trigger Action cloned', $logOptions);
         $this->_helper->messenger->addSuccess($this->view->translate('msg-info-triggerCloned', array('clonedTriggerName' => $data['name'])));
         $this->_helper->redirector->gotoRoute(array('controller' => 'trigger', 'action' => 'edit', 'triggerActionId' => $triggerActionId), 'ot', true);
     } else {
         throw new Ot_Exception_Access('You are not allowed to access this method directly');
     }
 }