Skip to content

Commit 3a98f73

Browse files
committed
Preparing src for release 8.2.0
1 parent 903a994 commit 3a98f73

File tree

215 files changed

+253958
-8446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+253958
-8446
lines changed

ChangeLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### 8.2.0
2+
3+
AdWords:
4+
- Fixed [issue #123](https://github.com/googleads/googleads-php-lib/issues/123).
5+
- Added support and examples for v201603.
6+
7+
DFP:
8+
- Fixed [issue #126](https://github.com/googleads/googleads-php-lib/issues/126).
9+
110
### 8.1.0
211

312
AdWords:

examples/AdWords/v201509/CampaignManagement/AddCompleteCampaignsUsingBatchJob.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ function AddCompleteCampaignUsingBatchJobExample(AdWordsUser $user) {
115115

116116
$pollAttempts++;
117117
if ($batchJob->status !== 'ACTIVE' &&
118-
$batchJob->status !== 'AWAITING_FILE') {
118+
$batchJob->status !== 'AWAITING_FILE' &&
119+
$batchJob->status !== 'CANCELING') {
119120
$isPending = false;
120121
}
121122
} while ($isPending && $pollAttempts <= MAX_POLL_ATTEMPTS);
@@ -140,6 +141,8 @@ function AddCompleteCampaignUsingBatchJobExample(AdWordsUser $user) {
140141
$processingError->reason
141142
);
142143
}
144+
} else {
145+
printf("No processing errors found.\n");
143146
}
144147

145148
if ($batchJob->downloadUrl !== null && $batchJob->downloadUrl->url !== null) {
@@ -156,6 +159,8 @@ function AddCompleteCampaignUsingBatchJobExample(AdWordsUser $user) {
156159
printf(" Operation [%d] - %s\n", $mutateResult->index, $outcome);
157160
}
158161
}
162+
} else {
163+
printf("No results available for download.\n");
159164
}
160165
}
161166

examples/AdWords/v201509/CampaignManagement/AddKeywordsInBulk.php

Lines changed: 0 additions & 202 deletions
This file was deleted.

