Category Archives: Programming

WordPress multi-site

I’ve been working on setting up a new set of WP sites on my servers and ran into a funky problem I wasn’t able to solve (initially) or find any other documented solutions out there.

I’m using a plugin called ‘WordPress MU Domain Mapping‘ and I’d followed the install instructions.  However, when I would visit the ‘Domain Mapping Configuration’ page in my Setting tab I’d always see a message at the top of the page ‘Domain mapping database table created.’.  This message appeared every time I went to that page.

Now some googling did find other folks who were having that message always appear, and it seemed that it was because the table wasn’t actually being created.  Things such as permissions and access were pointed out and I’d checked all that and every thing seemed in order.  I could even create a new table using phpMyAdmin with the same user WP used, so I knew the user was setup correctly.

Checking out the tables with phpMyAdmin, I could see that the ‘domain_mapping_logins’ table had been created, but the ‘domain_mapping’ table didn’t exist, and this was obviously needed and the root of the error.  I turned on WP debugging, hoping I’d see an error message about the table not being created, but no such luck.

In the end, I solved it by exporting a working table from another WP install I had, and then imported it via phpMyAdmin. This created the table for me, and all was well with the world!

I’d like to know why the plugin was unable to create the required table, but that’s a project for another day I think.  The table should have been created by the following code:

if ( $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->dmtable}'") != $wpdb->dmtable ) {
			$wpdb->query( "CREATE TABLE IF NOT EXISTS `{$wpdb->dmtable}` (
				`id` bigint(20) NOT NULL auto_increment,
				`blog_id` bigint(20) NOT NULL,
				`domain` varchar(255) NOT NULL,
				`active` tinyint(4) default '1',
				PRIMARY KEY  (`id`),
				KEY `blog_id` (`blog_id`,`domain`,`active`)
			);" );
			$created = 1;
		}

Which is similar, but with obvious differences from the code that creates the ‘domain_mapping_logins’ table:

if ( $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->dmtablelogins}'") != $wpdb->dmtablelogins ) {
			$wpdb->query( "CREATE TABLE IF NOT EXISTS `{$wpdb->dmtablelogins}` (
				`id` varchar(32) NOT NULL,
				`user_id` bigint(20) NOT NULL,
				`blog_id` bigint(20) NOT NULL,
				`t` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
				PRIMARY KEY  (`id`)
			);" );
			$created = 1;
		}

Update: Figured out what was going on:  The version of mysql running on my webserver is 32bit and I dug into the actual error.  It turns out that the ‘domain’ field exceeded the maximum length of a key (1,000 bytes).  This is because UTF8 is used as the default encoding, which allows basically 9 bytes per character, so the domain can be 2,295 bytes long.  To remedy this, I added the following to the SQL statement:

ENGINE=InnoDB DEFAULT CHARSET=latin1;

Which keeps the field length under the 1,000 byte limit and allows the field to be created.

Javascript and new way of thinking!

It’s been quite some time since I did any Javascript programming, and it’s hard to start thinking in an unstructured way again.  One of JS’s peculiar nuances is the ability to declare a property on an object by just assigning it! After working with C++/Obj C/C# and having to declare everything up front this takes a new way of thinking.

For instance, with the Cocos2D-X-JS the pattern of their script declaration didn’t make it obvious on where or how to declare variables that will persist between function calls.  Being used to pre-declaring everything, I stuck a few ‘var’ statements at the top of the file, before the ‘extends’ stuff starts.  This works, but looks a bit messy.

var self,canvas;

cc.Class({
extends: cc.Component,
...

Of course, with JS, there’s no need to declare variables, just assign them as a property and they’re created for you!  Of course, you’ll not get the benefit of type checking and even checking if the var you’re using is spelt the same as the one you declared, but you can’t have everything!

Time to expand my horizons!

I’m going to check out http://www.cocos2d-x.org/ as a cross platform language for some utility work that needs to be deployed on both Android & iOS.  I’d prefer to use Unity, but the client I’m talking with doesn’t want to spring for a full Unity license (turns out you can’t just buy the monthly sub for 4 months, release a product and then cancel…).

Can’t wait – especially given how much I love Javascript </sarcasm>.

 

Parse shutting down…

Got another email reminder that Parse is shutting down.  It’s quite disappointing that they’re shuttering this service after all the promotions and pushing it got – I used it for some ‘free’ logging on various apps but never really used it for anything serious.  There always seemed to be a huge security gap – they gave you all these keys and secret keys to access your database, but they seemed to be pretty easy to find in an app, thus exposing the database to anyone who really wanted to see what was going on.

Can’t say I’ll miss them – though I’m sure there are others out there who are seriously annoyed by them going away.

Accessing a Struct as a SerializedProperty

I’m working on a custom editor extension that will support a palatalized color system for Unity3D UI elements (both NGUI and new Unity UI).  As part of this process I’m learning how to create custom Inspectors and PropertyDrawers.

I added a struct to one of my objects that replaced a simple Int, and I needed to be able to access the struct from an inspector.  Normally, to access the Int you’d create a SerializedProperty that would point to the public serialized int and then access the value with the .intValue property.

Once I updated the class to use a custom struct, the inspector no longer worked (obviously) and I needed to pull values from this struct instead of a primitive type.

The struct is defined as:

    [Serializable]
    public struct PBMapperIndex
    {
        public int intValue;
        public string indexName;
    }

It contains a string and an int, and most importantly, it’s marked as serializable. This means Unity will keep the struct as a serializable object.

To access it in the custom inspector, I used the following:

    SerializedProperty tintProp = serializedObject.FindProperty(tintIndex);

Where tinitIndex is declared as a public PBMapperIndex in my class.

Then to drill down and get the intValue for this property I used:

        SerializedProperty ixProp = tintProp.FindPropertyRelative(intValue);
        int  index = ixProp.intValue;

Two keys, mark the original struct as [Serializable] and then used FindPropertyRelative to pull out the ‘child’ property.