Skip to content

Commit 4c5314c

Browse files
committed
Вывод времени миграции
1 parent 82fb22c commit 4c5314c

File tree

6 files changed

+49
-17
lines changed

6 files changed

+49
-17
lines changed

admin/main.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
$request = \Bitrix\Main\Application::getInstance()->getContext()->getRequest();
99
$apply = false;
10-
10+
$timeFormatter = new \WS\ReduceMigrations\TimeFormatter($localization->getDataByPath('timeLang'));
1111
if ($request->get('rollback')) {
1212
$module->rollbackLastBatch();
1313
$apply = true;
@@ -37,7 +37,19 @@
3737

3838
foreach ($lastSetupLog->getAppliedLogs() as $appliedLog) {
3939
$appliedLog->isFailed() && $errorFixes[] = $appliedLog;
40-
!$appliedLog->isFailed() && $appliedFixes[$appliedLog->getName()]++;
40+
if (!$appliedLog->isFailed()) {
41+
if (isset($appliedFixes[$appliedLog->getName()])) {
42+
$appliedFixes[$appliedLog->getName()] = array(
43+
'time' => $appliedFixes[$appliedLog->getName()]['time'] + $appliedLog->getTime(),
44+
'count' => $appliedFixes[$appliedLog->getName()]['count'] + 1
45+
);
46+
} else {
47+
$appliedFixes[$appliedLog->getName()] = array(
48+
'time' => $appliedLog->getTime(),
49+
'count' => 1
50+
);
51+
}
52+
}
4153
}
4254
}
4355
//--------------------------------------------------------------------------
@@ -103,9 +115,7 @@
103115
if (isset($scenarios[\WS\ReduceMigrations\Scenario\ScriptScenario::PRIORITY_OPTIONAL])) {
104116
$form->AddCheckBoxField('skipOptional', $localization->message('skipOptional'), false, 'Y', false);
105117
}
106-
$form->AddViewField('time', $localization->message('approximatelyTime'), $localization->message('time', array(
107-
'#time#' => $notAppliedScenarios->getApproximateTime()
108-
)));
118+
$form->AddViewField('time', $localization->message('approximatelyTime'), $timeFormatter->format($notAppliedScenarios->getApproximateTime()));
109119
}
110120
//--------------------
111121
if ($lastSetupLog) {
@@ -120,9 +130,11 @@
120130
<td width="30%" valign="top"><b><?= $localization->getDataByPath('appliedList') ?>:</b></td>
121131
<td width="70%">
122132
<ol style="list-style-type: none; padding-left: 0px; margin-top: 0px;">
123-
<? foreach ($appliedFixes as $fixName => $fixCount):
133+
<? foreach ($appliedFixes as $fixName => $item):
134+
$fixCount = $item['count'];
135+
$time = $item['time'];
124136
?>
125-
<li><?= $fixName ?> <?= $fixCount > 1 ? '['.$fixCount.']' : '' ?></li>
137+
<li><?= $fixName ?> <?= $fixCount > 1 ? '['.$fixCount.']' : '' ?> (<?=$timeFormatter->format($time)?>)</li>
126138
<?endforeach; ?>
127139
</ol>
128140
</tr>

lang/en/admin.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
'errorList' => 'Unsuccessful applied migrations',
1616
'appliedList' => 'Successful applied migrations',
1717
'approximatelyTime' => 'Approximately time of migrations',
18-
'time' => '#time# sec',
18+
'timeLang' => [
19+
'minutes' => 'min',
20+
'seconds' => 'sec'
21+
],
1922
'btnRollback' => 'Undo last change',
2023
'btnApply' => 'Apply',
2124
'lastSetup' => array(

lang/ru/admin.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
'errorList' => 'Ошибки',
1616
'appliedList' => 'Список обновлений',
1717
'approximatelyTime' => 'Примерное время применения миграций:',
18-
'time' => '#time# сек.',
18+
'timeLang' => [
19+
'minutes' => 'мин.',
20+
'seconds' => 'сек.'
21+
],
1922
'btnRollback' => 'Отменить последнее обновление',
2023
'btnApply' => 'Обновить',
2124
'lastSetup' => array(

lang/ru/menu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
'title' => 'Reduce Migrations',
55
'apply' => 'Обновление',
66
'log' => 'Журнал обновлений',
7-
'createScenario' => 'Сценарий обновления',
7+
'createScenario' => 'Новый сценарий обновления',
88
'diagnostic' => 'Диагностика'
99
);

lib/console/console.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use WS\ReduceMigrations\Console\Command\ListCommand;
1111
use WS\ReduceMigrations\Console\Command\RollbackCommand;
1212
use WS\ReduceMigrations\Console\Formatter\Output;
13-
use WS\ReduceMigrations\Console\Formatter\Time;
13+
use WS\ReduceMigrations\TimeFormatter;
1414

1515
class Console {
1616
const OUTPUT_ERROR = 'error';
@@ -29,7 +29,7 @@ class Console {
2929
private $progressOutput;
3030
/** @var Output */
3131
private $defaultOutput;
32-
/** @var Time */
32+
/** @var TimeFormatter */
3333
private $timeFormatter;
3434

3535
public function __construct($args) {
@@ -53,7 +53,10 @@ public function __construct($args) {
5353
$this->errorOutput = new Output('red');
5454
$this->progressOutput = new Output('yellow');
5555
$this->defaultOutput = new Output();
56-
$this->timeFormatter = new Time();
56+
$this->timeFormatter = new TimeFormatter(array(
57+
'minutes' => 'min',
58+
'seconds' => 'sec'
59+
));
5760
}
5861

5962
/**

lib/console/formatter/time.php renamed to lib/timeformatter.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
<?php
22

3-
namespace WS\ReduceMigrations\Console\Formatter;
3+
namespace WS\ReduceMigrations;
44

55

6-
class Time {
6+
class TimeFormatter {
77
const SECONDS_PRECISION = 3;
88
const MINUTES_PRECISION = 2;
99
const SECONDS_THRESHOLD_VALUE = 100;
1010
const SECONDS_IN_MINUTE = 60;
1111

12+
private $lang;
13+
14+
/**
15+
* Time constructor.
16+
*
17+
* @param array $lang - ['minutes'=> 'min', 'seconds' => 'sec']
18+
*/
19+
public function __construct($lang) {
20+
$this->lang = $lang;
21+
}
22+
1223
public function format($initialTime) {
1324
$time = round($initialTime, self::SECONDS_PRECISION);
1425
if ($time >= self::SECONDS_THRESHOLD_VALUE) {
1526
$time = round($time / self::SECONDS_IN_MINUTE, self::MINUTES_PRECISION);
16-
$time = sprintf('%s min', $time);
27+
$time = sprintf('%s %s', $time, $this->lang['minutes']);
1728
} else {
18-
$time = sprintf('%s sec', $time);
29+
$time = sprintf('%s %s', $time, $this->lang['seconds']);
1930
}
2031
return $time;
2132
}

0 commit comments

Comments
 (0)