|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Soheilrt\AdobeConnectClient\Client\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
|
6
|
|
|
use Soheilrt\AdobeConnectClient\Client\Abstracts\Command; |
|
7
|
|
|
use Soheilrt\AdobeConnectClient\Client\Converter\Converter; |
|
8
|
|
|
use Soheilrt\AdobeConnectClient\Client\Entities\SCO; |
|
9
|
|
|
use Soheilrt\AdobeConnectClient\Client\Filter; |
|
10
|
|
|
use Soheilrt\AdobeConnectClient\Client\Helpers\StatusValidate; |
|
11
|
|
|
use SplFileInfo; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Uploads a file to the server and then builds the file, if necessary. |
|
15
|
|
|
* |
|
16
|
|
|
* Create a new File SCO or update if exists in the folder (a SCO Meeting) and upload the file. |
|
17
|
|
|
* |
|
18
|
|
|
* More info see {@link https://helpx.adobe.com/adobe-connect/webservices/sco-upload.html} |
|
19
|
|
|
* |
|
20
|
|
|
* The filename (filePath) needs the extension for Adobe Connect purpose. |
|
21
|
|
|
* |
|
22
|
|
|
* The Adobe Connect API Documentation says to call the sco-info and analyse the status info |
|
23
|
|
|
* to determine if upload is ready, but the sco-info does not inform the status attribute. |
|
24
|
|
|
* |
|
25
|
|
|
* So we analyse the files array wich is returned by the sco-upload, but this info is deprecated. |
|
26
|
|
|
*/ |
|
27
|
|
|
class ScoUpload extends Command |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var int |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $folderId; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $resourceName; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var SplFileInfo|resource |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $file; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var SCO|mixed |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $sco; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param int $folderId The Folder (SCO ID) owned the file |
|
51
|
|
|
* @param string $resourceName |
|
52
|
|
|
* @param SplFileInfo|resource $file |
|
53
|
|
|
* |
|
54
|
|
|
* @throws InvalidArgumentException |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct($folderId, $resourceName, $file) |
|
57
|
|
|
{ |
|
58
|
|
|
if (!is_resource($file) && !($file instanceof SplFileInfo)) { |
|
|
|
|
|
|
59
|
|
|
throw new InvalidArgumentException('File need be a valid resource or a SplFileInfo object'); |
|
60
|
|
|
} |
|
61
|
|
|
$this->folderId = (int) $folderId; |
|
62
|
|
|
$this->resourceName = (string) $resourceName; |
|
63
|
|
|
$this->file = $file; |
|
64
|
|
|
$this->sco = $this->getEntity('sco'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
* |
|
70
|
|
|
* @return int|null The Content SCO ID or null if fail |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function process() |
|
73
|
|
|
{ |
|
74
|
|
|
$sco = $this->getSco(); |
|
75
|
|
|
|
|
76
|
|
|
$response = Converter::convert( |
|
77
|
|
|
$this->client->doPost( |
|
|
|
|
|
|
78
|
|
|
[ |
|
79
|
|
|
'file' => $this->file, |
|
80
|
|
|
], |
|
81
|
|
|
[ |
|
82
|
|
|
'action' => 'sco-upload', |
|
83
|
|
|
'sco-id' => $sco->getScoId(), |
|
84
|
|
|
'session' => $this->client->getSession(), |
|
|
|
|
|
|
85
|
|
|
] |
|
86
|
|
|
) |
|
87
|
|
|
); |
|
88
|
|
|
StatusValidate::validate($response['status']); |
|
89
|
|
|
|
|
90
|
|
|
return empty($response['files']) ? null : $sco->getScoId(); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get the SCO content if exists or create one. |
|
95
|
|
|
* |
|
96
|
|
|
* @return SCO |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function getSco() |
|
99
|
|
|
{ |
|
100
|
|
|
$scos = $this->client->scoContents( |
|
|
|
|
|
|
101
|
|
|
$this->folderId, |
|
102
|
|
|
Filter::instance() |
|
103
|
|
|
->equals('folderId', $this->folderId) |
|
104
|
|
|
->equals('name', $this->resourceName) |
|
105
|
|
|
->equals('type', SCO::TYPE_CONTENT) |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
return empty($scos) ? $this->createSco() : reset($scos); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Create a SCO content. |
|
113
|
|
|
* |
|
114
|
|
|
* @return SCO |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function createSco() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->client->scoCreate( |
|
|
|
|
|
|
119
|
|
|
SCO::instance() |
|
120
|
|
|
->setType(SCO::TYPE_CONTENT) |
|
121
|
|
|
->setFolderId($this->folderId) |
|
122
|
|
|
->setName($this->resourceName) |
|
123
|
|
|
); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|