From c44fb6d50749f4e863bc53469220e094659a6773 Mon Sep 17 00:00:00 2001 From: Pierre Dargham Date: Fri, 23 Jun 2023 11:52:19 +0200 Subject: [PATCH] Add command wp:apply-available-patch --- src/WordPressTrait.php | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/WordPressTrait.php b/src/WordPressTrait.php index 78f1df0..98c9161 100644 --- a/src/WordPressTrait.php +++ b/src/WordPressTrait.php @@ -430,4 +430,59 @@ public function wpInstallAcfPro($options = ['username' => '', 'password' => '']) $this->io()->success('ACF PRO was successfully installed.'); } } + + protected function wpShowAvailablePatch() + { + $cmd = new Command('composer'); + $process = $cmd->arg('outdated') + ->arg('roots/wordpress') + ->option('--patch-only') + ->option('--strict') + ->option('--format', 'json') + ->executeWithoutException(); + + $json = $process->getOutput(); + + $data = json_decode($json, true); + + if (!is_array($data)) { + return false; + } + + if (!isset($data['versions'])) { + return false; + } + + if (!isset($data['latest'])) { + return false; + } + + $currentVersion = current($data['versions']); + $latestVersion = $data['latest']; + + if (version_compare($currentVersion, $latestVersion) >= 0) { + return false; + } + + return $latestVersion; + } + + public function wpApplyAvailablePatch() + { + $version = $this->wpShowAvailablePatch(); + + if (empty($version)) { + $this->io()->info("There is no available patch for package roots/wordpress."); + return; + } + + $this->taskComposer('require') + ->arg('roots/wordpress:~' . $version) + ->option('--with-all-dependencies') + ->run(); + + $this->taskComposer('bump') + ->arg('roots/wordpress') + ->run(); + } }