/** * setData constructor. * * @param \Aura\Web\Request $request * @param \Aura\Web\Response $response * @param \Aura\View\View $view */ public function __construct($request, $response, $view) { $status = 'success'; $message = 'Image saved successfully.'; $image = $request->files->get('file', ['error' => 1]); $secureToken = (new Config())->getConfig()['secure_token']; $retrievedSecureToken = $request->query->get('key', ''); if ($secureToken !== $retrievedSecureToken) { $status = 'error'; $message = 'Incorrect secure token'; } else { if ($image['error'] === 0) { $fileSystem = new Filesystem(); $tmpName = $image['tmp_name']; $path = '../storage/'; try { $fileSystem->copy($tmpName, $path . $image['name']); } catch (\Exception $e) { Log::addError('Image upload error: ' . $e->getMessage()); $status = 'error'; $message = 'Move image exception: ' . $e->getMessage(); } } else { Log::addError('Image upload error: ' . serialize($image)); $status = 'error'; $message = 'Image upload error'; } } $view->setData(['status' => $status, 'message' => $message]); $response->content->set($view->__invoke()); }
/** * create connection */ public function __construct() { if (is_null(self::$_connection)) { try { $dbConfig = Config::getConfig()['database']; self::$_connection = new ExtendedPdo("mysql:host={$dbConfig['host']};dbname={$dbConfig['database']};port={$dbConfig['port']}", $dbConfig['user'], $dbConfig['pass']); self::$_connection->connect(); } catch (\Exception $e) { Log::addError($e->getMessage(), 'db connection'); } } }
/** * Defines the way to update data in the database tables * @param $query * @param $queryParams * * @return bool */ public function updateData($query, $queryParams) { try { $this->objConn->beginTransaction(); $stmt = $this->objConn->prepare($query); $stmt->execute($queryParams); $this->objConn->commit(); return $stmt->rowCount(); } catch (PDOException $ex) { $this->objConn->rollBack(); Log\Log::writeLog($ex->getMessage(), EXCEPTION_PATH); return false; } }