SilverStripe\EnvironmentCheck\Checks\FileAgeCheck
Checks for the maximum age of one or more files or folders.
Useful for files which should be frequently auto-generated,
like static caches, as well as for backup files and folders.
Does NOT check for existence of a file (will silently fail).
Examples:
// Checks that Requirements::combine_files() has regenerated files in the last 24h
EnvironmentCheckSuite::register(
'check',
'FileAgeCheck("' . ASSETS_PATH . '/_combined_files/*.js' . '", "-1 day", '>', " . FileAgeCheck::CHECK_ALL) . "'
);
// Checks that at least one backup folder has been created in the last 24h
EnvironmentCheckSuite::register(
'check',
'FileAgeCheck("' . BASE_PATH . '/../backups/*' . '", "-1 day", '>', " . FileAgeCheck::CHECK_SINGLE) . "'
);
Synopsis
class FileAgeCheck
implements
EnvironmentCheck
{
- // constants
- const CHECK_SINGLE = 1;
- const CHECK_ALL = 2;
- // members
- protected $path;
- protected $relativeAge;
- protected $checkFn;
- protected $checkType;
- protected $compareOperand;
- // methods
- public void __construct()
- public array check()
- protected array getFiles()
Hierarchy
Constants
Name | Value |
---|---|
CHECK_SINGLE | 1 |
CHECK_ALL | 2 |
ERROR | 3 |
WARNING | 2 |
OK | 1 |
Members
protected
- $checkFn
—
string
The function to use for checking file age: so filemtime(), filectime(), or fileatime(). - $checkType
—
int
Constant, check for a single file to match age criteria, or all of them. - $compareOperand
—
string
Type of comparison (either > or <). - $path
—
string
Absolute path to a file or folder, compatible with glob(). - $relativeAge
—
string
Relative date specification, compatible with strtotime().
Methods
protected
- getFiles() — Gets a list of absolute file paths.
public
- __construct()
- check() — {@inheritDoc}