Skip to content

Commit dcf2995

Browse files
authored
Merge pull request #13 from stellarwp/fix/make-sure-as-logs-table-exists-before-using-it
Checks for AS logs table existence before use
2 parents e0f35d6 + 378f389 commit dcf2995

File tree

7 files changed

+66
-125
lines changed

7 files changed

+66
-125
lines changed

.github/pull_request_template.md

Lines changed: 10 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
- [ ] 🧪 Test improvements
1414
- [ ] 🔧 Chore (build process, dependencies, etc.)
1515

16+
## Related Issues
17+
18+
<!-- Link to related issues using GitHub keywords -->
19+
20+
<!-- Ignore if not applicable -->
21+
22+
Closes #<!-- issue number -->
23+
1624
## Pre-Submission Checklist
1725

1826
<!-- Verify all items before submitting this PR -->
@@ -25,127 +33,8 @@
2533
- [ ] **All tests pass**: `slic run wpunit && slic run integration`
2634
- [ ] **No debug code** (var_dump, error_log, etc.) left in production code
2735
- [ ] **No commented-out code** unless specifically needed for reference
28-
29-
### Documentation & Communication
30-
3136
- [ ] **Documentation updated** for any new features or changed behavior
32-
- [ ] **CLAUDE.md updated** if changes affect AI assistance context
33-
- [ ] **Commit messages** follow [conventional commits format](/.github/CONTRIBUTING.md#commit-message-format)
34-
- [ ] **PR title** follows conventional format: `<type>[scope]: description`
35-
36-
### Branch & Conflicts
37-
38-
- [ ] **Branch is up to date** with target branch (usually `main`)
39-
- [ ] **No merge conflicts** exist
40-
- [ ] **CHANGELOG.md updated** (if applicable)
41-
42-
## Testing
43-
44-
### Automated Testing
45-
46-
- [ ] New tests have been added for new functionality
47-
- [ ] All existing tests continue to pass
48-
- [ ] Test coverage is maintained or improved
49-
50-
### Manual Testing
51-
52-
<!-- Describe how you tested this change manually -->
53-
54-
**Test Environment:**
55-
56-
- WordPress version:
57-
- PHP version:
58-
59-
**Test Steps:**
60-
61-
1. **Setup**: What initial setup is required? (e.g., `composer install`, activate plugins)
62-
2. **Steps to Reproduce**:
63-
- Go to '...'
64-
- Click on '....'
65-
- Execute '....'
66-
- Verify '....'
67-
3. **Verification**: What is the expected outcome?
68-
69-
**Expected Results:**
70-
<!-- What should happen -->
71-
72-
**Actual Results:**
73-
<!-- What actually happened -->
74-
75-
## Documentation Updates
76-
77-
- [ ] Code comments added/updated for complex logic
78-
- [ ] PHPDoc blocks added/updated for public methods
79-
- [ ] API documentation updated (`docs/api-reference.md`)
80-
- [ ] User documentation updated (if applicable)
81-
- [ ] Examples provided for new features
82-
83-
## Breaking Changes
84-
85-
<!-- If this is a breaking change, describe the impact -->
86-
87-
**What breaks:**
88-
<!-- Describe what existing functionality will no longer work -->
89-
90-
**Migration path:**
91-
<!-- Provide clear instructions for updating existing code -->
92-
93-
**Justification:**
94-
<!-- Explain why this breaking change is necessary -->
95-
96-
## Related Issues
97-
98-
<!-- Link to related issues using GitHub keywords -->
99-
100-
Closes #<!-- issue number -->
101-
Fixes #<!-- issue number -->
102-
Related to #<!-- issue number -->
103-
104-
## Additional Context
105-
106-
<!-- Add any other context, screenshots, or information about the PR here -->
107-
108-
### Performance Impact
109-
<!-- If applicable, describe any performance implications -->
110-
111-
### Security Considerations
112-
<!-- If applicable, describe any security implications -->
113-
114-
### Screenshots
115-
116-
<!-- If your changes include UI components, provide before/after screenshots -->
117-
118-
**Before:**
119-
<!-- Add screenshot here -->
120-
121-
**After:**
122-
<!-- Add screenshot here -->
123-
124-
---
125-
126-
## For Reviewers
127-
128-
### Review Checklist
129-
130-
- [ ] Code follows WordPress coding standards
131-
- [ ] Proper error handling is implemented
132-
- [ ] Security best practices are followed
133-
- [ ] Performance implications are acceptable
134-
- [ ] Documentation is complete and accurate
135-
- [ ] Tests provide adequate coverage
136-
- [ ] Breaking changes are properly documented
137-
138-
---
139-
140-
<!--
141-
By submitting this PR, I confirm that:
142-
- I have read and followed the contributing guidelines
143-
- My code follows the project's coding standards
144-
- I have performed a self-review of my own code
145-
- I have made corresponding changes to the documentation
146-
- My changes generate no new warnings or errors
147-
- I have added tests that prove my fix is effective or that my feature works
148-
- New and existing unit tests pass locally with my changes
149-
-->
37+
- [ ] **New tests** have been added for new functionality
38+
- [ ] **All existing tests** continue to pass
15039

15140
**📖 Read the full contributing guidelines: [CONTRIBUTING.md](/.github/CONTRIBUTING.md)**

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
All notable changes to this project will be documented in this file. This project adhere to the [Semantic Versioning](http://semver.org/) standard.
44

5+
## [0.0.5] 2025-08-19
6+
7+
* Fix - Ensure the AS logger table exists before using it. Introduce a filter `shepherd_<hook_prefix>_should_log` to disable logging.
8+
9+
[0.0.5]: https://github.com/stellarwp/shepherd/releases/tag/0.0.5
10+
11+
## [0.0.4] 2025-08-04
12+
13+
* Fix - Deal with issues of auto-loading the functions.php file while using Strauss.
14+
* Fix - Issue with php 7.4.
15+
16+
[0.0.4]: https://github.com/stellarwp/shepherd/releases/tag/0.0.4
17+
518
## [0.0.3] 2025-07-31
619

720
* Fix - Removed an empty line after the columns and before the primary key of the Table creation SQL.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Shepherd comes with a set of pre-packaged tasks to handle common background oper
2525

2626
## Contributing
2727

28-
We welcome contributions! Please see our contributing guidelines for more information. (TODO: Add a CONTRIBUTING.md file)
28+
We welcome contributions! Please see our contributing guidelines for more information.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"php": ">=7.4",
3737
"stellarwp/db": "^1.1",
3838
"stellarwp/schema": "^2.0",
39-
"woocommerce/action-scheduler": "3.9.2",
39+
"woocommerce/action-scheduler": "3.9.3",
4040
"psr/log": "^1.1"
4141
},
4242
"require-dev": {

shepherd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @wordpress-plugin
1010
* Plugin Name: Shepherd
1111
* Description: A library for offloading tasks to background processes.
12-
* Version: 0.0.3
12+
* Version: 0.0.5
1313
* Author: StellarWP
1414
* Author URI: https://stellarwp.com
1515
* License: GPL-2.0-or-later

src/Config.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use StellarWP\ContainerContract\ContainerInterface;
1414
use StellarWP\Shepherd\Contracts\Logger;
1515
use StellarWP\Shepherd\Loggers\ActionScheduler_DB_Logger;
16+
use StellarWP\Shepherd\Loggers\Null_Logger;
17+
use StellarWP\Shepherd\Loggers\DB_Logger;
18+
use StellarWP\Shepherd\Tables\AS_Logs;
1619

1720
/**
1821
* Shepherd Config
@@ -97,12 +100,24 @@ public static function get_hook_prefix(): string {
97100
* Gets the logger.
98101
*
99102
* @since 0.0.1
103+
* @since 0.0.5 Introduce a filter to disable logging. Ensures the AS logger table exists before using it.
100104
*
101105
* @return Logger
102106
*/
103107
public static function get_logger(): Logger {
104108
if ( ! static::$logger ) {
105-
static::$logger = new ActionScheduler_DB_Logger();
109+
/**
110+
* Filters whether to log anything.
111+
*
112+
* @since 0.0.5
113+
*
114+
* @param bool $should_log Whether to log anything.
115+
*
116+
* @return bool Whether to log anything.
117+
*/
118+
$should_log = (bool) apply_filters( 'shepherd_' . static::get_hook_prefix() . '_should_log', true );
119+
120+
static::$logger = ! $should_log ? new Null_Logger() : ( self::get_container()->get( AS_Logs::class )->exists() ? new ActionScheduler_DB_Logger() : new DB_Logger() );
106121
}
107122

108123
return static::$logger;

tests/wpunit/Config_Test.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
use RuntimeException;
99
use StellarWP\ContainerContract\ContainerInterface;
1010
use StellarWP\Shepherd\Loggers\ActionScheduler_DB_Logger;
11+
use StellarWP\Shepherd\Loggers\DB_Logger;
1112
use StellarWP\Shepherd\Loggers\Null_Logger;
13+
use StellarWP\Schema\Tables\Contracts\Table;
14+
use StellarWP\Shepherd\Tests\Traits\With_Uopz;
1215

1316
class Config_Test extends WPTestCase {
17+
use With_Uopz;
18+
1419
/**
1520
* @test
1621
*/
@@ -50,9 +55,28 @@ public function it_should_throw_exception_if_setting_empty_hook_prefix(): void {
5055
* @test
5156
*/
5257
public function it_should_get_default_db_logger_if_none_is_set(): void {
58+
Config::set_hook_prefix( 'my_prefix' );
5359
$this->assertInstanceOf( ActionScheduler_DB_Logger::class, Config::get_logger() );
5460
}
5561

62+
/**
63+
* @test
64+
*/
65+
public function it_should_get_db_logger_if_as_table_doesnt_exist(): void {
66+
Config::set_hook_prefix( 'my_prefix' );
67+
$this->set_class_fn_return( Table::class, 'exists', false );
68+
$this->assertInstanceOf( DB_Logger::class, Config::get_logger() );
69+
}
70+
71+
/**
72+
* @test
73+
*/
74+
public function it_should_get_null_logger_if_should_log_is_false(): void {
75+
Config::set_hook_prefix( 'my_prefix' );
76+
add_filter( 'shepherd_my_prefix_should_log', '__return_false' );
77+
$this->assertInstanceOf( Null_Logger::class, Config::get_logger() );
78+
}
79+
5680
/**
5781
* @test
5882
*/

0 commit comments

Comments
 (0)