Automated updates

The Coder Upgrade module provides a powerful, automated solution to assist developers wishing to upgrade a module for changes in the Drupal core API (or the API provided by any contributed module into Drupal 7. For an example of this, click here.) This tool relies on the Grammar Parser library to upgrade a module's code files. In addition, Coder Upgrade allows upgrade routines to be written using regular expressions. The latter type of routines are not emphasized due to the concerns with false positives (i.e. code incorrectly identified as needing change).

For updating Drupal 7 module code into Drupal 8, see the Drupal Module Upgrader, a separate project.

The Grammar Parser turns a string of code into an object-based structure that allows for precise manipulation in a programmatic fashion. This eliminates the need to rely on opportunistic regular expressions that can generate false positives and find/change things not intended.

The Grammar Parser is the new parsing engine for the API module which generates the documentation elements displayed on the Drupal API site. The Grammar Parser can parse interfaces and classes, which have become more popular in D7 (e.g. database layer and views).

The Coder Upgrade and Grammar Parser duo can also be used to:

  • Update Drupal core code files for core API changes. Just as Coder Upgrade can be used to update contributed modules, an upgrade routine could be added to update core files programmatically instead of manually. The changes to the permissions array structure in hook_perm (now hook_permissions) is a good example. Coder Upgrade will also generate the necessary patch file to post on the project issue.
  • Review code files for security issues.

See also Coder Module: Easily Port Modules to Drupal 7, DrupalCon video on this topic.

Examples: Beginner difficulty

Example 1: Rename a function

Examples: Changing your Custom API

There is a phrase among developers of "eat your own dog food." This phrase means that as you develop a tool, it is a good practice to use

Examples: Intermediate difficulty

There is a strong correlation between the degree of difficulty involved with a change and the usefulness of printing the associated grammar

Writing an upgrade routine: Introduction

Guide maintainers

solotandem's picture