Our office cleaner doesn’t vote. I think I know why.

Ever noticed that there’s a group of people who don’t vote? Good people, by and large… but they don’t vote. Eventually, I think I worked it out.

Ever noticed that there’s a group of people who don’t vote? Good people, by and large… but they don’t vote.

I noticed this during post-referendum chats with our office cleaners. Almost all of them said they didn’t vote. One said she voted for who her dad told her to vote for. I was a bit taken aback.

“But surely if you don’t vote, your interests won’t get looked after?” I asked.

One looked at me and snorted, “Like that happens! Doesn’t matter who gets in, they’re all the same!”

Sounds like a stereotype.

At the time, I wasn’t politically active. Now I am. The time before June 2016 is simply stated as “before the referendum” around here and with most people I know. As referendums go, it dwarfed all others. The Referendum, it should be. Because at that moment, a lot of things changed.

And, unusually, a lot of people voted. They voted for a change, and they were told it would make the NHS better and leave the country with more money.

I was deeply upset. I kept arguing with the hardcore Leavers, and then, in private, a friend sent me this message:

I’ve read a lot of what you have shared about the referendum, and as I leave voter I now fear I have made the wrong decision. I didn’t envisage the racial attacks that have since occurred, and did not vote out on the basis of immigration. I come across some of these people in work, and you then realise these are just normal and friendly people on the whole. I don’t have a great knowledge of politics and this is dangerous, as we all have the option to vote. I almost never voted, as had no strong bias to either side. I guess I’m trying to say your passion for remain has made me sit back and look at things from other people’s views. I can see you want the best for people. I wish I realised sooner, although it wouldn’t have changed the result.

Thing is, a lot of people realising sooner would have changed the result.

But people like me… we voted. But we didn’t try, did we? I know I didn’t protest, or man a stand in the streets. Had it too easy, you see. I thought others were doing it all anyway. Different people.

Let’s go back to our cleaner. Why didn’t she vote? Because she didn’t feel like she made a difference. Like she was going to get the shitty, difficult end of the stick either way. Not only that, but politics felt unreachable to her.

The Referendum got more people engaged, largely because a simple promise was made. £350m more for the NHS.

And people, even in post-Brexit Halton are still worried about the NHS. Here’s a local survey I did about concerns – sample size not massive at 67, but it’s enough to be a reasonable representation for the Halton area.

NHS is important. People worry about it. Because ultimately, we all get some sort of health problem at some point in our lives. Or our kids do. And we hear the stories of bankruptcies faced by US citizens due to their harsh private healthcare system.

Then Brexit and UK stability came in highly. And education. These are people’s primary concerns. I was actually surprised how few were worried about the benefits system, but then unlike the popular image of the North, most people aren’t substantially dependent on benefits. At least not in Widnes and Runcorn. So it’s not their biggest priority.

But let’s get back to our cleaner. Why doesn’t she* vote?

Unfortunately she couldn’t articulate it.

So I decided to remember what it was like when I was young, skint and facing homelessness. At no point did it occur to me to contact a councillor or my MP to see what could be done. They were distant people. Different people. Like teachers. I remember the shock and surprise when I learned that teachers had to go to the toilet! Yes really – they too need a wee sometimes. Amazeballs.

When you’re relatively naive, you don’t see the world all that clearly. Business-people are different. Asian people are different. People from the next town along… are different. It doesn’t matter. If you don’t know people, they’re different.

And most people don’t really know their local political parties. In the thirty years during which I’ve been able to vote, I’ve only heard from politicians during elections. I have never ever spoken to one on the doorstep. Except for one short period when I lived in Garston and my MP was David Alton. Now, David Alton has some peculiar views that I disagree with, but he’s a Liberal Democrat, now a Lord, and his councillors would drop in these weird Focus newsletters to the house. And I’d read them! I learned about what was going on in the area. They even had contact details so I could get in touch! They reached out… to me! Weird. But I realised, all politicians should try to do this. Push out their messages.

Then I moved back to Widnes.

And never, ever heard from a politician. Except during elections.

