Skip to content

Commit

Permalink
Merge pull request #779 from creative-commoners/pulls/master/cms5-com…
Browse files Browse the repository at this point in the history
…patibility

DEP Silverstripe CMS 5 compatibility
  • Loading branch information
Maxime Rainville authored Feb 21, 2023
2 parents c042104 + 1af962f commit 91b834f
Show file tree
Hide file tree
Showing 18 changed files with 4,764 additions and 3,972 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10
18
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ inherit: true

build:
environment:
php: 8.0
php: 8.1
nodes:
analysis:
tests:
Expand Down
4 changes: 0 additions & 4 deletions .upgrade.yml

This file was deleted.

5 changes: 0 additions & 5 deletions _config.php

This file was deleted.

6 changes: 6 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
2 changes: 1 addition & 1 deletion client/dist/js/fluent.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/fluent.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
"issues": "http://github.com/tractorcow-farm/silverstripe-fluent/issues"
},
"require": {
"php": "^7.1 || ^8",
"silverstripe/vendor-plugin": "^1.6",
"silverstripe/framework": "^4.7",
"silverstripe/admin": "^1",
"silverstripe/versioned": "^1.7",
"symbiote/silverstripe-gridfieldextensions": "^3.1",
"php": "^8.1",
"silverstripe/vendor-plugin": "^2",
"silverstripe/framework": "^5",
"silverstripe/admin": "^2",
"silverstripe/versioned": "^2",
"symbiote/silverstripe-gridfieldextensions": "^4",
"ext-json": "*"
},
"suggest": {
"silverstripe/cms": "Localise pages"
},
"require-dev": {
"silverstripe/recipe-testing": "^2"
"silverstripe/recipe-testing": "^3"
},
"extra": {
"branch-alias": {
Expand Down
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "tractorcow-fluent",
"version": "4.0.0",
"description": "Fluent localisation module for SilverStrip CMS",
"engines": {
"node": "^10.x"
"node": "^18.x"
},
"scripts": {
"build": "NODE_ENV=production webpack -p --bail --progress",
"build": "yarn && yarn lint && rm -rf client/dist/* && NODE_ENV=production webpack --mode production --bail --progress",
"dev": "NODE_ENV=development webpack --progress",
"watch": "NODE_ENV=development webpack --watch --progress",
"css": "WEBPACK_CHILD=css npm run build",
"lint": "eslint client/src && sass-lint -v"
Expand All @@ -27,12 +27,19 @@
},
"homepage": "https://github.com/tractorcow-farm/silverstripe-fluent",
"devDependencies": {
"@silverstripe/eslint-config": "^0.0.5",
"@silverstripe/webpack-config": "^0.4.1"
"@silverstripe/eslint-config": "^1.0.0-alpha6",
"@silverstripe/webpack-config": "^2.0.0-alpha6",
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0"
},
"dependencies": {
"jquery": "^3.5.0",
"query-string": "^5.0.0",
"query-string": "^8.1.0",
"url": "^0.11.0"
}
},
"resolutions": {
"colors": "1.4.0"
},
"browserslist": [
"defaults"
]
}
25 changes: 0 additions & 25 deletions src/Extension/FluentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Extension;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\GridField\GridField_ActionMenuItem;
Expand Down Expand Up @@ -1045,19 +1044,6 @@ public function getLocaleInstances(): array
return $locales;
}

/**
* Return the linking mode for the current locale and object
*
* @param string $locale
* @return string
* @deprecated 5.0 use LocaleInformation() instead
*/
public function getLinkingMode($locale)
{
Deprecation::notice('5.0', 'Use LocaleInformation instead');
return $this->LocaleInformation($locale)->getLinkingMode();
}

/**
* Determine the baseurl within a specified $locale.
*
Expand All @@ -1073,17 +1059,6 @@ public function BaseURLForLocale($locale)
return $localeObject->getBaseURL();
}

/**
* @param string $locale
* @return string
* @deprecated Use LocaleInformation instead
*/
public function LocaleLink($locale)
{
Deprecation::notice('5.0', 'Use LocaleInformation instead');
return $this->LocaleInformation($locale)->getLink();
}

