Skip to content
Sep 26 16

Fixing or installing Subversion SVN after upgrading to Mac OS Sierra

by Ben Hepworth

I upgraded to Mac OS Sierra the other day and my command line subversion broke. It sure seems like every time there is an update to the Mac OS, I spend a few days working through little kinks with the various programs that I use until everything stabilizes. After updating to Mac OS Sierra recently, I tried to run a standard svn up command and got the following error message:

$ svn up
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

The solution is pretty simple and also applies if you want to install command line SVN. It appears that the svn command line tools were uninstalled when I upgraded from Mac OS El Capitan to Mac OS Sierra. To install or reinstall the svn command line tools, run the following command:
xcode-select --install

After running this command, you’ll get a popup window prompting you to confirm installation of the XCode command line tools. You don’t have to install the entire 4GB+ installation of XCode in order to get command line tools like svn.

One more thing – when I was done installing, I tried to run a svn up and got the following error message:

tapir:$ svn up
svn: E155036: Please see the 'svn upgrade' command
svn: E155036: The working copy at '/Users/bhepworth/svn/trunk'
is too old (format 29) to work with client version '1.9.4 (r1740329)' (expects format 31). You need to upgrade the working copy first.

I went into the root of the trunk that I had checked out and ran the command:

svn upgrade

After that, I was able to update from svn:

tapir:$ svn upgrade
Upgraded '.'
tapir:$ svn up
Updating '.':
U share/scripts/deploy/deployBuild.sh
Updated to revision 1372.

I hope this helps you out! Every time Apple upgrades their OS, there are several kinks to work though. Luckily this one was a fairly easy fix.

Here is a quick youtube video I made that shows this fix in action:

~Ben

Aug 15 16

Turning Off Apple Live Photos

by Ben Hepworth

Why, oh why, would Apple introduce Live Photos with iOS 9? In my opinion it is one of the worst decisions ever made by Apple. Phil, come on. You are definitely smarter than that. Why would you want a small video clip with every single photo you take that includes audio? Before you read any further, please turn off Live Photos on your iPhone. Launching the camera app and click the yellow circle that is between the HDR and Timer button.

I made a quick video to show how to do this as well:

I discovered this by accident when I had posted a picture to Facebook. It had this yellow circle on it and said something like “Live Photo”.

I was like, “um, what’s that?”

I did a little Googling and found out that for some reason Apple thought it would be a good idea to turn still photos into “unforgettable living memories” that include what happened right before and right after the photo, INCLUDING AUDIO. I held down my finger on the picture, and sure enough, it was a mini video with audio.

Now there are tons of people who think they are sharing a photo with someone on Facebook, text, or whatever social media platform you prefer, when they are actually sending a small video – let me repeat – THAT INCLUDES AUDIO.

WTF Apple!

Talk about a privacy issue. Not to mention the fact that Apple turned it on by default for everyone when they updated to iOS 9. This should be an “opt-in” feature, not an “opt-out” feature. Yes, if you read about all of the features ahead of time, you could have know about this and been on the lookout for it – but who does that? I think I vaguely remember them announcing it, but it was one of those “um, ok – what’s the use case for that” kinda moments during the Apple event of Sep 2015.

Do you agree? The only valid use case I’ve found is one that my son showed me where you can take a live photo and put that as your lock screen. Then your lockscreen comes to life everytime you unlock it. Big fat whoop-dee-doo! I’ve waited 9 iOS releases for this feature – woohoo! Seriously though, what if you were having some sort of private conversation while snapping a quick photo and then sent it to a friend, not realizing that your audio was captured too? This one is almost as bad as the “Siri raise to speak” that was introduced in iOS 8…but that’s another topic for another blog post.

Peace out – and turn off your Live Photos for crying out loud!

Jun 27 16

The Best Way to Delete Old WordPress Revisions

by Ben Hepworth

By default, WordPress stores every modification to a post in a separate revision. The idea is that you can roll back to a previous revision. The problem with that, though, is that all of these old revisions can clog up your database and slow it down significantly. For my wife’s blog, her WordPress Admin was running very slow. She had tens of thousands of old revisions. I did a bunch of googling and there are several different ways posted on the internet on how to do this. There is also a WordPress plugin to do this, but I just wanted to use the build-in way of deleting revisions without having to run some database hack or load a plugin.

The problem with removing old posts is that the metadata is stored in multiple tables across the WordPress database. In order to ensure that all necessary rows are removed from all tables, you can call the wp_delete_post WordPress API. It is a native method in WordPress that handles the cleanup of all the necessary data everywhere in the database.

In pseudocode, this is what you do:

  1. Load WordPress Config so you have access to the wp_delete_post method
  2. Query the database and get the list of old revisions
  3. Loop through the list of revisions and call wp_delete_post for each one

Here is the code for the script:

<?php
require_once('WP_ROOT/wp-load.php');

$counter=0;

$post_revisions = $wpdb->get_results(
"SELECT `ID` AS revision_id
,`POST_TITLE` AS post_title
FROM ($wpdb->posts)
WHERE `post_type` = 'revision'
ORDER BY `ID` DESC"
);

foreach($post_revisions as $post)
{
echo "{$post->revision_id} : {$post->post_title}\n";
wp_delete_post($post->revision_id,true);
$counter++;
}
echo "Deleted $counter revisions\n";
?>

The only thing you should have to modify in this script is <> and replace it with the full path to the root directory of your wordpress install. If you’re not sure where this is, SSH into your server and run the command:
find . -name "wp-load.php"

This will tell you where the wp-load.php file is located and will give you access to the internal WordPress APIs.

Save the script to a file called deleteOldRevisions.php. Then, to execute it, run the following command from within the same directory where the script is located:

php -f deleteOldRevisions.php

Now, let’s break down what the script is doing:
require_once('WP_ROOT/wp-load.php');
This line loads the wp libraries so that you have access to the wp_delete_post method. We then set a counter variable so we can count how many revisions we end up deleting:
$counter=0;
We then query the database for all posts that are of type revision. We return the ID to pass into the wp_delete_post method and the post_title for a nice output to the screen when running.
$post_revisions = $wpdb->get_results(
"SELECT `ID` AS revision_id
,`POST_TITLE` AS post_title
FROM ($wpdb->posts)
WHERE `post_type` = 'revision'
ORDER BY `ID` DESC"
);

This returns an array that is now stored in the $post_revisions variable. We then loop through the $post_revisions variable and call wp_delete_post against each one. The echo we print before calling the method so that we can see which post revision it is deleting. The counter at the end increments the counter for how many revisions we are deleting.
foreach($post_revisions as $post)
{
echo "{$post->revision_id} : {$post->post_title}\n";
wp_delete_post($post->revision_id,true);
$counter++;
}

Then, last but not least, we print how many revisions were deleted by printing the $counter variable:
echo "Deleted $counter revisions\n";

This method of removing old posts is the safest because you are getting down at the core functions that are built and maintained by the WordPress team. Once I ran this on my wife’s server, her WordPress Admin sped up significantly. Before it would sometimes take 30 seconds to a minute just to save a post. Now it is almost instantaneous. Good luck!