Merge pull request #186 from tractorcow/pulls/3.2-compat-on-2.x

Compatibility with 3.2
This commit is contained in:
Ingo Schommer 2015-02-23 21:57:32 +13:00
commit c741a0bdf9
4 changed files with 46 additions and 16 deletions

View File

@ -1,12 +1,17 @@
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
language: php
php:
php:
- 5.3
- 5.4
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:
- pear -q install --onlyreqdeps pear/PHP_CodeSniffer
@ -16,5 +21,5 @@ before_script:
- cd ~/builds/ss
script:
- phpunit translatable/tests/
- vendor/bin/phpunit translatable/tests/
- phpcs --encoding=utf-8 --tab-width=4 --standard=translatable/tests/phpcs -np translatable

View File

@ -14,7 +14,6 @@ Note: This module was originally part of the SilverStripe CMS 2.x codebase.
## Requirements ##
* 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 ##

View File

@ -582,6 +582,30 @@ class Translatable extends DataExtension implements PermissionProvider {
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
* 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".
*/
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,
// limit the current call to its locale. This fixes a lot of problems
// with other extensions like Versioned
@ -611,14 +635,14 @@ class Translatable extends DataExtension implements PermissionProvider {
&& !$query->filtersOnID()
// the query contains this table
// @todo Isn't this always the case?!
&& array_search($baseTable, array_keys($query->getFrom())) !== false
// or we're already filtering by Lang (either from an earlier augmentSQL()
&& array_search($baseTable, array_keys($query->getFrom())) !== false
// or we're already filtering by Lang (either from an earlier augmentSQL()
// call or through custom SQL filters)
&& !preg_match('/("|\'|`)Locale("|\'|`)/', implode(' ', $query->getWhere()))
&& !$this->filtersOnLocale($query)
//&& !$query->filtersOnFK()
) {
$qry = sprintf('"%s"."Locale" = \'%s\'', $baseTable, Convert::raw2sql($locale));
$query->addWhere($qry);
$query->addWhere($qry);
}
}
@ -1435,6 +1459,7 @@ class Translatable extends DataExtension implements PermissionProvider {
$newTranslation->ID = 0;
$newTranslation->Locale = $locale;
$newTranslation->Version = 0;
$originalPage = $this->getTranslation(self::default_locale());
if ($originalPage) {
@ -1447,7 +1472,7 @@ class Translatable extends DataExtension implements PermissionProvider {
if(Config::inst()->get('Translatable', 'enforce_global_unique_urls')) {
$newTranslation->URLSegment = $urlSegment . '-' . i18n::convert_rfc1766($locale);
}
// hacky way to set an existing translation group in onAfterWrite()
$translationGroupID = $this->getTranslationGroup();
$newTranslation->_TranslationGroupID = $translationGroupID ? $translationGroupID : $this->owner->ID;

View File

@ -13,15 +13,16 @@
}
],
"require":
{
"php": ">=5.3.2",
"silverstripe/framework": "~3.1",
"silverstripe/cms": "~3.1"
},
{
"php": ">=5.3.2",
"silverstripe/framework": "~3.1",
"silverstripe/cms": "~3.1"
},
"require-dev": {
"silverstripe/postgresql": "*",
"silverstripe/sqlite3": "*",
"silverstripe/mssql": "*"
"silverstripe/mssql": "*",
"phpunit/PHPUnit": "~3.7@stable"
},
"extra":
{