1919
2020use Closure ;
2121use DateTimeInterface ;
22- use Google \ApiCore \OperationResponse ;
22+ use Google \Cloud \Core \LongRunning \LongRunningGapicConnection ;
23+ use Google \Cloud \Core \LongRunning \LongRunningOperation ;
2324use Google \ApiCore \ValidationException ;
2425use Google \Cloud \Core \Exception \NotFoundException ;
2526use Google \Cloud \Core \Iterator \ItemIterator ;
@@ -95,14 +96,14 @@ public function __construct(
9596 * consistent copy of the database. If not present, it will be the same
9697 * as the create time of the backup.
9798 * }
98- * @return OperationResponse
99+ * @return LongRunningOperation
99100 * @throws \InvalidArgumentException
100101 */
101102 public function create (
102103 $ database ,
103104 DateTimeInterface $ expireTime ,
104105 array $ options = []
105- ): OperationResponse {
106+ ): LongRunningOperation {
106107 [$ data , $ callOptions ] = $ this ->splitOptionalArgs ($ options );
107108
108109 $ data += [
@@ -124,10 +125,10 @@ public function create(
124125 }
125126
126127 $ request = $ this ->serializer ->decodeMessage (new CreateBackupRequest (), $ data );
127- return $ this ->databaseAdminClient ->createBackup ($ request , $ callOptions + [
128+ $ operation = $ this ->databaseAdminClient ->createBackup ($ request , $ callOptions + [
128129 'resource-prefix ' => $ this ->instance ->name (),
129- ])
130- -> withResultFunction ( $ this ->backupResultFunction () );
130+ ]);
131+ return $ this ->operationFromOperationResponse ( $ operation );
131132 }
132133
133134 /**
@@ -151,14 +152,14 @@ public function create(
151152 * @param array $options [optional] {
152153 * Configuration Options.
153154 * }
154- * @return OperationResponse
155+ * @return LongRunningOperation
155156 * @throws \InvalidArgumentException
156157 */
157158 public function createCopy (
158159 Backup $ newBackup ,
159160 DateTimeInterface $ expireTime ,
160161 array $ options = []
161- ): OperationResponse {
162+ ): LongRunningOperation {
162163 [$ data , $ callOptions ] = $ this ->splitOptionalArgs ($ options );
163164 $ data += [
164165 'parent ' => $ newBackup ->instance ->name (),
@@ -169,10 +170,10 @@ public function createCopy(
169170
170171 $ request = $ this ->serializer ->decodeMessage (new CopyBackupRequest (), $ data );
171172
172- return $ this ->databaseAdminClient ->copyBackup ($ request , $ callOptions + [
173+ $ operation = $ this ->databaseAdminClient ->copyBackup ($ request , $ callOptions + [
173174 'resource-prefix ' => $ this ->instance ->name (),
174- ])
175- -> withResultFunction ( $ this ->backupResultFunction () );
175+ ]);
176+ return $ this ->operationFromOperationResponse ( $ operation );
176177 }
177178
178179 /**
@@ -355,19 +356,25 @@ public function updateExpireTime(DateTimeInterface $newTimestamp, array $options
355356 *
356357 * Example:
357358 * ```
358- * $operation = $spanner ->resumeOperation($operationName);
359+ * $operation = $backup ->resumeOperation($operationName);
359360 * ```
360361 *
361362 * @param string $operationName The Long Running Operation name.
362- * @return OperationResponse
363+ * @return LongRunningOperation
363364 */
364- public function resumeOperation ($ operationName , array $ options = []): OperationResponse
365+ public function resumeOperation ($ operationName , array $ options = []): LongRunningOperation
365366 {
366- return (new OperationResponse (
367+ return new LongRunningOperation (
368+ new LongRunningGapicConnection ($ this ->databaseAdminClient , $ this ->serializer ),
367369 $ operationName ,
368- $ this ->databaseAdminClient ->getOperationsClient (),
370+ [
371+ [
372+ 'typeUrl ' => 'type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata ' ,
373+ 'callable ' => $ this ->backupResultFunction (),
374+ ]
375+ ],
369376 $ options
370- ))-> withResultFunction ( $ this -> backupResultFunction ()) ;
377+ );
371378 }
372379
373380 /**
@@ -390,7 +397,7 @@ public function resumeOperation($operationName, array $options = []): OperationR
390397 * @type string $pageToken A previously-returned page token used to
391398 * resume the loading of results from a specific point.
392399 * }
393- * @return ItemIterator<OperationResponse >
400+ * @return ItemIterator<LongRunningOperation >
394401 */
395402 public function longRunningOperations (array $ options = []): ItemIterator
396403 {
@@ -429,10 +436,9 @@ private function fullyQualifiedBackupName($name): string
429436
430437 private function backupResultFunction (): Closure
431438 {
432- return function (BackupProto $ backup ) {
433- $ name = DatabaseAdminClient::parseName ($ backup ->getName ());
434- $ info = $ this ->serializer ->decodeMessage ($ backup );
435- return $ this ->instance ->backup ($ name ['name ' ], $ info );
439+ return function (array $ backup ) {
440+ $ name = DatabaseAdminClient::parseName ($ backup ['name ' ]);
441+ return $ this ->instance ->backup ($ name ['name ' ], $ backup );
436442 };
437443 }
438444}
0 commit comments