Esempio n. 1
0
 /**
  * Update an AuthTicket. Note that every update to this record will always
  * reset the expires time to now + $this->_expireSeconds seconds.
  *
  * @param AuthTicketModel $model
  * @throws ControllerException
  * @return string authTicket on success
  * @SuppressWarnings indentation
  */
 public function update($model)
 {
     if ($model->validateForUpdate()) {
         try {
             $sql = 'UPDATE auth_ticket' . ' SET expires = ?' . ' WHERE auth_ticket = ?';
             $stmt = $this->_dbh->prepare($sql);
             if (!$stmt) {
                 throw new ControllerException('Prepared statement failed for ' . $sql);
             }
             $authTicket = $model->getAuthTicket();
             $expires = date('Y-m-d H:i:s', time() + $this->_expireSeconds);
             if (!$stmt->bind_param('ss', $expires, $authTicket)) {
                 throw new ControllerException('Binding parameters for prepared statement failed.');
             }
             if (!$stmt->execute()) {
                 throw new ControllerException('Failed to execute INSERT statement. Is this duplicate data? (' . $this->_dbh->error . ')');
             }
             /** @SuppressWarnings checkAliases */
             if (!$stmt->close()) {
                 throw new ControllerException('Something broke while trying to close the prepared statement.');
             }
             return $authTicket;
         } catch (Exception $e) {
             throw new ControllerException("Update failed." . $e->getMessage());
         }
     } else {
         throw new ControllerException('Invalid data');
     }
 }