@@ -32,24 +32,24 @@ discard block |
||
| 32 | 32 | protected $_datetime_string = ''; |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | - * where to write the error log to |
|
| 36 | - * |
|
| 37 | - * @type string $_error_log_dir |
|
| 35 | + * where to write the error log to |
|
| 36 | + * |
|
| 37 | + * @type string $_error_log_dir |
|
| 38 | 38 | */ |
| 39 | 39 | protected $_error_log_dir = ''; |
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param string $error_log_dir |
|
| 45 | - */ |
|
| 46 | - public function setErrorLogDir($error_log_dir) |
|
| 47 | - { |
|
| 48 | - // if the folder path is writable, then except the path + filename, else keep empty |
|
| 49 | - $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
|
| 50 | - ? $error_log_dir |
|
| 51 | - : ''; |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * @param string $error_log_dir |
|
| 45 | + */ |
|
| 46 | + public function setErrorLogDir($error_log_dir) |
|
| 47 | + { |
|
| 48 | + // if the folder path is writable, then except the path + filename, else keep empty |
|
| 49 | + $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
|
| 50 | + ? $error_log_dir |
|
| 51 | + : ''; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | |
@@ -61,73 +61,73 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | public function __sleep() { |
| 63 | 63 | $this->_datetime_string = $this->format( DbSafeDateTime::db_safe_timestamp_format ); |
| 64 | - $date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string); |
|
| 65 | - if ( ! $date instanceof \DateTime) { |
|
| 66 | - try { |
|
| 67 | - // we want a stack trace to determine where the malformed date came from, so... |
|
| 68 | - throw new \DomainException(); |
|
| 69 | - } catch (\DomainException $e) { |
|
| 70 | - $stack_trace = $e->getTraceAsString(); |
|
| 71 | - } |
|
| 72 | - $this->writeToErrorLog( |
|
| 73 | - sprintf( |
|
| 74 | - __( |
|
| 75 | - 'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s', |
|
| 76 | - 'event_espresso' |
|
| 77 | - ), |
|
| 78 | - $this->_datetime_string, |
|
| 79 | - '<br />', |
|
| 80 | - print_r(\DateTime::getLastErrors(), true), |
|
| 81 | - PHP_VERSION, |
|
| 82 | - $stack_trace |
|
| 83 | - ) |
|
| 84 | - ); |
|
| 85 | - } |
|
| 86 | - return array( '_datetime_string' ); |
|
| 64 | + $date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string); |
|
| 65 | + if ( ! $date instanceof \DateTime) { |
|
| 66 | + try { |
|
| 67 | + // we want a stack trace to determine where the malformed date came from, so... |
|
| 68 | + throw new \DomainException(); |
|
| 69 | + } catch (\DomainException $e) { |
|
| 70 | + $stack_trace = $e->getTraceAsString(); |
|
| 71 | + } |
|
| 72 | + $this->writeToErrorLog( |
|
| 73 | + sprintf( |
|
| 74 | + __( |
|
| 75 | + 'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s', |
|
| 76 | + 'event_espresso' |
|
| 77 | + ), |
|
| 78 | + $this->_datetime_string, |
|
| 79 | + '<br />', |
|
| 80 | + print_r(\DateTime::getLastErrors(), true), |
|
| 81 | + PHP_VERSION, |
|
| 82 | + $stack_trace |
|
| 83 | + ) |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | + return array( '_datetime_string' ); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | |
| 91 | 91 | public function __wakeup() { |
| 92 | - // if an empty or null value got saved to the db for a datetime, |
|
| 93 | - // then some servers and/or PHP itself will incorrectly convert that date string |
|
| 94 | - // resulting in "-0001-11-30" for the year-month-day. |
|
| 95 | - // We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
|
| 96 | - // but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
|
| 97 | - // so we're no better off, but at least things won't go fatal on us. |
|
| 98 | - $this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string); |
|
| 92 | + // if an empty or null value got saved to the db for a datetime, |
|
| 93 | + // then some servers and/or PHP itself will incorrectly convert that date string |
|
| 94 | + // resulting in "-0001-11-30" for the year-month-day. |
|
| 95 | + // We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
|
| 96 | + // but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
|
| 97 | + // so we're no better off, but at least things won't go fatal on us. |
|
| 98 | + $this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string); |
|
| 99 | 99 | $date = \DateTime::createFromFormat( DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string ); |
| 100 | 100 | if ( ! $date instanceof \DateTime) { |
| 101 | - $this->writeToErrorLog( |
|
| 102 | - sprintf( |
|
| 103 | - __( |
|
| 104 | - 'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s', |
|
| 105 | - 'event_espresso' |
|
| 106 | - ), |
|
| 107 | - $this->_datetime_string, |
|
| 108 | - '<br />', |
|
| 109 | - print_r(\DateTime::getLastErrors(), true), |
|
| 110 | - PHP_VERSION |
|
| 111 | - ) |
|
| 112 | - ); |
|
| 113 | - } else { |
|
| 114 | - $this->__construct( |
|
| 115 | - $date->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 116 | - new \DateTimeZone($date->format('e')) |
|
| 117 | - ); |
|
| 118 | - } |
|
| 101 | + $this->writeToErrorLog( |
|
| 102 | + sprintf( |
|
| 103 | + __( |
|
| 104 | + 'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s', |
|
| 105 | + 'event_espresso' |
|
| 106 | + ), |
|
| 107 | + $this->_datetime_string, |
|
| 108 | + '<br />', |
|
| 109 | + print_r(\DateTime::getLastErrors(), true), |
|
| 110 | + PHP_VERSION |
|
| 111 | + ) |
|
| 112 | + ); |
|
| 113 | + } else { |
|
| 114 | + $this->__construct( |
|
| 115 | + $date->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 116 | + new \DateTimeZone($date->format('e')) |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
| 122 | 122 | |
| 123 | - private function writeToErrorLog($message) |
|
| 124 | - { |
|
| 125 | - if ( ! empty($this->_error_log_dir)) { |
|
| 126 | - error_log($message, 3, $this->_error_log_dir); |
|
| 127 | - } else { |
|
| 128 | - error_log($message); |
|
| 129 | - } |
|
| 130 | - } |
|
| 123 | + private function writeToErrorLog($message) |
|
| 124 | + { |
|
| 125 | + if ( ! empty($this->_error_log_dir)) { |
|
| 126 | + error_log($message, 3, $this->_error_log_dir); |
|
| 127 | + } else { |
|
| 128 | + error_log($message); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | |
| 133 | 133 | } |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\core\domain\entities; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 5 | - exit( 'No direct script access allowed' ); |
|
| 4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -47,20 +47,20 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | // if the folder path is writable, then except the path + filename, else keep empty |
| 49 | 49 | $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
| 50 | - ? $error_log_dir |
|
| 50 | + ? $error_log_dir |
|
| 51 | 51 | : ''; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | |
| 56 | 56 | public function __toString() { |
| 57 | - return $this->format( DbSafeDateTime::db_safe_timestamp_format ); |
|
| 57 | + return $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | public function __sleep() { |
| 63 | - $this->_datetime_string = $this->format( DbSafeDateTime::db_safe_timestamp_format ); |
|
| 63 | + $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
| 64 | 64 | $date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string); |
| 65 | 65 | if ( ! $date instanceof \DateTime) { |
| 66 | 66 | try { |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | ) |
| 84 | 84 | ); |
| 85 | 85 | } |
| 86 | - return array( '_datetime_string' ); |
|
| 86 | + return array('_datetime_string'); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | // but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
| 97 | 97 | // so we're no better off, but at least things won't go fatal on us. |
| 98 | 98 | $this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string); |
| 99 | - $date = \DateTime::createFromFormat( DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string ); |
|
| 99 | + $date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string); |
|
| 100 | 100 | if ( ! $date instanceof \DateTime) { |
| 101 | 101 | $this->writeToErrorLog( |
| 102 | 102 | sprintf( |