Beispiel #1
0
 /**
  * Save or update worker
  * @param Worker $worker
  * @return Worker
  */
 public function saveWorker(Worker $worker)
 {
     if (is_null($worker->getId())) {
         $query = $this->db->prepare("INSERT INTO workers (host, port, type, status) VALUES (?, ?, ?, ?)");
         $query->execute([$worker->getHost(), $worker->getPort(), $worker->getType(), $worker->getStatus()]);
         $worker->setId($this->db->lastInsertId());
     } else {
         $query = $this->db->prepare("UPDATE workers SET host = ?, port = ?, type = ?, status = ? WHERE id = ?");
         $query->execute([$worker->getHost(), $worker->getPort(), $worker->getType(), $worker->getStatus(), $worker->getId()]);
     }
     return $worker;
 }