Sure, sometimes they’d say something in the local papers. But nothing relevant to me. Nothing that would fix my problem of living in a shitty shared house. Nothing that would make it easier for me to get a decent home. My parents had been able to get a council house, but it was denied to me. And I couldn’t save enough for a deposit on a house. It didn’t help that I wasn’t great with money either (credit card advertising has a lot to answer for!). But just being a young man, trying to run a car to get to work, renting a room, feeding myself, clothing myself and so on was sometimes tough. And nothing I ever saw from a politician made much impact on me.

Then I got older. And richer. Slowly but surely I made more money. I became a freelancer and discovered a piece of legislation might affect me – IR35. It wasn’t a massive issue, but it affected me. When politics affects you, you get to know stuff.

But working people are looked after by Labour, right?

I used to think that. Many people I knew voted Labour. Always voted Labour. Unquestioningly. I didn’t get it until I learned more about how unions work. Then I realised that unions and Labour are tied at the hip. Which is fine. The Labour Movement was what Labour was about, and it was massively important to the working man. Did a brilliant job.

Sadly, some unions got a bit giddy on power and decided to have battles to get more power. Which is a shame. They’d succeeded at getting working wages and privileges to a good point. They couldn’t see that some of those privileges were unaffordable in the long term. They simply had to keep them. At all cost.

That led to an interesting thing happening. Large organisations such as public sector, NHS and corporates started to outsource more and more functions. Our cleaners are employed by a company employed by our landlords. In many ways that can work. But truth is, that a cleaner at ICI or any other old large corporate like BA would have been exposed to unions, but our cleaners today are not. And even they were, many work for small companies disinterested in trade unions and employing fewer than 21 people. Others may not wish to join trade unions because they don’t like that they fund a political party.

So they’re not represented, really, by Labour. Labour mostly cares about people in trade unions and people who vote for them. People in unions are, for the most part, not the poorest part of society. In fact, I don’t think I know anyone in a union who earns less than about £30k a year once they’ve got five years experience in. That’s one reason why Labour are surprisingly reticent about taxing people in the OK to Quite Well Off groupings.

Nicked from the IFS website.

You could ask why the Lib Dems aren’t harder on the top 2%, but having worked with a lot of that range of people I can tell you that tax on income starts becoming optional at that level. If tax is too high they either put it into various perfectly legal vehicles (pensions and ISAs work well up to a limit) or they start looking keenly at moving cash offshore if possible. And taxing people too much can feel very unfair to those people. Get a £30k bonus and see £20k go to the government. They may not be right to feel like that, but that’s not the point. They feel unfairly treated and so get motivated to look for alternatives. As the IFS study reveals, the Lib Dems would almost certainly raise a lot more money with their tax changes than Labour would.

Labour is the party of the middle classes.

It’s true. Student fees position? Well, the current regime of student fee repayments introduced by the coalition means your repayments are lower if you earn under £35k than under the earlier top up fees system introduced by Labour.

Pensions position? Most of the people affected are people with good pension incomes. They are not poor people. Poor pensioners are considered in a secondary way, because they do at least vote. But most of the policies continue to leave wealthy pensioners paying far less in tax than young people on equivalent incomes.

The unions? Most union members earn good money. According to a study by the Department for Business, Innovation and Skills, trade union members were paid an average of £14.45-per-hour, 5p more than in 2012 (£28k/yr, equivalent to over £30k/yr today) – source

So who does represent the best interests of our cleaners?

I say the Liberal Democrats. A party I finally got involved with in 2016, after The Referendum. You’ve seen the chart above, and in the early years of coalition, before the Conservatives neutered them, they did a great job of taking low earners out of the tax system entirely. The UK’s Gini Coefficient improved for once!

For more information, see https://www.equalitytrust.org.uk/how-has-inequality-changed

But here’s the problem for the Liberal Democrats. Nobody really knows this. But our doorstep action, whilst being great on a local level, needs to talk about the bigger issues. Potholes and poorly kept parks are important, but these things rarely keep the bulk of people awake worrying. But the NHS does worry people. Brexit does worry people. Not being able to feed the kids does worry people. These issues need addressing. Loudly and proudly.

