如何使用 php-gds 将 Google 数据存储中所有实体的 属性 设置为相同的值?
How to set a property of all entities in a Google Datastore to the same value using php-gds?
我正在使用 php-gds 通过 [=] 连接并使用我的 Google 数据存储 18=]PHP。我所有的用户都存储在那里,他们都有一个名为 'points' 的 属性,其中包含一个整数。我想每个月将 属性 of all users 设置为 0。我已经有一个 cron-task 启动应该在正确的时间执行此操作的功能,但我不确定如何实现实际的重置。这是我想到的:
$store = new \GDS\Store($GLOBALS['userSchema']);
$store->query('SELECT * FROM User');
while ($arr_page = $store->fetchPage(50)) {
foreach($arr_page as $user){
$user->points = 0;
$store->upsert($user);
}
}
这是正确的方法还是会失败,因为我 在获取 时更新插入?有没有更好的方法?
我的示例现在可以正常运行几个星期了。
我正在使用 php-gds 通过 [=] 连接并使用我的 Google 数据存储 18=]PHP。我所有的用户都存储在那里,他们都有一个名为 'points' 的 属性,其中包含一个整数。我想每个月将 属性 of all users 设置为 0。我已经有一个 cron-task 启动应该在正确的时间执行此操作的功能,但我不确定如何实现实际的重置。这是我想到的:
$store = new \GDS\Store($GLOBALS['userSchema']);
$store->query('SELECT * FROM User');
while ($arr_page = $store->fetchPage(50)) {
foreach($arr_page as $user){
$user->points = 0;
$store->upsert($user);
}
}
这是正确的方法还是会失败,因为我 在获取 时更新插入?有没有更好的方法?
我的示例现在可以正常运行几个星期了。