examples/AdWords/v201509/AdvancedOperations/AddKeywordsUsingIncrementalBatchJob.php renamed to examples/AdWords/v201509/CampaignManagement/AddKeywordsUsingIncrementalBatchJob.php

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,40 +70,84 @@ function AddKeywordsUsingIncrementalBatchJob(AdWordsUser $user, $adGroupId) {
7070
buildAdGroupCriterionOperations($adGroupId);
7171
$batchJobUtils->UploadIncrementalBatchJobOperations(
7272
$adGroupCriterionOperations);
73+
printf("Uploaded %d operations for batch job with ID %d.\n",
74+
count($adGroupCriterionOperations), $batchJob->id);
7375

7476
// Generate and upload the second set of operations.
7577
$adGroupCriterionOperations =
7678
buildAdGroupCriterionOperations($adGroupId);
7779
$batchJobUtils->UploadIncrementalBatchJobOperations(
7880
$adGroupCriterionOperations);
81+
printf("Uploaded %d operations for batch job with ID %d.\n",
82+
count($adGroupCriterionOperations), $batchJob->id);
7983

8084
// Generate and upload the third and final set of operations.
8185
$adGroupCriterionOperations =
8286
buildAdGroupCriterionOperations($adGroupId);
8387
$batchJobUtils->UploadIncrementalBatchJobOperations(
8488
$adGroupCriterionOperations, true);
89+
printf("Uploaded %d operations for batch job with ID %d.\n",
90+
count($adGroupCriterionOperations), $batchJob->id);
8591

8692
// Poll for completion of the batch job using an exponential back off.
8793
$pollAttempts = 0;
8894
$isPending = true;
95+
$wasCancelRequested = false;
96+
97+
$selector = new Selector();
98+
$selector->fields = array('Id', 'Status', 'DownloadUrl', 'ProcessingErrors',
99+
'ProgressStats');
100+
$selector->predicates[] = new Predicate('Id', 'EQUALS', $batchJob->id);
89101
do {
90102
$sleepSeconds = POLL_FREQUENCY_SECONDS * pow(2, $pollAttempts);
91103
printf("Sleeping %d seconds...\n", $sleepSeconds);
92104
sleep($sleepSeconds);
93105

94-
$selector = new Selector();
95-
$selector->fields = array('Id', 'Status', 'DownloadUrl', 'ProcessingErrors',
96-
'ProgressStats');
97-
$selector->predicates[] = new Predicate('Id', 'EQUALS', $batchJob->id);
98106
$batchJob = $batchJobService->get($selector)->entries[0];
99107
printf("Batch job ID %d has status '%s'.\n", $batchJob->id,
100108
$batchJob->status);
101109

102110
$pollAttempts++;
103111
if ($batchJob->status !== 'ACTIVE' &&
104-
$batchJob->status !== 'AWAITING_FILE') {
112+
$batchJob->status !== 'AWAITING_FILE' &&
113+
$batchJob->status !== 'CANCELING') {
105114
$isPending = false;
106115
}
116+
117+
// Optional: Cancel the job if it has not completed after polling
118+
// MAX_POLL_ATTEMPTS times.
119+
if ($isPending && !$wasCancelRequested
120+
&& $pollAttempts == MAX_POLL_ATTEMPTS) {
121+
$batchJob->status = 'CANCELING';
122+
$batchJobSetOperation = new BatchJobOperation();
123+
$batchJobSetOperation->operand = $batchJob;
124+
$batchJobSetOperation->operator = 'SET';
125+
126+
// Only request cancellation once per job.
127+
$wasCancelRequested = true;
128+
try {
129+
$operations[] = $batchJobSetOperation;
130+
$batchJob = $batchJobService->mutate($operations)->value[0];
131+
printf("Requested cancellation of batch job with ID %d.\n",
132+
$batchJob->id);
133+
// Reset the poll attempt counter to wait for cancellation.
134+
$pollAttempts = 0;
135+
} catch (Exception $e) {
136+
$errors = $e->detail->ApiExceptionFault->errors;
137+
if ($errors !== null
138+
&& $errors->enc_value instanceof BatchJobError) {
139+
if ($errors->enc_value->reason === 'INVALID_STATE_CHANGE') {
140+
printf("Attempt to cancel batch job with ID %d was rejected because"
141+
. " the job already completed or was canceled.\n",
142+
$batchJob->id);
143+
// Reset the poll attempt counter to wait for cancellation.
144+
$pollAttempts = 0;
145+
continue;
146+
}
147+
}
148+
throw $e;
149+
}
150+
}
107151
} while ($isPending && $pollAttempts <= MAX_POLL_ATTEMPTS);
108152

109153
if ($isPending) {
@@ -126,6 +170,8 @@ function AddKeywordsUsingIncrementalBatchJob(AdWordsUser $user, $adGroupId) {
126170
$processingError->reason
127171
);
128172
}
173+
} else {
174+
printf("No processing errors found.\n");
129175
}
130176

131177
if ($batchJob->downloadUrl !== null && $batchJob->downloadUrl->url !== null) {
@@ -142,6 +188,8 @@ function AddKeywordsUsingIncrementalBatchJob(AdWordsUser $user, $adGroupId) {
142188
printf(" Operation [%d] - %s\n", $mutateResult->index, $outcome);
143189
}
144190
}
191+
} else {
192+
printf("No results available for download.\n");
145193
}
146194
}
147195

examples/AdWords/v201509/Optimization/GetKeywordBidSimulations.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* This example gets all available keyword bid simulations within an ad group.
44
* To get ad groups, run BasicOperation/GetAdGroups.php.
55
*
6-
* Restriction: adwords-only
7-
*
86
* Copyright 2014, Google Inc. All Rights Reserved.
97
*
108
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -70,20 +68,17 @@ function GetKeywordBidSimulationsExample(AdWordsUser $user, $adGroupId) {
7068
$bidLandscapePoint->bid->microAmount,
7169
$bidLandscapePoint->clicks,
7270
$bidLandscapePoint->cost->microAmount,
73-
$bidLandscapePoint->impressions);
71+
$bidLandscapePoint->impressions
72+
);
7473
}
7574
print "\n";
7675
}
76+
} else if ($selector->paging->startIndex === 0) {
77+
printf("No criterion bid landscapes were found.\n");
7778
}
78-
7979
// Advance the paging index.
8080
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
8181
} while (isset($page->entries) && count($page->entries) > 0);
82-
83-
if ($selector->paging->startIndex === 0) {
84-
print "No criterion bid landscapes were found.\n";
85-
}
86-
8782
}
8883

8984
// Don't run the example if the file is being included.

0 commit comments

Comments
 (0)