Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upgrade Wordpress and plugins when deploying using Capistrano?

I'm hoping someone can confirm whether or not the following scenario is an issue with deploying updates to WordPress sites and, if so, do you have a solution on how to best manage this?

The basics:

  • I have a local development WordPress Multisite project for which I use GIT and Capistrano to deploy to remote staging and production servers.
  • Everything EXCEPT the uploads and blogs.dir directories (in wp-content) are under version control. Yes, the WordPress core, themes, plugins, etc are updated locally, committed, pushed and deployed. This means that I have to login and activate plugins initially - they are simply installed via the Capistrano deploy
  • The databases on development, staging and production are different and I'm not concerned about trying to sync these up

My Concern:

Many updates to plugins and the WordPress core also perform updates to the database when doing an auto update via the admin. I am updating WordPress core and plugins locally on my development install. The code to these updates ends up being committed, pushed and deployed. However, when the code is deployed it is simply adding/deleting/replacing changed files to the staging and production servers. Production and staging are missing any of the updates to the database since this is usually part of the auto update process - eg, deactivate, updated, activate (run any updates to database).

My Questions:

  1. Is my concern about the production and staging servers having the latest code but missing any database updates required for the latest code accurate?
  2. If so, does anyone have thoughts on how I can modify Capistrano deploy code to deactivate/reactivate of plugins? What about changes in WordPress, eg, 3.2 to 3.3?
  3. If Capistrano isn't the tool for this - and I need to do it more "manually" by logging into the admin - is there a maintenance mode tool/plugin that will somewhat automate the deactivation/activation of the plugins so any updates upon activation are triggered?

Many Thanks,

Matt

like image 958
Matt Avatar asked Feb 24 '12 06:02

Matt


People also ask

Should I Update WordPress before plugins?

In most cases, you should update plugins before you update WordPress. From potential compatibility issues to update times, you want to make everything go as smoothly as possible.

How do I upgrade my WordPress version?

First, log in to the admin area of your WordPress website and go to Dashboard » Updates page. You will see the notice that a new version of WordPress is available. Now you just need to click on the 'Update Now' button to initiate the update.


1 Answers

Its important to note that you don't need to activate and deactivate plugins when you upgrading the WordPress core from version to version. Here is an explanation from Ryan Boren on why. Depending on the plugin though, some of them may have an upgrade process built into their upgrade - that is, the upgrade of the plugin, not of WordPress. None the less I'll go through your three questions and answer them as directly as i can.

1. Is my concern about the production and staging servers having the latest code but missing any database updates required for the latest code accurate?

Yes, when updating, if there is a change to the database schema, then WordPress will not function properly unless the new schema exists. When attempting to access the admin side of WordPress, if the db version is lower than your WordPress version expects, it will redirect you to a database upgrade page.

WordPress sets a global called $wp_db_version in the /wp-includes/version.php file and maintains each of the migration scripts to upgrade the database incrementally from each previous versions to the next until the version number is up to date, seen here. Here is a simpler list in a FAQ showing how the revision numbers correlate to WordPress versions..

2. If so, does anyone have thoughts on how I can modify Capistrano deploy code to deactivate/reactivate of plugins?

As I said above, you dont typically need to activate/deactivate plugins after core upgrades, unless I suppose the plugin specifically requires that you do so. If the schema changes in WordPress break a plugin, then the plugin developers will need to release a new version. When upgrading that plugin, it will be shut off and restarted, and its those developers responsibility to make sure everything that needs to take place does so.

However you may need to deactivate/activate separately in deployed environments such as yours, since the actual upgrade process is taking place on different machine, and thus probably a different database from that which it will ultimately be used on.

Perhaps the best thing to do would be to have your deployment script hit a URI of a plugin within WordPress, a plugin you would write which would deactivate/activate plugins, or an existing one that already does it.

It's possible some exiting plugins might handle parts of what your looking for, but I take the key component of your question to be automation, and an avoidance of having to log into each environment and upgrade plugins for each one, so developing one yourself that does exactly what you need might be the way to go. Developing a plugin is possible if you make use of the tools WordPress already provides.

  • activate_plugin()
  • activate_plugins()
  • deactivate_plugins()
  • validate_plugin()
  • Plugin_Upgrader class (maybe)

Look through the whole /wp-admin/includes/plugin.php file to see what you might find useful. Additionally checkout code that actually handles plugins in the admin side in /wp-admin/plugins.php - just to see how its done. You may want to stop the deactivate_plugin hooks from wiping out plugin configuration with plugins that clean-up after themselves, so consider passing $silent as true when de-activating the plugin.

To make this really slick, you'll probably want to grab get_option('active_plugins') to see which plugins were already activated, and only run your script on those (make sure the plugin excludes itself from the process)

3. What about changes in WordPress, eg, 3.2 to 3.3?

Changes from 3.2 to 3.3 should be thought of as no different from any other set of changes, so everything said here applies.

4. If Capistrano isn't the tool for this - and I need to do it more "manually" by logging into the admin - is there a maintenance mode tool/plugin that will somewhat automate the deactivation/activation of the plugins so any updates upon activation are triggered?

I don't think Capistrano will be doing any of the heavy lifting here - but its certainly not in the way either. You should just need to be able to just hit a URI within the plugin, and that should get things rolling within the application. The important thing is that obviously all those functions need to be available so you cant just run it as in independent script.

like image 73
eddiemoya Avatar answered Sep 29 '22 09:09

eddiemoya