Skip to content

[pull] master from ChurchCRM:master#16

Merged
pull[bot] merged 2 commits intorespencer:masterfrom
ChurchCRM:master
Jun 24, 2024
Merged

[pull] master from ChurchCRM:master#16
pull[bot] merged 2 commits intorespencer:masterfrom
ChurchCRM:master

Conversation

@pull
Copy link

@pull pull bot commented Jun 23, 2024

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

@pull pull bot added the ⤵️ pull label Jun 23, 2024
@pull pull bot merged commit a16602b into respencer:master Jun 24, 2024
pull bot pushed a commit that referenced this pull request Jun 17, 2025
# Description & Issue number it closes 
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. -->

Only display error details for SLIM if the application is in debug level
closes ChurchCRM#7240 

## How to test the changes?

Before - 

```
Content-Type: text/html;charset=UTF-8

<!doctype html><html lang="en">    <head>        <meta charset="utf-8">        <meta name="viewport" content="width=device-width, initial-scale=1">        <title>Slim Application Error</title>        <style>            body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif}            h1{margin:0;font-size:48px;font-weight:normal;line-height:48px}            strong{display:inline-block;width:65px}        </style>    </head>    <body>        <h1>Slim Application Error</h1>        <div><p>The application could not run because of the following error:</p><h2>Details</h2><div><strong>Type:</strong> TypeError</div><div><strong>Code:</strong> 0</div><div><strong>Message:</strong> Slim\Exception\HttpSpecializedException::__construct(): Argument #1 ($request) must be of type Psr\Http\Message\ServerRequestInterface, string given, called in /var/www/html/session/routes/password-reset.php on line 80</div><div><strong>File:</strong> /var/www/html/vendor/slim/slim/Slim/Exception/HttpSpecializedException.php</div><div><strong>Line:</strong> 23</div><h2>Trace</h2><pre>#0 /var/www/html/session/routes/password-reset.php(80): Slim\Exception\HttpSpecializedException-&gt;__construct()
#1 /var/www/html/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(38): userPasswordReset()
#2 /var/www/html/vendor/slim/slim/Slim/Routing/Route.php(363): Slim\Handlers\Strategies\RequestResponse-&gt;__invoke()
#3 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): Slim\Routing\Route-&gt;handle()
#4 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): Slim\MiddlewareDispatcher-&gt;handle()
#5 /var/www/html/vendor/slim/slim/Slim/Routing/Route.php(321): Slim\MiddlewareDispatcher-&gt;handle()
#6 /var/www/html/vendor/slim/slim/Slim/Routing/RouteRunner.php(74): Slim\Routing\Route-&gt;run()
#7 /var/www/html/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(77): Slim\Routing\RouteRunner-&gt;handle()
#8 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(129): Slim\Middleware\ErrorMiddleware-&gt;process()
#9 /var/www/html/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(45): Psr\Http\Server\RequestHandlerInterface@anonymous-&gt;handle()
#10 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(129): Slim\Middleware\RoutingMiddleware-&gt;process()
#11 /var/www/html/ChurchCRM/Slim/Middleware/VersionMiddleware.php(14): Psr\Http\Server\RequestHandlerInterface@anonymous-&gt;handle()
#12 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(280): ChurchCRM\Slim\Middleware\VersionMiddleware-&gt;__invoke()
#13 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): Psr\Http\Server\RequestHandlerInterface@anonymous-&gt;handle()
#14 /var/www/html/vendor/slim/slim/Slim/App.php(209): Slim\MiddlewareDispatcher-&gt;handle()
#15 /var/www/html/vendor/slim/slim/Slim/App.php(193): Slim\App-&gt;handle()
#16 /var/www/html/session/index.php(90): Slim\App-&gt;run()
#17 {main}</pre></div>        <a href="#" onclick="window.history.go(-1)">Go Back</a>    </body></html>%                                      
```

