mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
👌 Verify switch succeeded (#111)
- Verify switch was successful - Suggest "Fix My Valet" - Restart nginx when switching PHP versions
This commit is contained in:
@ -115,7 +115,7 @@ class Actions {
|
|||||||
brew("services stop php")
|
brew("services stop php")
|
||||||
brew("services stop nginx")
|
brew("services stop nginx")
|
||||||
|
|
||||||
brew("link php --force")
|
brew("link php --overwrite --force")
|
||||||
|
|
||||||
brew("services restart dnsmasq", sudo: true)
|
brew("services restart dnsmasq", sudo: true)
|
||||||
brew("services restart php", sudo: true)
|
brew("services restart php", sudo: true)
|
||||||
|
@ -155,4 +155,16 @@ class PhpEnv {
|
|||||||
.matching(constraint: $0.trimmingCharacters(in: .whitespacesAndNewlines))
|
.matching(constraint: $0.trimmingCharacters(in: .whitespacesAndNewlines))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Validates whether the currently running version matches the provided version.
|
||||||
|
*/
|
||||||
|
public func validate(_ version: String) -> Bool {
|
||||||
|
if self.currentInstall.version.short == version {
|
||||||
|
print("Switching to version \(version) seems to have succeeded. Validation passed.")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,9 @@ class InternalSwitcher: PhpSwitcher {
|
|||||||
brew("link \(formula) --overwrite --force")
|
brew("link \(formula) --overwrite --force")
|
||||||
brew("services start \(formula)", sudo: true)
|
brew("services start \(formula)", sudo: true)
|
||||||
|
|
||||||
|
Log.info("Restarting nginx, just to be sure!")
|
||||||
|
brew("services restart nginx", sudo: true)
|
||||||
|
|
||||||
Log.info("The new version has been linked!")
|
Log.info("The new version has been linked!")
|
||||||
completion()
|
completion()
|
||||||
}
|
}
|
||||||
|
@ -296,7 +296,16 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
|||||||
// Update the menu
|
// Update the menu
|
||||||
rebuild()
|
rebuild()
|
||||||
|
|
||||||
|
let sendLocalNotification = {
|
||||||
|
LocalNotification.send(
|
||||||
|
title: String(format: "notification.version_changed_title".localized, version),
|
||||||
|
subtitle: String(format: "notification.version_changed_desc".localized, version)
|
||||||
|
)
|
||||||
|
PhpEnv.phpInstall.notifyAboutBrokenPhpFpm()
|
||||||
|
}
|
||||||
|
|
||||||
let completion = {
|
let completion = {
|
||||||
|
// Fire off the delegate method
|
||||||
PhpEnv.shared.delegate?.switcherDidCompleteSwitch()
|
PhpEnv.shared.delegate?.switcherDidCompleteSwitch()
|
||||||
|
|
||||||
// Mark as no longer busy
|
// Mark as no longer busy
|
||||||
@ -307,12 +316,16 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
|||||||
updatePhpVersionInStatusBar()
|
updatePhpVersionInStatusBar()
|
||||||
rebuild()
|
rebuild()
|
||||||
|
|
||||||
let sendLocalNotification = {
|
if !PhpEnv.shared.validate(version) {
|
||||||
LocalNotification.send(
|
let outcome = Alert.present(
|
||||||
title: String(format: "notification.version_changed_title".localized, version),
|
messageText: "alert.php_switch_failed.title".localized(version),
|
||||||
subtitle: String(format: "notification.version_changed_desc".localized, version)
|
informativeText: "alert.php_switch_failed.info".localized(version),
|
||||||
)
|
buttonTitle: "alert.php_switch_failed.confirm".localized,
|
||||||
PhpEnv.phpInstall.notifyAboutBrokenPhpFpm()
|
secondButtonTitle: "alert.php_switch_failed.cancel".localized, style: .informational)
|
||||||
|
if outcome {
|
||||||
|
MainMenu.shared.fixMyValet()
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run composer updates
|
// Run composer updates
|
||||||
@ -322,6 +335,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
|||||||
sendLocalNotification()
|
sendLocalNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update stats
|
||||||
Stats.incrementSuccessfulSwitchCount()
|
Stats.incrementSuccessfulSwitchCount()
|
||||||
Stats.evaluateSponsorMessageShouldBeDisplayed()
|
Stats.evaluateSponsorMessageShouldBeDisplayed()
|
||||||
}
|
}
|
||||||
@ -366,7 +380,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
|||||||
// MARK: - Private Methods
|
// MARK: - Private Methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Updates the global dependencies and runs the completion callback when done.
|
||||||
*/
|
*/
|
||||||
private func updateGlobalDependencies(notify: Bool, completion: @escaping (Bool) -> Void) {
|
private func updateGlobalDependencies(notify: Bool, completion: @escaping (Bool) -> Void) {
|
||||||
if !Shell.fileExists("/usr/local/bin/composer") {
|
if !Shell.fileExists("/usr/local/bin/composer") {
|
||||||
|
@ -92,7 +92,6 @@
|
|||||||
"site_list.alert.folder_missing.cancel" = "Cancel Link";
|
"site_list.alert.folder_missing.cancel" = "Cancel Link";
|
||||||
"site_list.alert.folder_missing.return" = "OK";
|
"site_list.alert.folder_missing.return" = "OK";
|
||||||
|
|
||||||
|
|
||||||
"site_list.add.modal_description" = "First, select which folder you would like to link.";
|
"site_list.add.modal_description" = "First, select which folder you would like to link.";
|
||||||
|
|
||||||
// SITE LIST ACTIONS
|
// SITE LIST ACTIONS
|
||||||
@ -191,6 +190,12 @@ problem manually, using your own Terminal app (this just shows you the output)."
|
|||||||
"alert.composer_php_requirement.title" = "`%@` has the following PHP requirement: \"php\":\n\"%@\".";
|
"alert.composer_php_requirement.title" = "`%@` has the following PHP requirement: \"php\":\n\"%@\".";
|
||||||
"alert.composer_php_requirement.info" = "This required PHP version was determined by checking the `%@` field in the `composer.json` file when the site list was last refreshed.";
|
"alert.composer_php_requirement.info" = "This required PHP version was determined by checking the `%@` field in the `composer.json` file when the site list was last refreshed.";
|
||||||
|
|
||||||
|
// Suggest Fix My Valet
|
||||||
|
"alert.php_switch_failed.title" = "Switching to PHP %@ seems to have failed.";
|
||||||
|
"alert.php_switch_failed.info" = "PHP Monitor has detected that PHP %@ is not active after completing its switching procedure. You can try to run \"Fix My Valet\" and switch again after that. Do you want to try \"Fix My Valet\"?";
|
||||||
|
"alert.php_switch_failed.confirm" = "Yes, run \"Fix My Valet\"";
|
||||||
|
"alert.php_switch_failed.cancel" = "Do Not Run";
|
||||||
|
|
||||||
// Fix My Valet Started
|
// Fix My Valet Started
|
||||||
"alert.fix_my_valet.title" = "Having issues? Fix My Valet is ready to commence!";
|
"alert.fix_my_valet.title" = "Having issues? Fix My Valet is ready to commence!";
|
||||||
"alert.fix_my_valet.info" = "This can take a while. Please be patient.\n\nWhen this is done, all other services will be halted and PHP %@ will be linked. You will be able to switch to your desired version of PHP once this operation has completed.\n\n(You'll get another alert once Fix My Valet is done.)";
|
"alert.fix_my_valet.info" = "This can take a while. Please be patient.\n\nWhen this is done, all other services will be halted and PHP %@ will be linked. You will be able to switch to your desired version of PHP once this operation has completed.\n\n(You'll get another alert once Fix My Valet is done.)";
|
||||||
@ -258,7 +263,7 @@ You can do this by running `composer global update` in your terminal. After that
|
|||||||
|
|
||||||
/// 7. Multiple services active
|
/// 7. Multiple services active
|
||||||
"startup.errors.services.title" = "Multiple PHP services are active";
|
"startup.errors.services.title" = "Multiple PHP services are active";
|
||||||
"startup.errors.services.desc" = "This can cause php-fpm to serve a more recent version of PHP than the one you'd like to see active. Please terminate all extra PHP processes.\n\nThe easiest solution is to choose the option 'Force load latest PHP version' in the menu bar.\n\nAlternatively, you can fix this manually. You can do this by running `brew services list` and running `sudo brew services stop php@7.3` (and use the version that applies).\n\nPHP Monitor usually handles the starting and stopping of these services, so once the correct version is the only PHP version running you should not have any issues. It is recommended to restart PHP Monitor once you have resolved this issue.\n\nFor more information about this issue, please see the README.md file in the repository on GitHub.";
|
"startup.errors.services.desc" = "This can cause php-fpm to serve a more recent version of PHP than the one you'd like to see active. Please terminate all extra PHP processes.\n\nThe easiest solution is to choose the option 'First Aid & Services > Fix My Valet' in the menu bar.\n\nAlternatively, you can fix this manually. You can do this by running `brew services list` and running `sudo brew services stop php@7.3` (and use the version that applies).\n\nPHP Monitor usually handles the starting and stopping of these services, so once the correct version is the only PHP version running you should not have any issues. It is recommended to restart PHP Monitor once you have resolved this issue.\n\nFor more information about this issue, please see the README.md file in the repository on GitHub.";
|
||||||
|
|
||||||
// SPONSOR ENCOURAGEMENT
|
// SPONSOR ENCOURAGEMENT
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user