Posts tagged with development

Getting started with foreign keys

An often asked question on the Nooku Framework mailing list is how to deal with relations in databases. Nooku Framework doesn’t support relations out of the box yet, but fortunately the InnoDB engine in MySQL does!

There are three important rules that must be met in order to create relations:

  1. Both tables must be InnoDB tables and must not be TEMPORARY tables.
  2. Keys must have similar internal data types.
  3. Both foreign and referenced keys need to be indexed.

A basic example

Let’s see the basics through an example:

Assume that we have an articles table with two columns: article_id and title. We have an authors table as well with the columns: author_id and name. Here is the SQL code for the tables:

CREATE TABLE IF NOT EXISTS `articles` (
`article_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255) NOT NULL DEFAULT '',
PRIMARY KEY (`article_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

CREATE TABLE IF NOT EXISTS `authors` (
`author_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL DEFAULT '',
PRIMARY KEY (`author_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

We want to assign authors to articles. An author can belong to more than one articles, and an article can belong to more than one authors. So this is a many-to-many relation. That’s why we need a relation table too, which has article_id and author_id columns:

CREATE TABLE IF NOT EXISTS `articles_authors` (
`article_id` INT UNSIGNED NOT NULL,
`author_id` INT UNSIGNED NOT NULL,
FOREIGN KEY (`article_id`)
REFERENCES `articles`(`article_id`)
ON DELETE CASCADE,
FOREIGN KEY (`author_id`)
REFERENCES `authors`(`author_id`)
ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

As you can see, we specified the foreign keys with CASCADE and RESTRICT options. Let’s try to delete an article. Notice that relations in the articles_authors table are deleted with it automatically. Now let’s try to remove an author. If the author is referenced in the relation table, then MySQL refuses to delete it. This ensures referential integrity.

Keeping referential integrity

By using InnoDB, you can prevent accidental removal of referenced rows. Other than its roboust data management features, it has usability advantages too. For example some of the database management tools support foreign keys too. For example in Sequel Pro, an arrow is displayed next to the column’s value, and it takes you to the referenced row when you click on it. This little feature can be useful many times.

foreignkeys

InnoDB has become the default engine in MySQL 5.5 and has many features over MyISAM. I am highly recommending every developer to consider using it in their applications.

This was just a basic introduction to foreign keys, it is capable of much more! If you are interested, visit the MySQL Reference Manual.

Form validation with Nooku Framework

Nooku Server - Form Validation

Responsive validation feedback on forms is no longer a “nice to have” feature in modern web apps, it’s a standard that users have come to expect to be there.

In Nooku Framework Alpha 3, we added a new API that loads the forms validation library in MooTools More for you. And we implemented it in Nooku Server Alpha 3 to improve the usability of refactored components.

Today I’ll show you how easy it is to get started by simply adding CSS classes to your form inputs. Then I’ll show you how easy it is to create your own input validators for when you need to validate something custom.

Read the rest of this entry »

The magic of file uploads with com_files

In my last blog post, I wrote about the awesome new file manager that made its way into Nooku Server Alpha 3. In this blog post we are going to dive a little deeper into how to re-use com_files in your own components. Meet my new friend : com_uploads!

This is a proof of concept component that demonstrates two distinct features:

1. A custom file upload controller that handles file uploads
2. A full featured interface for managing files in your special container

Nooku Server - Files
Read the rest of this entry »

Meet com_files, Joomla file management 2.0

The Joomla Media Manager is currently a hermetically sealed black box which has been around since the Mambo days. It neither allows extending it, nor can it be easily re-used by developers. Over the past few weeks we have been giving it some much needed love and re-build it from the ground up. Meet : com_files !

For the diehards, in Joomla this component is called com_media. We gave it a new name to better reflect its use and to allow you to also install it in Joomla site. In good Nooku tradition com_files is fully re-usable and extend-able.

Nooku Server - Files

If you check out our Nooku Server demo you will notice that the user interface looks very similar to that of Joomla. Don’t let yourself be fooled by the looks. Under the hood this baby has a completely new and shiny engine.

In this blog I’ll walk you over the key points of the refactor and at the end I’ll show you how you can easily integrate this component in your own solutions.

Read the rest of this entry »

Say hello to the “dynamic module injector”

This is a guest post from Nick Balestra, CEO and Co-Founder of Beyounic, home of the Ohanah events manager for Joomla.

It has been said many times before, Nooku is not a one-way street. The Nooku community thrives on collaboration. At Beyounic we believe in this and decided to organise a hackathon at our own Beyounic HQ in Locarno Switzerland. We brought our team together and flew Johan in to hack for two full days on Nooku Framework. One of the little gems that came out of this is the ‘dynamic module injector’.

In Joomla, modules are attached to a menu item based on its ID. If you want to associate a specific module with a specific page you need to create a menu item for that page, then link the module to it. While this may work in many cases, it’s not always ideal.

Read the rest of this entry »

Nooku Development at Warpspeed

Not even 6 months ago we announced our plans for Nooku Server, a multi-site distribution of Joomla 1.5. We created a diet for Nooku Server and defined a roadmap. We initially planned to add multi-site support, caching improvements and a new administrator template which we did in alpha 1 and alpha 2, and then … community happened!

We couldn’t have expected so much enthusiasm from developers from all over the world who wanted to help out and contribute. Simply amazing!

Blossoming community

We announced our contributor agreement in November last year. In the past 6 months our contributor base has grown, from a handful to a total of 35. That’s a lot of developer power!

Ohloh Contributor Activity Comparison

Not less then 21 developers contributed to Nooku in the past year working on various projects. As you can see from this link and the graph above (taken from Ohloh) that’s more than double the amount of people who contributed to Joomla in the same period. Not bad huh!

Nooku Server loses 40% weight

40% code reduction for Nooku Server Last December we announced our plans for Nooku Server, a multi-site and multi-lingual distribution of Joomla 1.5. With the help of our community we created a diet for Nooku Server and defined a roadmap.

For the first alpha we are focusing on implementing the key ingredients of our diet. Most of the work involves removing legacy code, legacy libraries and doing clean-up. In the past weeks we have been making steady progress.

  • Core extensions: All the components, plugins and templates that didn’t made it into our list have been removed
  • XML-RPC: XML-RPC support has been removed
  • PDF: PDF support has been removed
  • Legacy: Legacy support for Joomla 1.0 and PHP4 has been removed
  • Security: All assets (css,js,images) have been moved to the media folder
  • Libraries: Legacy libraries have been removed
  • Performance: Hit support in Content and Weblinks has been removed
  • Mootools: Mootools has been upgraded to 1.2  including the compatibility layer
  • Framework: Nooku Framework has been added

With most of the refactoring completed it’s time to weigh the result. I have done a code count today to compare the code bases of Joomla 1.0, 1.5, 1.6 and Nooku Server. I used Ohcount, a little command line tool that is also used by Ohloh to do code counting.

We have made Nooku Server a whooping 40% lighter in code size. Yes, you read that right, we removed 40% code and we added a whole new framework at the same time.

Here are the detailed results:

Read the rest of this entry »

A roadmap for Nooku Server

Nooku Server Roadmap

With Nooku Server’s diet established, we now have a good idea of the work that needs to be done. A next step in the process is to define a little roadmap.

Over the next 4 months, we are going to be rolling out alpha releases implementing the key ingredients as defined in our little diet and at the same time adding key features.

We will be working towards releasing an alpha about once every four weeks. This gives the following roadmap :

  • Alpha 1 : February
  • Alpha 2 : March
  • Alpha 3 : April

Under ideal conditions Nooku Server would go beta in May 2011, right in time for JAB11.

Our development flow will be focused on maintaining the stability of the Joomla 1.5 core. Scope for the alpha releases will be kept very limited in order to avoid scope creep. For each alpha we will focus on one major feature or task.

Read the rest of this entry »

MySQL Query Cache

MySQL Logo As some would be aware we have been working on a multi-site installation of Joomla! that is running in excess of 130 sites for the Belgium Police. Needless to say performance is paramount hence we have spent a considerable amount of time researching and deploying the right server technologies. This has included the use of Nginx rather than Apache, APC for opcode caching and a little gem in MySQL called query_cache.

Query cache is something that to my knowledge only existed in MySQL until Oracle released 11g. It’s not the same as the caching historically found in Oracle and Microsoft SQL, both of which would cache the method/procedure but not the result set.

MySQL’s query cache is a must have configuration which is as simple to configure as to allocate it with some memory. To see if you’re already running it try this in command line…

Read the rest of this entry »

Project Deployment with Assembla

Assembla Server Configuration

Assembla FTP build configuration

For the best part of a year we have been using Assembla for all of our Nooku development. The first public example being the Nooku Developer Portal. Assembla is not only a great tool for our Nooku developer portal, we also use it for all our client projects. Assembla itself has a plethora of features, two of which are methods of deployment, a Build Tool and a FTP Tool.

The build tool utilises Capistrano and boasts some rather heavy duty capabilities. I have been testing this with Nooku Server, deploying to my own cloud server and whilst the setup is far more complex than a simple FTP deployment I can immediately see the advantages. For example the ability to run server side scripts allows for database updates to be run.

Read the rest of this entry »