Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » [Solved] PageCommentEmailNotification

Discuss the Blog Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 654 Views
  • borriej
    Avatar
    Community Member
    267 Posts

    [Solved] PageCommentEmailNotification Link to this post

    Hello,

    I couldn't find the topic, so im posting it again:

    Got this little script:

    PageCommentEmailNotification.php

    <?php

    class PageCommentEmailNotification extends DataObjectDecorator {
    function onAfterWrite() {
    parent::onAfterWrite();
    if ($this->NeedsModeration) {
    $email = new Email();
    $email->setTemplate('NewComment');
    $email->setTo(Email::getAdminEmail());
    $email->addCustomHeader('Reply-To', Member::currentUser()->Email);
    $email->setSubject('New Comment ' . str_replace(array("http://", "https://"), array("", ""), Director::absoluteBaseURL()));
    $email->populateTemplate(array(
    'URL' => Director::absoluteBaseURL() . $this->owner->Parent()->URLSegment,
    'PageTitle' => $this->owner->Parent()->Title,
    'Comment' => $this->owner->Comment,
    'Name' => $this->owner->Name,
    ));
    $email->send();
    }
    }
    }

    It sends emails when new comments are posted on my blog, this works well when your logged in as a admin..

    But when your not logged in: you get a pop-up with the html code of a error page. The message content:

       
          <h2>Server error</h2>
       
          <p>Sorry, there was a problem with handling your request.</p>

    How do i fix this?

       

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: [Solved] PageCommentEmailNotification Link to this post

    Put the site into devmode. That will give you a better error message.

    http://doc.silverstripe.org/sapphire/en/topics/debugging#environment-types

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: [Solved] PageCommentEmailNotification Link to this post

    Site is already in dev mode:
    Director::set_environment_type("dev");

    ..

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: [Solved] PageCommentEmailNotification Link to this post

    im debugging it now by removing and adding line by line.

    found out that the problem occurs when:

    if ($this->NeedsModeration) {

    }

    Is added into this code:

    class PageCommentEmailNotification extends DataObjectDecorator {
    function onAfterWrite() {
    parent::onAfterWrite();
    if ($this->NeedsModeration) {

    }

    What to do now?s

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: [Solved] PageCommentEmailNotification Link to this post

    Solved!

    For the people who are looking for this code:

    config:

    DataObject::add_extension('PageComment', 'PageCommentEmailNotification');

    PageCommentEmailNotification.php

    <?php

    class PageCommentEmailNotification extends DataObjectDecorator {
    function onAfterWrite() {
    parent::onAfterWrite();

           $email = new Email();
    $email->setTemplate('NewComment');
    $email->setTo(Email::getAdminEmail());
    // $email->addCustomHeader('Reply-To', Member::currentUser()->Email);
    $email->setSubject('New Comment ' . str_replace(array("http://", "https://"), array("", ""), Director::absoluteBaseURL()));
    $email->populateTemplate(array(
    'URL' => Director::absoluteBaseURL() . $this->owner->Parent()->URLSegment,
    'PageTitle' => $this->owner->Parent()->Title,
    'Comment' => $this->owner->Comment,
    'Name' => $this->owner->Name,
    ));
    $email->send();
    }
    }

    654 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.