1776 Posts in 498 Topics by 533 members
Blog Module
SilverStripe Forums » Blog Module » [Solved] PageCommentEmailNotification
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 522 Views |
-
[Solved] PageCommentEmailNotification

2 March 2011 at 3:23am
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?
-
Re: [Solved] PageCommentEmailNotification

2 March 2011 at 10:35pm
Put the site into devmode. That will give you a better error message.
http://doc.silverstripe.org/sapphire/en/topics/debugging#environment-types
-
Re: [Solved] PageCommentEmailNotification

2 March 2011 at 10:53pm
Site is already in dev mode:
Director::set_environment_type("dev");..
-
Re: [Solved] PageCommentEmailNotification

2 March 2011 at 11:06pm
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
-
Re: [Solved] PageCommentEmailNotification

2 March 2011 at 11:11pm Last edited: 2 March 2011 11:12pm
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();
}
}
| 522 Views | ||
|
Page:
1
|
Go to Top |

