Issues (27)

src/Cache/FileTextCache/Database.php (1 issue)

Severity
1
<?php
2
3
namespace SilverStripe\TextExtraction\Cache\FileTextCache;
4
5
use SilverStripe\Assets\File;
6
use SilverStripe\Core\Config\Configurable;
7
use SilverStripe\TextExtraction\Cache\FileTextCache;
8
9
/**
10
 * Caches the extracted content on the record for the file.
11
 * Limits the stored file content by default to avoid hitting query size limits.
12
 */
13
class Database implements FileTextCache
14
{
15
    use Configurable;
16
17
    /**
18
     * @config
19
     * @var int
20
     */
21
    private static $max_content_length = null;
0 ignored issues
show
The private property $max_content_length is not used, and could be removed.
Loading history...
22
23
    /**
24
     *
25
     * @param  File $file
26
     * @return FileTextCache
27
     */
28
    public function load(File $file)
29
    {
30
        return $file->FileContentCache;
31
    }
32
33
    /**
34
     * @param File $file
35
     * @param mixed $content
36
     */
37
    public function save(File $file, $content)
38
    {
39
        $maxLength = $this->config()->get('max_content_length');
40
        $file->FileContentCache = ($maxLength) ? substr($content, 0, $maxLength) : $content;
41
        $file->write();
42
    }
43
44
    /**
45
     * @param File $file
46
     * @return void
47
     */
48
    public function invalidate(File $file)
49
    {
50
        // To prevent writing to the cache from invalidating it
51
        if (!$file->isChanged('FileContentCache')) {
52
            $file->FileContentCache = '';
53
        }
54
    }
55
}
56