Using Grunt to test WordPress Upgrade changes

During the final moments of a WordPress release development cycle I was asked a very simple question:

How do I test the changes to src/wp-admin/includes/update-core.php before they’re committed to trunk?

One method that others have resorted to is to build a custom WordPress release zip and hack WordPress to always install from that custom zip file – It’s not hard to do that, but it’s a real pain when your development workflow includes testing things time and time again.  [note: I’ve used this method in the past, before Grunt was “a thing”]

So, here’s my current solution: Use grunt build and hit Update, something we all use already, coupled with WordPress’s own update routines!

The way that I do it, is that I apply the patch to /src/, and then alter class-wp-upgrader.php to use the local copy of update-core.php instead of the one from the zip file it’ll download, and then just hit Update on the dashboard.

This takes very little effort to pull off – below is an example of the code changes needed to cause it to abort a update early on with a custom message, all that’s left to do is to run grunt build and hit the update button! – Just make sure you’re in /build/ rather than /src/, as it could quickly lead to custom code going missing.. I know this from experience!

Index: src/wp-admin/includes/class-wp-upgrader.php
==================================================================
@@ class Core_Upgrader extends WP_Upgrader
 $working_dir = $this->unpack_package( $download );
 if ( is_wp_error($working_dir) )
 	return $working_dir;

 // Copy update-core.php from the new version into place.
-if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
+if ( false && !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
 	$wp_filesystem->delete($working_dir, true);
 	return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-admin/includes/update-core.php' );
 }
 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);

 require_once( ABSPATH . 'wp-admin/includes/update-core.php' );

Index: src/wp-admin/includes/update-core.php
==================================================================
  * @param string $from New release unzipped path.
  * @param string $to   Path to old WordPress installation.
  * @return WP_Error|null WP_Error on failure, null on success.
  */
 function update_core($from, $to) {
 	global $wp_filesystem, $_old_files, $_new_bundled_files, $wpdb;

+	// Demo code to show that this process works
+	echo "Hi! This is text to confirm that I'm using a custom update-core.php file during the update!";
+	die();
+
 	@set_time_limit( 300 );

A few frequently asked questions that have come up in the past with this method:

  1. Question: It’s still downloading the zip file from the internet though!
    Answer: Yes, it does. However my internet connections are usually fast enough that this isn’t a problem.
  2. Question: What if there’s other alterations needed in other update related files?
    Answer: It doesn’t actually matter, update-core.php is the only file from the zip that’s used during update, all the other files (WP_Upgrader / WP_Filesystem / etc) use what’s installed, they’re only overwritten once the update commences using the old code.
  3. Question: How do I stop it from redirecting after the update?
    Answer: When you find out, let me know!  I’ve resorted to simply adding a die(); after the debug code I’m using.
  4. Question: Why isn’t there a grunt task to build the WordPress zips?
    Answer: Haven’t needed one yet I guess? Why don’t you submit a patch on Trac for it? :)

WordCamp Brisbane 2015 – WordPress Conference

WordCamp Brisbane 2015 has been announced! May 30/31st at QUT in Gardens point. It seems like just yesterday that I wrote a post, but the reality is that the last few posts on this site have been WordCamp announcements.. Although I missed announcing WordCamp Sydney 2014, I’m happy to say, I’ve not missed my chance to post about WordCamp Brisbane 2015 :) What is a WordCamp?

WordCamps are casual, locally-organized conferences covering everything related to WordPress, the free and open source personal publishing software that powers over 75 million sites on the web. – http://central.wordcamp.org/about/

WordCamps are attended by people ranging from blogging newbies to professional WordPress developers and consultants, and usually combine scheduled programming with unconference sessions and other activities. – http://central.wordcamp.org/about/

What should I expect from a WordCamp? For more information about what to expect from a WordCamp, check out WordCamp Centra’s What to Expect page.

WordCamp Sydney 2012 – July 21-22

