We can use onBeforeUnpublish to notify us of when a page is unpublished to help debug the problem. We do this through a SiteTree extension.
We declare a SiteTree extension in our config.yml file (or an alternative yml file):
SiteTree:
extensions:
- SiteTreeExtension
In the extension class we add an onBeforeUnpublish function to email us when ever a page is unpublished:
class SiteTreeExtension extends DataExtension {
public function onBeforeUnpublish() {
$member = Member::currentUser();
$config = SiteConfig::current_site_config();
$pageEditLink = Director::absoluteBaseURL() . 'admin/pages/edit/show/' . $this->owner->ID;
$content = '<p>Page has been unpublished</p>';
$content .= '<p><strong>Page name</strong><br />';
$content .= '<a href="' . $pageEditLink . '">' . $this->owner->Title . '</a></p>';
$content .= '<p><strong>Page ID</strong><br />';
$content .= '<a href="' . $pageEditLink . '">' . $this->owner->ID . '</a></p>';
if ($member) {
$memberEditLink = Director::absoluteBaseURL() . 'admin/security/EditForm/field/Members/item/' . $member->ID . '/edit';
$content .= '<p><strong>Member email</strong><br />';
$content .= '<a href="' . $memberEditLink . '">' . $member->Email . '</a></p>';
$content .= '<p><strong>Member ID</strong><br />';
$content .= '<a href="' . $memberEditLink . '">' . $member->ID . '</a></p>';
}
$email = Email::create(
'[email protected]',
'[email protected]',
$config->Title . ' - Page Unpublished',
$content
);
$email->send();
}
}
In the above code the email content has a log of the page that was unpublished and member that unpublished the page.
This doesn't fix the problem but it should help track and debug the issue.
*_Livetable for the record to confirm it is there with the content etc you were intending. When it is randomly unpublished again, do the same check trying to find the same row. At the same time, update a random page that this is not happening to with an extra word or phrase. For me, the only thought that is coming to mind is the DB is going back in time (not even joking). Unless you have some crazy complex or different code, I don't think it is a Silverstripe issue. - Turnerj