| Total Complexity | 4 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | class M180222000000WorkerPing extends Migration |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @inheritdoc |
||
| 22 | */ |
||
| 23 | public function safeUp() |
||
| 24 | { |
||
| 25 | $this->addColumn( |
||
| 26 | $this->env->workerTableName, |
||
| 27 | 'pinged_at', |
||
| 28 | $this->integer()->notNull()->after('started_at') |
||
| 29 | ); |
||
| 30 | |||
| 31 | $time = $this->beginCommand("update {$this->env->workerTableName}"); |
||
| 32 | $this->compact = true; |
||
| 33 | $query = (new Query())->from($this->env->workerTableName); |
||
| 34 | foreach ($query->all($this->db) as $row) { |
||
| 35 | $this->update( |
||
| 36 | $this->env->workerTableName, |
||
| 37 | ['pinged_at' => $row['finished_at'] ?: time()], |
||
| 38 | ['id' => $row['id']] |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | $this->compact = false; |
||
| 42 | $this->endCommand($time); |
||
| 43 | |||
| 44 | $this->addColumn( |
||
| 45 | $this->env->workerTableName, |
||
| 46 | 'stopped_at', |
||
| 47 | $this->integer()->after('pinged_at') |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @inheritdoc |
||
| 53 | */ |
||
| 54 | public function safeDown() |
||
| 58 | } |
||
| 59 | } |
||
| 60 |