XF 1.5 Trouble with Datawriter

Gossamer

Active member
I have a datawriter that isn't saving, and I can't figure out why.

Extended User Datawriter
PHP:
    public function updateActivityStatus($userId)
    {
        $userModel = $this->_getUserModel();
        
        $posts = $userModel->getActivityPosts($userId);
        
        $options = XenForo_Application::get('options');
        
        /* check the activity posts and update usergroup appropriately */
        if(count($posts) < 3)
        {
            /* move to low activity group OR deletion group */
            
            /* set secondary usergroup based on current usergroups */
            $lowActivityUserGroup = $options->rps_ActivityCheck_LowActivity_Usergroup;
            $deletionUserGroup = $options->rps_ActivityCheck_Deletion_Usergroup;
            $secondaryUsergroups = explode(',', $this->get('secondary_group_ids'));
            
            $userModel = $this->_getUserModel();
            
            if($lowActivityUserGroup != null && $deletionUserGroup != null)
            {
                /* user is not in low activity group */
                if(!$userModel->isLowActivity($userId))
                {
                    /* add user to low activity group */
                    $secondaryUsergroups[] = $lowActivityUserGroup;
                    
                    $this->setExistingData($userId);
                    $this->setSecondaryGroups($secondaryUsergroups);
                    $this->save();
                }
                
                /* IF user is in low activity group AND enough time has passed Add user to deletion usergroup */
            }
        }
        else
        {
            /* remove from low activity or deletion group */
        }

Obviously the second half is unfinished. But I've confirmed that the code is running through the portion where it's supposed to be setting and saving the secondary group. It has the id of the correct secondaryGroup, but it's just not saving.
 
Are you forgetting to call return parent::updateActivityStatus($userId); at the bottom?

If that is an extension of a built-in XF function in that DataWriter, you need to do the above.


Fillip
 
I tried adding that to the bottom of the updateActivityStatus function, but it produces an error:

Fatal error: Call to undefined method XFCP_Goss_RoleplaySystem_DataWriter_User::updateActivityStatus() in C:\xampp\htdocs\xenforo_DEV\library\Goss\RoleplaySystem\DataWriter\User.php on line 116
 
I'm extending the user datawriter. Here is the full code from my extended DataWriter.

PHP:
<?php

class Goss_RoleplaySystem_DataWriter_User extends XFCP_Goss_RoleplaySystem_DataWriter_User
{
    protected function _getFields()
    {
        $fields = parent::_getFields();
        
        $fields['xf_user']['rp_message_count'] = array('type' => self::TYPE_UINT_FORCED, 'default' => 0);
        $fields['xf_user']['app_accept_date'] = array('type' => self::TYPE_UINT_FORCED, 'default' => 0);
        $fields['xf_user']['rp_messages_for_activity'] = array('type' => self::TYPE_STRING, 'default' => 0);
        $fields['xf_user']['immunity'] = array('type' => self::TYPE_STRING, 'default' => 0);
        $fields['xf_user']['immunity_end_date'] = array('type' => self::TYPE_UINT_FORCED, 'default' => 0);
        $fields['xf_user']['vacation'] = array('type' => self::TYPE_STRING, 'default' => 0);
        $fields['xf_user']['vacation_start_date'] = array('type' => self::TYPE_UINT_FORCED, 'default' => 0);
        $fields['xf_user']['vacation_end_date'] = array('type' => self::TYPE_UINT_FORCED, 'default' => 0);
        
        return $fields;
    }
    
    public function updateTrackedActivityPosts($userId, $postid, $postdate)
    {
        
        /* Get current activity posts from database */
        $activityPosts = $this->_getUserModel()->getActivityPosts($userId);
        
        /* Are there posts already? Is this account flagged for low activity? */
        if($activityPosts && !$this->_getUserModel()->isLowActivity($userId))
        {
            /* Posts exist and this account is NOT flagged for low activity.  Check for and remove expired entries from array */
            $activityPosts = $this->_getUserModel()->checkExpiredPosts($activityPosts);
        }
        
        /* Add new entry to activityPosts */
        $activityPosts[$postid] = $postdate;

        /* EXPIRED DATE TESTING */
        $activityPosts[$postid] = "1497143118"; 
        
        /* Serialize data */
        $activityPosts = serialize($activityPosts);
        
        $this->setExistingData($userId);
        $this->set('rp_messages_for_activity', $activityPosts);
        $this->save();
        
        /* Update activity status for user */
        $this->updateActivityStatus($userId);
        
        return true;
    }
    
    public function deleteTrackedActivityPost($userId, $postId)
    {
        $activityPosts = $this->_getUserModel()->getActivityPosts($userId);
        
        /* Are there posts already? */
        if(!$activityPosts)
        {
            return;
        }
        
        unset($activityPosts[$postId]);
        
        $activityPosts = serialize($activityPosts);
        
        $this->setExistingData($userId);
        $this->set('rp_messages_for_activity', $activityPosts);
        $this->save();
        
        return true;
    }
    
        
    public function updateActivityStatus($userId)
    {
        $userModel = $this->_getUserModel();
        
        $posts = $userModel->getActivityPosts($userId);
        
        $options = XenForo_Application::get('options');
        
        /* check the activity posts and update usergroup appropriately */
        if(count($posts) < 3)
        {
            /* move to low activity group OR deletion group */
            
            /* set secondary usergroup based on current usergroups */
            $lowActivityUserGroup = $options->rps_ActivityCheck_LowActivity_Usergroup;
            $deletionUserGroup = $options->rps_ActivityCheck_Deletion_Usergroup;
            $secondaryUsergroups = explode(',', $this->get('secondary_group_ids'));
            
            $userModel = $this->_getUserModel();
            
            if($lowActivityUserGroup != null && $deletionUserGroup != null)
            {
                /* user is not in low activity group */
                if(!$userModel->isLowActivity($userId))
                {
                    /* add user to low activity group */
                    $secondaryUsergroups[] = $lowActivityUserGroup;
                    
                    $this->setExistingData($userId);
                    $this->setSecondaryGroups($secondaryUsergroups);
                    $this->save();
                }
                
                /* IF user is in low activity group AND enough time has passed Add user to deletion usergroup */
            }
        }
        else
        {
            /* remove from low activity or deletion group */
        }
        
        return true;
        
    }
    
    protected function _getUserModel()
    {
        return $this->getModelFromCache('XenForo_Model_User');
    }
}

?>
 
Top Bottom