Please note: I’m not a WordCamp Sydney organiser, Any questions related to WordCamp Sydney should be directed towards their contact form. If you’re interested in WordPress in Sydney, also check out the WordPress Sydney meetup group.

Howdy folks,
So I don’t blog often, it’s a bad habit of mine, but it doesn’t mean I don’t love WordPress any less!

The number of WordPress professionals in Australia is forever increasing, how many are there? We don’t know – but what we do know, is that every time a WordCamp is held in Australia that up to 200 people jump at the opportunity to come out and meet other WordPress users, Designers, Developers, and even some of the crew who make using WordPress possible.

So I’m glad to be able to say, 2012 has brought with it yet another WordCamp, WordCamp Sydney, which is being held at the University of Sydney in July. I’m glad to be able to say I’ll be there, well really, I have to say, I’m rather looking forward to it!
(Did you know that the 2nd WordCamp to ever be held in Australia was WordCamp Australia held in Sydney in 2008?).

There’s not too much longer until the WordCamp is on top of us, so head over and check out their new site, talk to your friends about it, mention it to colleagues, friends and family, anyone who you think would be interested in a weekend of WordPress goodness – and don’t forget, WordCamp’s are not just for developers, they’re for users, designers and even those who don’t use WordPress, but are interested in the digital web we all work in.

WordCamp Sydney July 21-22, 2012

Me; WordPress; and the Future

As those at WordCamp Gold Coast recently found out(Wow, this past month has flown by!), I’m now listed on http://twitter.com/#!/automattic/automatticians/members!.

Yup. I’m an Automattician (Pst. That means I’ve been hired by Automattic)

So where does this leave my other projects:

  • My plugins will continue to be developed in my spare time.
  • My other random WordPressy projects may get some attention in my spare time, as they always have
  • I’m ceasing all development on WordPress.org to focus my efforts on WordPress.com
    ..just kidding, My involvement on WordPress.org will continue as it has in previous years, hopefully better than ever, whilst working on WordPress.org won’t be my day job, I’ll be able to give it the attention it deserves. WordPress.com was born out of WordPress.org, and I doubt I’d be anywhere near the first without the latter!
  • In other words – Life as normal.

Tonight marks the end of my 3 weeks Support Rotation my first week doing Development (It’s taken me a week to hit publish on this post..), from here on, I’ll be known as a Renewable Engineering Specialist, Yeah, you have to love the Tech. titles!

I’m quite proud to be able to say Automattic is my “place” of work, I’m looking forward to learning a whole lot more off the amazing people who I already know (and the many who I haven’t met) at Automattic – not that there’s too many to meet, with Automattic having just crossed the 100 employee mark, that’s not bad for a company who’s primary product handles over 250 million unique users per week. It’s also nice to see the Automattic population in Australia explode, up from 1 a month ago, to 4 of us!

Questions? :)
(better make them good ones.. so no questions on this ever-evolving design huh? You’ll be glad to know I’ve not been hired as a designer!)

PHP based mail server; Release Day

So the day has come, I’m a modern web developer come sysadmin. One thing that I have learn’t over time, is rely upon others for critical systems! as a result, I outsource Mail to Google Apps and DNS to Point HQ , they’re experts at both, they keep my email up 99.9% (or something) and my DNS systems running smoothly..

But being a web developer, I like tinkering with my web server configuration! As a result, I run a VPS for my http serving which combines a special blend of Nginx, Apache, PHP-fpm, mod_php and MySQL.. For the last 2 years this setup has been running awesome, but I’ve found one thing that was lacking.. being able to receive and act upon emails to my vps. With all mail being handled by Google Apps, I couldn’t just watch the local mailboxes.

The obvious way forward was to install a mail server onto my VPS to process incoming email. Long story short, email servers suck. While researching, I came up against the fact that every mail server out there was designed for being a proper mail server.. Not what I wanted, a server to process emails..

I could ramble, but skip to here if you don’t care about the back story above.


Today I give you: A PHP based Mail server, It’s written in pure PHP, it receives SMTP data on STDIN, and responds on STDOUT, perfect for use with xinetd.

