[Drupal] Migrating Drupal 7 modules to Drupal 8 using Drupal module upgrader
BY abhai.sasidharan
5 years ago
0 comments comment

After the launch of Drupal 8, there is now an incessant need for converting existing Drupal 7 modules to Drupal 8 compatible versions. Due to the substantial changes in Drupal 8 from its previous versions, developers find it hard and time consuming to migrate from D7 to D8. This is mainly because Drupal 8 is object oriented and much closer to an MVC (Model View Controller) architecture, Drupal is no longer a PAC (Presentation Abstraction Control) architecture framework, Drupal follows the PSR-4 folder structure in compatible with symfony component which Drupal 8 uses.

A lot of this difficulty can actually be overcome by a module called Drupal module upgrader. This module automates the migrate process of Drupal 7 modules to Drupal 8. This article elaborates on how this is accomplished and troubleshooting the Drupal module upgrader(dmu) module. DMU is still in its development stages but it does a pretty good job upgrading completely simple modules.

This module requires that you have Drush installed. This itself is quite a confusing process as Drush 7 is the only compatible Drush version with Drupal 8 and to install Drush 7, composer is required. So for the purposes of this article, I assume, Drush 7 is installed in the system. If it isn't please do : Installing drush.

Installing the module

The module can be installed like in Drupal 7 itself. Download and extract into the modules folder. In Drupal 8 the modules folder is not in sites/all/ but in $lt;Drupal root>/modules/ folder.

There is a simpler method to download and enable the module since there is composer involved. Composer is an application-level dependency manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries. DMU uses composer to install and update the module.

  • Go to the command line in your Linux system and navigate to the Drupal installation folder. Type "drush status" to see whether both installation and/or Drush 7 is working. If it is working, type "drush dl drupalmoduleupgrader --select --all". This will list out all the available versions of Drupalmoduleupgrader as you can see in the image. Choose the supported one as the development one will have lots of bugs. This will download the module in the modules folder. screenshot1.png
  • Before enabling the module, first navigate into the Drupalmoduleupgrader folder in your command line and type "composer install". This will install dmu and download all of its components as you can see in the image. Here, many of you may get a similar error message like in the yellow highlighted area in the image. Not to worry, this may only be a problem later which I will explain then. screenshot2.png
  • After this, return to the Drupal root on command line and enable the module by typing "drush en drupalmoduleupgrader". You will get a message saying module enabled.

Using the module

  • DMU provides some commands to analyze and upgrade the modules. For the purpose of this example, we will take the CCK(Content Construction Kit) module and see if we can upgrade it. If the Drupal 7 module is kept in the module folder then type "drush dmu-analyze cck", If it is kept in a sub folder then type "drush dmu-analyze module --path=<tDrupal/modules/path/to/module>". Type "drush help dmu-analyze" for more details. On successfull execution, a detailed description of the changes to be made with links to their changes will be saved as a html file in the root of the module.
  • To upgrade the module, we must run the command "drush dmu-upgrade cck" or "drush dmu-upgrade module --path=<Drupal/modules/path/to/module>". Some of you will get errors like the one shown in the image. This is because of the earlier errors that we ignored. To rectify this, we must navigate once more into the Drupalmoduleupgrader folder on our command line and type "composer update". This will solve the problem. Still if the error persists or the download of filesystem is getting timed out or failed, then you must go to the link here and download zip. Extract the same into the drupalmoduleupgrader/vendor/symfony/filesystem/component/ folder and rename it to Filesystem.screenshot3.png
  • Run the upgrade commands again. This will show indexing...done. Now if you look into the cck folder, you will see the yml info file and all the Drupal 8 necessary files.
  • Run "drush dmu-clean cck" to clean the module of all Drupal 7 files and go to extend in your Drupal site and you will see that the cck module has appeared in the list of modules. Enable and use it.

Workarounds to common errors

CCK is a simple module and therefore indexing it was easy and uncomplicated. There are a few workarounds to make indexing simpler for large modules.

  • Use the --only option in the dmu-analyze or dmu-upgrade command. Example, "drush dmu-upgrade cck --only=<HookMenu>"
  • Use the --path option to analyze or upgrade only one module in a project. Example, in the coder package there are three modules 'coder_sniffer', 'coder_review', 'coder_upgrade'. Here, we need only scan one of these modules with the command "drush dmu-analyze module --path=<Drupal/modules/coder/coder_review>".
  • Even after the dmu-upgrade has executed successfully, enabling your module can still throw off errors and/or give you a white screen death. This is mainly because the program while executing, skips call by references and minute changes like that. If you read your code after dmu-upgrade is done, you will see comment tags @FIXME. This is to indicate where the changes have to manually be done. Almost every change will be mentioned throughout the code and links to the corresponding change records are present in the html file generated by dmu-analyze.
  • Only run dmu-clean after the code is bug free and perfectly functional. Otherwise old code will be removed which had to be changed manually.
  • You can use the --backup option to create a backup of the module before upgrading or cleaning.

