VersionedUploadExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A onAfterLoad() 0 6 2
1
<?php
2
/**
3
 * @package silverstripe-versionedfiles
4
 */
5
class VersionedUploadExtension extends Extension
6
{
7
    /**
8
     * There is some duplication in the Upload: replaceFile functionality and the versionedFiles replace
9
     * functionality. With the CMS replace function the versionedFiles replace does't work and vice-versa.
10
     * This extension detects if the replaceFile config setting is turned on and hooks in to add create
11
     * a new version on each upload from the CMS, if that is the case.
12
     * @param $file File - the uploaded File object
13
     */
14
    public function onAfterLoad($file)
15
    {
16
        if ($this->owner->getReplaceFile()) {
17
            $file->createVersion();
18
        }
19
    }
20
}
21