/** * Calculate and set last and next run */ public function setLastAndNextRun() { // set lastRun, lastSuccess $this->lastRun = new DateTime(); $this->nextRun = null; // find nextTime to run foreach ($this->conditions as $condition) { $nextRun = $condition->getNextRunTime($this->lastRun); // if nextRun less than lastRun set lastRun + 1min if ($nextRun < $this->lastRun) { $nextRun = $this->lastRun->add(new \DateInterval("PT1M")); } if ($this->nextRun) { $this->nextRun = $this->nextRun > $nextRun ? $nextRun : $this->nextRun; } else { $this->nextRun = $nextRun; } } }
/** * Generate token for change password. * * @param string $email * * @return string|false */ public function resetPasswordToken($email) { $user = $this->userRepository->findOneBy(["email" => $email]); // userExist? if ($user) { $tokenExpires = new DateTime(); $tokenExpires->add(new \DateInterval('PT60M')); // 60 min for expire $token = $this->userRepository->resetPasswordToken($user, $tokenExpires); return $token ? $token : false; } else { return false; } }
/** * Lock table for read only and set task state to running (State = 1) * * @param Task $task * * @return bool */ public function setStateRunning(Task $task) { $table = $this->getTable(); if ($task->maxExecutionTimeInSecond) { $exceedDateTime = new Nette\Utils\DateTime(); $task->exceedDateTime = $exceedDateTime->add(new \DateInterval("PT" . $task->maxExecutionTimeInSecond . "S")); } $cnt = $table->where("TaskID", $task->id)->where("State", $task->state)->update(["State" => 1, "ExceedDateTime" => $task->exceedDateTime]); if ($cnt > 0) { $task->state = 1; } return $cnt > 0; }