The Drupal Module Upgrader (DMU) module despite being in the development stages, saves developers a lot of time when upgrading modules to be compatible with Drupal 8. This module is introduced by Acquia, a software-as-a-service company providing products, services, and technical support for open-source web content management platform Drupal much like Zyxware technologies, who is a partner to Acquia.




on 01st January 2008 / by webmaster
We have added a few new modules to our site recently. Drupal Technical StumbleThis Leave a reply Your email address will not be published. Required fields are marked * Sean (not verified) access_time 10 Aug 2020 - 23:39 Hi there, I uploaded the files, enabled the modules to use SU, and now I see the link, but there is no icon... How can I fix this? Thanks, Sean webmaster access_time 10 Aug 2020 - 23:39 In reply to Icon doesn&#039;t show by Sean (not verified) What do you see when you view the source? Search for stumblethis_button and you should be able to see the code for the image and the URL. Then you should be able to troubleshoot from there. Juicy Couture Addict (not verified) access_time 10 Aug 2020 - 23:39 thanks for the post. would love to hear more of you. by the way, drupal's really popular nowadays as it has easy and fast features. you agree with me? thanks. Add new comment

on 16th January 2008 / by webmaster
Most webmasters do not realize this, but a lot of the content on lot of websites can be accessed from multiple URLs. A simple example would be where www.example.com and example.com leads to the same page. This is a fatal mistake in Search Engine Optimization and search engines penalize you for duplicate content. The correct configuration would be where the above two urls will lead you to the same page but example.com will redirect you to www.example.com with a 301 (Moved permanently) status which will not result in search engines penalizing the page. It is very easy to configure 301 redirects using Apache .htaccess file and the process is the same for a Drupal installation also. Drupal Technical Apache htaccess SEO Leave a reply Your email address will not be published. Required fields are marked * Anonymous (not verified) access_time 10 Aug 2020 - 23:39 Hello. I'm trying to make example.com show as www.example.com, and I'm running into difficulties. I'm on Apache 2.0 and using the following lines in my httpd.conf file: RewriteEngine on RewriteCond %{HTTP_HOST} ^xxxxxxxxxx\.com$ [NC] RewriteRule ^(.*)$ http://www.xxxxxxxxxx.com/$1 [L,R=301] When I go to http://xxxxxxxxxx.com, I get http://www.xxxxxxxxxx.com (as expected). However, when I go to http://xxxxxxxxxx.com/node/1 (it's a Drupal site), I get a 404 thrown and the URL changes to xxxxxxxxxx.com/var/www/drupal/node/1. Same thing with www.xxxxxxxxxx.com/node/1. Any suggestions? I want to run without Drupal's .htaccess file (instead incorporating these calls into my httpd.conf file). webmaster access_time 10 Aug 2020 - 23:39 In reply to Rewrite including filesystem path by Anonymous (not verified) I think the problem is with the base path which results in the redirection to /var/www/ part. The best approach I would think is to start with drupal htaccess and then strip out parts and move to httpd SNVC (not verified) access_time 10 Aug 2020 - 23:39 This is definitely a good guide. Thanks for this. wellyson access_time 10 Aug 2020 - 23:39 This is really nice and helpful. Add new comment

on 08th February 2008 / by webmaster
Attachment Size slashdotit.tar.gz 173.55 KB Similar to the StumbleThis module that we had created earlier we have created another bookmarking Drupal Technical Slashdotit Leave a reply Your email address will not be published. Required fields are marked * Shlomi Fish (not verified) access_time 10 Aug 2020 - 23:39 Hi! I'm interested in this module, but Drupal 6.2 complains that it's incompatible with it. Can you please update it or tell me how? Regards, Shlomi Fish shlomifish.org webmaster access_time 10 Aug 2020 - 23:39 In reply to Can you update it for Drupal-6.x? by Shlomi Fish (not verified) Sure we are working on this currently and will post an update soon. Also we will post this module on www.drupal.org as well Cheers Anoop John Team Zyxware Anonymous (not verified) access_time 10 Aug 2020 - 23:39 Hello! Nice Article very interesting, thanks Add new comment
Leave a reply
Your email address will not be published. Required fields are marked *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.