/** * Do actual e-mail test by sending the e-mail to the given e-mail address * @return \Bootstrap\Response\Form */ public function testEmailAjax() { $validator = Validator::create(array('to' => 'required|email')); if ($validator->failed()) { return BootstrapUI::formResponse()->failedOn($validator); } if (!Mail::isEnabled()) { return BootstrapUI::formResponse()->message('Mail sender is not enabled!'); } $params = $validator->getParamsObj(); $mail = Mail::create()->from('no-replay@' . Request::hostNameDomain(), Request::hostName())->to($params->to)->subject('Configuration test mail')->body("If you got this e-mail, then your mail configuration is just fine!\n\n" . Url::current()); try { if ($mail->send()) { Log::info("Test e-mail is sent to {$params->to}"); return BootstrapUI::formResponse()->message('Test e-mail is sent!'); } } catch (Exception $e) { Log::info("Couldn\\'t send test e-mail to {$params->to}"); Log::exception($e); // we'll log this if needed, just to make sure it won't be forgotten return BootstrapUI::formResponse()->failed('E-mail wasn\'t sent:<br/>' . $e->getMessage()); // show user the actual error } }
/** * Insert archive metas * @param array $metas */ public function insertMeta(array $metas) { $ok = array('report_id', 'environment', 'build', 'settings_global', 'settings_system', 'settings_secure', 'device_features', 'shared_preferences', 'initial_configuration', 'crash_configuration', 'dumpsys_meminfo', 'display', 'stack_trace', 'logcat', 'tktal_mem_size', '@evice_features', 'installation_id', 'file_path', 'dropbox', 'is_silent', 'custom_data'); foreach ($metas as $key => $value) { if (in_array($key, $ok)) { // first, insert into meta_archive to get last ID try { $meta = Meta::create(array('crash_id' => $this->id, 'name' => $key, 'value' => $value)); } catch (\Exception $e) { Log::error("Can not insert meta for={$this->id} key={$key} value={$value}"); Log::exception($e); \Status::setCalculationStatus('Died. Failed on meta table'); exit(1); } } else { // key is not recognized, but we'll still write it in database try { UnknownMeta::create(array('report_id' => $this->id, 'meta_name' => $key, 'meta_value' => $value)); } catch (\Exception $e) { Log::error("Can not insert unknown meta report_id={$this->id} meta_name={$key} meta_value={$value}"); Log::exception($e); \Status::setCalculationStatus('Died. Failed on unknown meta table'); exit(1); } } } }
/** * The PDO will be initialized only if needed, not on adapter initialization * * @return PDO */ public function getAdapter() { if ($this->pdo === null) { try { $this->tryConnect($this->config); } catch (PDOException $e) { $this->lastException = $e; $this->lastError = $e->getMessage(); $this->pdo = null; if (isset($this->config['backup_connections']) && is_array($this->config['backup_connections'])) { $sizeof = count($this->config['backup_connections']); for ($i = 0; $i < $sizeof && $this->pdo === null; $i++) { $config = $this->config['backup_connections'][$i]; if (isset($config['log_error']) && $config['log_error'] === true) { Log::error("Error connecting to primary database connection on key={$this->configKey}, will now try backup_connection #{$i} {$config['username']}@{$config['host']}"); Log::exception($e); // log exception and continue } else { Log::notice("Error connecting to primary database connection on key={$this->configKey}, will now try backup_connection #{$i} {$config['username']}@{$config['host']}"); } $this->pdo = null; if (isset($config['wait_before_connect'])) { usleep($config['wait_before_connect'] * 1000); } try { $this->tryConnect($config); Log::notice("Connected to backup connection #{$i} ({$config['type']}:{$config['username']}@{$config['host']})"); } catch (PDOException $e) { $this->lastException = $e; $this->lastError = $e->getMessage(); $this->pdo = null; } } } if ($this->pdo === null) { throw new Exception('Error connecting to database'); } } } return $this->pdo; }
/** * If your app throws any kind of exception, it will end up here, so, handle it! * * @param \Exception $e */ public function handleException(\Exception $e) { if (!headers_sent()) { header('HTTP/1.1 503 Service Temporarily Unavailable', true, 503); header('Status: 503 Service Temporarily Unavailable'); header('Retry-After: 300'); // 300 seconds / 5 minutes } if ($this->isAjax()) { Json::create(array('success' => false, 'type' => 'exception', 'exception' => Application::inDevelopment() ? $e->getMessage() : null, 'trace' => Application::inDevelopment() ? $e->getTraceAsString() : null))->flush(); } else { $file503 = Application::getPublicPath('503.php'); if (is_file($file503)) { $code = 503; $message = $e->getMessage(); $exception = $e; include $file503; } else { if (Application::inDevelopment()) { echo "<strong>{$e->getMessage()}</strong><pre>{$e->getTraceAsString()}</pre>"; } else { echo "<h1>Error</h1><p>Something went wrong. Please try again later!</p>"; } } } Log::exception($e); }