本文整理汇总了PHP中RainLab\User\Models\User::chunk方法的典型用法代码示例。如果您正苦于以下问题:PHP User::chunk方法的具体用法?PHP User::chunk怎么用?PHP User::chunk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RainLab\User\Models\User
的用法示例。
在下文中一共展示了User::chunk方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
User::chunk(500, function ($users) {
foreach ($users as $user) {
if (strlen($user->barcode_id) > 10) {
$user->barcode_id = substr($user->barcode_id, 0, 9);
$user->forceSave();
}
}
});
}
示例2: updateExistingUsers
/**
* Updates the metadata from wordpress on existing users
*/
public function updateExistingUsers()
{
OctoberUser::chunk(500, function ($users) {
foreach ($users as $user) {
$id = $this->db->table('wp_users')->select('ID')->where('user_email', $user->email)->first();
if (!$id) {
continue;
}
$this->updateMetadata($user, $id->ID);
}
});
}
示例3: synchronizeUser
protected function synchronizeUser()
{
$alwaysUpdate = $this->option('force-update');
$this->progressbar = $this->getHelperSet()->get('progress');
$this->progressbar->start($this->output, User::count());
User::chunk(500, function ($users) use($alwaysUpdate) {
foreach ($users as $user) {
$this->progressbar->advance();
$email = $user->email;
MailChimpIntegration::syncMemberToMailChimp($email, $user, false);
}
});
${$this}->progressbar->finish();
}
示例4: fire
/**
* Read and process incomming data from listenable channels
* @return void
*/
public function fire()
{
// Long run queries fill memory pretty quickly due to a default
// behavior of Laravel where all queries are log in memory. Disabling
// this log fix the issue. See http://laravel.com/docs/4.2/database#query-logging
DB::connection()->disableQueryLog();
User::chunk(200, function ($users) {
foreach ($users as $user) {
$this->increaseCounter('total_users');
$data = $this->normalize($user);
foreach ($data as $attr => $value) {
$user->{$attr} = $value;
}
$user->forceSave();
}
});
var_dump($this->counters);
var_dump($this->writeReport());
}