0010054: allow to configure if notes should be written
authorDimitri Oleiynyk <d.oleiynyk@metaways.de>
Wed, 16 Jul 2014 11:04:48 +0000 (13:04 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 17 Jul 2014 13:53:35 +0000 (15:53 +0200)
- adds useNotes method to disable notes
- adds unit test

Change-Id: Id3ab27de1261b1f4c5d70094ecbfce2c3fa24b4a
Reviewed-on: http://gerrit.tine20.com/customers/869
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Michael Spahn <m.spahn@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Addressbook/ControllerTest.php
tine20/Tinebase/Controller/Record/Abstract.php

index 61138fd..dfa0c06 100644 (file)
@@ -171,6 +171,7 @@ class Addressbook_ControllerTest extends PHPUnit_Framework_TestCase
     {
         Addressbook_Controller_Contact::getInstance()->setGeoDataForContacts($this->_geodata);
         
+        $this->_instance->useNotes(true);
         if ((isset($this->objects['contact']) || array_key_exists('contact', $this->objects))) {
             $this->_instance->delete($this->objects['contact']);
         }
@@ -425,4 +426,40 @@ class Addressbook_ControllerTest extends PHPUnit_Framework_TestCase
         $count2 = $this->_instance->searchCount($filter);
         $this->assertEquals($count1, $count2);
     }
+    
+    /**
+     * test useNotes
+     */
+    public function testUseNotes()
+    {
+        $contact = $this->objects['initialContact'];
+        $contact1 = clone $contact;
+    
+        $contact1->notes = array(new Tinebase_Record_RecordSet('Tinebase_Model_Note', array($this->objects['note'])));
+        $contact->notes = array(new Tinebase_Record_RecordSet('Tinebase_Model_Note', array($this->objects['note'])));
+    
+        $newcontact1 = $this->_instance->create($contact1);
+        $this->_instance->delete($newcontact1);
+    
+        $this->_instance->useNotes(false);
+        $this->objects['contact'] = $this->_instance->create($contact);
+    
+        $compStr = 'Array
+(
+    [0] => Array
+        (
+            [note_type_id] => 1
+            [note] => phpunit test note
+            [record_backend] => Sql
+            [id] => 
+        )
+
+)';
+        
+        $this->assertTrue($newcontact1->has('notes'));
+        $this->assertEquals($compStr, $newcontact1->notes[0]->note);
+        
+        $this->setExpectedException('Tinebase_Exception_NotFound');
+        $this->objects['contact']->notes[0]->note = 'note';
+    }
 }
index 3cb2608..42c747a 100644 (file)
@@ -54,6 +54,13 @@ abstract class Tinebase_Controller_Record_Abstract
     protected $_doRightChecks = TRUE;
 
     /**
+     * use notes - can be enabled/disabled by useNotes
+     *
+     * @var boolean
+     */
+    protected $_setNotes = TRUE;
+
+    /**
      * delete or just set is_delete=1 if record is going to be deleted
      * - legacy code -> remove that when all backends/applications are using the history logging
      *
@@ -955,7 +962,7 @@ abstract class Tinebase_Controller_Record_Abstract
      */
     protected function _setNotes($_updatedRecord, $_record, $_systemNoteType = Tinebase_Model_Note::SYSTEM_NOTE_NAME_CREATED, $_currentMods = NULL)
     {
-        if (! $_record->has('notes')) {
+        if (! $_record->has('notes') || $this->_setNotes === false) {
             return;
         }
 
@@ -1141,6 +1148,18 @@ abstract class Tinebase_Controller_Record_Abstract
     }
     
     /**
+     * enable / disable notes
+     *
+     * @param boolean $_value
+     * @return void
+     */
+    public function useNotes()
+    {
+        $value = (func_num_args() === 1) ? (bool) func_get_arg(0) : NULL;
+        return $this->_setBooleanMemberVar('_setNotes', $value);
+    }
+    
+    /**
      * iterate relations
      * 
      * @param Tinebase_Record_Abstract $currentRecord