How do you update database when using composer/jenkins and wordpress with plugins? How do you update database when using composer/jenkins and wordpress with plugins? jenkins jenkins

How do you update database when using composer/jenkins and wordpress with plugins?


So I used the following to create my solution

https://roots.io/using-composer-with-wordpress/

and

https://roots.io/wordpress-plugins-with-composer/

With a few modifications/Jank that I will detail below

The database update I found that as long as you don't run two word press updates that need database changes you will be fine.

Exampleswordpress 4.2 to 4.3 works if you login in to wp admin and update the database

If you however update 4.2 to 4.3 do nothing and update 4.3 to 4.6 you sometimes have an issue, that I still have not solved

However I do have plugins and wordpress updating automatically

Overview

I made a base wordpress repo that all new projects are forked off of

My jenkins build runs composer update or composer install depending on if the vendor folder is present

I made a plugin repo for all "approved" plugins the plugin repos are just copies of the current plugin and must contain

{  "name": "YOURBITBUCKETGROUP/NAMEOFPLUGINEXACTLY",  "type": "wordpress-plugin",  "require": {    "composer/installers": "v1.0.6"  }}

I made these all public so that any site can access them with no creds

Also when updating the plugin just make a branch called "pluginversion"

Example 1.2.3

This will allow you to revert to an older version of a plugin when needed

Installing and updating wordpress and plugins

From the links above I created a composer.json that looks a bit like this

{  "repositories": [    {      "type": "composer",      "url": "https://wpackagist.org"    },    {      "type": "git",      "url": "https://bitbucket.org/YOUREPOLINEHERE/NAMEOFPLUGIN"    }    ],  "type": "wordpress-core",  "require": {    "johnpbloch/wordpress-core-installer": "~0.1",    "johnpbloch/wordpress": "4.*",    "YOUREPOLINEHER/NAMEOFPLUGIN": "dev-master"  },  "extra": {    "wordpress-install-dir": "wp"  }}

This will update the site to wordpress 4.X and install the latest version of your plugin on build

If you want to install a old version of the plugin you just change

"YOUREPOLINEHER/NAMEOFPLUGIN": "dev-master"

to

"YOUREPOLINEHER/NAMEOFPLUGIN": "1.2.3.x-dev"

This will install wp core in the root of the project in the wp folder and plugins in side the wp-content folder

You will need to alter index.php with this

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

To

require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );

At this point if you followed the above links you might think you are done, well not exactly

Issues and fixes

These are my fixes they are likely not the best way to get this done but they work for me any input on improving these would be appreciated.

The first issue is .gitignore

You would think you can just ignore the plugins directory right ? Well this creates a problem that the plugins directory does not exist and the empty index.php does not exists

Second issue with this solution the uploads folder is versioned and user can not upload images (the will get deleted on build)

My solution to this is to not add the plugins to the repo but allow add the index.php file

also I am excluding all files in .gitignore from the final build step so they do not get overwritten

my .gitignore looks something like this (you may need to ignore other files)

/.htaccess/wp/*/vendor/*/wp-content/mu-plugins/*/wp-content/backup*/*/wp-content/managewp/*/wp-content/*.log/wp-content/uploads/*.DS_store

This causes all the ignored files to be versioned and allows the upload folder to be changed by end users

It also means you have to manually upload the uploads folder to the server

Hopefully this helps you out if you are trying to version wordpress

EDIT: also in the db wp_options site url needs to be suffixed with /wp