Piotras' blog

When metadata creator is empty

Posted on 2008-05-23 16:49:48 EEST.

Quite major bug has been found today. 1.8.7 Midgard release doesn't populate metadata_creator guid. Midgard news page has a note about this.

I wrote additional script which should help with database upgrade if needed:

#!/bin/sh

DB="midgard"
MYSQLCMD="/usr/bin/mysql"

THEADER="Tables_in_${DB}"
MIDGARD_TABLES=`$MYSQLCMD -D $DB -e 'show tables' | grep -Ev '(_i\s*\|?\s*$)|repligard|sitegroup|Tables_in_.+'`

for TABLE in $MIDGARD_TABLES; do

    QUERY="UPDATE ${TABLE} SET metadata_creator=REPLACE(metadata_authors, '|' ,'')  WHERE metadata_creator='' AND metadata_authors<>'' AND metadata_authors<>'||' AND LENGTH(metadata_authors) < 39"
    echo "Fixing table: ${TABLE}"
    $MYSQLCMD -D ${DB} -e "${QUERY}"

    echo "Looking for multiple authors"
    QUERY="SELECT guid from ${TABLE} WHERE LENGTH(metadata_authors) > 38 AND metadata_creator='' AND metadata_authors<>'||' AND metadata_authors<>''"
    $MYSQLCMD -D ${DB} -e "${QUERY}"

done

Voices in my head

Posted on 2008-05-20 01:15:37 EEST.

rs.jpg

It was last sunday.  And there are still "Voices in my head". Riverside guys made real show in best studio in Poland, and it's quite obvious as they recorded live DVD at the same time. Probably this DVD is going to be in stores this winter. Damn!  So long time. 

First time I heared them in LizardKing pub in Łódź. It was February, this Year. Since then, I am addicted. There is no single word that can be said about this event. No one seems to want to comment it. Only few of them appears from time to time on different forums: perfect.  

"Join in the shadow dance"

PEAR registry, where are you?

Posted on 2008-05-19 15:19:13 EEST.

I wrote this simple script to clear my local pear setup and to have clean pear instalation for Midgard.

apt-get remove php-pear
rm -rf /usr/share/php/PEAR
rm /root/.pearrc
rm -rf /etc/pear
rm -rf /tmp/pear
apt-get -y install php-pear

So, when I cleaned my pear ,imagine, how much confused I was when I saw this in my terminal:

MIDGARD SETUP: Role_Web - installed: 1.1.1 available: 1.1.1

wtf?

pear list-files pearified/role_web
Installed Files For pearified/role_web
======================================
Type Install Path
php  /usr/share/php/PEAR/Installer/Role/Web.php
php  /usr/share/php/PEAR/Installer/Role/Web.xml
php  /usr/share/php/Pearified/Role/Web/setup.php

ls -l /usr/share/php/PEAR/Installer/Role/Web.php
ls: /usr/share/php/PEAR/Installer/Role/Web.php: No such file or directory

PEAR registry...where are you?

Updated: I found registry and channel files under /usr/share/php. So on debian these two lines must be added additionally:

rm -rf /usr/share/php/.registry 
rm -rf /usr/share/php/.channels

MySQL doesn't support TEXT type

Posted on 2008-05-08 17:46:56 EEST.

Yes, it does not. But you could say:

Oh, yes indeed. They mention "The four TEXT types", but it doesn't seem to help me even a bit. Why? Bergie and Solt reported quite weird issue. Text value ( text type in database ) has been returned as array on PHP bindings for Midgard.

I started to investigate it from the very beginning, to catch why text type becomes an array:

  1. Parameter class has value member of longtext type.
  2. Database column for this property has longtext column type.
  3. GDA library with MySQL provider uses MySQL column types to determine what value should be initialized on C level.
  4. GDA gets BLOB type.
  5. GDA initializes its own GdaBinary type( GdaBinary is GBoxed derived type ).
  6. PHP bindings for midgard and especially GValue and zval converter gets boxed type.
  7. We support only array type of gboxed one so zend array is initialized and returned.

Not easy to fetch at first glance, isn't it?

I was wondering and checked GDA sources ,and indeed MySQL provider implementation is not aware of something like TEXT or LONGTEXT. Later on I checked MySQL's headers and supported column types.

So, there is support for strings (char and varchar):

  • MYSQL_TYPE_VAR_STRING
  • MYSQL_TYPE_STRING

And for blobs:

  • MYSQL_TYPE_TINY_BLOB
  • MYSQL_TYPE_MEDIUM_BLOB
  • MYSQL_TYPE_LONG_BLOB
  • MYSQL_TYPE_BLOB

