Skip to content

Commit

Permalink
Enable --update-wp flag for --vip-dev-env
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed Apr 12, 2024
1 parent ea456c7 commit 7f2a36c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 23 deletions.
8 changes: 7 additions & 1 deletion docs/003-vip-local-dev-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The [VIP Local Development Environment](https://docs.wpvip.com/vip-local-develop

There are gotchas and limitations. Please refer to the official documentation.

Besides dealing with the containers and providing useful helper commands, from an aplication perspective it also deals with:
Besides dealing with the containers and providing useful helper commands, from an application perspective it also deals with:

- Copy/symlink the various folders in the skeleton (and/or setting configuration constants) so that WordPress can find them
- [VIP platform MU plugins](https://docs.wpvip.com/vip-go-mu-plugins/)
Expand All @@ -30,6 +30,12 @@ We can leverage that option to implement the following workflow:



## Prerequisites

Having to run `composer vip` command _before_ we build and start the VIP local development environment, likely means **we need PHP and Composer installed on the host machine**. There's no hard requirement for the host PHP context (version and extensions) to match what's in the container, as long as the this plugin's minimum requirements are met. However, using a different PHP version might cause the installation of undesired dependencies versions. To overcome this issue, there are two possibilities: use the `config.platform` Composer setting to match the container's PHP version, or run `composer update` _again_ from inside the application container as soon as the environment is started.



## Preparing the `vip` folder

To prepare the environment for the VIP Local Development Environment, after having installed Composer dependencies, run:
Expand Down
6 changes: 4 additions & 2 deletions docs/006-vip-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ However, this command alone won't work. It is necessary to provide one or more f

### WordPress and MU Plugins Options

All the following flags are intended to be used in combination with `--local`. See the ["WP and MU Plugins Command Flags" chapter](./012-wp-mu-plugins-command-flags.md) for more details.
All the following flags are mostly intended to be used in combination with `--local` (and on a lesser extend with `--vip-dev-env`).

- `--update-wp` - Force the update of WordPress core.
See the ["WP and MU Plugins Command Flags" chapter](./012-wp-mu-plugins-command-flags.md) for more details.

- `--update-wp` - Force the update of WordPress core. Can also be used as standalone flag.
- `--skip-wp` - Skip the update of WordPress core.
- `--update-vip-mu-plugins` - Force the update of VIP Go MU plugins. Can also be used as standalone flag.
- `--skip-vip-mu-plugins` - Skip the update of VIP Go MU plugins.
16 changes: 15 additions & 1 deletion docs/012-wp-mu-plugins-command-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ First of all, to download WordPress the plugin needs to know which version. In t
"vip-composer": {
"wordpress": {
"version": "6.*"
},
}
}
}
}
Expand Down Expand Up @@ -62,6 +62,14 @@ Please note that this is *not* relevant on deployment. When deploying, there's n



#### Usage with VIP Local Development Environment

The `--update-wp` flag might also be useful when using the [VIP Local Development Environment](./003-vip-local-dev-env.md). Even if the VIP local environment will *not* utilize the files downloaded to execute the code (but rather the core version in the container) having a local WordPress copy might be useful to configure a step-debugger and be able to step-in WP core code in the IDE by using "local folder mappings".

Of course, it is essential the WP version in the container (which is the WP version used online when using `--slug` for `vip dev-even create`) and the WP version downloaded by this plugin are the same. That could be simplified configuring a fixed WordPress version in the `composer.json` plugin configuration mentioned above.



### Skip WP Update

The `--skip-wp` flag tells the command to **never download WP**. This might be useful when, for example, version requirement is set to `"latest"` but one wants to save the time necessary to download and unzip WordPress (which might take a while, especially on slow connections).
Expand All @@ -84,6 +92,12 @@ Essentially, `composer vip --local --update-vip-mu-plugins` means *"update loca



#### Usage with VIP Local Development Environment

