diff --git a/composer.json b/composer.json index 2e7bfe48adc057a254d5cfd96d66c018d85c5da5..1c2c50887b50c94708d3d46a4fcff84cfa79758c 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "composer-plugin-api": "^1.0" + "composer-plugin-api": "^2.0" }, "autoload": { "psr-4": { diff --git a/src/Translatable.php b/src/Translatable.php index 6649fe63aa37227c01d08315c74f83588360658c..ec5add6ed433a6d62004e995cecaf68fd0632d4a 100644 --- a/src/Translatable.php +++ b/src/Translatable.php @@ -60,7 +60,7 @@ class Translatable { * @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 $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. */ public function __construct( $type, $slug, $version, $languages, $wpLanguageDir ) { @@ -100,14 +100,14 @@ class Translatable { break; default: - throw new \Exception( 'Unknown package type' ); + throw new \Exception( sprintf('Unknown package type "%s"', $this->type) ); } $body = file_get_contents( $url ); $res = json_decode( $body ); 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 = []; diff --git a/src/Wplang.php b/src/Wplang.php index 31f32b68b5d78e43ab67706e264b0f35a438a089..b376b4d26655d0ec8c95a05f860d7d8093b32946 100644 --- a/src/Wplang.php +++ b/src/Wplang.php @@ -3,7 +3,7 @@ namespace BJ\Wplang; use Composer\Composer; -use Composer\Script\Event; +use Composer\DependencyResolver\Operation\UpdateOperation; use Composer\EventDispatcher\EventSubscriberInterface; use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; @@ -50,10 +50,19 @@ class Wplang implements PluginInterface, EventSubscriberInterface { } 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. @@ -77,7 +86,7 @@ class Wplang implements PluginInterface, EventSubscriberInterface { * @param PackageEvent $event The package event object. */ public function onPackageAction( PackageEvent $event ) { - if ( 'update' === $event->getOperation()->getJobType() ) { + if ($event->getOperation() instanceof UpdateOperation) { $package = $event->getOperation()->getTargetPackage(); } else { $package = $event->getOperation()->getPackage(); @@ -128,7 +137,7 @@ class Wplang implements PluginInterface, EventSubscriberInterface { } } } catch ( \Exception $e ) { - $this->io->writeError( $e->getMessage() ); + $this->io->writeError( ' - ' . $e->getMessage() ); } }