-
-
Notifications
You must be signed in to change notification settings - Fork 523
Refactor: Upgrade api service #7731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+204
β30
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
21393fa
Fix(upgrade): ensure fresh release data and accurate update availabilβ¦
DawoudIO adba971
refactor(upgrade-api): extract reusable UpgradeAPIService to eliminatβ¦
DawoudIO 4b3ae5a
style(admin-routes): move inline imports to top of system.php
DawoudIO 8d66d16
Update upgrade-wizard-app.js
DawoudIO 0f12e9f
Update src/ChurchCRM/Service/UpgradeAPIService.php
DawoudIO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
|
|
||
| namespace ChurchCRM\Service; | ||
|
|
||
| use ChurchCRM\Utils\ChurchCRMReleaseManager; | ||
|
|
||
| /** | ||
| * UpgradeAPIService | ||
| * | ||
| * Provides API operations for system upgrade and update checking. | ||
| * This service wraps ChurchCRMReleaseManager operations for admin API routes. | ||
| * Admin authentication is enforced by AdminRoleAuthMiddleware at the application level. | ||
| */ | ||
| class UpgradeAPIService | ||
| { | ||
| /** | ||
| * Download the latest release from GitHub | ||
| * | ||
| * @return array Upgrade file information (fileName, fullPath, releaseNotes, sha1) | ||
| * @throws \Exception | ||
| */ | ||
| public static function downloadLatestRelease(): array | ||
| { | ||
| return ChurchCRMReleaseManager::downloadLatestRelease(); | ||
| } | ||
|
|
||
| /** | ||
| * Apply the upgrade with the given file and SHA1 hash | ||
| * | ||
| * @param string $fullPath Full path to upgrade file | ||
| * @param string $sha1 SHA1 hash for verification | ||
| * @return void | ||
| * @throws \Exception | ||
| */ | ||
| public static function doUpgrade(string $fullPath, string $sha1): void | ||
| { | ||
| ChurchCRMReleaseManager::doUpgrade($fullPath, $sha1); | ||
| } | ||
|
|
||
| /** | ||
| * Refresh upgrade information from GitHub and update session state | ||
| * | ||
| * @return array Session update data (updateAvailable, updateVersion, latestVersion) | ||
| * @throws \Exception | ||
| */ | ||
| public static function refreshUpgradeInfo(): array | ||
| { | ||
| // Force fresh check from GitHub | ||
| ChurchCRMReleaseManager::checkForUpdates(); | ||
|
|
||
| // Recompute whether an update is available | ||
| $updateInfo = ChurchCRMReleaseManager::checkSystemUpdateAvailable(); | ||
| $_SESSION['systemUpdateAvailable'] = $updateInfo['available']; | ||
| $_SESSION['systemUpdateVersion'] = $updateInfo['version']; | ||
| $_SESSION['systemLatestVersion'] = $updateInfo['latestVersion']; | ||
|
|
||
| // Return updated session data | ||
| return [ | ||
| 'updateAvailable' => $_SESSION['systemUpdateAvailable'] ?? false, | ||
| 'updateVersion' => isset($_SESSION['systemUpdateVersion']) ? $_SESSION['systemUpdateVersion']->__toString() : null, | ||
| 'latestVersion' => isset($_SESSION['systemLatestVersion']) ? $_SESSION['systemLatestVersion']->__toString() : null | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional logic is incorrect. When a method is provided,
dataTypeshould be set to "json", but the current logic only sets it when a method is NOT provided. This means GET requests won't havedataType: "json"but POST/PUT requests will.This should be:
The same bug exists in the original
APIRequestfunction above (lines 6-10).