**After** 
```
 CRM % curl --path-as-is -i -s -k -X $'POST' \
    -H $'Host: localhost' -H $'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36' -H $'Accept: */*' -H $'Accept-Language: en-US,en;q=0.5' -H $'Accept-Encoding: gzip, deflate, br' -H $'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H $'X-Requested-With: XMLHttpRequest' -H $'Content-Length: 23' -H $'Origin: http://localhost' -H $'Connection: keep-alive' -H $'Referer: http://localhost/session/forgot-password/reset-request' -H $'sec-ch-ua-platform: \"Windows\"' -H $'sec-ch-ua: \"Google Chrome\";v=\"117\", \"Chromium\";v=\"117\", \"Not=A?Brand\";v=\"24\"' -H $'sec-ch-ua-mobile: ?0' -H $'Priority: u=0' \
    -b $'CRM-<redacted>=<redacted>' \
    --data-binary $'{\"userName\":\"fakeUser\"}' \
    $'http://localhost/session/forgot-password/reset-request'
HTTP/1.1 500 Internal Server Error
Date: Mon, 03 Feb 2025 00:56:20 GMT
Server: Apache/2.4.62 (Debian)
X-Powered-By: PHP/8.4.2
Set-Cookie: CRM-40d1b2d83998fabacb726e5bc3d22129=5ef343dac86e3f4708ea2cba8168ae05; path=/
CRM_VERSION: 5.14.0
Content-Length: 672
Connection: close
Content-Type: text/html;charset=UTF-8

<!doctype html><html lang="en">    <head>        <meta charset="utf-8">        <meta name="viewport" content="width=device-width, initial-scale=1">        <title>Slim Application Error</title>        <style>            body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif}            h1{margin:0;font-size:48px;font-weight:normal;line-height:48px}            strong{display:inline-block;width:65px}        </style>    </head>    <body>        <h1>Slim Application Error</h1>        <div><p>A website error has occurred. Sorry for the temporary inconvenience.</p></div>        <a href="#" onclick="window.history.go(-1)">Go Back</a>    </body></html>%           
```

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

# How Has This Been Tested?

<!-- Please describe the tests that you ran to verify your changes.
Provide instructions so we can reproduce. Please also list any relevant
details for your test configuration -->

# Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
pull bot pushed a commit that referenced this pull request Oct 19, 2025
…andling (ChurchCRM#7417)

## Problem

Users were encountering unclear errors when attempting to run database
backups from the Admin menu. The error message was cryptic and didn't
indicate the root cause:

```
Error making API Call to: /api/database/backup
Error text: Unable to create backup archive at /volume1/wwwroot/ChurchCRM-3.0.5/tmp_attach/ChurchCRMBackups/...
```

The underlying issue was that when the backup temporary directory
couldn't be created (typically due to permission issues), the `mkdir()`
call would fail silently. The code would continue execution and fail
later when attempting to write backup files to the non-existent
directory, resulting in confusing error messages.

## Solution

Added proper error handling to the `createEmptyTempFolder()` method in
`src/ChurchCRM/Backup/JobBase.php`. The fix:

1. **Checks if directory creation succeeds** - Verifies the return value
of `mkdir()`
2. **Handles edge cases** - Doesn't throw an exception if the directory
already exists
3. **Provides clear error messages** - Includes:
   - The exact path where creation failed
   - The underlying system error message
   - Actionable guidance to check web server permissions
4. **Logs errors appropriately** - Ensures issues are captured for
debugging

### Code Change

```php
// Before: No error checking
mkdir($TempFolder, 0750, true);

// After: Proper error handling
if (!mkdir($TempFolder, 0750, true) && !is_dir($TempFolder)) {
    $error = error_get_last();
    $message = 'Failed to create backup directory at ' . $TempFolder;
    if ($error) {
        $message .= ': ' . $error['message'];
    }
    $message .= '. Please ensure the web server has write permissions to the parent directory.';
    LoggerUtils::getAppLogger()->error($message);
    throw new \Exception($message, 500);
}
```

## Benefits

- **Early failure detection** - Errors are caught immediately when
directory creation fails
- **Clear error messages** - Users get actionable information about what
went wrong and how to fix it
- **Better debugging** - Errors are properly logged for system
administrators
- **Broader impact** - Fixes both backup AND restore operations since
both inherit from `JobBase`

## Testing

- Verified logic with multiple test scenarios (normal operation,
existing directory, permission denied)
- PHP syntax validation passed
- No breaking changes or side effects

Fixes #8846 (referenced in the issue comments about permission-related
backup failures)

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>


