-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbatch.php
58 lines (46 loc) · 1.17 KB
/
batch.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
<?php
require dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Airtable.php';
require dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Request.php';
require dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Response.php';
$a = new \TANIOS\Airtable\Airtable( [
'base' => '###',
'api_key' => '###'
] );
/**
* Batch creating
*/
$content = $a->saveContent( 'Links', [
[
'fields' => [
'Name' => 'Tasty'
]
],
[
'fields' => [
'Name' => 'Yolo'
]
]
] );
/**
* Batch updating
*/
$update = [];
foreach ( $content->records as $record )
{
$update[] = [
'id' => $record->id,
'fields' => [
'Slug' => strtolower( $record->fields->Name )
]
];
}
$response = $a->updateContent( 'Links', $update );
/**
* Batch deleting
*/
$delete = [];
foreach ( $response->records as $record )
{
$delete[] = $record->id;
}
$response = $a->deleteContent( 'Links', $delete );