| Total Complexity | 5 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | class M180222000000WorkerPing extends Migration |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var Env |
||
| 23 | */ |
||
| 24 | protected $env; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param Env $env |
||
| 28 | * @inheritdoc |
||
| 29 | */ |
||
| 30 | public function __construct(Env $env, $config = []) |
||
| 31 | { |
||
| 32 | $this->env = $env; |
||
| 33 | parent::__construct($config); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @inheritdoc |
||
| 38 | */ |
||
| 39 | public function up() |
||
| 40 | { |
||
| 41 | $this->addColumn( |
||
| 42 | $this->env->workerTableName, |
||
| 43 | 'pinged_at', |
||
| 44 | $this->integer()->notNull()->after('started_at') |
||
| 45 | ); |
||
| 46 | |||
| 47 | $query = (new Query())->from($this->env->workerTableName); |
||
| 48 | foreach ($query->all() as $row) { |
||
| 49 | $this->update( |
||
| 50 | $this->env->workerTableName, |
||
| 51 | ['pinged_at' => $row['finished_at'] ?: time()], |
||
| 52 | ['id' => $row['id']] |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | |||
| 56 | $this->addColumn( |
||
| 57 | $this->env->workerTableName, |
||
| 58 | 'stopped_at', |
||
| 59 | $this->integer()->after('pinged_at') |
||
| 60 | ); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @inheritdoc |
||
| 65 | */ |
||
| 66 | public function down() |
||
| 70 | } |
||
| 71 | } |
||
| 72 |