mirror of
https://github.com/silverstripe/silverstripe-translatable
synced 2024-10-22 11:05:59 +02:00
Merge pull request #186 from tractorcow/pulls/3.2-compat-on-2.x
Compatibility with 3.2
This commit is contained in:
commit
c741a0bdf9
@ -8,6 +8,11 @@ php:
|
|||||||
env:
|
env:
|
||||||
- DB=MYSQL CORE_RELEASE=3.1
|
- DB=MYSQL CORE_RELEASE=3.1
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- php: 5.4
|
||||||
|
env: DB=MYSQL CORE_RELEASE=3
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- pear -q install --onlyreqdeps pear/PHP_CodeSniffer
|
- pear -q install --onlyreqdeps pear/PHP_CodeSniffer
|
||||||
- phpenv rehash
|
- phpenv rehash
|
||||||
@ -16,5 +21,5 @@ before_script:
|
|||||||
- cd ~/builds/ss
|
- cd ~/builds/ss
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- phpunit translatable/tests/
|
- vendor/bin/phpunit translatable/tests/
|
||||||
- phpcs --encoding=utf-8 --tab-width=4 --standard=translatable/tests/phpcs -np translatable
|
- phpcs --encoding=utf-8 --tab-width=4 --standard=translatable/tests/phpcs -np translatable
|
||||||
|
@ -14,7 +14,6 @@ Note: This module was originally part of the SilverStripe CMS 2.x codebase.
|
|||||||
## Requirements ##
|
## Requirements ##
|
||||||
|
|
||||||
* SilverStripe Framework 3.1+ and CMS 3.1+
|
* SilverStripe Framework 3.1+ and CMS 3.1+
|
||||||
* Note: For SilverStripe 2.3/2.4 support, please use the core built-in version (no module required)
|
|
||||||
|
|
||||||
## Maintainers ##
|
## Maintainers ##
|
||||||
|
|
||||||
|
@ -582,6 +582,30 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a given SQLQuery filters on the Locale field
|
||||||
|
*
|
||||||
|
* @param SQLQuery $query
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected function filtersOnLocale($query) {
|
||||||
|
foreach($query->getWhere() as $condition) {
|
||||||
|
// Compat for 3.1/3.2 where syntax
|
||||||
|
if(is_array($condition)) {
|
||||||
|
// In >=3.2 each $condition is a single length array('condition' => array('params'))
|
||||||
|
reset($condition);
|
||||||
|
$condition = key($condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
// >=3.2 allows conditions to be expressed as evaluatable objects
|
||||||
|
if(interface_exists('SQLConditionGroup') && ($condition instanceof SQLConditionGroup)) {
|
||||||
|
$condition = $condition->conditionSQL($params);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(preg_match('/("|\'|`)Locale("|\'|`)/', $condition)) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes any SELECT query thats not filtering on an ID
|
* Changes any SELECT query thats not filtering on an ID
|
||||||
* to limit by the current language defined in {@link get_current_locale()}.
|
* to limit by the current language defined in {@link get_current_locale()}.
|
||||||
@ -590,7 +614,7 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* Use {@link disable_locale_filter()} to temporarily disable this "auto-filtering".
|
* Use {@link disable_locale_filter()} to temporarily disable this "auto-filtering".
|
||||||
*/
|
*/
|
||||||
function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
|
public function augmentSQL(SQLQuery &$query, DataQuery $dataQuery = null) {
|
||||||
// If the record is saved (and not a singleton), and has a locale,
|
// 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
|
// limit the current call to its locale. This fixes a lot of problems
|
||||||
// with other extensions like Versioned
|
// with other extensions like Versioned
|
||||||
@ -614,7 +638,7 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
&& array_search($baseTable, array_keys($query->getFrom())) !== false
|
&& array_search($baseTable, array_keys($query->getFrom())) !== false
|
||||||
// or we're already filtering by Lang (either from an earlier augmentSQL()
|
// or we're already filtering by Lang (either from an earlier augmentSQL()
|
||||||
// call or through custom SQL filters)
|
// call or through custom SQL filters)
|
||||||
&& !preg_match('/("|\'|`)Locale("|\'|`)/', implode(' ', $query->getWhere()))
|
&& !$this->filtersOnLocale($query)
|
||||||
//&& !$query->filtersOnFK()
|
//&& !$query->filtersOnFK()
|
||||||
) {
|
) {
|
||||||
$qry = sprintf('"%s"."Locale" = \'%s\'', $baseTable, Convert::raw2sql($locale));
|
$qry = sprintf('"%s"."Locale" = \'%s\'', $baseTable, Convert::raw2sql($locale));
|
||||||
@ -1435,6 +1459,7 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
|
|
||||||
$newTranslation->ID = 0;
|
$newTranslation->ID = 0;
|
||||||
$newTranslation->Locale = $locale;
|
$newTranslation->Locale = $locale;
|
||||||
|
$newTranslation->Version = 0;
|
||||||
|
|
||||||
$originalPage = $this->getTranslation(self::default_locale());
|
$originalPage = $this->getTranslation(self::default_locale());
|
||||||
if ($originalPage) {
|
if ($originalPage) {
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
"require-dev": {
|
"require-dev": {
|
||||||
"silverstripe/postgresql": "*",
|
"silverstripe/postgresql": "*",
|
||||||
"silverstripe/sqlite3": "*",
|
"silverstripe/sqlite3": "*",
|
||||||
"silverstripe/mssql": "*"
|
"silverstripe/mssql": "*",
|
||||||
|
"phpunit/PHPUnit": "~3.7@stable"
|
||||||
},
|
},
|
||||||
"extra":
|
"extra":
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user