Merge branch '1.0'

Conflicts:
	.travis.yml
	code/model/Translatable.php
This commit is contained in:
Ingo Schommer 2013-06-03 12:06:29 +02:00
commit 51cd0146df
3 changed files with 59 additions and 9 deletions

View File

@ -12,4 +12,7 @@ LeftAndMain:
['TranslatableCMSMainExtension']
HtmlEditorField_Toolbar:
extensions:
['TranslatableEditorToolbarExtension']
['TranslatableEditorToolbarExtension']
DataQuery:
extensions:
['Translatable']

View File

@ -15,7 +15,7 @@
* The extension is automatically enabled for SiteTree and SiteConfig records,
* if they can be found. Add the following to your config.yml in order to
* register a custom class:
*
*
* <code>
* MyClass:
* extensions:
@ -153,6 +153,8 @@
*/
class Translatable extends DataExtension implements PermissionProvider {
const QUERY_LOCALE_FILTER_ENABLED = 'Translatable.LocaleFilterEnabled';
/**
* The 'default' language.
* @var string
@ -551,7 +553,7 @@ class Translatable extends DataExtension implements PermissionProvider {
*
* Use {@link disable_locale_filter()} to temporarily disable this "auto-filtering".
*/
function augmentSQL(SQLQuery &$query) {
function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
// If the record is saved (and not a singleton), and has a locale,
// limit the current call to its locale. This fixes a lot of problems
// with other extensions like Versioned
@ -566,6 +568,8 @@ class Translatable extends DataExtension implements PermissionProvider {
$locale
// unless the filter has been temporarily disabled
&& self::locale_filter_enabled()
// or it was disabled when the DataQuery was created
&& $dataQuery->getQueryParam(self::QUERY_LOCALE_FILTER_ENABLED)
// DataObject::get_by_id() should work independently of language
&& !$query->filtersOnID()
// the query contains this table
@ -580,6 +584,11 @@ class Translatable extends DataExtension implements PermissionProvider {
$query->addWhere($qry);
}
}
function augmentDataQueryCreation(SQLQuery &$sqlQuery, DataQuery &$dataQuery) {
$enabled = self::locale_filter_enabled();
$dataQuery->setQueryParam(self::QUERY_LOCALE_FILTER_ENABLED, $enabled);
}
/**
* Create <table>_translation database table to enable
@ -1020,7 +1029,7 @@ class Translatable extends DataExtension implements PermissionProvider {
function updateSettingsFields(&$fields) {
$this->addTranslatableFields($fields);
}
public function updateRelativeLink(&$base, &$action) {
// Prevent home pages for non-default locales having their urlsegments
// reduced to the site root.
@ -1706,11 +1715,11 @@ class Translatable extends DataExtension implements PermissionProvider {
$IDFilter = ($this->owner->ID) ? "AND \"SiteTree\".\"ID\" <> {$this->owner->ID}" : null;
$parentFilter = null;
if($this->owner->ParentID) {
$parentFilter = " AND \"SiteTree\".\"ParentID\" = {$this->owner->ParentID}";
} else {
$parentFilter = ' AND "SiteTree"."ParentID" = 0';
}
if($this->owner->ParentID) {
$parentFilter = " AND \"SiteTree\".\"ParentID\" = {$this->owner->ParentID}";
} else {
$parentFilter = ' AND "SiteTree"."ParentID" = 0';
}
$existingPage = SiteTree::get()
// disable get_one cache, as this otherwise may pick up results from when locale_filter was on

View File

@ -40,6 +40,44 @@ class TranslatableTest extends FunctionalTest {
parent::tearDown();
}
function testLocaleFilteringEnabledAndDisabled() {
$this->assertTrue(Translatable::locale_filter_enabled());
// get our base page to use for testing
$origPage = $this->objFromFixture('Page', 'testpage_en');
$origPage->MenuTitle = 'unique-key-used-in-my-query';
$origPage->write();
$origPage->publish('Stage', 'Live');
// create a translation of it so that we can see if translations are filtered
$translatedPage = $origPage->createTranslation('de_DE');
$translatedPage->MenuTitle = $origPage->MenuTitle;
$translatedPage->write();
$translatedPage->publish('Stage', 'Live');
$where = sprintf("\"MenuTitle\" = '%s'", Convert::raw2sql($origPage->MenuTitle));
// make sure that our query was filtered
$this->assertEquals(1, Page::get()->where($where)->count());
// test no filtering with disabled locale filter
Translatable::disable_locale_filter();
$this->assertEquals(2, Page::get()->where($where)->count());
Translatable::enable_locale_filter();
// make sure that our query was filtered after re-enabling the filter
$this->assertEquals(1, Page::get()->where($where)->count());
// test effectiveness of disabling locale filter with 3.x delayed querying
// see https://github.com/silverstripe/silverstripe-translatable/issues/113
Translatable::disable_locale_filter();
// create the DataList while the locale filter is disabled
$dataList = Page::get()->where($where);
Translatable::enable_locale_filter();
// but don't use it until later - after the filter is re-enabled
$this->assertEquals(2, $dataList->count());
}
function testLocaleGetParamRedirectsToTranslation() {
$origPage = $this->objFromFixture('Page', 'testpage_en');