$fix->action->value, 'created_at' => $fix->created_at, 'new_url' => $fix->new_url, 'first_url' => $fix->first_url, 'links_total' => $fix->links_total(), 'link_ids' => $this->fix_json_columns->encode_link_ids( $fix->link_ids ), ); $id = $this->query_runner->insert( $this->tables->fixes(), array_merge( $columns, $this->progress_columns( $fix->progress ) ) ); return $fix->with_id( $id ); } public function find( int $id ): Fix|null { $row = $this->query_runner->row( $this->query_runner->prepare( 'SELECT * FROM ' . $this->tables->fixes() . ' WHERE id = %d', $id ) ); return null === $row ? null : $this->fix_row_mapper->to_fix( $row ); } public function save_progress( Fix $fix ): void { $this->query_runner->update( $this->tables->fixes(), $this->progress_columns( $fix->progress ), array( 'id' => $fix->id ) ); } /** @return list */ public function page( PageRequest $page_request ): array { $rows = $this->query_runner->rows( $this->query_runner->prepare( 'SELECT * FROM ' . $this->tables->fixes() . ' ORDER BY created_at DESC, id DESC LIMIT %d OFFSET %d', $page_request->per_page, $page_request->offset() ) ); $fixes = array(); foreach ( $rows as $row ) { $fixes[] = $this->fix_row_mapper->to_fix( $row ); } return $fixes; } public function count(): int { return (int) $this->query_runner->value( 'SELECT COUNT(*) FROM ' . $this->tables->fixes() ); } /** @return array */ private function progress_columns( FixProgress $progress ): array { return array( 'state' => $progress->state->value, 'links_done' => $progress->links_done, 'places_total' => $progress->places_total, 'places_done' => $progress->places_done, 'places_failed' => $progress->places_failed, 'journal' => $this->fix_json_columns->encode_journal( $progress->journal ), ); } }