Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
[#1037] RequirementChecker now checks availability of needed composer…
Browse files Browse the repository at this point in the history
… scripts
  • Loading branch information
JanVoracek committed May 18, 2016
1 parent 9eecada commit 9b48866
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion plugins/versionpress/src/Utils/RequirementsChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace VersionPress\Utils;

use Exception;
use Nette\Utils\Strings;
use Symfony\Component\Filesystem\Exception\IOException;
use VersionPress\Database\Database;
use VersionPress\Database\DbSchemaInfo;
Expand Down Expand Up @@ -121,6 +120,16 @@ public function __construct($database, DbSchemaInfo $schema, $checkScope = Requi
'help' => 'VersionPress automatically tries to secure certain locations, like `wp-content/vpdb`. You either don\'t have a supported web server or rules cannot be enforced. [Learn more](http://docs.versionpress.net/en/getting-started/installation-uninstallation#supported-web-servers).'
];
if ($checkScope === RequirementsChecker::SITE) {
if (file_exists(VP_PROJECT_ROOT . '/composer.json')) {
$this->requirements[] = [
'name' => 'Composer scripts',
'level' => 'warning',
'fulfilled' => $this->testComposerJson(),
// @codingStandardsIgnoreLine
'help' => 'Your project uses Composer but `pre-update-cmd` or `post-update-cmd` scripts in `composer.json` are already defined. VersionPress needs to run a WP-CLI commands in these scripts to automatically commit changes of Composer packages. Please update your scripts to run [the WP-CLI commands](http://docs.versionpress.net/en/feature-focus/composer).'
];
}

$this->requirements[] = [
'name' => 'wpdb hook',
'level' => 'critical',
Expand Down Expand Up @@ -331,4 +340,19 @@ private function testExternalPlugins()
}
return $unsupportedPluginsCount;
}

private function testComposerJson()
{
$composerJsonPath = VP_PROJECT_ROOT . '/composer.json';
$composerJson = json_decode(file_get_contents($composerJsonPath));
if (!isset($composerJson->scripts)) {
return true;
}

if (isset($composerJson->scripts->{'pre-update-cmd'}) || isset($composerJson->scripts->{'post-update-cmd'})) {
return false;
}

return true;
}
}

0 comments on commit 9b48866

Please sign in to comment.