Wednesday 10 November 2010

importing external data to mySQL

For a project i was working on I had to import a csv file provided by booking.com
The constraint of this file is that i wanted to be able to allow to reimport that file as booking.com publishes updates with a list of new hotels quite often. That means that if another table in the database relies on the data of the imported file we can't create a normal foreign key as when we reimport the file, we can't guarantee the primary key will remain identical.

I decided to create the foreign key to a hash of the combination of town name and country name, why not only the town name? as for example London exists in England and in Canada, which would cause a problem as we want the foreign key to have only one option in the imported table.

Symfony doesn't know how to handle none numerical values of foreign key, hence we need to do the task of the association between the tables ourself.

in my schema.yml i configured the table PromoteTown that has a relation to BookingComHotels


PromoteTown:
  columns:
    town_hotel_id:
      type: BINARY(16)
      notnull: true
      unique: true
    position:
      type: integer(4)
  relations:
    BookingComHotels: { local: town_hotel_id, foreign: id_hash, onDelete: cascade, foreignAlias: PromoteTowns }


and in the model i have a method to insert to PromoteTown, the $this is related to BookingComHotels as this function is in BookingComHotels class.



        $hash = $this->getIdHash();
        $pt = new PromoteTown();
        $pt->type = '2';
        $pt->town_hotel_id = $hash;
        $pt->save();
        $pt->link('BookingComHotels', $hash);


Monday 1 November 2010

installing PHPUnit

to install the latest version of PHPUnit, 3.5 in my case. you need to upgrade the PEAR that come by default with snow Leopard.
sudo pear upgrade pear
will upgrade the snow Leopard Pear.
then I just followed the instructions PHPUnit website

Saturday 4 September 2010

unique on multiple columns

In Doctrine documentation I couldn't come across on how to mark in YML file to have unique on 2 columns.
The idea is as this example demonstrates of setting the category_id and user_id fields as unique:
Entry:
columns:
project_name:
type: string(255)
category_id:
type: integer
notnull: true      
user_id:
type: integer(4)
notnull: true
indexes:
category_user_idx:
fields:
user_id: []
category_id: []
type: unique

Wednesday 14 July 2010

internalization of mysql

On a recent project I had a problem to import into MySQL a file tab delimited formatted with utf-8. I found that I have to set the collation of the column to utf-8, but there are several. according to what i found in other blogs, i tried utf8_unicode_ci, but after few trials and that i got gibberish for the special characters I changed it to utf8_bin and it works fine.

A later addition:
I repeat what I thought works a bit later and realised I can't repeat my success. It seems only writing php script solves the problem. Another thing if you copy utf8 data and use phpmyadmin it's important to verify the page's encoding is indeed utf8.

Tuesday 27 April 2010

Transfering the code to Xubuntu production server

I needed  a server to deploy the code for testing. As I have old PC I installed the light linux Xubuntu.
During the development I installed some additional packages to Apache. Mostly it's easy to spot if you check the log files for errors, but for plugin sfImageTransformPlugin I use the mime type detector and in order to use it, the mime type package has to be installed. The result was blank page when manipulating images, which happened when initializing the sfImage class. To enable the detecting mime type I configured app.yml
  sfImageTransformPlugin:
    mime_type:
      auto_detect: true
      library: MIME_Type 

Wednesday 24 March 2010

cache or why symfony stops running

Installing a new plugin left me with the command line of symfony does nothing.
steps i've made to try and tackle the problem were checking the php_error.log inside MAMP if you go to main folder of MAMP it's under logs (there's an article explaining how to have the error logs as a widget when clicking F4, how to have it.
the symfony file itself is a batch file, so you can try and debug the file, i just use echo to print in the terminal.
well the errors i got aren't very helpful, so last resort i decided after spending quite a while is to delete the cache. 
in the project folder one of the folders is cache. i renamed it and created a new cache folder. i suspect the project_autoload.cache file caused the problem.
although running the dev env should omit the cahce it didn't reach that point in the code :-(

Thursday 18 February 2010

debug using Netbeans IDE on MAMP

Clicking the debug and hoping it will work without doing anything on Netbeans version 6.8 didn't prove itself. I had to follow the following tutorial http://wiki.netbeans.org/HowToConfigureXDebug to do the configuration.

I had to update the php.ini in the following folder /Applications/MAMP/conf/php5 to start the debug on Mac I use the CMD+F5

Monday 4 January 2010

symfony with WAMP on Windows 7

my Mac has a major problem with its trackpad so i have to give it away to the lab for a while and use a PC which equiped with Windoews 7. It means I have to install Symfony with WAMP. PEAR is required for this task, but it has a fault so I have to follow this post in order to be able to install it. I use sub version with 2 different usernames to sync between the development on the Mac and PC.