Adding custom mapping types in doctrine

While working in some enhancements for my startup Careerise, I had an issue with doctrine not recognising the mysql data type “blob“.

The error I was getting while running doctrine diff was :

  [Doctrine\DBAL\DBALException]
  Unknown database type blob requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.

In order to overcome the issue, I had to add the blob data type to doctrine.

Step 1 :

Creating a class to handle the blob type.

path : Doctrine/DBAL/Types/BlobType.php

file content :

<?php
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
 
/**
 * Type that maps a database BLOB to an encoded base64 value
 *
 * @author Ahmed Abdelaliem <a.abdelaliem[AT]careerise.com>
 *
 */
class BlobType extends Type
{
 
    public function getName ()
    {
        return TYPE::BLOB;
    }
 
    public function getSQLDeclaration (array $fieldDeclaration,
            AbstractPlatform $platform)
    {
        return $platform->getDoctrineTypeMapping('BLOB');
    }
 
    public function convertToDatabaseValue ($value, AbstractPlatform $platform)
    {
        return ($value === null) ? null : base64_encode($value);
    }
 
    public function convertToPHPValue ($value, AbstractPlatform $platform)
    {
        return ($value === null) ? null : base64_decode($value);
    }
}

Step 2: Add the blob type name to the Type abstract class

File Path : Doctrine/DBAL/Types/Type.php

    const BLOB = 'blob';

Step 3: Modify the DoctrineTypeMappings for mysql

File Path: Doctrine/DBAL/Platforms/MySqlPlatform.php

Append the blob type to the end of the array, ex :

protected function initializeDoctrineTypeMappings()
    {
        $this->doctrineTypeMapping = array(
            'tinyint'       => 'boolean',
            'smallint'      => 'smallint',
            'mediumint'     => 'integer',
            'int'           => 'integer',
            'integer'       => 'integer',
            'bigint'        => 'bigint',
            'tinytext'      => 'text',
            'mediumtext'    => 'text',
            'longtext'      => 'text',
            'text'          => 'text',
            'varchar'       => 'string',
            'string'        => 'string',
            'char'          => 'string',
            'date'          => 'date',
            'datetime'      => 'datetime',
            'timestamp'     => 'datetime',
            'time'          => 'time',
            'float'         => 'float',
            'double'        => 'float',
            'real'          => 'float',
            'decimal'       => 'decimal',
            'numeric'       => 'decimal',
            'year'          => 'date',
            'blob'          => 'blob',
        );
    }

now doctrine will be able to recognise the mysql data type blob.

the documentation here was helpful in some of the steps above : Custom Mapping Types

How to reduce your virtualbox linux virtual machine size

After using a linux virtual machine that has been configured with dynamically expanding drive, the size gets larger even if you remove files from it.

Here is the steps to shrink your linux virtual machine size :

1- Remove any unnecessary files you don’t need from the virtual machine.

2- Fill the unused spaces on it with zeros.

  • Open the virtual machine.
  • Install zero free
sudo apt-get install zerofree
  • Reboot the machine in repair mode, and login to root shell
  • Kill any processes using the hard disk.
service rsyslog stop
service network-manager stop
killall dhclient
  • list your virtual machine harddisks
df
  • Unmount and Fill all the unused spaces for each physical drive on the machine with zeros.
mount -n -o remount,ro -t ext3 /dev/sda1 /
zerofree /dev/sda1
  • Shutdown the machine.

3- Clone the old HD file into a new shrinked one

VBoxManage clonehd oldHd.vdi newHd.vdi

4- Now add the new cloned HD file as the new HD for the machine and test it.

5- Remove your old HD file.

 

Second life and Virtual Worlds on the web

I had had the chance to do some investigations on how to create a second life similar application that run on the web, and allows people to communicate, chat, and interact in different ways.

The applications of such tools can be virtual meeting rooms, small virtual world for people to share or discuss some cause or idea. there is also the fun part where people can interact as in a game, purchase items, go to virtual malls, etc.

Here is some links to the wikis of tools that can create virtual worlds:

http://en.wikipedia.org/wiki/RedDwarf_Server

http://en.wikipedia.org/wiki/Project_Darkstar

http://en.wikipedia.org/wiki/Croquet_project

http://en.wikipedia.org/wiki/Open_Wonderland

http://en.wikipedia.org/wiki/GForge

http://en.wikipedia.org/wiki/OpenSimulator

I hope those would be useful for any one interested in virtual world applications, Have any urls to add to those, please let me know .

Using Juniper Network on Ubuntu 32 and 64 bit without Firefox

Lately i have moved from Ubuntu 32bit to 64bit to make use of the 8G memory, and since I have been struggling to get our juniper vpn connection working, turned out it is not compatible with 64bit binaries of java and firefox.

I found this great tutorial here to have the juniper network VPN working from command line http://mad-scientist.us/juniper.html

the only disadvantage of this is you won’t have a status window to monitor the connection activity.

This has been tested on Ubuntu 10.10 maverick.

