本文整理匯總了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());
}