Skip to content

Commit

Permalink
feat: add workflow template id for pfop
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 committed Oct 15, 2024
1 parent a9b6716 commit 36a4942
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/Qiniu/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,11 @@ public function uploadToken($bucket, $key = null, $expires = 3600, $policy = nul
'fsizeMin',
'fsizeLimit',

'persistentOps',
'persistentOps', // 与 persistentWorkflowTemplateID 二选一
'persistentNotifyUrl',
'persistentPipeline',
'persistentType', // 为 `1` 时开启闲时任务
'persistentWorkflowTemplateID', // 与 persistentOps 二选一

'deleteAfterDays',
'fileType',
Expand Down
9 changes: 6 additions & 3 deletions src/Qiniu/Processing/PersistentFop.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,22 @@ public function __construct($auth, $config = null, $proxy = null, $proxy_auth =
public function execute(
$bucket,
$key,
$fops,
$fops = null,
$pipeline = null,
$notify_url = null,
$force = false,
$type = null
$type = null,
$workflow_template_id = null
) {
if (is_array($fops)) {
$fops = implode(';', $fops);
}
$params = array('bucket' => $bucket, 'key' => $key, 'fops' => $fops);
$params = array('bucket' => $bucket, 'key' => $key);
\Qiniu\setWithoutEmpty($params, 'fops', $fops);
\Qiniu\setWithoutEmpty($params, 'pipeline', $pipeline);
\Qiniu\setWithoutEmpty($params, 'notifyURL', $notify_url);
\Qiniu\setWithoutEmpty($params, 'type', $type);
\Qiniu\setWithoutEmpty($params, 'workflowTemplateID', $workflow_template_id);
if ($force) {
$params['force'] = 1;
}
Expand Down
114 changes: 89 additions & 25 deletions tests/Qiniu/Tests/PfopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,32 @@

use PHPUnit\Framework\TestCase;

use Qiniu\Auth;
use Qiniu\Processing\PersistentFop;
use Qiniu\Storage\UploadManager;
use Qiniu\Region;
use Qiniu\Config;
//use Qiniu\Region;
//use Qiniu\Config;

class PfopTest extends TestCase
{
/**
* @var Auth
*/
private static $testAuth;

private static $bucketName;
/**
* @beforeClass
*/
public static function setupBeforeClass()
{
global $bucketName;
global $testAuth;

self::$bucketName = $bucketName;
self::$testAuth = $testAuth;
}

private static function getConfig()
{
// use this func to test in test env
Expand Down Expand Up @@ -52,7 +71,7 @@ public function testPfopExecuteAndStatusWithMultipleFops()
$this->assertNull($error);
}

private function pfopTypeTestData()
private function pfopOptionsTestData()
{
return array(
array(
Expand All @@ -69,31 +88,47 @@ private function pfopTypeTestData()
),
array(
'type' => 2
),
array(
'workflowTemplateID' => 'test-workflow'
)
);
}

public function testPfopWithIdleTimeType()
public function testPfopExecuteWithOptions()
{
global $testAuth;

$bucket = 'testres';
$key = 'sintel_trailer.mp4';
$persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1');
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry;
$pfop = new PersistentFop($testAuth, self::getConfig());
$bucket = self::$bucketName;
$key = 'qiniu.png';
$pfop = new PersistentFop(self::$testAuth, self::getConfig());

$testCases = $this->pfopTypeTestData();
$testCases = $this->pfopOptionsTestData();

foreach ($testCases as $testCase) {
if ($testCase['workflowTemplateID']) {
$fops = null;
} else {
$persistentEntry = \Qiniu\entry(
$bucket,
implode(
'_',
array(
'test-pfop/test-pfop-by-api',
'type',
$testCase['type']
)
)
);
$fops = 'avinfo|saveas/' . $persistentEntry;
}
list($id, $error) = $pfop->execute(
$bucket,
$key,
$fops,
null,
null,
false,
$testCase['type']
$testCase['type'],
$testCase['workflowTemplateID']
);

if (in_array($testCase['type'], array(null, 0, 1))) {
Expand All @@ -104,29 +139,50 @@ public function testPfopWithIdleTimeType()
if ($testCase['type'] == 1) {
$this->assertEquals(1, $status['type']);
}
if ($testCase['workflowTemplateID']) {
// assertStringContainsString when PHPUnit >= 8.0
$this->assertTrue(
strpos(
$status['taskFrom'],
$testCase['workflowTemplateID']
) !== false
);
}
$this->assertNotEmpty($status['creationDate']);
} else {
$this->assertNotNull($error);
}
}
}


public function testPfopByUploadPolicy()
public function testPfopWithUploadPolicy()
{
global $testAuth;
$bucket = 'testres';
$key = 'sintel_trailer.mp4';
$persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1');
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry;
$bucket = self::$bucketName;
$testAuth = self::$testAuth;
$key = 'test-pfop/upload-file';

$testCases = $this->pfopTypeTestData();
$testCases = $this->pfopOptionsTestData();

foreach ($testCases as $testCase) {
$putPolicy = array(
'persistentOps' => $fops,
'persistentType' => $testCase['type']
);
if ($testCase['workflowTemplateID']) {
$putPolicy['persistentWorkflowTemplateID'] = $testCase['workflowTemplateID'];
} else {
$persistentEntry = \Qiniu\entry(
$bucket,
implode(
'_',
array(
'test-pfop/test-pfop-by-upload',
'type',
$testCase['type']
)
)
);
$putPolicy['persistentOps'] = 'avinfo|saveas/' . $persistentEntry;
}

if ($testCase['type'] == null) {
unset($putPolicy['persistentType']);
Expand Down Expand Up @@ -165,16 +221,24 @@ public function testPfopByUploadPolicy()
if ($testCase['type'] == 1) {
$this->assertEquals(1, $status['type']);
}
if ($testCase['workflowTemplateID']) {
// assertStringContainsString when PHPUnit >= 8.0
$this->assertTrue(
strpos(
$status['taskFrom'],
$testCase['workflowTemplateID']
) !== false
);
}
$this->assertNotEmpty($status['creationDate']);
}
}

public function testMkzip()
{
global $testAuth;
$bucket = 'phpsdk';
$bucket = self::$bucketName;
$key = 'php-logo.png';
$pfop = new PersistentFop($testAuth, null);
$pfop = new PersistentFop(self::$testAuth, null);

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

0 comments on commit 36a4942

Please sign in to comment.