2009-11-02 05:02:57 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Daily task to send emails to the owners of content items
|
|
|
|
* when the review date rolls around
|
|
|
|
*
|
|
|
|
* @package contentreview
|
|
|
|
*/
|
2013-09-23 07:55:59 +02:00
|
|
|
class ContentReviewEmails extends BuildTask {
|
|
|
|
|
2014-02-13 02:07:39 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param SS_HTTPRequest $request
|
|
|
|
*/
|
2013-09-23 07:55:59 +02:00
|
|
|
public function run($request) {
|
2009-11-02 05:02:57 +01:00
|
|
|
// Disable subsite filter (if installed)
|
|
|
|
if (ClassInfo::exists('Subsite')) {
|
|
|
|
$oldSubsiteState = Subsite::$disable_subsite_filter;
|
|
|
|
Subsite::$disable_subsite_filter = true;
|
|
|
|
}
|
|
|
|
|
2014-02-13 04:35:13 +01:00
|
|
|
$now = class_exists('SS_Datetime') ? SS_Datetime::now()->URLDate() : SSDatetime::now()->URLDate();
|
|
|
|
|
|
|
|
$pages = Page::get('Page')
|
|
|
|
->leftJoin('Group_SiteTreeContentReview', '"SiteTree"."ID" = "OwnerGroups"."SiteTreeID"', 'OwnerGroups')
|
|
|
|
->leftJoin('Member_SiteTreeContentReview', '"SiteTree"."ID" = "OwnerUsers"."SiteTreeID"', "OwnerUsers")
|
|
|
|
->where('"SiteTree"."NextReviewDate" <= \''.$now.'\' AND' .' ("OwnerGroups"."ID" IS NOT NULL OR "OwnerUsers"."ID" IS NOT NULL)')
|
|
|
|
;
|
|
|
|
|
2009-11-02 05:02:57 +01:00
|
|
|
if ($pages && $pages->Count()) {
|
|
|
|
foreach($pages as $page) {
|
2014-02-13 04:35:13 +01:00
|
|
|
$owners = $page->ContentReviewOwners();
|
|
|
|
if(!$owners->count()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$sender = Security::findAnAdministrator();
|
|
|
|
|
|
|
|
foreach($owners as $recipient) {
|
2009-11-02 05:02:57 +01:00
|
|
|
$subject = sprintf(_t('ContentReviewEmails.SUBJECT', 'Page %s due for content review'), $page->Title);
|
|
|
|
|
|
|
|
$email = new Email();
|
|
|
|
$email->setTo($recipient->Email);
|
|
|
|
$email->setFrom(($sender->Email) ? $sender->Email : Email::getAdminEmail());
|
|
|
|
$email->setTemplate('ContentReviewEmails');
|
|
|
|
$email->setSubject($subject);
|
|
|
|
$email->populateTemplate(array(
|
2012-07-16 07:50:50 +02:00
|
|
|
"PageCMSLink" => "admin/pages/edit/show/".$page->ID,
|
2009-11-02 05:02:57 +01:00
|
|
|
"Recipient" => $recipient,
|
|
|
|
"Sender" => $sender,
|
|
|
|
"Page" => $page,
|
2010-05-11 07:35:23 +02:00
|
|
|
"StageSiteLink" => Controller::join_links($page->Link(), "?stage=Stage"),
|
|
|
|
"LiveSiteLink" => Controller::join_links($page->Link(), "?stage=Live"),
|
2009-11-02 05:02:57 +01:00
|
|
|
));
|
2010-01-22 00:36:52 +01:00
|
|
|
$email->send();
|
2014-02-14 02:49:43 +01:00
|
|
|
|
|
|
|
$message = '<strong>'._t('ContentReviewEmails.EMAIL_HEADING','Page due for review').'</strong><br/>'.
|
|
|
|
'The page "'.$page->Title.'" is due for review today by you.<br/>
|
|
|
|
<a href="admin/pages/edit/show/'.$page->ID.'">'. _t('ContentReviewEmails.REVIEWPAGELINK','Review the page in the CMS') .'</a> —
|
|
|
|
<a href="#">'. _t('ContentReviewEmails.VIEWPUBLISHEDLINK','View this page on the website') .'</a>';
|
|
|
|
if(class_exists('Notification')) {
|
|
|
|
Notification::notify($recipient, $message);
|
|
|
|
}
|
2009-11-02 05:02:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Revert subsite filter (if installed)
|
|
|
|
if (ClassInfo::exists('Subsite')) {
|
|
|
|
Subsite::$disable_subsite_filter = $oldSubsiteState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|