1

I'm using code I've been using to update existing entries for a while now and it's failing to fire following the 2.5 upgrade. Trying to figure out what might have changed, or if there's something I'm overlooking. I'm consistently getting the "not saved" response and seeing no update in the entry. showInInvestmentAdvisersReference is the new field I'm setting. I've got limit=1 set for testing purposes.

$entries = craft()->elements->getCriteria(ElementType::Entry);
$entries->section = 'referenceMaterials';
$entries->limit = 1;

$existingEntries = $entries->find();

foreach ($existingEntries as $existingEntry) {
    echo 'id: ' . $existingEntry->id . '<br />';

    $entryToSave = new EntryModel();

    $entryToSave = $existingEntry;

    // Setting these in case they're required to be set for saveEntry()
    $entryToSave->sectionId = 9;
    $entryToSave->typeId = 9;
    $entryToSave->authorId = 1;
    $entryToSave->enabled = true;
    $entryToSave->getContent()->title = $existingEntry->title;

    $entryToSave->getContent()->showInInvestmentAdvisersReference = 1;

    if ( craft()->entries->saveEntry($entryToSave) )
    {
        echo 'saved<br />';
    }
    else {
        echo 'not saved<br />';
    }
}

Is it me? Did something change? Happy to file a bug report but thought I'd start here first where code formatting is supported.

1 Answer 1

3

Something on the $entryToSave EntryModel is failing validation. If you echo out implode(', ', $entryToSave()->getAllErrors());, then you'll see what those errors are and you can correct them.

1
  • That helped! It was balking on a required field. Just to be clear, if a required field is not explicitly set, even though it was set in existing entry I'm assigning to the entryToSave, I'll still get that error? I resolved it by temporarily setting those fields as not required for the section. Thanks, Brad! Dec 2, 2015 at 22:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.