The VIP Local Development Environment includes containerized service VIP MU plugins. However, it provides an option to load VIP MU plugins from a local folder. By using `--update-vip-mu-plugins` in combination `composer vip --vip-dev-env` and then building the VIP Local Development Environment with [`vip dev-env create --mu-plugins="./vip-go-mu-plugins"`](https://docs.wpvip.com/vip-cli/commands/dev-env/create/) it is possible to run the VIP local environment loading the VIP MU plugins from a local folder this plugins download, which might be useful for debugging purposes.



### Skip MU Plugins Update

The `--skip-vip-mu-plugins` flag tells the command to **never download VIP Platform MU plugins**. This is useful when MU plugins are not there (never downloaded or deleted by hand), but one wants to save the time necessary to download them, for any reason.
Expand Down
6 changes: 3 additions & 3 deletions src/Task/DownloadVipGoMuPlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function name(): string
*/
public function enabled(TaskConfig $taskConfig): bool
{
return ($taskConfig->isAnyLocal() && !$taskConfig->skipVipMuPlugins())
return ($taskConfig->isLocal() && !$taskConfig->skipVipMuPlugins())
|| $taskConfig->forceVipMuPlugins();
}

Expand All @@ -54,7 +54,7 @@ public function run(Io $io, TaskConfig $taskConfig): void
$targetDir = $this->vipDirectories->vipMuPluginsDir();
if (!$taskConfig->forceVipMuPlugins() && $this->alreadyInstalled()) {
$io->infoLine('VIP Go MU plugins already there, skipping.');
$this->copySunrise($io);
$taskConfig->isLocal() and $this->copySunrise($io);

return;
}
Expand All @@ -75,7 +75,7 @@ public function run(Io $io, TaskConfig $taskConfig): void
$io->lines(Io::ERROR, ...$outputs);
}

$this->copySunrise($io);
$taskConfig->isLocal() and $this->copySunrise($io);
}

/**
Expand Down
22 changes: 14 additions & 8 deletions src/Task/DownloadWpCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public function name(): string
*/
public function enabled(TaskConfig $taskConfig): bool
{
return $taskConfig->isLocal() && !$taskConfig->skipCoreUpdate();
return ($taskConfig->isLocal() && !$taskConfig->skipCoreUpdate())
|| $taskConfig->forceCoreUpdate();
}

/**
Expand All @@ -110,10 +111,9 @@ public function run(Io $io, TaskConfig $taskConfig): void
return;
}

if (
!$taskConfig->forceCoreUpdate()
&& !$this->shouldInstall($targetVersion, $this->discoverInstalledVersion(), $io)
) {
$forceUpdate = $taskConfig->forceCoreUpdate();
$installed = $this->discoverInstalledVersion();
if (!$this->shouldInstall($targetVersion, $installed, $forceUpdate, $io)) {
$io->infoLine(
'No need to download WordPress: installed version matches required version.'
);
Expand Down Expand Up @@ -306,11 +306,17 @@ private function resolveTargetVersion(string $version, Io $io): string
*
* @param string $targetVersion
* @param string $installedVersion
* @param bool $forceUpdate
* @param Io $io
* @return bool
*/
private function shouldInstall(string $targetVersion, string $installedVersion, Io $io): bool
{
private function shouldInstall(
string $targetVersion,
string $installedVersion,
bool $forceUpdate,
Io $io
): bool {

if (!$installedVersion) {
return true;
}
Expand All @@ -319,7 +325,7 @@ private function shouldInstall(string $targetVersion, string $installedVersion,
return false;
}

if (Semver::satisfies($installedVersion, $targetVersion)) {
if (Semver::satisfies($installedVersion, $targetVersion) && !$forceUpdate) {
return false;
}

Expand Down
11 changes: 4 additions & 7 deletions src/Task/TaskConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ private function validateBaseMode(): void
$muPlugins = $this->forceVipMuPlugins();
$autoload = $this->data[self::PROD_AUTOLOAD];
$devPaths = $this->syncDevPaths();
$core = $this->forceCoreUpdate();

if (($mainMode === 0) && ($autoload || $muPlugins || $devPaths)) {
if (($mainMode === 0) && ($autoload || $muPlugins || $devPaths || $core)) {
return;
}

Expand All @@ -336,10 +337,6 @@ private function validateBaseMode(): void
'--sync-dev-paths can be used as standalone flag or in combination with --local.'
);
}

if ($isVipEnv && !$muPlugins && !$this->skipVipMuPlugins()) {
$this->data[self::SKIP_VIP_MU] = true;
}
}

/**
Expand Down Expand Up @@ -381,8 +378,8 @@ private function validateWp(): void
throw new \LogicException('Can\'t both *skip* and *force* core update.');
}

if (!$this->isLocal()) {
throw new \LogicException('Force and skip core update are --local operations.');
if (!$this->isAnyLocal()) {
throw new \LogicException('Force and skip core update are local operations.');
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Task/UpdateLocalWpConfigFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public function name(): string
*/
public function enabled(TaskConfig $taskConfig): bool
{
return $taskConfig->isLocal();
return $taskConfig->isLocal()
|| ($taskConfig->forceVipMuPlugins() && !$taskConfig->isVipDevEnv());
}

/**
Expand Down

0 comments on commit 7f2a36c

Please sign in to comment.