Update CMS for new i18n API

This commit is contained in:
Damian Mooyman 2017-01-26 17:21:00 +13:00
parent a7c3befd8f
commit 945eba8efb
6 changed files with 19 additions and 13 deletions

View File

@ -433,12 +433,12 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'q[LastEditedFrom]',
_t('CMSSearch.FILTERDATEFROM', 'From')
);
$dateFrom->setConfig('showcalendar', true);
$dateFrom->setShowCalendar(true);
$dateTo = new DateField(
'q[LastEditedTo]',
_t('CMSSearch.FILTERDATETO', 'To')
);
$dateTo->setConfig('showcalendar', true);
$dateTo->setShowCalendar(true);
$pageFilter = new DropdownField(
'q[FilterClass]',
_t('CMSMain.PAGES', 'Page status'),

View File

@ -213,7 +213,7 @@ class ContentController extends Controller
if (class_exists('Translatable')) {
$locale = $request->getVar('locale');
if ($locale
&& i18n::validate_locale($locale)
&& i18n::getData()->validate($locale)
&& $this->dataRecord
&& $this->dataRecord->Locale != $locale
) {

View File

@ -9,12 +9,13 @@ use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Resettable;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\DataModel;
use SilverStripe\ORM\DB;
use Translatable;
class RootURLController extends Controller
class RootURLController extends Controller implements Resettable
{
/**

View File

@ -17,6 +17,7 @@ use SilverStripe\Control\RequestHandler;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Resettable;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\CompositeField;
@ -92,7 +93,7 @@ use Subsite;
* @mixin Versioned
* @mixin SiteTreeLinkTracking
*/
class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvider, CMSPreviewable
class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvider, CMSPreviewable, Resettable
{
/**
@ -2687,7 +2688,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// If we're in translation mode, the link between the translated pagetype title and the actual classname
// might not be obvious, so we add it in parantheses. Example: class "RedirectorPage" has the title
// "Weiterleitung" in German, so it shows up as "Weiterleitung (RedirectorPage)"
if (i18n::get_lang_from_locale(i18n::get_locale()) != 'en') {
if (i18n::getData()->langFromLocale(i18n::get_locale()) != 'en') {
$result[$class] = $result[$class] . " ({$class})";
}
}

View File

@ -2,6 +2,7 @@
namespace SilverStripe\CMS\Reports;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\DataObject;
use SilverStripe\Reports\Report;
@ -26,8 +27,10 @@ class RecentlyEditedReport extends Report
public function sourceRecords($params = null)
{
$threshold = strtotime('-14 days', DBDatetime::now()->Format('U'));
return DataObject::get("SilverStripe\\CMS\\Model\\SiteTree", "\"SiteTree\".\"LastEdited\" > '".date("Y-m-d H:i:s", $threshold)."'", "\"SiteTree\".\"LastEdited\" DESC");
$threshold = strtotime('-14 days', DBDatetime::now()->getTimestamp());
return SiteTree::get()
->filter('LastEdited:GreaterThan', date("Y-m-d H:i:s", $threshold))
->sort("\"SiteTree\".\"LastEdited\" DESC");
}
public function columns()

View File

@ -1,5 +1,6 @@
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\CMS\Reports\RecentlyEditedReport;
@ -32,8 +33,8 @@ class CmsReportsTest extends SapphireTest
$afterThreshold = strtotime('-'.(self::$daysAgo-1).' days', strtotime('31-06-2009 00:00:00'));
$beforeThreshold = strtotime('-'.(self::$daysAgo+1).' days', strtotime('31-06-2009 00:00:00'));
$after = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'after');
$before = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'before');
$after = $this->objFromFixture(SiteTree::class, 'after');
$before = $this->objFromFixture(SiteTree::class, 'before');
DB::query("UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='".date('Y-m-d H:i:s', $afterThreshold)."' WHERE \"ID\"='".$after->ID."'");
DB::query("UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='".date('Y-m-d H:i:s', $beforeThreshold)."' WHERE \"ID\"='".$before->ID."'");
@ -65,10 +66,10 @@ class CmsReportsTest extends SapphireTest
public function testRecentlyEdited()
{
DBDatetime::set_mock_now('31-06-2009 00:00:00');
DBDatetime::set_mock_now('2009-06-30 00:00:00');
$after = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'after');
$before = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'before');
$after = $this->objFromFixture(SiteTree::class, 'after');
$before = $this->objFromFixture(SiteTree::class, 'before');
$r = new RecentlyEditedReport();