Articles


Drupal Module Upgrader to Drupal 7 to Drupal 8

Drupal Module Upgrader to Drupal 7 to Drupal 8



Posted byvarghese.t,25th Nov 2015

Drupal Module Upgrader is a script that scans the source of a Drupal 7 module, flags any code that requires updating to Drupal 8, points off to any relevant API change notices from https://www.drupal.org/list-changes/, and (where possible) will actually attempt to *convert* the Drupal 7 code automatically to the Drupal 8 version!

REQUIREMENTS

This project requires the following dependencies:

  • Composer (https://getcomposer.org)
  • Drush 7+ (https://github.com/drush-ops/drush)
  • Pharborist (https://github.com/grom358/pharborist)
  • Symfony Yaml Component (https://github.com/symfony/Yaml)

Note that most dependencies are automatically downloaded by Composer during installation.

 

INSTALLATION

  • Download and install Composer: https://getcomposer.org/doc/00-intro.md#system-requirements
  • Download and install the latest version of Drush:
    
       https://github.com/drush-ops/drush#installupdate---composer
       
  • Download and install the latest Drupal 8:
    
       git clone --branch 8.0.x http://git.drupal.org/project/drupal.git 8.x
       
  • Download the latest release of drupalmoduleupgrader to your Drupal 8 site’s /modules directory:
    
       drush dl drupalmoduleupgrader
     
  • Run `composer install` from the drupalmoduleupgrader directory:
    
       cd drupalmoduleupgrader
       composer install
    
    You should see output as it downloads various dependencies (pharborist, phpcs, yaml...)
  • Finally, enable the module:
    
       drush en drupalmoduleupgrader -y
    

TROUBLESHOOTING

git pull --rebase - Are you using the very latest drupalmoduleupgrader code (and dependencies' code)? From the drupalmoduleupgrader root directory: git pull --rebase composer update drush pm-uninstall drupalmoduleupgrader -y drush en drupalmoduleupgrader 

RUNNING TESTS

Drupal Module Upgrader uses Composer to install its dependencies inside the module folder. Since it operates as a standalone project this is perfectly fine. However if we want to run the tests we have to use a different strategy. Drupal core itself also uses Composer, and it manages its dependencies and namespaces inside the core/vendor/ folder. It is unaware of DMU's dependencies and the tests will fail.

We can use Composer Manager [1] to generate a new composer.json file in the root of the Drupal site. This will combine the dependencies of Drupal core and all contributed and custom projects.

  • Navigate to the root folder of your Drupal installation:
    
       cd /path/to/drupal/site/
    
  • Download Composer Manager:
    
       drush dl composer_manager
    
  • Initialize Composer Manager:
    
       php modules/composer_manager/scripts/init.php
    
  • Install the combined dependencies of Drupal core and modules:
    
       composer drupal-install
    
  • 4. Run the tests:
    
      ./vendor/bin/phpunit -c core --group=DMU