/**
* Ensure has_one cache is segmented by locale
*
Expand Down
2 changes: 1 addition & 1 deletion src/Extension/FluentVersionedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ protected function getCurrentVersionNumbers(string $class, string $stage, ?array
$results = DB::prepared_query($query, $params);
$versions = [];

while ($result = $results->next()) {
foreach ($results as $result) {
$id = (int) $result['LatestID'];
$version = (int) $result['LatestVersion'];

Expand Down
3 changes: 0 additions & 3 deletions src/Forms/LocaleToggleColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class LocaleToggleColumn implements GridField_SaveHandler, GridField_ColumnProvi
{
use Injectable;

/**
* @skipUpgrade
*/
const COLUMN_NAME = 'VisibleToggle';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Model/CachableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function getCached()
$dataList = DataObject::get(static::class);
$sort = Config::inst()->get(static::class, 'default_sort');
if ($sort) {
$dataList = $dataList->sort($sort);
$dataList = $dataList->orderBy($sort);
}

// If DB isn't ready, silently return empty array to prevent bootstrapping issues
Expand Down
15 changes: 10 additions & 5 deletions tests/php/Extension/FluentExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testLocalisedMixSorting()

// Sort by the NonLocalisedSort field first then the LocalisedField second both in ascending order
// so the result will be opposite if the order of the columns is not maintained
$objects=MixedLocalisedSortObject::get()->sort(
$objects=MixedLocalisedSortObject::get()->orderBy(
'"FluentExtensionTest_MixedLocalisedSortObject"."LocalizedSort", '.
'"FluentExtensionTest_MixedLocalisedSortObject"."NonLocalizedSort", '.
'"FluentExtensionTest_MixedLocalisedSortObject"."Title"'
Expand Down Expand Up @@ -289,12 +289,16 @@ public function testLocalisedCopyClassNameChange(): void
* @param string[] $expected
* @group exclude-from-travis
*/
public function testLocalisedFieldsCanBeSorted($locale, array $sortArgs, $expected)
public function testLocalisedFieldsCanBeSorted($locale, array $sortArgs, $expected, $useOrderBy = false)
{
FluentState::singleton()->withState(function (FluentState $newState) use ($locale, $sortArgs, $expected) {
FluentState::singleton()->withState(function (FluentState $newState) use ($locale, $sortArgs, $expected, $useOrderBy) {
$newState->setLocale($locale);

$records = LocalisedParent::get()->sort(...$sortArgs);
if ($useOrderBy) {
$records = LocalisedParent::get()->orderBy(...$sortArgs);
} else {
$records = LocalisedParent::get()->sort(...$sortArgs);
}
$titles = $records->column('Title');
$this->assertEquals($expected, $titles);
});
Expand Down Expand Up @@ -411,6 +415,7 @@ public function sortRecordProvider()
'en_US',
['CONCAT((SELECT COUNT(*) FROM "FluentExtensionTest_LocalisedParent_Localised"), "FluentExtensionTest_LocalisedParent"."ID")'],
['A record', 'Read about things', 'Go for a run'],
true,
]
];
}
Expand All @@ -431,7 +436,7 @@ protected function hasLocalisedRecord(DataObject $record, $locale)
'"Locale"' => $locale,
])
->execute()
->first();
->record();

return !empty($result);
}
Expand Down
7 changes: 4 additions & 3 deletions tests/php/Extension/FluentSiteTreeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Page;
use SilverStripe\CMS\Forms\SiteTreeURLSegmentField;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
Expand Down Expand Up @@ -74,8 +75,8 @@ public function testGetLocaleInformation()
$this->assertEquals('English (New Zealand)', $result->getTitle());
$this->assertEquals('English', $result->getLanguageNative());
$this->assertEquals('en', $result->getLanguage());
$this->assertEquals('/newzealand/a-page/', $result->getLink());
$this->assertEquals('http://mocked/newzealand/a-page/', $result->getAbsoluteLink());
$this->assertEquals(Controller::normaliseTrailingSlash('/newzealand/a-page/'), $result->getLink());
$this->assertEquals(Controller::normaliseTrailingSlash('http://mocked/newzealand/a-page/'), $result->getAbsoluteLink());
$this->assertEquals('link', $result->getLinkingMode());
$this->assertEquals('newzealand', $result->getURLSegment());
});
Expand Down Expand Up @@ -179,7 +180,7 @@ function (FluentState $newState) use ($domain, $locale, $prefixDisabled, $pageNa

/** @var Page|FluentSiteTreeExtension $page */
$page = $this->objFromFixture(Page::class, $pageName);
$this->assertEquals($url, $page->Link());
$this->assertEquals(Controller::normaliseTrailingSlash($url), $page->Link());
}
);
}
Expand Down
Loading

0 comments on commit 91b834f

Please sign in to comment.