/**
  * Add group to user and write to persistence immediately
  * The method has to update user's profile and group relationship
  *
  * @var CMS_profile_user $user
  * @return true on success, false on failure
  * @access public
  */
 function addToUserAndWriteToPersistence(&$user, $writeUser = true)
 {
     if (is_a($user, "CMS_profile_user") && !$user->hasError()) {
         //Get current user groups ids
         $userGroupIds = CMS_profile_usersGroupsCatalog::getGroupsOfUser($user, true, true);
         //if user has no group, we must clear his profile before
         if (!$userGroupIds) {
             //reset profile clearances
             $user->resetClearances();
         }
         // Update user profile
         $user->addPageClearances(parent::getPageClearances());
         $user->addModuleClearances(parent::getModuleClearances());
         $user->addModuleCategoriesClearancesStack(parent::getModuleCategoriesClearancesStack());
         $user->addValidationClearances(parent::getValidationClearances());
         $user->addAdminClearance(parent::getAdminClearance());
         $user->addTemplateGroupsDenied(parent::getTemplateGroupsDenied());
         $user->addRowGroupsDenied(parent::getRowGroupsDenied());
         $user->setActive(true);
         if ($writeUser) {
             $user->writeToPersistence();
         }
         if (!$user->hasError()) {
             if (!SensitiveIO::isInSet($user->getUserId(), $this->_users)) {
                 // Insert this user in group
                 $this->_users[] = $user->getUserId();
                 $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\tprofileUsersByGroup\n\t\t\t\t\tset\n\t\t\t\t\t\tgroupId_gu='" . $this->_groupId . "' ,\n\t\t\t\t\t\tuserId_gu='" . $user->getUserID() . "'\n\t\t\t\t\t";
                 $q = new CMS_query($sql);
                 if ($q->hasError()) {
                     $this->raiseError('Insertion failed');
                 } else {
                     return true;
                 }
             } else {
                 return true;
             }
         } else {
             $this->raiseError('User error when adding group values');
         }
     } else {
         $this->raiseError('Incorrect user given');
     }
     return false;
 }