PHP (Drupal) debugging with Eclipse

Submitted by Jochus on Wed, 08/09/2010 - 00:51 | Posted in: Drupal
Posted in

Anybody saying that you can't debug a PHP application? Well, then you are so wrong :-). At DrupalCon CPH, I attended this nice presentation by Randy Fay: http://www.randyfay.com/node/68. Just follow the steps at his blogpost, and you will get this:



(click to enlarge)

I was using XDebug before I attended the presentation and I must say ... it really s*cks! But Randy Fay is using Zend(Debugger), which seems to me sooo much better in performance and usability !

TRAC: DataError: (1264, "Out of range value for column 'due' at row 1")

Submitted by Jochus on Mon, 06/09/2010 - 00:31 | Posted in: Java
Posted in

We are using TRAC as our SCM and project management tool. There are a lot of nice plugins to integrate in the project, and one of them is the ScrumBurndownPlugin, which makes it possible to perform SCRUM @ my company.

But by installing the plugin, I was receiving this error:

Traceback (most recent call last):
  File "\trac\web\main.py", line 513, in _dispatch_request
    dispatcher.dispatch(req)
  File "\trac\web\main.py", line 235, in dispatch
    resp = chosen_handler.process_request(req)
  File "\trac\ticket\roadmap.py", line 591, in process_request
    return self._do_save(req, db, milestone)
  File "\trac\ticket\roadmap.py", line 673, in _do_save
    milestone.update()
  File "\trac\ticket\model.py", line 1004, in update
    @self.env.with_transaction(db)
  File "\trac\db\api.py", line 77, in transaction_wrapper
    fn(ldb)
  File "\trac\ticket\model.py", line 1014, in do_update
    self.description, old_name))
  File "\lib\site-packages\trac\db\util.py", line 65, in execute
    return self.cursor.execute(sql_escape_percent(sql), args)
  File "\lib\site-packages\MySQLdb\cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "\lib\site-packages\MySQLdb\connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
DataError: (1264, "Out of range value for column 'due' at row 1")

It seems that the ScrumBurndownPlugin, which adds the started column by re-creating the whole table milestone, unfortunately changes column types with int types instead of bigint. So I fixed it by performing this query:

ALTER TABLE `milestone` CHANGE `due` `due` BIGINT( 20 ) NULL DEFAULT NULL 

For more details, go here ...

SQL INTERSECT with MySQL 5.x

Submitted by Jochus on Thu, 02/09/2010 - 00:56 | Posted in: Database
Posted in

Yesterday, I wanted to perform a SQL INTERSECT operation on a MySQL 5.x database. I'm pretty used to work with Oracle, and Oracle is totally familiar with this

( SELECT foo FROM bar1 )
INTERSECT
( SELECT foo FROM bar2 )

Unfortunately, MySQL doesn't know this syntax. This is my workaround:
SELECT foo
FROM bar1
WHERE foo IN ( SELECT foo FROM bar2 )

GIT vs SVN (part 2)

Submitted by Jochus on Tue, 31/08/2010 - 00:06 | Posted in: Linux
Posted in

A couple of weeks ago, I made this blogpost. Last week, I visited DrupalCon CPH. There was a talk by Randy Fay about GIT. The presentation was really good, as of the demo! But as I discovered in my blogpost, I still see no advantages from moving to a distributed architecture. This architecture is required for open source development as Drupal, kernel of Linux and many, many other open source frameworks, but I doubt it's useful in an enterprise, where you work with a team on several branches, etc, etc, ...

Anywayz, this is what I wrote down:

Advantages

  • GIT is really great for community projects, such as Drupal, Wordpress, kernel of Linux and all other open source communities
  • you really have a copy of the project on your local disk and you can create tags, branches, ... for whatever and for as long as you want. You never get back to the server. This is easy when you're often at different locations or you're not always connected to the network
  • it's so much faster to swith from a branch to a branch
  • you don't need the SSH access keys, it's possible to do HTTP authentication => I was wrong about this in my previous blogpost

Disadvantages

  • an extra operation is required
  • // GIT
    $ git add foo.bar
    $ git commit foo.bar -m "initial commit"
    $ git push # to server
     
    // SVN
    $ svn add foo.bar
    $ svn commit foo.bar -m "initial commit" # and that's really it!

PHP 5.3: pass by reference problems

Submitted by Jochus on Wed, 11/08/2010 - 00:57 | Posted in: Drupal
Posted in

Interesting problem in the new PHP 5.3 (I'm currently using 5.3.2-1ubuntu4.2).

Imagine you have following code:
-> Function test() takes 2 arguments. The 2 arguments are referenced arguments (notice the '&'):

function test(&$arg, &$arg2){
  // some code
}

... and you want to call it using the call_user_func_array() function.
In PHP 5.2 (or lower), you could simply do this by:

call_user_func_array('test', $arg1, $arg2);

... but since PHP 5.3, this will not work any longer :-). You cannot pass arguments by reference to functions called with callbacks. The reason is that call_user_func_array() parameters are not references. If you really need to do it with a callback, you will need to wrap the parameters into an object (objects are always passed by reference)

function test($params){
  // some code
  echo $params->arg1;
  echo $params->arg2;
}
...
$params = (object) array('arg1' => $arg1, 'arg2' => $arg2);
call_user_func_array('test', $params);

Kenny Geldhof wins Indoor Kart World Championship 2010 - Phoenix USA

Submitted by Jochus on Fri, 06/08/2010 - 01:18 | Posted in: Lifetime
Posted in

