mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-06 19:40:08 +02:00
⬆️ Upstream PHP 8.3 upgrade changes to v7.0
This commit is contained in:
@ -29,7 +29,7 @@ class PhpEnvironments {
|
||||
/**
|
||||
Determine which PHP version the `php` formula is aliased to.
|
||||
*/
|
||||
func determinePhpAlias() async {
|
||||
@MainActor func determinePhpAlias() async {
|
||||
let brewPhpAlias = await Shell.pipe("\(Paths.brew) info php --json").out
|
||||
|
||||
self.homebrewPackage = try! JSONDecoder().decode(
|
||||
@ -37,7 +37,27 @@ class PhpEnvironments {
|
||||
from: brewPhpAlias.data(using: .utf8)!
|
||||
).first!
|
||||
|
||||
Log.info("[BREW] On your system, the `php` formula means version \(homebrewPackage.version)!")
|
||||
Log.info("[BREW] On your system, the `php` formula means version \(homebrewPackage.version).")
|
||||
|
||||
// Check if that version actually corresponds to an older version
|
||||
let phpConfigExecutablePath = "\(Paths.optPath)/php/bin/php-config"
|
||||
if FileSystem.fileExists(phpConfigExecutablePath) {
|
||||
let longVersionString = Command.execute(
|
||||
path: phpConfigExecutablePath,
|
||||
arguments: ["--version"],
|
||||
trimNewlines: false
|
||||
).trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
if let version = try? VersionNumber.parse(longVersionString) {
|
||||
PhpEnvironments.brewPhpAlias = version.short
|
||||
if version.short != homebrewPackage.version {
|
||||
Log.info("[BREW] An older version of `php` is actually installed (\(version.short)).")
|
||||
}
|
||||
} else {
|
||||
Log.warn("Could not determine the actual version of the php binary; assuming Homebrew is correct.")
|
||||
PhpEnvironments.brewPhpAlias = homebrewPackage.version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
@ -77,7 +97,12 @@ class PhpEnvironments {
|
||||
|
||||
As such, we take that information from Homebrew.
|
||||
*/
|
||||
static var brewPhpAlias: String {
|
||||
static var brewPhpAlias: String = ""
|
||||
|
||||
/**
|
||||
It's possible for the alias to be newer than the actual installed version of PHP.
|
||||
*/
|
||||
static var homebrewBrewPhpAlias: String {
|
||||
if PhpEnvironments.shared.homebrewPackage == nil { return "8.2" }
|
||||
|
||||
return PhpEnvironments.shared.homebrewPackage.version
|
||||
@ -144,7 +169,12 @@ class PhpEnvironments {
|
||||
|
||||
// Avoid inserting a duplicate
|
||||
if !supportedVersions.contains(phpAlias) && FileSystem.fileExists("\(Paths.optPath)/php/bin/php") {
|
||||
supportedVersions.insert(phpAlias)
|
||||
let phpAliasInstall = PhpInstallation(phpAlias)
|
||||
// Before inserting, ensure that the actual output matches the alias
|
||||
// if that isn't the case, our formula remains out-of-date
|
||||
if !phpAliasInstall.missingBinary {
|
||||
supportedVersions.insert(phpAlias)
|
||||
}
|
||||
}
|
||||
|
||||
availablePhpVersions = Array(supportedVersions)
|
||||
|
@ -12,6 +12,8 @@ class PhpInstallation {
|
||||
|
||||
var versionNumber: VersionNumber
|
||||
|
||||
var missingBinary: Bool = false
|
||||
|
||||
var isHealthy: Bool = true
|
||||
|
||||
/**
|
||||
@ -35,6 +37,10 @@ class PhpInstallation {
|
||||
// The parser should always work, or the string has to be very unusual.
|
||||
// If so, the app SHOULD crash, so that the users report what's up.
|
||||
self.versionNumber = try! VersionNumber.parse(longVersionString)
|
||||
} else {
|
||||
// Keep track that the `php-config` binary is missing; this often means there's a mismatch between
|
||||
// the `php` version alias and the actual installed version (e.g. you haven't upgraded `php`)
|
||||
missingBinary = true
|
||||
}
|
||||
|
||||
if FileSystem.fileExists(phpExecutablePath) {
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
struct BrewPhpFormula {
|
||||
struct BrewPhpFormula: Equatable {
|
||||
/// Name of the formula.
|
||||
let name: String
|
||||
|
||||
@ -48,6 +48,25 @@ struct BrewPhpFormula {
|
||||
return upgradeVersion != nil
|
||||
}
|
||||
|
||||
/// Whether this formula alias is different.
|
||||
var hasUpgradedFormulaAlias: Bool {
|
||||
return self.shortVersion == PhpEnvironments.homebrewBrewPhpAlias
|
||||
&& PhpEnvironments.homebrewBrewPhpAlias != PhpEnvironments.brewPhpAlias
|
||||
}
|
||||
|
||||
var unavailableAfterUpgrade: Bool {
|
||||
if installedVersion == nil || upgradeVersion == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if let installed = try? VersionNumber.parse(self.installedVersion!),
|
||||
let upgrade = try? VersionNumber.parse(self.upgradeVersion!) {
|
||||
return upgrade.short != installed.short
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/// The associated Homebrew folder with this PHP formula.
|
||||
var homebrewFolder: String {
|
||||
let resolved = name
|
||||
@ -60,7 +79,7 @@ struct BrewPhpFormula {
|
||||
/// The short version associated with this formula, if installed.
|
||||
var shortVersion: String? {
|
||||
guard let version = self.installedVersion else {
|
||||
return nil
|
||||
return self.displayName.replacingOccurrences(of: "PHP ", with: "")
|
||||
}
|
||||
|
||||
return VersionNumber.make(from: version)?.short ?? nil
|
||||
|
@ -17,6 +17,7 @@ extension HandlesBrewPhpFormulae {
|
||||
public func refreshPhpVersions(loadOutdated: Bool) async {
|
||||
let items = await loadPhpVersions(loadOutdated: loadOutdated)
|
||||
Task { @MainActor in
|
||||
await PhpEnvironments.shared.determinePhpAlias()
|
||||
Brew.shared.formulae.phpVersions = items
|
||||
}
|
||||
}
|
||||
@ -43,7 +44,8 @@ class BrewPhpFormulaeHandler: HandlesBrewPhpFormulae {
|
||||
}
|
||||
|
||||
return Brew.phpVersionFormulae.map { (version, formula) in
|
||||
let fullVersion = PhpEnvironments.shared.cachedPhpInstallations[version]?.versionNumber.text
|
||||
let fullVersion = PhpEnvironments.shared.cachedPhpInstallations[version]?
|
||||
.versionNumber.text
|
||||
|
||||
var upgradeVersion: String?
|
||||
|
||||
|
@ -44,12 +44,22 @@ class ModifyPhpVersionCommand: BrewCommand {
|
||||
description: "PHP Monitor is preparing Homebrew..."
|
||||
))
|
||||
|
||||
let unavailable = upgrading.first(where: { formula in
|
||||
formula.unavailableAfterUpgrade
|
||||
})
|
||||
|
||||
// Make sure the tap is installed
|
||||
try await self.checkPhpTap(onProgress)
|
||||
|
||||
// Try to run all upgrade and installation operations
|
||||
try await self.upgradePackages(onProgress)
|
||||
try await self.installPackages(onProgress)
|
||||
if unavailable == nil {
|
||||
// Try to run all upgrade and installation operations
|
||||
try await self.upgradePackages(onProgress)
|
||||
try await self.installPackages(onProgress)
|
||||
} else {
|
||||
// Simply upgrade `php` to the latest version
|
||||
try await self.upgradeMainPhpFormula(unavailable!, onProgress)
|
||||
await PhpEnvironments.shared.determinePhpAlias()
|
||||
}
|
||||
|
||||
// Re-check the installed versions
|
||||
await PhpEnvironments.detectPhpVersions()
|
||||
@ -61,6 +71,39 @@ class ModifyPhpVersionCommand: BrewCommand {
|
||||
await self.completedOperations(onProgress)
|
||||
}
|
||||
|
||||
private func upgradeMainPhpFormula(
|
||||
_ unavailable: BrewPhpFormula,
|
||||
_ onProgress: @escaping (BrewCommandProgress) -> Void
|
||||
) async throws {
|
||||
// Determine which version was previously available (that will become unavailable)
|
||||
guard let short = try? VersionNumber
|
||||
.parse(unavailable.installedVersion!).short else {
|
||||
return
|
||||
}
|
||||
|
||||
// Upgrade the main formula
|
||||
let command = """
|
||||
export HOMEBREW_NO_INSTALL_CLEANUP=true; \
|
||||
\(Paths.brew) upgrade php;
|
||||
\(Paths.brew) install php@\(short);
|
||||
"""
|
||||
|
||||
// Run the upgrade command
|
||||
try await run(command, onProgress)
|
||||
}
|
||||
|
||||
private func checkPhpTap(_ onProgress: @escaping (BrewCommandProgress) -> Void) async throws {
|
||||
if !BrewDiagnostics.installedTaps.contains("shivammathur/php") {
|
||||
let command = "brew tap shivammathur/php"
|
||||
try await run(command, onProgress)
|
||||
}
|
||||
|
||||
if !BrewDiagnostics.installedTaps.contains("shivammathur/extensions") {
|
||||
let command = "brew tap shivammathur/extensions"
|
||||
try await run(command, onProgress)
|
||||
}
|
||||
}
|
||||
|
||||
private func upgradePackages(_ onProgress: @escaping (BrewCommandProgress) -> Void) async throws {
|
||||
// If no upgrades are needed, early exit
|
||||
if self.upgrading.isEmpty {
|
||||
|
@ -225,7 +225,7 @@ struct PhpVersionManagerView: View {
|
||||
} else {
|
||||
Button("phpman.buttons.install".localizedForSwiftUI) {
|
||||
Task { await self.install(formula) }
|
||||
}
|
||||
}.disabled(formula.hasUpgradedFormulaAlias)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -240,7 +240,11 @@ struct PhpVersionManagerView: View {
|
||||
}
|
||||
}
|
||||
|
||||
if formula.isInstalled && formula.hasUpgrade {
|
||||
if formula.hasUpgradedFormulaAlias {
|
||||
Text("phpman.version.automatic_upgrade".localized(formula.shortVersion!))
|
||||
.font(.system(size: 11))
|
||||
.foregroundColor(.gray)
|
||||
} else if formula.isInstalled && formula.hasUpgrade {
|
||||
Text("phpman.version.has_update".localized(
|
||||
formula.installedVersion!,
|
||||
formula.upgradeVersion!
|
||||
|
@ -90,6 +90,7 @@
|
||||
"phpman.version.has_update" = "Version %@ installiert, %@ verfügbar.";
|
||||
"phpman.version.installed" = "Version %@ ist derzeit installiert.";
|
||||
"phpman.version.available_for_installation" = "Diese Version kann installiert werden.";
|
||||
"phpman.version.automatic_upgrade" = "Diese Version wird automatisch installiert, indem eine ältere Version aktualisiert wird.";
|
||||
"phpman.buttons.uninstall" = "Deinstallieren";
|
||||
"phpman.buttons.install" = "Installieren";
|
||||
"phpman.buttons.update" = "Aktualisieren";
|
||||
|
@ -115,6 +115,7 @@
|
||||
"phpman.version.has_update" = "Version %@ installed, %@ available.";
|
||||
"phpman.version.installed" = "Version %@ is currently installed.";
|
||||
"phpman.version.available_for_installation" = "This version can be installed.";
|
||||
"phpman.version.automatic_upgrade" = "This version will be automatically installed by upgrading an older version.";
|
||||
"phpman.buttons.uninstall" = "Uninstall";
|
||||
"phpman.buttons.install" = "Install";
|
||||
"phpman.buttons.update" = "Update";
|
||||
|
@ -107,6 +107,7 @@
|
||||
"phpman.version.has_update" = "Version %@ installée, %@ disponible.";
|
||||
"phpman.version.installed" = "La version %@ est actuellement installée.";
|
||||
"phpman.version.available_for_installation" = "Cette version peut être installée.";
|
||||
"phpman.version.automatic_upgrade" = "Cette version sera installée automatiquement en mettant à jour une version plus ancienne.";
|
||||
"phpman.buttons.uninstall" = "Désinstaller";
|
||||
"phpman.buttons.install" = "Installer";
|
||||
"phpman.buttons.update" = "Mettre à jour";
|
||||
|
@ -91,6 +91,7 @@
|
||||
"phpman.version.has_update" = "Versie %@ geïnstalleerd, %@ beschikbaar.";
|
||||
"phpman.version.installed" = "Versie %@ is momenteel geïnstalleerd.";
|
||||
"phpman.version.available_for_installation" = "Deze versie kan worden geïnstalleerd.";
|
||||
"phpman.version.automatic_upgrade" = "Deze versie zal automatisch geïnstalleerd worden door een upgrade.";
|
||||
"phpman.buttons.uninstall" = "Verwijderen";
|
||||
"phpman.buttons.install" = "Installeren";
|
||||
"phpman.buttons.update" = "Bijwerken";
|
||||
|
@ -90,6 +90,7 @@
|
||||
"phpman.version.has_update" = "Versão %@ instalada, %@ disponível.";
|
||||
"phpman.version.installed" = "Versão %@ atualmente instalada.";
|
||||
"phpman.version.available_for_installation" = "Esta versão pode ser instalada.";
|
||||
"phpman.version.automatic_upgrade" = "Esta versão será instalada automaticamente ao atualizar uma versão mais antiga.";
|
||||
"phpman.buttons.uninstall" = "Desinstalar";
|
||||
"phpman.buttons.install" = "Instalar";
|
||||
"phpman.buttons.update" = "Atualizar";
|
||||
|
@ -90,6 +90,7 @@
|
||||
"phpman.version.has_update" = "Phiên bản %@ được cài đặt, Phiên bản %@ có sẵn.";
|
||||
"phpman.version.installed" = "Phiên bản %@ hiện đã được cài đặt.";
|
||||
"phpman.version.available_for_installation" = "Phiên bản này có thể được cài đặt.";
|
||||
"phpman.version.automatic_upgrade" = "Phiên bản này sẽ được cài đặt tự động bằng cách nâng cấp từ một phiên bản cũ hơn.";
|
||||
"phpman.buttons.uninstall" = "Gỡ cài đặt";
|
||||
"phpman.buttons.install" = "Cài đặt";
|
||||
"phpman.buttons.update" = "Cập nhật";
|
||||
|
Reference in New Issue
Block a user