Skip to content

Commit

Permalink
fix elastic version bug
Browse files Browse the repository at this point in the history
  • Loading branch information
FaulMarco committed Feb 24, 2020
1 parent 1532c20 commit 6cc0d4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
30 changes: 19 additions & 11 deletions cli/Valet/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Elasticsearch
const ES_V24_VERSION = '2.4';
const ES_V56_VERSION = '5.6';
const ES_V68_VERSION = '6.8';
const ES_DEFAULT_VERSION = self::ES_V24_VERSION;
const ES_DEFAULT_VERSION = self::ES_V56_VERSION;

const SUPPORTED_ES_FORMULAE = [
self::ES_V24_VERSION => self::ES_FORMULA_NAME . '@' . self::ES_V24_VERSION,
Expand Down Expand Up @@ -129,9 +129,13 @@ public function installed(string $version = null): bool
*/
public function restart(?string $version = null): void
{
$version = ($version ? $version : $this->getCurrentVersion());
$version = $this->installed($version);
if (!$version) {
$version = $version ?: $this->getCurrentVersion();
if (!$this->installed($version)) {
return;
}

if (array_key_exists($version, self::SUPPORTED_ES_FORMULAE) === false) {
warning(sprintf('No assigned Elastic Version found for: "%s"', $version));
return;
}

Expand All @@ -148,9 +152,13 @@ public function restart(?string $version = null): void
*/
public function stop(?string $version = null): void
{
$version = ($version ? $version : $this->getCurrentVersion());
$version = $this->installed($version);
if (!$version) {
$version = ($version ?: $this->getCurrentVersion());
if (!$this->installed($version)) {
return;
}

if (array_key_exists($version, self::SUPPORTED_ES_FORMULAE) === false) {
warning(sprintf('No assigned Elastic Version found for: "%s"', $version));
return;
}

Expand Down Expand Up @@ -196,7 +204,7 @@ public function switchTo(string $version): void
$currentVersion = $this->getCurrentVersion();

if (!array_key_exists($version, self::SUPPORTED_ES_FORMULAE)) {
throw new DomainException("This version of Elasticsearch is not supported. The following versions are supported: " . implode(', ', array_keys(self::SUPPORTED_ES_FORMULAE)) . ($currentVersion ? "\nCurrent version is " . $currentVersion : ""));
throw new DomainException('This version of Elasticsearch is not supported. The following versions are supported: ' . implode(', ', array_keys(self::SUPPORTED_ES_FORMULAE)) . ($currentVersion ? "\nCurrent version is " . $currentVersion : ''));
}

// If the current version equals that of the current PHP version, do not switch.
Expand All @@ -223,21 +231,21 @@ public function switchTo(string $version): void
} else {
// Install PHP dependencies through installation of PHP.
$this->phpFpm->install();
warning("Switching Elasticsearch requires PECL extension yaml. Try switching again.");
warning('Switching Elasticsearch requires PECL extension yaml. Try switching again.');

return;
}

// Start requested version.
$this->restart($version);

info("Valet is now using " . self::SUPPORTED_ES_FORMULAE[$version] . ". You might need to reindex your data.");
info('Valet is now using ' . self::SUPPORTED_ES_FORMULAE[$version] . '. You might need to reindex your data.');
}

/**
* Returns the current running version.
*
* @return bool|string
* @return string
*/
public function getCurrentVersion()
{
Expand Down
4 changes: 2 additions & 2 deletions cli/includes/compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# read composer.json the get min php version
$minPHPVersion = str_replace('>=', '', json_decode(file_get_contents(__DIR__ . '/../../composer.json'), true)['require']['php']);

if (version_compare(PHP_VERSION, '7.2', '<')) {
echo "Valet requires PHP 7.2 or later.";
if (PHP_VERSION_ID <= 70200) {
echo 'Valet requires PHP 7.2 or later.';

exit(1);
}
Expand Down

0 comments on commit 6cc0d4b

Please sign in to comment.