Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SilverStripe Auckland Meetup - Maxime on upgrading to SS4

66 views

Published on

SilverStripe Developer Maxime Rainville discusses upgrading to SilverStripe 4 at our Auckland Meetup. Check the full presentation video here: https://vimeo.com/280482609

Published in: Technology
  • Be the first to comment

  • Be the first to like this

SilverStripe Auckland Meetup - Maxime on upgrading to SS4

  1. 1. Maxime Rainville ● Been using SilverStripe since 2014. ● Senior Developer on the SilverStripe Open Sourcerers team since April. ● https://github.com/maxime-rainville Who is this person?
  2. 2. Upgrading from SilverStripe 3 to SilverStripe 4
  3. 3. Agenda Upgrading from SilverStripe 3 to SilverStripe 4 ● Step 0 - Prerequisites ● Step 1 - Upgrade your dependencies ● Step 2 - Update your environment configuration ● Step 3 - Namespacing your project ● Step 4 - Use namespaced classes ● Step 5 - Using SilverStripe 4 API ● Step 6 - Update your entry point ● Step 7 - Update project structure ● Step 8 - Switch to public web-root ● Step 9 - Fix hardcoded paths for static assets ● Step 10 - First run!!!
  4. 4. Upgrading from SilverStripe 3 to SilverStripe 4 Step 0 - Prerequisites
  5. 5. ● Don’t do this on the live server. ● Install composer. ● Install the SilverStripe upgrader composer global require silverstripe/upgrader Getting ready Step 0 - Prerequisites
  6. 6. ● Manual vs automated upgrade ● All in one command upgrade-code all --recipe-core-constraint=4.1 -- namespace="AppWeb" --psr4 About the upgrader Step 0 - Prerequisites
  7. 7. Upgrading from SilverStripe 3 to SilverStripe 4 Step 1 - Upgrade your dependencies
  8. 8. ● upgrade-code recompose --recipe-core-constraint=4.1 -- write ● Tries to find equivalent SilverStripe 4 dependencies. ● Tries to upgrade you to use recipes. The automated way Step 1 - Upgrade your dependencies
  9. 9. ● Switch to using recipes. ● Replace silverstripe/cms with silverstripe/recipe-cms. ● Replace silverstripe/framework with silverstripe/recipe-core ● Find SilverStripe 4 compatible versions of your modules. The manual way Step 1 - Upgrade your dependencies
  10. 10. ● Set minimum stability to “dev”. ● Look up the module on GitHub. ● Handling module that have not been upgraded. ● Remove. ● Fork. ● Integrate. Resolving conflicts Step 1 - Upgrade your dependencies
  11. 11. Upgrading from SilverStripe 3 to SilverStripe 4 Step 2 - Update your environment configuration
  12. 12. ● upgrade-code environment --write ● Be careful with conditional logic. The automated way Step 2 - Update your environment configuration
  13. 13. _ss_environment.php <?php // Environment define('SS_ENVIRONMENT_TYPE', 'dev'); define('SS_DEFAULT_ADMIN_USERNAME', 'admin'); define('SS_DEFAULT_ADMIN_PASSWORD', 'password'); $_FILE_TO_URL_MAPPING[__DIR__] = 'http://localhost'; // Database define('SS_DATABASE_CHOOSE_NAME', true); define('SS_DATABASE_CLASS', 'MySQLDatabase'); define('SS_DATABASE_USERNAME', 'root'); define('SS_DATABASE_PASSWORD', ''); define('SS_DATABASE_SERVER', '127.0.0.1'); The manual way Step 2 - Update your environment configuration .env ## Environment SS_ENVIRONMENT_TYPE="dev" SS_DEFAULT_ADMIN_USERNAME="admin" SS_DEFAULT_ADMIN_PASSWORD="password" SS_BASE_URL="http://localhost/" ## Database SS_DATABASE_CHOOSE_NAME="true" SS_DATABASE_CLASS="MySQLDatabase" SS_DATABASE_USERNAME="root" SS_DATABASE_PASSWORD="" SS_DATABASE_SERVER="127.0.0.1"
  14. 14. ● Clean up mysite/_config.php ● Remove $database and $databaseConfig ● Remove conf/ConfigureFromEnv.php ● Use SilverStripeCoreEnvironment::setEnv() if you need conditional logic. ● Update .gitignore ● Create .env.sample ● Delete legacy _ss_environment.php file Finalising things Step 2 - Update your environment configuration
  15. 15. Upgrading from SilverStripe 3 to SilverStripe 4 Step 3 - Namespacing your project
  16. 16. ● upgrade-code add-namespace "AppWeb" ./mysite/code -- recursive --write ● Use --psr4 if you want to use PSR-4 ● What’s up with .upgrade.yml? The automated way Step 3 - Namespacing your project
  17. 17. ● Put a namespace statement at the top of each file. The manual way Step 3 - Namespacing your project <?php class ExplosiveTennisBall extends DataObject { // ... } <?php namespace AppWebProducts; use AppWebProductService; class ExplosiveTennisBall extends DataObject { // ... }
  18. 18. ● Add these lines to your composer.json file { // ... "autoload": { "psr-4": { "AppWeb": "mysite/code", "AppSubModule": "sub-module/code" } }, "autoload-dev": { "psr-4": { "AppWebTests": "mysite/tests" } }, // ... } Enabling PSR-4 autoloading Step 3 - Namespacing your project
  19. 19. Upgrading from SilverStripe 3 to SilverStripe 4 Step 4 - Use namespaced classes
  20. 20. ● upgrade-code upgrade ./mysite/ --write ● Reads class equivalence from .upgrade.yml ● Updates PHP code, YML config files and YML language files The automated way Step 4 - Use namespaced classes
  21. 21. <?php namespace AppWebProducts; class ExplosiveTennisBall extends DataObject { private static $has_one = [ 'Thumbnail' => 'Image' ]; public function getShippingCost() { return Injector::inst('ProductService') ->calculateCost($this); } } The manual way - PHP Step 4 - Use namespaced classes <?php namespace AppWebProducts; use SilverStripeORMDataObject; use SilverStripeAssetsImage; use AppWebProductService; class ExplosiveTennisBall extends DataObject { private static $has_one = [ 'Thumbnail' => Image::class ]; public function getShippingCost() { return Injector::inst(ProductService::class) ->calculateCost($this); } }
  22. 22. Injector: ProductService: properties: RoadRunnerSpeed: 99999999 CoyoteSpeed: 1 BlogPost: extensions: - HasOneExplosiveTennisBallExtension Email: admin_email: no-reply@example.com The manual way - YML config Step 4 - Use namespaced classes SilverStripeCoreInjectorInjector: AppWebProductService: properties: RoadRunnerSpeed: 99999999 CoyoteSpeed: 1 SilverStripeBlogModelBlogPost: extensions: - AppWebHasOneExplosiveTennisBallExtension SilverStripeControlEmailEmail: admin_email: no-reply@example.com
  23. 23. en: Member: SINGULARNAME: Coyote RoadRunner: SALUTATION: Beep Beep The manual way - YML language Step 4 - Use namespaced classes en: SilverStripeSecurityMember: SINGULARNAME: Coyote AppWebRoadRunner: SALUTATION: Beep Beep
  24. 24. ● Calls to _t() need to be updated. _t( CMSMain::class .'.ACCESS', "Access to ''{title}'' section", ['title' => 'Products'] ); ● Template needs to use fully qualified name of classes. <%t SilverStripeSecurityMember.SINGULARNAME 'Member' %> Updating translations Step 4 - Use namespaced classes
  25. 25. Upgrading from SilverStripe 3 to SilverStripe 4 Step 5 - Using SilverStripe 4 API
  26. 26. ● upgrade-code inspect ./mysite/ --write ● Reads API changes from each module’s .upgrade.yml file ● Beware crashes. The automated way Step 5 - Using SilverStripe 4 API
  27. 27. The manual way Step 5 - Using SilverStripe 4 API
  28. 28. Upgrading from SilverStripe 3 to SilverStripe 4 Step 6 - Update your entry point
  29. 29. ● index.php is now the entry point ● Copy files from silverstripe/recipe-core ● index.php ● .htaccess ● web.config The manual way Step 6 - Update your entry point
  30. 30. Upgrading from SilverStripe 3 to SilverStripe 4 Step 7 - Update project structure
  31. 31. ● upgrade-code reoganise --write ● Rename mysite to app ● Rename app/code to app/src ● Other manual steps ● Update composer.json if using PSR-4 ● Add these lines to your YML config SilverStripeCoreManifestModuleManifest: project: app The automated and manual way Step 7 - Update project structure
  32. 32. Upgrading from SilverStripe 3 to SilverStripe 4 Step 8 - Switch to public web-root
  33. 33. ● upgrade-code webroot --write ● Create a public folder ● Move files/folders in public ● assets ● index.php ● .htaccess and web.config ● Delete resources ● composer vendor-expose The automated and manual way Step 8 - Switch to public web-root
  34. 34. Upgrading from SilverStripe 3 to SilverStripe 4 Step 9 - Fix hardcoded paths for static assets
  35. 35. ● Exposing assets in composer.json { // … "extra": { "expose": [ "app/scripts", "app/images", "app/css" ] }, // … } ● composer vendor- expose The manual way Step 9 - Fix hardcoded paths for static assets ● Update Requirements calls Requirements::script('silverstripe/blog: js/main.bundle.js'); ● Update ModelAdmin and Page icons private static $icon = 'app: images/icon.png'; ● Update references in templates <img src="$ModulePath(app)/images/coyote.png" /> <% require css("app: css/styles.css") %>
  36. 36. Upgrading from SilverStripe 3 to SilverStripe 4 Step 10 - First run!!!
  37. 37. ● vendor/bin/sake dev/build ● vendor/bin/sake dev/tasks/MigrateFileTask The manual way Step 10 - First run!!!
  38. 38. Theoretical next step Step 10 - First run!!!
  39. 39. Probable next step Step 10 - First run!!!
  40. 40. Thank you! https://docs.silverstripe.org/en/4/upgrading https://github.com/silverstripe/silverstripe-upgrader

×