1

I got a little problem: I would like to publish an item with some "different" states (1,0,2,-2,-1).

I'm doing this this way:

if(empty($this->getErrors()))
{
    $tableitem->store();    
    $publish                                    =   $modelitem->publish($id, $state);
    $return                                     =   true;               
}

Now the problem: If I call this function via Web GUI (Joomla Admin Backend) $publish returns true.

If I do this via CLI (I would like to set different publishing-states via CLI if an item is older than xyz) $publish returns false.

The method is not overwritten in modelitem.php.

If I try to override the publish-method in modelitem.php like this:

public function publish(&$pks, $value = 1)
{
    // Initialise variables.
    $dispatcher = JDispatcher::getInstance();
    $user = JFactory::getUser();
    $table = $this->getTable();
    $pks = (array) $pks;
    // Include the content plugins for the change of state event.
    JPluginHelper::importPlugin('content');
    // Access checks.

    foreach ($pks as $i => $pk)
    {
        $table->reset();
        var_dump($this->canEditState($table)); die;
        if ($table->load($pk))
        {
            if (!$this->canEditState($table))
            {                   
                // Prune items that you can't change.
                unset($pks[$i]);
                JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
                return false;
            }
        }
    }

    // Attempt to change the state of the records.
    if (!$table->publish($pks, $value, $user->get('id')))
    {
        $this->setError($table->getError());
        return false;
    }

    $context = $this->option . '.' . $this->name;
    // Trigger the onContentChangeState event.
    $result = $dispatcher->trigger($this->event_change_state, array($context, $pks, $value));
    if (in_array(false, $result, true))
    {
        $this->setError($table->getError());
        return false;
    }
    // Clear the component's cache
    $this->cleanCache();

    return true;
}

I mention that $this->canEditState($table) returns NULL and so the publish-function returns false.

What can I do here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.