Slide 1

Slide 1 text

Converting modules from 6.x to 7.x João Ventura (jcnventura) [email protected]

Slide 2

Slide 2 text

About me  'print' module mantainer  Using Drupal since 2004  1 patch in Drupal 7 core :)  100% drupal developer for >1yr now  Now working at Trellon

Slide 3

Slide 3 text

Thanks  Drupal Ireland for organizing this  First Drupalcamp!  Trellon for sponsoring my trip  Stella for inviting me to propose a session  Guiness  For my headache.. :)

Slide 4

Slide 4 text

API changes  82 API changes to take into account when converting a module from Drupal 5 to Drupal 6  19 + 8 + 8 + 20 + 10 + 7 + 22 + 25 + 41 + 24 + 15 + 15 + 6 + 13 + 5 + 1 – 5 = 234 API changes

Slide 5

Slide 5 text

Database API - Select // Drupal 6 $result = db_query("SELECT nid, title FROM {node} WHERE uid = %d AND type = '%s'", 5, 'page'); // Drupal 7 $result = db_query("SELECT nid, title FROM {node} WHERE uid = :uid AND type = :type", array( ':uid' => 5, ':type' => 'page', ));

Slide 6

Slide 6 text

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 }

Slide 7

Slide 7 text

Database API - Insert // Drupal 6 db_query("INSERT INTO {mytable} (intvar, stringvar, floatvar) VALUES (%d, '%s', %f)", 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();

Slide 8

Slide 8 text

Database API - Update // Drupal 6 db_query("UPDATE {node} SET title='%s', status=%d WHERE uid=%d", 'hello world', 1, 5); // Drupal 7 db_update('node') ->fields(array('title' => 'hello world', 'status' => 1)) ->condition('uid', 5) ->execute();

Slide 9

Slide 9 text

Database API - Delete // Drupal 6 db_query("DELETE FROM {node} WHERE uid=%d AND created < %d", 5, REQUEST_TIME - 3600); // Drupal 7 db_delete('node') ->condition('uid', 5) ->condition('created', REQUEST_TIME - 3600, '<') ->execute();

Slide 10

Slide 10 text

hook_nodeapi → hook_node_*  hook_nodeapi() is now:  hook_node_delete(),  hook_node_insert(),  hook_node_load(),  hook_node_prepare(),  hook_node_prepare_translation(),  hook_node_search_result(),  hook_node_presave(),  hook_node_update(),  hook_node_update_index(),  hook_node_validate(), and  hook_node_view().

Slide 11

Slide 11 text

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. }

Slide 12

Slide 12 text

The bad news + another 232 API changes

Slide 13

Slide 13 text

The good news  Some nice Drupal people have written the coder_upgrade module that simplifies the upgrade task for you.  It's a sub-module of the coder module.  Requires the grammar_parser module.  It can either do a review of the code and provide a list of required changes or;  It can automatically apply those changes

Slide 14

Slide 14 text

Coder review / upgrade Coder includes two useful functionalities:  Review  Allows you to check your code against the Drupal coding standards  Some rules regarding stuff that should be done to convert modules from 6.x to 7.x  Upgrade  Upgrades your code from 6.x to 7.x, providing an upgraded version and the patch.

Slide 15

Slide 15 text

Reference  Converting 6.x modules to 7.x (http://drupal.org/update/modules/6/7)  Coder module (http://drupal.org/project/coder)  Coder upgrade  #D7CX  http://cyrve.com/d7cx  http://drupal.org/project/modules?text=d7cx

Slide 16

Slide 16 text

Questions  Any questions?  Shameless plug:  You're invited to our Drupalcamp in Lisbon in March 2011 (TBC).