Permalink
Browse files

Merge pull request #1078

  • Loading branch information...
2 parents 7f4541e + c4dde90 commit 6cb15702825733829b51840d5288e19581598f56 @chillu chillu committed Jan 29, 2013
@@ -41,6 +41,7 @@
*
* Email:
* - SS_SEND_ALL_EMAILS_TO: If you set this define, all emails will be redirected to this address.
+ * - SS_SEND_ALL_EMAILS_FROM: If you set this define, all emails will be send from this address.
*
* @package framework
* @subpackage core
@@ -105,7 +106,10 @@
}
if(defined('SS_SEND_ALL_EMAILS_TO')) {
- Email::send_all_emails_to(SS_SEND_ALL_EMAILS_TO);
+ Config::inst()->update("Email","send_all_emails_to", SS_SEND_ALL_EMAILS_TO);
+}
+if(defined('SS_SEND_ALL_EMAILS_FROM')) {
+ Config::inst()->update("Email","send_all_emails_from", SS_SEND_ALL_EMAILS_FROM);
}
if(defined('SS_DEFAULT_ADMIN_USERNAME')) {
View
@@ -454,7 +454,7 @@ public function popCurrent() {
public function redirect($url, $code=302) {
if(!$this->response) $this->response = new SS_HTTPResponse();
- if($this->response->getHeader('Location')) {
+ if($this->response->getHeader('Location') && $this->response->getHeader('Location') != $url) {
user_error("Already directed to " . $this->response->getHeader('Location')
. "; now trying to direct to $url", E_USER_WARNING);
return;
View
@@ -725,6 +725,9 @@ public static function forceSSL($patterns = null) {
$matched = false;
if($patterns) {
+ // Calling from the command-line?
+ if(!isset($_SERVER['REQUEST_URI'])) return;
+
// protect portions of the site based on the pattern
$relativeURL = self::makeRelative(Director::absoluteURL($_SERVER['REQUEST_URI']));
foreach($patterns as $pattern) {
View
@@ -220,11 +220,17 @@ public function output() {
<meta http-equiv=\"refresh\" content=\"1; url=$url\" />
<script type=\"text/javascript\">setTimeout('window.location.href = \"$url\"', 50);</script>";
} else {
- if(!headers_sent()) {
+ $line = $file = null;
+ if(!headers_sent($file, $line)) {
header($_SERVER['SERVER_PROTOCOL'] . " $this->statusCode " . $this->getStatusDescription());
foreach($this->headers as $header => $value) {
header("$header: $value", true, $this->statusCode);
}
+ } else {
+ // It's critical that these status codes are sent; we need to report a failure if not.
+ if($this->statusCode >= 300) {
+ user_error("Couldn't set response type to $this->statusCode because of output on line $line of $file", E_USER_WARNING);
+ }
}
// Only show error pages or generic "friendly" errors if the status code signifies
View
@@ -415,7 +415,7 @@ public function inst_save() {
protected function recursivelyApply($data, &$dest) {
foreach($data as $k => $v) {
if(is_array($v)) {
- if(!isset($dest[$k])) $dest[$k] = array();
+ if(!isset($dest[$k]) || !is_array($dest[$k])) $dest[$k] = array();
$this->recursivelyApply($v, $dest[$k]);
} else {
$dest[$k] = $v;
View
@@ -213,6 +213,7 @@ public static function loadErrorHandlers() {
public static function noticeHandler($errno, $errstr, $errfile, $errline, $errcontext) {
if(error_reporting() == 0) return;
+ ini_set('display_errors', 0);
// Send out the error details to the logger for writing
SS_Log::log(
@@ -227,7 +228,9 @@ public static function noticeHandler($errno, $errstr, $errfile, $errline, $errco
);
if(Director::isDev()) {
- self::showError($errno, $errstr, $errfile, $errline, $errcontext, "Notice");
+ return self::showError($errno, $errstr, $errfile, $errline, $errcontext, "Notice");
+ } else {
+ return false;
}
}
@@ -242,8 +245,10 @@ public static function noticeHandler($errno, $errstr, $errfile, $errline, $errco
*/
public static function warningHandler($errno, $errstr, $errfile, $errline, $errcontext) {
if(error_reporting() == 0) return;
+ ini_set('display_errors', 0);
+
if(self::$send_warnings_to) {
- self::emailError(self::$send_warnings_to, $errno, $errstr, $errfile, $errline, $errcontext, "Warning");
+ return self::emailError(self::$send_warnings_to, $errno, $errstr, $errfile, $errline, $errcontext, "Warning");
}
// Send out the error details to the logger for writing
@@ -263,8 +268,10 @@ public static function warningHandler($errno, $errstr, $errfile, $errline, $errc
}
if(Director::isDev()) {
- self::showError($errno, $errstr, $errfile, $errline, $errcontext, "Warning");
- }
+ return self::showError($errno, $errstr, $errfile, $errline, $errcontext, "Warning");
+ } else {
+ return false;
+ }
}
/**
@@ -279,6 +286,8 @@ public static function warningHandler($errno, $errstr, $errfile, $errline, $errc
* @param unknown_type $errcontext
*/
public static function fatalHandler($errno, $errstr, $errfile, $errline, $errcontext) {
+ ini_set('display_errors', 0);
+
if(self::$send_errors_to) {
self::emailError(self::$send_errors_to, $errno, $errstr, $errfile, $errline, $errcontext, "Error");
}
@@ -300,11 +309,10 @@ public static function fatalHandler($errno, $errstr, $errfile, $errline, $errcon
}
if(Director::isDev() || Director::is_cli()) {
- self::showError($errno, $errstr, $errfile, $errline, $errcontext, "Error");
+ return self::showError($errno, $errstr, $errfile, $errline, $errcontext, "Error");
} else {
- self::friendlyError();
+ return self::friendlyError();
}
- exit(1);
}
/**
@@ -363,6 +371,7 @@ class_exists('Translatable') ? Translatable::get_current_locale() : null
$renderer->writeFooter();
}
}
+ return false;
}
/**
@@ -652,7 +661,7 @@ public static function require_developer_login() {
$_SESSION['Security']['Message']['type'] = 'warning';
$_SESSION['BackURL'] = $_SERVER['REQUEST_URI'];
header($_SERVER['SERVER_PROTOCOL'] . " 302 Found");
- header("Location: " . Director::baseURL() . "Security/login");
+ header("Location: " . Director::baseURL() . Security::login_url());
die();
}
}
@@ -679,7 +688,7 @@ function exceptionHandler($exception) {
$file = $exception->getFile();
$line = $exception->getLine();
$context = $exception->getTrace();
- Debug::fatalHandler($errno, $message, $file, $line, $context);
+ return Debug::fatalHandler($errno, $message, $file, $line, $context);
}
/**
@@ -698,21 +707,18 @@ function errorHandler($errno, $errstr, $errfile, $errline) {
case E_ERROR:
case E_CORE_ERROR:
case E_USER_ERROR:
- Debug::fatalHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
- break;
+ return Debug::fatalHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
case E_WARNING:
case E_CORE_WARNING:
case E_USER_WARNING:
- Debug::warningHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
- break;
+ return Debug::warningHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
case E_NOTICE:
case E_USER_NOTICE:
case E_DEPRECATED:
case E_USER_DEPRECATED:
case E_STRICT:
- Debug::noticeHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
- break;
+ return Debug::noticeHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
}
}
View
@@ -205,7 +205,15 @@ public function setUp() {
$className = get_class($this);
$fixtureFile = eval("return {$className}::\$fixture_file;");
+
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
+
+ // Set up email
+ $this->originalMailer = Email::mailer();
+ $this->mailer = new TestMailer();
+ Email::set_mailer($this->mailer);
+ Config::inst()->remove('Email', 'send_all_emails_to');
+ Email::send_all_emails_to(null);
// Todo: this could be a special test model
$this->model = DataModel::inst();
@@ -259,12 +267,6 @@ public function setUp() {
$this->logInWithPermission("ADMIN");
}
- // Set up email
- $this->originalMailer = Email::mailer();
- $this->mailer = new TestMailer();
- Email::set_mailer($this->mailer);
- Email::send_all_emails_to(null);
-
// Preserve memory settings
$this->originalMemoryLimit = ini_get('memory_limit');
View
@@ -96,8 +96,12 @@ public function submitForm($formID, $button = null, $data = array()) {
$form->setField(new SimpleByName($k), $v);
}
- if($button) $submission = $form->submitButton(new SimpleByName($button));
- else $submission = $form->submit();
+ if($button) {
+ $submission = $form->submitButton(new SimpleByName($button));
+ if(!$submission) throw new Exception("Can't find button '$button' to submit as part of test.");
+ } else {
+ $submission = $form->submit();
+ }
$url = Director::makeRelative($form->getAction()->asString());
@@ -137,6 +141,15 @@ public function lastResponse() {
return $this->lastResponse;
}
+ /**
+ * Return the fake HTTP_REFERER; set each time get() or post() is called.
+ *
+ * @return string
+ */
+ public function lastUrl() {
+ return $this->lastUrl;
+ }
+
/**
* Get the most recent response's content
*/
Oops, something went wrong.

0 comments on commit 6cb1570

Please sign in to comment.