@@ -408,7 +408,7 @@ function descending_sort(DatastoreClient $datastore)
408408 // [START descending_sort]
409409 $ query = $ datastore ->query ()
410410 ->kind ('Task ' )
411- ->order ('create ' , Query::ORDER_DESCENDING );
411+ ->order ('created ' , Query::ORDER_DESCENDING );
412412 // [END descending_sort]
413413 return $ query ;
414414}
@@ -438,13 +438,11 @@ function multi_sort(DatastoreClient $datastore)
438438 */
439439function ancestor_query (DatastoreClient $ datastore )
440440{
441- // TODO: Move to `hasAncestor` once it's available.
442- // https://github.com/GoogleCloudPlatform/google-cloud-php/issues/186
443441 // [START ancestor_query]
444442 $ ancestorKey = $ datastore ->key ('TaskList ' , 'default ' );
445443 $ query = $ datastore ->query ()
446444 ->kind ('Task ' )
447- ->filter ( ' __key__ ' , Query:: OP_HAS_ANCESTOR , $ ancestorKey );
445+ ->hasAncestor ( $ ancestorKey );
448446 // [END ancestor_query]
449447 return $ query ;
450448}
@@ -473,11 +471,9 @@ function kindless_query(DatastoreClient $datastore, Key $lastSeenKey)
473471 */
474472function keys_only_query (DatastoreClient $ datastore )
475473{
476- // TODO: Move to `keysOnly()` once it's available.
477- // https://github.com/GoogleCloudPlatform/google-cloud-php/issues/187
478474 // [START keys_only_query]
479475 $ query = $ datastore ->query ()
480- ->projection ( ' __key__ ' )
476+ ->keysOnly ( )
481477 ->limit (1 );
482478 // [END keys_only_query]
483479 return $ query ;
@@ -780,21 +776,14 @@ function transfer_funds(
780776 $ amount
781777) {
782778 $ transaction = $ datastore ->transaction ();
783- $ result = $ transaction ->lookupBatch ([$ fromKey , $ toKey ]);
779+ // The option 'sort' is important here, otherwise the order of the result
780+ // might be different from the order of the keys.
781+ $ result = $ transaction ->lookupBatch ([$ fromKey , $ toKey ], ['sort ' => true ]);
784782 if (count ($ result ['found ' ]) != 2 ) {
785783 $ transaction ->rollback ();
786784 }
787- // Currently, the result from lookupBatch doesn't guarantee the same order
788- // as the given keys with the client library.
789- // TODO: remove this hack once the issue below is fixed.
790- // https://github.com/GoogleCloudPlatform/google-cloud-php/issues/175
791- if ($ result ['found ' ][0 ]->key ()->path () == $ fromKey ->path ()) {
792- $ fromAccount = $ result ['found ' ][0 ];
793- $ toAccount = $ result ['found ' ][1 ];
794- } else {
795- $ fromAccount = $ result ['found ' ][1 ];
796- $ toAccount = $ result ['found ' ][0 ];
797- }
785+ $ fromAccount = $ result ['found ' ][0 ];
786+ $ toAccount = $ result ['found ' ][1 ];
798787 $ fromAccount ['balance ' ] -= $ amount ;
799788 $ toAccount ['balance ' ] += $ amount ;
800789 $ transaction ->updateBatch ([$ fromAccount , $ toAccount ]);
0 commit comments