mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch 'email-scope' into 2.4
Merge of GH-1137 into 2.4
This commit is contained in:
commit
9cffb0b4c1
3 changed files with 46 additions and 6 deletions
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
App::uses('Set', 'Utility');
|
||||
App::uses('CakeLog', 'Log');
|
||||
|
||||
/**
|
||||
* Object class provides a few generic methods used in several subclasses.
|
||||
|
@ -151,12 +152,12 @@ class Object {
|
|||
* @param integer $type Error type constant. Defined in app/Config/core.php.
|
||||
* @return boolean Success of log write
|
||||
*/
|
||||
public function log($msg, $type = LOG_ERR) {
|
||||
App::uses('CakeLog', 'Log');
|
||||
public function log($msg, $type = LOG_ERR, $scope = null) {
|
||||
if (!is_string($msg)) {
|
||||
$msg = print_r($msg, true);
|
||||
}
|
||||
return CakeLog::write($type, $msg);
|
||||
|
||||
return CakeLog::write($type, $msg, $scope);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1065,11 +1065,21 @@ class CakeEmail {
|
|||
|
||||
$contents = $this->transportClass()->send($this);
|
||||
if (!empty($this->_config['log'])) {
|
||||
$level = LOG_DEBUG;
|
||||
$config = array(
|
||||
'level' => LOG_DEBUG,
|
||||
'scope' => 'email'
|
||||
);
|
||||
if ($this->_config['log'] !== true) {
|
||||
$level = $this->_config['log'];
|
||||
if (!is_array($this->_config['log'])) {
|
||||
$this->_config['log'] = array('level' => $this->_config['log']);
|
||||
}
|
||||
$config = array_merge($config, $this->_config['log']);
|
||||
}
|
||||
CakeLog::write($level, PHP_EOL . $contents['headers'] . PHP_EOL . $contents['message']);
|
||||
CakeLog::write(
|
||||
$config['level'],
|
||||
PHP_EOL . $contents['headers'] . PHP_EOL . $contents['message'],
|
||||
$config['scope']
|
||||
);
|
||||
}
|
||||
return $contents;
|
||||
}
|
||||
|
|
|
@ -1013,6 +1013,35 @@ class CakeEmailTest extends CakeTestCase {
|
|||
CakeLog::drop('email');
|
||||
}
|
||||
|
||||
/**
|
||||
* testSendWithLogAndScope method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSendWithLogAndScope() {
|
||||
CakeLog::config('email', array(
|
||||
'engine' => 'FileLog',
|
||||
'path' => TMP,
|
||||
'types' => array('cake_test_emails'),
|
||||
'scopes' => array('email')
|
||||
));
|
||||
CakeLog::drop('default');
|
||||
$this->CakeEmail->transport('Debug');
|
||||
$this->CakeEmail->to('me@cakephp.org');
|
||||
$this->CakeEmail->from('cake@cakephp.org');
|
||||
$this->CakeEmail->subject('My title');
|
||||
$this->CakeEmail->config(array('log' => array('level' => 'cake_test_emails', 'scope' => 'email')));
|
||||
$result = $this->CakeEmail->send("Logging This");
|
||||
|
||||
App::uses('File', 'Utility');
|
||||
$File = new File(TMP . 'cake_test_emails.log');
|
||||
$log = $File->read();
|
||||
$this->assertTrue(strpos($log, $result['headers']) !== false);
|
||||
$this->assertTrue(strpos($log, $result['message']) !== false);
|
||||
$File->delete();
|
||||
CakeLog::drop('email');
|
||||
}
|
||||
|
||||
/**
|
||||
* testSendRender method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue