0012120: put crm lead import autotask into configured default container
authorsstamer <s.stamer@metaways.de>
Thu, 18 Aug 2016 12:16:05 +0000 (14:16 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 19 Aug 2016 07:25:20 +0000 (09:25 +0200)
* fixes getDefaultContainer for other users

https://forge.tine20.org/view.php?id=12120

Change-Id: I500396fdcc63892a1aa70f8c357495b6f92efceb
Reviewed-on: http://gerrit.tine20.com/customers/3462
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Crm/Import/CsvTest.php
tine20/Crm/Import/Csv.php
tine20/Tinebase/Container.php

index fef619f..41573a4 100644 (file)
@@ -92,8 +92,8 @@ class Crm_Import_CsvTest extends ImportTestCase
     public function testAutoTaskImport()
     {
         Crm_Config::getInstance()->set(Crm_Config::LEAD_IMPORT_AUTOTASK, true);
-        $personalContainerOfSClever = $this->_getPersonalContainer('Tasks', $this->_personas['sclever']);
-        $this->_setPersonaGrantsForTestContainer($personalContainerOfSClever->getId(), 'sclever', true, false);
+        $defaultContainerOfSClever = Tinebase_Container::getInstance()->getDefaultContainer('Tasks_Model_Task', $this->_personas['sclever'], 'defaultTaskList');
+        $this->_setPersonaGrantsForTestContainer($defaultContainerOfSClever->getId(), 'sclever', true, false);
 
         $result = $this->testImport(/* dry run = */ false);
         foreach ($result['results'] as $lead) {
@@ -104,9 +104,9 @@ class Crm_Import_CsvTest extends ImportTestCase
             }
         }
 
-        $tasks = $this->_searchTestTasks($personalContainerOfSClever->getId());
+        $tasks = $this->_searchTestTasks($defaultContainerOfSClever->getId());
         $this->assertEquals(1, count($tasks), 'could not find task in sclevers container: '
-            . print_r($personalContainerOfSClever->toArray(), true));
+            . print_r($defaultContainerOfSClever->toArray(), true));
         $task = $tasks->getFirstRecord();
         $this->assertEquals($this->_personas['sclever']['accountId'], $task->organizer);
         $this->assertEquals('IN-PROCESS', $task->status);
index ed6a1a2..4644a8b 100644 (file)
@@ -187,23 +187,18 @@ class Crm_Import_Csv extends Tinebase_Import_Csv_Abstract
             }
 
             $autoTaskForResponsible = clone($autoTask);
-            $responsiblePersonalContainer = Tinebase_Container::getInstance()->getPersonalContainer(
-                Tinebase_Core::getUser(),
-                'Tasks_Model_Task',
-                $user->getId(),
-                Tinebase_Model_Grants::GRANT_ADD
-            )->getFirstRecord();
-            if (! $responsiblePersonalContainer) {
-                if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
-                    . ' Could not find personal container of user with ADD grant');
+            $responsibleContainer = Tinebase_Container::getInstance()->getDefaultContainer('Tasks_Model_Task', $user->getId(), 'defaultTaskList');
+            if (! $responsibleContainer) {
+                if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
+                    . ' Could not find default container of user with ADD grant');
                 continue;
             }
-            $autoTaskForResponsible->container_id = $responsiblePersonalContainer->getId();
+            $autoTaskForResponsible->container_id = $responsibleContainer->getId();
             $autoTaskForResponsible->organizer = $responsible->account_id;
             Tasks_Controller_Task::getInstance()->create($autoTaskForResponsible);
 
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
-                . ' Created auto task for user ' . $user->getId() . ' in container ' . $responsiblePersonalContainer->name);
+                . ' Created auto task for user ' . $user->getId() . ' in container ' . $responsibleContainer->name);
         }
     }
 
index 8d1e512..ab8e6bc 100644 (file)
@@ -753,7 +753,7 @@ class Tinebase_Container extends Tinebase_Backend_Sql_Abstract
      *  - allows now to use different models with default container in one application
      *
      * @param   string|Tinebase_Record_Interface    $recordClass
-     * @param   string|Tinebase_Model_User          $accountId
+     * @param   string|Tinebase_Model_User          $accountId use current user if omitted
      * @param   string                              $defaultContainerPreferenceName
      * @return  Tinebase_Model_Container
      * 
@@ -763,9 +763,13 @@ class Tinebase_Container extends Tinebase_Backend_Sql_Abstract
     {
         // legacy handling
         $meta = $this->_resolveRecordClassArgument($recordClass);
+
+        $account = ($accountId !== NULL)
+            ? Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $accountId)
+            : Tinebase_Core::getUser();
         
         if ($defaultContainerPreferenceName !== NULL) {
-            $defaultContainerId = Tinebase_Core::getPreference($meta['appName'])->getValue($defaultContainerPreferenceName);
+            $defaultContainerId = Tinebase_Core::getPreference($meta['appName'])->getValueForUser($defaultContainerPreferenceName, $account->getId());
             try {
                 $result = $this->getContainerById($defaultContainerId);
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
@@ -781,9 +785,6 @@ class Tinebase_Container extends Tinebase_Backend_Sql_Abstract
             }
         }
         
-        $account = ($accountId !== NULL)
-            ? Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $accountId)
-            : Tinebase_Core::getUser();
         $result = $this->getPersonalContainer($account, $recordClass, $account, Tinebase_Model_Grants::GRANT_ADD)->getFirstRecord();
         
         if ($result === NULL) {