[SOLVED] How To Upgrade Contributed Module Of Drupal 7 To Drupal 8 Using Drupal Module Upgrader

June 01, 2018 - 15:57

For upgrading any of your contributed Drupal 7 modules, you just need to follow the few steps shown below. First of all you have to make sure that Drush is installed. If not installed, follow the steps from here.

Now install a fresh Drupal 8 in your system using Drush commands or directly download from Drupal.org. You must be aware that Drupal 8 has changed its structure from Drupal 7 in configuration, theming, folder structure etc. So now we can find the contributed and custom modules in the modules folder in the root directory. It is also better to create a contrib folder in modules folder for both DMU (Drupal Module Upgrader) and your Drupal 7 module for migration.

And now let's have a look at DMU. Drupal Module Upgrader is a script that scans and upgrades the source code of your Drupal 7 module, it also generates a list of new fixes with information links to Drupal.org as an upgrade-info.html file that will be available in your upgrading module directory. Also note that, this DMU scripts will run using Drush and Composer.

Now get into your Drupal 8's contrib folder using the terminal (For example: cd public_html/d8/modules/contrib) and follow the steps :

  • Download DMU using the drush command drush dl drupalmoduleupgrader. For example :
    xx@xx:~/public_html/d8/modules/contrib$ drush dl drupalmoduleupgrader
    Project drupalmoduleupgrader (8.x-1.2) downloaded to                 [success]
    /home/xx/public_html/d8/modules/contrib/drupalmoduleupgrader.
  • Now get into your Drupal module upgrader folder and install Composer. For example:
    xx@xx:~/public_html/d8/modules/contrib$ cd drupalmoduleupgrader/
    xx@xx:~/public_html/d8/modules/contrib/drupalmoduleupgrader$ composer install
    Loading composer repositories with package information
    Installing dependencies (including require-dev) from lock file
      - Installing cebe/markdown (dev-master f89dc1d)
        Cloning f89dc1da1fc6823f0286d6cad736a642efd0f59e
    
      - Installing phpdocumentor/reflection-docblock (2.0.4)
        Loading from cache
    
      - Installing grom358/pharborist (dev-master 0db9e51)
        Cloning 0db9e51299a80e95b06857ed1809f59bbbab1af6
    
      - Installing symfony/filesystem (2.6.x-dev 823c035)
        Cloning 823c035b1a5c13a4924e324d016eb07e70f94735
    
      - Installing symfony/finder (2.6.x-dev 203a10f)
        Cloning 203a10f928ae30176deeba33512999233181dd28
    
      - Installing mikey179/vfsstream (v1.5.0)
        Loading from cache
    
      - Installing phpunit/php-token-stream (1.4.8)
        Loading from cache
    
      - Installing symfony/yaml (v2.7.4)
        Loading from cache
    
      - Installing sebastian/version (1.0.6)
        Loading from cache
    
      - Installing sebastian/global-state (1.0.0)
        Loading from cache
    
      - Installing sebastian/recursion-context (1.0.1)
        Loading from cache
    
      - Installing sebastian/exporter (1.2.1)
        Loading from cache
    
      - Installing sebastian/environment (1.3.2)
        Loading from cache
    
      - Installing sebastian/diff (1.3.0)
        Loading from cache
    
      - Installing sebastian/comparator (1.2.0)
        Loading from cache
    
      - Installing phpunit/php-text-template (1.2.1)
        Loading from cache
    
      - Installing doctrine/instantiator (1.0.5)
        Loading from cache
    
      - Installing phpunit/phpunit-mock-objects (2.3.7)
        Loading from cache
    
      - Installing phpunit/php-timer (1.0.7)
        Loading from cache
    
      - Installing phpunit/php-file-iterator (1.4.1)
        Loading from cache
    
      - Installing phpunit/php-code-coverage (2.2.3)
        Loading from cache
    
      - Installing phpspec/prophecy (v1.5.0)
        Loading from cache
    
      - Installing phpunit/phpunit (4.8.9)
        Loading from cache
    
    phpdocumentor/reflection-docblock suggests installing dflydev/markdown (~1.0)
    phpdocumentor/reflection-docblock suggests installing erusev/parsedown (~1.0)
    sebastian/global-state suggests installing ext-uopz (*)
    phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1)
    phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
    Generating autoload files
  • Get back to your contrib folder and clone your Drupal 7 module to it. You can find its cloning commands from its Drupal.org version control page. Here for example: commerce_techprocess is used as Drupal 7 module for migration.
    xx@xx:~/public_html/d8/modules/contrib/drupalmoduleupgrader$ cd ..
    xx@xx:~/public_html/d8/modules/contrib$ git clone --branch 7.x-1.x http://git.drupal.org/project/commerce_techprocess.git
    Cloning into 'commerce_techprocess'...
    remote: Counting objects: 23, done.
    remote: Compressing objects: 100% (22/22), done.
    remote: Total 23 (delta 6), reused 0 (delta 0)
    Unpacking objects: 100% (23/23), done.
    Checking connectivity... done.
  • Get back to your site root directory and enable drupalmoduleupgrader.
    xx@xx:~/public_html/d8$ drush en drupalmoduleupgrader
    The following extensions will be enabled: drupalmoduleupgrader
    Do you really want to continue? (y/n): y
    drupalmoduleupgrader was enabled successfully.                       [ok]
    
  • Now start analysing your module using the upgrader, it will list out the fixes and generate an html info file.
    xx@xx:~/public_html/d8$ drush dmu-analyze commerce_techprocess --path=modules/contrib/commerce_techprocess/
    Indexing...done.
    Generated a report at                                                [success]
    modules/contrib/commerce_techprocess//upgrade-info.html
  • After all, you can upgrade your module using the command,
    xx@xx:~/public_html/d8$ drush dmu-upgrade commerce_techprocess --path=modules/contrib/commerce_techprocess/
    Indexing...done.

    It will automatically create some of the Drupal 8 supporting files (for example: .info.yml, .routing.yml etc) and update some of your module codes, and other main functionalities will be commented and provide a @FIXME comment along with it. So that you can easily findout the necessary fixes that the DMU can't do.

Now enable your module and fix the issues in Drupal 8 syntax. Also note that your .info or other Drupal 7 supporting files will be there which can be easily removed after fix(if it has no use) and completely upgrading your module codes. Now test your code.

Happy Coding!

Get Drupal updates straight to your inbox

To prevent automated spam submissions leave this field empty.

Post your comments / questions