本文整理汇总了PHP中yii\helpers\Console::updateProgress方法的典型用法代码示例。如果您正苦于以下问题:PHP Console::updateProgress方法的具体用法?PHP Console::updateProgress怎么用?PHP Console::updateProgress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Console
的用法示例。
在下文中一共展示了Console::updateProgress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processCron
/**
* Processes update e-mails for all users
*/
public static function processCron($controller)
{
// Detect the mailing interval we're in
$interval = 0;
if (Yii::$app->controller->action->id == 'hourly') {
$interval = self::INTERVAL_HOURY;
} elseif (Yii::$app->controller->action->id == 'daily') {
$interval = self::INTERVAL_DAILY;
} else {
throw new \yii\console\Exception('Invalid mail update interval!');
}
// Get users
$users = User::find()->distinct()->joinWith(['httpSessions', 'profile'])->where(['user.status' => User::STATUS_ENABLED]);
$totalUsers = $users->count();
$processed = 0;
Console::startProgress($processed, $totalUsers, 'Sending update e-mails to users... ', false);
$mailsSent = 0;
foreach ($users->each() as $user) {
$mailSender = new self();
$mailSender->user = $user;
$mailSender->interval = $interval;
if ($mailSender->send()) {
$mailsSent++;
}
Console::updateProgress(++$processed, $totalUsers);
}
Console::endProgress(true);
$controller->stdout('done - ' . $mailsSent . ' email(s) sent.' . PHP_EOL, Console::FG_GREEN);
// Switch back to system language
self::switchLanguage();
}
示例2: render
/**
* @inheritDoc
*/
public function render($files, $targetDir)
{
// $types = array_merge($this->apiContext->classes, $this->apiContext->interfaces, $this->apiContext->traits);
//
// $extTypes = [];
// foreach ($this->extensions as $k => $ext) {
// $extType = $this->filterTypes($types, $ext);
// if (empty($extType)) {
// unset($this->extensions[$k]);
// continue;
// }
// $extTypes[$ext] = $extType;
// }
$fileCount = count($files) + 1;
if ($this->controller !== null) {
Console::startProgress(0, $fileCount, 'Rendering markdown files: ', false);
}
$done = 0;
$fileData = [];
$chapters = $this->loadGuideStructure($files);
foreach ($files as $file) {
$fileData[basename($file)] = file_get_contents($file);
// if (preg_match("/^(.*)\n=+/", $fileData[$file], $matches)) {
// $headlines[$file] = $matches[1];
// } else {
// $headlines[$file] = basename($file);
// }
}
$md = new ApiMarkdownLaTeX();
$output = '';
foreach ($chapters as $chapter) {
if (isset($chapter['headline'])) {
$output .= '\\chapter{' . $chapter['headline'] . "}\n";
}
foreach ($chapter['content'] as $content) {
if (isset($fileData[$content['file']])) {
$md->labelPrefix = $content['file'] . '#';
$output .= '\\label{' . $content['file'] . '}';
$output .= $md->parse($fileData[$content['file']]) . "\n\n";
} else {
$output .= '\\newpage';
$output .= '\\label{' . $content['file'] . '}';
$output .= '\\textbf{Error: not existing file: ' . $content['file'] . '}\\newpage' . "\n";
}
if ($this->controller !== null) {
Console::updateProgress(++$done, $fileCount);
}
}
}
file_put_contents($targetDir . '/guide.tex', $output);
copy(__DIR__ . '/main.tex', $targetDir . '/main.tex');
copy(__DIR__ . '/title.tex', $targetDir . '/title.tex');
copy(__DIR__ . '/Makefile', $targetDir . '/Makefile');
if ($this->controller !== null) {
Console::updateProgress(++$done, $fileCount);
Console::endProgress(true);
$this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
}
echo "\nnow run `make` in {$targetDir} (you need pdflatex to compile pdf file)\n\n";
}
示例3: generatePosts
private function generatePosts()
{
$count = mt_rand(300, 500);
Console::startProgress(0, $count, 'Generating posts: ');
$sectionIds = (new Query())->select('id')->from('{{%section}}')->where('section_id IS NOT NULL')->column($this->getDb());
$authorIds = (new Query())->select('id')->from('{{%user}}')->column($this->getDb());
for ($i = 1; $i <= $count; ++$i) {
$title = rtrim($this->getFaker()->sentence(mt_rand(3, 10)), '.');
$this->getDb()->createCommand()->insert('{{%post}}', ['title' => $title, 'slug' => Inflector::slug($title), 'section_id' => $sectionIds[array_rand($sectionIds)], 'author_id' => $authorIds[array_rand($authorIds)], 'text' => implode("\n\n", $this->getFaker()->paragraphs(mt_rand(1, 5))), 'created_at' => time(), 'updated_at' => time()])->execute();
Console::updateProgress($i, $count);
}
Console::endProgress();
}
示例4: getProgress
/**
* Returns progress closure.
*
* @param string $action
* @return callable
*/
private function getProgress($action)
{
$progress = false;
return function ($processed, $total, $message = null) use($progress, $action) {
if (!$progress) {
Console::startProgress(0, $total, $action);
}
if ($message) {
Console::endProgress($message . PHP_EOL, false);
} else {
Console::updateProgress($processed, $total);
}
};
}
示例5: clearAliases
private function clearAliases($assets)
{
$len = count($assets);
$message = '';
Console::startProgress(0, $len, 'Doing Updates: ', false);
foreach ($assets as $key => $asset) {
$uri = Yii::getAlias($asset);
FileHelper::removeDirectory($uri);
FileHelper::createDirectory($uri);
Console::updateProgress($key + 1, $len);
$message .= 'cleared: ' . $this->ansiFormat($uri, Console::FG_GREEN) . PHP_EOL;
}
Console::endProgress("done." . PHP_EOL);
echo $message;
}
示例6: onSubscribe
public function onSubscribe($redis, $chan, $msg)
{
if ($msg === 'ready') {
$this->post = ['s_bidnmKor' => '', 's_openDtm1' => date('Y/m/d', strtotime('-7 day')), 's_openDtm2' => date('Y/m/d'), 's_cstrtnJobGbCd' => '', 's_bidNum' => '', 'pageSpec' => 'default', 'targetRow' => 1, 'devonOrderBy' => '', 'selectednum' => ''];
$this->pub->publish($this->channel . '-client', ['url' => self::URL, 'post' => http_build_query($this->post)]);
return;
}
$html = iconv('euckr', 'utf-8//IGNORE', $msg);
$html = strip_tags($html, '<tr><td><option>');
$html = preg_replace('/<td[^>]*>/i', '<td>', $html);
if (strpos($html, '한국정보인증(주)의 보안S/W를 설치중입니다') > 0) {
return;
}
$p = '#<tr onclick="fn_dds_open\\(\'\\d{7}\', \'(?<subno>\\d{2})\',[^>]*>' . ' <td>(?<notinum>\\d{7})</td>' . ' <td>(?<bidtype>[^<]*)</td>' . ' <td>(?<bidcls>[^<]*)</td>' . ' <td>(?<constnm>[^<]*)</td>' . ' <td>(?<constdt>\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2})</td>' . ' <td>(?<status>[^<]*)</td>' . ' </tr>#i';
if (preg_match_all(str_replace(' ', '\\s*', $p), $html, $matches, PREG_SET_ORDER)) {
foreach ($matches as $m) {
$row = ['notinum' => trim($m['notinum']), 'subno' => trim($m['subno']), 'bidtype' => trim($m['bidtype']), 'bidcls' => trim($m['bidcls']), 'constnm' => trim($m['constnm']), 'constdt' => trim($m['constdt']), 'status' => trim($m['status'])];
$event = new WatchEvent();
$event->row = $row;
$this->trigger(WatchEvent::EVENT_ROW, $event);
}
}
if (preg_match('#/ (?<total_page>\\d+) 페이지\\)#', $html, $m)) {
$total_page = intval($m['total_page']);
}
if (!$total_page) {
$this->sub->close();
throw new \Exception('total_page is null');
}
$page = ceil($this->post['targetRow'] / 10);
if ($page === 1) {
Console::startProgress(0, $total_page);
Console::updateProgress(1, $total_page);
} else {
Console::updateProgress($page, $total_page);
}
if ($page == $total_page) {
$this->pub->publish($this->channel . '-client', ['url' => 'close', 'post' => '']);
$this->sub->close();
Console::endProgress();
return;
} else {
$this->post['targetRow'] += 10;
}
sleep(mt_rand($this->module->delay_min, $this->module->delay_max));
$this->pub->publish($this->channel . '-client', ['url' => self::URL, 'post' => http_build_query($this->post)]);
}
示例7: generateFakeData
public function generateFakeData($num)
{
Console::startProgress(0, 100);
$topic = new Topic();
$comment = new PostComment();
$node = new PostMeta();
$faker = Faker\Factory::create('zh_CN');
$nodeData = [['name' => '分享', 'alias' => '', 'parent' => 0], ['name' => '招聘', 'alias' => 'jobs', 'parent' => 1], ['name' => '瞎扯淡', 'alias' => 'booshit', 'parent' => 1], ['name' => '健康', 'alias' => 'health', 'parent' => 1], ['name' => '创业', 'alias' => 'startup', 'parent' => 1]];
$transaction = Yii::$app->db->beginTransaction();
try {
for ($j = 0; $j < count($nodeData); $j++) {
$_node = clone $node;
$_node->setAttributes($nodeData[$j] + ['type' => 'topic_category']);
$_node->save();
}
$this->execute("INSERT INTO {{%merit_template}} (`id`, `type`, `title`, `unique_id`, `method`, `event`, `action_type`, `rule_key`, `rule_value`, `increment`, `status`, `created_at`, `updated_at`) VALUES\n(1, 1, '登录', 'site/login', 2, 0, 2, 1, 1, 2, 1, 1458657160, 1458823425),\n(2, 1, '发帖', 'topic/default/create', 2, 0, 2, 0, NULL, 6, 1, 1458657218, 1458657218),\n(3, 1, '回复', 'topic/comment/create', 2, 0, 2, 0, NULL, 4, 1, 1458657251, 1458657251),\n(4, 1, '发动弹', 'tweet/default/create', 2, 0, 2, 0, NULL, 4, 1, 1458657296, 1468647701);\n");
/** @var User $user */
$user = User::find()->where(['role' => User::ROLE_SUPER_ADMIN])->one();
Yii::$app->user->setIdentity($user);
for ($i = 1; $i <= $num; $i++) {
$_topic = clone $topic;
$_topic->setAttributes(['type' => Topic::TYPE, 'title' => $faker->text(rand(10, 50)), 'post_meta_id' => rand(2, 4), 'status' => rand(1, 2), 'content' => $faker->text(rand(100, 2000)), 'user_id' => 1]);
if (!$_topic->save()) {
throw new Exception(array_values($_topic->getFirstErrors())[0]);
}
for ($_i = 1; $_i <= rand(1, 20); $_i++) {
$_comment = clone $comment;
$_comment->setAttributes(['comment' => $faker->text(rand(100, 2000)), 'post_id' => $_topic->id, 'ip' => '127.0.0.1', 'user_id' => 1]);
if (!$_comment->save()) {
throw new Exception(array_values($_comment->getFirstErrors())[0]);
}
// 更新回复时间
$_topic->lastCommentToUpdate($user['username']);
// 评论计数器
Topic::updateAllCounters(['comment_count' => 1], ['id' => $_topic->id]);
// 更新个人总统计
UserInfo::updateAllCounters(['comment_count' => 1], ['user_id' => $_topic->user_id]);
}
Console::updateProgress($i / $num * 100, 100);
}
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
}
Console::endProgress();
}
示例8: actionGenerate
/**
* Generate fake data and
*/
public function actionGenerate()
{
$input = $this->parseArguments(func_get_args());
$container = new Container();
$container->set(GeneratorInterface::class, array_merge(['class' => $this->generator_fqn], $input['generator']));
$container->set(DbProviderInterface::class, array_merge(['class' => $this->dbprovider_fqn], $input['dbprovider']));
$this->generator_obj = $container->get(GeneratorInterface::class);
if (!$this->force && !$this->confirmGeneration()) {
return;
}
$this->dbprovider_obj = $container->get(DbProviderInterface::class);
Console::startProgress(0, $this->count);
foreach ($this->dbprovider_obj->export($this->count) as $count) {
Console::updateProgress($this->count - $count, $this->count);
}
Console::endProgress(true);
}
示例9: actionRun
/**
* Импортировать товары
*/
public function actionRun()
{
$products = $this->_getProducts();
$total = count($products);
$this->stdout("Import products from yupe: {$total}\n", Console::BOLD);
Console::startProgress(0, $total);
$counter = 0;
foreach ($products as $product) {
//print_R($product);die;
$counter++;
Console::updateProgress($counter, $total);
$name = ArrayHelper::getValue($product, 'name');
$v3toysId = ArrayHelper::getValue($product, 'external_id');
$this->_addProduct($product);
//sleep(1);
}
Console::endProgress();
}
示例10: render
/**
* @inheritDoc
*/
public function render($context, $targetDir)
{
$types = array_merge($context->classes, $context->traits, $context->interfaces);
$typeCount = count($types) + 1;
if ($this->controller !== null) {
Console::startProgress(0, $typeCount, 'Rendering files: ', false);
}
$done = 0;
foreach ($types as $type) {
$fileContent = $this->getView()->render('type', ['type' => $type, 'apiContext' => $context, 'types' => $types], $this);
file_put_contents($targetDir . '/' . $this->generateFileName($type->name), $fileContent);
if ($this->controller !== null) {
Console::updateProgress(++$done, $typeCount);
}
}
if ($this->controller !== null) {
Console::updateProgress(++$done, $typeCount);
Console::endProgress(true);
$this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
}
}
示例11: generateFakeData
public function generateFakeData($num)
{
Console::startProgress(0, 100);
$queston = new Question();
$answer = new Answer();
$faker = Faker\Factory::create('zh_CN');
for ($i = 1; $i <= $num; $i++) {
$_question = clone $queston;
$_question->setAttributes(['subject' => $faker->text(rand(10, 100)), 'content' => $faker->text(rand(100, 2000)), 'author_id' => 1]);
if ($_question->save()) {
$_question->setActive();
for ($_i = 1; $_i <= rand(1, 20); $_i++) {
$_answer = clone $answer;
$_answer->setAttributes(['content' => $faker->text(rand(100, 2000)), 'author_id' => 1]);
if ($_question->addAnswer($_answer)) {
$_answer->setActive();
}
}
}
Console::updateProgress($i / $num * 100, 100);
}
Console::endProgress();
}
示例12: generateFakeData
public function generateFakeData($num)
{
Console::startProgress(0, 100);
$topic = new Topic();
$comment = new PostComment();
$node = new PostMeta();
$faker = Faker\Factory::create('zh_CN');
$nodeData = [['name' => '分享', 'alias' => '', 'parent' => 0], ['name' => '招聘', 'alias' => 'recruit', 'parent' => 1], ['name' => '瞎扯淡', 'alias' => 'booshit', 'parent' => 1], ['name' => '健康', 'alias' => 'health', 'parent' => 1], ['name' => '创业', 'alias' => 'startup', 'parent' => 1]];
for ($j = 0; $j < count($nodeData); $j++) {
$_node = clone $node;
$_node->setAttributes($nodeData[$j] + ['type' => 'topic_category']);
$_node->save();
}
$user = User::find()->where(['role' => User::ROLE_SUPER_ADMIN])->one();
for ($i = 1; $i <= $num; $i++) {
$_topic = clone $topic;
$_topic->setAttributes(['type' => Topic::TYPE, 'title' => $faker->text(rand(10, 50)), 'post_meta_id' => rand(2, 4), 'status' => rand(1, 2), 'content' => $faker->text(rand(100, 2000)), 'user_id' => 1]);
if (!$_topic->save()) {
throw new Exception(array_values($_topic->getFirstErrors())[0]);
}
for ($_i = 1; $_i <= rand(1, 20); $_i++) {
$_comment = clone $comment;
$_comment->setAttributes(['comment' => $faker->text(rand(100, 2000)), 'post_id' => $_topic->id, 'ip' => '127.0.0.1', 'user_id' => 1]);
if (!$_comment->save()) {
throw new Exception(array_values($_comment->getFirstErrors())[0]);
}
// 更新回复时间
$_topic->lastCommentToUpdate($user['username']);
// 评论计数器
Topic::updateAllCounters(['comment_count' => 1], ['id' => $_topic->id]);
// 更新个人总统计
UserInfo::updateAllCounters(['comment_count' => 1], ['user_id' => $_topic->user_id]);
}
Console::updateProgress($i / $num * 100, 100);
}
Console::endProgress();
}
示例13: run
public function run($workload, $className)
{
try {
$notinum_ex = $workload['bidno'];
if (isset($workload['bidproc']) and ArrayHelper::isIn($workload['bidproc'], ['유찰', '재공고'])) {
$query = BidKey::find()->where(['whereis' => '08', 'notinum' => $data['notinum']]);
if ($notinum_ex == 1) {
$query->andWhere("notinum_ex='' or notinum_ex='1'");
} else {
$query->andWhere(['notinum_ex' => $notinum_ex]);
}
$bidkey = $query->orderBy('bidid desc')->limit(1)->one();
if ($bidkey !== null and $bidkey->bidproc !== 'F') {
$this->gman_client->doBackground('i2_auto_suc_test', Json::encode(['bidid' => $bidkey->bidid, 'bidproc' => 'F']));
$this->stdout2(" >>> {$bidkey->bidid} ({$bidkey->bidproc}) %y유찰%n\n");
}
return;
}
$worker = new $className(['notino' => $workload['notino'], 'bidno' => $workload['bidno'], 'bidseq' => $workload['bidseq'], 'state' => $workload['state']]);
$worker->on('total_page', function ($event) {
Console::startProgress(0, $event->sender->succom_total_page);
});
$worker->on('page', function ($event) {
if ($event->sender->succom_total_page == $event->sender->succom_page) {
Console::updateProgress($event->sender->succom_page, $event->sender->succom_total_page);
Console::endProgress();
} else {
Console::updateProgress($event->sender->succom_page, $event->sender->succom_total_page);
}
});
$data = $worker->run();
$query = BidKey::find()->where(['whereis' => '08', 'notinum' => $data['notinum']]);
if ($notinum_ex == 1) {
$query->andWhere("notinum_ex='' or notinum_ex='1'");
} else {
$query->andWhere(['notinum_ex' => $notinum_ex]);
}
$bidkey = $query->orderBy('bidid desc')->limit(1)->one();
if ($bidkey === null) {
return;
}
$bidvalue = $bidkey->bidValue;
$data['multispare'] = $bidvalue->multispare;
if (is_array($data['selms'])) {
$selms = [];
$multispares = explode('|', $data['multispare']);
foreach ($multispares as $i => $v) {
if (ArrayHelper::isIn($v, $data['selms'])) {
$selms[] = $i + 1;
}
}
$data['selms'] = join('|', $selms);
}
$data['bidid'] = $bidkey->bidid;
$data['bidproc'] = 'S';
$this->gman_client->doBackground('i2_auto_suc_test', Json::encode($data));
$this->stdout2(" >>> {$bidkey->bidid} ({$bidkey->bidproc}) 예가:{$data['yega']} 참여수:{$data['innum']} %g개찰%n\n");
} catch (\Exception $e) {
$this->stdout("{$e}\n", Console::FG_RED);
\Yii::error($e, 'ebidex');
}
}
示例14: actionIndex
/**
* Renders API documentation files
* @param array $sourceDirs
* @param string $targetDir
* @return int
*/
public function actionIndex(array $sourceDirs, $targetDir)
{
$renderer = $this->findRenderer($this->template);
$targetDir = $this->normalizeTargetDir($targetDir);
if ($targetDir === false || $renderer === false) {
return 1;
}
$renderer->apiUrl = './';
$renderer->guidePrefix = $this->guidePrefix;
if ($this->pageTitle !== null) {
$renderer->pageTitle = $this->pageTitle;
}
// setup reference to guide
if ($this->guide !== null) {
$renderer->guideUrl = $guideUrl = $this->guide;
} else {
$guideUrl = './';
$renderer->guideUrl = $targetDir;
if (file_exists($renderer->generateGuideUrl('README.md'))) {
$renderer->guideUrl = $guideUrl;
} else {
$renderer->guideUrl = null;
}
}
// search for files to process
if (($files = $this->searchFiles($sourceDirs)) === false) {
return 1;
}
// load context from cache
$context = $this->loadContext($targetDir);
$this->stdout('Checking for updated files... ');
foreach ($context->files as $file => $sha) {
if (!file_exists($file)) {
$this->stdout('At least one file has been removed. Rebuilding the context...');
$context = new Context();
if (($files = $this->searchFiles($sourceDirs)) === false) {
return 1;
}
break;
}
if (sha1_file($file) === $sha) {
unset($files[$file]);
}
}
$this->stdout('done.' . PHP_EOL, Console::FG_GREEN);
// process files
$fileCount = count($files);
$this->stdout($fileCount . ' file' . ($fileCount == 1 ? '' : 's') . ' to update.' . PHP_EOL);
Console::startProgress(0, $fileCount, 'Processing files... ', false);
$done = 0;
foreach ($files as $file) {
$context->addFile($file);
Console::updateProgress(++$done, $fileCount);
}
Console::endProgress(true);
$this->stdout('done.' . PHP_EOL, Console::FG_GREEN);
// save processed data to cache
$this->storeContext($context, $targetDir);
$this->updateContext($context);
// render models
$renderer->controller = $this;
$renderer->render($context, $targetDir);
if (!empty($context->errors)) {
ArrayHelper::multisort($context->errors, 'file');
file_put_contents($targetDir . '/errors.txt', print_r($context->errors, true));
$this->stdout(count($context->errors) . " errors have been logged to {$targetDir}/errors.txt\n", Console::FG_RED, Console::BOLD);
}
}
示例15: onCronRun
public static function onCronRun($event)
{
$controller = $event->sender;
$interval = "";
if (Yii::$app->controller->action->id == 'hourly') {
$interval = CronController::EVENT_ON_HOURLY_RUN;
} elseif (Yii::$app->controller->action->id == 'daily') {
$interval = CronController::EVENT_ON_DAILY_RUN;
} else {
return;
}
$users = User::find()->distinct()->joinWith(['httpSessions', 'profile'])->where(['status' => User::STATUS_ENABLED]);
$totalUsers = $users->count();
$done = 0;
$mailsSent = 0;
$defaultLanguage = Yii::$app->language;
Console::startProgress($done, $totalUsers, 'Sending update e-mails to users... ', false);
foreach ($users->each() as $user) {
if ($user->email === "") {
continue;
}
// Check user should receive an email
Yii::$app->user->switchIdentity($user);
if ($user->language != "") {
Yii::$app->language = $user->language;
} else {
Yii::$app->language = $defaultLanguage;
}
$notifications = Yii::$app->getModule('notification')->getMailUpdate($user, $interval);
$activities = Yii::$app->getModule('activity')->getMailUpdate($user, $interval);
if ($notifications != "" || $activities != "") {
try {
$mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/content/views/mails/Update'], ['activities' => $activities, 'notifications' => $notifications]);
$mail->setFrom([Setting::Get('systemEmailAddress', 'mailing') => Setting::Get('systemEmailName', 'mailing')]);
$mail->setTo($user->email);
if ($interval == CronController::EVENT_ON_HOURLY_RUN) {
$mail->setSubject(Yii::t('base', "Latest news"));
} else {
$mail->setSubject(Yii::t('base', "Your daily summary"));
}
$mail->send();
$mailsSent++;
} catch (\Swift_SwiftException $ex) {
Yii::error('Could not send mail to: ' . $user->email . ' - Error: ' . $ex->getMessage());
} catch (Exception $ex) {
Yii::error('Could not send mail to: ' . $user->email . ' - Error: ' . $ex->getMessage());
}
}
Console::updateProgress(++$done, $totalUsers);
}
Console::endProgress(true);
$controller->stdout('done - ' . $mailsSent . ' email(s) sent.' . PHP_EOL, \yii\helpers\Console::FG_GREEN);
}