diff --git a/phpmon-common/Core/Actions.swift b/phpmon-common/Core/Actions.swift index bf3c5ee..fc41ec7 100644 --- a/phpmon-common/Core/Actions.swift +++ b/phpmon-common/Core/Actions.swift @@ -115,7 +115,7 @@ class Actions { brew("services stop php") brew("services stop nginx") - brew("link php --force") + brew("link php --overwrite --force") brew("services restart dnsmasq", sudo: true) brew("services restart php", sudo: true) diff --git a/phpmon-common/PHP/PHP Version/PhpEnv.swift b/phpmon-common/PHP/PHP Version/PhpEnv.swift index c42bcbd..3d6c159 100644 --- a/phpmon-common/PHP/PHP Version/PhpEnv.swift +++ b/phpmon-common/PHP/PHP Version/PhpEnv.swift @@ -155,4 +155,16 @@ class PhpEnv { .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 + } } diff --git a/phpmon-common/PHP/Switcher/InternalSwitcher.swift b/phpmon-common/PHP/Switcher/InternalSwitcher.swift index 59fccbb..4c313ad 100644 --- a/phpmon-common/PHP/Switcher/InternalSwitcher.swift +++ b/phpmon-common/PHP/Switcher/InternalSwitcher.swift @@ -50,6 +50,9 @@ class InternalSwitcher: PhpSwitcher { brew("link \(formula) --overwrite --force") 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!") completion() } diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index 00cacb3..02b2b07 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -296,7 +296,16 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { // Update the menu 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 = { + // Fire off the delegate method PhpEnv.shared.delegate?.switcherDidCompleteSwitch() // Mark as no longer busy @@ -307,12 +316,16 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { updatePhpVersionInStatusBar() 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() + if !PhpEnv.shared.validate(version) { + let outcome = Alert.present( + messageText: "alert.php_switch_failed.title".localized(version), + informativeText: "alert.php_switch_failed.info".localized(version), + buttonTitle: "alert.php_switch_failed.confirm".localized, + secondButtonTitle: "alert.php_switch_failed.cancel".localized, style: .informational) + if outcome { + MainMenu.shared.fixMyValet() + } + return } // Run composer updates @@ -322,6 +335,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { sendLocalNotification() } + // Update stats Stats.incrementSuccessfulSwitchCount() Stats.evaluateSponsorMessageShouldBeDisplayed() } @@ -366,7 +380,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { // MARK: - Private Methods /** - + Updates the global dependencies and runs the completion callback when done. */ private func updateGlobalDependencies(notify: Bool, completion: @escaping (Bool) -> Void) { if !Shell.fileExists("/usr/local/bin/composer") { diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index fadc204..04e3bc1 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -92,7 +92,6 @@ "site_list.alert.folder_missing.cancel" = "Cancel Link"; "site_list.alert.folder_missing.return" = "OK"; - "site_list.add.modal_description" = "First, select which folder you would like to link."; // 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.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 "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.)"; @@ -258,7 +263,7 @@ You can do this by running `composer global update` in your terminal. After that /// 7. Multiple services 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