Archive for category Tips

Board migration – Discus 4.x to vBulletin

I just finished the initial trial migration of a Discus v4.x based board over to vBulletin.

Now, I’d like to write a few words on Discus. I cannot see why anyone looking to set up a new board would choose this software. It’s actually file based (!). Yes, you heard me. The posts, users and threads are stored in (plain) text files. I was quite surprised the first time I got around to checking out what I was supposed to migrate. If you head over to their site and check out a demo-site or two you’ll notice that the whole board seems a bit … unprofessional. It currently sells for 149 USD, which is quite amazing when you can get vBulletin for 180USD, or even phpBB for free. I went with vBulletin because they supported (at least partial) import from Discus, as well as the email based service in case I got stuck.

Now, the data migration. Upon purchasing vBulletin I got a migration utility called ImpEx which supports quite a number of boards to import from. Discus is listed as a tier 3 board, meaning it’s not actively supported anymore.. not a good sign, but still worth a shot.

Here is a quick recap of the required actions:

1. Download vBulletin and ImpEx from vBulletin.com
2. Create a new database for vBulletin
3. Install vBulletin as described here.
4. Install the ImpEx tool as described here.
5. Configure ImpEx as described here.
6. Run the ImpEx tool for Discus

Now, in step 6 there are some modules to import. Some of them runs in a matter of seconds, while others takes up to 10 minutes in my case. I’m not sure if the script actually refreshes, so one might want to up maximum execution time for PHP to be safe.

To my surprise everything went absolutely fine. Not a single hickup in the migration scripts. After the data was imported I followed the post-migrate instructions and did some data verification. Everything seemed to be present, but I was not able to see any threads in the forums. I could find them with searching, and when I opened a thread it clearly stated that it was belonging in the correct forum. After looking around for some time I discovered that the forums from Discus was now configured to act as categories. I solved this by going to Edit Forum -> Act as Forum and set it to Yes for each forum. When I got back to the forum listing everything was in order.

The only things left is to move the forums around some, get a proper language pack and some other minor adjustments. All in I’m quite satisfied with the whole process. Kudos to vBulletin.

, ,

2 Comments

Tip: What every programmer should know about memory

Some time ago a friend of mine tipped me about this article series called “What every programmer should know about memory” written by Ulrich Drepper (lead contributor and maintainer of glib). I just recently came around to start reading it. This is a 100 page long text which covers computer memory in detail, with focus on how software interacts with memory. From RAM to CPU caches the text moves on to tips on how we as programmers can improve our code when it comes to memory management and performance. A really good read which I suggest every programmer should check out.

Technorati Tags: , ,

3 Comments

Simple config management for PHP

When doing complex applications it’s often nice to have some sort of system for handling settings. PHP has a nice function called parse_ini_file which can be used to create a basic but still usable setting file feature. A simple class which loads the configuration file and offers some methods to retrieve the values for a given key is all that’s needed. The example I’m providing is pretty basic, but it’s still very usable and can be added to almost any application.

First, we need to create a file to hold the settings. It’s ordinary plaintext and follows the INI format.

Here is a quick sample of some key / value pairs:

[general]
locale = no_NO
company.name = MyCompany

datasource.host = localhost
datasource.database = mydb
datasource.username = user
datasource.password = 1234

The class for accessing the file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class MyConfigClass{
  protected $config;
 
    public function __construct()
    {
      $this->config = parse_ini_file('../conf/myapp.ini');
 
    }
 
    public function getConfig($key = null)
    {
      if($key !== null)
      {
        if(isset($this->config[$key]))
        {
          return $this->config[$key];
        }
        else
        {
          throw new Exception("Unknown key '$key' in configuration");
        }
      }
      else
      {
        return $this->config;
      }
    }
 
    public function setConfig($config)
    {
 
      $this->config = $config;
    }
}
 
?>

Usage:

1
2
3
$configManager = new MyConfigClass();
 
$value = $configManager->getConfig['datasource.host'];

Now, when working on larger application one usually have a application like class, and that’s a nice place to put this code. When using Prado I usually place the config code in the TApplication class.

Technorati Tags:

19 Comments

Firefox java problem with Ubuntu 8.04 Solved!

I’ve been struggling with lava support for Firefox after upgrading from Ubuntu 7.10 to 8.04. All I had to do was to remove the package called icedtea-gcjwebplugin. Now, I don’t know my way around Java anymore, but at least it did the trick. Worth a shot if you have problems.

Update:

John has some more information on this issue if the above didn’t do the trick:

I also needed to link to the new plugin….

cd /usr/lib/firefox-3.0/plugins$
sudo ln -s /usr/lib/jvm/java-6-sun/jre/plugin/i386/ns7/libjavaplugin_oji.so

Thanks John!

Technorati Tags: , ,

30 Comments

Handy online regex tool for PHP, Perl, JS and Python


A coworker of mine has been working on a ajax enabled regex tool which lets you evaluate regex expressions in several languages (including PHP PCRE and PHP POSIX) with instant results. You can choose which functions to use, such as match, match all, replace, split etc. It also offers some basic help and hints. It’s really handy when working on those painful expressions.

