mirror of
https://github.com/silverstripe/silverstripe-contentreview
synced 2024-10-22 17:05:47 +02:00
Inherit content review settings from siteconfig or parent page
This commit is contained in:
parent
78d84a57c6
commit
0ad06c49fd
@ -28,31 +28,32 @@ class ContentReviewEmails extends BuildTask {
|
|||||||
Subsite::$disable_subsite_filter = true;
|
Subsite::$disable_subsite_filter = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$overduePages = array();
|
||||||
|
|
||||||
$now = class_exists('SS_Datetime') ? SS_Datetime::now()->URLDate() : SSDatetime::now()->URLDate();
|
$now = class_exists('SS_Datetime') ? SS_Datetime::now()->URLDate() : SSDatetime::now()->URLDate();
|
||||||
|
|
||||||
// First grab all the pages with a custom setting
|
// First grab all the pages with a custom setting
|
||||||
$pages = Page::get('Page')
|
$customSettingsPages = Page::get('Page')
|
||||||
->leftJoin('Group_SiteTreeContentReview', '"SiteTree"."ID" = "OwnerGroups"."SiteTreeID"', 'OwnerGroups')
|
->leftJoin('Group_SiteTreeContentReview', '"SiteTree"."ID" = "OwnerGroups"."SiteTreeID"', 'OwnerGroups')
|
||||||
->leftJoin('Member_SiteTreeContentReview', '"SiteTree"."ID" = "OwnerUsers"."SiteTreeID"', "OwnerUsers")
|
->leftJoin('Member_SiteTreeContentReview', '"SiteTree"."ID" = "OwnerUsers"."SiteTreeID"', "OwnerUsers")
|
||||||
->where('"SiteTree"."ContentReviewType" != \'Custom\' AND "SiteTree"."NextReviewDate" <= \''.$now.'\' AND' .
|
->where('"SiteTree"."ContentReviewType" = \'Custom\' AND "SiteTree"."NextReviewDate" <= \''.$now.'\' AND' .
|
||||||
' ("OwnerGroups"."ID" IS NOT NULL OR "OwnerUsers"."ID" IS NOT NULL)')
|
' ("OwnerGroups"."ID" IS NOT NULL OR "OwnerUsers"."ID" IS NOT NULL)')
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->notify($pages);
|
$this->getOverduePagesForOwners($customSettingsPages, $overduePages);
|
||||||
|
|
||||||
// Then grab all the pages with that inherits their settings
|
// Then grab all the pages with that inherits their settings
|
||||||
|
$inheritedSettingsPages = Page::get('Page')
|
||||||
$pages = Page::get('Page')
|
|
||||||
->leftJoin('Group_SiteTreeContentReview', '"SiteTree"."ID" = "OwnerGroups"."SiteTreeID"', 'OwnerGroups')
|
->leftJoin('Group_SiteTreeContentReview', '"SiteTree"."ID" = "OwnerGroups"."SiteTreeID"', 'OwnerGroups')
|
||||||
->leftJoin('Member_SiteTreeContentReview', '"SiteTree"."ID" = "OwnerUsers"."SiteTreeID"', "OwnerUsers")
|
->leftJoin('Member_SiteTreeContentReview', '"SiteTree"."ID" = "OwnerUsers"."SiteTreeID"', "OwnerUsers")
|
||||||
->where('"SiteTree"."ContentReviewType" = \'Inherit\'')
|
->where('"SiteTree"."ContentReviewType" = \'Inherit\'')
|
||||||
;
|
;
|
||||||
|
|
||||||
$overduePages = $this->findInheritedSettings($pages);
|
$this->getOverduePagesForOwners($inheritedSettingsPages, $overduePages);
|
||||||
|
|
||||||
// Lets send one email to one owner with all the pages in there instead of no of pages of emails
|
// Lets send one email to one owner with all the pages in there instead of no of pages of emails
|
||||||
foreach($overduePages as $memberID => $pages) {
|
foreach($overduePages as $memberID => $pages) {
|
||||||
$this->notify_user($memberID, $pages);
|
$this->notifyOwner($memberID, $pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Revert subsite filter (if installed)
|
// Revert subsite filter (if installed)
|
||||||
@ -64,33 +65,17 @@ class ContentReviewEmails extends BuildTask {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param SS_list $pages
|
* @param SS_list $pages
|
||||||
|
* @param array &$pages
|
||||||
* @return type
|
* @return type
|
||||||
*/
|
*/
|
||||||
protected function findInheritedSettings(SS_list $pages) {
|
protected function getOverduePagesForOwners(SS_list $pages, array &$overduePages) {
|
||||||
$overduePages = array();
|
|
||||||
|
|
||||||
foreach($pages as $page) {
|
foreach($pages as $page) {
|
||||||
|
if(!$page->isContentReviewOverdue($page)) {
|
||||||
$settings = $this->findContentSettingFor($page);
|
|
||||||
// This page has a parent with the 'Disabled' option
|
|
||||||
if(!$settings) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$owners = $settings->ContentReviewOwners();
|
$settings = $page->getContentReviewSetting($page);
|
||||||
if(!$owners->count()) {
|
foreach($settings->ContentReviewOwners() as $owner) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(!$settings->ReviewPeriodDays) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Calculate next time this page should be reviewed from the LastEdited datea
|
|
||||||
$nextReviewUnixSec = strtotime($page->LastEdited . ' + '.$settings->ReviewPeriodDays . ' days');
|
|
||||||
if($nextReviewUnixSec > time()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($owners as $owner) {
|
|
||||||
if(!isset(self::$member_cache[$owner->ID])) {
|
if(!isset(self::$member_cache[$owner->ID])) {
|
||||||
self::$member_cache[$owner->ID] = $owner;
|
self::$member_cache[$owner->ID] = $owner;
|
||||||
}
|
}
|
||||||
@ -103,36 +88,14 @@ class ContentReviewEmails extends BuildTask {
|
|||||||
return $overduePages;
|
return $overduePages;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param SiteTree $page
|
|
||||||
* @return DataObject or false if no settings found
|
|
||||||
*/
|
|
||||||
protected function findContentSettingFor($page) {
|
|
||||||
while($parent = $page->Parent()) {
|
|
||||||
// Root page, use siteconfig
|
|
||||||
if(!$parent->exists()) {
|
|
||||||
return SiteConfig::current_site_config();
|
|
||||||
}
|
|
||||||
if($parent->ContentReviewType == 'Custom') {
|
|
||||||
return $parent;
|
|
||||||
}
|
|
||||||
if($parent->ContentReviewType == 'Disabled') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$page = $parent;
|
|
||||||
}
|
|
||||||
throw new Exception('This shouldnt really happen, as usual.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param int $owner
|
* @param int $owner
|
||||||
* @param array $pages
|
* @param array $pages
|
||||||
*/
|
*/
|
||||||
protected function notify_user($ownerID, array $pages) {
|
protected function notifyOwner($ownerID, array $pages) {
|
||||||
$owner = self::$member_cache[$ownerID];
|
$owner = self::$member_cache[$ownerID];
|
||||||
echo $owner->Email.PHP_EOL;
|
echo "----- ".$owner->Email." -----".PHP_EOL;
|
||||||
foreach($pages as $page) {
|
foreach($pages as $page) {
|
||||||
echo $page->Title.PHP_EOL;
|
echo $page->Title.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,13 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
|
|||||||
365 => "12 months",
|
365 => "12 months",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_schedule() {
|
||||||
|
return self::$schedule;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
@ -111,13 +118,6 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
|
|||||||
return $contentReviewOwners;
|
return $contentReviewOwners;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function get_schedule() {
|
|
||||||
return self::$schedule;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ManyManyList
|
* @return ManyManyList
|
||||||
*/
|
*/
|
||||||
@ -140,7 +140,6 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
|
|||||||
public function updateSettingsFields(FieldList $fields) {
|
public function updateSettingsFields(FieldList $fields) {
|
||||||
|
|
||||||
Requirements::javascript('contentreview/javascript/contentreview.js');
|
Requirements::javascript('contentreview/javascript/contentreview.js');
|
||||||
$crFields = new FieldList();
|
|
||||||
|
|
||||||
// Display read-only version only
|
// Display read-only version only
|
||||||
if(!Permission::check("EDIT_CONTENT_REVIEW_FIELDS")) {
|
if(!Permission::check("EDIT_CONTENT_REVIEW_FIELDS")) {
|
||||||
@ -168,7 +167,6 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
|
|||||||
$reviewFreq,
|
$reviewFreq,
|
||||||
$logs
|
$logs
|
||||||
));
|
));
|
||||||
// Done!
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,11 +176,6 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
|
|||||||
$options["Custom"] = _t('ContentReview.CUSTOM', "Custom settings");
|
$options["Custom"] = _t('ContentReview.CUSTOM', "Custom settings");
|
||||||
$viewersOptionsField = OptionsetField::create("ContentReviewType", _t('ContentReview.OPTIONS', "Options"), $options);
|
$viewersOptionsField = OptionsetField::create("ContentReviewType", _t('ContentReview.OPTIONS', "Options"), $options);
|
||||||
|
|
||||||
//$viewersOptionsField->setValue($this->owner->ContentReviewType);
|
|
||||||
|
|
||||||
#var_dump($this->owner->ContentReviewType);
|
|
||||||
#die();
|
|
||||||
|
|
||||||
$users = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
$users = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
|
||||||
|
|
||||||
$usersMap = $users->map('ID', 'Title')->toArray();
|
$usersMap = $users->map('ID', 'Title')->toArray();
|
||||||
@ -253,9 +246,11 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
|
|||||||
if($this->owner->ReviewPeriodDays) {
|
if($this->owner->ReviewPeriodDays) {
|
||||||
$this->owner->NextReviewDate = date('Y-m-d', strtotime('+' . $this->owner->ReviewPeriodDays . ' days'));
|
$this->owner->NextReviewDate = date('Y-m-d', strtotime('+' . $this->owner->ReviewPeriodDays . ' days'));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$hasNextReview = false;
|
$hasNextReview = false;
|
||||||
$this->owner->NextReviewDate = null;
|
$this->owner->NextReviewDate = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->owner->write();
|
$this->owner->write();
|
||||||
return $hasNextReview;
|
return $hasNextReview;
|
||||||
}
|
}
|
||||||
@ -265,7 +260,7 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
|
|||||||
* @param \FieldList $actions
|
* @param \FieldList $actions
|
||||||
*/
|
*/
|
||||||
public function updateCMSActions(\FieldList $actions) {
|
public function updateCMSActions(\FieldList $actions) {
|
||||||
if($this->canBeReviewedBy(Member::currentUser())) {
|
if($this->isContentReviewOverdue($this->owner, Member::currentUser())) {
|
||||||
$reviewAction = FormAction::create('reviewed', _t('ContentReview.BUTTONREVIEWED', 'Content reviewed'))
|
$reviewAction = FormAction::create('reviewed', _t('ContentReview.BUTTONREVIEWED', 'Content reviewed'))
|
||||||
->setAttribute('data-icon', 'pencil')
|
->setAttribute('data-icon', 'pencil')
|
||||||
->setAttribute('data-text-alternate', _t('ContentReview.BUTTONREVIEWED', 'Content reviewed'));
|
->setAttribute('data-text-alternate', _t('ContentReview.BUTTONREVIEWED', 'Content reviewed'));
|
||||||
@ -273,6 +268,82 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method calculates if this page review date is over due.
|
||||||
|
*
|
||||||
|
* If NextReviewDate is set, it will use the it, otherwise if fallsback to
|
||||||
|
* LastEdited and ReviewPeriodDays
|
||||||
|
*
|
||||||
|
* @param DataObject $settings
|
||||||
|
* @param Member $null - optional check for a certain Member
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isContentReviewOverdue(SiteTree $page, Member $member = null) {
|
||||||
|
$settings = $this->getContentReviewSetting($page);
|
||||||
|
|
||||||
|
if(!$settings) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$settings->ContentReviewOwners()->count()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($member !== null) {
|
||||||
|
// member must exists in either owner groups ro owner users
|
||||||
|
if(!($member->inGroups($settings->OwnerGroups()) || $settings->OwnerUsers()->find('ID', $member->ID))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($page->obj('NextReviewDate')->exists() && !$page->obj('NextReviewDate')->InFuture()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallover to check on ReviewPeriodDays + LastEdited > Now
|
||||||
|
if(!$settings->ReviewPeriodDays) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate next time this page should be reviewed from the LastEdited datea
|
||||||
|
$nextReviewUnixSec = strtotime($this->owner->LastEdited . ' + '.$settings->ReviewPeriodDays . ' days');
|
||||||
|
|
||||||
|
if($nextReviewUnixSec < time()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the object that have the information about the content
|
||||||
|
* review settings
|
||||||
|
*
|
||||||
|
* Will go through parents and root pages will use the siteconfig
|
||||||
|
* if their setting is Inherit.
|
||||||
|
*
|
||||||
|
* @param SiteTree $page
|
||||||
|
* @return DataObject or false if no settings found
|
||||||
|
*/
|
||||||
|
public function getContentReviewSetting($page) {
|
||||||
|
if($page->ContentReviewType == 'Custom') {
|
||||||
|
return $page;
|
||||||
|
}
|
||||||
|
while($parent = $page->Parent()) {
|
||||||
|
// Root page, use siteconfig
|
||||||
|
if(!$parent->exists()) {
|
||||||
|
return SiteConfig::current_site_config();
|
||||||
|
}
|
||||||
|
if($parent->ContentReviewType == 'Custom') {
|
||||||
|
return $parent;
|
||||||
|
}
|
||||||
|
if($parent->ContentReviewType == 'Disabled') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$page = $parent;
|
||||||
|
}
|
||||||
|
throw new Exception('This shouldn\'t really happen, as per usual developer logic.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a review is due by a member for this owner
|
* Check if a review is due by a member for this owner
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user