send deleted notification to lead responsible
authorsstamer <s.stamer@metaways.de>
Thu, 5 Mar 2015 14:01:25 +0000 (15:01 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 6 Mar 2015 17:00:28 +0000 (18:00 +0100)
Change-Id: I7e910b31220d2881588a83c4ed75ad3e8504a19c
Reviewed-on: http://gerrit.tine20.com/customers/1711
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Crm/NotificationsTests.php
tine20/Crm/Controller/Lead.php
tine20/Tinebase/Controller/Record/Abstract.php

index 306e562..6a6586e 100644 (file)
@@ -94,4 +94,35 @@ class Crm_NotificationsTests extends Crm_AbstractTest
         $bodyText = $messages[0]->getBodyText()->getContent();
         $this->assertContains('**PHPUnit **', $bodyText);
     }
+    
+    /**
+     * testNotificationToResponsible
+     */
+    public function testNotificationOnDelete()
+    {
+        $lead = $this->_getLead();
+        
+        // give sclever access to lead container
+        $this->_setPersonaGrantsForTestContainer($lead['container_id'], 'sclever');
+        
+        $lead->relations = array(new Tinebase_Model_Relation(array(
+                'type'                   => 'RESPONSIBLE',
+                'related_record'         => Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::getUser()->getId()),
+                'own_model'              => 'Crm_Model_Lead',
+                'own_backend'            => 'Sql',
+                'own_degree'             => Tinebase_Model_Relation::DEGREE_SIBLING,
+                'related_model'          => 'Addressbook_Model_Contact',
+                'related_backend'        => Tasks_Backend_Factory::SQL,
+        ), TRUE));
+        $savedLead = $this->_leadController->create($lead);
+        
+        self::flushMailer();
+        
+        $this->_leadController->delete($savedLead->getId());
+        
+        $messages = self::getMessages();
+        $this->assertEquals(1, count($messages));
+        $bodyText = $messages[0]->getBodyText()->getContent();
+        $this->assertContains('**PHPUnit **', $bodyText);
+    }
 }
index c0ffeab..06277de 100644 (file)
@@ -209,10 +209,12 @@ class Crm_Controller_Lead extends Tinebase_Controller_Record_Abstract
         
         if ($_action == 'changed') {
             $subject = sprintf($translate->_('Lead %s has been changed'), $_lead->lead_name);
+        } else if ($_action == 'deleted') {
+            $subject = sprintf($translate->_('Lead %s has been deleted'), $_lead->lead_name);
         } else {
             $subject = sprintf($translate->_('Lead %s has been created'), $_lead->lead_name);
         }
-
+        
         // create pdf
         try {
             $pdfGenerator = new Crm_Export_Pdf();
index d64b87d..b0140d3 100644 (file)
@@ -1345,6 +1345,7 @@ abstract class Tinebase_Controller_Record_Abstract
         $ids = $this->_inspectDelete((array) $_ids);
 
         $records = $this->_backend->getMultiple((array)$ids);
+        
         if (count((array)$ids) != count($records)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Only ' . count($records) . ' of ' . count((array)$ids) . ' records exist.');
         }
@@ -1360,8 +1361,11 @@ abstract class Tinebase_Controller_Record_Abstract
             $db = $this->_backend->getAdapter();
             $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($db);
             $this->_checkRight('delete');
-
+            
             foreach ($records as $record) {
+                if ($this->sendNotifications()) {
+                    $this->_getRelatedData($record);
+                }
                 $this->_deleteRecord($record);
             }