----

*This section details on the original issue you should resolve*

<issue_title>Failed to Run Backup Database</issue_title>
<issue_description>Hi,
Encounter error when run Backup Database from the Admin menu.
The directory and file has permission 755 & 744 receptively.

Following is the error reported.

Error making API Call to: /api/database/backup

Error text: Unable to create backup archive at
/volume1/wwwroot/ChurchCRM-3.0.5/tmp_attach/ChurchCRMBackups/SIBKLChineseChurch-Database.sql]

```
[
  "#0 /volume1/wwwroot/ChurchCRM-3.0.5/api/routes/system/system-database.php(31): ChurchCRM\\Service\\SystemService->getDatabaseBackup(Object(stdClass))",
  "#1 [internal function]: Closure->{closure}(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Array)",
  "#2 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(41): call_user_func(Object(Closure), Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Array)",
  "#3 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/Route.php(335): Slim\\Handlers\\Strategies\\RequestResponse->__invoke(Object(Closure), Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Array)",
  "#4 /volume1/wwwroot/ChurchCRM-3.0.5/ChurchCRM/Slim/Middleware/Role/BaseAuthRoleMiddleware.php(27): Slim\\Route->__invoke(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))",
  "#5 [internal function]: ChurchCRM\\Slim\\Middleware\\Role\\BaseAuthRoleMiddleware->__invoke(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Object(Slim\\Route))",
  "#6 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/DeferredCallable.php(43): call_user_func_array(Object(ChurchCRM\\Slim\\Middleware\\Role\\AdminRoleAuthMiddleware), Array)",
  "#7 [internal function]: Slim\\DeferredCallable->__invoke(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Object(Slim\\Route))",
  "#8 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\\DeferredCallable), Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Object(Slim\\Route))",
  "#9 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\\Route->Slim\\{closure}(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))",
  "#10 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/Route.php(313): Slim\\Route->callMiddlewareStack(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))",
  "#11 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/App.php(495): Slim\\Route->run(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))",
  "#12 /volume1/wwwroot/ChurchCRM-3.0.5/ChurchCRM/Slim/Middleware/VersionMiddleware.php(13): Slim\\App->__invoke(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))",
  "#13 [internal function]: ChurchCRM\\Slim\\Middleware\\VersionMiddleware->__invoke(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Object(Slim\\App))",
  "#14 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/DeferredCallable.php(43): call_user_func_array(Object(ChurchCRM\\Slim\\Middleware\\VersionMiddleware), Array)",
  "#15 [internal function]: Slim\\DeferredCallable->__invoke(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Object(Slim\\App))",
  "#16 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\\DeferredCallable), Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Object(Slim\\App))",
  "#17 /volume1/wwwroot/ChurchCRM-3.0.5/ChurchCRM/Slim/Middleware/AuthMiddleware.php(42): Slim\\App->Slim\\{closure}(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))",
  "#18 [internal function]: ChurchCRM\\Slim\\Middleware\\AuthMiddleware->__invoke(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Object(Closure))",
  "#19 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/DeferredCallable.php(43): call_user_func_array(Object(ChurchCRM\\Slim\\Middleware\\AuthMiddleware), Array)",
  "#20 [internal function]: Slim\\DeferredCallable->__invoke(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Object(Closure))",
  "#21 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\\DeferredCallable), Object(Slim\\Http\\Request), Object(Slim\\Http\\Response), Object(Closure))",
  "#22 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\\App->Slim\\{closure}(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))",
  "#23 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/App.php(388): Slim\\App->callMiddlewareStack(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))",
  "#24 /volume1/wwwroot/ChurchCRM-3.0.5/vendor/slim/slim/Slim/App.php(296): Slim\\App->process(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))",
  "#25 /volume1/wwwroot/ChurchCRM-3.0.5/api/index.php(75): Slim\\App->run()",
  "#26 {main}"
]
```
...

</details>

Fixes ChurchCRM#4300

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey3.medallia.com/?EAHeSx-AP01bZqG0Ld9QLQ) to start
the survey.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants