forked from jessp01/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03.usersBulkUpload.php
114 lines (98 loc) · 2.62 KB
/
03.usersBulkUpload.php
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
<?php
$config = null;
$clientConfig = null;
/* @var $clientConfig KalturaConfiguration */
$client = null;
/* @var $client KalturaClient */
require_once __DIR__ . '/lib/init.php';
echo "Test started [" . __FILE__ . "]\n";
/**
* Start a new session
*/
$partnerId = $config['session']['partnerId'];
$adminSecretForSigning = $config['session']['adminSecret'];
$client->setKs($client->generateSessionV2($adminSecretForSigning, 'sanity-user', KalturaSessionType::USER, $partnerId, 86400, ''));
echo "Session started\n";
/**
* Creates CSV file
*/
$csvPath = tempnam(sys_get_temp_dir(), 'csv');
$csvData = array(
array(
"*action" => KalturaBulkUploadAction::ADD,
"userId" => "sanity-test1",
"screenName" => "sanity-test1",
"firstName" => "sanity",
"lastName" => "test1",
"email" => "[email protected]",
"tags" => "sanity,test1",
// "gender" => "",
// "zip" => "",
// "country" => "",
// "state" => "",
// "city" => "",
// "dateOfBirth" => "",
// "partnerData" => "",
),
array(
"*action" => KalturaBulkUploadAction::ADD,
"userId" => "sanity-test2",
"screenName" => "sanity-test2",
"firstName" => "sanity",
"lastName" => "test2",
"email" => "[email protected]",
"tags" => "sanity,test2",
// "gender" => "",
// "zip" => "",
// "country" => "",
// "state" => "",
// "city" => "",
// "dateOfBirth" => "",
// "partnerData" => "",
),
);
$f = fopen($csvPath, 'w');
fputcsv($f, array_keys(reset($csvData)));
foreach ($csvData as $csvLine)
fputcsv($f, $csvLine);
fclose($f);
$bulkUpload = $client->user->addFromBulkUpload($csvPath);
/* @var $bulkUpload KalturaBulkUpload */
echo "Bulk upload added [$bulkUpload->id]\n";
$bulkUploadPlugin = KalturaBulkUploadClientPlugin::get($client);
while($bulkUpload)
{
if($bulkUpload->status == KalturaBatchJobStatus::FINISHED || $bulkUpload->status == KalturaBatchJobStatus::FINISHED_PARTIALLY)
break;
if($bulkUpload->status == KalturaBatchJobStatus::FAILED)
{
echo "Bulk upload [$bulkUpload->id] failed\n";
exit(-1);
}
if($bulkUpload->status == KalturaBatchJobStatus::ABORTED)
{
echo "Bulk upload [$bulkUpload->id] aborted\n";
exit(-1);
}
if($bulkUpload->status == KalturaBatchJobStatus::FATAL)
{
echo "Bulk upload [$bulkUpload->id] failed fataly\n";
exit(-1);
}
if($bulkUpload->status == KalturaBatchJobStatus::DONT_PROCESS)
{
echo "Bulk upload [$bulkUpload->id] removed temporarily from the batch queue \n";
}
sleep(15);
$bulkUpload = $bulkUploadPlugin->bulk->get($bulkUpload->id);
}
if(!$bulkUpload)
{
echo "Bulk upload not found\n";
exit(-1);
}
/**
* All is SABABA
*/
echo "OK\n";
exit(0);