• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Convert modules from 6.x to 7.x
 

Convert modules from 6.x to 7.x

on

  • 5,085 views

Now that Drupal 7 is upon us, I would like to explain the resources available to convert existing 6.x modules to 7.x....

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.

Statistics

Views

Total Views
5,085
Views on SlideShare
5,053
Embed Views
32

Actions

Likes
3
Downloads
46
Comments
0

3 Embeds 32

http://boblinux.fr.nf 27
http://deblibhack02.lan 4
http://192.168.0.13 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Convert modules from 6.x to 7.x Convert modules from 6.x to 7.x Presentation Transcript

    • Converting modules from 6.x to 7.x João Ventura (jcnventura) [email_address]
    • 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
    • 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.. :)
    • 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
    • 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', ));
    • 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 }
    • 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();
    • 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();
    • 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();
    • 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().
    • 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. }
    • The bad news + another 232 API changes
    • 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
    • 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.
    • 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
    • Questions
      • Any questions?
      • Shameless plug:
        • You're invited to our Drupalcamp in Lisbon in March 2011 (TBC).