And what about TEXT and LONGTEXT? And what about those 4 mentioned text types? Nothing. There's completely nothing. How can I know if retrieved data is binary or text type then? Use randomized type? Maybe for you blob type is the same as longtext, but for me plain text book stored in field is quite different thing than compressed image file.

Midgard with Lighttpd

Posted on 2008-04-22 11:05:55 EEST.

Please. Read the whole this simple howto. It's adressed for developers who would like to have Midgard and Midgard2 available as web services on the same machine. Of course, you may still install or compile Apache 1.3 as the second web server.

First of all you need to install and configure Lighttpd web serwer. On debian I installed it using apt-get:

apt-get install lighttpd

Do not forget to stop Apache before installing lighttpd. If you do not, dpkg will return with failure status as lighttpd tries to bind to port 80 by default when package is installed.

Also, you need to have php5 compiled with fast-cgi support. Again, on debian install it quickly:

apt-get instal php5-cgi

Edit cgi's php.ini file (/etc/php5/cgi/php.ini), and add midgard support:

extension=midgard2.so
midgard.configuration="midgard"
midgard.http="on"

Then configure your new web server. I found these two sites very helpful to configue lighttpd server:

Later on, you need to install Midgard2 from trunk, which is going to be released as alpha2 soon.

In my case, I configured lighttpd with these options:

server.port = 81

Just to have both, Apache and lighttpd available. You may of course use different port if you like.

Enable required modules, mod_rewrite and mod_fastcgi:

server.modules              = (
        "mod_access",
        "mod_alias",
        "mod_accesslog",
        "mod_compress",
        "mod_rewrite",
        "mod_fastcgi",
)

Configure fastcgi:

fastcgi.server = (
    ".php" => (
            "localhost" =>
                    (
                            "socket" => "/tmp/php-fastcgi.socket",
                            "bin-path" => "/usr/bin/php5-cgi"
                    )
            )
    )

Configure virtual host:

$HTTP["host"] == "myhost" {
    server.port = 81
    server.document-root = "/var/lib/midgard/vhosts/myhost/8080"
    url.rewrite-once = ( "^(.*)\.*" => "midgard-root.php" )
}

I use virtual host on 8080 port with Apache, so I wanted to re use its DocumentRoot. You will change it of course, depending on your needs.

midgard-root.php file should be copied or symlinked from midcom's git repository. I do not have to remind that midcom itself should be installed and ready to use.

Do something you should never do in real life. It seems that lighttpd drops root privileges too quickly and php module is loaded with configured user and group privileges. At least I couldn't manage to open root's configuration files from system configuration directory( which is easily done with Apache ). To establish database connection(s) you must have all secret configuratoin readable for the whole world.

chmod 644 /etc/midgard-2.0/conf.d/*

After this, restart lighttpd:

/etc/init.d/lighttpd restart

And open http://myhost:81 with your favourite browser. If all went fine, you should have midcom's web page without style. Reason is that we do not make midcom-static exception in our hosts' rewrite condition.

MidCOM3 without apache module

Posted on 2008-04-11 17:15:07 EEST.

This is really HOT!

It's proof of concept to work with Midgard without its Apache module. And the concept is cool :) Especially with this lovely MidCOM3 screenshot.

Basics of midgard_dbus

Posted on 2008-04-08 13:55:41 EEST.

midgard_dbus API is very simple, but my approach was to make it just simple as possible. Basically we have two major methods of midgard_dbus:

  • constructor, which registers object at path
  • send, which asynchronously send message to object at given path

New initialized object doesn't do anything special. It just waits for any call to him and then emits "notified" signal, which you can connect callback to.

I tested simple code with midgard-php and midgard-python.

midgard_python "service":

import dbus.mainloop.glib
import _midgard as midgard

def mbus_callback(object, arg):
        print "Hi! I am midgard_dbus from midgard-python. I got message:"
        print object.get_message()

mbus = midgard.dbus("/midgard_article")
mbus.connect("notified", mbus_callback, "foo")

mainloop = gobject.MainLoop()
mainloop.run()

midgard-php "client":

$message = "Greetings from midgard-php!(" . mgd_version() . ") PHP ver." . phpversion();
midgard_dbus::send("/midgard_article", $message);

I started php script which immidietialy ended, and on midgard-python service's terminal I got this message:

Hi! I am midgard_dbus from midgard-python. I got message:
Greetings from midgard-php! (2.0alpha0) PHP ver.5.2.5-3

Probably the code will be soon ported to 1-9 branch, so I will be able to test midgard_dbus in Apache environment. But for now, basic idea looks fine and works fine. We just notify objects at path with particular message, and local proccess does the rest with connected callbacks.

Layout Copyright © 2006 Finnish Teleservice Center Ltd Oy - Site Powered by Midgard CMS