-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathDropFolderConfigureAction.php
More file actions
157 lines (140 loc) · 5.25 KB
/
DropFolderConfigureAction.php
File metadata and controls
157 lines (140 loc) · 5.25 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
<?php
/**
* @package plugins.dropFolder
* @subpackage Admin
*/
class DropFolderConfigureAction extends KalturaApplicationPlugin
{
/**
* @return string - absolute file path of the phtml template
*/
public function getTemplatePath()
{
return realpath(dirname(__FILE__));
}
public function getRequiredPermissions()
{
return array(Kaltura_Client_Enum_PermissionName::SYSTEM_ADMIN_DROP_FOLDER_MODIFY);
}
public function doAction(Zend_Controller_Action $action)
{
$action->getHelper('layout')->disableLayout();
$request = $action->getRequest();
$dropFolderId = $this->_getParam('drop_folder_id');
$partnerId = $this->_getParam('new_partner_id');
$dropFolderType = $this->_getParam('new_drop_folder_type');
$dropFolderForm = null;
$action->view->formValid = false;
try
{
if ($request->isPost())
{
$partnerId = $this->_getParam('partnerId');
$dropFolderType = $this->_getParam('type');
$postData = $request->getPost();
$dropFolderForm = $this->getDropFolderConfigure($dropFolderType, $partnerId, $dropFolderType);
$action->view->formValid = $this->processForm($dropFolderForm, $postData, $partnerId, $dropFolderId);
if(!is_null($dropFolderId))
{
$dropFolder = $dropFolderForm->getObject("Kaltura_Client_DropFolder_Type_DropFolder", $request->getPost(), false, true);
$this->disableFileHandlerType($dropFolderForm, $dropFolder->fileHandlerType);
}
}
else
{
if (!is_null($dropFolderId))
{
$client = Infra_ClientHelper::getClient();
$dropFolderPluginClient = Kaltura_Client_DropFolder_Plugin::get($client);
$dropFolder = $dropFolderPluginClient->dropFolder->get($dropFolderId);
$partnerId = $dropFolder->partnerId;
$dropFolderType = $dropFolder->type;
$dropFolderForm = $this->getDropFolderConfigure($dropFolderType, $partnerId, $dropFolderType);
$dropFolderForm->populateFromObject($dropFolder, false);
$this->disableFileHandlerType($dropFolderForm, $dropFolder->fileHandlerType);
}
else
{
$dropFolderForm = $this->getDropFolderConfigure($dropFolderType, $partnerId, $dropFolderType);
$dropFolderForm->getElement('partnerId')->setValue($partnerId);
$settings = Zend_Registry::get('config')->dropFolder;
if($dropFolderType ===Kaltura_Client_DropFolder_Enum_DropFolderType::LOCAL)
{
$dropFolderForm->getElement('fileSizeCheckInterval')->setValue($settings->fileSizeCheckIntervalLocal);
}
else
{
$dropFolderForm->getElement('fileSizeCheckInterval')->setValue($settings->fileSizeCheckIntervalRemote);
}
}
}
}
catch(Exception $e)
{
$action->view->formValid = false;
KalturaLog::err($e->getMessage() . "\n" . $e->getTraceAsString());
$action->view->errMessage = $e->getMessage();
}
$action->view->form = $dropFolderForm;
}
protected function getDropFolderConfigure($type, $partnerId, $dropFolderType)
{
switch ($type)
{
case S3DropFolderPlugin::getPluginName(). '.S3DROPFOLDER':
return new Form_S3DropFolderConfigure($partnerId, $dropFolderType);
default:
return new Form_DropFolderConfigure($partnerId, $dropFolderType);
}
}
private function processForm(Form_DropFolderConfigure $form, $formData, $partnerId, $dropFolderId = null)
{
if ($form->isValid($formData))
{
$client = Infra_ClientHelper::getClient();
$dropFolderPluginClient = Kaltura_Client_DropFolder_Plugin::get($client);
$dropFolder = $form->getObject("Kaltura_Client_DropFolder_Type_DropFolder", $formData, false, true);
$this->validateConversionProfileId($dropFolder->conversionProfileId, $partnerId);
unset($dropFolder->id);
if($dropFolder->fileHandlerType === Kaltura_Client_DropFolder_Enum_DropFolderFileHandlerType::CONTENT)
$dropFolder->fileNamePatterns = '*';
if (is_null($dropFolderId)) {
$dropFolder->status = Kaltura_Client_DropFolder_Enum_DropFolderStatus::ENABLED;
$responseDropFolder = $dropFolderPluginClient->dropFolder->add($dropFolder);
}
else {
$responseDropFolder = $dropFolderPluginClient->dropFolder->update($dropFolderId, $dropFolder);
}
$form->setAttrib('class', 'valid');
return true;
}
else
{
$form->populate($formData);
return false;
}
}
private function disableFileHandlerType(Form_DropFolderConfigure $dropFolderForm, $fileHandlerTypeValue)
{
$fileHandlerType = $dropFolderForm->getElement('fileHandlerType');
$fileHandlerType->setAttrib('style', 'display:none');
$fileHandlerType->setLabel('');
$fileHandlerTypeForView = $dropFolderForm->getElement('fileHandlerTypeForView');
$fileHandlerTypeForView->setLabel('Ingestion Workflow:');
$fileHandlerTypeForView->setAttrib('style', 'display:inline');
$fileHandlerTypeForView->setValue($fileHandlerTypeValue);
}
protected function validateConversionProfileId ($conversionProfileId, $partnerId)
{
$client = Infra_ClientHelper::getClient();
$filter = new Kaltura_Client_Type_ConversionProfileFilter();
$filter->idEqual = $conversionProfileId;
Infra_ClientHelper::impersonate($partnerId);
$conversionProfiles = $client->conversionProfile->listAction($filter);
Infra_ClientHelper::unimpersonate();
if (!$conversionProfiles->totalCount)
{
throw new Exception("Conversion profile ID [$conversionProfileId] not found.");
}
}
}