wellington meetup silverstripe 4 upgrading presentation (feb 2017)

26
Upgrading to SilverStripe 4 Projects, modules, tips and tricks 22 Feb 2017 • Robbie Averill

Upload: robbie-averill

Post on 03-Mar-2017

68 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Upgrading to SilverStripe 4Projects, modules, tips and tricks

22 Feb 2017 • Robbie Averill

Page 2: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

● PHP namespaces

● Bootstrap 4 in the CMS

● ReactJS

● Public API changes - lots of them

● Quirks! E.g. dotenv

● PSR-2 style guidelines

● Controller naming: Page_Controller -> PageController

● Config API is changing! Still to come...

SilverStripe 4 Changes(That generally affect you: a developer)

Page 3: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

SilverStripe Roadmap

Page 4: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

● Modules: now!

● Projects: now/soon (beta)

When should I upgrade?

Page 5: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Run a quick upgradability check!

Disclaimer: It's a QUICK check!gist.github.com/robbieaverill/cad0260414226645b404c45b2059fdf9

Page 6: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Projects: fork and fix!

Get involved with the open source community. It might be a quick job, you might be surprised!

Suggested tools:

● Hub: hub.github.com● silverstripe/upgrader:

github.com/silverstripe/silverstripe-upgrader

Page 7: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Composer

● List your forks as VCS repositories until merged

● Projects: "minimum-stability": "dev" and "prefer-stable": true

● "extra": { "branch-alias": { "dev-master": "2.x-dev" }}

Page 8: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Modules: Get into it, now!

● The more SilverStripe 4 compatible a module is, the more likely you and other developers will use it, and recommend it for use to those you work for

● Upgrading a module will give you a much deeper understanding of how it works, especially if you didn't write it!

Page 9: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Namespacing and PSR-4People asked, SilverStripe responded. Please welcome namespacing to the stage!

With it comes PSR-4 compatible autoloading, which makes sense.

● Use "git mv" to configure your module for PSR-4 compatibility without losing history

● Add and implement namespaces with the upgrader

● Do these in separate commits/PRs from PSR-2 linting

Page 10: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Adding namespaces with upgrader

Page 11: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Implementing namespaces

Page 12: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Implementing PSR-4

Tip: don't forget to run composer validate!

Page 13: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

The framework has switched to using dotenv for configuration. It's worth

mentioning now, because you won't be able to "build" without it.

File: .env

Hello dotenv, bye bye _ss_environment

Page 14: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

In SilverStripe the suggested PHP style guideline to follow is PSR-2 (which includes PSR-1).

This means spaces for indentation, brackets on new lines, sensible spacing, etc.

You can automate most of the required changes using PHP CodeSniffer and the PSR2 standard it ships with.

More info: php-fig.org/psr/psr-2

PHP style guidelines: PSR-1/2

Page 15: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

● In 3.x: Page_Controller

● In 4.x: PageController

Don't forget to add this to the .upgrade.yml mapping!

Move the controller to its own file now - PSR-2 requires each class to be on its own.

Naming controllers

Page 16: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

In SilverStripe 3.x you can mostly put templates wherever you feel like.

With 4.x things are stricter:

● Default: fully qualified template location matches class namespace

● ->renderWith('TemplateName'): still looks in root of "templates"

SilverStripe encourages the use of fully qualified template locations where possible, even if you don't have to move them when you upgrade!

Naming templates

Page 17: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

DataObject table names

By default a namespaced DataObject will use a backslash in the table name,

matching the namespace. To replace this, or to provide backwards compatibility,

specify private static $table_name = 'MyTableName'; on your

DataObject.

BuildTask segments

BuildTasks will use a fully qualified class name (sanitised) for the segment. You

may see dev/tasks/Robbie-MeetupDemo-Task-DoesNothingTask. To

make this simpler, add private static $segment =

'DoesNothingTask'; to your task.

Small gotchas

Page 18: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

● "ClassName" value remapping

When working with existing data (i.e. upgrade, not fresh install), if your

DataObject has a ClassName field, it will need to become fully qualified in

legacy date. Use YAML config - see the CMS module for an example.

● php-intl extension is now required

● Upgrader bugs:

Still in development too - it will occasionally replace things it shouldn't.

Doesn't update YAML configuration files (yet). This also applies to YAML

fixtures in unit test - they must be fully qualified!

More gotchas...

Page 19: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Handling files, or whatever

● Asset abstraction provides secure assets out of the

box as well as versioning and coupling with

campaigns

● The upload process changes

● The image manipulation public API has changed a

bit

● Take a look at the changelog

Page 20: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Mono-Logging!

SS_Log is still available, but it's deprecated - you shouldn't

and probably can't use it.

Instead, use Monolog (PSR-3 compatible) via the Injector:

More: github.com/Seldaek/monolog

Page 21: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Cascading themes!

As very cool feature - now you can have multiple themes

that inherit from each other! This includes looking up

resources by their base filename across any registered

theme.

Page 22: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Deprecation and removals● All deprecation and removals are documented in the

4.0.0 changelog, which is kept up to date

● If your code complains, check for updates

● Some important backends have been updated or

replaced entirely: logging, config (shortly), localisation,

cache (soon)

Page 23: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Considerations

● Entwine being phased out in favour of ReactJS (CMS)

● Use Webpack or similar for bundling assets

● REST API modules replaced with core GraphQL

● RestfulService gone, use guzzlehttp/guzzle or similar

● Use the injector wherever you can

Page 24: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

General tips

● Good unit test coverage to start with will help a lot

● Start namespacing early if you can (SS3 can handle it, to an extent)

● Use the upgrader tool

● Bump your branch alias

● Release alpha tags for your upgraded code

Page 25: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Useful links

● docs.silverstripe.org/en/4/changelogs/4.0.0

● github.com/silverstripe/silverstripe-upgrader

● github.com/robbieaverill/meetup-demo

● hub.github.com

● gist.github.com/robbieaverill/cad0260414226645b404c45b2059fdf9

Page 26: Wellington meetup SilverStripe 4 upgrading presentation (Feb 2017)

Thank you!Twitter: @robbieaverill

Email: [email protected]

22nd Feb 2017 • Robbie Averill