I originally started out with code from:  http://perplexed.co.uk/545_php_smtp_server_for_receiving_emails.htm however, fast replaced it with a home grown version, and have now expanded further to today’s class based approach.

This isn’t, and hasn’t been, designed for high load that being said, It’s received over 5,000 spam emails last month with little impact upon the VPS.  (who knew that spam bots just connect to port 25 on random IP’s??)

This is designed for a single-user situation, since PHP is a scripting language running as a single user, this can’t switch to the correct users account for processing or anything.. Doesnt suit everyone.. but works

This relies upon an external application to handle the TCP -> Stream conversion, a future release might daemon itself and use sockets to accept connections, do some pcntl_fork()’ing for individual connections, and even posix_setuid() to set the effective user.. but that’s filed into the Future Release bucket.

There is no support at all. although, if you throw a comment on this post, I might respond if I’ve got time. hopefully it should be reasonably straight forward to understand.

Licensing is also left sketchy for now, See the mail-server.php header for a initial custom license, tl;dr: You may use it for commercial and personal use, you must however credit, don’t fork/rename/charge for it, but give it to your friends.. always refer to the license in the header however, as that’s the only valid source of licensing details.

No External libraries required, Aside from the previous mentioned PHP and XInetd (or similar) to handle the connections. Oddly enough, It doesn’t even require WordPress (what a shock huh? – Stay tuned, I’m sure you’ll see WordPress as a Email Client soon enough with the integration of this ;))

This is NOT a relay mail server, It’s been designed to process incoming mail, and discard mail for addresses which it doesnt know. It will not forward mail on for you. Please check that you don’t conflict with sendmail on your own system, I think I have mine set for sendmail on loopback, and this on the external interface or something like that.

You can get the code from my SVN: http://svn.dd32.id.au/php-mail-server/ – Please note, this is a READ ONLY repository, if you find a bug and would like to submit it, for now, just sent it over to me at contact [at] dd32.id.au

 Integrating with Xinetd:

How I have it running is as follows: /etc/xinetd.d/d-mail

service smtp {
        port                    = 25
        bind                    = YOUR IP ADDRESS
        socket_type             = stream
        protocol                = tcp
        wait                    = no
        user                    = USERID TO RUN IT AS
        server                  = /path/to/mail-server/mail-server.php
        instances               = 10
        nice                    = 10
        disable                 = no
}

That limits connections to 10 active at a time (instances) which works well for me, that should hopefully prevent overloading.

What emails am I processing? Well, the examples should suggest that to you! SVNSync to automatically sync up a local repository with a remote repository which I don’t have admin access on for one, SVN update on a local WordPress installation (This site! It’s running on the latest WordPress trunk release within a few seconds of each commit) and there’s a few domino effect processing I’d like to do as well (ie. Alter mailing list posts to selectivly ignore certain things, Remove partial content from svn emails (I don’t want to see a 100kb minified css file in a commit email!). I’ll publish those details later when I get to it!

Magic 8 Ball Example! 

Included in the SVN repo, is a single Example plugin. A Magic 8ball extension, send an email to it with a question in the subject, and it’ll reply with an answer.

You can test this out by emailing 8ball [at] php-mail.dd32.id.au and seeing if it replies (It better!)

FIN.

So go forth and download/run/test out the PHP Mail Server!  Download from  http://svn.dd32.id.au/php-mail-server/ Send patches to contact[at] dd32.id.au, oh, and test it out by sending an email to 8ball  [at]  php-mail.dd32.id.au with a question in the subject!  

WordCamp Gold Coast Status Update

Hey all,

Just a quick update for those of you who subscribe via RSS! I’d just like to remind you all that WordCamp Gold Coast has been announced (And will take place on Nov 5th & 6th at Bond University), and not only that, but is also open for ticket sales, accepting speaker nominations, and seeking sponsorship!. If you’re interested in WordCamp going-ons, please subscribe the the WordCamp Gold Coast RSS Feed

D