Skip to content

Commit

Permalink
Add command wp:apply-available-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Dargham committed Jun 23, 2023
1 parent bb032ee commit c44fb6d
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/WordPressTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit c44fb6d

Please sign in to comment.