return parent::update($_record);
}
+
+ public function setContainerOwners()
+ {
+ $select = $this->_getSelect('id')
+ ->where('type = ?', Tinebase_Model_Container::TYPE_PERSONAL)
+ ->where('owner_id is null or owner_id = ?', '');
+
+ $stmt = $this->_db->query($select);
+ $containers = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
+
+ $count = 0;
+ foreach ($containers as $container) {
+ $id = $container['id'];
+ $grants = $this->getGrantsOfContainer($id, /* ignore acl */ true);
+ foreach ($grants as $grant) {
+ if ($grant->adminGrant && $grant->account_type == 'user') {
+ if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
+ . ' Set owner for container id ' . $id . ': ' . $grant->account_id);
+ $where = array(
+ $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $id),
+ );
+
+ $this->_db->update($this->_tablePrefix . $this->_tableName, array('owner_id' => $grant->account_id), $where);
+
+ $count++;
+ }
+ }
+ }
+
+ if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
+ . ' Set owner for ' . $count . ' containers.');
+ }
}
}
$this->setTableVersion('container', '10');
- //Tinebase_Core::getCache()->clean();
- $this->_setContainerOwners();
+ Tinebase_Container::getInstance()->setContainerOwners();
$this->setApplicationVersion('Tinebase', '9.5');
}
/**
- * write owner to all personal containers
- */
- protected function _setContainerOwners()
- {
- $filter = new Tinebase_Model_ContainerFilter(array(
- array('field' => 'type', 'operator' => 'equals', 'value' => Tinebase_Model_Container::TYPE_PERSONAL),
- array('field' => 'owner_id', 'operator' => 'isnull', 'value' => ''),
- ));
- $count = 0;
- $paging = new Tinebase_Model_Pagination(array(
- 'start' => 0,
- 'limit' => 100,
- ));
- $containers = Tinebase_Container::getInstance()->search($filter, $paging);
- while (count($containers) > 0) {
- foreach ($containers as $container) {
- $ownerId = Tinebase_Container::getInstance()->getContainerOwner($container);
- if ($ownerId) {
- $container->owner_id = $ownerId;
- Tinebase_Container::getInstance()->update($container);
- $count++;
- }
- }
- $paging->start += $paging->limit;
- $containers = Tinebase_Container::getInstance()->search($filter, $paging);
- }
-
- if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
- . ' Set owner for ' . $count . ' containers.');
- }
-
- /**
* update to 9.6
*
* change length of groups.description column from varchar(255) to text