Skip to content

Instantly share code, notes, and snippets.

@Liongold
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Liongold/f0fcda4f39c9e8f33233 to your computer and use it in GitHub Desktop.
Save Liongold/f0fcda4f39c9e8f33233 to your computer and use it in GitHub Desktop.
Website Change Notifications
public function onAfterPublish(&$original) {
$subSites = Subsite::currentSubsite();
if($subSites->ContactEmail) {
$versioned = Versioned::get_version('SiteTree', $this->ID, $this->Version);
$member = Member::get()->byId($versioned->AuthorID);
// Check for changes in page controller
$mailer = new Email(
"no-reply@documentfoundation.org",
$subSites->ContactEmail,
"The site has just been updated. "
);
$mailer->setTemplate("RevisionEmail");
$diffData = new DataDifferencer($original, $this);
$mailer->populateTemplate(new ArrayData(array(
'Name' => $member->FirstName,
'Surname' => $member->Surname,
'Title' => $this->getMenuTitle(),
'Link' => $this->AbsoluteLink(),
'Difference' => $diffData
)));
$mailer->sendPlain();
}
return true;
}
Website Change Notification\n\n
Dear community,\n this email is being sent to inform you that $Name $Surname has just published a new version of $Title. \n\n
The following changes have been made to the page:\n
<% with $Difference %>
<% loop ChangedFields %>
$Title\n\n $Diff\n\n
<% end_loop %>
<% end_with %>
You can checkout the latest version of the page by visiting $Link.
@cloph
Copy link

cloph commented Mar 30, 2015

<dl class="diff">
<% with Difference %>
<% loop ChangedFields %> 
   <dt>$Title</dt>
   <dd>$Diff</dd>
<% end_loop %> 
<% end_with %> 
</dl>

and using 'Difference' => $diffData
should fit our needs better (no Content field used in many pagetypes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment