The first code sprint: Refactoring the TYPO3 Bootstrap

Categories: Development Created by Susanne Moog, Christian Kuhn, Oliver Hader, Helmut Hummel
From friday 15.6.2012 to 17.6.2012 a small team met in Hamburg for a code sprint session with the topic "Bootstrap refactoring for upcoming TYPO3 6.0".
The term "bootstrap" is nowadays often associated with a responsive web layout, however this sprint was not about the "Twitter CSS/JS Bootstrap", but all about the "TYPO3 Bootstrap" which in fact is the PHP code that is executed to load the configuration, extensions and set up a basic TYPO3 environment for different scopes (backend, frontend, command line). The current implementation basically separates different mechanisms for frontend and backend. Besides that, there are more specific aspects for the command line interface (CLI), the install tool and AJAX calls that extend the two basic scopes. Each of those (sub-) scopes have an own way to e.g. load configuration, extension settings, initialization of database objects and path handling, which makes it quite difficult to modify and handle the TYPO3 initialization phase for each of those scopes. Since automated test cases are just impossible currently, the chances are high that even tiny changes in this area break functionality.

Participants 

  • Oliver Hader
  • Helmut Hummel
  • Susanne Moog
  • Christian Kuhn

Location 

  • The office of e-net Consulting in Hamburg, Germany

General the goals

  • Reduce complexity of different scope initializations (can be tested, is understandable, is consistent)
  • Create discrete steps (initialization of configuration, extension settings and basic environments)
  • Allow transparent caching of configurations
  • Define strict meaning of "configuration"
  • Remove amount of different entry points

Statistics

  • More than 30 hours of coding and discussing in two and a half days
  • Consumed 8 pizza, 10 Club Mate, 29 beers, 8 Apples, 2 Snickers and 7 Bifi Rolls
  • Merged 22 issues related to the bootstrap and a hand full of others
  • Deleted 1112 lines in config_default.php and after that the empty file
  • Removed 9 entry points

 Achievements

  • The tasks that where tackled during the sprint can be seen in this umbrella issue: <link http: forge.typo3.org issues>forge.typo3.org/issues/38086
  • Created a list of current entry points to the TYPO3 core to get a better overview: <link http: forge.typo3.org projects typo3v4-bootstrap wiki list_of_entry_points>forge.typo3.org/projects/typo3v4-bootstrap/wiki/List_of_entry_points
  • To reduce the number of entry points 9 additional backend modules are now using the module dispatcher script. All default modules are now migrated.
  • Refactored the current bootstrap spaghetti code into small methods with proper naming for a better overview of what happens during bootstrap. This is also a foundation for an easier performance analysis through cleaner, more separate code.
  • Got rid of most code running in global scope.
  • To further reduce the number of entry points a method to dispatch sub-submodules (for example the dropdown in info) is needed. Step one was to transform the backend module menu to an object hierarchy.
  • Kickstarted the rebuilding of the info module based on Extbase.

Next steps

  • Automated tests for bootstrap methods
  • Further disentangle install tool and backend bootstrap code
  • Build method groups for functionality that belongs together and move bootstrap code around
  • Finish module menu integration, review class concept, build API for extbase modules (sub-sub)
  • Finish rewrite of the "info" module to extbase
  • Review the order of the execution of the current bootstrap methods, group them in a few main public methods
  • Further decrease the number of entry points to at most a hand full
  • Write a document that clearly defines what code and what configuration is allowed in which extension file (ext_tables, ext_localconf)
  • Get the global configuration (TYPO3_CONF_VARS) which is set in localconf.php and ext_localconf.php as an array which can be merged with the default configuration. The final configuration could then be exported with var_export to a file.
  • Side project: make an array out of the extension list (instead of comma separated list)
  • Move the loading (and caching) of extensions and extension files from t3lib_extmgm to the bootstrap class to have full control what is cached at what time

Working mode

During the sprint we made use of many of the nifty tools the typo3.org infrastructure provides. We decided to work directly in git master and to push and immediatly review small, separated patches to the current development head. This way our work was very transparent, so other contributers could step in and support us with testing and reviews. The workflow turned out to be very productive, we now have most of the code merged with master and did not end up with one big piece of code rotting in some other branch like the Incubator - thus even if the same parts have been changed multiple times, this incremental working mode had the side-effect of alwalys having a working TYPO3. This workflow even enabled us to fix several other bugs we stumbled upon and merge right away. This may serve as an example for other teams and code sprints as it proved to be a productive and also fun way to work.

Thank you to:

Our sponsors 

  • <link http: www.e-net.info>e-net Consulting GmbH & Co. KG for the location and food
  • <link http: etobi.de>Tobias Liebig for "<link http: twitter.com etobi status>a pizza and a beer"
  • <link http: www.neusta-sd.de>neusta software development for the day off for Susanne
  • <link http: www.naw.info>naw.info GmbH for the day off for Helmut
  • TYPO3 Association for accommodation and travel costs

Our remote reviewers 

  • Philipp Gampe
  • Wouter Wolters
  • Oliver Klee