From the 27th of July till the 1th of August, there was an indoor kart championship in Phoenix - Arizona, USA. This championship isn't just "another championship". No, it's a race between the best pilotes (indoor karting people) in the whole world. 5 Belgians took a flight to the USA and tried to win the cup!

  • Gregory Laporte
  • Kenny Geldhof
  • Mats de Jong
  • Robin Borremans
  • Mathias Grooten

Unfortunately, taking a flight to USA is rather expensive, so we had to follow up everything by internet. There was a (forum)thread on kartgrid.be. Our Belgian drivers reported every night what they did, what were the standings, the condition of the karts, etc, etc, ... You can read the full story here: http://www.kartgrid.be/forum/viewtopic.php?f=25&t=6029

I'm not gonna post the whole story here again. The important thing is: in the final race, a Belgian - Kenny Geldhof -, was the first to see the checkered flag! After Mathias Grooten, winning the IKWC trophy in 2008, Kenny Geldhof is the second Belgian racer winning this cup (the cup is organized since 2005).

The results (top 10 IKWC 2010):

1   Kenny Geldhof     BEL    191
2   Ruben Boutens     NED    187
3   Mathias Grooten   BEL    180
4   Mats de Jong      BEL    179,5
5   Miles Calvin      USA    179
6   Aaron Downs       USA    177
7   Robin Borremans   BEL    173
8   Jon Kimbrell      USA    173
9   Gregory Laporte   BEL    172
10  Logan Calvin      USA    165

The podium:

Congratz to Kenny !!!

Microsoft Wireless Laser Mouse 5000: scroll speed too fast @ Ubuntu Lucid (10.04 LTS)

Submitted by Jochus on Tue, 03/08/2010 - 00:56 | Posted in: Linux
Posted in


I'm extremely happy with this mouse at my work, but there's was one thing that was really annoying: the scroll speed in Ubuntu Lucid (10.04 LTS) was just toooo fast. Scrolling one time at the wheel, created a scroll effect of several steps.

After Googling a while, I came up this link: https://answers.launchpad.net/ubuntu/+question/9200. This ticket says:

This has been driving me nuts for a while now. The scroll wheel on my desktop mouse
(it's an MS wireless one) scrolls rather fast. Instead of moving a few lines, it
scrolls half a page or more with a very gentle scroll.
...
In Ubuntu (!) again I just unplugged the receiver and plugged it in again as fyo
described (by reading fyo's explanations I thought I must do the plugging in Windows,
so this is just for clarification). This solved the problem for me.

So unplugging the receiver did indeed solve the problem: crazy as hell :-). Interesting to know:

You see, the wheel is not a wheel at all (its not analog), in fact wheel movements
are seen as button presses (its digital). If you open the X event monitor (from
terminal just type xev) and you go with your pointer within the white window, you
will see that at each movement of the wheel there is a button press/release event 
(depending on your xorg.conf, usually 4 and 5).

Versioning Drupal "views" with hook_views_default_views()

Submitted by Jochus on Mon, 02/08/2010 - 00:12 | Posted in: Drupal
Posted in

The Views module provides a flexible method for Drupal site designers to control how lists and tables of content (nodes in Views 1, almost anything in Views 2) are presented. Traditionally, Drupal has hard-coded most of this, particularly in how taxonomy and tracker lists are formatted.

This tool is essentially a smart query builder that, given enough information, can build the proper query, execute it, and display the results. It has four modes, plus a special mode, and provides an impressive amount of functionality from these modes.

Among other things, Views can be used to generate reports, create summaries, and display collections of images and other content.
Source: http://drupal.org/project/views

Describing the problem ...

At first, we created views using the Drupal UI interface. And then, to move to the PROD server, we re-executed the steps on the PROD Drupal server. This wasn't very nice for 2 reasons:

  • losing time to re-execute steps
  • no control of what changes are made in the view (and by who ...?)


... providing a solution

I found 2 possible solutions:

  • Features (http://drupal.org/project/features: The features module enables the capture and management of features in Drupal. A feature is a collection of Drupal entities which taken together satisfy a certain use-case. Features provides a UI and API for taking different site building components from modules with exportables and bundling them together in a single feature module. A feature module is like any other Drupal module except that it declares its components (e.g. views, contexts, CCK fields, etc.) in its .info file so that it can be checked, updated, or reverted programmatically.
    I really love this Drupal module, but the problem is: all your views are bundled into a seperate module. So when you create a new custom module ABC, and you create a view for module ABC, you're not able to store the code into the codebase of module ABC. Features is still in beta phase, so not sure if we can trust on a stable working version ...
  • Working with hook_views_default_views(). This hook is provided in the views module. This hook allows modules to provide their own views which can either be used as-is or as a "starter" for users to build from. This hook should be placed in MODULENAME.views_default.inc and it will be auto-loaded. This must either be in the same directory as the .module file or in a subdirectory named 'includes'..
    It seems very nice, and it is. So what do you have to do:

    • export your view using the Drupal UI
    • insert the code in the .inc file
    • ... now, for me, the view wasn't loaded for me. We had to do something extra, which isn't described in the documentation. You have to activate the hook by entering this code in your .module file:
      /**
       * This function is needed to automatically load the views_default.inc file
       * It specifies the "views" api version. Default path is set to the modules' root directory
       */
      function ##module_name##_views_api() {
        return array(
          'api' => 2
        );
      }

      There's an extra variable, which makes it possible to change the path where all includes are stored. Default is root, but "path" makes it possible to change :-)