Skip to content

Commit

Permalink
fix: allow the plugin to be active locally without breaking everything
Browse files Browse the repository at this point in the history
  • Loading branch information
carlalexander committed Mar 13, 2021
1 parent d26ca59 commit 6014e07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Configuration/ConsoleConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@ class ConsoleConfiguration implements ContainerConfigurationInterface
*/
public function modify(Container $container)
{
$container['is_wp_cli'] = defined('WP_CLI') && WP_CLI;
$container['commands'] = $container->service(function (Container $container) {
return [
new Console\CreateAttachmentMetadataCommand($container['file_manager']),
new Console\CreateCroppedImageCommand($container['file_manager'], $container['event_manager']),
new Console\CreateSiteIconCommand($container['file_manager'], $container['event_manager'], $container['site_icon']),
new Console\EditAttachmentImageCommand($container['file_manager']),
new Console\InstallObjectCacheCommand($container['content_directory'], $container['filesystem'], $container['plugin_dir_path']),
new Console\ResizeAttachmentImageCommand($container['file_manager']),
new Console\RunAllCronCommand($container['console_client'], $container['site_query']),
];
});
$container['console_client'] = $container->service(function (Container $container) {
return new LambdaClient($container['ymir_http_client'], $container['cloud_provider_function_name'], $container['cloud_provider_key'], $container['cloud_provider_region'], $container['cloud_provider_secret'], $container['site_url']);
});
$container['is_wp_cli'] = defined('WP_CLI') && WP_CLI;
$container['local_commands'] = $container->service(function (Container $container) {
return [
new Console\InstallObjectCacheCommand($container['content_directory'], $container['filesystem'], $container['plugin_dir_path']),
];
});
}
}
16 changes: 16 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ public function load()

CloudStorageStreamWrapper::register($this->container['cloud_storage_client']);

foreach ($this->container['local_commands'] as $command) {
$this->registerCommand($command);
}

if ($this->isLocal()) {
return;
}

foreach ($this->container['priority_subscribers'] as $subscriber) {
$this->container['event_manager']->addSubscriber($subscriber);
}
Expand All @@ -130,6 +138,14 @@ public function load()
$this->loaded = true;
}

/**
* Checks if the code is running locally.
*/
private function isLocal(): bool
{
return empty($this->container['ymir_environment']);
}

/**
* Register the given command with WP-CLI.
*/
Expand Down

0 comments on commit 6014e07

Please sign in to comment.