1

Is it obvious why the task validation errors are not getting output in my log:

public function runStep($step)
{
    try
    {
        $entry = craft()->entries->getEntryById($this->_entryIds[$step], $this->_localeId);

        if (!$entry)
        {
            return true;
        }

        $newExpiryDate = new DateTime($entry->date);
        $newExpiryDate->add(new DateInterval('P1D'));


        // Update Expiry Date
        if($entry->expiryDate != $newExpiryDate)
        {
            $entry->expiryDate = $newExpiryDate->format('Y-m-d');
        }

        // Update Status
        $entry->enabled = true;

        // Save Entry
        if(craft()->entries->saveEntry($entry))
        {
            return true;    
        }
        else
        {
            $error = 'Encountered the following validation errors when trying to save entry with the ID "'.$entry->id.'":';

            foreach ($entry->getAllErrors() as $attributeError)
            {
                $error .= "\n - {$attributeError}";
            }

            return $error;              
        }

        return true;
    }
    catch (\Exception $e)
    {
        return 'An exception was thrown while trying to save the entry with the ID “'.$this->_entryIds[$step].'”: '.$e->getMessage();
    }
}

This task step is based on one of the Craft default steps but the error gets output without the specific validation issues:

Encountered an error running task 1191 (Logic_UpdateEvents), step 1 of 1440: Encountered the following validation errors when trying to save entry with the ID "10295":

12
  • What happens if you Craft::log('error count = '.count($entry->getAllErrors()));
    – Brad Bell
    Apr 30, 2015 at 14:52
  • error count = 1 Apr 30, 2015 at 14:57
  • Looks O.K. to me. What if you do: Craft::log('error = '.$entry->getAllErrors[0]);?
    – Brad Bell
    Apr 30, 2015 at 15:16
  • Encountered an error running task 1193 (Logic_UpdateEvents), step 1 of 1440: An exception was thrown while trying to save the entry with the ID “10295”: Property "Craft\EntryModel.getAllErrors" is not defined. Apr 30, 2015 at 15:20
  • Wait a second surely that needs to be Craft::log('error = '.$entry->getAllErrors()[0]) ? Apr 30, 2015 at 15:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.