Skip to content

Commit 36a4942

Browse files
committed
feat: add workflow template id for pfop
1 parent a9b6716 commit 36a4942

File tree

3 files changed

+97
-29
lines changed

3 files changed

+97
-29
lines changed

src/Qiniu/Auth.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,11 @@ public function uploadToken($bucket, $key = null, $expires = 3600, $policy = nul
219219
'fsizeMin',
220220
'fsizeLimit',
221221

222-
'persistentOps',
222+
'persistentOps', // 与 persistentWorkflowTemplateID 二选一
223223
'persistentNotifyUrl',
224224
'persistentPipeline',
225225
'persistentType', // 为 `1` 时开启闲时任务
226+
'persistentWorkflowTemplateID', // 与 persistentOps 二选一
226227

227228
'deleteAfterDays',
228229
'fileType',

src/Qiniu/Processing/PersistentFop.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,22 @@ public function __construct($auth, $config = null, $proxy = null, $proxy_auth =
6161
public function execute(
6262
$bucket,
6363
$key,
64-
$fops,
64+
$fops = null,
6565
$pipeline = null,
6666
$notify_url = null,
6767
$force = false,
68-
$type = null
68+
$type = null,
69+
$workflow_template_id = null
6970
) {
7071
if (is_array($fops)) {
7172
$fops = implode(';', $fops);
7273
}
73-
$params = array('bucket' => $bucket, 'key' => $key, 'fops' => $fops);
74+
$params = array('bucket' => $bucket, 'key' => $key);
75+
\Qiniu\setWithoutEmpty($params, 'fops', $fops);
7476
\Qiniu\setWithoutEmpty($params, 'pipeline', $pipeline);
7577
\Qiniu\setWithoutEmpty($params, 'notifyURL', $notify_url);
7678
\Qiniu\setWithoutEmpty($params, 'type', $type);
79+
\Qiniu\setWithoutEmpty($params, 'workflowTemplateID', $workflow_template_id);
7780
if ($force) {
7881
$params['force'] = 1;
7982
}

tests/Qiniu/Tests/PfopTest.php

+89-25
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,32 @@
33

44
use PHPUnit\Framework\TestCase;
55

6+
use Qiniu\Auth;
67
use Qiniu\Processing\PersistentFop;
78
use Qiniu\Storage\UploadManager;
8-
use Qiniu\Region;
9-
use Qiniu\Config;
9+
//use Qiniu\Region;
10+
//use Qiniu\Config;
1011

1112
class PfopTest extends TestCase
1213
{
14+
/**
15+
* @var Auth
16+
*/
17+
private static $testAuth;
18+
19+
private static $bucketName;
20+
/**
21+
* @beforeClass
22+
*/
23+
public static function setupBeforeClass()
24+
{
25+
global $bucketName;
26+
global $testAuth;
27+
28+
self::$bucketName = $bucketName;
29+
self::$testAuth = $testAuth;
30+
}
31+
1332
private static function getConfig()
1433
{
1534
// use this func to test in test env
@@ -52,7 +71,7 @@ public function testPfopExecuteAndStatusWithMultipleFops()
5271
$this->assertNull($error);
5372
}
5473

55-
private function pfopTypeTestData()
74+
private function pfopOptionsTestData()
5675
{
5776
return array(
5877
array(
@@ -69,31 +88,47 @@ private function pfopTypeTestData()
6988
),
7089
array(
7190
'type' => 2
91+
),
92+
array(
93+
'workflowTemplateID' => 'test-workflow'
7294
)
7395
);
7496
}
7597

76-
public function testPfopWithIdleTimeType()
98+
public function testPfopExecuteWithOptions()
7799
{
78-
global $testAuth;
79-
80-
$bucket = 'testres';
81-
$key = 'sintel_trailer.mp4';
82-
$persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1');
83-
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry;
84-
$pfop = new PersistentFop($testAuth, self::getConfig());
100+
$bucket = self::$bucketName;
101+
$key = 'qiniu.png';
102+
$pfop = new PersistentFop(self::$testAuth, self::getConfig());
85103

86-
$testCases = $this->pfopTypeTestData();
104+
$testCases = $this->pfopOptionsTestData();
87105

88106
foreach ($testCases as $testCase) {
107+
if ($testCase['workflowTemplateID']) {
108+
$fops = null;
109+
} else {
110+
$persistentEntry = \Qiniu\entry(
111+
$bucket,
112+
implode(
113+
'_',
114+
array(
115+
'test-pfop/test-pfop-by-api',
116+
'type',
117+
$testCase['type']
118+
)
119+
)
120+
);
121+
$fops = 'avinfo|saveas/' . $persistentEntry;
122+
}
89123
list($id, $error) = $pfop->execute(
90124
$bucket,
91125
$key,
92126
$fops,
93127
null,
94128
null,
95129
false,
96-
$testCase['type']
130+
$testCase['type'],
131+
$testCase['workflowTemplateID']
97132
);
98133

99134
if (in_array($testCase['type'], array(null, 0, 1))) {
@@ -104,29 +139,50 @@ public function testPfopWithIdleTimeType()
104139
if ($testCase['type'] == 1) {
105140
$this->assertEquals(1, $status['type']);
106141
}
142+
if ($testCase['workflowTemplateID']) {
143+
// assertStringContainsString when PHPUnit >= 8.0
144+
$this->assertTrue(
145+
strpos(
146+
$status['taskFrom'],
147+
$testCase['workflowTemplateID']
148+
) !== false
149+
);
150+
}
107151
$this->assertNotEmpty($status['creationDate']);
108152
} else {
109153
$this->assertNotNull($error);
110154
}
111155
}
112156
}
113157

114-
115-
public function testPfopByUploadPolicy()
158+
public function testPfopWithUploadPolicy()
116159
{
117-
global $testAuth;
118-
$bucket = 'testres';
119-
$key = 'sintel_trailer.mp4';
120-
$persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1');
121-
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry;
160+
$bucket = self::$bucketName;
161+
$testAuth = self::$testAuth;
162+
$key = 'test-pfop/upload-file';
122163

123-
$testCases = $this->pfopTypeTestData();
164+
$testCases = $this->pfopOptionsTestData();
124165

125166
foreach ($testCases as $testCase) {
126167
$putPolicy = array(
127-
'persistentOps' => $fops,
128168
'persistentType' => $testCase['type']
129169
);
170+
if ($testCase['workflowTemplateID']) {
171+
$putPolicy['persistentWorkflowTemplateID'] = $testCase['workflowTemplateID'];
172+
} else {
173+
$persistentEntry = \Qiniu\entry(
174+
$bucket,
175+
implode(
176+
'_',
177+
array(
178+
'test-pfop/test-pfop-by-upload',
179+
'type',
180+
$testCase['type']
181+
)
182+
)
183+
);
184+
$putPolicy['persistentOps'] = 'avinfo|saveas/' . $persistentEntry;
185+
}
130186

131187
if ($testCase['type'] == null) {
132188
unset($putPolicy['persistentType']);
@@ -165,16 +221,24 @@ public function testPfopByUploadPolicy()
165221
if ($testCase['type'] == 1) {
166222
$this->assertEquals(1, $status['type']);
167223
}
224+
if ($testCase['workflowTemplateID']) {
225+
// assertStringContainsString when PHPUnit >= 8.0
226+
$this->assertTrue(
227+
strpos(
228+
$status['taskFrom'],
229+
$testCase['workflowTemplateID']
230+
) !== false
231+
);
232+
}
168233
$this->assertNotEmpty($status['creationDate']);
169234
}
170235
}
171236

172237
public function testMkzip()
173238
{
174-
global $testAuth;
175-
$bucket = 'phpsdk';
239+
$bucket = self::$bucketName;
176240
$key = 'php-logo.png';
177-
$pfop = new PersistentFop($testAuth, null);
241+
$pfop = new PersistentFop(self::$testAuth, null);
178242

179243
$url1 = 'http://phpsdk.qiniudn.com/php-logo.png';
180244
$url2 = 'http://phpsdk.qiniudn.com/php-sdk.html';

0 commit comments

Comments
 (0)