If you’re campaigning in the 2018 local elections, it’s important to share a little bit about what the Lib Dems mean for everybody. Not just campaign in the middle class areas and get squeezed, but in the poorer working class areas where we can make a big difference. Our policies are better for them. They just don’t know it. Not to tell them this is a disservice to them and to the Liberal Democrats. The working poor need us to help them. And if we reach out to them, maybe they’ll reach out to us. And our cleaners and their friends – they’re essential people, and once they get going they are awesome!

Feature Photo by Verne Ho on Unsplash

Blog “Reboot”

Hello – here’s the refreshed blog. I’ve decided to revert to a more typical blog format, after many months of soul searching on the issue. I previously had a layout based on a framework we used at interconnect/it for a couple of clients

But not only have I opted to switch to a blog layout, I’ve decided to use an off-the-shelf theme.  I’m now using Khoi Vinh‘s Basic Maths WordPress theme.

Why?

Well, it’s a lovely theme, for starters.  The typography is pretty good.  The archives page is brilliant (check it out) and should be the standard bearer for all themes archive pages.

But the real question for many, I suspect, is why I’m not using an interconnect/it designed theme.  Well, for starters, interconnect/it hasn’t produced an off-the-shelf theme in years.  It’s just not our business.  So rather than use a product of ours, we’d have to spend good and valuable time on creating a new theme.  And, well, why would we want to do that?

Lots of reasons, actually.  I could have a theme coded at the office that really shows off what we can do.  But the problem with that is that there’s not much need.  My blog is not an important one.  It isn’t about WordPress (most WP related content will be on our company site, not my personal one) and it just doesn’t get much traffic.

I run a business.  Its purpose is to make money, employ five people, and, with a bit of luck, turn a reasonable profit.  Its job is not to service my ego or make me look good.  A really good theme costs the equivalent of around £10k-£20k of chargeable time to design, code, test and implement.

Given that we’re turning work away, I thought “why bother?”  And decided to go shopping for something.

So What’s It Like?

It’s actually quite weird using somebody else’s theme.  I actually tried a few out and here are the things I learned that will hold us in good stead.

Themes don’t do enough to make life easy.

No really, they don’t.  One of interconnect/it’s biggest challenges is making sure that WP is as easy to use for clients as possible.  This means following standards, but it also means using some little tricks that help out – for example, registering and setting plenty of different image sizes, and setting/over-ruling whatever the media settings say.

Migrating WP content really sucks.

There’s a fundamental flaw with the default WP export/import.  If you have inline images, although the importer has the ability to download and attach the image in your new site it won’t change the links.  And if you do a search and replace, and your image sizes have changes, your lost.  Totally – the img tag will point to a file that doesn’t exist.

So what do you do?  Well, usually if I’m moving a site from one server to another, even switching domains, it’s a non-issue.  I have my tools.  But if you’re starting from fresh and working like an end-user would then you have to go through every single damn post in order to fix the images.  Every post with an image in it.  That’ll take a while.

If you’re really geeky, you’ll sort it, but it takes time.  Way too much time.  This kind of stuff needs to be sorted and it’s something we may look into as a contribution to the WP project.

Some Plugins Leave Lots of Crud

The reason for a reboot was that I felt that my site’s DB had been filled up with all sorts of crud.  Lots of plugins create tables, leave options, and so on.  Surplus tables have little impact, but they clutter the place up.  But options, lots and lots of them, do have a minor performance hit, and they add up.

Other plugins leave hooks, don’t deactivate properly and so on.  And over the years, I’d been through an awful lot of plugins.  The site hadn’t been redone since WP 2.0 had been set up on it.  I felt it was getting sluggish.

So… there are beautiful and amazing themes out there, and WP is wonderful, but there are little things that could make life just that bit better.  Better migration tools, a better system of managing images within content and their migration, and a better system for activating themes so that image sizes are better handled.

Is it a lot to ask?  Well, we’ll see what we can do about that!

