Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Convert modules from 6.x to 7.x

5,321 views

Published on

Now that Drupal 7 is upon us, I would like to explain the resources available to convert existing 6.x modules to 7.x.
I will summarize the major changes in the API, and where to get further information. I will also present the coder upgrade module which eases this process. Finally I will present a brief example of how to apply this process in an existing module.

Published in: Technology
  • Be the first to comment

Convert modules from 6.x to 7.x

  1. 1. Converting modules from 6.x to 7.x João Ventura (jcnventura) [email_address]
  2. 2. About me <ul><li>'print' module mantainer
  3. 3. Using Drupal since 2004
  4. 4. 1 patch in Drupal 7 core :)
  5. 5. 100% drupal developer for >1yr now
  6. 6. Now working at Trellon </li></ul>
  7. 7. Thanks <ul><li>Drupal Ireland for organizing this </li><ul><li>First Drupalcamp! </li></ul><li>Trellon for sponsoring my trip
  8. 8. Stella for inviting me to propose a session
  9. 9. Guiness </li><ul><li>For my headache.. :) </li></ul></ul>
  10. 10. API changes <ul><li>82 API changes to take into account when converting a module from Drupal 5 to Drupal 6
  11. 11. 19 + 8 + 8 + 20 + 10 + 7 + 22 + 25 + 41 + 24 + 15 + 15 + 6 + 13 + 5 + 1 – 5 = 234 API changes </li></ul>
  12. 12. Database API - Select // Drupal 6 $result = db_query(&quot;SELECT nid, title FROM {node} WHERE uid = %d AND type = '%s'&quot;, 5, 'page'); // Drupal 7 $result = db_query(&quot;SELECT nid, title FROM {node} WHERE uid = :uid AND type = :type&quot;, array( ':uid' => 5, ':type' => 'page', ));
  13. 13. Database API – Results // Drupal 6 while ($record = db_fetch_object($result)) { // Do stuff with $record, which is an object } // Drupal 7 foreach ($result as $record) { // Do stuff with $record, which is an object }
  14. 14. Database API - Insert // Drupal 6 db_query(&quot;INSERT INTO {mytable} (intvar, stringvar, floatvar) VALUES (%d, '%s', %f)&quot;, 5, 'hello world', 3.14); $id = db_last_insert_id(); // Drupal 7 $id = db_insert('mytable') ->fields(array( 'intvar' => 5, 'stringvar' => 'hello world', 'floatvar' => 3.14, )) ->execute();
  15. 15. Database API - Update // Drupal 6 db_query(&quot;UPDATE {node} SET title='%s', status=%d WHERE uid=%d&quot;, 'hello world', 1, 5); // Drupal 7 db_update('node') ->fields(array('title' => 'hello world', 'status' => 1)) ->condition('uid', 5) ->execute();
  16. 16. Database API - Delete // Drupal 6 db_query(&quot;DELETE FROM {node} WHERE uid=%d AND created < %d&quot;, 5, REQUEST_TIME - 3600); // Drupal 7 db_delete('node') ->condition('uid', 5) ->condition('created', REQUEST_TIME - 3600, '<') ->execute();
  17. 17. hook_nodeapi -> hook_node_* <ul><li>hook_nodeapi() is now: </li><ul><li>hook_node_delete(),
  18. 18. hook_node_insert(),
  19. 19. hook_node_load(),
  20. 20. hook_node_prepare(),
  21. 21. hook_node_prepare_translation(),
  22. 22. hook_node_search_result(),
  23. 23. hook_node_presave(),
  24. 24. hook_node_update(),
  25. 25. hook_node_update_index(),
  26. 26. hook_node_validate(), and
  27. 27. hook_node_view(). </li></ul></ul>
  28. 28. hook_nodeapi -> hook_node_* // Drupal 6 function book_nodeapi(&$node, $op, $teaser, $page) { switch ($op) { case 'load': // Load a book. } } // Drupal 7 function book_node_load($nodes, $types) { // Load a book. }
  29. 29. The bad news + another 232 API changes
  30. 30. The good news <ul><li>Some nice Drupal people have written the coder_upgrade module that simplifies the upgrade task for you.
  31. 31. It's a sub-module of the coder module.
  32. 32. Requires the grammar_parser module.
  33. 33. It can either do a review of the code and provide a list of required changes or;
  34. 34. It can automatically apply those changes </li></ul>
  35. 35. Coder review / upgrade <ul>Coder includes two useful functionalities: <li>Review </li><ul><li>Allows you to check your code against the Drupal coding standards
  36. 36. Some rules regarding stuff that should be done to convert modules from 6.x to 7.x </li></ul><li>Upgrade </li><ul><li>Upgrades your code from 6.x to 7.x, providing an upgraded version and the patch. </li></ul></ul>
  37. 37. Reference <ul><li>Converting 6.x modules to 7.x
  38. 38. ( http://drupal.org/update/modules/6/7 )
  39. 39. Coder module ( http://drupal.org/project/coder ) </li><ul><li>Coder upgrade </li></ul><li>#D7CX </li><ul><li>http://cyrve.com/d7cx
  40. 40. http://drupal.org/project/modules?text=d7cx </li></ul></ul>
  41. 41. Questions <ul><li>Any questions?
  42. 42. Shameless plug: </li><ul><li>You're invited to our Drupalcamp in Lisbon in March 2011 (TBC). </li></ul></ul>

×