Skip to content
Snippets Groups Projects
Unverified Commit baa7ba8e authored by Bjørn Johansen's avatar Bjørn Johansen Committed by GitHub
Browse files

Merge pull request #8 from SeifertDaniel/dev_composer2

Composer 2 compatibility
parents 3194a2a7 fb10cc8c
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
} }
], ],
"require": { "require": {
"composer-plugin-api": "^1.0" "composer-plugin-api": "^2.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
......
...@@ -60,7 +60,7 @@ class Translatable { ...@@ -60,7 +60,7 @@ class Translatable {
* @param string $type The package type: 'plugin', 'theme' or 'core'. * @param string $type The package type: 'plugin', 'theme' or 'core'.
* @param string $slug The plugin/theme slug, E.g. 'query-monitor'. In case of core, this is 'wordpress'. * @param string $slug The plugin/theme slug, E.g. 'query-monitor'. In case of core, this is 'wordpress'.
* @param string $version The package version. * @param string $version The package version.
* @param string $languages Array of the languages we are using. * @param array $languages Array of the languages we are using.
* @param string $wpLanguageDir Full path to the language files target directory. * @param string $wpLanguageDir Full path to the language files target directory.
*/ */
public function __construct( $type, $slug, $version, $languages, $wpLanguageDir ) { public function __construct( $type, $slug, $version, $languages, $wpLanguageDir ) {
...@@ -100,14 +100,14 @@ class Translatable { ...@@ -100,14 +100,14 @@ class Translatable {
break; break;
default: default:
throw new \Exception( 'Unknown package type' ); throw new \Exception( sprintf('Unknown package type "%s"', $this->type) );
} }
$body = file_get_contents( $url ); $body = file_get_contents( $url );
$res = json_decode( $body ); $res = json_decode( $body );
if ( ! isset( $res->translations ) || empty( $res->translations ) ) { if ( ! isset( $res->translations ) || empty( $res->translations ) ) {
throw new \Exception( 'No translations found' ); throw new \Exception( sprintf('No translations found for %s', $this->slug) );
} }
$translations = []; $translations = [];
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace BJ\Wplang; namespace BJ\Wplang;
use Composer\Composer; use Composer\Composer;
use Composer\Script\Event; use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\EventDispatcher\EventSubscriberInterface; use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface; use Composer\Plugin\PluginInterface;
...@@ -50,10 +50,19 @@ class Wplang implements PluginInterface, EventSubscriberInterface { ...@@ -50,10 +50,19 @@ class Wplang implements PluginInterface, EventSubscriberInterface {
} }
if ( ! empty( $extra['wordpress-language-dir'] ) ) { if ( ! empty( $extra['wordpress-language-dir'] ) ) {
$this->wpLanguageDir = dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) . '/' . $extra['wordpress-language-dir']; $this->wpLanguageDir = dirname( __DIR__, 4 ) . '/' . $extra['wordpress-language-dir'];
} }
} }
public function deactivate(Composer $composer, IOInterface $io)
{
// do nothing
}
public function uninstall(Composer $composer, IOInterface $io)
{
// do nothing
}
/** /**
* Subscribe to Composer events. * Subscribe to Composer events.
...@@ -77,7 +86,7 @@ class Wplang implements PluginInterface, EventSubscriberInterface { ...@@ -77,7 +86,7 @@ class Wplang implements PluginInterface, EventSubscriberInterface {
* @param PackageEvent $event The package event object. * @param PackageEvent $event The package event object.
*/ */
public function onPackageAction( PackageEvent $event ) { public function onPackageAction( PackageEvent $event ) {
if ( 'update' === $event->getOperation()->getJobType() ) { if ($event->getOperation() instanceof UpdateOperation) {
$package = $event->getOperation()->getTargetPackage(); $package = $event->getOperation()->getTargetPackage();
} else { } else {
$package = $event->getOperation()->getPackage(); $package = $event->getOperation()->getPackage();
...@@ -128,7 +137,7 @@ class Wplang implements PluginInterface, EventSubscriberInterface { ...@@ -128,7 +137,7 @@ class Wplang implements PluginInterface, EventSubscriberInterface {
} }
} }
} catch ( \Exception $e ) { } catch ( \Exception $e ) {
$this->io->writeError( $e->getMessage() ); $this->io->writeError( ' - ' . $e->getMessage() );
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment