我正在嘗試製作一個計劃發佈模塊(在將來的某個日期發佈簡單頁面)。 我搜索了一個類似的插件,並找到了Embargo-Expiry模塊,它還包含Queued Jobs模塊。我已經成功安裝並配置它們作爲dev-master,但不知道如何配置或使用它們。我只有在管理區域看起來像這樣的標籤: 銀色條紋將來發布頁面
那麼,我需要任何cron作業嗎?我該怎麼做?我只想在發佈附近添加一個新按鈕,如wordpress,設置發佈/取消發佈日期。
我正在嘗試製作一個計劃發佈模塊(在將來的某個日期發佈簡單頁面)。 我搜索了一個類似的插件,並找到了Embargo-Expiry模塊,它還包含Queued Jobs模塊。我已經成功安裝並配置它們作爲dev-master,但不知道如何配置或使用它們。我只有在管理區域看起來像這樣的標籤: 銀色條紋將來發布頁面
那麼,我需要任何cron作業嗎?我該怎麼做?我只想在發佈附近添加一個新按鈕,如wordpress,設置發佈/取消發佈日期。
這裏的許多例子是更簡單的解決方案:
例如添加/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
從https://github.com/silverstripe-scienceninjas/embargoexpiry文檔...
Ensure the QueuedJobs module is installed and configured correctly. You should have a cronjob similar to the following in place, running as the webserver user.
*/1 * * * * cd && sudo -u www php /sites/default/www/framework/cli-script.php dev/tasks/ProcessJobQueueTask
注意:您將需要更新的路徑,CLI-script.php的引用自己的環境。 也存在queuedjobs模塊本身
,謝謝你的幫助。我試過這個代碼,但我恐怕沒有成功。在開發/構建之後,所有東西都可以,CMS中顯示的字段選擇將來的日期(將來幾分鐘),然後保存爲草稿。該頁面立即出現(在選擇日期之前)。我再讀一遍,你說'發佈',所以我創建了一個新頁面,選擇一個新的未來日期,並且我發佈了它。該頁面不可見,並且當發佈時間到達時,仍然沒有顯示......等待幾分鐘,保持清爽,刷新現金並且仍然不可見。有任何想法嗎 ?再次感謝 – Spidey
right :) beforCallActionHandler不會被調用隱式默認操作'index'。感謝您的編輯,您必須在Page.php –
中定義它。我做了更改,但現在,當我創建新頁面(在發佈或保存爲草稿之前)頁面會自動發佈爲網站上的新頁面,當我點擊發布或另存爲草稿時,頁面只會更新我給出的名稱在CMS中,仍然沒有成功:( – Spidey