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

SilverStripe 4 Compatibility #289

Merged
merged 55 commits into from
Aug 29, 2017

Conversation

Cheddam
Copy link
Member

@Cheddam Cheddam commented Aug 28, 2017

This giant PR, in short, makes Subsites function on SilverStripe 4 Beta 2.

It does not include:

  • Passing tests
  • Design updates to match SS4
  • An in-depth review of the architecture (this is very lift-and-shift, and I'm sure there are a lot of improvements in SS4 we're not yet taking advantage of)

Shout out to @wernerkrauss for completing a significant portion of the work!

wernerkrauss and others added 30 commits May 24, 2017 12:03
(cherry picked from commit 2f99e51)
- moving all phpunit tests into tests/php
- moving all extensions from _config.php into config.yml and removing obsolete _config.php
- moving GridFieldSubsiteDetailForm_ItemRequest into own file

(cherry picked from commit ee02828)
call extension directly in test, as Versioned now is also applied to File
and has this method
Updating config and i18n calls
Copy link
Contributor

@robbieaverill robbieaverill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Epic work @Cheddam @wernerkrauss and everyone else involved! I've left a few comments, most are things that occur a lot throughout this pull request, so should be updated in bulk. If we can get this pull request to a point where the tests are at least running on Travis (not necessarily passing) then we can look at merging this as a basis then work incrementally in smaller, more manageable pull requests from then on.

@@ -4,6 +4,8 @@ language: php

sudo: false

sudo: false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create a new Travis config to replace this, see silverstripe/silverstripe-taxonomy#36 for an example

@@ -0,0 +1,42 @@
<?php

namespace SilverStripe\Subsites\Admin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the file path would match the namespace for PSR-4, e.g. Admin rather than admin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for this, you can address this using git mv to ensure the case sensitivity is emitted to the log.

I'd not even mind if you renamed 'code' to 'src' (new standard) as a means of addressing this, but the important thing is that it's PSR-4. :)

Copy link
Contributor

@robbieaverill robbieaverill Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if you move code to src then you can also capitalise the subfolders at the same time. Otherwise you'll need to do something like git mv admin blah && git mv blah Admin since it won't pick up the case change otherwise (at least on macOS anyway)

{
$form = parent::getEditForm($id, $fields);

$grid = $form->Fields()->dataFieldByName(Subsite::class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is likely a mistake - dataFieldByName expects a field name string which wouldn't be a FQCN. This could have been an upgrader tool error, but should be replaced with 'Subsite'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fault of the upgrader;

You can put /** @skipUpgrade */ on either the line before this statement, or in the getEditForm PHPDoc to suppress the upgrader making this subsitution.

* Relax the access permissions, so anyone who has access to any CMS subsite can access this controller.
* @param null $member
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to type hint the expected type as well as, rather than the optional fallback e.g. @param Member|null $member

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to this.

@@ -8,11 +14,11 @@ public function controllerAugmentInit()
{
if ($subsite = Subsite::currentSubsite()) {
if ($theme = $subsite->Theme) {
SSViewer::set_theme($theme);
SSViewer::set_themes([$theme, SSViewer::DEFAULT_THEME]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting situation, where in SS3 we would explicitly set the theme to a subsite's theme, but in SS4 we can use cascading/partial themes, so maybe we should just add_themes instead of setting it to subsite theme + default. What do you think @Cheddam?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this into getThemes() in the Subsite class, and user code can customise / modify this with an extension.

E.g.

public function getThemes()
{
	$themes = [
		$this->Theme,
		SSViewer::DEFAULT_THEME,
	];
	// Allow usercode to customise themes for this subsite
	$this->extend('updateThemes', $themes);
	return $themes;
}
// ...
SSViewer::set_themes($subsite->getThemes());

@@ -136,24 +157,26 @@ public function testSubsiteVirtualPagesArentInappropriatelyPublished()
$this->assertFalse($vp->IsModifiedOnStage);
}

/**
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above, switch doPublish for publishRecursive or publishSingle

{
Config::inst()->update('StaticPublisher', 'disable_realtime', true);
Config::modify()->set('StaticPublisher', 'disable_realtime', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably needs a todo for static publisher namespacing

@@ -0,0 +1,87 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests/php/SubsitesVirtualPageTest.yml will need to have namespacing added to it

* Check that valid domains are accepted
*
* @dataProvider validDomains
* @param $domain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing type

{
$field = new WildcardDomainField('DomainField');
$this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain wildcard");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just combine these three tests into one - testDomains with a dataprovider that also provides the expectation and message

@@ -0,0 +1,42 @@
<?php

namespace SilverStripe\Subsites\Admin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for this, you can address this using git mv to ensure the case sensitivity is emitted to the log.

I'd not even mind if you renamed 'code' to 'src' (new standard) as a means of addressing this, but the important thing is that it's PSR-4. :)

/**
* Admin interface to manage and create {@link Subsite} instances.
*
* @package subsites
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With namespaces, we prefer to dump all @package and @subpackage tags.

{
$form = parent::getEditForm($id, $fields);

$grid = $form->Fields()->dataFieldByName(Subsite::class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fault of the upgrader;

You can put /** @skipUpgrade */ on either the line before this statement, or in the getEditForm PHPDoc to suppress the upgrader making this subsitution.

* Relax the access permissions, so anyone who has access to any CMS subsite can access this controller.
* @param null $member
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to this.

@@ -51,6 +67,7 @@ public function getResponseNegotiator()
*/
public function SubsiteList()
{
return $this->renderWith('SubsiteList');
return $this->renderWith('Includes/SubsiteList');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use [ 'type' => 'Includes', 'SubsiteList'] instead of baking the variant into the path.

I would also suggest you consider namespacing templates. E.g. templates\SilverStripe\Subsites\Controller\Includes\SubsiteXHRController_subsitelist.ss. Then you could refer to the template using the below:

return $this->renderWith(['type' => 'Includes', self::class . '_subsitelist']);

///////////////////////////////////////////////////////////////////////////////////////////
// Querying

/**
* @param arary $params
* @return void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to explicitly declare voids.

"silverstripe/cms": "^4.0@dev"
"silverstripe/framework": "~4.0",
"silverstripe/cms": "~4.0",
"silverstripe/asset-admin": "~1.0.0"
},
"require-dev": {
"phpunit/PHPUnit": "~4.8@stable"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core phpunit has been upgraded to ^5.7 please. :)

"silverstripe/cms": "^4.0@dev"
"silverstripe/framework": "~4.0",
"silverstripe/cms": "~4.0",
"silverstripe/asset-admin": "~1.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer semver ^1.0 vs ~1.0.0. Note that ^1.0 and ~1.0 are equivalent, but the former is preferred.

"silverstripe/cms": "^4.0@dev"
"silverstripe/framework": "~4.0",
"silverstripe/cms": "~4.0",
"silverstripe/asset-admin": "~1.0.0"
},
"require-dev": {
"phpunit/PHPUnit": "~4.8@stable"
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out ^4@dev doesn't actually have any effect; ^4 is fine.

"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"license": "BSD-3-Clause"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was license removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's duplicated, towards the top of the file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah true.

@tractorcow
Copy link
Contributor

@Cheddam I can merge, but before then, could you please get a .travis.yml minimal fix that will at least start the tests running? That way I can get a better picture of what's left to fix subsequent to this PR.

PHP needs to be changed from 5.5 to 5.6 and/or 7.x, and don't use travis support module anymore.

@tractorcow
Copy link
Contributor

I'll just merge this so we can start PRing to get this faster.

@tractorcow tractorcow merged commit 60725e7 into silverstripe:master Aug 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants