Upgrade
3 weeks ago
CLIService.php
3 weeks ago
FeedCacheUpdateService.php
3 weeks ago
MigrationReactivationNotice.php
3 weeks ago
SBR_Upgrader.php
3 weeks ago
SettingsManagerService.php
3 weeks ago
ShortcodeService.php
3 weeks ago
SiteUrlWatcher.php
3 weeks ago
UsageTrackingService.php
3 weeks ago
CLIService.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SmashBalloon\Reviews\Common\Services; |
| 4 | |
| 5 | use SmashBalloon\Reviews\Common\Exceptions\RelayResponseException; |
| 6 | use SmashBalloon\Reviews\Common\Integrations\SBRelay; |
| 7 | use Smashballoon\Stubs\Services\ServiceProvider; |
| 8 | |
| 9 | class CLIService extends ServiceProvider |
| 10 | { |
| 11 | private $relay; |
| 12 | |
| 13 | public function __construct(SBRelay $relay) |
| 14 | { |
| 15 | $this->relay = $relay; |
| 16 | } |
| 17 | |
| 18 | public function register() |
| 19 | { |
| 20 | if (defined('WP_CLI') && WP_CLI) { |
| 21 | \WP_CLI::add_command('sbr_update', [$this, 'update_site_setting']); |
| 22 | \WP_CLI::add_command('sbr_get', [$this, 'get_site_setting']); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | public function update_site_setting($args, $assoc_args) |
| 27 | { |
| 28 | try { |
| 29 | $response = $this->relay->call('settings', $assoc_args, 'POST', true); |
| 30 | if (isset($response['data'])) { |
| 31 | \WP_CLI::success(json_encode($response['data'])); |
| 32 | } |
| 33 | } catch (RelayResponseException $exception) { |
| 34 | \WP_CLI::error($exception->getMessage()); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public function get_site_setting($args, $assoc_args) |
| 39 | { |
| 40 | try { |
| 41 | $response = $this->relay->call('settings', [], 'GET', true); |
| 42 | if (isset($response['data'])) { |
| 43 | \WP_CLI::success(json_encode($response['data'])); |
| 44 | } |
| 45 | } catch (RelayResponseException $exception) { |
| 46 | \WP_CLI::error($exception->getMessage()); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 |