我正在尝试制作计划发布模块(将来某个日期发布一个简单页面)。 我搜索了一个类似的插件,发现了Embargo-Expiry Module,其中还包括Queued Jobs模块。我已成功安装和配置它们作为开发人员,但不知道如何配置或使用它们。我在管理区域只有一个标签,如下所示:
所以我需要任何cron工作吗?我该怎么做?我只想要一个靠近发布的新按钮,比如wordpress,设置发布/取消发布日期。
答案 0 :(得分:4)
来自https://github.com/silverstripe-scienceninjas/embargoexpiry ...
的文档B
注意:您需要更新cli-script.php的路径以引用您自己的环境。 queuedjobs模块本身https://github.com/nyeholt/silverstripe-queuedjobs
还有更多示例答案 1 :(得分:3)
这是更简单的解决方案:
例如,添加/mysite/code/FuturePublishDate.php
<?php
class FuturePublishDate extends DataExtension
{
private static $db = array(
'PublishDate' => 'SS_DateTime'
);
public function updateCMSFields(FieldList $fields) {
$datetimeField = new DatetimeField( 'PublishDate', 'Publish From' );
$dateField = $datetimeField->getDateField();
$dateField->setConfig( 'dateformat', 'yyyy-MM-dd' );
$dateField->setConfig( 'showcalendar', true );
$timeField = $datetimeField->getTimeField();
$timeField->setConfig( 'timeformat', 'H:m:s' );
$fields->insertBefore( $datetimeField, 'Content' );
}
public function populateDefaults() {
$this->owner->PublishDate = SS_Datetime::now();
}
}
class FuturePublishDateController extends Extension
{
public function beforeCallActionHandler($request, $action) {
if ('index' !== $action || $this->owner->is_a('ErrorPage_Controller')) {
return;
}
$isDraftPreview = 'Stage' === $request->getVar('stage');
if( !$isDraftPreview
&& $this->owner->PublishDate
&& strtotime($this->owner->PublishDate) > strtotime('now')
){
// bug in SS 3.1 in OldPageRedirector
// $this->owner->httpError( 404 );
$response = $request->isMedia() ? null : ErrorPage::response_for(404);
if ($response) {
return $response;
}
throw new SS_HTTPResponse_Exception('404 Not Found', 404);
}
}
}
并在mysite / _config / config.yml
中注册---
Name: mysiteconfig
---
Page:
extensions:
- FuturePublishDate
Page_Controller:
extensions:
- FuturePublishDateController
在Page.php中定义默认操作,以便挂钩beforeCallActionHandler工作
class Page_Controller extends ContentController
{
public function index(SS_HTTPRequest $request) {
return $this->getViewer('index')->process($this);
}
public function Menu($level) {
$items = parent::Menu($level);
$isDraftPreview = 'Stage' === $this->request->getVar('stage');
if ($isDraftPreview) {
return $items;
}
$now = strtotime('now');
$visible = array();
foreach ($items as $page) {
if ($page->PublishDate && strtotime($page->PublishDate) <= $now) {
$visible[] = $page;
} elseif (!$page->PublishDate) {
$visible[] = $page;
}
}
return new ArrayList($visible);
}
}
如果您使用SilverStripe 3.3.1,则需要删除Controller.php中的一行
protected function handleAction($request, $action) {
//DELETED $this->extend('beforeCallActionHandler', $request, $action);
foreach($request->latestParams() as $k => $v) {
并运行dev/build?flush=1