diff --git a/ComposerScript/Installer.php b/ComposerScript/Installer.php
new file mode 100644
index 0000000..38cdb33
--- /dev/null
+++ b/ComposerScript/Installer.php
@@ -0,0 +1,212 @@
+getComposer();
+ $io = $event->getIO();
+ $operation = $event->getOperation();
+ $package = $operation->getPackage();
+ $im = $composer->getInstallationManager();
+
+ $install_path = $im->getInstallPath( $package );
+
+ self::handle_plugin_requires( $install_path, $io );
+ }
+
+ /**
+ * Hooks the pre-package-update Composer event
+ *
+ * Before a package is updated, we need to remove
+ * related require files, in case they are stale
+ * (we will recreate the required files after the
+ * package has been updated).
+ *
+ * @param Event $event A Composer Event object
+ * @return void
+ * @author Simon Wheatley
+ **/
+ public static function pre_package_update( Event $event ) {
+ $composer = $event->getComposer();
+ $io = $event->getIO();
+ $operation = $event->getOperation();
+ $package = $operation->getTargetPackage();
+ $im = $composer->getInstallationManager();
+
+ $install_path = $im->getInstallPath( $package );
+
+ self::remove_require_files( $install_path, $io );
+ }
+
+ /**
+ * Hooks the post-package-update Composer event
+ *
+ * After the package is updated, we write any
+ * require files we need.
+ *
+ * @param Event $event A Composer Event object
+ * @return void
+ * @author Simon Wheatley
+ **/
+ public static function post_package_update( Event $event ) {
+ $composer = $event->getComposer();
+ $io = $event->getIO();
+ $operation = $event->getOperation();
+ $package = $operation->getTargetPackage();
+ $im = $composer->getInstallationManager();
+
+ $install_path = $im->getInstallPath( $package );
+
+ self::handle_plugin_requires( $install_path, $io );
+ }
+
+ /**
+ * Hooks the pre-package-uninstall Composer event
+ *
+ * Before the package is uninstalled, while it still
+ * exists, we remove the require files.
+ *
+ * @param Event $event A Composer Event object
+ * @return void
+ * @author Simon Wheatley
+ **/
+ public static function pre_package_uninstall( Event $event ) {
+ $composer = $event->getComposer();
+ $io = $event->getIO();
+ $operation = $event->getOperation();
+ $package = $operation->getPackage();
+ $im = $composer->getInstallationManager();
+
+ $install_path = $im->getInstallPath( $package );
+
+ self::remove_require_files( $install_path, $io );
+ }
+
+ /**
+ * Process a mu-plugins installed package, creating the relevant
+ * require file(s).
+ *
+ * @param string $install_path The path to the package
+ * @param IOInterface $io The Composer IOInterface, for writing messages
+ * @return void
+ * @author Simon Wheatley
+ **/
+ protected static function handle_plugin_requires( $install_path, $io ) {
+ if ( 'htdocs/wp-content/mu-plugins' == dirname( $install_path ) ) {
+ $plugin_files = self::get_plugin_files( $install_path );
+ foreach ( $plugin_files as $plugin_file => $plugin_name ) {
+ self::write_plugin_require( $io, $plugin_name, $plugin_file, $install_path );
+ }
+ }
+ }
+
+ /**
+ * Remove the require file for a mu-plugins installed package.
+ *
+ * @param string $install_path The path to the package
+ * @param IOInterface $io The Composer IOInterface, for writing messages
+ * @return void
+ * @author Simon Wheatley
+ **/
+ protected static function remove_require_files( $install_path, $io ) {
+ if ( 'htdocs/wp-content/mu-plugins' == dirname( $install_path ) ) {
+ $plugin_files = self::get_plugin_files( $install_path );
+ foreach ( $plugin_files as $plugin_file => $plugin_name ) {
+ self::remove_plugin_require( $io, $plugin_name, $plugin_file, $install_path );
+ }
+ }
+
+ }
+
+ /**
+ * Get all the plugin files within the package, and their plugin names.
+ *
+ * @param strong $install_path The path to the Composer package (a mu-plugins subdirectory)
+ * @return array An array of plugin paths (key) and plugin names (value)
+ * @author Simon Wheatley
+ **/
+ protected static function get_plugin_files( $install_path ) {
+ $files = array();
+ foreach ( glob( "{$install_path}*.php" ) as $file ) {
+ $file_contents = file_get_contents( $file, false, null, -1, 8192 );
+ if ( preg_match( '/^[ \t\/*#@]*Plugin Name:(.*)$/mi', $file_contents, $matches ) ) {
+ $files[ $file ] = trim( $matches[1] );
+ }
+ }
+ return $files;
+ }
+
+ /**
+ * Write a basic plugin file, which requires the relevant file
+ * inside mu-plugins/[folder].
+ *
+ * @param IOInterface $io The Composer IOInterface, for writing messages
+ * @param array $plugin_name A plugin name
+ * @param array $plugin_file A plugin file path
+ * @param string $install_path The path to the Composer package (a mu-plugins subdirectory)
+ * @return void
+ * @author Simon Wheatley
+ **/
+ protected static function write_plugin_require( $io, $plugin_name, $plugin_file, $install_path ) {
+ $lines = array();
+ $lines[] = 'write( sprintf( 'Created auto-require file for "%s" at %s', $plugin_name, $require_plugin_file ) );
+ }
+
+ /**
+ * Remove the basic plugin file, which requires the relevant file
+ * inside mu-plugins/[folder].
+ *
+ * @param IOInterface $io The Composer IOInterface, for writing messages
+ * @param array $plugin_name A plugin name
+ * @param array $plugin_file A plugin file path
+ * @param string $install_path The path to the Composer package (a mu-plugins subdirectory)
+ * @return void
+ * @author Simon Wheatley
+ **/
+ protected static function remove_plugin_require( $io, $plugin_name, $plugin_file, $install_path ) {
+ $require_plugin_file = self::require_plugin_file_path( $install_path, $plugin_file );
+ unlink( $require_plugin_file );
+ $io->write( sprintf( 'Removed auto-require file for "%s" at %s', $plugin_name, $require_plugin_file ) );
+ }
+
+
+ /**
+ * Provide the file path for a file within the mu-plugins folder.
+ *
+ * @param string $install_path The path to the Composer package (a mu-plugins subdirectory)
+ * @param string $plugin_file The path to the plugin file within the Composer package
+ * @return string A file path
+ * @author Simon Wheatley
+ **/
+ static function require_plugin_file_path( $install_path, $plugin_file ) {
+ return sprintf( '%s/auto-require-%s', dirname( $install_path ), basename( $plugin_file ) );
+ }
+}
diff --git a/composer.json b/composer.json
index db07715..e859f24 100644
--- a/composer.json
+++ b/composer.json
@@ -20,14 +20,38 @@
},
"require" : {
"wpackagist-plugin/query-monitor" : "dev-master",
+ "wpackagist-plugin/responsible" : "@stable",
"php" : ">=5.2.4"
},
"require-dev" : {
},
"extra" : {
"installer-paths": {
+ "htdocs/wp-content/mu-plugins/{$name}/": [
+ "wpackagist-plugin/responsible"
+ ],
"htdocs/wp-content/plugins/{$name}/" : ["type:wordpress-plugin"],
"htdocs/wp-content/themes/{$name}/" : ["type:wordpress-theme"]
}
- }
-}
\ No newline at end of file
+ },
+ "autoload": {
+ "psr-0": {
+ "ComposerScript\\Installer" : ""
+ }
+ },
+ "scripts": {
+ "pre-package-uninstall" : [
+ "ComposerScript\\Installer::pre_package_uninstall"
+ ],
+ "pre-package-update": [
+ "ComposerScript\\Installer::pre_package_update"
+ ],
+ "post-package-update": [
+ "ComposerScript\\Installer::post_package_update"
+ ],
+ "post-package-install": [
+ "ComposerScript\\Installer::post_package_install"
+ ]
+ }
+
+}
diff --git a/composer.lock b/composer.lock
new file mode 100644
index 0000000..3455de9
--- /dev/null
+++ b/composer.lock
@@ -0,0 +1,163 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+ "This file is @generated automatically"
+ ],
+ "hash": "6b3f44afdcf696bde25a7fb5a0d00d50",
+ "packages": [
+ {
+ "name": "composer/installers",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/composer/installers.git",
+ "reference": "9eb391bcafef76503d0bd4e585756391efc8740f"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/composer/installers/zipball/9eb391bcafef76503d0bd4e585756391efc8740f",
+ "reference": "9eb391bcafef76503d0bd4e585756391efc8740f",
+ "shasum": ""
+ },
+ "replace": {
+ "roundcube/plugin-installer": "*",
+ "shama/baton": "*"
+ },
+ "require-dev": {
+ "composer/composer": "1.0.*@dev",
+ "phpunit/phpunit": "4.1.*"
+ },
+ "type": "composer-installer",
+ "extra": {
+ "class": "Composer\\Installers\\Installer",
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Composer\\Installers\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Kyle Robinson Young",
+ "email": "[email protected]",
+ "homepage": "https://github.com/shama",
+ "role": "Developer"
+ }
+ ],
+ "description": "A multi-framework Composer library installer",
+ "homepage": "http://composer.github.com/installers/",
+ "keywords": [
+ "Craft",
+ "Dolibarr",
+ "Hurad",
+ "MODX Evo",
+ "OXID",
+ "WolfCMS",
+ "agl",
+ "annotatecms",
+ "bitrix",
+ "cakephp",
+ "codeigniter",
+ "concrete5",
+ "croogo",
+ "drupal",
+ "elgg",
+ "fuelphp",
+ "installer",
+ "joomla",
+ "kohana",
+ "laravel",
+ "lithium",
+ "magento",
+ "mako",
+ "mediawiki",
+ "modulework",
+ "moodle",
+ "phpbb",
+ "piwik",
+ "ppi",
+ "roundcube",
+ "shopware",
+ "silverstripe",
+ "symfony",
+ "typo3",
+ "wordpress",
+ "zend",
+ "zikula"
+ ],
+ "time": "2014-06-27 16:11:39"
+ },
+ {
+ "name": "wpackagist-plugin/query-monitor",
+ "version": "dev-trunk",
+ "source": {
+ "type": "svn",
+ "url": "http://plugins.svn.wordpress.org/query-monitor/",
+ "reference": "trunk"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "http://downloads.wordpress.org/plugin/query-monitor.zip",
+ "reference": null,
+ "shasum": null
+ },
+ "require": {
+ "composer/installers": "~1.0"
+ },
+ "replace": {
+ "wpackagist/query-monitor": "self.version"
+ },
+ "type": "wordpress-plugin",
+ "homepage": "http://wordpress.org/plugins/query-monitor/",
+ "time": "2014-05-03 02:59:35"
+ },
+ {
+ "name": "wpackagist-plugin/responsible",
+ "version": "1.1",
+ "source": {
+ "type": "svn",
+ "url": "http://plugins.svn.wordpress.org/responsible/",
+ "reference": "trunk"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "http://downloads.wordpress.org/plugin/responsible.zip",
+ "reference": null,
+ "shasum": null
+ },
+ "require": {
+ "composer/installers": "~1.0"
+ },
+ "replace": {
+ "wpackagist/responsible": "self.version"
+ },
+ "type": "wordpress-plugin",
+ "homepage": "http://wordpress.org/plugins/responsible/"
+ }
+ ],
+ "packages-dev": [
+
+ ],
+ "aliases": [
+
+ ],
+ "minimum-stability": "dev",
+ "stability-flags": {
+ "wpackagist-plugin/query-monitor": 20,
+ "wpackagist-plugin/responsible": 0
+ },
+ "platform": {
+ "php": ">=5.2.4"
+ },
+ "platform-dev": [
+
+ ]
+}
diff --git a/vvv-init.sh b/vvv-init.sh
index 499e82f..0411731 100755
--- a/vvv-init.sh
+++ b/vvv-init.sh
@@ -58,24 +58,26 @@ done
service ssh force-reload
# Clone the repo, if it's not there already
-if [ ! -d htdocs ]
-then
- ssh-agent bash -c "ssh-add ssh/cftp_deploy_id_rsa; git clone $REPO_SSH_URL htdocs;"
- echo "Cloning the repo"
-else
- echo "The htdocs directory already exists, and should contain the repo. If not, delete it and run Vagrant provisioning again."
-fi
+# Optional step
+# if [ ! -d htdocs ]
+# then
+# ssh-agent bash -c "ssh-add ssh/cftp_deploy_id_rsa; git clone $REPO_SSH_URL htdocs;"
+# echo "Cloning the repo"
+# else
+# echo "The htdocs directory already exists, and should contain the repo. If not, delete it and run Vagrant provisioning again."
+# fi
# Make a database, if we don't already have one
mysql -u root --password=root -e "CREATE DATABASE IF NOT EXISTS $DB_NAME; GRANT ALL PRIVILEGES ON $DB_NAME.* TO wp@localhost IDENTIFIED BY 'wp';"
-# Let's get some config in the house
+# Let's get some WordPress config in the house
if [ ! -f htdocs/wp-config.php ]; then
+ wp core download --path=htdocs
echo "Creating wp-config.php"
wp core config --dbname="$DB_NAME" --dbuser=wp --dbpass=wp --dbhost="localhost" --extra-php <