/**
  * repair groups
  * 
  * * add missing lists
  * * checks if list container has been deleted (and hides groups if that's the case)
  * 
  * @see 0010401: add repair script for groups without list_ids
  */
 public function repairGroups()
 {
     $count = 0;
     $be = new Tinebase_Group_Sql();
     $listBackend = new Addressbook_Backend_List();
     $groups = $be->getGroups();
     foreach ($groups as $group) {
         if ($group->list_id == null) {
             $list = Addressbook_Controller_List::getInstance()->createByGroup($group);
             $group->list_id = $list->getId();
             $group->visibility = Tinebase_Model_Group::VISIBILITY_DISPLAYED;
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Add missing list for group ' . $group->name);
             }
             $be->updateGroupInSqlBackend($group);
             $count++;
         } else {
             if ($group->visibility === Tinebase_Model_Group::VISIBILITY_DISPLAYED) {
                 try {
                     $list = $listBackend->get($group->list_id);
                     $listContainer = Tinebase_Container::getInstance()->get($list->container_id);
                 } catch (Tinebase_Exception_NotFound $tenf) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Hide group ' . $group->name . ' without list / list container.');
                     }
                     $group->visibility = Tinebase_Model_Group::VISIBILITY_HIDDEN;
                     $be->updateGroupInSqlBackend($group);
                     $count++;
                 }
             }
         }
     }
     echo $count . " groups repaired!\n";
 }
 /**
  * import single record (create password if in data)
  *
  * @param Tinebase_Record_Abstract $_record
  * @param string $_resolveStrategy
  * @param array $_recordData
  * @return Tinebase_Record_Interface
  * @throws Tinebase_Exception_Record_Validation
  */
 protected function _importRecord($_record, $_resolveStrategy = NULL, $_recordData = array())
 {
     $admCfg = Tinebase_Core::getConfig()->get('Admin');
     $excludeGroups = array();
     $be = new Tinebase_Group_Sql();
     $members = explode(' ', $_record->members);
     $_record->members = null;
     unset($_record->members);
     $this->_setController();
     try {
         $group = $be->getGroupByName($_record->name);
     } catch (Tinebase_Exception_Record_NotDefined $e) {
         $group = NULL;
         parent::_importRecord($_record, $_resolveStrategy, $_recordData);
     }
     if ($group) {
         $this->_handleGroupMemberShip($group, $members);
     } else {
         $group = Admin_Controller_Group::getInstance()->get($_record->getId());
         $list = Addressbook_Controller_List::getInstance()->createByGroup($group);
         $group->list_id = $list->getId();
         $group->visibility = Tinebase_Model_Group::VISIBILITY_DISPLAYED;
         $be->updateGroupInSqlBackend($group);
         $memberUids = array();
         if (!empty($members)) {
             $users = $this->_resolveUsers($members);
             foreach ($users as $userId) {
                 try {
                     $be->addGroupMember($_record->getId(), $userId);
                 } catch (Exception $e) {
                 }
             }
         }
     }
     return $group;
 }