mySQL Database Search & Replace With Serialized PHP [Updated]

Ever needed to migrate a database to a new server or website (especially with WordPress and other PHP applications) and been stuck because when you do a search and replace some of the data seems to get corrupted?

Please note that a newer version of this code is now available from my Interconnect’s site over at https://interconnectit.com/search-and-replace-for-wordpress-databases/ 

Ever needed to migrate a database to a new server or website (especially with WordPress and other PHP applications) and been stuck because when you do a search and replace some of the data seems to get corrupted?

Serialized PHP Arrays Cause Problems

In PHP one of the easiest ways of storing an array in a database is to use the serialize function.  Works a treat, but the downside is that you’re not storing data with a cross platform method.  In many product development environments this would get you a stern talking to, but in the world of web development where deadlines are tight and betas are the norm, this seems to be overlooked somewhat.

So what we have are tables full of data that can’t be easily edited by hand.  For example:

;a:3:{s:5:"title";s:17:"This Week\'s Poll";s:18:"poll_multiplepolls";s:0:"";s:14:"multiple_polls";N;}

Say you had thousands of records like the one above, and the word ‘multiple’ needs to be changed to ‘happy’.  Two bits would change – poll_multiplepolls would now read poll_happypolls and multiple_polls would read happy_polls.  In both cases you would have three characters fewer to deal with.

Fine, you may think, but you can only do the change by hand because where it says s:18:"poll_multiplepolls" it now has to say s:15:"poll_happypolls" – see the difference?  S18 spells out the length of the following string, and it has to be changed to s:15

I’ll say right now, that that was a pain.  For simple arrays I wrote the straightforward PHP Serialization fixer code, which got me out of many a pickle – do the search and replace without worrying, and then run the script.  Fixed about 90% of problems.

Multidimensional Array Problem

Sadly those 10% of problems left were a real pain.  I needed something more robust.  Something more powerful.  And finally today it was a Bank Holiday in the UK – that means no phone calls… I could have a quiet day of coding and concentrate on the best solution to this problem.

What I’ve done is to write a database search and replace utility in PHP that scans through an entire database (so use with care!) which is designed for developers to use on database migrations.  It’s definitely not what you’d call an end-user tool, though I may sanitize it at some point and turn it into an easy to use WordPress plugin.  Thing is – this is dangerous code – sometimes I think it’s better to make it deliberately a bit tricky, don’t you?

It’s not that bad though – if you can manually install WordPress, you can easily configure the database connection settings.

What the code does is to look at the database, analyse the tables, columns and keys, and then starts reading through it.  It will attempt to unserialize any data it finds, and if it succeeds it will modify that data then reserialize it and pop it back in the database where it found it.  If it finds unserialized data it will still carry out the search and replace.

Use in WordPress

In most WordPress migrations you tend to have the primary problem of changing the domain name entries in content, settings and widgets – you simply need to put in the $search_for string the old domain address (including the http if it’s there) as seen on the database, and the new one into $replace_with.  Then put this script onto your server, and run it by visiting it in your browser or inputting the appropriate command line – depending on your server configuration.

Other things you may want to check are for plugins or themes that have made the mistake of storing the full server path to the installation – cFormsII does this, for example.  You will need to find out your old and new server paths and use those, in full, for another iteration of this script.

After less than a second of running, you should have a freshly edited database.  It may take a little longer on slow or share hosting, or if you have a very large database, but on my laptop I can manage around 60,000 items of data per second.

I’ve just used the script to migrate, in its entirety, with content, settings, 87 widgets (yes, really!) and hundreds of images to my localhost server.  It took moments, and the site is perfectly preserved.

Search and Replace Database download.
download file

Search and Replace Database download

BIG WARNING: I take no responsibility for what this code does to your data. Use it at your own risk. Test it. Be careful. OK? Here in the North we might describe the code as being as “Rough as a badger’s arse.” Never felt a badger’s arse, but I’ll take their word for it.

PHP Serialization Fix for WordPress Migrations (& other applications like Expression Engine)

