silverstripe-archive / silverstripe-newsletter

NewsletterAdmin is the CMS class for managing the newsletter system.
BSD 3-Clause "New" or "Revised" License
69 stars 59 forks source link

exclude can't be called on an UnsavedRelationList #67

Closed jimt closed 6 years ago

jimt commented 10 years ago

After updating from SilverStripe 3.0 to 3.1.3, and the newsletter module to trunk 77d916e29 I get an error when I visit the admin/newsletter/MailingList page:

Error at framework/model/UnsavedRelationList.php line 315: Uncaught LogicException: exclude can't be called on an UnsavedRelationList.

I can eliminate the error (and some of the functionality :-/ ) by changing the value returned by:

        /**
         * Returns all recipients who aren't blacklisted, and are verified.
         */
        public function ActiveRecipients() {
                return $this->Recipients()->exclude('Blacklisted', 1)->exclude('Verified', 0);
        }

to simply:

                return $this->Recipients();
ss23 commented 10 years ago

As a quick fix, we could do a "If the list isn't saved, filter -- if it is, don't filter"? That would retain the functionality and get it working.

I have no idea off hand if something has changed in framework to cause this, or it was just not seen for this long. Might be worth grabbing someone who knows what they're doing to comment.

jimt commented 10 years ago

Some additional logging suggests the method's first call when the Mailing LIst tab is clicked is for a mailing list with ID==0 (and no title) which doesn't exist. My first mailing list appears to have ID==1. The right solution is doubtlessly figuring out why it is now looking for list zero, but for now this gets me going:

        public function ActiveRecipients() {
                if ($this->ID) {
                        return $this->Recipients()->exclude('Blacklisted', 1)->exclude('Verified', 0);
                } else {
                        return $this->Recipients();
                }
        }
wilr commented 6 years ago

Fixed in ab2de6fb