<?php //chdir( dirname(__DIR__) ); // First we mandate that this file is in the same location for any parent project // so we can get the project root directory $dir_root = dirname(__DIR__); // we can specify the config file to use relative to the project root $filename = "build-src/patch-conf.json"; if( isset($argv[1]) ) $filename = $argv[1]; // full path to config file $filename = "$dir_root/$filename"; if( !is_file($filename) ){ throw new \Exception("Missing JSON config file: $filename"); } //call autoload require "$dir_root/vendor/autoload.php"; use \Johnpearcey\Dbpatcher\DbPatchMain; // load the config file $conf_json = json_decode( file_get_contents( $filename ), true ); if($conf_json=='') throw new \Exception("Empty or badly formatted JSON file $filename"); // instantiate the patcher $patcher = new DbPatchMain( ); $patcher->open( $filename ); // Now apply each set of patches in order foreach( $conf_json['prefixes'] as $prfx ){ $patcher->setPrefix( $prfx ); $pathtopatches = dirname($filename); if($prfx=='amara'){ if( getPackageName( "$dir_root/composer.json" ) != 'johnpearcey/amara' ){ //running in a parent project, locate the amara package to use instead // TODO: use \Composer\InstalledVersions::getInstallPath('johnpearcey/amara'); $pathtopatches = "$dir_root/vendor/johnpearcey/amara/build-src"; } } $tot_applied = $patcher->apply_patches( $pathtopatches ); echo "Finished: applied $tot_applied patches\n"; $version = $patcher->get_curr_patch_ver( ); echo "DB patch($prfx) version: $version\n"; } function getPackageName( $composerfile ){ $conf_json = json_decode( file_get_contents( $composerfile ), true ); return $conf_json['name']; } ?>