You can check it out at http://regex.larsolavtorvik.com/. Stop by his blog as well.

Technorati Tags: , , ,

12 Comments

Populate PDF templates with PHP / FPDF / FPDI


Ever wanted to generated PDF documents on the fly with PHP? Perhaps populate a standard contract with a customers name and address? FPDF and FPDI are two neat libraries which greatly helps when working with PDF files. FPDF is the main library for handling PDF files, while FPDI lets your import existing PDF documents into the FPDF documents. In the code sample I’ve prepared here I’m importing a PDF template document, writing some information to the document, then sending it to the “customer”. FPDF offers several neat ways to expose the generated document, such as a stream to the browser, a string, or just storing it to file. You can download PDF Sample code to test it.

Be sure to head on over to the FPDF site and FPDI site for more information on these two libs.

Related posts:
Generated PDFs over HTTPS with Internet Explorer

Technorati Tags: , ,

10 Comments

Google does a Selenium framework?


I just came across this post by Mike Henke, where he writes about a presentation from the Google Automating Testing Conference. Google is working on a framework based on Selenium which they use internally. The post contains some interesting slides in addition to a presentation video. I’ve embedded the video in this post for your convenience, but I suggest you give Mike a visit.

Update: Video removed, please check the links above.

Technorati Tags: , ,

1 Comment

Setting xsi:type for objects sent over SOAP (inheritance)

This post is pretty much a revamp of a previous post called “Working with X-Fire soap services and inheritance in PHP“. That title was a bit misleading, and not really that good when it came to providing a sample.

Let’s say we have a SOAP method called createCustomer(Customer c), and we have a base class called Customer, which has to subclasses, Person and Organization. Person has firstname, lastname, while Organization as orgname and orgid. Now, the createCustomer call accepts a object of the class Customer, and any derived classes.

When retrieving a Person / Organization over SOAP, PHP automatically creates instances of the correct classes, but when calling createCustomer, passing a Person / Organization it breaks. Out object is sent as a Customer, but with Person or Organization fields added. The SOAP server expects to find a xsi:type for the object we are sending to tell what kind of Customer it is. It seems like PHP does not set this itself (maybe it should?).

I spent quite some time looking for info on how to specify the xsi:type for the objects, and I finally came across SoapVar.

I created a base class which the SOAP classes extended. A method called pack is responsible for setting xsi:type.

(I’m very aware that my pasted code looks like a mess in this blog. I will fix that ASAP).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
class BaseClass{
  private  $namespace = "http://model.api.domain.com"; // from your WSDL
  protected function pack($obj){
    $class_name = get_class($obj);
    $namespace = "http://model.api.domain.com";
    $pack = new SoapVar($obj, XSD_STRING, "$class_name", $namespace);
    return $pack;
  }
}
 
class createCustomer extends BaseClass{
  public function setCustomer($customer){
    $this->customer = $this->pack($customer);
  }
}
 
$customer = new Person();
$customer->setName("John Doe");
 
$request = new createCustomer();
$request->setAccountID(123);
$request->setCustomer($customer);
 
$client->createCustomer($request);

That fixed the problems for me atleast.

PS: If your SOAP classes are prefixed you’ll need to strip the prefix in class_name when creating the SoapVar.

Related posts:

Technorati Tags: ,

 

1 Comment

Dying with grace – PHP’s register_shutdown_function

Update:

I guess I didn’t make the purpose quite clear here. This method will allow you to show custom error messages when PHP hits a fatal error. The shutdown function will always run.

Scripts tend to die, and that’s not usually nice. We do not want to show the user a fatal error nor a blank page (display errors off) . PHP has a function called register_shutdown_function which lets us set up a function which is called at execution shutdown. What this means is that our function will be executed when our script is done executing / dying and PHP execution is about to shut down. By setting up a variable to false at the start of our script, and setting it to true at the very end of the script we can have our shutdown function check if the script completed successfully or not. If our variable is still false we know that we never made it to the last line of our script, hence it died somewhere. I’ve prepared a very basic sample which shows how you can give the user some proper feedback if a fatal error should arise. You’d want to turn of display of fatal errors for this to look nice.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$clean = false;
function shutdown_func(){
  global $clean;
  if (!$clean){
    die("not a clean shutdown");
  }
}
 
register_shutdown_function('shutdown_func');
 
$a = 1;
$a = new FooClass(); // will fail with fatal
 
$clean = true;
?>

As you can see, the shutdown_func prints something if the clean variable isn’t set to true when the shutdown function runs. This should of course be wrapped in a class (and NOT use globals), and for something more usable I recommend checking EZ Components way of doing this.

7 Comments

Array problems with SOAP and PHP – Updated

This is a follow up to my post about array problems with SOAP and PHP. The scenario was that when an array with only one object was returned over SOAP the array was discarded and pointed straight to the single object.

Cmm was kind enough to tip me this PHP bug report, which explains that this is actually not a bug, but a feature.

To get arrays containing one single element, simply create the SoapClient as follows:

1
$x = new SoapClient($wsdl, array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

Related articles:

8 Comments