-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathDropFolder.php
More file actions
375 lines (313 loc) · 9.01 KB
/
DropFolder.php
File metadata and controls
375 lines (313 loc) · 9.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<?php
/**
* Skeleton subclass for representing a row from the 'drop_folder' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package plugins.dropFolder
* @subpackage model
*/
class DropFolder extends BaseDropFolder implements IBaseObject
{
const AUTO_FILE_DELETE_DAYS_DEFAULT_VALUE = 0;
const FILE_SIZE_CHECK_INTERVAL_DEFAULT_VALUE = '600'; // 600 seconds = 10 minutes
const FILE_NAME_PATTERNS_DEFAULT_VALUE = '*';
const FILE_PROCESSING_GRACE_PERIOD_DEFAULT_VALUE = 10800; // 10800 seconds = 3 hours
const FILE_PROCESSING_GRACE_PERIOD_MAX_VALUE = 21600; // 21600 seconds = 6 hours
const INCREMENTAL = 'incremental';
const LAST_FILE_TIMESTAMP = 'last_file_timestamp';
const METADATA_PROFILE_ID = 'metadata_profile_id';
const CATEGORIES_METADATA_FIELD_NAME = 'categories_metadata_field_name';
const ENFORCE_ENTITLEMENT = 'enforce_entitlement';
const SHOULD_VALIDATE_KS = 'should_validate_ks';
protected static $nonEssentialCustomDataFields = array('last_file_timestamp', 'last_accessed_at');
// -------------------------------------
// -- Default values -------------------
// -------------------------------------
/**
* Code to be run before inserting to database
* @param PropelPDO $con
* @return boolean
*/
public function preInsert(PropelPDO $con = null)
{
$ret = parent::preInsert($con);
// set default values where null
if (is_null($this->getFileSizeCheckInterval())) {
$this->setFileSizeCheckInterval(DropFolder::FILE_SIZE_CHECK_INTERVAL_DEFAULT_VALUE);
}
if (is_null($this->getFileDeletePolicy())) {
$this->setFileDeletePolicy(DropFolderFileDeletePolicy::AUTO_DELETE);
}
if (is_null($this->getAutoFileDeleteDays())) {
$this->setAutoFileDeleteDays(DropFolder::AUTO_FILE_DELETE_DAYS_DEFAULT_VALUE);
}
$currentValue = $this->getFileProcessingGracePeriod();
if (is_null($currentValue)) {
$this->setFileProcessingGracePeriod(DropFolder::FILE_PROCESSING_GRACE_PERIOD_DEFAULT_VALUE);
}
return $ret;
}
public function preUpdate(PropelPDO $con = null)
{
$before = $this->getUpdatedAt();
$ret = parent::preUpdate($con);
if (count($this->modifiedColumns) == 2 && $this->isColumnModified(DropFolderPeer::CUSTOM_DATA)
&& !$this->checkNonEssentialFieldsUpdate())
{
$this->setUpdatedAt($before);
}
return $ret;
}
protected function checkNonEssentialFieldsUpdate ()
{
//All of the custom data fields irrelevant to updatedAt propagation are under the '' namespace
$allOldCustomMetadataValues = $this->getCustomDataOldValues();
$modifiedCustomDataFields = array_keys($allOldCustomMetadataValues['']);
$diff = array_diff($modifiedCustomDataFields, self::$nonEssentialCustomDataFields);
if (!count($diff))
{
return false;
}
return true;
}
// -------------------------------------
// -- Override base methods ------------
// -------------------------------------
/**
* @return DropFolderFileHandlerConfig
*/
public function getFileHandlerConfig()
{
$serializedConfig = parent::getFileHandlerConfig();
try {
$config = @unserialize($serializedConfig);
}
catch (Exception $e) {
KalturaLog::err('Error unserializing file handler config for drop folder id ['.$this->getId().']');
$config = null;
}
if ($config instanceof DropFolderFileHandlerConfig) {
return $config;
}
return null;
}
/**
* @param DropFolderFileHandlerConfig $fileHandlerConfig
*/
public function setFileHandlerConfig($fileHandlerConfig)
{
if ($fileHandlerConfig instanceof DropFolderFileHandlerConfig)
{
$serializedConfig = serialize($fileHandlerConfig);
parent::setFileHandlerConfig($serializedConfig);
}
else
{
KalturaLog::err('Given input $fileHandlerConfig is not an instance of DropFolderFileHandlerConfig - ignoring');
}
}
// ------------------------------------------
// -- Custom data columns -------------------
// ------------------------------------------
const CUSTOM_DATA_FILE_SIZE_CHECK_INTERVAL = 'file_size_check_interval';
const CUSTOM_DATA_AUTO_FILE_DELETE_DAYS = 'auto_file_delete_days';
const CUSTOM_DATA_IGNORE_FILE_NAME_PATTERNS = 'ignore_file_name_patterns';
const CUSTOM_DATA_LAST_ACCESSED_AT = 'last_accessed_at';
const CUSTOM_DATA_FILE_DELETE_REGEX = 'file_delete_regex';
const CUSTOM_DATA_FILE_PROCESSING_GRACE_PERIOD = 'file_processing_grace_period';
// File size check interval - value in seconds
/**
* @return int
*/
public function getFileSizeCheckInterval()
{
return $this->getFromCustomData(self::CUSTOM_DATA_FILE_SIZE_CHECK_INTERVAL);
}
public function setFileSizeCheckInterval($interval)
{
$this->putInCustomData(self::CUSTOM_DATA_FILE_SIZE_CHECK_INTERVAL, $interval);
}
// file delete regex
/**
* @return string
*/
public function getFileDeleteRegex()
{
return $this->getFromCustomData(self::CUSTOM_DATA_FILE_DELETE_REGEX);
}
public function setFileDeleteRegex($fileDeleteRegex)
{
$this->putInCustomData(self::CUSTOM_DATA_FILE_DELETE_REGEX, $fileDeleteRegex);
}
// File processing grace period
/**
* @return int
*/
public function getFileProcessingGracePeriod()
{
return $this->getFromCustomData(self::CUSTOM_DATA_FILE_PROCESSING_GRACE_PERIOD);
}
public function setFileProcessingGracePeriod($seconds)
{
$this->putInCustomData(self::CUSTOM_DATA_FILE_PROCESSING_GRACE_PERIOD, $seconds);
}
// Automatic file delete days
/**
* @return int
*/
public function getAutoFileDeleteDays()
{
return $this->getFromCustomData(self::CUSTOM_DATA_AUTO_FILE_DELETE_DAYS);
}
public function setAutoFileDeleteDays($days)
{
$this->putInCustomData(self::CUSTOM_DATA_AUTO_FILE_DELETE_DAYS, $days);
}
// Ignore file patterns
/**
* @return int
*/
public function getIgnoreFileNamePatterns()
{
return $this->getFromCustomData(self::CUSTOM_DATA_IGNORE_FILE_NAME_PATTERNS);
}
public function setIgnoreFileNamePatterns($patterns)
{
$this->putInCustomData(self::CUSTOM_DATA_IGNORE_FILE_NAME_PATTERNS, $patterns);
}
// last accessed by watcher
/**
* @return int
*/
public function getLastAccessedAt()
{
return $this->getFromCustomData(self::CUSTOM_DATA_LAST_ACCESSED_AT);
}
public function setLastAccessedAt($date)
{
$this->putInCustomData(self::CUSTOM_DATA_LAST_ACCESSED_AT, $date);
}
/**
* @return bool
*/
public function getIncremental()
{
return $this->getFromCustomData(self::INCREMENTAL);
}
/**
* @param bool $v
*/
public function setIncremental($v)
{
$this->putInCustomData(self::INCREMENTAL, $v);
}
/**
* @return int
*/
public function getLastFileTimestamp()
{
return $this->getFromCustomData(self::LAST_FILE_TIMESTAMP);
}
/**
* @param bool $v
*/
public function setLastFileTimestamp($v)
{
$this->putInCustomData(self::LAST_FILE_TIMESTAMP, $v);
}
/**
* @param int $v
*/
public function setMetadataProfileId ($v)
{
$this->putInCustomData(self::METADATA_PROFILE_ID, $v);
}
/**
* return int
*/
public function getMetadataProfileId ()
{
return $this->getFromCustomData(self::METADATA_PROFILE_ID);
}
/**
* return string
*/
public function getCategoriesMetadataFieldName ()
{
return $this->getFromCustomData(self::CATEGORIES_METADATA_FIELD_NAME);
}
/**
* @param string $v
*/
public function setCategoriesMetadataFieldName ($v)
{
$this->putInCustomData(self::CATEGORIES_METADATA_FIELD_NAME, $v);
}
/**
* return bool
*/
public function getEnforceEntitlement ()
{
return $this->getFromCustomData(self::ENFORCE_ENTITLEMENT);
}
/**
* @param bool $v
*/
public function setEnforceEntitlement ($v)
{
$this->putInCustomData(self::ENFORCE_ENTITLEMENT, $v);
}
/**
* @return bool
*/
public function getShouldValidateKS()
{
return $this->getFromCustomData(self::SHOULD_VALIDATE_KS);
}
/**
* @param bool $v
*/
public function setShouldValidateKS($v)
{
$this->putInCustomData(self::SHOULD_VALIDATE_KS, $v);
}
public function getCacheInvalidationKeys()
{
return array("dropFolder:id=".strtolower($this->getId()), "dropFolder:dc=".strtolower($this->getDc()));
}
/**
* @return kFileTransferMgrType
*/
public function getFileTransferMgrType()
{
return kFileTransferMgrType::LOCAL;
}
/**
* Login using fileTransferMgr according to the available credentials
* @param kFileTransferMgr $fileTransferMgr
*/
public function loginByCredentialsType(kFileTransferMgr $fileTransferMgr)
{
return $fileTransferMgr->login(null, null, null);
}
/**
* get full local file path
* @param string $fileName
* @param int $fileId
* @param kFileTransferMgr $fileTransferMgr
*/
public function getLocalFilePath($fileName, $fileId, kFileTransferMgr $fileTransferMgr)
{
$dropFolderFilePath = $this->getPath().'/'.$fileName;
return realpath($dropFolderFilePath);
}
public function getDropFolderParams()
{
return array();
}
} // DropFolder