generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
287 additions
and
857 deletions.
There are no files selected for viewing
This file contains 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 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,89 @@ | ||
# Upgrade Guide | ||
|
||
## Upgrading from 2.x to 3.0 | ||
|
||
### Breaking Changes | ||
|
||
Version 3.0 introduces several breaking changes in how deduplication storage is handled: | ||
|
||
1. **Removed Custom Store Implementations** | ||
- FileStore, RedisStore, and DatabaseStore have been removed | ||
- All deduplication storage now uses Laravel's cache system | ||
|
||
2. **Configuration Changes** | ||
- Store-specific configuration options have been removed | ||
- New simplified cache-based configuration | ||
|
||
### Migration Steps | ||
|
||
1. **Update Package** | ||
```bash | ||
composer require naoray/laravel-github-monolog:^3.0 | ||
``` | ||
|
||
2. **Run Cleanup** | ||
- Keep your old configuration in place | ||
- Run the cleanup code above to remove old storage artifacts | ||
- The cleanup code needs your old configuration to know what to clean up | ||
|
||
3. **Update Configuration** | ||
- Migrate to new store-specific configuration | ||
- Add new cache-based configuration | ||
- Configure Laravel cache as needed | ||
|
||
### Configuration Updates | ||
|
||
#### Before (2.x) | ||
- [ ] ```php | ||
'deduplication' => [ | ||
'store' => 'redis', // or 'file', 'database' | ||
'connection' => 'default', // Redis/Database connection | ||
'prefix' => 'github-monolog:', // Redis prefix | ||
'table' => 'github_monolog_deduplication', // Database table | ||
'time' => 60, | ||
], | ||
``` | ||
|
||
#### After (3.0) | ||
```php | ||
'deduplication' => [ | ||
'store' => null, // (optional) Uses Laravel's default cache store | ||
'time' => 60, // Time window in seconds | ||
'prefix' => 'dedup', // Cache key prefix | ||
], | ||
``` | ||
|
||
### Cleanup Code | ||
|
||
Before updating your configuration to the new format, you should clean up artifacts from the 2.x version. The cleanup code uses your existing configuration to find and remove old storage: | ||
|
||
```php | ||
use Illuminate\Support\Facades\{Schema, Redis, File, DB}; | ||
|
||
// Get your current config | ||
$config = config('logging.channels.github.deduplication', []); | ||
$store = $config['store'] ?? 'file'; | ||
|
||
if ($store === 'database') { | ||
// Clean up database table using your configured connection and table name | ||
$connection = $config['connection'] ?? config('database.default'); | ||
$table = $config['table'] ?? 'github_monolog_deduplication'; | ||
|
||
Schema::connection($connection)->dropIfExists($table); | ||
} | ||
|
||
if ($store === 'redis') { | ||
// Clean up Redis entries using your configured connection and prefix | ||
$connection = $config['connection'] ?? 'default'; | ||
$prefix = $config['prefix'] ?? 'github-monolog:'; | ||
Redis::connection($connection)->del($prefix . 'dedup'); | ||
} | ||
|
||
if ($store === 'file') { | ||
// Clean up file storage using your configured path | ||
$path = $config['path'] ?? storage_path('logs/github-monolog-deduplication.log'); | ||
if (File::exists($path)) { | ||
File::delete($path); | ||
} | ||
} | ||
``` |
This file contains 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 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,65 @@ | ||
<?php | ||
|
||
namespace Naoray\LaravelGithubMonolog\Deduplication; | ||
|
||
use Illuminate\Contracts\Cache\Repository; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\Cache; | ||
|
||
class CacheManager | ||
{ | ||
private const KEY_PREFIX = 'github-monolog'; | ||
private const KEY_SEPARATOR = ':'; | ||
|
||
private readonly string $store; | ||
private readonly Repository $cache; | ||
|
||
public function __construct( | ||
?string $store = null, | ||
private readonly string $prefix = 'dedup', | ||
private readonly int $ttl = 60 | ||
) { | ||
$this->store = $store ?? config('cache.default'); | ||
$this->cache = Cache::store($this->store); | ||
} | ||
|
||
public function has(string $signature): bool | ||
{ | ||
return $this->cache->has($this->composeKey($signature)); | ||
} | ||
|
||
public function add(string $signature): void | ||
{ | ||
$this->cache->put( | ||
$this->composeKey($signature), | ||
Carbon::now()->timestamp, | ||
$this->ttl | ||
); | ||
} | ||
|
||
/** | ||
* Clear all entries for the current prefix. | ||
* Note: This is a best-effort operation and might not work with all cache stores. | ||
*/ | ||
public function clear(): void | ||
{ | ||
// For Redis/Memcached stores that support tag-like operations | ||
if (method_exists($this->cache->getStore(), 'flush')) { | ||
$this->cache->getStore()->flush(); | ||
return; | ||
} | ||
|
||
// For other stores, we'll have to rely on TTL cleanup | ||
// You might want to implement a more specific cleanup strategy | ||
// based on your cache store if needed | ||
} | ||
|
||
private function composeKey(string $signature): string | ||
{ | ||
return implode(self::KEY_SEPARATOR, [ | ||
self::KEY_PREFIX, | ||
$this->prefix, | ||
$signature, | ||
]); | ||
} | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.