0011124: recur events with missing displaycontainer_id
authorCornelius Weiß <mail@corneliusweiss.de>
Fri, 3 Jul 2015 08:07:41 +0000 (10:07 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 8 Jul 2015 08:01:42 +0000 (10:01 +0200)
* add missing displaycontainer
* THISANDFUTURE updates with attendee add had missing
  displaycontainer
* Fixes the bug
* repair script

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

Change-Id: I6b4af4850e919a3226068d735eba8bc45fcdb01c
Reviewed-on: http://gerrit.tine20.com/customers/2012
Tested-by: Jenkins CI (http://ci.tine20.com/)
Tested-by: sstamer <s.stamer@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Controller/RecurTest.php
tine20/Calendar/Controller/Event.php
tine20/Calendar/Setup/Update/Release8.php
tine20/Calendar/Setup/setup.xml

index a58ab5b..0d79cf5 100644 (file)
@@ -677,15 +677,19 @@ class Calendar_Controller_RecurTest extends Calendar_TestCase
         
         $exceptions = new Tinebase_Record_RecordSet('Calendar_Model_Event');
         $recurSet = Calendar_Model_Rrule::computeRecurrenceSet($persistentEvent, $exceptions, $from, $until);
-        
-        $recurSet[5]->attendee->addRecord(new Calendar_Model_Attender(array(
+
+        $pwulf = new Calendar_Model_Attender(array(
             'user_type'   => Calendar_Model_Attender::USERTYPE_USER,
             'user_id'     => $this->_getPersonasContacts('pwulf')->getId()
-        )));
+        ));
+        $recurSet[5]->attendee->addRecord($pwulf);
         
         $updatedPersistentEvent = $this->_controller->createRecurException($recurSet[5], FALSE, TRUE);
         
         $this->assertEquals(3, count($updatedPersistentEvent->attendee));
+
+        $persistentPwulf = Calendar_Model_Attender::getAttendee($updatedPersistentEvent->attendee, $pwulf);
+        $this->assertNotNull($persistentPwulf->displaycontainer_id);
     }
     
     /**
index 7bf97a4..c46391d 100644 (file)
@@ -1111,17 +1111,10 @@ class Calendar_Controller_Event extends Tinebase_Controller_Record_Abstract impl
                 $note = $_event->notes; unset($_event->notes);
                 $persistentExceptionEvent = $this->create($_event, $_checkBusyConflicts && $dtStartHasDiff);
                 
-                // we save attendee seperatly to preserve their attributes
+                // we save attendee separately to preserve their attributes
                 if ($attendees instanceof Tinebase_Record_RecordSet) {
-                    $attendees->cal_event_id = $persistentExceptionEvent->getId();
-                    
                     foreach($attendees as $attendee) {
-                        if (! $attendee->status_authkey) {
-                            // new invitations
-                            $attendee->status_authkey = Tinebase_Record_Abstract::generateUID();
-                        }
-                        $this->_backend->createAttendee($attendee);
-                        $this->_increaseDisplayContainerContentSequence($attendee, $persistentExceptionEvent, Tinebase_Model_ContainerContent::ACTION_CREATE);
+                        $this->_createAttender($attendee, $persistentExceptionEvent, true);
                     }
                 }
                 
@@ -1978,6 +1971,7 @@ class Calendar_Controller_Event extends Tinebase_Controller_Record_Abstract impl
     {
         // apply defaults
         $attender->user_type         = isset($attender->user_type) ? $attender->user_type : Calendar_Model_Attender::USERTYPE_USER;
+        $attender->cal_event_id      =  $event->getId();
         $calendar = ($calendar) ? $calendar : Tinebase_Container::getInstance()->getContainerById($event->container_id);
         
         $userAccountId = $attender->getUserAccountId();
index 03ddb92..d1ce406 100644 (file)
@@ -248,4 +248,68 @@ class Calendar_Setup_Update_Release8 extends Setup_Update_Abstract
         $this->setTableVersion('cal_events', '9');
         $this->setApplicationVersion('Calendar', '8.7');
     }
+
+    /**
+     * repair missing displaycontainer_id
+     */
+    public function update_7()
+    {
+        $allUser = $this->_db->query(
+            "SELECT " . $this->_db->quoteIdentifier('id') . "," .  $this->_db->quoteIdentifier('contact_id') .
+            " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "accounts") .
+            " WHERE " . $this->_db->quoteIdentifier("contact_id") . " IS NOT NULL"
+        )->fetchAll(Zend_Db::FETCH_ASSOC);
+
+        $contactUserMap = array();
+        foreach ($allUser as $id => $user) {
+            $contactUserMap[$user['contact_id']] = $user['id'];
+        }
+
+        // find all user/groupmember attendees with missing displaycontainer
+        $attendees = $this->_db->query(
+            "SELECT DISTINCT" . $this->_db->quoteIdentifier('user_type') . "," . $this->_db->quoteIdentifier('user_id') .
+            " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_attendee") .
+            " WHERE " . $this->_db->quoteIdentifier("displaycontainer_id") . " IS  NULL" .
+            "  AND " . $this->_db->quoteIdentifier("user_type")  . $this->_db->quoteInto(" IN (?)", array('user', 'groupmemeber')) .
+            "  AND " . $this->_db->quoteIdentifier("user_id")  . $this->_db->quoteInto(" IN (?)", array_keys($contactUserMap))
+        )->fetchAll(Zend_Db::FETCH_ASSOC);
+
+        // find all user/groupmember attendees with missing displaycontainer
+        $attendees = array_merge($attendees, $this->_db->query(
+            "SELECT DISTINCT" . $this->_db->quoteIdentifier('user_type') . "," . $this->_db->quoteIdentifier('user_id') .
+            " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_attendee") .
+            " WHERE " . $this->_db->quoteIdentifier("displaycontainer_id") . " IS  NULL" .
+            "  AND " . $this->_db->quoteIdentifier("user_type")  . $this->_db->quoteInto(" IN (?)", array('resource'))
+        )->fetchAll(Zend_Db::FETCH_ASSOC));
+
+        $resources = $this->_db->query(
+            "SELECT " . $this->_db->quoteIdentifier('id') . "," . $this->_db->quoteIdentifier('container_id') .
+            " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_resources")
+        )->fetchAll(Zend_Db::FETCH_ASSOC);
+
+        $resourceContainerMap = array();
+        foreach($resources as $resource) {
+            $resourceContainerMap[$resource['id']] = $resource['container_id'];
+        }
+
+        foreach ($attendees as $attendee) {
+            //find out displaycontainer
+            if ($attendee['user_type'] != 'resource') {
+                $userAccountId = $contactUserMap[$attendee['user_id']];
+                $attendee['displaycontainerId'] = Calendar_Controller_Event::getDefaultDisplayContainerId($userAccountId);
+            } else {
+                $attendee['displaycontainerId'] = $resourceContainerMap[$attendee['user_id']];
+            }
+
+            // update displaycontainer
+            $this->_db->query(
+                "UPDATE" . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_attendee") .
+                " SET " . $this->_db->quoteIdentifier("displaycontainer_id") . " = " . $this->_db->quote($attendee['displaycontainerId']) .
+                " WHERE " . $this->_db->quoteIdentifier("user_type") . " = " . $this->_db->quote($attendee['user_type']) .
+                "  AND " . $this->_db->quoteIdentifier("user_id") . " = " . $this->_db->quote($attendee['user_id'])
+            );
+        }
+
+        $this->setApplicationVersion('Calendar', '8.8');
+    }
 }
index fd77402..bc5fea1 100644 (file)
@@ -2,7 +2,7 @@
 <application>
     <name>Calendar</name>
     <!-- gettext('Calendar') -->   
-    <version>8.7</version>
+    <version>8.8</version>
     <order>15</order>
     <status>enabled</status>
     <tables>