/** * @param $dataSourceName * @param $bypassAuth * @return mixed */ public function createInDB($bypassAuth) { $currentDataSource = $this->dbSettings->getDataSourceTargetArray(); try { $className = get_class($this->userExpanded); // if ($this->userExpanded !== null && method_exists($this->userExpanded, "doBeforeNewToDB")) { // $this->logger->setDebugMessage("The method 'doBeforeNewToDB' of the class '{$className}' is calling.", 2); // $this->userExpanded->doBeforeNewToDB($dataSourceName); // } if ($this->userExpanded !== null && method_exists($this->userExpanded, "doBeforeCreateToDB")) { $this->logger->setDebugMessage("The method 'doBeforeCreateToDB' of the class '{$className}' is calling.", 2); $this->userExpanded->doBeforeCreateToDB(); } if ($this->dbClass !== null) { if (isset($currentDataSource['send-mail']['new']) || isset($currentDataSource['send-mail']['create']) || $this->dbSettings->notifyServer) { $this->dbClass->requireUpdatedRecord(true); } $result = $this->dbClass->createInDB($bypassAuth); } // if ($this->userExpanded !== null && method_exists($this->userExpanded, "doAfterNewToDB")) { // $this->logger->setDebugMessage("The method 'doAfterNewToDB' of the class '{$className}' is calling.", 2); // $result = $this->userExpanded->doAfterNewToDB($dataSourceName, $this->dbClass->updatedRecord()); // } if ($this->userExpanded !== null && method_exists($this->userExpanded, "doAfterCreateToDB")) { $this->logger->setDebugMessage("The method 'doAfterCreateToDB' of the class '{$className}' is calling.", 2); $result = $this->userExpanded->doAfterCreateToDB($this->dbClass->updatedRecord()); } if ($this->dbSettings->notifyServer && $this->clientPusherAvailable) { try { $this->dbSettings->notifyServer->created($_POST['notifyid'], $this->dbClass->queriedEntity(), $this->dbClass->queriedPrimaryKeys(), $this->dbClass->updatedRecord()); } catch (Exception $ex) { if ($ex->getMessage() == '_im_no_pusher_exception') { $this->logger->setErrorMessage("The 'Pusher.php' isn't installed on any valid directory."); } else { throw $ex; } } } if (isset($currentDataSource['send-mail']['new']) || isset($currentDataSource['send-mail']['create'])) { $this->logger->setDebugMessage("Try to send an email."); $mailSender = new SendMail(); if (isset($currentDataSource['send-mail']['new'])) { $dataSource = $currentDataSource['send-mail']['new']; } else { if (isset($currentDataSource['send-mail']['create'])) { $dataSource = $currentDataSource['send-mail']['create']; } } $mailResult = $mailSender->processing($dataSource, $this->dbClass->updatedRecord(), $this->dbSettings->getSmtpConfiguration()); if ($mailResult !== true) { $this->logger->setErrorMessage("Mail sending error: {$mailResult}"); } } } catch (Exception $e) { $this->logger->setErrorMessage("Exception: {$e->getMessage()}"); return false; } return $result; }