Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CMS for new i18n API #1734

Merged
merged 1 commit into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,12 @@ public function SearchForm()
'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'),
Expand Down
2 changes: 1 addition & 1 deletion code/Controllers/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function handleRequest(HTTPRequest $request, DataModel $model)
if (class_exists('Translatable')) {
$locale = $request->getVar('locale');
if ($locale
&& i18n::validate_locale($locale)
&& i18n::getData()->validate($locale)
&& $this->dataRecord
&& $this->dataRecord->Locale != $locale
) {
Expand Down
3 changes: 2 additions & 1 deletion code/Controllers/RootURLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
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
{

/**
Expand Down
5 changes: 3 additions & 2 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -92,7 +93,7 @@
* @mixin Versioned
* @mixin SiteTreeLinkTracking
*/
class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvider, CMSPreviewable
class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvider, CMSPreviewable, Resettable
{

/**
Expand Down Expand Up @@ -2687,7 +2688,7 @@ protected function getClassDropdown()
// 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})";
}
}
Expand Down
7 changes: 5 additions & 2 deletions code/Reports/RecentlyEditedReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,8 +27,10 @@ public function sort()

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()
Expand Down
11 changes: 6 additions & 5 deletions tests/reports/CmsReportsTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\CMS\Reports\RecentlyEditedReport;
Expand Down Expand Up @@ -32,8 +33,8 @@ public function setUp()
$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."'");
Expand Down Expand Up @@ -65,10 +66,10 @@ public function isReportBroken($report, $isDraftBroken, $isPublishedBroken)

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();

Expand Down