1 | <?php |
||
8 | class SecureEditableFileField extends DataExtension |
||
|
|||
9 | { |
||
10 | |||
11 | /** |
||
12 | * Path to secure files location under assets |
||
13 | * |
||
14 | * @config |
||
15 | * @var type |
||
16 | */ |
||
17 | private static $secure_folder_name = 'SecureUploads'; |
||
18 | |||
19 | /** |
||
20 | * Disable file security if a user-defined mechanism is in place |
||
21 | * |
||
22 | * @config |
||
23 | * @var bool |
||
24 | */ |
||
25 | private static $disable_security = false; |
||
26 | |||
27 | /* |
||
28 | * Check if file security is enabled |
||
29 | * |
||
30 | * @return bool |
||
31 | */ |
||
32 | public function getIsSecurityEnabled() |
||
47 | |||
48 | public function requireDefaultRecords() |
||
49 | { |
||
50 | // Skip if disabled |
||
51 | if (!$this->getIsSecurityEnabled()) { |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | // Update all instances of editablefilefield which do NOT have a secure folder assigned |
||
56 | foreach (EditableFileField::get() as $fileField) { |
||
57 | // Skip if secured |
||
58 | if ($fileField->getIsSecure()) { |
||
59 | continue; |
||
60 | } |
||
61 | |||
62 | // Force this field to secure itself on write |
||
63 | $fileField->write(false, false, true); |
||
64 | DB::alteration_message( |
||
65 | "Restricting editable file field \"{$fileField->Title}\" to secure folder", |
||
66 | "changed" |
||
67 | ); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Secure this field before saving |
||
73 | */ |
||
74 | public function onBeforeWrite() |
||
78 | |||
79 | /** |
||
80 | * Ensure this field is secured, but does not write changes to the database |
||
81 | */ |
||
82 | public function makeSecure() |
||
105 | |||
106 | /** |
||
107 | * Find target group to record |
||
108 | * |
||
109 | * @return Group |
||
110 | */ |
||
111 | protected function findAdminGroup() |
||
116 | |||
117 | /** |
||
118 | * Determine if the field is secure |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | public function getIsSecure() |
||
126 | |||
127 | /** |
||
128 | * Check if a Folder object is secure |
||
129 | * |
||
130 | * @param Folder $folder |
||
131 | * @return boolean |
||
132 | */ |
||
133 | protected function isFolderSecured($folder) |
||
151 | } |
||
152 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.