Speed your internet browsing on Ubuntu using local DNS Cache

Use these steps to speed your internet browsing requests on Ubuntu, by enabling local DNS cache :

1- Run this command to install dnsmasq package

sudo apt-get install dnsmasq

2- Modify the file :

sudo gedit /etc/dnsmasq.conf

change the line :

#listen-address=

To :

listen-address=127.0.0.1

3- Modify the file :

sudo gedit /etc/dhcp3/dhclient.conf

Ucomment the line :

prepend domain-name-servers 127.0.0.1;

4- Add the DNS 127.0.0.1 to your connection through your connection manager

Your DNS servers should be :

127.0.0.1,8.8.8.8,4.2.2.4

5- Restart your connection

sudo /etc/init.d/networking restart

To check if it is working issue the following command twice:

dig php-architect.com | grep 'Query'

first response will be like :

;; Query time: 96 msec

run the previous command again

dig php-architect.com | grep 'Query'

Response now should be :

;; Query time: 0 msec

This will speed your browsing especially in pages with many HTTP requests.

Backup or Export, Compress and upload mysql database to remote host

This is a handy command that i use to backup or export, compress and upload a mysql database to my remote host, very handy when you wanna upload your development database to the remote host after some changes.

/usr/mysql/bin/mysqldump --opt -uUsername -pPassword Databasename  | gzip -c | ssh -q user@remote-host.com 'cat > ~/Databasename.sql.gz'

Replace the following :

  • /usr/mysql/bin/mysqldump : The path for mysqldump on your localmachine
  • Username : Username for local mysql database.
  • Password : Password for local mysql database.
  • Databasename : Name of the database to export.
  • user@remote-host.com : the user and the IP or the address of the remote host.

the above command will upload the compressed database to your home directory on the remote host, to change the directoy, replace ~/ with the path you want.

Virtualbox hidden gems, VBoxManage

Virtual box has this little secret, the Command Line interface (CLI), this is very useful for users who wants to manage their virtual boxes on headless servers.

Question is why using command line while you have a nice easy to use GUI, the answer is POWER. you can do anything with the virtual box command line, you can create virtual machines, modify their settings, take snapshots, start and shutdown them.

VBoxManage supports everything the graphical user interface does, and much more.

VBoxManage has its share of Virtual Box documentation, you can find it here http://www.virtualbox.org/manual/ch08.html

Where I am ?

Looks like i have stopped blogging for a while. except from some trips and tricks I am keeping for my reference and public users.

well that’s not the case but since the team I am working with grew to around 22 developer, which i believe considered the biggest php team in one company in Egypt, things were going so crazy, lots of projects going, lots of new approaches, new integrations, and i have to be on top of it all the time.

meanwhile i am driven by four ideas for projects that i believe is gonna make a little difference in their business areas, I am prototyping each one of them, jumping from one to other, I launched one of them already which is www.lamptag.com, which is simply a crawler for LAMP resources and related technologies, after less than a month from launching he prototype, the feedback is good, the twitter page reached 100 follower. and the number of clicks on the links is good too.

Soon i will blog about the recent challenged i have encountered in the field, weather they are technically or management related.

Installing Java plugin for Firefox on Ubuntu 10.10 (Maverick)

Again after upgrading from Ubuntu 9.10 to 10.4, I had some issues getting Java to work with Firefox, after checking the software center, I found that the Java plugin for firefox is not working properly which broke my vpn connection.

To get this fixed, I simply followed the steps :

1- Backup your repositories files.

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

2- Open your repositories file:

sudo gedit /etc/apt/sources.list

3- Add the following line then close the sources.list file

deb http://archive.canonical.com/ubuntu maverick partner

4- Uninstall both icedtea6-plugin and openjdk-6-jre.

sudo apt-get remove icedtea6-plugin openjdk-6-jre

5- Install sun-java6-plugin

sudo apt-get update
sudo apt-get install sun-java6-plugin
sudo update-alternatives --install /usr/lib/mozilla/plugins/mozilla-javaplugin.so mozilla-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/i386/libnpjp2.so 1

6- Close your firefox and reopen it again, it should be working smoothly.

Dear Developers. I will be watching you

Every build you break
Every delivery you fail
Every risk you take
Every fix you make
I will be watching you

Every single break
Every diff you make
Every game you play
Every small delay
I will be watching you

Oh can’t you see
there is no caching
and the production breaks
with every merge you make

Every date you fake
Every small mistake
Every claim you stake
Every merge you make
I will be watching you

When the build doesn’t work , It is a big disgrace
I dream at night i can only see your face….

I look around i can see         no good practice
I feel so cold and i work         till a fix is in place
I keep crying baby fix it !        pleassssssse

Oh cant you see,             you are not code-complete
Oh the application aches    with every build you break

Every claim you stake
Every date you fake
Every build you break
Every code you fail

Every build you break
Every delivery you fail
I will be watching you

I will be watching you

————————————-

Thanks to the original one here

[youtube=http://www.youtube.com/watch?v=q2h_uKypdGE]