Serialization of data loaded into an SQL table is a dreadful thing and makes WordPress migrations harder than they should be, but it happens and so we must deal with it. I’ve knocked up a rough and ready bit of code which does its best to resolve the problem.

When you move a WordPress blog from one folder to another, or from one site to another, you normally use the export/import functionality.

This is fine for normal blogs, but say you’ve developed a new website and set it up on your local machine – the URL for the site may be something like http://localhost/devsite and the live URL will be something like https://davidcoveney.com – you won’t want to set up all the theme options, site options, plugin options and so on all over again.

A different kind of migration - public domain from Wikipedia Commons
A different kind of migration – public domain from Wikipedia Commons

Instead, a theoretically simple approach is to do a database dump, a search and replace for all references to server paths and URLs, and then reimport that data in the new location.

Should work, but it often falls apart.

What happens is that in WordPress, its themes and its plugins, a lot of data is stored using a method known as serialization.  Now, in my opinion this breaks all known good practice around data – it’s language specific, it’s not relational even though it often could be, and it’s hard to edit by hand.

One particular problem is that if you change the length of the data in a serialised string you have to change the length declared in the generated string.

That’s very painful when you have hundreds of the fields.

So, because I’d found this painful I decided to knock together a quick application to at least reduce the amount of editing I had to do.  You just do your search and replace, forget about the serialized string lengths, upload your data to the new database, and run this script.

Warning: I haven’t got it to work for widgets and cForms II yet, but the latter has some export functionality anyway, which takes that particular pain away if you plan ahead.  In the meantime, feel free to play with the attached file.  You use it at your own risk, of course.

To use it, download the file linked in this post, extract it, open the file, edit the connection settings, tell it the table you want to scan through, the column, and the unique key field.  If you somehow manage to have more than one unique key to deal with (you shouldn’t, but then it surprises me what people manage to code up), then you’ll have to modify the code accordingly.  Once done, make sure you have a backup of that table, and execute the php – either at the command line or through the browser. License is WTFPL, and if you’d like to improve the code, please do and I’ll host the new version.

Serialization-fixer.zip download.
download file

Serialization-fixer.zip download

BIG WARNING: I take no responsibility for what this code does to your data. Use it at your own risk. Test it. Be careful. OK? Here in the North we might describe the code as being as “Rough as a badger’s arse.” Never felt a badger’s arse, but I’ll take their word for it.

Resolving WordPress Migration Issue

I’m posting this for the benefit of anyone who experiences a similar problem to mine when moving WordPress from a directory into the web’s root directory.

What happened was that many links and pictures, some placed in there by plugins, others simply links that were typed in, had failed.

I realised that although I’d followed the migration instructions, a lot of things were left poorly sorted. A quick run through of all the tables showed where values were left incorrectly set. To fix this I wrote the following SQL statements and applied them to my database:

update wp_posts set guid = replace(guid,”/wordpress”,””);

update wp_postmeta set meta_value = replace(meta_value,”/wordpress”,””);

update wp_options set option_value = replace(option_value,”/wordpress”,””);

update wp_posts set post_content = replace(post_content,”/wordpress”,””);

These worked a treat.

To use this yourself I’ve done a version below that you can edit – simply replace $$$olddir$$$ with your old directory name (in my case wordpress) and replace $$$newdir$$$ with your new directory name. If your new directory is the root, remove the / at the beginning of each $$$newdir$$$ – see my example above.

A couple of warnings though – first take a backup of your database! Then think carefully – if you don’t know what you’re doing you may well be advised in seeking someone out who does.
update wp_posts set guid = replace(guid,”/$$$olddir$$$”,”/$$$newdir$$$”);

update wp_postmeta set meta_value = replace(meta_value,”/$$$olddir$$$”,”$$$newdir$$$”);

update wp_options set option_value = replace(option_value,”/$$$olddir$$$”,”$$$newdir$$$”);

update wp_posts set post_content = replace(post_content,”/$$$olddir$$$”,”$$$newdir$$$”);

Good luck and have fun!