| 1 |
<?php |
| 2 |
/** |
| 3 |
* How a cleanup task decides what is expired. |
| 4 |
* |
| 5 |
* @package Templately |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Templately\Modules\Utilities\Cleanup; |
| 9 |
|
| 10 |
/** |
| 11 |
* Three kinds, because "expired" genuinely means three different things across |
| 12 |
* the plugin's disposable data — and collapsing them into one age window is a |
| 13 |
* defect, not a simplification: |
| 14 |
* |
| 15 |
* - AGE — untouched for longer than the ONE shared retention window. |
| 16 |
* Import sessions, AI process records, and the working |
| 17 |
* directories that belong to them. These already all used 7 days; |
| 18 |
* sharing the window removes the possibility of future drift. |
| 19 |
* - COUNT — keep the newest N, whatever their age. Import logs. An age rule |
| 20 |
* here deletes the log of a week-old failure support is still |
| 21 |
* investigating, and keeps two hundred from one busy afternoon. |
| 22 |
* - INTRINSIC — the writer recorded an expiry on each item; honour that and |
| 23 |
* ignore both the window and the count. Plugin cache entries, the |
| 24 |
* cached pattern library, agent approval records. Applying the |
| 25 |
* shared window here would delete cache the plugin still |
| 26 |
* considers live — and the pattern library rebuilds over the |
| 27 |
* network, so that costs real requests. |
| 28 |
* |
| 29 |
* Not a PHP 8.1 enum: this plugin supports PHP 7.4. |
| 30 |
*/ |
| 31 |
final class RetentionKind { |
| 32 |
|
| 33 |
const AGE = 'age'; |
| 34 |
const COUNT = 'count'; |
| 35 |
const INTRINSIC = 'intrinsic'; |
| 36 |
|
| 37 |
/** |
| 38 |
* @return string[] |
| 39 |
*/ |
| 40 |
public static function all(): array { |
| 41 |
return [ self::AGE, self::COUNT, self::INTRINSIC ]; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* @param mixed $kind |
| 46 |
* @return bool |
| 47 |
*/ |
| 48 |
public static function is_valid( $kind ): bool { |
| 49 |
return is_string( $kind ) && in_array( $kind, self::all(), true ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Whether the shared age window applies to this kind. |
| 54 |
* |
| 55 |
* @param string $kind |
| 56 |
* @return bool |
| 57 |
*/ |
| 58 |
public static function uses_age( string $kind ): bool { |
| 59 |
return self::AGE === $kind; |
| 60 |
} |
| 61 |
} |
| 62 |
|