-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathDropFolderService.php
More file actions
348 lines (286 loc) · 11.4 KB
/
DropFolderService.php
File metadata and controls
348 lines (286 loc) · 11.4 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
<?php
/**
* DropFolder service lets you create and manage drop folders
* @service dropFolder
* @package plugins.dropFolder
* @subpackage api.services
*/
class DropFolderService extends KalturaBaseService
{
public function initService($serviceId, $serviceName, $actionName)
{
parent::initService($serviceId, $serviceName, $actionName);
if (!DropFolderPlugin::isAllowedPartner($this->getPartnerId()))
throw new KalturaAPIException(KalturaErrors::FEATURE_FORBIDDEN, DropFolderPlugin::PLUGIN_NAME);
$this->applyPartnerFilterForClass('DropFolder');
$this->applyPartnerFilterForClass('DropFolderFile');
}
/**
* Allows you to add a new KalturaDropFolder object
*
* @action add
* @param KalturaDropFolder $dropFolder
* @return KalturaDropFolder
*
* @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
* @throws KalturaErrors::INGESTION_PROFILE_ID_NOT_FOUND
* @throws KalturaDropFolderErrors::DROP_FOLDER_ALREADY_EXISTS
* @throws KalturaErrors::DATA_CENTER_ID_NOT_FOUND
*/
public function addAction(KalturaDropFolder $dropFolder)
{
// check for required parameters
$dropFolder->validatePropertyNotNull('name');
$dropFolder->validatePropertyNotNull('status');
$dropFolder->validatePropertyNotNull('type');
$dropFolder->validatePropertyNotNull('dc');
$dropFolder->validatePropertyNotNull('path');
$dropFolder->validatePropertyNotNull('partnerId');
$dropFolder->validatePropertyMinValue('fileSizeCheckInterval', 0, true);
$dropFolder->validatePropertyMinValue('fileProcessingGracePeriod', 0, true);
$dropFolder->validatePropertyMinValue('autoFileDeleteDays', 0, true);
$dropFolder->validatePropertyNotNull('fileHandlerType');
$dropFolder->validatePropertyNotNull('fileHandlerConfig');
// validate values
if (is_null($dropFolder->fileSizeCheckInterval)) {
$dropFolder->fileSizeCheckInterval = DropFolder::FILE_SIZE_CHECK_INTERVAL_DEFAULT_VALUE;
}
// Convert to integer if it's a numeric string
if (is_string($dropFolder->fileProcessingGracePeriod) && is_numeric($dropFolder->fileProcessingGracePeriod)) {
$dropFolder->fileProcessingGracePeriod = (int)$dropFolder->fileProcessingGracePeriod;
}
if (is_null($dropFolder->fileProcessingGracePeriod) || $dropFolder->fileProcessingGracePeriod === '' || $dropFolder->fileProcessingGracePeriod === 0) {
$dropFolder->fileProcessingGracePeriod = DropFolder::FILE_PROCESSING_GRACE_PERIOD_DEFAULT_VALUE;
}
if ($dropFolder->fileProcessingGracePeriod > DropFolder::FILE_PROCESSING_GRACE_PERIOD_MAX_VALUE) {
throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'fileProcessingGracePeriod');
}
if (is_null($dropFolder->fileNamePatterns)) {
$dropFolder->fileNamePatterns = DropFolder::FILE_NAME_PATTERNS_DEFAULT_VALUE;
}
if (!kDataCenterMgr::dcExists($dropFolder->dc)) {
throw new KalturaAPIException(KalturaErrors::DATA_CENTER_ID_NOT_FOUND, $dropFolder->dc);
}
if (!PartnerPeer::retrieveByPK($dropFolder->partnerId)) {
throw new KalturaAPIException(KalturaErrors::INVALID_PARTNER_ID, $dropFolder->partnerId);
}
if (!DropFolderPlugin::isAllowedPartner($dropFolder->partnerId))
{
throw new KalturaAPIException(KalturaErrors::PLUGIN_NOT_AVAILABLE_FOR_PARTNER, DropFolderPlugin::getPluginName(), $dropFolder->partnerId);
}
if($dropFolder->type == KalturaDropFolderType::LOCAL)
{
$existingDropFolder = DropFolderPeer::retrieveByPathDefaultFilter($dropFolder->path);
if ($existingDropFolder) {
throw new KalturaAPIException(KalturaDropFolderErrors::DROP_FOLDER_ALREADY_EXISTS, $dropFolder->path);
}
}
if (!is_null($dropFolder->conversionProfileId)) {
$conversionProfileDb = conversionProfile2Peer::retrieveByPK($dropFolder->conversionProfileId);
if (!$conversionProfileDb) {
throw new KalturaAPIException(KalturaErrors::INGESTION_PROFILE_ID_NOT_FOUND, $dropFolder->conversionProfileId);
}
}
// save in database
$dbDropFolder = $dropFolder->toInsertableObject();
$dbDropFolder->save();
// return the saved object
$dropFolder = KalturaDropFolder::getInstanceByType($dbDropFolder->getType());
$dropFolder->fromObject($dbDropFolder, $this->getResponseProfile());
return $dropFolder;
}
/**
* Retrieve a KalturaDropFolder object by ID
*
* @action get
* @param int $dropFolderId
* @return KalturaDropFolder
*
* @throws KalturaErrors::INVALID_OBJECT_ID
*/
public function getAction($dropFolderId)
{
$dbDropFolder = DropFolderPeer::retrieveByPK($dropFolderId);
if (!$dbDropFolder) {
throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderId);
}
$dropFolder = KalturaDropFolder::getInstanceByType($dbDropFolder->getType());
$dropFolder->fromObject($dbDropFolder, $this->getResponseProfile());
return $dropFolder;
}
/**
* Update an existing KalturaDropFolder object
*
* @action update
* @param int $dropFolderId
* @param KalturaDropFolder $dropFolder
* @return KalturaDropFolder
*
* @throws KalturaErrors::INVALID_OBJECT_ID
* @throws KalturaErrors::INGESTION_PROFILE_ID_NOT_FOUND
* @throws KalturaErrors::DATA_CENTER_ID_NOT_FOUND
*/
public function updateAction($dropFolderId, KalturaDropFolder $dropFolder)
{
$dbDropFolder = DropFolderPeer::retrieveByPK($dropFolderId);
if (!$dbDropFolder) {
throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderId);
}
$dropFolder->validatePropertyMinValue('fileSizeCheckInterval', 0, true);
$dropFolder->validatePropertyMinValue('fileProcessingGracePeriod', 0, true);
$dropFolder->validatePropertyMinValue('autoFileDeleteDays', 0, true);
// Validate fileProcessingGracePeriod does not exceed maximum value
if (!is_null($dropFolder->fileProcessingGracePeriod) && $dropFolder->fileProcessingGracePeriod > DropFolder::FILE_PROCESSING_GRACE_PERIOD_MAX_VALUE) {
throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'fileProcessingGracePeriod');
}
if (!is_null($dropFolder->path) && $dropFolder->path != $dbDropFolder->getPath() && $dropFolder->type == KalturaDropFolderType::LOCAL)
{
$existingDropFolder = DropFolderPeer::retrieveByPathDefaultFilter($dropFolder->path);
if ($existingDropFolder) {
throw new KalturaAPIException(KalturaDropFolderErrors::DROP_FOLDER_ALREADY_EXISTS, $dropFolder->path);
}
}
if (!is_null($dropFolder->dc)) {
if (!kDataCenterMgr::dcExists($dropFolder->dc)) {
throw new KalturaAPIException(KalturaErrors::DATA_CENTER_ID_NOT_FOUND, $dropFolder->dc);
}
}
if (!is_null($dropFolder->conversionProfileId)) {
$conversionProfileDb = conversionProfile2Peer::retrieveByPK($dropFolder->conversionProfileId);
if (!$conversionProfileDb) {
throw new KalturaAPIException(KalturaErrors::INGESTION_PROFILE_ID_NOT_FOUND, $dropFolder->conversionProfileId);
}
}
$dbDropFolder = $dropFolder->toUpdatableObject($dbDropFolder);
$dbDropFolder->save();
$dropFolder = KalturaDropFolder::getInstanceByType($dbDropFolder->getType());
$dropFolder->fromObject($dbDropFolder, $this->getResponseProfile());
return $dropFolder;
}
/**
* Mark the KalturaDropFolder object as deleted
*
* @action delete
* @param int $dropFolderId
* @return KalturaDropFolder
*
* @throws KalturaErrors::INVALID_OBJECT_ID
*/
public function deleteAction($dropFolderId)
{
$dbDropFolder = DropFolderPeer::retrieveByPK($dropFolderId);
if (!$dbDropFolder) {
throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderId);
}
$dbDropFolder->setStatus(DropFolderStatus::DELETED);
$dbDropFolder->save();
$dropFolder = KalturaDropFolder::getInstanceByType($dbDropFolder->getType());
$dropFolder->fromObject($dbDropFolder, $this->getResponseProfile());
return $dropFolder;
}
/**
* List KalturaDropFolder objects
*
* @action list
* @param KalturaDropFolderFilter $filter
* @param KalturaFilterPager $pager
* @return KalturaDropFolderListResponse
*/
public function listAction(KalturaDropFolderFilter $filter = null, KalturaFilterPager $pager = null)
{
if (!$filter)
$filter = new KalturaDropFolderFilter();
$dropFolderFilter = $filter->toObject();
$c = new Criteria();
$dropFolderFilter->attachToCriteria($c);
$count = DropFolderPeer::doCount($c);
if (! $pager)
$pager = new KalturaFilterPager ();
$pager->attachToCriteria ( $c );
$list = DropFolderPeer::doSelect($c);
$response = new KalturaDropFolderListResponse();
$response->objects = KalturaDropFolderArray::fromDbArray($list, $this->getResponseProfile());
$response->totalCount = $count;
return $response;
}
/**
* getExclusive KalturaDropFolder object
*
* @action getExclusiveDropFolder
* @param string $tag
* @param int $maxTime
* @return KalturaDropFolder
*/
public function getExclusiveDropFolderAction($tag, $maxTime)
{
$allocateDropFolder = kDropFolderAllocator::getDropFolder($tag, $maxTime);
if ($allocateDropFolder && self::isValidForWatch($allocateDropFolder))
{
$dropFolder = KalturaDropFolder::getInstanceByType($allocateDropFolder->getType());
$dropFolder->fromObject($allocateDropFolder, $this->getResponseProfile());
return $dropFolder;
}
}
/**
* freeExclusive KalturaDropFolder object
*
* @action freeExclusiveDropFolder
* @param int $dropFolderId
* @param string $errorCode
* @param string $errorDescription
* @throws KalturaAPIException
* @return KalturaDropFolder
*/
public function freeExclusiveDropFolderAction($dropFolderId, $errorCode = null, $errorDescription = null)
{
kDropFolderAllocator::freeDropFolder($dropFolderId);
$dbDropFolder = DropFolderPeer::retrieveByPK($dropFolderId);
if (!$dbDropFolder)
throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderId);
$dbDropFolder->setLastAccessedAt(time());
$dbDropFolder->setErrorCode($errorCode);
$dbDropFolder->setErrorDescription($errorDescription);
$dbDropFolder->save();
$dropFolder = KalturaDropFolder::getInstanceByType($dbDropFolder->getType());
$dropFolder->fromObject($dbDropFolder, $this->getResponseProfile());
return $dropFolder;
}
private static function isValidForWatch(DropFolder $dropFolder)
{
$partner = PartnerPeer::retrieveByPK($dropFolder->getPartnerId());
if (!$partner || $partner->getStatus() != Partner::PARTNER_STATUS_ACTIVE)
return false;
return true;
}
/**
* @action updateStatus
* @param int $dropFolderId
* @param KalturaDropFolderStatus $status
*/
public function updateStatusAction($dropFolderId, $status)
{
$dbDropFolder = DropFolderPeer::retrieveByPK($dropFolderId);
if (!$dbDropFolder)
throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderId);
$dbDropFolder->setStatus($status);
$dbDropFolder->save();
}
/**
* @action updateBasicFields
* @param int $dropFolderId
* @param KalturaBasicFieldsDropFolder $dropFolder
*
* @return KalturaDropFolder
*/
public function updateBasicFieldsAction($dropFolderId, KalturaBasicFieldsDropFolder $dropFolder)
{
$dbDropFolder = DropFolderPeer::retrieveByPK($dropFolderId);
if (!$dbDropFolder)
throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderId);
$dbDropFolder = $dropFolder->toUpdatableObject($dbDropFolder);
$dbDropFolder->save();
$dropFolder = KalturaDropFolder::getInstanceByType($dbDropFolder->getType());
$dropFolder->fromObject($dbDropFolder, $this->getResponseProfile());
return $dropFolder;
}
}