Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Increase your Productivity with TYPO3 Console

Increase your Productivity with TYPO3 Console

I'll show a set of TYPO3 Commands, that helps you automate TYPO3 installation and deployment and therefore let's you achieve more with doing less, hence increase your productivity.

Helmut Hummel

July 14, 2017
Tweet

More Decks by Helmut Hummel

Other Decks in Technology

Transcript

  1. Increase your Productivity
    with TYPO3 Console
    Helmut Hummel
    Increase your Productivity
    with TYPO3 Console
    Inspiring people to
    share

    View Slide

  2. TYPO3 Console
    TYPO3 Console in a nutshell
    2

    View Slide

  3. TYPO3 Console
    TYPO3 Console
    TYPO3 Console in a nutshell
    • Command line interface for TYPO3
    • Built for humans
    • Usable by robots
    • Powerful
    • Extendable
    • Comes as composer package with CLI binary
    3

    View Slide

  4. TYPO3 Console
    TYPO3 Console installation
    4
    $ composer require helhum/typo3-console

    View Slide

  5. TYPO3 Console
    TYPO3 Console usage
    5
    $ vendor/bin/typo3cms help

    View Slide

  6. TYPO3 Console extension
    (Also installable as extension)
    6

    View Slide

  7. 7
    @helhum

    View Slide

  8. How to become more productive?
    8

    View Slide

  9. 9

    View Slide

  10. Productivity
    Productivity is expressed as the
    ratio of output to inputs
    https://en.wikipedia.org/wiki/Productivity
    10

    View Slide

  11. Increase Productivity
    Increase output
    11

    View Slide

  12. Increase Productivity
    Lower input
    12

    View Slide

  13. 13

    View Slide

  14. 14

    View Slide

  15. Development Cycle
    15

    View Slide

  16. Development Cycle
    16
    Change
    code
    Commit to
    VCS
    Deploy

    View Slide

  17. 17

    View Slide

  18. Set up dev system
    18

    View Slide

  19. Set up dev system
    Log in to live server
    19

    View Slide

  20. Set up dev system
    Package files
    20

    View Slide

  21. Set up dev system
    Package database
    21

    View Slide

  22. Set up dev system
    Download and unpack
    22

    View Slide

  23. Set up dev system
    Adapt configuration
    23

    View Slide

  24. Set up dev system
    Connect VCS
    24

    View Slide

  25. Change code
    25

    View Slide

  26. Push to VCS
    26

    View Slide

  27. Deploy
    27

    View Slide

  28. Deploy
    Log in to live server
    28

    View Slide

  29. Deploy
    Verify changes
    29

    View Slide

  30. Deploy
    Merge changes
    30

    View Slide

  31. Deploy
    Upload code
    31

    View Slide

  32. Deploy
    …in the right order
    32

    View Slide

  33. Deploy
    Log into install tool
    33

    View Slide

  34. Deploy
    Update database schema
    34

    View Slide

  35. Deploy
    Create missing directories
    35

    View Slide

  36. Deploy
    Activate extensions
    36

    View Slide

  37. Deploy
    Configure extensions
    37

    View Slide

  38. Deploy
    Flush caches
    38

    View Slide

  39. Deploy
    Restart webserver
    39

    View Slide

  40. Deploy
    Pray
    40

    View Slide

  41. Deploy
    Hotfix on live server
    41

    View Slide

  42. Deploy
    Apply hotfix to VCS
    42

    View Slide

  43. 43

    View Slide

  44. 44

    View Slide

  45. 45

    View Slide

  46. TYPO3 Console
    Set up dev system
    46

    View Slide

  47. TYPO3 Console
    Set up dev system
    47
    $ composer create-project vendor/project
    $ project/vendor/bin/typo3cms server:run

    View Slide

  48. TYPO3 Console
    Change code
    48

    View Slide

  49. TYPO3 Console
    Change code
    49
    $ composer require vendor/ext

    View Slide

  50. TYPO3 Console
    Commit to VCS
    50

    View Slide

  51. TYPO3 Console
    Commit to VCS
    51
    $ git commit -a
    $ git push

    View Slide

  52. TYPO3 Console
    Deploy
    52

    View Slide

  53. TYPO3 Console
    Deploy
    53
    $ surf deploy

    View Slide

  54. TYPO3 Console
    Complete development cycle
    54

    View Slide

  55. TYPO3 Console
    Complete development cycle
    55
    $ # Set up dev system
    $ composer create-project vendor/project
    $ # Change code
    $ composer require vendor/ext
    $ # Commit to VCS
    $ git commit -a
    $ # Deploy
    $ surf deploy

    View Slide

  56. TYPO3 Console
    Demo
    56

    View Slide

  57. TYPO3 Console
    Meanwhile…
    57

    View Slide

  58. TYPO3 Console
    …little helpers
    58

    View Slide

  59. TYPO3 Console
    Composer binaries in PATH
    59

    View Slide

  60. TYPO3 Console
    Composer binaries in PATH
    60
    $ export PATH="$PATH:./vendor/bin"

    View Slide

  61. TYPO3 Console
    Little helpers
    Composer binaries in PATH
    • Mind the potential security impact
    • Malicious composer packages might ship „ls“
    • Make sure composer binaries can’t override global binaries
    61

    View Slide

  62. TYPO3 Console
    Command autocompletion
    62

    View Slide

  63. TYPO3 Console
    Command autocompletion
    63
    $ eval "$(typo3cms autocomplete)"

    View Slide

  64. TYPO3 Console
    Do less, achieve more
    64

    View Slide

  65. TYPO3 Console
    Building blocks
    65

    View Slide

  66. TYPO3 Console
    Building blocks
    66

    View Slide

  67. TYPO3 Console
    Building blocks
    Composer
    • Builds a project package from set of requirements
    • Provides several extension points to execute additional code
    • Better performance with optimized class loading
    67

    View Slide

  68. TYPO3 Console
    PackageStates.php
    68

    View Slide

  69. TYPO3 Console
    Building blocks
    PackageStates.php
    • Tracks which extensions should be active
    • Is changed when (de-)activating extensions in EM
    • Bad for automated processes
    • What to do for automated deployment?
    • typo3/cli_dispatch.phpsh extbase extension:install

    • typo3cms extension:activate
    • Merge conflicts during a project lifetime
    69

    View Slide

  70. TYPO3 Console
    PackageStates.php
    70
    $ typo3cms install:generatepackagestates

    View Slide

  71. TYPO3 Console
    Building blocks
    Generate PackageStates.php
    • Add PackageStates.php to your .gitignore
    • typo3cms install:generatepackagestates
    • Everything in typo3conf/ext/ is marked active
    • Every required TYPO3 core extension is marked active
    • Why would you install code, but mark it as inactive?
    • Each line of code is one line with potential security issues
    or bugs
    71

    View Slide

  72. TYPO3 Console
    PackageStates.php
    72
    "require": {
    "typo3/cms-belog": "^8.7",
    "typo3/cms-beuser": "^8.7",
    "typo3/cms-context-help": "^8.7",
    "typo3/cms-fluid-styled-content": "^8.7",
    "typo3/cms-felogin": "^8.7",
    "typo3/cms-filelist": "^8.7",
    "typo3/cms-impexp": "^8.7",
    "typo3/cms-info": "^8.7",
    "typo3/cms-info-pagetsconfig": "^8.7",
    "typo3/cms-lowlevel": "^8.7",
    "typo3/cms-reports": "^8.7",
    "typo3/cms-rte-ckeditor": "^8.7",
    "typo3/cms-setup": "^8.7",
    "typo3/cms-tstemplate": "^8.7",
    "typo3/cms-viewpage": "^8.7"
    }

    View Slide

  73. TYPO3 Console
    PackageStates.php
    73
    "scripts": {
    "package-states": [
    "typo3cms install:generatepackagestates"
    ],
    "post-autoload-dump": [
    "@package-states"
    ]
    }

    View Slide

  74. 74

    View Slide

  75. TYPO3 Console
    Create TYPO3 folder structure
    75

    View Slide

  76. TYPO3 Console
    Create TYPO3 folder structure
    76
    $ typo3cms install:fixfolderstructure

    View Slide

  77. TYPO3 Console
    Building blocks
    Create TYPO3 folder structure
    • Creates all required folders
    • Including ones defined by (active) extensions
    • Perfect for creating typo3temp/**
    • Makes it possible to start with empty typo3temp/ for every deployment
    • (Reconsider clean start when using gifbuilder or similar)
    • (Maybe reconsider using gifbuilder)
    77

    View Slide

  78. TYPO3 Console
    Create TYPO3 folder structure
    78
    "scripts": {
    "package-states": [
    "typo3cms install:generatepackagestates"
    ],
    "folder-structure": [
    "typo3cms install:fixfolderstructure"
    ],
    "post-autoload-dump": [
    "@package-states",
    "@folder-structure"
    ]
    }

    View Slide

  79. 79

    View Slide

  80. TYPO3 Console
    Set up active extensions
    80

    View Slide

  81. TYPO3 Console
    Set up active extensions
    81
    $ typo3cms extension:setupactive

    View Slide

  82. TYPO3 Console
    Building blocks
    Set up active extensions
    • One command
    • Same as activating every single extension in EM manually
    • Idempotent
    • Executing once or multiple times leads to same result
    • Fast
    • Does not flush caches
    • Groups DB schema update
    82

    View Slide

  83. TYPO3 Console
    Set up TYPO3 from CLI
    83

    View Slide

  84. TYPO3 Console
    Set up TYPO3
    84
    $ typo3cms install:setup

    View Slide

  85. TYPO3 Console
    Building blocks
    Set up TYPO3 from CLI
    • Completely automatable
    • No more manual clicking in web installer
    • Sets up active extensions as last step
    • Ideal for dev setup
    • Local LAMP
    • Vagrant
    • Docker
    85

    View Slide

  86. But…
    86

    View Slide

  87. TYPO3 Console
    Building blocks
    Set up TYPO3 from CLI
    • NOT idempotent
    • Needs LocalConfiguration.php to be absent
    • Writes its own LocalConfiguration.php during setup
    • Only useful for INITIAL deployment
    87

    View Slide

  88. TYPO3 Console
    Update database schema
    88

    View Slide

  89. TYPO3 Console
    Update database schema
    89
    $ typo3cms database:updateschema

    View Slide

  90. TYPO3 Console
    Building blocks
    Update database schema
    • Can be used WITHOUT any tables in database
    • By default not destructive*
    • Adds tables and fields
    • Changes tables and fields
    • * Be careful with type and size changes
    • Works great for initial and subsequent deployments
    90

    View Slide

  91. TYPO3 Console
    Combining DB schema update and
    extension setup
    91

    View Slide

  92. TYPO3 Console
    Building blocks
    92
    $ typo3cms install:extensionsetupifpossible

    View Slide

  93. TYPO3 Console
    Building blocks
    Extension setup if possible
    • Combines DB schema update with extension setup
    • typo3cms database:updateschema
    • typo3cms cache:fush
    • typo3cms extension:setup
    • Gracefully exits in failure case
    • Ideal as composer post autoload dump script
    93

    View Slide

  94. TYPO3 Console
    Extension setup if possible
    94
    "scripts": {
    "package-states": [
    "typo3cms install:generatepackagestates"
    ],
    "folder-structure": [
    "typo3cms install:fixfolderstructure"
    ],
    "ext-setup": [
    "typo3cms install:extensionsetupifpossible"
    ],
    "post-autoload-dump": [
    "@package-states",
    "@folder-structure",
    "@ext-setup"
    ]
    }

    View Slide

  95. TYPO3 Console
    Building blocks
    95
    $ composer create-project \
    helhum/minimal-typo3-distribution \
    new-project ^7

    View Slide

  96. TYPO3 Console
    Building blocks
    96
    $ composer create-project \
    helhum/minimal-typo3-distribution \
    new-project ^8

    View Slide

  97. 97

    View Slide

  98. TYPO3 Console
    Create your own commands
    98

    View Slide

  99. TYPO3 Console
    Building blocks
    Create your own commands
    • As composer package
    • As TYPO3 extension
    • Configuration/Console/Commands.php
    • Classes/Command/YourCommandController.php
    • Every public function with suffix „Command“
    • https://github.com/TYPO3-Console/php-server-command
    • PHPDoc extracted as help text
    99

    View Slide

  100. TYPO3 Console
    Create your own commands
    100

    View Slide

  101. TYPO3 Console
    Create your own commands
    101

    View Slide

  102. TYPO3 Console
    Bonus
    102

    View Slide

  103. TYPO3 Console
    Upgrade TYPO3 from CLI
    103

    View Slide

  104. TYPO3 Console
    Upgrade TYPO3 from CLI
    104
    $ composer require typo3/cms ^8.7
    $ typo3cms upgrade:all

    View Slide

  105. TYPO3 Console
    Bonus
    Upgrade TYPO3 from CLI
    • Fast
    • Unattended
    • Idempotent
    • Can be executed for every deployment
    • Write your own upgrade wizards for migrations
    • Prepare everything locally and lean back during deploy
    105

    View Slide

  106. 106

    View Slide

  107. TYPO3 Console
    One more thing…
    107

    View Slide

  108. TYPO3 Console
    helhum/typo3-distribution
    108

    View Slide

  109. TYPO3 Console
    One more thing
    helhum/typo3-distribution
    • Multiple environment support
    • One or more configuration files depending on context
    • Merged in LocalConfiguration.php for production
    • Reasonable default dev and prod config
    • Yaml or PHP file support
    • Extension configuration as plain arrays
    • Overridable with environment specific config
    109

    View Slide

  110. TYPO3 Console
    One more thing
    helhum/typo3-distribution
    • Auto setup on composer install
    • Fully automatable for defined environments
    • Prompts for user input for setup if required/ wanted
    • Ready for dev and deploy
    • Easy to customize
    110

    View Slide

  111. 111

    View Slide

  112. 112

    View Slide

  113. TYPO3 Console
    Questions?
    113

    View Slide

  114. TYPO3 Console
    Workshop at coding night
    114

    View Slide

  115. TYPO3 Console
    Thank you!
    @helhum
    http://insight.helhum.io
    [email protected]
    115

    View Slide