@@ -14,2524 +14,2524 @@ discard block |
||
| 14 | 14 | final class EE_Config implements ResettableInterface |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const OPTION_NAME = 'ee_config'; |
|
| 18 | - |
|
| 19 | - const LOG_NAME = 'ee_config_log'; |
|
| 20 | - |
|
| 21 | - const LOG_LENGTH = 100; |
|
| 22 | - |
|
| 23 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * instance of the EE_Config object |
|
| 27 | - * |
|
| 28 | - * @var EE_Config $_instance |
|
| 29 | - * @access private |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var boolean $_logging_enabled |
|
| 35 | - */ |
|
| 36 | - private static $_logging_enabled = false; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | - */ |
|
| 41 | - private $legacy_shortcodes_manager; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * An StdClass whose property names are addon slugs, |
|
| 45 | - * and values are their config classes |
|
| 46 | - * |
|
| 47 | - * @var StdClass |
|
| 48 | - */ |
|
| 49 | - public $addons; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var EE_Admin_Config |
|
| 53 | - */ |
|
| 54 | - public $admin; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var EE_Core_Config |
|
| 58 | - */ |
|
| 59 | - public $core; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var EE_Currency_Config |
|
| 63 | - */ |
|
| 64 | - public $currency; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var EE_Organization_Config |
|
| 68 | - */ |
|
| 69 | - public $organization; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var EE_Registration_Config |
|
| 73 | - */ |
|
| 74 | - public $registration; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var EE_Template_Config |
|
| 78 | - */ |
|
| 79 | - public $template_settings; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Holds EE environment values. |
|
| 83 | - * |
|
| 84 | - * @var EE_Environment_Config |
|
| 85 | - */ |
|
| 86 | - public $environment; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * settings pertaining to Google maps |
|
| 90 | - * |
|
| 91 | - * @var EE_Map_Config |
|
| 92 | - */ |
|
| 93 | - public $map_settings; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * settings pertaining to Taxes |
|
| 97 | - * |
|
| 98 | - * @var EE_Tax_Config |
|
| 99 | - */ |
|
| 100 | - public $tax_settings; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Settings pertaining to global messages settings. |
|
| 104 | - * |
|
| 105 | - * @var EE_Messages_Config |
|
| 106 | - */ |
|
| 107 | - public $messages; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated |
|
| 111 | - * @var EE_Gateway_Config |
|
| 112 | - */ |
|
| 113 | - public $gateway; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var array $_addon_option_names |
|
| 117 | - * @access private |
|
| 118 | - */ |
|
| 119 | - private $_addon_option_names = array(); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @var array $_module_route_map |
|
| 123 | - * @access private |
|
| 124 | - */ |
|
| 125 | - private static $_module_route_map = array(); |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @var array $_module_forward_map |
|
| 129 | - * @access private |
|
| 130 | - */ |
|
| 131 | - private static $_module_forward_map = array(); |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @var array $_module_view_map |
|
| 135 | - * @access private |
|
| 136 | - */ |
|
| 137 | - private static $_module_view_map = array(); |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @singleton method used to instantiate class object |
|
| 142 | - * @access public |
|
| 143 | - * @return EE_Config instance |
|
| 144 | - */ |
|
| 145 | - public static function instance() |
|
| 146 | - { |
|
| 147 | - // check if class object is instantiated, and instantiated properly |
|
| 148 | - if (! self::$_instance instanceof EE_Config) { |
|
| 149 | - self::$_instance = new self(); |
|
| 150 | - } |
|
| 151 | - return self::$_instance; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Resets the config |
|
| 157 | - * |
|
| 158 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | - * reflect its state in the database |
|
| 161 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | - * site was put into maintenance mode) |
|
| 165 | - * @return EE_Config |
|
| 166 | - */ |
|
| 167 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | - { |
|
| 169 | - if (self::$_instance instanceof EE_Config) { |
|
| 170 | - if ($hard_reset) { |
|
| 171 | - self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | - self::$_instance->_addon_option_names = array(); |
|
| 173 | - self::$_instance->_initialize_config(); |
|
| 174 | - self::$_instance->update_espresso_config(); |
|
| 175 | - } |
|
| 176 | - self::$_instance->update_addon_option_names(); |
|
| 177 | - } |
|
| 178 | - self::$_instance = null; |
|
| 179 | - // we don't need to reset the static properties imo because those should |
|
| 180 | - // only change when a module is added or removed. Currently we don't |
|
| 181 | - // support removing a module during a request when it previously existed |
|
| 182 | - if ($reinstantiate) { |
|
| 183 | - return self::instance(); |
|
| 184 | - } else { |
|
| 185 | - return null; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * class constructor |
|
| 192 | - * |
|
| 193 | - * @access private |
|
| 194 | - */ |
|
| 195 | - private function __construct() |
|
| 196 | - { |
|
| 197 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | - // setup empty config classes |
|
| 200 | - $this->_initialize_config(); |
|
| 201 | - // load existing EE site settings |
|
| 202 | - $this->_load_core_config(); |
|
| 203 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | - $this->_verify_config(); |
|
| 205 | - // register shortcodes and modules |
|
| 206 | - add_action( |
|
| 207 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | - array($this, 'register_shortcodes_and_modules'), |
|
| 209 | - 999 |
|
| 210 | - ); |
|
| 211 | - // initialize shortcodes and modules |
|
| 212 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | - // register widgets |
|
| 214 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | - // shutdown |
|
| 216 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | - // construct__end hook |
|
| 218 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | - // hardcoded hack |
|
| 220 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @return boolean |
|
| 226 | - */ |
|
| 227 | - public static function logging_enabled() |
|
| 228 | - { |
|
| 229 | - return self::$_logging_enabled; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * use to get the current theme if needed from static context |
|
| 235 | - * |
|
| 236 | - * @return string current theme set. |
|
| 237 | - */ |
|
| 238 | - public static function get_current_theme() |
|
| 239 | - { |
|
| 240 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * _initialize_config |
|
| 247 | - * |
|
| 248 | - * @access private |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - private function _initialize_config() |
|
| 252 | - { |
|
| 253 | - EE_Config::trim_log(); |
|
| 254 | - // set defaults |
|
| 255 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | - $this->addons = new stdClass(); |
|
| 257 | - // set _module_route_map |
|
| 258 | - EE_Config::$_module_route_map = array(); |
|
| 259 | - // set _module_forward_map |
|
| 260 | - EE_Config::$_module_forward_map = array(); |
|
| 261 | - // set _module_view_map |
|
| 262 | - EE_Config::$_module_view_map = array(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * load core plugin configuration |
|
| 268 | - * |
|
| 269 | - * @access private |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - private function _load_core_config() |
|
| 273 | - { |
|
| 274 | - // load_core_config__start hook |
|
| 275 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | - $espresso_config = $this->get_espresso_config(); |
|
| 277 | - foreach ($espresso_config as $config => $settings) { |
|
| 278 | - // load_core_config__start hook |
|
| 279 | - $settings = apply_filters( |
|
| 280 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | - $settings, |
|
| 282 | - $config, |
|
| 283 | - $this |
|
| 284 | - ); |
|
| 285 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | - // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | - if (method_exists($settings, 'populate')) { |
|
| 289 | - $this->{$config}->populate(); |
|
| 290 | - } |
|
| 291 | - if (method_exists($settings, 'do_hooks')) { |
|
| 292 | - $this->{$config}->do_hooks(); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | - $this->update_espresso_config(); |
|
| 298 | - } |
|
| 299 | - // load_core_config__end hook |
|
| 300 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * _verify_config |
|
| 306 | - * |
|
| 307 | - * @access protected |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - protected function _verify_config() |
|
| 311 | - { |
|
| 312 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | - ? $this->core |
|
| 314 | - : new EE_Core_Config(); |
|
| 315 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | - ? $this->organization |
|
| 318 | - : new EE_Organization_Config(); |
|
| 319 | - $this->organization = apply_filters( |
|
| 320 | - 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | - $this->organization |
|
| 322 | - ); |
|
| 323 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | - ? $this->currency |
|
| 325 | - : new EE_Currency_Config(); |
|
| 326 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | - ? $this->registration |
|
| 329 | - : new EE_Registration_Config(); |
|
| 330 | - $this->registration = apply_filters( |
|
| 331 | - 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | - $this->registration |
|
| 333 | - ); |
|
| 334 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | - ? $this->admin |
|
| 336 | - : new EE_Admin_Config(); |
|
| 337 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | - ? $this->template_settings |
|
| 340 | - : new EE_Template_Config(); |
|
| 341 | - $this->template_settings = apply_filters( |
|
| 342 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | - $this->template_settings |
|
| 344 | - ); |
|
| 345 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | - ? $this->map_settings |
|
| 347 | - : new EE_Map_Config(); |
|
| 348 | - $this->map_settings = apply_filters( |
|
| 349 | - 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | - $this->map_settings |
|
| 351 | - ); |
|
| 352 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | - ? $this->environment |
|
| 354 | - : new EE_Environment_Config(); |
|
| 355 | - $this->environment = apply_filters( |
|
| 356 | - 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | - $this->environment |
|
| 358 | - ); |
|
| 359 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | - ? $this->tax_settings |
|
| 361 | - : new EE_Tax_Config(); |
|
| 362 | - $this->tax_settings = apply_filters( |
|
| 363 | - 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | - $this->tax_settings |
|
| 365 | - ); |
|
| 366 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | - ? $this->messages |
|
| 369 | - : new EE_Messages_Config(); |
|
| 370 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | - ? $this->gateway |
|
| 372 | - : new EE_Gateway_Config(); |
|
| 373 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | - $this->legacy_shortcodes_manager = null; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * get_espresso_config |
|
| 380 | - * |
|
| 381 | - * @access public |
|
| 382 | - * @return array of espresso config stuff |
|
| 383 | - */ |
|
| 384 | - public function get_espresso_config() |
|
| 385 | - { |
|
| 386 | - // grab espresso configuration |
|
| 387 | - return apply_filters( |
|
| 388 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * double_check_config_comparison |
|
| 396 | - * |
|
| 397 | - * @access public |
|
| 398 | - * @param string $option |
|
| 399 | - * @param $old_value |
|
| 400 | - * @param $value |
|
| 401 | - */ |
|
| 402 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | - { |
|
| 404 | - // make sure we're checking the ee config |
|
| 405 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | - if ($value != $old_value) { |
|
| 409 | - // if they are NOT the same, then remove the hook, |
|
| 410 | - // which means the subsequent update results will be based solely on the update query results |
|
| 411 | - // the reason we do this is because, as stated above, |
|
| 412 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | - // If values are found to match their previous old value, |
|
| 415 | - // then WP bails before performing any update. |
|
| 416 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | - // MySQL MAY ALSO NOT perform the update because |
|
| 420 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * update_espresso_config |
|
| 431 | - * |
|
| 432 | - * @access public |
|
| 433 | - */ |
|
| 434 | - protected function _reset_espresso_addon_config() |
|
| 435 | - { |
|
| 436 | - $this->_addon_option_names = array(); |
|
| 437 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | - } |
|
| 442 | - $this->addons->{$addon_name} = null; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * update_espresso_config |
|
| 449 | - * |
|
| 450 | - * @access public |
|
| 451 | - * @param bool $add_success |
|
| 452 | - * @param bool $add_error |
|
| 453 | - * @return bool |
|
| 454 | - */ |
|
| 455 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | - { |
|
| 457 | - // don't allow config updates during WP heartbeats |
|
| 458 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | - return false; |
|
| 460 | - } |
|
| 461 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | - // $clone = clone( self::$_instance ); |
|
| 463 | - // self::$_instance = NULL; |
|
| 464 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | - $this->_reset_espresso_addon_config(); |
|
| 466 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | - // but BEFORE the actual update occurs |
|
| 468 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | - $this->legacy_shortcodes_manager = null; |
|
| 472 | - // now update "ee_config" |
|
| 473 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | - // if not saved... check if the hook we just added still exists; |
|
| 477 | - // if it does, it means one of two things: |
|
| 478 | - // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | - // or... |
|
| 480 | - // the db update query returned 0 rows affected |
|
| 481 | - // (probably because the data value was the same from it's perspective) |
|
| 482 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | - // but just means no update occurred, so don't display an error to the user. |
|
| 484 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | - // then it means that something truly went wrong |
|
| 486 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | - // remove our action since we don't want it in the system anymore |
|
| 488 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | - // self::$_instance = $clone; |
|
| 491 | - // unset( $clone ); |
|
| 492 | - // if config remains the same or was updated successfully |
|
| 493 | - if ($saved) { |
|
| 494 | - if ($add_success) { |
|
| 495 | - EE_Error::add_success( |
|
| 496 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | - __FILE__, |
|
| 498 | - __FUNCTION__, |
|
| 499 | - __LINE__ |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - return true; |
|
| 503 | - } else { |
|
| 504 | - if ($add_error) { |
|
| 505 | - EE_Error::add_error( |
|
| 506 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | - __FILE__, |
|
| 508 | - __FUNCTION__, |
|
| 509 | - __LINE__ |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * _verify_config_params |
|
| 519 | - * |
|
| 520 | - * @access private |
|
| 521 | - * @param string $section |
|
| 522 | - * @param string $name |
|
| 523 | - * @param string $config_class |
|
| 524 | - * @param EE_Config_Base $config_obj |
|
| 525 | - * @param array $tests_to_run |
|
| 526 | - * @param bool $display_errors |
|
| 527 | - * @return bool TRUE on success, FALSE on fail |
|
| 528 | - */ |
|
| 529 | - private function _verify_config_params( |
|
| 530 | - $section = '', |
|
| 531 | - $name = '', |
|
| 532 | - $config_class = '', |
|
| 533 | - $config_obj = null, |
|
| 534 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | - $display_errors = true |
|
| 536 | - ) { |
|
| 537 | - try { |
|
| 538 | - foreach ($tests_to_run as $test) { |
|
| 539 | - switch ($test) { |
|
| 540 | - // TEST #1 : check that section was set |
|
| 541 | - case 1: |
|
| 542 | - if (empty($section)) { |
|
| 543 | - if ($display_errors) { |
|
| 544 | - throw new EE_Error( |
|
| 545 | - sprintf( |
|
| 546 | - __( |
|
| 547 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | - 'event_espresso' |
|
| 549 | - ), |
|
| 550 | - $config_class |
|
| 551 | - ) |
|
| 552 | - ); |
|
| 553 | - } |
|
| 554 | - return false; |
|
| 555 | - } |
|
| 556 | - break; |
|
| 557 | - // TEST #2 : check that settings section exists |
|
| 558 | - case 2: |
|
| 559 | - if (! isset($this->{$section})) { |
|
| 560 | - if ($display_errors) { |
|
| 561 | - throw new EE_Error( |
|
| 562 | - sprintf( |
|
| 563 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | - $section |
|
| 565 | - ) |
|
| 566 | - ); |
|
| 567 | - } |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - break; |
|
| 571 | - // TEST #3 : check that section is the proper format |
|
| 572 | - case 3: |
|
| 573 | - if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | - ) { |
|
| 575 | - if ($display_errors) { |
|
| 576 | - throw new EE_Error( |
|
| 577 | - sprintf( |
|
| 578 | - __( |
|
| 579 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 580 | - 'event_espresso' |
|
| 581 | - ), |
|
| 582 | - $section |
|
| 583 | - ) |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - return false; |
|
| 587 | - } |
|
| 588 | - break; |
|
| 589 | - // TEST #4 : check that config section name has been set |
|
| 590 | - case 4: |
|
| 591 | - if (empty($name)) { |
|
| 592 | - if ($display_errors) { |
|
| 593 | - throw new EE_Error( |
|
| 594 | - __( |
|
| 595 | - 'No name has been provided for the specific configuration section.', |
|
| 596 | - 'event_espresso' |
|
| 597 | - ) |
|
| 598 | - ); |
|
| 599 | - } |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - break; |
|
| 603 | - // TEST #5 : check that a config class name has been set |
|
| 604 | - case 5: |
|
| 605 | - if (empty($config_class)) { |
|
| 606 | - if ($display_errors) { |
|
| 607 | - throw new EE_Error( |
|
| 608 | - __( |
|
| 609 | - 'No class name has been provided for the specific configuration section.', |
|
| 610 | - 'event_espresso' |
|
| 611 | - ) |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - return false; |
|
| 615 | - } |
|
| 616 | - break; |
|
| 617 | - // TEST #6 : verify config class is accessible |
|
| 618 | - case 6: |
|
| 619 | - if (! class_exists($config_class)) { |
|
| 620 | - if ($display_errors) { |
|
| 621 | - throw new EE_Error( |
|
| 622 | - sprintf( |
|
| 623 | - __( |
|
| 624 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 625 | - 'event_espresso' |
|
| 626 | - ), |
|
| 627 | - $config_class |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - return false; |
|
| 632 | - } |
|
| 633 | - break; |
|
| 634 | - // TEST #7 : check that config has even been set |
|
| 635 | - case 7: |
|
| 636 | - if (! isset($this->{$section}->{$name})) { |
|
| 637 | - if ($display_errors) { |
|
| 638 | - throw new EE_Error( |
|
| 639 | - sprintf( |
|
| 640 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 641 | - $section, |
|
| 642 | - $name |
|
| 643 | - ) |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - return false; |
|
| 647 | - } else { |
|
| 648 | - // and make sure it's not serialized |
|
| 649 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 650 | - } |
|
| 651 | - break; |
|
| 652 | - // TEST #8 : check that config is the requested type |
|
| 653 | - case 8: |
|
| 654 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | - if ($display_errors) { |
|
| 656 | - throw new EE_Error( |
|
| 657 | - sprintf( |
|
| 658 | - __( |
|
| 659 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 660 | - 'event_espresso' |
|
| 661 | - ), |
|
| 662 | - $section, |
|
| 663 | - $name, |
|
| 664 | - $config_class |
|
| 665 | - ) |
|
| 666 | - ); |
|
| 667 | - } |
|
| 668 | - return false; |
|
| 669 | - } |
|
| 670 | - break; |
|
| 671 | - // TEST #9 : verify config object |
|
| 672 | - case 9: |
|
| 673 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | - if ($display_errors) { |
|
| 675 | - throw new EE_Error( |
|
| 676 | - sprintf( |
|
| 677 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 678 | - print_r($config_obj, true) |
|
| 679 | - ) |
|
| 680 | - ); |
|
| 681 | - } |
|
| 682 | - return false; |
|
| 683 | - } |
|
| 684 | - break; |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - } catch (EE_Error $e) { |
|
| 688 | - $e->get_error(); |
|
| 689 | - } |
|
| 690 | - // you have successfully run the gauntlet |
|
| 691 | - return true; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * _generate_config_option_name |
|
| 697 | - * |
|
| 698 | - * @access protected |
|
| 699 | - * @param string $section |
|
| 700 | - * @param string $name |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 704 | - { |
|
| 705 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * _set_config_class |
|
| 711 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 712 | - * |
|
| 713 | - * @access private |
|
| 714 | - * @param string $config_class |
|
| 715 | - * @param string $name |
|
| 716 | - * @return string |
|
| 717 | - */ |
|
| 718 | - private function _set_config_class($config_class = '', $name = '') |
|
| 719 | - { |
|
| 720 | - return ! empty($config_class) |
|
| 721 | - ? $config_class |
|
| 722 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * set_config |
|
| 728 | - * |
|
| 729 | - * @access protected |
|
| 730 | - * @param string $section |
|
| 731 | - * @param string $name |
|
| 732 | - * @param string $config_class |
|
| 733 | - * @param EE_Config_Base $config_obj |
|
| 734 | - * @return EE_Config_Base |
|
| 735 | - */ |
|
| 736 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 737 | - { |
|
| 738 | - // ensure config class is set to something |
|
| 739 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 740 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 741 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | - return null; |
|
| 743 | - } |
|
| 744 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 745 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 746 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 748 | - $this->update_addon_option_names(); |
|
| 749 | - } |
|
| 750 | - // verify the incoming config object but suppress errors |
|
| 751 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | - $config_obj = new $config_class(); |
|
| 753 | - } |
|
| 754 | - if (get_option($config_option_name)) { |
|
| 755 | - EE_Config::log($config_option_name); |
|
| 756 | - update_option($config_option_name, $config_obj); |
|
| 757 | - $this->{$section}->{$name} = $config_obj; |
|
| 758 | - return $this->{$section}->{$name}; |
|
| 759 | - } else { |
|
| 760 | - // create a wp-option for this config |
|
| 761 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 762 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 763 | - return $this->{$section}->{$name}; |
|
| 764 | - } else { |
|
| 765 | - EE_Error::add_error( |
|
| 766 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 767 | - __FILE__, |
|
| 768 | - __FUNCTION__, |
|
| 769 | - __LINE__ |
|
| 770 | - ); |
|
| 771 | - return null; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * update_config |
|
| 779 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 780 | - * |
|
| 781 | - * @access public |
|
| 782 | - * @param string $section |
|
| 783 | - * @param string $name |
|
| 784 | - * @param EE_Config_Base|string $config_obj |
|
| 785 | - * @param bool $throw_errors |
|
| 786 | - * @return bool |
|
| 787 | - */ |
|
| 788 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 789 | - { |
|
| 790 | - // don't allow config updates during WP heartbeats |
|
| 791 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 792 | - return false; |
|
| 793 | - } |
|
| 794 | - $config_obj = maybe_unserialize($config_obj); |
|
| 795 | - // get class name of the incoming object |
|
| 796 | - $config_class = get_class($config_obj); |
|
| 797 | - // run tests 1-5 and 9 to verify config |
|
| 798 | - if (! $this->_verify_config_params( |
|
| 799 | - $section, |
|
| 800 | - $name, |
|
| 801 | - $config_class, |
|
| 802 | - $config_obj, |
|
| 803 | - array(1, 2, 3, 4, 7, 9) |
|
| 804 | - ) |
|
| 805 | - ) { |
|
| 806 | - return false; |
|
| 807 | - } |
|
| 808 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 809 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 810 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 811 | - // save new config to db |
|
| 812 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 813 | - return true; |
|
| 814 | - } |
|
| 815 | - } else { |
|
| 816 | - // first check if the record already exists |
|
| 817 | - $existing_config = get_option($config_option_name); |
|
| 818 | - $config_obj = serialize($config_obj); |
|
| 819 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 820 | - if ($existing_config == $config_obj) { |
|
| 821 | - $this->{$section}->{$name} = $config_obj; |
|
| 822 | - return true; |
|
| 823 | - } elseif (update_option($config_option_name, $config_obj)) { |
|
| 824 | - EE_Config::log($config_option_name); |
|
| 825 | - // update wp-option for this config class |
|
| 826 | - $this->{$section}->{$name} = $config_obj; |
|
| 827 | - return true; |
|
| 828 | - } elseif ($throw_errors) { |
|
| 829 | - EE_Error::add_error( |
|
| 830 | - sprintf( |
|
| 831 | - __( |
|
| 832 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 833 | - 'event_espresso' |
|
| 834 | - ), |
|
| 835 | - $config_class, |
|
| 836 | - 'EE_Config->' . $section . '->' . $name |
|
| 837 | - ), |
|
| 838 | - __FILE__, |
|
| 839 | - __FUNCTION__, |
|
| 840 | - __LINE__ |
|
| 841 | - ); |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - return false; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * get_config |
|
| 850 | - * |
|
| 851 | - * @access public |
|
| 852 | - * @param string $section |
|
| 853 | - * @param string $name |
|
| 854 | - * @param string $config_class |
|
| 855 | - * @return mixed EE_Config_Base | NULL |
|
| 856 | - */ |
|
| 857 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | - { |
|
| 859 | - // ensure config class is set to something |
|
| 860 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | - return null; |
|
| 864 | - } |
|
| 865 | - // now test if the requested config object exists, but suppress errors |
|
| 866 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | - // config already exists, so pass it back |
|
| 868 | - return $this->{$section}->{$name}; |
|
| 869 | - } |
|
| 870 | - // load config option from db if it exists |
|
| 871 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | - // verify the newly retrieved config object, but suppress errors |
|
| 873 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | - // config is good, so set it and pass it back |
|
| 875 | - $this->{$section}->{$name} = $config_obj; |
|
| 876 | - return $this->{$section}->{$name}; |
|
| 877 | - } |
|
| 878 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | - // verify the newly created config object |
|
| 881 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | - return $this->{$section}->{$name}; |
|
| 883 | - } else { |
|
| 884 | - EE_Error::add_error( |
|
| 885 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | - __FILE__, |
|
| 887 | - __FUNCTION__, |
|
| 888 | - __LINE__ |
|
| 889 | - ); |
|
| 890 | - } |
|
| 891 | - return null; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * get_config_option |
|
| 897 | - * |
|
| 898 | - * @access public |
|
| 899 | - * @param string $config_option_name |
|
| 900 | - * @return mixed EE_Config_Base | FALSE |
|
| 901 | - */ |
|
| 902 | - public function get_config_option($config_option_name = '') |
|
| 903 | - { |
|
| 904 | - // retrieve the wp-option for this config class. |
|
| 905 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 906 | - if (empty($config_option)) { |
|
| 907 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 908 | - } |
|
| 909 | - return $config_option; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * log |
|
| 915 | - * |
|
| 916 | - * @param string $config_option_name |
|
| 917 | - */ |
|
| 918 | - public static function log($config_option_name = '') |
|
| 919 | - { |
|
| 920 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 921 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 922 | - // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 923 | - $_request = $_REQUEST; |
|
| 924 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 925 | - $config_log[ (string) microtime(true) ] = array( |
|
| 926 | - 'config_name' => $config_option_name, |
|
| 927 | - 'request' => $_request, |
|
| 928 | - ); |
|
| 929 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * trim_log |
|
| 936 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 937 | - */ |
|
| 938 | - public static function trim_log() |
|
| 939 | - { |
|
| 940 | - if (! EE_Config::logging_enabled()) { |
|
| 941 | - return; |
|
| 942 | - } |
|
| 943 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 944 | - $log_length = count($config_log); |
|
| 945 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 946 | - ksort($config_log); |
|
| 947 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 948 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * get_page_for_posts |
|
| 955 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 956 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 957 | - * |
|
| 958 | - * @access public |
|
| 959 | - * @return string |
|
| 960 | - */ |
|
| 961 | - public static function get_page_for_posts() |
|
| 962 | - { |
|
| 963 | - $page_for_posts = get_option('page_for_posts'); |
|
| 964 | - if (! $page_for_posts) { |
|
| 965 | - return 'posts'; |
|
| 966 | - } |
|
| 967 | - /** @type WPDB $wpdb */ |
|
| 968 | - global $wpdb; |
|
| 969 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 970 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * register_shortcodes_and_modules. |
|
| 976 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 977 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 978 | - * so they can help trigger maintenance mode if it's needed |
|
| 979 | - * |
|
| 980 | - * @access public |
|
| 981 | - * @return void |
|
| 982 | - */ |
|
| 983 | - public function register_shortcodes_and_modules() |
|
| 984 | - { |
|
| 985 | - // allow modules to set hooks for the rest of the system |
|
| 986 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * initialize_shortcodes_and_modules |
|
| 992 | - * meaning they can start adding their hooks to get stuff done |
|
| 993 | - * |
|
| 994 | - * @access public |
|
| 995 | - * @return void |
|
| 996 | - */ |
|
| 997 | - public function initialize_shortcodes_and_modules() |
|
| 998 | - { |
|
| 999 | - // allow modules to set hooks for the rest of the system |
|
| 1000 | - $this->_initialize_modules(); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * widgets_init |
|
| 1006 | - * |
|
| 1007 | - * @access private |
|
| 1008 | - * @return void |
|
| 1009 | - */ |
|
| 1010 | - public function widgets_init() |
|
| 1011 | - { |
|
| 1012 | - // only init widgets on admin pages when not in complete maintenance, and |
|
| 1013 | - // on frontend when not in any maintenance mode |
|
| 1014 | - if (! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | - || ( |
|
| 1016 | - is_admin() |
|
| 1017 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1018 | - ) |
|
| 1019 | - ) { |
|
| 1020 | - // grab list of installed widgets |
|
| 1021 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1022 | - // filter list of modules to register |
|
| 1023 | - $widgets_to_register = apply_filters( |
|
| 1024 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1025 | - $widgets_to_register |
|
| 1026 | - ); |
|
| 1027 | - if (! empty($widgets_to_register)) { |
|
| 1028 | - // cycle thru widget folders |
|
| 1029 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1030 | - // add to list of installed widget modules |
|
| 1031 | - EE_Config::register_ee_widget($widget_path); |
|
| 1032 | - } |
|
| 1033 | - } |
|
| 1034 | - // filter list of installed modules |
|
| 1035 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1036 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1037 | - EE_Registry::instance()->widgets |
|
| 1038 | - ); |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * register_ee_widget - makes core aware of this widget |
|
| 1045 | - * |
|
| 1046 | - * @access public |
|
| 1047 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1048 | - * @return void |
|
| 1049 | - */ |
|
| 1050 | - public static function register_ee_widget($widget_path = null) |
|
| 1051 | - { |
|
| 1052 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1053 | - $widget_ext = '.widget.php'; |
|
| 1054 | - // make all separators match |
|
| 1055 | - $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1056 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1057 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1058 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1059 | - $file_name = explode('.', basename($widget_path)); |
|
| 1060 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1061 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1062 | - // sanitize shortcode directory name |
|
| 1063 | - $widget = sanitize_key($widget); |
|
| 1064 | - // now we need to rebuild the shortcode path |
|
| 1065 | - $widget_path = explode(DS, $widget_path); |
|
| 1066 | - // remove last segment |
|
| 1067 | - array_pop($widget_path); |
|
| 1068 | - // glue it back together |
|
| 1069 | - $widget_path = implode(DS, $widget_path); |
|
| 1070 | - } else { |
|
| 1071 | - // grab and sanitize widget directory name |
|
| 1072 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1073 | - } |
|
| 1074 | - // create classname from widget directory name |
|
| 1075 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1076 | - // add class prefix |
|
| 1077 | - $widget_class = 'EEW_' . $widget; |
|
| 1078 | - // does the widget exist ? |
|
| 1079 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1080 | - $msg = sprintf( |
|
| 1081 | - __( |
|
| 1082 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1083 | - 'event_espresso' |
|
| 1084 | - ), |
|
| 1085 | - $widget_class, |
|
| 1086 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1087 | - ); |
|
| 1088 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | - return; |
|
| 1090 | - } |
|
| 1091 | - // load the widget class file |
|
| 1092 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1093 | - // verify that class exists |
|
| 1094 | - if (! class_exists($widget_class)) { |
|
| 1095 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1096 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | - return; |
|
| 1098 | - } |
|
| 1099 | - register_widget($widget_class); |
|
| 1100 | - // add to array of registered widgets |
|
| 1101 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * _register_modules |
|
| 1107 | - * |
|
| 1108 | - * @access private |
|
| 1109 | - * @return array |
|
| 1110 | - */ |
|
| 1111 | - private function _register_modules() |
|
| 1112 | - { |
|
| 1113 | - // grab list of installed modules |
|
| 1114 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1115 | - // filter list of modules to register |
|
| 1116 | - $modules_to_register = apply_filters( |
|
| 1117 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1118 | - $modules_to_register |
|
| 1119 | - ); |
|
| 1120 | - if (! empty($modules_to_register)) { |
|
| 1121 | - // loop through folders |
|
| 1122 | - foreach ($modules_to_register as $module_path) { |
|
| 1123 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1124 | - if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1126 | - ) { |
|
| 1127 | - // add to list of installed modules |
|
| 1128 | - EE_Config::register_module($module_path); |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1131 | - } |
|
| 1132 | - // filter list of installed modules |
|
| 1133 | - return apply_filters( |
|
| 1134 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1135 | - EE_Registry::instance()->modules |
|
| 1136 | - ); |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - |
|
| 1140 | - /** |
|
| 1141 | - * register_module - makes core aware of this module |
|
| 1142 | - * |
|
| 1143 | - * @access public |
|
| 1144 | - * @param string $module_path - full path up to and including module folder |
|
| 1145 | - * @return bool |
|
| 1146 | - */ |
|
| 1147 | - public static function register_module($module_path = null) |
|
| 1148 | - { |
|
| 1149 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1150 | - $module_ext = '.module.php'; |
|
| 1151 | - // make all separators match |
|
| 1152 | - $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1153 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1154 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1155 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1156 | - $module_file = explode('.', basename($module_path)); |
|
| 1157 | - // now we need to rebuild the shortcode path |
|
| 1158 | - $module_path = explode(DS, $module_path); |
|
| 1159 | - // remove last segment |
|
| 1160 | - array_pop($module_path); |
|
| 1161 | - // glue it back together |
|
| 1162 | - $module_path = implode(DS, $module_path) . DS; |
|
| 1163 | - // take first segment from file name pieces and sanitize it |
|
| 1164 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1165 | - // ensure class prefix is added |
|
| 1166 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1167 | - } else { |
|
| 1168 | - // we need to generate the filename based off of the folder name |
|
| 1169 | - // grab and sanitize module name |
|
| 1170 | - $module = strtolower(basename($module_path)); |
|
| 1171 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1172 | - // like trailingslashit() |
|
| 1173 | - $module_path = rtrim($module_path, DS) . DS; |
|
| 1174 | - // create classname from module directory name |
|
| 1175 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1176 | - // add class prefix |
|
| 1177 | - $module_class = 'EED_' . $module; |
|
| 1178 | - } |
|
| 1179 | - // does the module exist ? |
|
| 1180 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1181 | - $msg = sprintf( |
|
| 1182 | - __( |
|
| 1183 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1184 | - 'event_espresso' |
|
| 1185 | - ), |
|
| 1186 | - $module |
|
| 1187 | - ); |
|
| 1188 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | - return false; |
|
| 1190 | - } |
|
| 1191 | - // load the module class file |
|
| 1192 | - require_once($module_path . $module_class . $module_ext); |
|
| 1193 | - // verify that class exists |
|
| 1194 | - if (! class_exists($module_class)) { |
|
| 1195 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1196 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | - return false; |
|
| 1198 | - } |
|
| 1199 | - // add to array of registered modules |
|
| 1200 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1201 | - do_action( |
|
| 1202 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1203 | - $module_class, |
|
| 1204 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1205 | - ); |
|
| 1206 | - return true; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * _initialize_modules |
|
| 1212 | - * allow modules to set hooks for the rest of the system |
|
| 1213 | - * |
|
| 1214 | - * @access private |
|
| 1215 | - * @return void |
|
| 1216 | - */ |
|
| 1217 | - private function _initialize_modules() |
|
| 1218 | - { |
|
| 1219 | - // cycle thru shortcode folders |
|
| 1220 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1221 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1222 | - // which set hooks ? |
|
| 1223 | - if (is_admin()) { |
|
| 1224 | - // fire immediately |
|
| 1225 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1226 | - } else { |
|
| 1227 | - // delay until other systems are online |
|
| 1228 | - add_action( |
|
| 1229 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1230 | - array($module_class, 'set_hooks') |
|
| 1231 | - ); |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - |
|
| 1237 | - /** |
|
| 1238 | - * register_route - adds module method routes to route_map |
|
| 1239 | - * |
|
| 1240 | - * @access public |
|
| 1241 | - * @param string $route - "pretty" public alias for module method |
|
| 1242 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1243 | - * @param string $method_name - the actual module method to be routed to |
|
| 1244 | - * @param string $key - url param key indicating a route is being called |
|
| 1245 | - * @return bool |
|
| 1246 | - */ |
|
| 1247 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1248 | - { |
|
| 1249 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1250 | - $module = str_replace('EED_', '', $module); |
|
| 1251 | - $module_class = 'EED_' . $module; |
|
| 1252 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1254 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | - return false; |
|
| 1256 | - } |
|
| 1257 | - if (empty($route)) { |
|
| 1258 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1259 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | - return false; |
|
| 1261 | - } |
|
| 1262 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1263 | - $msg = sprintf( |
|
| 1264 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1265 | - $route |
|
| 1266 | - ); |
|
| 1267 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | - return false; |
|
| 1269 | - } |
|
| 1270 | - EE_Config::$_module_route_map[ $key ][ $route ] = array('EED_' . $module, $method_name); |
|
| 1271 | - return true; |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - |
|
| 1275 | - /** |
|
| 1276 | - * get_route - get module method route |
|
| 1277 | - * |
|
| 1278 | - * @access public |
|
| 1279 | - * @param string $route - "pretty" public alias for module method |
|
| 1280 | - * @param string $key - url param key indicating a route is being called |
|
| 1281 | - * @return string |
|
| 1282 | - */ |
|
| 1283 | - public static function get_route($route = null, $key = 'ee') |
|
| 1284 | - { |
|
| 1285 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1286 | - $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1287 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1289 | - } |
|
| 1290 | - return null; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - /** |
|
| 1295 | - * get_routes - get ALL module method routes |
|
| 1296 | - * |
|
| 1297 | - * @access public |
|
| 1298 | - * @return array |
|
| 1299 | - */ |
|
| 1300 | - public static function get_routes() |
|
| 1301 | - { |
|
| 1302 | - return EE_Config::$_module_route_map; |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - |
|
| 1306 | - /** |
|
| 1307 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1308 | - * |
|
| 1309 | - * @access public |
|
| 1310 | - * @param string $route - "pretty" public alias for module method |
|
| 1311 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1312 | - * class, allows different forwards to be served based on status |
|
| 1313 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1314 | - * @param string $key - url param key indicating a route is being called |
|
| 1315 | - * @return bool |
|
| 1316 | - */ |
|
| 1317 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1318 | - { |
|
| 1319 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1320 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1321 | - $msg = sprintf( |
|
| 1322 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1323 | - $route |
|
| 1324 | - ); |
|
| 1325 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | - return false; |
|
| 1327 | - } |
|
| 1328 | - if (empty($forward)) { |
|
| 1329 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1330 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | - return false; |
|
| 1332 | - } |
|
| 1333 | - if (is_array($forward)) { |
|
| 1334 | - if (! isset($forward[1])) { |
|
| 1335 | - $msg = sprintf( |
|
| 1336 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1337 | - $route |
|
| 1338 | - ); |
|
| 1339 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | - return false; |
|
| 1341 | - } |
|
| 1342 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1343 | - $msg = sprintf( |
|
| 1344 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1345 | - $forward[1], |
|
| 1346 | - $route |
|
| 1347 | - ); |
|
| 1348 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | - return false; |
|
| 1350 | - } |
|
| 1351 | - } elseif (! function_exists($forward)) { |
|
| 1352 | - $msg = sprintf( |
|
| 1353 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1354 | - $forward, |
|
| 1355 | - $route |
|
| 1356 | - ); |
|
| 1357 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | - return false; |
|
| 1359 | - } |
|
| 1360 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1361 | - return true; |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - /** |
|
| 1366 | - * get_forward - get forwarding route |
|
| 1367 | - * |
|
| 1368 | - * @access public |
|
| 1369 | - * @param string $route - "pretty" public alias for module method |
|
| 1370 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1371 | - * allows different forwards to be served based on status |
|
| 1372 | - * @param string $key - url param key indicating a route is being called |
|
| 1373 | - * @return string |
|
| 1374 | - */ |
|
| 1375 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1376 | - { |
|
| 1377 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1378 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1379 | - return apply_filters( |
|
| 1380 | - 'FHEE__EE_Config__get_forward', |
|
| 1381 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1382 | - $route, |
|
| 1383 | - $status |
|
| 1384 | - ); |
|
| 1385 | - } |
|
| 1386 | - return null; |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - |
|
| 1390 | - /** |
|
| 1391 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1392 | - * results |
|
| 1393 | - * |
|
| 1394 | - * @access public |
|
| 1395 | - * @param string $route - "pretty" public alias for module method |
|
| 1396 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1397 | - * allows different views to be served based on status |
|
| 1398 | - * @param string $view |
|
| 1399 | - * @param string $key - url param key indicating a route is being called |
|
| 1400 | - * @return bool |
|
| 1401 | - */ |
|
| 1402 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1403 | - { |
|
| 1404 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1405 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1406 | - $msg = sprintf( |
|
| 1407 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1408 | - $route |
|
| 1409 | - ); |
|
| 1410 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | - return false; |
|
| 1412 | - } |
|
| 1413 | - if (! is_readable($view)) { |
|
| 1414 | - $msg = sprintf( |
|
| 1415 | - __( |
|
| 1416 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1417 | - 'event_espresso' |
|
| 1418 | - ), |
|
| 1419 | - $view |
|
| 1420 | - ); |
|
| 1421 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | - return false; |
|
| 1423 | - } |
|
| 1424 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1425 | - return true; |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * get_view - get view for route and status |
|
| 1431 | - * |
|
| 1432 | - * @access public |
|
| 1433 | - * @param string $route - "pretty" public alias for module method |
|
| 1434 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1435 | - * allows different views to be served based on status |
|
| 1436 | - * @param string $key - url param key indicating a route is being called |
|
| 1437 | - * @return string |
|
| 1438 | - */ |
|
| 1439 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1440 | - { |
|
| 1441 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1442 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1443 | - return apply_filters( |
|
| 1444 | - 'FHEE__EE_Config__get_view', |
|
| 1445 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1446 | - $route, |
|
| 1447 | - $status |
|
| 1448 | - ); |
|
| 1449 | - } |
|
| 1450 | - return null; |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - |
|
| 1454 | - public function update_addon_option_names() |
|
| 1455 | - { |
|
| 1456 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - |
|
| 1460 | - public function shutdown() |
|
| 1461 | - { |
|
| 1462 | - $this->update_addon_option_names(); |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * @return LegacyShortcodesManager |
|
| 1468 | - */ |
|
| 1469 | - public static function getLegacyShortcodesManager() |
|
| 1470 | - { |
|
| 1471 | - |
|
| 1472 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1474 | - EE_Registry::instance() |
|
| 1475 | - ); |
|
| 1476 | - } |
|
| 1477 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * register_shortcode - makes core aware of this shortcode |
|
| 1483 | - * |
|
| 1484 | - * @deprecated 4.9.26 |
|
| 1485 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1486 | - * @return bool |
|
| 1487 | - */ |
|
| 1488 | - public static function register_shortcode($shortcode_path = null) |
|
| 1489 | - { |
|
| 1490 | - EE_Error::doing_it_wrong( |
|
| 1491 | - __METHOD__, |
|
| 1492 | - __( |
|
| 1493 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1494 | - 'event_espresso' |
|
| 1495 | - ), |
|
| 1496 | - '4.9.26' |
|
| 1497 | - ); |
|
| 1498 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1499 | - } |
|
| 1500 | -} |
|
| 1501 | - |
|
| 1502 | -/** |
|
| 1503 | - * Base class used for config classes. These classes should generally not have |
|
| 1504 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1505 | - * basically, they should just be well-defined stdClasses |
|
| 1506 | - */ |
|
| 1507 | -class EE_Config_Base |
|
| 1508 | -{ |
|
| 1509 | - |
|
| 1510 | - /** |
|
| 1511 | - * Utility function for escaping the value of a property and returning. |
|
| 1512 | - * |
|
| 1513 | - * @param string $property property name (checks to see if exists). |
|
| 1514 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1515 | - * @throws \EE_Error |
|
| 1516 | - */ |
|
| 1517 | - public function get_pretty($property) |
|
| 1518 | - { |
|
| 1519 | - if (! property_exists($this, $property)) { |
|
| 1520 | - throw new EE_Error( |
|
| 1521 | - sprintf( |
|
| 1522 | - __( |
|
| 1523 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1524 | - 'event_espresso' |
|
| 1525 | - ), |
|
| 1526 | - get_class($this), |
|
| 1527 | - $property |
|
| 1528 | - ) |
|
| 1529 | - ); |
|
| 1530 | - } |
|
| 1531 | - // just handling escaping of strings for now. |
|
| 1532 | - if (is_string($this->{$property})) { |
|
| 1533 | - return stripslashes($this->{$property}); |
|
| 1534 | - } |
|
| 1535 | - return $this->{$property}; |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - |
|
| 1539 | - public function populate() |
|
| 1540 | - { |
|
| 1541 | - // grab defaults via a new instance of this class. |
|
| 1542 | - $class_name = get_class($this); |
|
| 1543 | - $defaults = new $class_name; |
|
| 1544 | - // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1545 | - // default from our $defaults object. |
|
| 1546 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1547 | - if ($this->{$property} === null) { |
|
| 1548 | - $this->{$property} = $value; |
|
| 1549 | - } |
|
| 1550 | - } |
|
| 1551 | - // cleanup |
|
| 1552 | - unset($defaults); |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * __isset |
|
| 1558 | - * |
|
| 1559 | - * @param $a |
|
| 1560 | - * @return bool |
|
| 1561 | - */ |
|
| 1562 | - public function __isset($a) |
|
| 1563 | - { |
|
| 1564 | - return false; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - |
|
| 1568 | - /** |
|
| 1569 | - * __unset |
|
| 1570 | - * |
|
| 1571 | - * @param $a |
|
| 1572 | - * @return bool |
|
| 1573 | - */ |
|
| 1574 | - public function __unset($a) |
|
| 1575 | - { |
|
| 1576 | - return false; |
|
| 1577 | - } |
|
| 1578 | - |
|
| 1579 | - |
|
| 1580 | - /** |
|
| 1581 | - * __clone |
|
| 1582 | - */ |
|
| 1583 | - public function __clone() |
|
| 1584 | - { |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * __wakeup |
|
| 1590 | - */ |
|
| 1591 | - public function __wakeup() |
|
| 1592 | - { |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * __destruct |
|
| 1598 | - */ |
|
| 1599 | - public function __destruct() |
|
| 1600 | - { |
|
| 1601 | - } |
|
| 1602 | -} |
|
| 1603 | - |
|
| 1604 | -/** |
|
| 1605 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1606 | - */ |
|
| 1607 | -class EE_Core_Config extends EE_Config_Base |
|
| 1608 | -{ |
|
| 1609 | - |
|
| 1610 | - const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1611 | - |
|
| 1612 | - |
|
| 1613 | - public $current_blog_id; |
|
| 1614 | - |
|
| 1615 | - public $ee_ueip_optin; |
|
| 1616 | - |
|
| 1617 | - public $ee_ueip_has_notified; |
|
| 1618 | - |
|
| 1619 | - /** |
|
| 1620 | - * Not to be confused with the 4 critical page variables (See |
|
| 1621 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1622 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1623 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1624 | - * |
|
| 1625 | - * @var array |
|
| 1626 | - */ |
|
| 1627 | - public $post_shortcodes; |
|
| 1628 | - |
|
| 1629 | - public $module_route_map; |
|
| 1630 | - |
|
| 1631 | - public $module_forward_map; |
|
| 1632 | - |
|
| 1633 | - public $module_view_map; |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1637 | - * |
|
| 1638 | - * @var int |
|
| 1639 | - */ |
|
| 1640 | - public $reg_page_id; |
|
| 1641 | - |
|
| 1642 | - public $txn_page_id; |
|
| 1643 | - |
|
| 1644 | - public $thank_you_page_id; |
|
| 1645 | - |
|
| 1646 | - public $cancel_page_id; |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1650 | - * |
|
| 1651 | - * @var int |
|
| 1652 | - */ |
|
| 1653 | - public $reg_page_url; |
|
| 1654 | - |
|
| 1655 | - public $txn_page_url; |
|
| 1656 | - |
|
| 1657 | - public $thank_you_page_url; |
|
| 1658 | - |
|
| 1659 | - public $cancel_page_url; |
|
| 1660 | - |
|
| 1661 | - /** |
|
| 1662 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1663 | - */ |
|
| 1664 | - public $event_cpt_slug; |
|
| 1665 | - |
|
| 1666 | - /** |
|
| 1667 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1668 | - * request across blog switches in a multisite context. |
|
| 1669 | - * Avoids extra queries to the db for this option. |
|
| 1670 | - * |
|
| 1671 | - * @var bool |
|
| 1672 | - */ |
|
| 1673 | - public static $ee_ueip_option; |
|
| 1674 | - |
|
| 1675 | - |
|
| 1676 | - /** |
|
| 1677 | - * class constructor |
|
| 1678 | - * |
|
| 1679 | - * @access public |
|
| 1680 | - */ |
|
| 1681 | - public function __construct() |
|
| 1682 | - { |
|
| 1683 | - // set default organization settings |
|
| 1684 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1685 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1686 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1687 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1688 | - $this->post_shortcodes = array(); |
|
| 1689 | - $this->module_route_map = array(); |
|
| 1690 | - $this->module_forward_map = array(); |
|
| 1691 | - $this->module_view_map = array(); |
|
| 1692 | - // critical EE page IDs |
|
| 1693 | - $this->reg_page_id = 0; |
|
| 1694 | - $this->txn_page_id = 0; |
|
| 1695 | - $this->thank_you_page_id = 0; |
|
| 1696 | - $this->cancel_page_id = 0; |
|
| 1697 | - // critical EE page URLs |
|
| 1698 | - $this->reg_page_url = ''; |
|
| 1699 | - $this->txn_page_url = ''; |
|
| 1700 | - $this->thank_you_page_url = ''; |
|
| 1701 | - $this->cancel_page_url = ''; |
|
| 1702 | - // cpt slugs |
|
| 1703 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1704 | - // ueip constant check |
|
| 1705 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1706 | - $this->ee_ueip_optin = false; |
|
| 1707 | - $this->ee_ueip_has_notified = true; |
|
| 1708 | - } |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * @return array |
|
| 1714 | - */ |
|
| 1715 | - public function get_critical_pages_array() |
|
| 1716 | - { |
|
| 1717 | - return array( |
|
| 1718 | - $this->reg_page_id, |
|
| 1719 | - $this->txn_page_id, |
|
| 1720 | - $this->thank_you_page_id, |
|
| 1721 | - $this->cancel_page_id, |
|
| 1722 | - ); |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - |
|
| 1726 | - /** |
|
| 1727 | - * @return array |
|
| 1728 | - */ |
|
| 1729 | - public function get_critical_pages_shortcodes_array() |
|
| 1730 | - { |
|
| 1731 | - return array( |
|
| 1732 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1733 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1734 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1735 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1736 | - ); |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * gets/returns URL for EE reg_page |
|
| 1742 | - * |
|
| 1743 | - * @access public |
|
| 1744 | - * @return string |
|
| 1745 | - */ |
|
| 1746 | - public function reg_page_url() |
|
| 1747 | - { |
|
| 1748 | - if (! $this->reg_page_url) { |
|
| 1749 | - $this->reg_page_url = add_query_arg( |
|
| 1750 | - array('uts' => time()), |
|
| 1751 | - get_permalink($this->reg_page_id) |
|
| 1752 | - ) . '#checkout'; |
|
| 1753 | - } |
|
| 1754 | - return $this->reg_page_url; |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - |
|
| 1758 | - /** |
|
| 1759 | - * gets/returns URL for EE txn_page |
|
| 1760 | - * |
|
| 1761 | - * @param array $query_args like what gets passed to |
|
| 1762 | - * add_query_arg() as the first argument |
|
| 1763 | - * @access public |
|
| 1764 | - * @return string |
|
| 1765 | - */ |
|
| 1766 | - public function txn_page_url($query_args = array()) |
|
| 1767 | - { |
|
| 1768 | - if (! $this->txn_page_url) { |
|
| 1769 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1770 | - } |
|
| 1771 | - if ($query_args) { |
|
| 1772 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1773 | - } else { |
|
| 1774 | - return $this->txn_page_url; |
|
| 1775 | - } |
|
| 1776 | - } |
|
| 1777 | - |
|
| 1778 | - |
|
| 1779 | - /** |
|
| 1780 | - * gets/returns URL for EE thank_you_page |
|
| 1781 | - * |
|
| 1782 | - * @param array $query_args like what gets passed to |
|
| 1783 | - * add_query_arg() as the first argument |
|
| 1784 | - * @access public |
|
| 1785 | - * @return string |
|
| 1786 | - */ |
|
| 1787 | - public function thank_you_page_url($query_args = array()) |
|
| 1788 | - { |
|
| 1789 | - if (! $this->thank_you_page_url) { |
|
| 1790 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1791 | - } |
|
| 1792 | - if ($query_args) { |
|
| 1793 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1794 | - } else { |
|
| 1795 | - return $this->thank_you_page_url; |
|
| 1796 | - } |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * gets/returns URL for EE cancel_page |
|
| 1802 | - * |
|
| 1803 | - * @access public |
|
| 1804 | - * @return string |
|
| 1805 | - */ |
|
| 1806 | - public function cancel_page_url() |
|
| 1807 | - { |
|
| 1808 | - if (! $this->cancel_page_url) { |
|
| 1809 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1810 | - } |
|
| 1811 | - return $this->cancel_page_url; |
|
| 1812 | - } |
|
| 1813 | - |
|
| 1814 | - |
|
| 1815 | - /** |
|
| 1816 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1817 | - * |
|
| 1818 | - * @since 4.7.5 |
|
| 1819 | - */ |
|
| 1820 | - protected function _reset_urls() |
|
| 1821 | - { |
|
| 1822 | - $this->reg_page_url = ''; |
|
| 1823 | - $this->txn_page_url = ''; |
|
| 1824 | - $this->cancel_page_url = ''; |
|
| 1825 | - $this->thank_you_page_url = ''; |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - |
|
| 1829 | - /** |
|
| 1830 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1831 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1832 | - * on the main site only. |
|
| 1833 | - * |
|
| 1834 | - * @return bool |
|
| 1835 | - */ |
|
| 1836 | - protected function _get_main_ee_ueip_optin() |
|
| 1837 | - { |
|
| 1838 | - // if this is the main site then we can just bypass our direct query. |
|
| 1839 | - if (is_main_site()) { |
|
| 1840 | - return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1841 | - } |
|
| 1842 | - // is this already cached for this request? If so use it. |
|
| 1843 | - if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1844 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1845 | - } |
|
| 1846 | - global $wpdb; |
|
| 1847 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1848 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1849 | - $option = self::OPTION_NAME_UXIP; |
|
| 1850 | - // set correct table for query |
|
| 1851 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1852 | - // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1853 | - // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1854 | - // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1855 | - // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1856 | - // for the purpose of caching. |
|
| 1857 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1858 | - if (false !== $pre) { |
|
| 1859 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1860 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1861 | - } |
|
| 1862 | - $row = $wpdb->get_row( |
|
| 1863 | - $wpdb->prepare( |
|
| 1864 | - "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1865 | - $option |
|
| 1866 | - ) |
|
| 1867 | - ); |
|
| 1868 | - if (is_object($row)) { |
|
| 1869 | - $value = $row->option_value; |
|
| 1870 | - } else { // option does not exist so use default. |
|
| 1871 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1872 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1873 | - } |
|
| 1874 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1875 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - /** |
|
| 1880 | - * Utility function for escaping the value of a property and returning. |
|
| 1881 | - * |
|
| 1882 | - * @param string $property property name (checks to see if exists). |
|
| 1883 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1884 | - * @throws \EE_Error |
|
| 1885 | - */ |
|
| 1886 | - public function get_pretty($property) |
|
| 1887 | - { |
|
| 1888 | - if ($property === self::OPTION_NAME_UXIP) { |
|
| 1889 | - return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1890 | - } |
|
| 1891 | - return parent::get_pretty($property); |
|
| 1892 | - } |
|
| 1893 | - |
|
| 1894 | - |
|
| 1895 | - /** |
|
| 1896 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1897 | - * on the object. |
|
| 1898 | - * |
|
| 1899 | - * @return array |
|
| 1900 | - */ |
|
| 1901 | - public function __sleep() |
|
| 1902 | - { |
|
| 1903 | - // reset all url properties |
|
| 1904 | - $this->_reset_urls(); |
|
| 1905 | - // return what to save to db |
|
| 1906 | - return array_keys(get_object_vars($this)); |
|
| 1907 | - } |
|
| 1908 | -} |
|
| 1909 | - |
|
| 1910 | -/** |
|
| 1911 | - * Config class for storing info on the Organization |
|
| 1912 | - */ |
|
| 1913 | -class EE_Organization_Config extends EE_Config_Base |
|
| 1914 | -{ |
|
| 1915 | - |
|
| 1916 | - /** |
|
| 1917 | - * @var string $name |
|
| 1918 | - * eg EE4.1 |
|
| 1919 | - */ |
|
| 1920 | - public $name; |
|
| 1921 | - |
|
| 1922 | - /** |
|
| 1923 | - * @var string $address_1 |
|
| 1924 | - * eg 123 Onna Road |
|
| 1925 | - */ |
|
| 1926 | - public $address_1; |
|
| 1927 | - |
|
| 1928 | - /** |
|
| 1929 | - * @var string $address_2 |
|
| 1930 | - * eg PO Box 123 |
|
| 1931 | - */ |
|
| 1932 | - public $address_2; |
|
| 1933 | - |
|
| 1934 | - /** |
|
| 1935 | - * @var string $city |
|
| 1936 | - * eg Inna City |
|
| 1937 | - */ |
|
| 1938 | - public $city; |
|
| 1939 | - |
|
| 1940 | - /** |
|
| 1941 | - * @var int $STA_ID |
|
| 1942 | - * eg 4 |
|
| 1943 | - */ |
|
| 1944 | - public $STA_ID; |
|
| 1945 | - |
|
| 1946 | - /** |
|
| 1947 | - * @var string $CNT_ISO |
|
| 1948 | - * eg US |
|
| 1949 | - */ |
|
| 1950 | - public $CNT_ISO; |
|
| 1951 | - |
|
| 1952 | - /** |
|
| 1953 | - * @var string $zip |
|
| 1954 | - * eg 12345 or V1A 2B3 |
|
| 1955 | - */ |
|
| 1956 | - public $zip; |
|
| 1957 | - |
|
| 1958 | - /** |
|
| 1959 | - * @var string $email |
|
| 1960 | - * eg [email protected] |
|
| 1961 | - */ |
|
| 1962 | - public $email; |
|
| 1963 | - |
|
| 1964 | - /** |
|
| 1965 | - * @var string $phone |
|
| 1966 | - * eg. 111-111-1111 |
|
| 1967 | - */ |
|
| 1968 | - public $phone; |
|
| 1969 | - |
|
| 1970 | - /** |
|
| 1971 | - * @var string $vat |
|
| 1972 | - * VAT/Tax Number |
|
| 1973 | - */ |
|
| 1974 | - public $vat; |
|
| 1975 | - |
|
| 1976 | - /** |
|
| 1977 | - * @var string $logo_url |
|
| 1978 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1979 | - */ |
|
| 1980 | - public $logo_url; |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * The below are all various properties for holding links to organization social network profiles |
|
| 1984 | - * |
|
| 1985 | - * @var string |
|
| 1986 | - */ |
|
| 1987 | - /** |
|
| 1988 | - * facebook (facebook.com/profile.name) |
|
| 1989 | - * |
|
| 1990 | - * @var string |
|
| 1991 | - */ |
|
| 1992 | - public $facebook; |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * twitter (twitter.com/twitter_handle) |
|
| 1996 | - * |
|
| 1997 | - * @var string |
|
| 1998 | - */ |
|
| 1999 | - public $twitter; |
|
| 2000 | - |
|
| 2001 | - /** |
|
| 2002 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2003 | - * |
|
| 2004 | - * @var string |
|
| 2005 | - */ |
|
| 2006 | - public $linkedin; |
|
| 2007 | - |
|
| 2008 | - /** |
|
| 2009 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2010 | - * |
|
| 2011 | - * @var string |
|
| 2012 | - */ |
|
| 2013 | - public $pinterest; |
|
| 2014 | - |
|
| 2015 | - /** |
|
| 2016 | - * google+ (google.com/+profileName) |
|
| 2017 | - * |
|
| 2018 | - * @var string |
|
| 2019 | - */ |
|
| 2020 | - public $google; |
|
| 2021 | - |
|
| 2022 | - /** |
|
| 2023 | - * instagram (instagram.com/handle) |
|
| 2024 | - * |
|
| 2025 | - * @var string |
|
| 2026 | - */ |
|
| 2027 | - public $instagram; |
|
| 2028 | - |
|
| 2029 | - |
|
| 2030 | - /** |
|
| 2031 | - * class constructor |
|
| 2032 | - * |
|
| 2033 | - * @access public |
|
| 2034 | - */ |
|
| 2035 | - public function __construct() |
|
| 2036 | - { |
|
| 2037 | - // set default organization settings |
|
| 2038 | - // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2039 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2040 | - $this->address_1 = '123 Onna Road'; |
|
| 2041 | - $this->address_2 = 'PO Box 123'; |
|
| 2042 | - $this->city = 'Inna City'; |
|
| 2043 | - $this->STA_ID = 4; |
|
| 2044 | - $this->CNT_ISO = 'US'; |
|
| 2045 | - $this->zip = '12345'; |
|
| 2046 | - $this->email = get_bloginfo('admin_email'); |
|
| 2047 | - $this->phone = ''; |
|
| 2048 | - $this->vat = '123456789'; |
|
| 2049 | - $this->logo_url = ''; |
|
| 2050 | - $this->facebook = ''; |
|
| 2051 | - $this->twitter = ''; |
|
| 2052 | - $this->linkedin = ''; |
|
| 2053 | - $this->pinterest = ''; |
|
| 2054 | - $this->google = ''; |
|
| 2055 | - $this->instagram = ''; |
|
| 2056 | - } |
|
| 2057 | -} |
|
| 2058 | - |
|
| 2059 | -/** |
|
| 2060 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2061 | - */ |
|
| 2062 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2063 | -{ |
|
| 2064 | - |
|
| 2065 | - /** |
|
| 2066 | - * @var string $code |
|
| 2067 | - * eg 'US' |
|
| 2068 | - */ |
|
| 2069 | - public $code; |
|
| 2070 | - |
|
| 2071 | - /** |
|
| 2072 | - * @var string $name |
|
| 2073 | - * eg 'Dollar' |
|
| 2074 | - */ |
|
| 2075 | - public $name; |
|
| 2076 | - |
|
| 2077 | - /** |
|
| 2078 | - * plural name |
|
| 2079 | - * |
|
| 2080 | - * @var string $plural |
|
| 2081 | - * eg 'Dollars' |
|
| 2082 | - */ |
|
| 2083 | - public $plural; |
|
| 2084 | - |
|
| 2085 | - /** |
|
| 2086 | - * currency sign |
|
| 2087 | - * |
|
| 2088 | - * @var string $sign |
|
| 2089 | - * eg '$' |
|
| 2090 | - */ |
|
| 2091 | - public $sign; |
|
| 2092 | - |
|
| 2093 | - /** |
|
| 2094 | - * Whether the currency sign should come before the number or not |
|
| 2095 | - * |
|
| 2096 | - * @var boolean $sign_b4 |
|
| 2097 | - */ |
|
| 2098 | - public $sign_b4; |
|
| 2099 | - |
|
| 2100 | - /** |
|
| 2101 | - * How many digits should come after the decimal place |
|
| 2102 | - * |
|
| 2103 | - * @var int $dec_plc |
|
| 2104 | - */ |
|
| 2105 | - public $dec_plc; |
|
| 2106 | - |
|
| 2107 | - /** |
|
| 2108 | - * Symbol to use for decimal mark |
|
| 2109 | - * |
|
| 2110 | - * @var string $dec_mrk |
|
| 2111 | - * eg '.' |
|
| 2112 | - */ |
|
| 2113 | - public $dec_mrk; |
|
| 2114 | - |
|
| 2115 | - /** |
|
| 2116 | - * Symbol to use for thousands |
|
| 2117 | - * |
|
| 2118 | - * @var string $thsnds |
|
| 2119 | - * eg ',' |
|
| 2120 | - */ |
|
| 2121 | - public $thsnds; |
|
| 2122 | - |
|
| 2123 | - |
|
| 2124 | - /** |
|
| 2125 | - * class constructor |
|
| 2126 | - * |
|
| 2127 | - * @access public |
|
| 2128 | - * @param string $CNT_ISO |
|
| 2129 | - * @throws \EE_Error |
|
| 2130 | - */ |
|
| 2131 | - public function __construct($CNT_ISO = '') |
|
| 2132 | - { |
|
| 2133 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2134 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2135 | - // get country code from organization settings or use default |
|
| 2136 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2137 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2138 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2139 | - : ''; |
|
| 2140 | - // but override if requested |
|
| 2141 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2142 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2143 | - if (! empty($CNT_ISO) |
|
| 2144 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2145 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2146 | - ) { |
|
| 2147 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2148 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2149 | - if ($country instanceof EE_Country) { |
|
| 2150 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2151 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2152 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2153 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2154 | - $this->sign_b4 = $country->currency_sign_before( |
|
| 2155 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | - $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2158 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2159 | - $this->thsnds = $country->currency_thousands_separator( |
|
| 2160 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2161 | - } |
|
| 2162 | - } |
|
| 2163 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2164 | - if (empty($this->code)) { |
|
| 2165 | - // set default currency settings |
|
| 2166 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2167 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2168 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2169 | - $this->sign = '$'; // currency sign: $ |
|
| 2170 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2171 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2172 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2173 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2174 | - } |
|
| 2175 | - } |
|
| 2176 | -} |
|
| 2177 | - |
|
| 2178 | -/** |
|
| 2179 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2180 | - */ |
|
| 2181 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2182 | -{ |
|
| 2183 | - |
|
| 2184 | - /** |
|
| 2185 | - * Default registration status |
|
| 2186 | - * |
|
| 2187 | - * @var string $default_STS_ID |
|
| 2188 | - * eg 'RPP' |
|
| 2189 | - */ |
|
| 2190 | - public $default_STS_ID; |
|
| 2191 | - |
|
| 2192 | - /** |
|
| 2193 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2194 | - * registrations) |
|
| 2195 | - * |
|
| 2196 | - * @var int |
|
| 2197 | - */ |
|
| 2198 | - public $default_maximum_number_of_tickets; |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * level of validation to apply to email addresses |
|
| 2202 | - * |
|
| 2203 | - * @var string $email_validation_level |
|
| 2204 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2205 | - */ |
|
| 2206 | - public $email_validation_level; |
|
| 2207 | - |
|
| 2208 | - /** |
|
| 2209 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2210 | - * |
|
| 2211 | - * @var boolean $show_pending_payment_options |
|
| 2212 | - */ |
|
| 2213 | - public $show_pending_payment_options; |
|
| 2214 | - |
|
| 2215 | - /** |
|
| 2216 | - * Whether to skip the registration confirmation page |
|
| 2217 | - * |
|
| 2218 | - * @var boolean $skip_reg_confirmation |
|
| 2219 | - */ |
|
| 2220 | - public $skip_reg_confirmation; |
|
| 2221 | - |
|
| 2222 | - /** |
|
| 2223 | - * an array of SPCO reg steps where: |
|
| 2224 | - * the keys denotes the reg step order |
|
| 2225 | - * each element consists of an array with the following elements: |
|
| 2226 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2227 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2228 | - * "slug" => the URL param used to trigger the reg step |
|
| 2229 | - * |
|
| 2230 | - * @var array $reg_steps |
|
| 2231 | - */ |
|
| 2232 | - public $reg_steps; |
|
| 2233 | - |
|
| 2234 | - /** |
|
| 2235 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2236 | - * |
|
| 2237 | - * @var boolean $reg_confirmation_last |
|
| 2238 | - */ |
|
| 2239 | - public $reg_confirmation_last; |
|
| 2240 | - |
|
| 2241 | - /** |
|
| 2242 | - * Whether or not to enable the EE Bot Trap |
|
| 2243 | - * |
|
| 2244 | - * @var boolean $use_bot_trap |
|
| 2245 | - */ |
|
| 2246 | - public $use_bot_trap; |
|
| 2247 | - |
|
| 2248 | - /** |
|
| 2249 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2250 | - * |
|
| 2251 | - * @var boolean $use_encryption |
|
| 2252 | - */ |
|
| 2253 | - public $use_encryption; |
|
| 2254 | - |
|
| 2255 | - /** |
|
| 2256 | - * Whether or not to use ReCaptcha |
|
| 2257 | - * |
|
| 2258 | - * @var boolean $use_captcha |
|
| 2259 | - */ |
|
| 2260 | - public $use_captcha; |
|
| 2261 | - |
|
| 2262 | - /** |
|
| 2263 | - * ReCaptcha Theme |
|
| 2264 | - * |
|
| 2265 | - * @var string $recaptcha_theme |
|
| 2266 | - * options: 'dark', 'light', 'invisible' |
|
| 2267 | - */ |
|
| 2268 | - public $recaptcha_theme; |
|
| 2269 | - |
|
| 2270 | - /** |
|
| 2271 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2272 | - * |
|
| 2273 | - * @var string $recaptcha_badge |
|
| 2274 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2275 | - */ |
|
| 2276 | - public $recaptcha_badge; |
|
| 17 | + const OPTION_NAME = 'ee_config'; |
|
| 18 | + |
|
| 19 | + const LOG_NAME = 'ee_config_log'; |
|
| 20 | + |
|
| 21 | + const LOG_LENGTH = 100; |
|
| 22 | + |
|
| 23 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * instance of the EE_Config object |
|
| 27 | + * |
|
| 28 | + * @var EE_Config $_instance |
|
| 29 | + * @access private |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var boolean $_logging_enabled |
|
| 35 | + */ |
|
| 36 | + private static $_logging_enabled = false; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | + */ |
|
| 41 | + private $legacy_shortcodes_manager; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * An StdClass whose property names are addon slugs, |
|
| 45 | + * and values are their config classes |
|
| 46 | + * |
|
| 47 | + * @var StdClass |
|
| 48 | + */ |
|
| 49 | + public $addons; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var EE_Admin_Config |
|
| 53 | + */ |
|
| 54 | + public $admin; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var EE_Core_Config |
|
| 58 | + */ |
|
| 59 | + public $core; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var EE_Currency_Config |
|
| 63 | + */ |
|
| 64 | + public $currency; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var EE_Organization_Config |
|
| 68 | + */ |
|
| 69 | + public $organization; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var EE_Registration_Config |
|
| 73 | + */ |
|
| 74 | + public $registration; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var EE_Template_Config |
|
| 78 | + */ |
|
| 79 | + public $template_settings; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Holds EE environment values. |
|
| 83 | + * |
|
| 84 | + * @var EE_Environment_Config |
|
| 85 | + */ |
|
| 86 | + public $environment; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * settings pertaining to Google maps |
|
| 90 | + * |
|
| 91 | + * @var EE_Map_Config |
|
| 92 | + */ |
|
| 93 | + public $map_settings; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * settings pertaining to Taxes |
|
| 97 | + * |
|
| 98 | + * @var EE_Tax_Config |
|
| 99 | + */ |
|
| 100 | + public $tax_settings; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Settings pertaining to global messages settings. |
|
| 104 | + * |
|
| 105 | + * @var EE_Messages_Config |
|
| 106 | + */ |
|
| 107 | + public $messages; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated |
|
| 111 | + * @var EE_Gateway_Config |
|
| 112 | + */ |
|
| 113 | + public $gateway; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var array $_addon_option_names |
|
| 117 | + * @access private |
|
| 118 | + */ |
|
| 119 | + private $_addon_option_names = array(); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @var array $_module_route_map |
|
| 123 | + * @access private |
|
| 124 | + */ |
|
| 125 | + private static $_module_route_map = array(); |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @var array $_module_forward_map |
|
| 129 | + * @access private |
|
| 130 | + */ |
|
| 131 | + private static $_module_forward_map = array(); |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @var array $_module_view_map |
|
| 135 | + * @access private |
|
| 136 | + */ |
|
| 137 | + private static $_module_view_map = array(); |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @singleton method used to instantiate class object |
|
| 142 | + * @access public |
|
| 143 | + * @return EE_Config instance |
|
| 144 | + */ |
|
| 145 | + public static function instance() |
|
| 146 | + { |
|
| 147 | + // check if class object is instantiated, and instantiated properly |
|
| 148 | + if (! self::$_instance instanceof EE_Config) { |
|
| 149 | + self::$_instance = new self(); |
|
| 150 | + } |
|
| 151 | + return self::$_instance; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Resets the config |
|
| 157 | + * |
|
| 158 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | + * reflect its state in the database |
|
| 161 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | + * site was put into maintenance mode) |
|
| 165 | + * @return EE_Config |
|
| 166 | + */ |
|
| 167 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | + { |
|
| 169 | + if (self::$_instance instanceof EE_Config) { |
|
| 170 | + if ($hard_reset) { |
|
| 171 | + self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | + self::$_instance->_addon_option_names = array(); |
|
| 173 | + self::$_instance->_initialize_config(); |
|
| 174 | + self::$_instance->update_espresso_config(); |
|
| 175 | + } |
|
| 176 | + self::$_instance->update_addon_option_names(); |
|
| 177 | + } |
|
| 178 | + self::$_instance = null; |
|
| 179 | + // we don't need to reset the static properties imo because those should |
|
| 180 | + // only change when a module is added or removed. Currently we don't |
|
| 181 | + // support removing a module during a request when it previously existed |
|
| 182 | + if ($reinstantiate) { |
|
| 183 | + return self::instance(); |
|
| 184 | + } else { |
|
| 185 | + return null; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * class constructor |
|
| 192 | + * |
|
| 193 | + * @access private |
|
| 194 | + */ |
|
| 195 | + private function __construct() |
|
| 196 | + { |
|
| 197 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | + // setup empty config classes |
|
| 200 | + $this->_initialize_config(); |
|
| 201 | + // load existing EE site settings |
|
| 202 | + $this->_load_core_config(); |
|
| 203 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | + $this->_verify_config(); |
|
| 205 | + // register shortcodes and modules |
|
| 206 | + add_action( |
|
| 207 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | + array($this, 'register_shortcodes_and_modules'), |
|
| 209 | + 999 |
|
| 210 | + ); |
|
| 211 | + // initialize shortcodes and modules |
|
| 212 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | + // register widgets |
|
| 214 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | + // shutdown |
|
| 216 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | + // construct__end hook |
|
| 218 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | + // hardcoded hack |
|
| 220 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @return boolean |
|
| 226 | + */ |
|
| 227 | + public static function logging_enabled() |
|
| 228 | + { |
|
| 229 | + return self::$_logging_enabled; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * use to get the current theme if needed from static context |
|
| 235 | + * |
|
| 236 | + * @return string current theme set. |
|
| 237 | + */ |
|
| 238 | + public static function get_current_theme() |
|
| 239 | + { |
|
| 240 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * _initialize_config |
|
| 247 | + * |
|
| 248 | + * @access private |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + private function _initialize_config() |
|
| 252 | + { |
|
| 253 | + EE_Config::trim_log(); |
|
| 254 | + // set defaults |
|
| 255 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | + $this->addons = new stdClass(); |
|
| 257 | + // set _module_route_map |
|
| 258 | + EE_Config::$_module_route_map = array(); |
|
| 259 | + // set _module_forward_map |
|
| 260 | + EE_Config::$_module_forward_map = array(); |
|
| 261 | + // set _module_view_map |
|
| 262 | + EE_Config::$_module_view_map = array(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * load core plugin configuration |
|
| 268 | + * |
|
| 269 | + * @access private |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + private function _load_core_config() |
|
| 273 | + { |
|
| 274 | + // load_core_config__start hook |
|
| 275 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | + $espresso_config = $this->get_espresso_config(); |
|
| 277 | + foreach ($espresso_config as $config => $settings) { |
|
| 278 | + // load_core_config__start hook |
|
| 279 | + $settings = apply_filters( |
|
| 280 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | + $settings, |
|
| 282 | + $config, |
|
| 283 | + $this |
|
| 284 | + ); |
|
| 285 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | + // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | + if (method_exists($settings, 'populate')) { |
|
| 289 | + $this->{$config}->populate(); |
|
| 290 | + } |
|
| 291 | + if (method_exists($settings, 'do_hooks')) { |
|
| 292 | + $this->{$config}->do_hooks(); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | + $this->update_espresso_config(); |
|
| 298 | + } |
|
| 299 | + // load_core_config__end hook |
|
| 300 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * _verify_config |
|
| 306 | + * |
|
| 307 | + * @access protected |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + protected function _verify_config() |
|
| 311 | + { |
|
| 312 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | + ? $this->core |
|
| 314 | + : new EE_Core_Config(); |
|
| 315 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | + ? $this->organization |
|
| 318 | + : new EE_Organization_Config(); |
|
| 319 | + $this->organization = apply_filters( |
|
| 320 | + 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | + $this->organization |
|
| 322 | + ); |
|
| 323 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | + ? $this->currency |
|
| 325 | + : new EE_Currency_Config(); |
|
| 326 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | + ? $this->registration |
|
| 329 | + : new EE_Registration_Config(); |
|
| 330 | + $this->registration = apply_filters( |
|
| 331 | + 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | + $this->registration |
|
| 333 | + ); |
|
| 334 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | + ? $this->admin |
|
| 336 | + : new EE_Admin_Config(); |
|
| 337 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | + ? $this->template_settings |
|
| 340 | + : new EE_Template_Config(); |
|
| 341 | + $this->template_settings = apply_filters( |
|
| 342 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | + $this->template_settings |
|
| 344 | + ); |
|
| 345 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | + ? $this->map_settings |
|
| 347 | + : new EE_Map_Config(); |
|
| 348 | + $this->map_settings = apply_filters( |
|
| 349 | + 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | + $this->map_settings |
|
| 351 | + ); |
|
| 352 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | + ? $this->environment |
|
| 354 | + : new EE_Environment_Config(); |
|
| 355 | + $this->environment = apply_filters( |
|
| 356 | + 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | + $this->environment |
|
| 358 | + ); |
|
| 359 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | + ? $this->tax_settings |
|
| 361 | + : new EE_Tax_Config(); |
|
| 362 | + $this->tax_settings = apply_filters( |
|
| 363 | + 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | + $this->tax_settings |
|
| 365 | + ); |
|
| 366 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | + ? $this->messages |
|
| 369 | + : new EE_Messages_Config(); |
|
| 370 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | + ? $this->gateway |
|
| 372 | + : new EE_Gateway_Config(); |
|
| 373 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | + $this->legacy_shortcodes_manager = null; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * get_espresso_config |
|
| 380 | + * |
|
| 381 | + * @access public |
|
| 382 | + * @return array of espresso config stuff |
|
| 383 | + */ |
|
| 384 | + public function get_espresso_config() |
|
| 385 | + { |
|
| 386 | + // grab espresso configuration |
|
| 387 | + return apply_filters( |
|
| 388 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * double_check_config_comparison |
|
| 396 | + * |
|
| 397 | + * @access public |
|
| 398 | + * @param string $option |
|
| 399 | + * @param $old_value |
|
| 400 | + * @param $value |
|
| 401 | + */ |
|
| 402 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | + { |
|
| 404 | + // make sure we're checking the ee config |
|
| 405 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | + if ($value != $old_value) { |
|
| 409 | + // if they are NOT the same, then remove the hook, |
|
| 410 | + // which means the subsequent update results will be based solely on the update query results |
|
| 411 | + // the reason we do this is because, as stated above, |
|
| 412 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | + // If values are found to match their previous old value, |
|
| 415 | + // then WP bails before performing any update. |
|
| 416 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | + // MySQL MAY ALSO NOT perform the update because |
|
| 420 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * update_espresso_config |
|
| 431 | + * |
|
| 432 | + * @access public |
|
| 433 | + */ |
|
| 434 | + protected function _reset_espresso_addon_config() |
|
| 435 | + { |
|
| 436 | + $this->_addon_option_names = array(); |
|
| 437 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | + } |
|
| 442 | + $this->addons->{$addon_name} = null; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * update_espresso_config |
|
| 449 | + * |
|
| 450 | + * @access public |
|
| 451 | + * @param bool $add_success |
|
| 452 | + * @param bool $add_error |
|
| 453 | + * @return bool |
|
| 454 | + */ |
|
| 455 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | + { |
|
| 457 | + // don't allow config updates during WP heartbeats |
|
| 458 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 461 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | + // $clone = clone( self::$_instance ); |
|
| 463 | + // self::$_instance = NULL; |
|
| 464 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | + $this->_reset_espresso_addon_config(); |
|
| 466 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | + // but BEFORE the actual update occurs |
|
| 468 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | + $this->legacy_shortcodes_manager = null; |
|
| 472 | + // now update "ee_config" |
|
| 473 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | + // if not saved... check if the hook we just added still exists; |
|
| 477 | + // if it does, it means one of two things: |
|
| 478 | + // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | + // or... |
|
| 480 | + // the db update query returned 0 rows affected |
|
| 481 | + // (probably because the data value was the same from it's perspective) |
|
| 482 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | + // but just means no update occurred, so don't display an error to the user. |
|
| 484 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | + // then it means that something truly went wrong |
|
| 486 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | + // remove our action since we don't want it in the system anymore |
|
| 488 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | + // self::$_instance = $clone; |
|
| 491 | + // unset( $clone ); |
|
| 492 | + // if config remains the same or was updated successfully |
|
| 493 | + if ($saved) { |
|
| 494 | + if ($add_success) { |
|
| 495 | + EE_Error::add_success( |
|
| 496 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | + __FILE__, |
|
| 498 | + __FUNCTION__, |
|
| 499 | + __LINE__ |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + return true; |
|
| 503 | + } else { |
|
| 504 | + if ($add_error) { |
|
| 505 | + EE_Error::add_error( |
|
| 506 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | + __FILE__, |
|
| 508 | + __FUNCTION__, |
|
| 509 | + __LINE__ |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * _verify_config_params |
|
| 519 | + * |
|
| 520 | + * @access private |
|
| 521 | + * @param string $section |
|
| 522 | + * @param string $name |
|
| 523 | + * @param string $config_class |
|
| 524 | + * @param EE_Config_Base $config_obj |
|
| 525 | + * @param array $tests_to_run |
|
| 526 | + * @param bool $display_errors |
|
| 527 | + * @return bool TRUE on success, FALSE on fail |
|
| 528 | + */ |
|
| 529 | + private function _verify_config_params( |
|
| 530 | + $section = '', |
|
| 531 | + $name = '', |
|
| 532 | + $config_class = '', |
|
| 533 | + $config_obj = null, |
|
| 534 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | + $display_errors = true |
|
| 536 | + ) { |
|
| 537 | + try { |
|
| 538 | + foreach ($tests_to_run as $test) { |
|
| 539 | + switch ($test) { |
|
| 540 | + // TEST #1 : check that section was set |
|
| 541 | + case 1: |
|
| 542 | + if (empty($section)) { |
|
| 543 | + if ($display_errors) { |
|
| 544 | + throw new EE_Error( |
|
| 545 | + sprintf( |
|
| 546 | + __( |
|
| 547 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | + 'event_espresso' |
|
| 549 | + ), |
|
| 550 | + $config_class |
|
| 551 | + ) |
|
| 552 | + ); |
|
| 553 | + } |
|
| 554 | + return false; |
|
| 555 | + } |
|
| 556 | + break; |
|
| 557 | + // TEST #2 : check that settings section exists |
|
| 558 | + case 2: |
|
| 559 | + if (! isset($this->{$section})) { |
|
| 560 | + if ($display_errors) { |
|
| 561 | + throw new EE_Error( |
|
| 562 | + sprintf( |
|
| 563 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | + $section |
|
| 565 | + ) |
|
| 566 | + ); |
|
| 567 | + } |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + break; |
|
| 571 | + // TEST #3 : check that section is the proper format |
|
| 572 | + case 3: |
|
| 573 | + if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | + ) { |
|
| 575 | + if ($display_errors) { |
|
| 576 | + throw new EE_Error( |
|
| 577 | + sprintf( |
|
| 578 | + __( |
|
| 579 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 580 | + 'event_espresso' |
|
| 581 | + ), |
|
| 582 | + $section |
|
| 583 | + ) |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + return false; |
|
| 587 | + } |
|
| 588 | + break; |
|
| 589 | + // TEST #4 : check that config section name has been set |
|
| 590 | + case 4: |
|
| 591 | + if (empty($name)) { |
|
| 592 | + if ($display_errors) { |
|
| 593 | + throw new EE_Error( |
|
| 594 | + __( |
|
| 595 | + 'No name has been provided for the specific configuration section.', |
|
| 596 | + 'event_espresso' |
|
| 597 | + ) |
|
| 598 | + ); |
|
| 599 | + } |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + break; |
|
| 603 | + // TEST #5 : check that a config class name has been set |
|
| 604 | + case 5: |
|
| 605 | + if (empty($config_class)) { |
|
| 606 | + if ($display_errors) { |
|
| 607 | + throw new EE_Error( |
|
| 608 | + __( |
|
| 609 | + 'No class name has been provided for the specific configuration section.', |
|
| 610 | + 'event_espresso' |
|
| 611 | + ) |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + return false; |
|
| 615 | + } |
|
| 616 | + break; |
|
| 617 | + // TEST #6 : verify config class is accessible |
|
| 618 | + case 6: |
|
| 619 | + if (! class_exists($config_class)) { |
|
| 620 | + if ($display_errors) { |
|
| 621 | + throw new EE_Error( |
|
| 622 | + sprintf( |
|
| 623 | + __( |
|
| 624 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 625 | + 'event_espresso' |
|
| 626 | + ), |
|
| 627 | + $config_class |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + return false; |
|
| 632 | + } |
|
| 633 | + break; |
|
| 634 | + // TEST #7 : check that config has even been set |
|
| 635 | + case 7: |
|
| 636 | + if (! isset($this->{$section}->{$name})) { |
|
| 637 | + if ($display_errors) { |
|
| 638 | + throw new EE_Error( |
|
| 639 | + sprintf( |
|
| 640 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 641 | + $section, |
|
| 642 | + $name |
|
| 643 | + ) |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + return false; |
|
| 647 | + } else { |
|
| 648 | + // and make sure it's not serialized |
|
| 649 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 650 | + } |
|
| 651 | + break; |
|
| 652 | + // TEST #8 : check that config is the requested type |
|
| 653 | + case 8: |
|
| 654 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | + if ($display_errors) { |
|
| 656 | + throw new EE_Error( |
|
| 657 | + sprintf( |
|
| 658 | + __( |
|
| 659 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 660 | + 'event_espresso' |
|
| 661 | + ), |
|
| 662 | + $section, |
|
| 663 | + $name, |
|
| 664 | + $config_class |
|
| 665 | + ) |
|
| 666 | + ); |
|
| 667 | + } |
|
| 668 | + return false; |
|
| 669 | + } |
|
| 670 | + break; |
|
| 671 | + // TEST #9 : verify config object |
|
| 672 | + case 9: |
|
| 673 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | + if ($display_errors) { |
|
| 675 | + throw new EE_Error( |
|
| 676 | + sprintf( |
|
| 677 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 678 | + print_r($config_obj, true) |
|
| 679 | + ) |
|
| 680 | + ); |
|
| 681 | + } |
|
| 682 | + return false; |
|
| 683 | + } |
|
| 684 | + break; |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + } catch (EE_Error $e) { |
|
| 688 | + $e->get_error(); |
|
| 689 | + } |
|
| 690 | + // you have successfully run the gauntlet |
|
| 691 | + return true; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * _generate_config_option_name |
|
| 697 | + * |
|
| 698 | + * @access protected |
|
| 699 | + * @param string $section |
|
| 700 | + * @param string $name |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 704 | + { |
|
| 705 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * _set_config_class |
|
| 711 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 712 | + * |
|
| 713 | + * @access private |
|
| 714 | + * @param string $config_class |
|
| 715 | + * @param string $name |
|
| 716 | + * @return string |
|
| 717 | + */ |
|
| 718 | + private function _set_config_class($config_class = '', $name = '') |
|
| 719 | + { |
|
| 720 | + return ! empty($config_class) |
|
| 721 | + ? $config_class |
|
| 722 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * set_config |
|
| 728 | + * |
|
| 729 | + * @access protected |
|
| 730 | + * @param string $section |
|
| 731 | + * @param string $name |
|
| 732 | + * @param string $config_class |
|
| 733 | + * @param EE_Config_Base $config_obj |
|
| 734 | + * @return EE_Config_Base |
|
| 735 | + */ |
|
| 736 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 737 | + { |
|
| 738 | + // ensure config class is set to something |
|
| 739 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 740 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 741 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | + return null; |
|
| 743 | + } |
|
| 744 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 745 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 746 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | + $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 748 | + $this->update_addon_option_names(); |
|
| 749 | + } |
|
| 750 | + // verify the incoming config object but suppress errors |
|
| 751 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | + $config_obj = new $config_class(); |
|
| 753 | + } |
|
| 754 | + if (get_option($config_option_name)) { |
|
| 755 | + EE_Config::log($config_option_name); |
|
| 756 | + update_option($config_option_name, $config_obj); |
|
| 757 | + $this->{$section}->{$name} = $config_obj; |
|
| 758 | + return $this->{$section}->{$name}; |
|
| 759 | + } else { |
|
| 760 | + // create a wp-option for this config |
|
| 761 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 762 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 763 | + return $this->{$section}->{$name}; |
|
| 764 | + } else { |
|
| 765 | + EE_Error::add_error( |
|
| 766 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 767 | + __FILE__, |
|
| 768 | + __FUNCTION__, |
|
| 769 | + __LINE__ |
|
| 770 | + ); |
|
| 771 | + return null; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * update_config |
|
| 779 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 780 | + * |
|
| 781 | + * @access public |
|
| 782 | + * @param string $section |
|
| 783 | + * @param string $name |
|
| 784 | + * @param EE_Config_Base|string $config_obj |
|
| 785 | + * @param bool $throw_errors |
|
| 786 | + * @return bool |
|
| 787 | + */ |
|
| 788 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 789 | + { |
|
| 790 | + // don't allow config updates during WP heartbeats |
|
| 791 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 792 | + return false; |
|
| 793 | + } |
|
| 794 | + $config_obj = maybe_unserialize($config_obj); |
|
| 795 | + // get class name of the incoming object |
|
| 796 | + $config_class = get_class($config_obj); |
|
| 797 | + // run tests 1-5 and 9 to verify config |
|
| 798 | + if (! $this->_verify_config_params( |
|
| 799 | + $section, |
|
| 800 | + $name, |
|
| 801 | + $config_class, |
|
| 802 | + $config_obj, |
|
| 803 | + array(1, 2, 3, 4, 7, 9) |
|
| 804 | + ) |
|
| 805 | + ) { |
|
| 806 | + return false; |
|
| 807 | + } |
|
| 808 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 809 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 810 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 811 | + // save new config to db |
|
| 812 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 813 | + return true; |
|
| 814 | + } |
|
| 815 | + } else { |
|
| 816 | + // first check if the record already exists |
|
| 817 | + $existing_config = get_option($config_option_name); |
|
| 818 | + $config_obj = serialize($config_obj); |
|
| 819 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 820 | + if ($existing_config == $config_obj) { |
|
| 821 | + $this->{$section}->{$name} = $config_obj; |
|
| 822 | + return true; |
|
| 823 | + } elseif (update_option($config_option_name, $config_obj)) { |
|
| 824 | + EE_Config::log($config_option_name); |
|
| 825 | + // update wp-option for this config class |
|
| 826 | + $this->{$section}->{$name} = $config_obj; |
|
| 827 | + return true; |
|
| 828 | + } elseif ($throw_errors) { |
|
| 829 | + EE_Error::add_error( |
|
| 830 | + sprintf( |
|
| 831 | + __( |
|
| 832 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 833 | + 'event_espresso' |
|
| 834 | + ), |
|
| 835 | + $config_class, |
|
| 836 | + 'EE_Config->' . $section . '->' . $name |
|
| 837 | + ), |
|
| 838 | + __FILE__, |
|
| 839 | + __FUNCTION__, |
|
| 840 | + __LINE__ |
|
| 841 | + ); |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + return false; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * get_config |
|
| 850 | + * |
|
| 851 | + * @access public |
|
| 852 | + * @param string $section |
|
| 853 | + * @param string $name |
|
| 854 | + * @param string $config_class |
|
| 855 | + * @return mixed EE_Config_Base | NULL |
|
| 856 | + */ |
|
| 857 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | + { |
|
| 859 | + // ensure config class is set to something |
|
| 860 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | + return null; |
|
| 864 | + } |
|
| 865 | + // now test if the requested config object exists, but suppress errors |
|
| 866 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | + // config already exists, so pass it back |
|
| 868 | + return $this->{$section}->{$name}; |
|
| 869 | + } |
|
| 870 | + // load config option from db if it exists |
|
| 871 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | + // verify the newly retrieved config object, but suppress errors |
|
| 873 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | + // config is good, so set it and pass it back |
|
| 875 | + $this->{$section}->{$name} = $config_obj; |
|
| 876 | + return $this->{$section}->{$name}; |
|
| 877 | + } |
|
| 878 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | + // verify the newly created config object |
|
| 881 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | + return $this->{$section}->{$name}; |
|
| 883 | + } else { |
|
| 884 | + EE_Error::add_error( |
|
| 885 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | + __FILE__, |
|
| 887 | + __FUNCTION__, |
|
| 888 | + __LINE__ |
|
| 889 | + ); |
|
| 890 | + } |
|
| 891 | + return null; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * get_config_option |
|
| 897 | + * |
|
| 898 | + * @access public |
|
| 899 | + * @param string $config_option_name |
|
| 900 | + * @return mixed EE_Config_Base | FALSE |
|
| 901 | + */ |
|
| 902 | + public function get_config_option($config_option_name = '') |
|
| 903 | + { |
|
| 904 | + // retrieve the wp-option for this config class. |
|
| 905 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 906 | + if (empty($config_option)) { |
|
| 907 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 908 | + } |
|
| 909 | + return $config_option; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * log |
|
| 915 | + * |
|
| 916 | + * @param string $config_option_name |
|
| 917 | + */ |
|
| 918 | + public static function log($config_option_name = '') |
|
| 919 | + { |
|
| 920 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 921 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 922 | + // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 923 | + $_request = $_REQUEST; |
|
| 924 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 925 | + $config_log[ (string) microtime(true) ] = array( |
|
| 926 | + 'config_name' => $config_option_name, |
|
| 927 | + 'request' => $_request, |
|
| 928 | + ); |
|
| 929 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * trim_log |
|
| 936 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 937 | + */ |
|
| 938 | + public static function trim_log() |
|
| 939 | + { |
|
| 940 | + if (! EE_Config::logging_enabled()) { |
|
| 941 | + return; |
|
| 942 | + } |
|
| 943 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 944 | + $log_length = count($config_log); |
|
| 945 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 946 | + ksort($config_log); |
|
| 947 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 948 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * get_page_for_posts |
|
| 955 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 956 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 957 | + * |
|
| 958 | + * @access public |
|
| 959 | + * @return string |
|
| 960 | + */ |
|
| 961 | + public static function get_page_for_posts() |
|
| 962 | + { |
|
| 963 | + $page_for_posts = get_option('page_for_posts'); |
|
| 964 | + if (! $page_for_posts) { |
|
| 965 | + return 'posts'; |
|
| 966 | + } |
|
| 967 | + /** @type WPDB $wpdb */ |
|
| 968 | + global $wpdb; |
|
| 969 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 970 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * register_shortcodes_and_modules. |
|
| 976 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 977 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 978 | + * so they can help trigger maintenance mode if it's needed |
|
| 979 | + * |
|
| 980 | + * @access public |
|
| 981 | + * @return void |
|
| 982 | + */ |
|
| 983 | + public function register_shortcodes_and_modules() |
|
| 984 | + { |
|
| 985 | + // allow modules to set hooks for the rest of the system |
|
| 986 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * initialize_shortcodes_and_modules |
|
| 992 | + * meaning they can start adding their hooks to get stuff done |
|
| 993 | + * |
|
| 994 | + * @access public |
|
| 995 | + * @return void |
|
| 996 | + */ |
|
| 997 | + public function initialize_shortcodes_and_modules() |
|
| 998 | + { |
|
| 999 | + // allow modules to set hooks for the rest of the system |
|
| 1000 | + $this->_initialize_modules(); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * widgets_init |
|
| 1006 | + * |
|
| 1007 | + * @access private |
|
| 1008 | + * @return void |
|
| 1009 | + */ |
|
| 1010 | + public function widgets_init() |
|
| 1011 | + { |
|
| 1012 | + // only init widgets on admin pages when not in complete maintenance, and |
|
| 1013 | + // on frontend when not in any maintenance mode |
|
| 1014 | + if (! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | + || ( |
|
| 1016 | + is_admin() |
|
| 1017 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1018 | + ) |
|
| 1019 | + ) { |
|
| 1020 | + // grab list of installed widgets |
|
| 1021 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1022 | + // filter list of modules to register |
|
| 1023 | + $widgets_to_register = apply_filters( |
|
| 1024 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1025 | + $widgets_to_register |
|
| 1026 | + ); |
|
| 1027 | + if (! empty($widgets_to_register)) { |
|
| 1028 | + // cycle thru widget folders |
|
| 1029 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1030 | + // add to list of installed widget modules |
|
| 1031 | + EE_Config::register_ee_widget($widget_path); |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 1034 | + // filter list of installed modules |
|
| 1035 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1036 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1037 | + EE_Registry::instance()->widgets |
|
| 1038 | + ); |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * register_ee_widget - makes core aware of this widget |
|
| 1045 | + * |
|
| 1046 | + * @access public |
|
| 1047 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1048 | + * @return void |
|
| 1049 | + */ |
|
| 1050 | + public static function register_ee_widget($widget_path = null) |
|
| 1051 | + { |
|
| 1052 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1053 | + $widget_ext = '.widget.php'; |
|
| 1054 | + // make all separators match |
|
| 1055 | + $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1056 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1057 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1058 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1059 | + $file_name = explode('.', basename($widget_path)); |
|
| 1060 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1061 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1062 | + // sanitize shortcode directory name |
|
| 1063 | + $widget = sanitize_key($widget); |
|
| 1064 | + // now we need to rebuild the shortcode path |
|
| 1065 | + $widget_path = explode(DS, $widget_path); |
|
| 1066 | + // remove last segment |
|
| 1067 | + array_pop($widget_path); |
|
| 1068 | + // glue it back together |
|
| 1069 | + $widget_path = implode(DS, $widget_path); |
|
| 1070 | + } else { |
|
| 1071 | + // grab and sanitize widget directory name |
|
| 1072 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1073 | + } |
|
| 1074 | + // create classname from widget directory name |
|
| 1075 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1076 | + // add class prefix |
|
| 1077 | + $widget_class = 'EEW_' . $widget; |
|
| 1078 | + // does the widget exist ? |
|
| 1079 | + if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1080 | + $msg = sprintf( |
|
| 1081 | + __( |
|
| 1082 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1083 | + 'event_espresso' |
|
| 1084 | + ), |
|
| 1085 | + $widget_class, |
|
| 1086 | + $widget_path . DS . $widget_class . $widget_ext |
|
| 1087 | + ); |
|
| 1088 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | + return; |
|
| 1090 | + } |
|
| 1091 | + // load the widget class file |
|
| 1092 | + require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1093 | + // verify that class exists |
|
| 1094 | + if (! class_exists($widget_class)) { |
|
| 1095 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1096 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | + return; |
|
| 1098 | + } |
|
| 1099 | + register_widget($widget_class); |
|
| 1100 | + // add to array of registered widgets |
|
| 1101 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * _register_modules |
|
| 1107 | + * |
|
| 1108 | + * @access private |
|
| 1109 | + * @return array |
|
| 1110 | + */ |
|
| 1111 | + private function _register_modules() |
|
| 1112 | + { |
|
| 1113 | + // grab list of installed modules |
|
| 1114 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1115 | + // filter list of modules to register |
|
| 1116 | + $modules_to_register = apply_filters( |
|
| 1117 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1118 | + $modules_to_register |
|
| 1119 | + ); |
|
| 1120 | + if (! empty($modules_to_register)) { |
|
| 1121 | + // loop through folders |
|
| 1122 | + foreach ($modules_to_register as $module_path) { |
|
| 1123 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1124 | + if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1126 | + ) { |
|
| 1127 | + // add to list of installed modules |
|
| 1128 | + EE_Config::register_module($module_path); |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | + } |
|
| 1132 | + // filter list of installed modules |
|
| 1133 | + return apply_filters( |
|
| 1134 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1135 | + EE_Registry::instance()->modules |
|
| 1136 | + ); |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + |
|
| 1140 | + /** |
|
| 1141 | + * register_module - makes core aware of this module |
|
| 1142 | + * |
|
| 1143 | + * @access public |
|
| 1144 | + * @param string $module_path - full path up to and including module folder |
|
| 1145 | + * @return bool |
|
| 1146 | + */ |
|
| 1147 | + public static function register_module($module_path = null) |
|
| 1148 | + { |
|
| 1149 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1150 | + $module_ext = '.module.php'; |
|
| 1151 | + // make all separators match |
|
| 1152 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1153 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1154 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1155 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1156 | + $module_file = explode('.', basename($module_path)); |
|
| 1157 | + // now we need to rebuild the shortcode path |
|
| 1158 | + $module_path = explode(DS, $module_path); |
|
| 1159 | + // remove last segment |
|
| 1160 | + array_pop($module_path); |
|
| 1161 | + // glue it back together |
|
| 1162 | + $module_path = implode(DS, $module_path) . DS; |
|
| 1163 | + // take first segment from file name pieces and sanitize it |
|
| 1164 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1165 | + // ensure class prefix is added |
|
| 1166 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1167 | + } else { |
|
| 1168 | + // we need to generate the filename based off of the folder name |
|
| 1169 | + // grab and sanitize module name |
|
| 1170 | + $module = strtolower(basename($module_path)); |
|
| 1171 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1172 | + // like trailingslashit() |
|
| 1173 | + $module_path = rtrim($module_path, DS) . DS; |
|
| 1174 | + // create classname from module directory name |
|
| 1175 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1176 | + // add class prefix |
|
| 1177 | + $module_class = 'EED_' . $module; |
|
| 1178 | + } |
|
| 1179 | + // does the module exist ? |
|
| 1180 | + if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1181 | + $msg = sprintf( |
|
| 1182 | + __( |
|
| 1183 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1184 | + 'event_espresso' |
|
| 1185 | + ), |
|
| 1186 | + $module |
|
| 1187 | + ); |
|
| 1188 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | + return false; |
|
| 1190 | + } |
|
| 1191 | + // load the module class file |
|
| 1192 | + require_once($module_path . $module_class . $module_ext); |
|
| 1193 | + // verify that class exists |
|
| 1194 | + if (! class_exists($module_class)) { |
|
| 1195 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1196 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | + return false; |
|
| 1198 | + } |
|
| 1199 | + // add to array of registered modules |
|
| 1200 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1201 | + do_action( |
|
| 1202 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1203 | + $module_class, |
|
| 1204 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1205 | + ); |
|
| 1206 | + return true; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * _initialize_modules |
|
| 1212 | + * allow modules to set hooks for the rest of the system |
|
| 1213 | + * |
|
| 1214 | + * @access private |
|
| 1215 | + * @return void |
|
| 1216 | + */ |
|
| 1217 | + private function _initialize_modules() |
|
| 1218 | + { |
|
| 1219 | + // cycle thru shortcode folders |
|
| 1220 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1221 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1222 | + // which set hooks ? |
|
| 1223 | + if (is_admin()) { |
|
| 1224 | + // fire immediately |
|
| 1225 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1226 | + } else { |
|
| 1227 | + // delay until other systems are online |
|
| 1228 | + add_action( |
|
| 1229 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1230 | + array($module_class, 'set_hooks') |
|
| 1231 | + ); |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + |
|
| 1237 | + /** |
|
| 1238 | + * register_route - adds module method routes to route_map |
|
| 1239 | + * |
|
| 1240 | + * @access public |
|
| 1241 | + * @param string $route - "pretty" public alias for module method |
|
| 1242 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1243 | + * @param string $method_name - the actual module method to be routed to |
|
| 1244 | + * @param string $key - url param key indicating a route is being called |
|
| 1245 | + * @return bool |
|
| 1246 | + */ |
|
| 1247 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1248 | + { |
|
| 1249 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1250 | + $module = str_replace('EED_', '', $module); |
|
| 1251 | + $module_class = 'EED_' . $module; |
|
| 1252 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1254 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | + return false; |
|
| 1256 | + } |
|
| 1257 | + if (empty($route)) { |
|
| 1258 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1259 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | + return false; |
|
| 1261 | + } |
|
| 1262 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1263 | + $msg = sprintf( |
|
| 1264 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1265 | + $route |
|
| 1266 | + ); |
|
| 1267 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | + return false; |
|
| 1269 | + } |
|
| 1270 | + EE_Config::$_module_route_map[ $key ][ $route ] = array('EED_' . $module, $method_name); |
|
| 1271 | + return true; |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + |
|
| 1275 | + /** |
|
| 1276 | + * get_route - get module method route |
|
| 1277 | + * |
|
| 1278 | + * @access public |
|
| 1279 | + * @param string $route - "pretty" public alias for module method |
|
| 1280 | + * @param string $key - url param key indicating a route is being called |
|
| 1281 | + * @return string |
|
| 1282 | + */ |
|
| 1283 | + public static function get_route($route = null, $key = 'ee') |
|
| 1284 | + { |
|
| 1285 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1286 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1287 | + if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | + return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1289 | + } |
|
| 1290 | + return null; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + /** |
|
| 1295 | + * get_routes - get ALL module method routes |
|
| 1296 | + * |
|
| 1297 | + * @access public |
|
| 1298 | + * @return array |
|
| 1299 | + */ |
|
| 1300 | + public static function get_routes() |
|
| 1301 | + { |
|
| 1302 | + return EE_Config::$_module_route_map; |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + |
|
| 1306 | + /** |
|
| 1307 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1308 | + * |
|
| 1309 | + * @access public |
|
| 1310 | + * @param string $route - "pretty" public alias for module method |
|
| 1311 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1312 | + * class, allows different forwards to be served based on status |
|
| 1313 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1314 | + * @param string $key - url param key indicating a route is being called |
|
| 1315 | + * @return bool |
|
| 1316 | + */ |
|
| 1317 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1318 | + { |
|
| 1319 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1320 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1321 | + $msg = sprintf( |
|
| 1322 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1323 | + $route |
|
| 1324 | + ); |
|
| 1325 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | + return false; |
|
| 1327 | + } |
|
| 1328 | + if (empty($forward)) { |
|
| 1329 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1330 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | + return false; |
|
| 1332 | + } |
|
| 1333 | + if (is_array($forward)) { |
|
| 1334 | + if (! isset($forward[1])) { |
|
| 1335 | + $msg = sprintf( |
|
| 1336 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1337 | + $route |
|
| 1338 | + ); |
|
| 1339 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | + return false; |
|
| 1341 | + } |
|
| 1342 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1343 | + $msg = sprintf( |
|
| 1344 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1345 | + $forward[1], |
|
| 1346 | + $route |
|
| 1347 | + ); |
|
| 1348 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | + return false; |
|
| 1350 | + } |
|
| 1351 | + } elseif (! function_exists($forward)) { |
|
| 1352 | + $msg = sprintf( |
|
| 1353 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1354 | + $forward, |
|
| 1355 | + $route |
|
| 1356 | + ); |
|
| 1357 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | + return false; |
|
| 1359 | + } |
|
| 1360 | + EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1361 | + return true; |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + /** |
|
| 1366 | + * get_forward - get forwarding route |
|
| 1367 | + * |
|
| 1368 | + * @access public |
|
| 1369 | + * @param string $route - "pretty" public alias for module method |
|
| 1370 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1371 | + * allows different forwards to be served based on status |
|
| 1372 | + * @param string $key - url param key indicating a route is being called |
|
| 1373 | + * @return string |
|
| 1374 | + */ |
|
| 1375 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1376 | + { |
|
| 1377 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1378 | + if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1379 | + return apply_filters( |
|
| 1380 | + 'FHEE__EE_Config__get_forward', |
|
| 1381 | + EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1382 | + $route, |
|
| 1383 | + $status |
|
| 1384 | + ); |
|
| 1385 | + } |
|
| 1386 | + return null; |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + |
|
| 1390 | + /** |
|
| 1391 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1392 | + * results |
|
| 1393 | + * |
|
| 1394 | + * @access public |
|
| 1395 | + * @param string $route - "pretty" public alias for module method |
|
| 1396 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1397 | + * allows different views to be served based on status |
|
| 1398 | + * @param string $view |
|
| 1399 | + * @param string $key - url param key indicating a route is being called |
|
| 1400 | + * @return bool |
|
| 1401 | + */ |
|
| 1402 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1403 | + { |
|
| 1404 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1405 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1406 | + $msg = sprintf( |
|
| 1407 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1408 | + $route |
|
| 1409 | + ); |
|
| 1410 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | + return false; |
|
| 1412 | + } |
|
| 1413 | + if (! is_readable($view)) { |
|
| 1414 | + $msg = sprintf( |
|
| 1415 | + __( |
|
| 1416 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1417 | + 'event_espresso' |
|
| 1418 | + ), |
|
| 1419 | + $view |
|
| 1420 | + ); |
|
| 1421 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | + return false; |
|
| 1423 | + } |
|
| 1424 | + EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1425 | + return true; |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * get_view - get view for route and status |
|
| 1431 | + * |
|
| 1432 | + * @access public |
|
| 1433 | + * @param string $route - "pretty" public alias for module method |
|
| 1434 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1435 | + * allows different views to be served based on status |
|
| 1436 | + * @param string $key - url param key indicating a route is being called |
|
| 1437 | + * @return string |
|
| 1438 | + */ |
|
| 1439 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1440 | + { |
|
| 1441 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1442 | + if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1443 | + return apply_filters( |
|
| 1444 | + 'FHEE__EE_Config__get_view', |
|
| 1445 | + EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1446 | + $route, |
|
| 1447 | + $status |
|
| 1448 | + ); |
|
| 1449 | + } |
|
| 1450 | + return null; |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + |
|
| 1454 | + public function update_addon_option_names() |
|
| 1455 | + { |
|
| 1456 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + |
|
| 1460 | + public function shutdown() |
|
| 1461 | + { |
|
| 1462 | + $this->update_addon_option_names(); |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * @return LegacyShortcodesManager |
|
| 1468 | + */ |
|
| 1469 | + public static function getLegacyShortcodesManager() |
|
| 1470 | + { |
|
| 1471 | + |
|
| 1472 | + if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1474 | + EE_Registry::instance() |
|
| 1475 | + ); |
|
| 1476 | + } |
|
| 1477 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * register_shortcode - makes core aware of this shortcode |
|
| 1483 | + * |
|
| 1484 | + * @deprecated 4.9.26 |
|
| 1485 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1486 | + * @return bool |
|
| 1487 | + */ |
|
| 1488 | + public static function register_shortcode($shortcode_path = null) |
|
| 1489 | + { |
|
| 1490 | + EE_Error::doing_it_wrong( |
|
| 1491 | + __METHOD__, |
|
| 1492 | + __( |
|
| 1493 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1494 | + 'event_espresso' |
|
| 1495 | + ), |
|
| 1496 | + '4.9.26' |
|
| 1497 | + ); |
|
| 1498 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1499 | + } |
|
| 1500 | +} |
|
| 2277 | 1501 | |
| 2278 | - /** |
|
| 2279 | - * ReCaptcha Type |
|
| 2280 | - * |
|
| 2281 | - * @var string $recaptcha_type |
|
| 2282 | - * options: 'audio', 'image' |
|
| 2283 | - */ |
|
| 2284 | - public $recaptcha_type; |
|
| 1502 | +/** |
|
| 1503 | + * Base class used for config classes. These classes should generally not have |
|
| 1504 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1505 | + * basically, they should just be well-defined stdClasses |
|
| 1506 | + */ |
|
| 1507 | +class EE_Config_Base |
|
| 1508 | +{ |
|
| 2285 | 1509 | |
| 2286 | - /** |
|
| 2287 | - * ReCaptcha language |
|
| 2288 | - * |
|
| 2289 | - * @var string $recaptcha_language |
|
| 2290 | - * eg 'en' |
|
| 2291 | - */ |
|
| 2292 | - public $recaptcha_language; |
|
| 1510 | + /** |
|
| 1511 | + * Utility function for escaping the value of a property and returning. |
|
| 1512 | + * |
|
| 1513 | + * @param string $property property name (checks to see if exists). |
|
| 1514 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1515 | + * @throws \EE_Error |
|
| 1516 | + */ |
|
| 1517 | + public function get_pretty($property) |
|
| 1518 | + { |
|
| 1519 | + if (! property_exists($this, $property)) { |
|
| 1520 | + throw new EE_Error( |
|
| 1521 | + sprintf( |
|
| 1522 | + __( |
|
| 1523 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1524 | + 'event_espresso' |
|
| 1525 | + ), |
|
| 1526 | + get_class($this), |
|
| 1527 | + $property |
|
| 1528 | + ) |
|
| 1529 | + ); |
|
| 1530 | + } |
|
| 1531 | + // just handling escaping of strings for now. |
|
| 1532 | + if (is_string($this->{$property})) { |
|
| 1533 | + return stripslashes($this->{$property}); |
|
| 1534 | + } |
|
| 1535 | + return $this->{$property}; |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + |
|
| 1539 | + public function populate() |
|
| 1540 | + { |
|
| 1541 | + // grab defaults via a new instance of this class. |
|
| 1542 | + $class_name = get_class($this); |
|
| 1543 | + $defaults = new $class_name; |
|
| 1544 | + // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1545 | + // default from our $defaults object. |
|
| 1546 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1547 | + if ($this->{$property} === null) { |
|
| 1548 | + $this->{$property} = $value; |
|
| 1549 | + } |
|
| 1550 | + } |
|
| 1551 | + // cleanup |
|
| 1552 | + unset($defaults); |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * __isset |
|
| 1558 | + * |
|
| 1559 | + * @param $a |
|
| 1560 | + * @return bool |
|
| 1561 | + */ |
|
| 1562 | + public function __isset($a) |
|
| 1563 | + { |
|
| 1564 | + return false; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + |
|
| 1568 | + /** |
|
| 1569 | + * __unset |
|
| 1570 | + * |
|
| 1571 | + * @param $a |
|
| 1572 | + * @return bool |
|
| 1573 | + */ |
|
| 1574 | + public function __unset($a) |
|
| 1575 | + { |
|
| 1576 | + return false; |
|
| 1577 | + } |
|
| 1578 | + |
|
| 1579 | + |
|
| 1580 | + /** |
|
| 1581 | + * __clone |
|
| 1582 | + */ |
|
| 1583 | + public function __clone() |
|
| 1584 | + { |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * __wakeup |
|
| 1590 | + */ |
|
| 1591 | + public function __wakeup() |
|
| 1592 | + { |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * __destruct |
|
| 1598 | + */ |
|
| 1599 | + public function __destruct() |
|
| 1600 | + { |
|
| 1601 | + } |
|
| 1602 | +} |
|
| 2293 | 1603 | |
| 2294 | - /** |
|
| 2295 | - * ReCaptcha public key |
|
| 2296 | - * |
|
| 2297 | - * @var string $recaptcha_publickey |
|
| 2298 | - */ |
|
| 2299 | - public $recaptcha_publickey; |
|
| 1604 | +/** |
|
| 1605 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1606 | + */ |
|
| 1607 | +class EE_Core_Config extends EE_Config_Base |
|
| 1608 | +{ |
|
| 2300 | 1609 | |
| 2301 | - /** |
|
| 2302 | - * ReCaptcha private key |
|
| 2303 | - * |
|
| 2304 | - * @var string $recaptcha_privatekey |
|
| 2305 | - */ |
|
| 2306 | - public $recaptcha_privatekey; |
|
| 1610 | + const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1611 | + |
|
| 1612 | + |
|
| 1613 | + public $current_blog_id; |
|
| 1614 | + |
|
| 1615 | + public $ee_ueip_optin; |
|
| 1616 | + |
|
| 1617 | + public $ee_ueip_has_notified; |
|
| 1618 | + |
|
| 1619 | + /** |
|
| 1620 | + * Not to be confused with the 4 critical page variables (See |
|
| 1621 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1622 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1623 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1624 | + * |
|
| 1625 | + * @var array |
|
| 1626 | + */ |
|
| 1627 | + public $post_shortcodes; |
|
| 1628 | + |
|
| 1629 | + public $module_route_map; |
|
| 1630 | + |
|
| 1631 | + public $module_forward_map; |
|
| 1632 | + |
|
| 1633 | + public $module_view_map; |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1637 | + * |
|
| 1638 | + * @var int |
|
| 1639 | + */ |
|
| 1640 | + public $reg_page_id; |
|
| 1641 | + |
|
| 1642 | + public $txn_page_id; |
|
| 1643 | + |
|
| 1644 | + public $thank_you_page_id; |
|
| 1645 | + |
|
| 1646 | + public $cancel_page_id; |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1650 | + * |
|
| 1651 | + * @var int |
|
| 1652 | + */ |
|
| 1653 | + public $reg_page_url; |
|
| 1654 | + |
|
| 1655 | + public $txn_page_url; |
|
| 1656 | + |
|
| 1657 | + public $thank_you_page_url; |
|
| 1658 | + |
|
| 1659 | + public $cancel_page_url; |
|
| 1660 | + |
|
| 1661 | + /** |
|
| 1662 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1663 | + */ |
|
| 1664 | + public $event_cpt_slug; |
|
| 1665 | + |
|
| 1666 | + /** |
|
| 1667 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1668 | + * request across blog switches in a multisite context. |
|
| 1669 | + * Avoids extra queries to the db for this option. |
|
| 1670 | + * |
|
| 1671 | + * @var bool |
|
| 1672 | + */ |
|
| 1673 | + public static $ee_ueip_option; |
|
| 1674 | + |
|
| 1675 | + |
|
| 1676 | + /** |
|
| 1677 | + * class constructor |
|
| 1678 | + * |
|
| 1679 | + * @access public |
|
| 1680 | + */ |
|
| 1681 | + public function __construct() |
|
| 1682 | + { |
|
| 1683 | + // set default organization settings |
|
| 1684 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1685 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1686 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1687 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1688 | + $this->post_shortcodes = array(); |
|
| 1689 | + $this->module_route_map = array(); |
|
| 1690 | + $this->module_forward_map = array(); |
|
| 1691 | + $this->module_view_map = array(); |
|
| 1692 | + // critical EE page IDs |
|
| 1693 | + $this->reg_page_id = 0; |
|
| 1694 | + $this->txn_page_id = 0; |
|
| 1695 | + $this->thank_you_page_id = 0; |
|
| 1696 | + $this->cancel_page_id = 0; |
|
| 1697 | + // critical EE page URLs |
|
| 1698 | + $this->reg_page_url = ''; |
|
| 1699 | + $this->txn_page_url = ''; |
|
| 1700 | + $this->thank_you_page_url = ''; |
|
| 1701 | + $this->cancel_page_url = ''; |
|
| 1702 | + // cpt slugs |
|
| 1703 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1704 | + // ueip constant check |
|
| 1705 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1706 | + $this->ee_ueip_optin = false; |
|
| 1707 | + $this->ee_ueip_has_notified = true; |
|
| 1708 | + } |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * @return array |
|
| 1714 | + */ |
|
| 1715 | + public function get_critical_pages_array() |
|
| 1716 | + { |
|
| 1717 | + return array( |
|
| 1718 | + $this->reg_page_id, |
|
| 1719 | + $this->txn_page_id, |
|
| 1720 | + $this->thank_you_page_id, |
|
| 1721 | + $this->cancel_page_id, |
|
| 1722 | + ); |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + |
|
| 1726 | + /** |
|
| 1727 | + * @return array |
|
| 1728 | + */ |
|
| 1729 | + public function get_critical_pages_shortcodes_array() |
|
| 1730 | + { |
|
| 1731 | + return array( |
|
| 1732 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1733 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1734 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1735 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1736 | + ); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * gets/returns URL for EE reg_page |
|
| 1742 | + * |
|
| 1743 | + * @access public |
|
| 1744 | + * @return string |
|
| 1745 | + */ |
|
| 1746 | + public function reg_page_url() |
|
| 1747 | + { |
|
| 1748 | + if (! $this->reg_page_url) { |
|
| 1749 | + $this->reg_page_url = add_query_arg( |
|
| 1750 | + array('uts' => time()), |
|
| 1751 | + get_permalink($this->reg_page_id) |
|
| 1752 | + ) . '#checkout'; |
|
| 1753 | + } |
|
| 1754 | + return $this->reg_page_url; |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + |
|
| 1758 | + /** |
|
| 1759 | + * gets/returns URL for EE txn_page |
|
| 1760 | + * |
|
| 1761 | + * @param array $query_args like what gets passed to |
|
| 1762 | + * add_query_arg() as the first argument |
|
| 1763 | + * @access public |
|
| 1764 | + * @return string |
|
| 1765 | + */ |
|
| 1766 | + public function txn_page_url($query_args = array()) |
|
| 1767 | + { |
|
| 1768 | + if (! $this->txn_page_url) { |
|
| 1769 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1770 | + } |
|
| 1771 | + if ($query_args) { |
|
| 1772 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1773 | + } else { |
|
| 1774 | + return $this->txn_page_url; |
|
| 1775 | + } |
|
| 1776 | + } |
|
| 1777 | + |
|
| 1778 | + |
|
| 1779 | + /** |
|
| 1780 | + * gets/returns URL for EE thank_you_page |
|
| 1781 | + * |
|
| 1782 | + * @param array $query_args like what gets passed to |
|
| 1783 | + * add_query_arg() as the first argument |
|
| 1784 | + * @access public |
|
| 1785 | + * @return string |
|
| 1786 | + */ |
|
| 1787 | + public function thank_you_page_url($query_args = array()) |
|
| 1788 | + { |
|
| 1789 | + if (! $this->thank_you_page_url) { |
|
| 1790 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1791 | + } |
|
| 1792 | + if ($query_args) { |
|
| 1793 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1794 | + } else { |
|
| 1795 | + return $this->thank_you_page_url; |
|
| 1796 | + } |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * gets/returns URL for EE cancel_page |
|
| 1802 | + * |
|
| 1803 | + * @access public |
|
| 1804 | + * @return string |
|
| 1805 | + */ |
|
| 1806 | + public function cancel_page_url() |
|
| 1807 | + { |
|
| 1808 | + if (! $this->cancel_page_url) { |
|
| 1809 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1810 | + } |
|
| 1811 | + return $this->cancel_page_url; |
|
| 1812 | + } |
|
| 1813 | + |
|
| 1814 | + |
|
| 1815 | + /** |
|
| 1816 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1817 | + * |
|
| 1818 | + * @since 4.7.5 |
|
| 1819 | + */ |
|
| 1820 | + protected function _reset_urls() |
|
| 1821 | + { |
|
| 1822 | + $this->reg_page_url = ''; |
|
| 1823 | + $this->txn_page_url = ''; |
|
| 1824 | + $this->cancel_page_url = ''; |
|
| 1825 | + $this->thank_you_page_url = ''; |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + |
|
| 1829 | + /** |
|
| 1830 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1831 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1832 | + * on the main site only. |
|
| 1833 | + * |
|
| 1834 | + * @return bool |
|
| 1835 | + */ |
|
| 1836 | + protected function _get_main_ee_ueip_optin() |
|
| 1837 | + { |
|
| 1838 | + // if this is the main site then we can just bypass our direct query. |
|
| 1839 | + if (is_main_site()) { |
|
| 1840 | + return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1841 | + } |
|
| 1842 | + // is this already cached for this request? If so use it. |
|
| 1843 | + if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1844 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1845 | + } |
|
| 1846 | + global $wpdb; |
|
| 1847 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1848 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1849 | + $option = self::OPTION_NAME_UXIP; |
|
| 1850 | + // set correct table for query |
|
| 1851 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1852 | + // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1853 | + // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1854 | + // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1855 | + // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1856 | + // for the purpose of caching. |
|
| 1857 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1858 | + if (false !== $pre) { |
|
| 1859 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1860 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1861 | + } |
|
| 1862 | + $row = $wpdb->get_row( |
|
| 1863 | + $wpdb->prepare( |
|
| 1864 | + "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1865 | + $option |
|
| 1866 | + ) |
|
| 1867 | + ); |
|
| 1868 | + if (is_object($row)) { |
|
| 1869 | + $value = $row->option_value; |
|
| 1870 | + } else { // option does not exist so use default. |
|
| 1871 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1872 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1873 | + } |
|
| 1874 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1875 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + /** |
|
| 1880 | + * Utility function for escaping the value of a property and returning. |
|
| 1881 | + * |
|
| 1882 | + * @param string $property property name (checks to see if exists). |
|
| 1883 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1884 | + * @throws \EE_Error |
|
| 1885 | + */ |
|
| 1886 | + public function get_pretty($property) |
|
| 1887 | + { |
|
| 1888 | + if ($property === self::OPTION_NAME_UXIP) { |
|
| 1889 | + return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1890 | + } |
|
| 1891 | + return parent::get_pretty($property); |
|
| 1892 | + } |
|
| 1893 | + |
|
| 1894 | + |
|
| 1895 | + /** |
|
| 1896 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1897 | + * on the object. |
|
| 1898 | + * |
|
| 1899 | + * @return array |
|
| 1900 | + */ |
|
| 1901 | + public function __sleep() |
|
| 1902 | + { |
|
| 1903 | + // reset all url properties |
|
| 1904 | + $this->_reset_urls(); |
|
| 1905 | + // return what to save to db |
|
| 1906 | + return array_keys(get_object_vars($this)); |
|
| 1907 | + } |
|
| 1908 | +} |
|
| 2307 | 1909 | |
| 2308 | - /** |
|
| 2309 | - * array of form names protected by ReCaptcha |
|
| 2310 | - * |
|
| 2311 | - * @var array $recaptcha_protected_forms |
|
| 2312 | - */ |
|
| 2313 | - public $recaptcha_protected_forms; |
|
| 1910 | +/** |
|
| 1911 | + * Config class for storing info on the Organization |
|
| 1912 | + */ |
|
| 1913 | +class EE_Organization_Config extends EE_Config_Base |
|
| 1914 | +{ |
|
| 2314 | 1915 | |
| 2315 | - /** |
|
| 2316 | - * ReCaptcha width |
|
| 2317 | - * |
|
| 2318 | - * @var int $recaptcha_width |
|
| 2319 | - * @deprecated |
|
| 2320 | - */ |
|
| 2321 | - public $recaptcha_width; |
|
| 1916 | + /** |
|
| 1917 | + * @var string $name |
|
| 1918 | + * eg EE4.1 |
|
| 1919 | + */ |
|
| 1920 | + public $name; |
|
| 1921 | + |
|
| 1922 | + /** |
|
| 1923 | + * @var string $address_1 |
|
| 1924 | + * eg 123 Onna Road |
|
| 1925 | + */ |
|
| 1926 | + public $address_1; |
|
| 1927 | + |
|
| 1928 | + /** |
|
| 1929 | + * @var string $address_2 |
|
| 1930 | + * eg PO Box 123 |
|
| 1931 | + */ |
|
| 1932 | + public $address_2; |
|
| 1933 | + |
|
| 1934 | + /** |
|
| 1935 | + * @var string $city |
|
| 1936 | + * eg Inna City |
|
| 1937 | + */ |
|
| 1938 | + public $city; |
|
| 1939 | + |
|
| 1940 | + /** |
|
| 1941 | + * @var int $STA_ID |
|
| 1942 | + * eg 4 |
|
| 1943 | + */ |
|
| 1944 | + public $STA_ID; |
|
| 1945 | + |
|
| 1946 | + /** |
|
| 1947 | + * @var string $CNT_ISO |
|
| 1948 | + * eg US |
|
| 1949 | + */ |
|
| 1950 | + public $CNT_ISO; |
|
| 1951 | + |
|
| 1952 | + /** |
|
| 1953 | + * @var string $zip |
|
| 1954 | + * eg 12345 or V1A 2B3 |
|
| 1955 | + */ |
|
| 1956 | + public $zip; |
|
| 1957 | + |
|
| 1958 | + /** |
|
| 1959 | + * @var string $email |
|
| 1960 | + * eg [email protected] |
|
| 1961 | + */ |
|
| 1962 | + public $email; |
|
| 1963 | + |
|
| 1964 | + /** |
|
| 1965 | + * @var string $phone |
|
| 1966 | + * eg. 111-111-1111 |
|
| 1967 | + */ |
|
| 1968 | + public $phone; |
|
| 1969 | + |
|
| 1970 | + /** |
|
| 1971 | + * @var string $vat |
|
| 1972 | + * VAT/Tax Number |
|
| 1973 | + */ |
|
| 1974 | + public $vat; |
|
| 1975 | + |
|
| 1976 | + /** |
|
| 1977 | + * @var string $logo_url |
|
| 1978 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1979 | + */ |
|
| 1980 | + public $logo_url; |
|
| 1981 | + |
|
| 1982 | + /** |
|
| 1983 | + * The below are all various properties for holding links to organization social network profiles |
|
| 1984 | + * |
|
| 1985 | + * @var string |
|
| 1986 | + */ |
|
| 1987 | + /** |
|
| 1988 | + * facebook (facebook.com/profile.name) |
|
| 1989 | + * |
|
| 1990 | + * @var string |
|
| 1991 | + */ |
|
| 1992 | + public $facebook; |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * twitter (twitter.com/twitter_handle) |
|
| 1996 | + * |
|
| 1997 | + * @var string |
|
| 1998 | + */ |
|
| 1999 | + public $twitter; |
|
| 2000 | + |
|
| 2001 | + /** |
|
| 2002 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2003 | + * |
|
| 2004 | + * @var string |
|
| 2005 | + */ |
|
| 2006 | + public $linkedin; |
|
| 2007 | + |
|
| 2008 | + /** |
|
| 2009 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2010 | + * |
|
| 2011 | + * @var string |
|
| 2012 | + */ |
|
| 2013 | + public $pinterest; |
|
| 2014 | + |
|
| 2015 | + /** |
|
| 2016 | + * google+ (google.com/+profileName) |
|
| 2017 | + * |
|
| 2018 | + * @var string |
|
| 2019 | + */ |
|
| 2020 | + public $google; |
|
| 2021 | + |
|
| 2022 | + /** |
|
| 2023 | + * instagram (instagram.com/handle) |
|
| 2024 | + * |
|
| 2025 | + * @var string |
|
| 2026 | + */ |
|
| 2027 | + public $instagram; |
|
| 2028 | + |
|
| 2029 | + |
|
| 2030 | + /** |
|
| 2031 | + * class constructor |
|
| 2032 | + * |
|
| 2033 | + * @access public |
|
| 2034 | + */ |
|
| 2035 | + public function __construct() |
|
| 2036 | + { |
|
| 2037 | + // set default organization settings |
|
| 2038 | + // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2039 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2040 | + $this->address_1 = '123 Onna Road'; |
|
| 2041 | + $this->address_2 = 'PO Box 123'; |
|
| 2042 | + $this->city = 'Inna City'; |
|
| 2043 | + $this->STA_ID = 4; |
|
| 2044 | + $this->CNT_ISO = 'US'; |
|
| 2045 | + $this->zip = '12345'; |
|
| 2046 | + $this->email = get_bloginfo('admin_email'); |
|
| 2047 | + $this->phone = ''; |
|
| 2048 | + $this->vat = '123456789'; |
|
| 2049 | + $this->logo_url = ''; |
|
| 2050 | + $this->facebook = ''; |
|
| 2051 | + $this->twitter = ''; |
|
| 2052 | + $this->linkedin = ''; |
|
| 2053 | + $this->pinterest = ''; |
|
| 2054 | + $this->google = ''; |
|
| 2055 | + $this->instagram = ''; |
|
| 2056 | + } |
|
| 2057 | +} |
|
| 2322 | 2058 | |
| 2323 | - /** |
|
| 2324 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2325 | - * |
|
| 2326 | - * @var boolean $track_invalid_checkout_access |
|
| 2327 | - */ |
|
| 2328 | - protected $track_invalid_checkout_access = true; |
|
| 2059 | +/** |
|
| 2060 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2061 | + */ |
|
| 2062 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2063 | +{ |
|
| 2329 | 2064 | |
| 2330 | - /** |
|
| 2331 | - * Whether or not to show the privacy policy consent checkbox |
|
| 2332 | - * |
|
| 2333 | - * @var bool |
|
| 2334 | - */ |
|
| 2335 | - public $consent_checkbox_enabled; |
|
| 2065 | + /** |
|
| 2066 | + * @var string $code |
|
| 2067 | + * eg 'US' |
|
| 2068 | + */ |
|
| 2069 | + public $code; |
|
| 2070 | + |
|
| 2071 | + /** |
|
| 2072 | + * @var string $name |
|
| 2073 | + * eg 'Dollar' |
|
| 2074 | + */ |
|
| 2075 | + public $name; |
|
| 2076 | + |
|
| 2077 | + /** |
|
| 2078 | + * plural name |
|
| 2079 | + * |
|
| 2080 | + * @var string $plural |
|
| 2081 | + * eg 'Dollars' |
|
| 2082 | + */ |
|
| 2083 | + public $plural; |
|
| 2084 | + |
|
| 2085 | + /** |
|
| 2086 | + * currency sign |
|
| 2087 | + * |
|
| 2088 | + * @var string $sign |
|
| 2089 | + * eg '$' |
|
| 2090 | + */ |
|
| 2091 | + public $sign; |
|
| 2092 | + |
|
| 2093 | + /** |
|
| 2094 | + * Whether the currency sign should come before the number or not |
|
| 2095 | + * |
|
| 2096 | + * @var boolean $sign_b4 |
|
| 2097 | + */ |
|
| 2098 | + public $sign_b4; |
|
| 2099 | + |
|
| 2100 | + /** |
|
| 2101 | + * How many digits should come after the decimal place |
|
| 2102 | + * |
|
| 2103 | + * @var int $dec_plc |
|
| 2104 | + */ |
|
| 2105 | + public $dec_plc; |
|
| 2106 | + |
|
| 2107 | + /** |
|
| 2108 | + * Symbol to use for decimal mark |
|
| 2109 | + * |
|
| 2110 | + * @var string $dec_mrk |
|
| 2111 | + * eg '.' |
|
| 2112 | + */ |
|
| 2113 | + public $dec_mrk; |
|
| 2114 | + |
|
| 2115 | + /** |
|
| 2116 | + * Symbol to use for thousands |
|
| 2117 | + * |
|
| 2118 | + * @var string $thsnds |
|
| 2119 | + * eg ',' |
|
| 2120 | + */ |
|
| 2121 | + public $thsnds; |
|
| 2122 | + |
|
| 2123 | + |
|
| 2124 | + /** |
|
| 2125 | + * class constructor |
|
| 2126 | + * |
|
| 2127 | + * @access public |
|
| 2128 | + * @param string $CNT_ISO |
|
| 2129 | + * @throws \EE_Error |
|
| 2130 | + */ |
|
| 2131 | + public function __construct($CNT_ISO = '') |
|
| 2132 | + { |
|
| 2133 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2134 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2135 | + // get country code from organization settings or use default |
|
| 2136 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2137 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2138 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2139 | + : ''; |
|
| 2140 | + // but override if requested |
|
| 2141 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2142 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2143 | + if (! empty($CNT_ISO) |
|
| 2144 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2145 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2146 | + ) { |
|
| 2147 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2148 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2149 | + if ($country instanceof EE_Country) { |
|
| 2150 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2151 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2152 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2153 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2154 | + $this->sign_b4 = $country->currency_sign_before( |
|
| 2155 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | + $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2158 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2159 | + $this->thsnds = $country->currency_thousands_separator( |
|
| 2160 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2161 | + } |
|
| 2162 | + } |
|
| 2163 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2164 | + if (empty($this->code)) { |
|
| 2165 | + // set default currency settings |
|
| 2166 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2167 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2168 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2169 | + $this->sign = '$'; // currency sign: $ |
|
| 2170 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2171 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2172 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2173 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2174 | + } |
|
| 2175 | + } |
|
| 2176 | +} |
|
| 2336 | 2177 | |
| 2337 | - /** |
|
| 2338 | - * Label text to show on the checkbox |
|
| 2339 | - * |
|
| 2340 | - * @var string |
|
| 2341 | - */ |
|
| 2342 | - public $consent_checkbox_label_text; |
|
| 2178 | +/** |
|
| 2179 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2180 | + */ |
|
| 2181 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2182 | +{ |
|
| 2343 | 2183 | |
| 2344 | - /* |
|
| 2184 | + /** |
|
| 2185 | + * Default registration status |
|
| 2186 | + * |
|
| 2187 | + * @var string $default_STS_ID |
|
| 2188 | + * eg 'RPP' |
|
| 2189 | + */ |
|
| 2190 | + public $default_STS_ID; |
|
| 2191 | + |
|
| 2192 | + /** |
|
| 2193 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2194 | + * registrations) |
|
| 2195 | + * |
|
| 2196 | + * @var int |
|
| 2197 | + */ |
|
| 2198 | + public $default_maximum_number_of_tickets; |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * level of validation to apply to email addresses |
|
| 2202 | + * |
|
| 2203 | + * @var string $email_validation_level |
|
| 2204 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2205 | + */ |
|
| 2206 | + public $email_validation_level; |
|
| 2207 | + |
|
| 2208 | + /** |
|
| 2209 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2210 | + * |
|
| 2211 | + * @var boolean $show_pending_payment_options |
|
| 2212 | + */ |
|
| 2213 | + public $show_pending_payment_options; |
|
| 2214 | + |
|
| 2215 | + /** |
|
| 2216 | + * Whether to skip the registration confirmation page |
|
| 2217 | + * |
|
| 2218 | + * @var boolean $skip_reg_confirmation |
|
| 2219 | + */ |
|
| 2220 | + public $skip_reg_confirmation; |
|
| 2221 | + |
|
| 2222 | + /** |
|
| 2223 | + * an array of SPCO reg steps where: |
|
| 2224 | + * the keys denotes the reg step order |
|
| 2225 | + * each element consists of an array with the following elements: |
|
| 2226 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2227 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2228 | + * "slug" => the URL param used to trigger the reg step |
|
| 2229 | + * |
|
| 2230 | + * @var array $reg_steps |
|
| 2231 | + */ |
|
| 2232 | + public $reg_steps; |
|
| 2233 | + |
|
| 2234 | + /** |
|
| 2235 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2236 | + * |
|
| 2237 | + * @var boolean $reg_confirmation_last |
|
| 2238 | + */ |
|
| 2239 | + public $reg_confirmation_last; |
|
| 2240 | + |
|
| 2241 | + /** |
|
| 2242 | + * Whether or not to enable the EE Bot Trap |
|
| 2243 | + * |
|
| 2244 | + * @var boolean $use_bot_trap |
|
| 2245 | + */ |
|
| 2246 | + public $use_bot_trap; |
|
| 2247 | + |
|
| 2248 | + /** |
|
| 2249 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2250 | + * |
|
| 2251 | + * @var boolean $use_encryption |
|
| 2252 | + */ |
|
| 2253 | + public $use_encryption; |
|
| 2254 | + |
|
| 2255 | + /** |
|
| 2256 | + * Whether or not to use ReCaptcha |
|
| 2257 | + * |
|
| 2258 | + * @var boolean $use_captcha |
|
| 2259 | + */ |
|
| 2260 | + public $use_captcha; |
|
| 2261 | + |
|
| 2262 | + /** |
|
| 2263 | + * ReCaptcha Theme |
|
| 2264 | + * |
|
| 2265 | + * @var string $recaptcha_theme |
|
| 2266 | + * options: 'dark', 'light', 'invisible' |
|
| 2267 | + */ |
|
| 2268 | + public $recaptcha_theme; |
|
| 2269 | + |
|
| 2270 | + /** |
|
| 2271 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2272 | + * |
|
| 2273 | + * @var string $recaptcha_badge |
|
| 2274 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2275 | + */ |
|
| 2276 | + public $recaptcha_badge; |
|
| 2277 | + |
|
| 2278 | + /** |
|
| 2279 | + * ReCaptcha Type |
|
| 2280 | + * |
|
| 2281 | + * @var string $recaptcha_type |
|
| 2282 | + * options: 'audio', 'image' |
|
| 2283 | + */ |
|
| 2284 | + public $recaptcha_type; |
|
| 2285 | + |
|
| 2286 | + /** |
|
| 2287 | + * ReCaptcha language |
|
| 2288 | + * |
|
| 2289 | + * @var string $recaptcha_language |
|
| 2290 | + * eg 'en' |
|
| 2291 | + */ |
|
| 2292 | + public $recaptcha_language; |
|
| 2293 | + |
|
| 2294 | + /** |
|
| 2295 | + * ReCaptcha public key |
|
| 2296 | + * |
|
| 2297 | + * @var string $recaptcha_publickey |
|
| 2298 | + */ |
|
| 2299 | + public $recaptcha_publickey; |
|
| 2300 | + |
|
| 2301 | + /** |
|
| 2302 | + * ReCaptcha private key |
|
| 2303 | + * |
|
| 2304 | + * @var string $recaptcha_privatekey |
|
| 2305 | + */ |
|
| 2306 | + public $recaptcha_privatekey; |
|
| 2307 | + |
|
| 2308 | + /** |
|
| 2309 | + * array of form names protected by ReCaptcha |
|
| 2310 | + * |
|
| 2311 | + * @var array $recaptcha_protected_forms |
|
| 2312 | + */ |
|
| 2313 | + public $recaptcha_protected_forms; |
|
| 2314 | + |
|
| 2315 | + /** |
|
| 2316 | + * ReCaptcha width |
|
| 2317 | + * |
|
| 2318 | + * @var int $recaptcha_width |
|
| 2319 | + * @deprecated |
|
| 2320 | + */ |
|
| 2321 | + public $recaptcha_width; |
|
| 2322 | + |
|
| 2323 | + /** |
|
| 2324 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2325 | + * |
|
| 2326 | + * @var boolean $track_invalid_checkout_access |
|
| 2327 | + */ |
|
| 2328 | + protected $track_invalid_checkout_access = true; |
|
| 2329 | + |
|
| 2330 | + /** |
|
| 2331 | + * Whether or not to show the privacy policy consent checkbox |
|
| 2332 | + * |
|
| 2333 | + * @var bool |
|
| 2334 | + */ |
|
| 2335 | + public $consent_checkbox_enabled; |
|
| 2336 | + |
|
| 2337 | + /** |
|
| 2338 | + * Label text to show on the checkbox |
|
| 2339 | + * |
|
| 2340 | + * @var string |
|
| 2341 | + */ |
|
| 2342 | + public $consent_checkbox_label_text; |
|
| 2343 | + |
|
| 2344 | + /* |
|
| 2345 | 2345 | * String describing how long to keep payment logs. Passed into DateTime constructor |
| 2346 | 2346 | * @var string |
| 2347 | 2347 | */ |
| 2348 | - public $gateway_log_lifespan = '1 week'; |
|
| 2349 | - |
|
| 2350 | - |
|
| 2351 | - /** |
|
| 2352 | - * class constructor |
|
| 2353 | - * |
|
| 2354 | - * @access public |
|
| 2355 | - */ |
|
| 2356 | - public function __construct() |
|
| 2357 | - { |
|
| 2358 | - // set default registration settings |
|
| 2359 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2360 | - $this->email_validation_level = 'wp_default'; |
|
| 2361 | - $this->show_pending_payment_options = true; |
|
| 2362 | - $this->skip_reg_confirmation = true; |
|
| 2363 | - $this->reg_steps = array(); |
|
| 2364 | - $this->reg_confirmation_last = false; |
|
| 2365 | - $this->use_bot_trap = true; |
|
| 2366 | - $this->use_encryption = true; |
|
| 2367 | - $this->use_captcha = false; |
|
| 2368 | - $this->recaptcha_theme = 'light'; |
|
| 2369 | - $this->recaptcha_badge = 'bottomleft'; |
|
| 2370 | - $this->recaptcha_type = 'image'; |
|
| 2371 | - $this->recaptcha_language = 'en'; |
|
| 2372 | - $this->recaptcha_publickey = null; |
|
| 2373 | - $this->recaptcha_privatekey = null; |
|
| 2374 | - $this->recaptcha_protected_forms = array(); |
|
| 2375 | - $this->recaptcha_width = 500; |
|
| 2376 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2377 | - $this->consent_checkbox_enabled = false; |
|
| 2378 | - $this->consent_checkbox_label_text = ''; |
|
| 2379 | - $this->gateway_log_lifespan = '7 days'; |
|
| 2380 | - } |
|
| 2381 | - |
|
| 2382 | - |
|
| 2383 | - /** |
|
| 2384 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2385 | - * |
|
| 2386 | - * @since 4.8.8.rc.019 |
|
| 2387 | - */ |
|
| 2388 | - public function do_hooks() |
|
| 2389 | - { |
|
| 2390 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2391 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2392 | - add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2393 | - } |
|
| 2394 | - |
|
| 2395 | - |
|
| 2396 | - /** |
|
| 2397 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2398 | - * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2399 | - */ |
|
| 2400 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2401 | - { |
|
| 2402 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2403 | - } |
|
| 2404 | - |
|
| 2405 | - |
|
| 2406 | - /** |
|
| 2407 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2408 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2409 | - */ |
|
| 2410 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2411 | - { |
|
| 2412 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2413 | - } |
|
| 2414 | - |
|
| 2415 | - |
|
| 2416 | - /** |
|
| 2417 | - * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2418 | - * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2419 | - * |
|
| 2420 | - * @throws InvalidArgumentException |
|
| 2421 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2422 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2423 | - */ |
|
| 2424 | - public function setDefaultCheckboxLabelText() |
|
| 2425 | - { |
|
| 2426 | - if ($this->getConsentCheckboxLabelText() === null |
|
| 2427 | - || $this->getConsentCheckboxLabelText() === '') { |
|
| 2428 | - $opening_a_tag = ''; |
|
| 2429 | - $closing_a_tag = ''; |
|
| 2430 | - if (function_exists('get_privacy_policy_url')) { |
|
| 2431 | - $privacy_page_url = get_privacy_policy_url(); |
|
| 2432 | - if (! empty($privacy_page_url)) { |
|
| 2433 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2434 | - $closing_a_tag = '</a>'; |
|
| 2435 | - } |
|
| 2436 | - } |
|
| 2437 | - $loader = LoaderFactory::getLoader(); |
|
| 2438 | - $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2439 | - /** |
|
| 2440 | - * @var $org_config EE_Organization_Config |
|
| 2441 | - */ |
|
| 2442 | - |
|
| 2443 | - $this->setConsentCheckboxLabelText( |
|
| 2444 | - sprintf( |
|
| 2445 | - esc_html__( |
|
| 2446 | - 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2447 | - 'event_espresso' |
|
| 2448 | - ), |
|
| 2449 | - $org_config->name, |
|
| 2450 | - $opening_a_tag, |
|
| 2451 | - $closing_a_tag |
|
| 2452 | - ) |
|
| 2453 | - ); |
|
| 2454 | - } |
|
| 2455 | - } |
|
| 2456 | - |
|
| 2457 | - |
|
| 2458 | - /** |
|
| 2459 | - * @return boolean |
|
| 2460 | - */ |
|
| 2461 | - public function track_invalid_checkout_access() |
|
| 2462 | - { |
|
| 2463 | - return $this->track_invalid_checkout_access; |
|
| 2464 | - } |
|
| 2465 | - |
|
| 2466 | - |
|
| 2467 | - /** |
|
| 2468 | - * @param boolean $track_invalid_checkout_access |
|
| 2469 | - */ |
|
| 2470 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2471 | - { |
|
| 2472 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2473 | - $track_invalid_checkout_access, |
|
| 2474 | - FILTER_VALIDATE_BOOLEAN |
|
| 2475 | - ); |
|
| 2476 | - } |
|
| 2477 | - |
|
| 2478 | - |
|
| 2479 | - /** |
|
| 2480 | - * Gets the options to make availalbe for the gateway log lifespan |
|
| 2481 | - * @return array |
|
| 2482 | - */ |
|
| 2483 | - public function gatewayLogLifespanOptions() |
|
| 2484 | - { |
|
| 2485 | - return (array) apply_filters( |
|
| 2486 | - 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2487 | - array( |
|
| 2488 | - '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2489 | - '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2490 | - '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2491 | - '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2492 | - '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2493 | - ) |
|
| 2494 | - ); |
|
| 2495 | - } |
|
| 2496 | - |
|
| 2497 | - |
|
| 2498 | - /** |
|
| 2499 | - * @return bool |
|
| 2500 | - */ |
|
| 2501 | - public function isConsentCheckboxEnabled() |
|
| 2502 | - { |
|
| 2503 | - return $this->consent_checkbox_enabled; |
|
| 2504 | - } |
|
| 2505 | - |
|
| 2506 | - |
|
| 2507 | - /** |
|
| 2508 | - * @param bool $consent_checkbox_enabled |
|
| 2509 | - */ |
|
| 2510 | - public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2511 | - { |
|
| 2512 | - $this->consent_checkbox_enabled = filter_var( |
|
| 2513 | - $consent_checkbox_enabled, |
|
| 2514 | - FILTER_VALIDATE_BOOLEAN |
|
| 2515 | - ); |
|
| 2516 | - } |
|
| 2517 | - |
|
| 2518 | - |
|
| 2519 | - /** |
|
| 2520 | - * @return string |
|
| 2521 | - */ |
|
| 2522 | - public function getConsentCheckboxLabelText() |
|
| 2523 | - { |
|
| 2524 | - return $this->consent_checkbox_label_text; |
|
| 2525 | - } |
|
| 2526 | - |
|
| 2527 | - |
|
| 2528 | - /** |
|
| 2529 | - * @param string $consent_checkbox_label_text |
|
| 2530 | - */ |
|
| 2531 | - public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2532 | - { |
|
| 2533 | - $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2534 | - } |
|
| 2348 | + public $gateway_log_lifespan = '1 week'; |
|
| 2349 | + |
|
| 2350 | + |
|
| 2351 | + /** |
|
| 2352 | + * class constructor |
|
| 2353 | + * |
|
| 2354 | + * @access public |
|
| 2355 | + */ |
|
| 2356 | + public function __construct() |
|
| 2357 | + { |
|
| 2358 | + // set default registration settings |
|
| 2359 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2360 | + $this->email_validation_level = 'wp_default'; |
|
| 2361 | + $this->show_pending_payment_options = true; |
|
| 2362 | + $this->skip_reg_confirmation = true; |
|
| 2363 | + $this->reg_steps = array(); |
|
| 2364 | + $this->reg_confirmation_last = false; |
|
| 2365 | + $this->use_bot_trap = true; |
|
| 2366 | + $this->use_encryption = true; |
|
| 2367 | + $this->use_captcha = false; |
|
| 2368 | + $this->recaptcha_theme = 'light'; |
|
| 2369 | + $this->recaptcha_badge = 'bottomleft'; |
|
| 2370 | + $this->recaptcha_type = 'image'; |
|
| 2371 | + $this->recaptcha_language = 'en'; |
|
| 2372 | + $this->recaptcha_publickey = null; |
|
| 2373 | + $this->recaptcha_privatekey = null; |
|
| 2374 | + $this->recaptcha_protected_forms = array(); |
|
| 2375 | + $this->recaptcha_width = 500; |
|
| 2376 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2377 | + $this->consent_checkbox_enabled = false; |
|
| 2378 | + $this->consent_checkbox_label_text = ''; |
|
| 2379 | + $this->gateway_log_lifespan = '7 days'; |
|
| 2380 | + } |
|
| 2381 | + |
|
| 2382 | + |
|
| 2383 | + /** |
|
| 2384 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2385 | + * |
|
| 2386 | + * @since 4.8.8.rc.019 |
|
| 2387 | + */ |
|
| 2388 | + public function do_hooks() |
|
| 2389 | + { |
|
| 2390 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2391 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2392 | + add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2393 | + } |
|
| 2394 | + |
|
| 2395 | + |
|
| 2396 | + /** |
|
| 2397 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2398 | + * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2399 | + */ |
|
| 2400 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2401 | + { |
|
| 2402 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2403 | + } |
|
| 2404 | + |
|
| 2405 | + |
|
| 2406 | + /** |
|
| 2407 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2408 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2409 | + */ |
|
| 2410 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2411 | + { |
|
| 2412 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2413 | + } |
|
| 2414 | + |
|
| 2415 | + |
|
| 2416 | + /** |
|
| 2417 | + * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2418 | + * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2419 | + * |
|
| 2420 | + * @throws InvalidArgumentException |
|
| 2421 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2422 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2423 | + */ |
|
| 2424 | + public function setDefaultCheckboxLabelText() |
|
| 2425 | + { |
|
| 2426 | + if ($this->getConsentCheckboxLabelText() === null |
|
| 2427 | + || $this->getConsentCheckboxLabelText() === '') { |
|
| 2428 | + $opening_a_tag = ''; |
|
| 2429 | + $closing_a_tag = ''; |
|
| 2430 | + if (function_exists('get_privacy_policy_url')) { |
|
| 2431 | + $privacy_page_url = get_privacy_policy_url(); |
|
| 2432 | + if (! empty($privacy_page_url)) { |
|
| 2433 | + $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2434 | + $closing_a_tag = '</a>'; |
|
| 2435 | + } |
|
| 2436 | + } |
|
| 2437 | + $loader = LoaderFactory::getLoader(); |
|
| 2438 | + $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2439 | + /** |
|
| 2440 | + * @var $org_config EE_Organization_Config |
|
| 2441 | + */ |
|
| 2442 | + |
|
| 2443 | + $this->setConsentCheckboxLabelText( |
|
| 2444 | + sprintf( |
|
| 2445 | + esc_html__( |
|
| 2446 | + 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2447 | + 'event_espresso' |
|
| 2448 | + ), |
|
| 2449 | + $org_config->name, |
|
| 2450 | + $opening_a_tag, |
|
| 2451 | + $closing_a_tag |
|
| 2452 | + ) |
|
| 2453 | + ); |
|
| 2454 | + } |
|
| 2455 | + } |
|
| 2456 | + |
|
| 2457 | + |
|
| 2458 | + /** |
|
| 2459 | + * @return boolean |
|
| 2460 | + */ |
|
| 2461 | + public function track_invalid_checkout_access() |
|
| 2462 | + { |
|
| 2463 | + return $this->track_invalid_checkout_access; |
|
| 2464 | + } |
|
| 2465 | + |
|
| 2466 | + |
|
| 2467 | + /** |
|
| 2468 | + * @param boolean $track_invalid_checkout_access |
|
| 2469 | + */ |
|
| 2470 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2471 | + { |
|
| 2472 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2473 | + $track_invalid_checkout_access, |
|
| 2474 | + FILTER_VALIDATE_BOOLEAN |
|
| 2475 | + ); |
|
| 2476 | + } |
|
| 2477 | + |
|
| 2478 | + |
|
| 2479 | + /** |
|
| 2480 | + * Gets the options to make availalbe for the gateway log lifespan |
|
| 2481 | + * @return array |
|
| 2482 | + */ |
|
| 2483 | + public function gatewayLogLifespanOptions() |
|
| 2484 | + { |
|
| 2485 | + return (array) apply_filters( |
|
| 2486 | + 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2487 | + array( |
|
| 2488 | + '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2489 | + '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2490 | + '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2491 | + '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2492 | + '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2493 | + ) |
|
| 2494 | + ); |
|
| 2495 | + } |
|
| 2496 | + |
|
| 2497 | + |
|
| 2498 | + /** |
|
| 2499 | + * @return bool |
|
| 2500 | + */ |
|
| 2501 | + public function isConsentCheckboxEnabled() |
|
| 2502 | + { |
|
| 2503 | + return $this->consent_checkbox_enabled; |
|
| 2504 | + } |
|
| 2505 | + |
|
| 2506 | + |
|
| 2507 | + /** |
|
| 2508 | + * @param bool $consent_checkbox_enabled |
|
| 2509 | + */ |
|
| 2510 | + public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2511 | + { |
|
| 2512 | + $this->consent_checkbox_enabled = filter_var( |
|
| 2513 | + $consent_checkbox_enabled, |
|
| 2514 | + FILTER_VALIDATE_BOOLEAN |
|
| 2515 | + ); |
|
| 2516 | + } |
|
| 2517 | + |
|
| 2518 | + |
|
| 2519 | + /** |
|
| 2520 | + * @return string |
|
| 2521 | + */ |
|
| 2522 | + public function getConsentCheckboxLabelText() |
|
| 2523 | + { |
|
| 2524 | + return $this->consent_checkbox_label_text; |
|
| 2525 | + } |
|
| 2526 | + |
|
| 2527 | + |
|
| 2528 | + /** |
|
| 2529 | + * @param string $consent_checkbox_label_text |
|
| 2530 | + */ |
|
| 2531 | + public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2532 | + { |
|
| 2533 | + $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2534 | + } |
|
| 2535 | 2535 | } |
| 2536 | 2536 | |
| 2537 | 2537 | /** |
@@ -2540,154 +2540,154 @@ discard block |
||
| 2540 | 2540 | class EE_Admin_Config extends EE_Config_Base |
| 2541 | 2541 | { |
| 2542 | 2542 | |
| 2543 | - /** |
|
| 2544 | - * @var boolean $use_personnel_manager |
|
| 2545 | - */ |
|
| 2546 | - public $use_personnel_manager; |
|
| 2547 | - |
|
| 2548 | - /** |
|
| 2549 | - * @var boolean $use_dashboard_widget |
|
| 2550 | - */ |
|
| 2551 | - public $use_dashboard_widget; |
|
| 2552 | - |
|
| 2553 | - /** |
|
| 2554 | - * @var int $events_in_dashboard |
|
| 2555 | - */ |
|
| 2556 | - public $events_in_dashboard; |
|
| 2557 | - |
|
| 2558 | - /** |
|
| 2559 | - * @var boolean $use_event_timezones |
|
| 2560 | - */ |
|
| 2561 | - public $use_event_timezones; |
|
| 2562 | - |
|
| 2563 | - /** |
|
| 2564 | - * @var boolean $use_full_logging |
|
| 2565 | - */ |
|
| 2566 | - public $use_full_logging; |
|
| 2567 | - |
|
| 2568 | - /** |
|
| 2569 | - * @var string $log_file_name |
|
| 2570 | - */ |
|
| 2571 | - public $log_file_name; |
|
| 2572 | - |
|
| 2573 | - /** |
|
| 2574 | - * @var string $debug_file_name |
|
| 2575 | - */ |
|
| 2576 | - public $debug_file_name; |
|
| 2577 | - |
|
| 2578 | - /** |
|
| 2579 | - * @var boolean $use_remote_logging |
|
| 2580 | - */ |
|
| 2581 | - public $use_remote_logging; |
|
| 2582 | - |
|
| 2583 | - /** |
|
| 2584 | - * @var string $remote_logging_url |
|
| 2585 | - */ |
|
| 2586 | - public $remote_logging_url; |
|
| 2587 | - |
|
| 2588 | - /** |
|
| 2589 | - * @var boolean $show_reg_footer |
|
| 2590 | - */ |
|
| 2591 | - public $show_reg_footer; |
|
| 2592 | - |
|
| 2593 | - /** |
|
| 2594 | - * @var string $affiliate_id |
|
| 2595 | - */ |
|
| 2596 | - public $affiliate_id; |
|
| 2597 | - |
|
| 2598 | - /** |
|
| 2599 | - * help tours on or off (global setting) |
|
| 2600 | - * |
|
| 2601 | - * @var boolean |
|
| 2602 | - */ |
|
| 2603 | - public $help_tour_activation; |
|
| 2604 | - |
|
| 2605 | - /** |
|
| 2606 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2607 | - * but is incompatible with some server configuration errors |
|
| 2608 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2609 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2610 | - * |
|
| 2611 | - * @var boolean $encode_session_data |
|
| 2612 | - */ |
|
| 2613 | - private $encode_session_data = false; |
|
| 2614 | - |
|
| 2615 | - |
|
| 2616 | - /** |
|
| 2617 | - * class constructor |
|
| 2618 | - * |
|
| 2619 | - * @access public |
|
| 2620 | - */ |
|
| 2621 | - public function __construct() |
|
| 2622 | - { |
|
| 2623 | - // set default general admin settings |
|
| 2624 | - $this->use_personnel_manager = true; |
|
| 2625 | - $this->use_dashboard_widget = true; |
|
| 2626 | - $this->events_in_dashboard = 30; |
|
| 2627 | - $this->use_event_timezones = false; |
|
| 2628 | - $this->use_full_logging = false; |
|
| 2629 | - $this->use_remote_logging = false; |
|
| 2630 | - $this->remote_logging_url = null; |
|
| 2631 | - $this->show_reg_footer = true; |
|
| 2632 | - $this->affiliate_id = 'default'; |
|
| 2633 | - $this->help_tour_activation = true; |
|
| 2634 | - $this->encode_session_data = false; |
|
| 2635 | - } |
|
| 2636 | - |
|
| 2637 | - |
|
| 2638 | - /** |
|
| 2639 | - * @param bool $reset |
|
| 2640 | - * @return string |
|
| 2641 | - */ |
|
| 2642 | - public function log_file_name($reset = false) |
|
| 2643 | - { |
|
| 2644 | - if (empty($this->log_file_name) || $reset) { |
|
| 2645 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2646 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2647 | - } |
|
| 2648 | - return $this->log_file_name; |
|
| 2649 | - } |
|
| 2650 | - |
|
| 2651 | - |
|
| 2652 | - /** |
|
| 2653 | - * @param bool $reset |
|
| 2654 | - * @return string |
|
| 2655 | - */ |
|
| 2656 | - public function debug_file_name($reset = false) |
|
| 2657 | - { |
|
| 2658 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2659 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2660 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2661 | - } |
|
| 2662 | - return $this->debug_file_name; |
|
| 2663 | - } |
|
| 2664 | - |
|
| 2665 | - |
|
| 2666 | - /** |
|
| 2667 | - * @return string |
|
| 2668 | - */ |
|
| 2669 | - public function affiliate_id() |
|
| 2670 | - { |
|
| 2671 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2672 | - } |
|
| 2673 | - |
|
| 2674 | - |
|
| 2675 | - /** |
|
| 2676 | - * @return boolean |
|
| 2677 | - */ |
|
| 2678 | - public function encode_session_data() |
|
| 2679 | - { |
|
| 2680 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2681 | - } |
|
| 2682 | - |
|
| 2683 | - |
|
| 2684 | - /** |
|
| 2685 | - * @param boolean $encode_session_data |
|
| 2686 | - */ |
|
| 2687 | - public function set_encode_session_data($encode_session_data) |
|
| 2688 | - { |
|
| 2689 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2690 | - } |
|
| 2543 | + /** |
|
| 2544 | + * @var boolean $use_personnel_manager |
|
| 2545 | + */ |
|
| 2546 | + public $use_personnel_manager; |
|
| 2547 | + |
|
| 2548 | + /** |
|
| 2549 | + * @var boolean $use_dashboard_widget |
|
| 2550 | + */ |
|
| 2551 | + public $use_dashboard_widget; |
|
| 2552 | + |
|
| 2553 | + /** |
|
| 2554 | + * @var int $events_in_dashboard |
|
| 2555 | + */ |
|
| 2556 | + public $events_in_dashboard; |
|
| 2557 | + |
|
| 2558 | + /** |
|
| 2559 | + * @var boolean $use_event_timezones |
|
| 2560 | + */ |
|
| 2561 | + public $use_event_timezones; |
|
| 2562 | + |
|
| 2563 | + /** |
|
| 2564 | + * @var boolean $use_full_logging |
|
| 2565 | + */ |
|
| 2566 | + public $use_full_logging; |
|
| 2567 | + |
|
| 2568 | + /** |
|
| 2569 | + * @var string $log_file_name |
|
| 2570 | + */ |
|
| 2571 | + public $log_file_name; |
|
| 2572 | + |
|
| 2573 | + /** |
|
| 2574 | + * @var string $debug_file_name |
|
| 2575 | + */ |
|
| 2576 | + public $debug_file_name; |
|
| 2577 | + |
|
| 2578 | + /** |
|
| 2579 | + * @var boolean $use_remote_logging |
|
| 2580 | + */ |
|
| 2581 | + public $use_remote_logging; |
|
| 2582 | + |
|
| 2583 | + /** |
|
| 2584 | + * @var string $remote_logging_url |
|
| 2585 | + */ |
|
| 2586 | + public $remote_logging_url; |
|
| 2587 | + |
|
| 2588 | + /** |
|
| 2589 | + * @var boolean $show_reg_footer |
|
| 2590 | + */ |
|
| 2591 | + public $show_reg_footer; |
|
| 2592 | + |
|
| 2593 | + /** |
|
| 2594 | + * @var string $affiliate_id |
|
| 2595 | + */ |
|
| 2596 | + public $affiliate_id; |
|
| 2597 | + |
|
| 2598 | + /** |
|
| 2599 | + * help tours on or off (global setting) |
|
| 2600 | + * |
|
| 2601 | + * @var boolean |
|
| 2602 | + */ |
|
| 2603 | + public $help_tour_activation; |
|
| 2604 | + |
|
| 2605 | + /** |
|
| 2606 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2607 | + * but is incompatible with some server configuration errors |
|
| 2608 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2609 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2610 | + * |
|
| 2611 | + * @var boolean $encode_session_data |
|
| 2612 | + */ |
|
| 2613 | + private $encode_session_data = false; |
|
| 2614 | + |
|
| 2615 | + |
|
| 2616 | + /** |
|
| 2617 | + * class constructor |
|
| 2618 | + * |
|
| 2619 | + * @access public |
|
| 2620 | + */ |
|
| 2621 | + public function __construct() |
|
| 2622 | + { |
|
| 2623 | + // set default general admin settings |
|
| 2624 | + $this->use_personnel_manager = true; |
|
| 2625 | + $this->use_dashboard_widget = true; |
|
| 2626 | + $this->events_in_dashboard = 30; |
|
| 2627 | + $this->use_event_timezones = false; |
|
| 2628 | + $this->use_full_logging = false; |
|
| 2629 | + $this->use_remote_logging = false; |
|
| 2630 | + $this->remote_logging_url = null; |
|
| 2631 | + $this->show_reg_footer = true; |
|
| 2632 | + $this->affiliate_id = 'default'; |
|
| 2633 | + $this->help_tour_activation = true; |
|
| 2634 | + $this->encode_session_data = false; |
|
| 2635 | + } |
|
| 2636 | + |
|
| 2637 | + |
|
| 2638 | + /** |
|
| 2639 | + * @param bool $reset |
|
| 2640 | + * @return string |
|
| 2641 | + */ |
|
| 2642 | + public function log_file_name($reset = false) |
|
| 2643 | + { |
|
| 2644 | + if (empty($this->log_file_name) || $reset) { |
|
| 2645 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2646 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2647 | + } |
|
| 2648 | + return $this->log_file_name; |
|
| 2649 | + } |
|
| 2650 | + |
|
| 2651 | + |
|
| 2652 | + /** |
|
| 2653 | + * @param bool $reset |
|
| 2654 | + * @return string |
|
| 2655 | + */ |
|
| 2656 | + public function debug_file_name($reset = false) |
|
| 2657 | + { |
|
| 2658 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2659 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2660 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2661 | + } |
|
| 2662 | + return $this->debug_file_name; |
|
| 2663 | + } |
|
| 2664 | + |
|
| 2665 | + |
|
| 2666 | + /** |
|
| 2667 | + * @return string |
|
| 2668 | + */ |
|
| 2669 | + public function affiliate_id() |
|
| 2670 | + { |
|
| 2671 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2672 | + } |
|
| 2673 | + |
|
| 2674 | + |
|
| 2675 | + /** |
|
| 2676 | + * @return boolean |
|
| 2677 | + */ |
|
| 2678 | + public function encode_session_data() |
|
| 2679 | + { |
|
| 2680 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2681 | + } |
|
| 2682 | + |
|
| 2683 | + |
|
| 2684 | + /** |
|
| 2685 | + * @param boolean $encode_session_data |
|
| 2686 | + */ |
|
| 2687 | + public function set_encode_session_data($encode_session_data) |
|
| 2688 | + { |
|
| 2689 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2690 | + } |
|
| 2691 | 2691 | } |
| 2692 | 2692 | |
| 2693 | 2693 | /** |
@@ -2696,70 +2696,70 @@ discard block |
||
| 2696 | 2696 | class EE_Template_Config extends EE_Config_Base |
| 2697 | 2697 | { |
| 2698 | 2698 | |
| 2699 | - /** |
|
| 2700 | - * @var boolean $enable_default_style |
|
| 2701 | - */ |
|
| 2702 | - public $enable_default_style; |
|
| 2703 | - |
|
| 2704 | - /** |
|
| 2705 | - * @var string $custom_style_sheet |
|
| 2706 | - */ |
|
| 2707 | - public $custom_style_sheet; |
|
| 2708 | - |
|
| 2709 | - /** |
|
| 2710 | - * @var boolean $display_address_in_regform |
|
| 2711 | - */ |
|
| 2712 | - public $display_address_in_regform; |
|
| 2713 | - |
|
| 2714 | - /** |
|
| 2715 | - * @var int $display_description_on_multi_reg_page |
|
| 2716 | - */ |
|
| 2717 | - public $display_description_on_multi_reg_page; |
|
| 2718 | - |
|
| 2719 | - /** |
|
| 2720 | - * @var boolean $use_custom_templates |
|
| 2721 | - */ |
|
| 2722 | - public $use_custom_templates; |
|
| 2723 | - |
|
| 2724 | - /** |
|
| 2725 | - * @var string $current_espresso_theme |
|
| 2726 | - */ |
|
| 2727 | - public $current_espresso_theme; |
|
| 2728 | - |
|
| 2729 | - /** |
|
| 2730 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2731 | - */ |
|
| 2732 | - public $EED_Ticket_Selector; |
|
| 2733 | - |
|
| 2734 | - /** |
|
| 2735 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2736 | - */ |
|
| 2737 | - public $EED_Event_Single; |
|
| 2738 | - |
|
| 2739 | - /** |
|
| 2740 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2741 | - */ |
|
| 2742 | - public $EED_Events_Archive; |
|
| 2743 | - |
|
| 2744 | - |
|
| 2745 | - /** |
|
| 2746 | - * class constructor |
|
| 2747 | - * |
|
| 2748 | - * @access public |
|
| 2749 | - */ |
|
| 2750 | - public function __construct() |
|
| 2751 | - { |
|
| 2752 | - // set default template settings |
|
| 2753 | - $this->enable_default_style = true; |
|
| 2754 | - $this->custom_style_sheet = null; |
|
| 2755 | - $this->display_address_in_regform = true; |
|
| 2756 | - $this->display_description_on_multi_reg_page = false; |
|
| 2757 | - $this->use_custom_templates = false; |
|
| 2758 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2759 | - $this->EED_Event_Single = null; |
|
| 2760 | - $this->EED_Events_Archive = null; |
|
| 2761 | - $this->EED_Ticket_Selector = null; |
|
| 2762 | - } |
|
| 2699 | + /** |
|
| 2700 | + * @var boolean $enable_default_style |
|
| 2701 | + */ |
|
| 2702 | + public $enable_default_style; |
|
| 2703 | + |
|
| 2704 | + /** |
|
| 2705 | + * @var string $custom_style_sheet |
|
| 2706 | + */ |
|
| 2707 | + public $custom_style_sheet; |
|
| 2708 | + |
|
| 2709 | + /** |
|
| 2710 | + * @var boolean $display_address_in_regform |
|
| 2711 | + */ |
|
| 2712 | + public $display_address_in_regform; |
|
| 2713 | + |
|
| 2714 | + /** |
|
| 2715 | + * @var int $display_description_on_multi_reg_page |
|
| 2716 | + */ |
|
| 2717 | + public $display_description_on_multi_reg_page; |
|
| 2718 | + |
|
| 2719 | + /** |
|
| 2720 | + * @var boolean $use_custom_templates |
|
| 2721 | + */ |
|
| 2722 | + public $use_custom_templates; |
|
| 2723 | + |
|
| 2724 | + /** |
|
| 2725 | + * @var string $current_espresso_theme |
|
| 2726 | + */ |
|
| 2727 | + public $current_espresso_theme; |
|
| 2728 | + |
|
| 2729 | + /** |
|
| 2730 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2731 | + */ |
|
| 2732 | + public $EED_Ticket_Selector; |
|
| 2733 | + |
|
| 2734 | + /** |
|
| 2735 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2736 | + */ |
|
| 2737 | + public $EED_Event_Single; |
|
| 2738 | + |
|
| 2739 | + /** |
|
| 2740 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2741 | + */ |
|
| 2742 | + public $EED_Events_Archive; |
|
| 2743 | + |
|
| 2744 | + |
|
| 2745 | + /** |
|
| 2746 | + * class constructor |
|
| 2747 | + * |
|
| 2748 | + * @access public |
|
| 2749 | + */ |
|
| 2750 | + public function __construct() |
|
| 2751 | + { |
|
| 2752 | + // set default template settings |
|
| 2753 | + $this->enable_default_style = true; |
|
| 2754 | + $this->custom_style_sheet = null; |
|
| 2755 | + $this->display_address_in_regform = true; |
|
| 2756 | + $this->display_description_on_multi_reg_page = false; |
|
| 2757 | + $this->use_custom_templates = false; |
|
| 2758 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2759 | + $this->EED_Event_Single = null; |
|
| 2760 | + $this->EED_Events_Archive = null; |
|
| 2761 | + $this->EED_Ticket_Selector = null; |
|
| 2762 | + } |
|
| 2763 | 2763 | } |
| 2764 | 2764 | |
| 2765 | 2765 | /** |
@@ -2768,114 +2768,114 @@ discard block |
||
| 2768 | 2768 | class EE_Map_Config extends EE_Config_Base |
| 2769 | 2769 | { |
| 2770 | 2770 | |
| 2771 | - /** |
|
| 2772 | - * @var boolean $use_google_maps |
|
| 2773 | - */ |
|
| 2774 | - public $use_google_maps; |
|
| 2775 | - |
|
| 2776 | - /** |
|
| 2777 | - * @var string $api_key |
|
| 2778 | - */ |
|
| 2779 | - public $google_map_api_key; |
|
| 2780 | - |
|
| 2781 | - /** |
|
| 2782 | - * @var int $event_details_map_width |
|
| 2783 | - */ |
|
| 2784 | - public $event_details_map_width; |
|
| 2785 | - |
|
| 2786 | - /** |
|
| 2787 | - * @var int $event_details_map_height |
|
| 2788 | - */ |
|
| 2789 | - public $event_details_map_height; |
|
| 2790 | - |
|
| 2791 | - /** |
|
| 2792 | - * @var int $event_details_map_zoom |
|
| 2793 | - */ |
|
| 2794 | - public $event_details_map_zoom; |
|
| 2795 | - |
|
| 2796 | - /** |
|
| 2797 | - * @var boolean $event_details_display_nav |
|
| 2798 | - */ |
|
| 2799 | - public $event_details_display_nav; |
|
| 2800 | - |
|
| 2801 | - /** |
|
| 2802 | - * @var boolean $event_details_nav_size |
|
| 2803 | - */ |
|
| 2804 | - public $event_details_nav_size; |
|
| 2805 | - |
|
| 2806 | - /** |
|
| 2807 | - * @var string $event_details_control_type |
|
| 2808 | - */ |
|
| 2809 | - public $event_details_control_type; |
|
| 2810 | - |
|
| 2811 | - /** |
|
| 2812 | - * @var string $event_details_map_align |
|
| 2813 | - */ |
|
| 2814 | - public $event_details_map_align; |
|
| 2815 | - |
|
| 2816 | - /** |
|
| 2817 | - * @var int $event_list_map_width |
|
| 2818 | - */ |
|
| 2819 | - public $event_list_map_width; |
|
| 2820 | - |
|
| 2821 | - /** |
|
| 2822 | - * @var int $event_list_map_height |
|
| 2823 | - */ |
|
| 2824 | - public $event_list_map_height; |
|
| 2825 | - |
|
| 2826 | - /** |
|
| 2827 | - * @var int $event_list_map_zoom |
|
| 2828 | - */ |
|
| 2829 | - public $event_list_map_zoom; |
|
| 2830 | - |
|
| 2831 | - /** |
|
| 2832 | - * @var boolean $event_list_display_nav |
|
| 2833 | - */ |
|
| 2834 | - public $event_list_display_nav; |
|
| 2835 | - |
|
| 2836 | - /** |
|
| 2837 | - * @var boolean $event_list_nav_size |
|
| 2838 | - */ |
|
| 2839 | - public $event_list_nav_size; |
|
| 2840 | - |
|
| 2841 | - /** |
|
| 2842 | - * @var string $event_list_control_type |
|
| 2843 | - */ |
|
| 2844 | - public $event_list_control_type; |
|
| 2845 | - |
|
| 2846 | - /** |
|
| 2847 | - * @var string $event_list_map_align |
|
| 2848 | - */ |
|
| 2849 | - public $event_list_map_align; |
|
| 2850 | - |
|
| 2851 | - |
|
| 2852 | - /** |
|
| 2853 | - * class constructor |
|
| 2854 | - * |
|
| 2855 | - * @access public |
|
| 2856 | - */ |
|
| 2857 | - public function __construct() |
|
| 2858 | - { |
|
| 2859 | - // set default map settings |
|
| 2860 | - $this->use_google_maps = true; |
|
| 2861 | - $this->google_map_api_key = ''; |
|
| 2862 | - // for event details pages (reg page) |
|
| 2863 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2864 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2865 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2866 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2867 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2868 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2869 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2870 | - // for event list pages |
|
| 2871 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2872 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2873 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2874 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2875 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2876 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2877 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2878 | - } |
|
| 2771 | + /** |
|
| 2772 | + * @var boolean $use_google_maps |
|
| 2773 | + */ |
|
| 2774 | + public $use_google_maps; |
|
| 2775 | + |
|
| 2776 | + /** |
|
| 2777 | + * @var string $api_key |
|
| 2778 | + */ |
|
| 2779 | + public $google_map_api_key; |
|
| 2780 | + |
|
| 2781 | + /** |
|
| 2782 | + * @var int $event_details_map_width |
|
| 2783 | + */ |
|
| 2784 | + public $event_details_map_width; |
|
| 2785 | + |
|
| 2786 | + /** |
|
| 2787 | + * @var int $event_details_map_height |
|
| 2788 | + */ |
|
| 2789 | + public $event_details_map_height; |
|
| 2790 | + |
|
| 2791 | + /** |
|
| 2792 | + * @var int $event_details_map_zoom |
|
| 2793 | + */ |
|
| 2794 | + public $event_details_map_zoom; |
|
| 2795 | + |
|
| 2796 | + /** |
|
| 2797 | + * @var boolean $event_details_display_nav |
|
| 2798 | + */ |
|
| 2799 | + public $event_details_display_nav; |
|
| 2800 | + |
|
| 2801 | + /** |
|
| 2802 | + * @var boolean $event_details_nav_size |
|
| 2803 | + */ |
|
| 2804 | + public $event_details_nav_size; |
|
| 2805 | + |
|
| 2806 | + /** |
|
| 2807 | + * @var string $event_details_control_type |
|
| 2808 | + */ |
|
| 2809 | + public $event_details_control_type; |
|
| 2810 | + |
|
| 2811 | + /** |
|
| 2812 | + * @var string $event_details_map_align |
|
| 2813 | + */ |
|
| 2814 | + public $event_details_map_align; |
|
| 2815 | + |
|
| 2816 | + /** |
|
| 2817 | + * @var int $event_list_map_width |
|
| 2818 | + */ |
|
| 2819 | + public $event_list_map_width; |
|
| 2820 | + |
|
| 2821 | + /** |
|
| 2822 | + * @var int $event_list_map_height |
|
| 2823 | + */ |
|
| 2824 | + public $event_list_map_height; |
|
| 2825 | + |
|
| 2826 | + /** |
|
| 2827 | + * @var int $event_list_map_zoom |
|
| 2828 | + */ |
|
| 2829 | + public $event_list_map_zoom; |
|
| 2830 | + |
|
| 2831 | + /** |
|
| 2832 | + * @var boolean $event_list_display_nav |
|
| 2833 | + */ |
|
| 2834 | + public $event_list_display_nav; |
|
| 2835 | + |
|
| 2836 | + /** |
|
| 2837 | + * @var boolean $event_list_nav_size |
|
| 2838 | + */ |
|
| 2839 | + public $event_list_nav_size; |
|
| 2840 | + |
|
| 2841 | + /** |
|
| 2842 | + * @var string $event_list_control_type |
|
| 2843 | + */ |
|
| 2844 | + public $event_list_control_type; |
|
| 2845 | + |
|
| 2846 | + /** |
|
| 2847 | + * @var string $event_list_map_align |
|
| 2848 | + */ |
|
| 2849 | + public $event_list_map_align; |
|
| 2850 | + |
|
| 2851 | + |
|
| 2852 | + /** |
|
| 2853 | + * class constructor |
|
| 2854 | + * |
|
| 2855 | + * @access public |
|
| 2856 | + */ |
|
| 2857 | + public function __construct() |
|
| 2858 | + { |
|
| 2859 | + // set default map settings |
|
| 2860 | + $this->use_google_maps = true; |
|
| 2861 | + $this->google_map_api_key = ''; |
|
| 2862 | + // for event details pages (reg page) |
|
| 2863 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2864 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2865 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2866 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2867 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2868 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2869 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2870 | + // for event list pages |
|
| 2871 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2872 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2873 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2874 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2875 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2876 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2877 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2878 | + } |
|
| 2879 | 2879 | } |
| 2880 | 2880 | |
| 2881 | 2881 | /** |
@@ -2884,46 +2884,46 @@ discard block |
||
| 2884 | 2884 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2885 | 2885 | { |
| 2886 | 2886 | |
| 2887 | - public $display_status_banner; |
|
| 2887 | + public $display_status_banner; |
|
| 2888 | 2888 | |
| 2889 | - public $display_description; |
|
| 2889 | + public $display_description; |
|
| 2890 | 2890 | |
| 2891 | - public $display_ticket_selector; |
|
| 2891 | + public $display_ticket_selector; |
|
| 2892 | 2892 | |
| 2893 | - public $display_datetimes; |
|
| 2893 | + public $display_datetimes; |
|
| 2894 | 2894 | |
| 2895 | - public $display_venue; |
|
| 2895 | + public $display_venue; |
|
| 2896 | 2896 | |
| 2897 | - public $display_expired_events; |
|
| 2897 | + public $display_expired_events; |
|
| 2898 | 2898 | |
| 2899 | - public $use_sortable_display_order; |
|
| 2899 | + public $use_sortable_display_order; |
|
| 2900 | 2900 | |
| 2901 | - public $display_order_tickets; |
|
| 2901 | + public $display_order_tickets; |
|
| 2902 | 2902 | |
| 2903 | - public $display_order_datetimes; |
|
| 2903 | + public $display_order_datetimes; |
|
| 2904 | 2904 | |
| 2905 | - public $display_order_event; |
|
| 2905 | + public $display_order_event; |
|
| 2906 | 2906 | |
| 2907 | - public $display_order_venue; |
|
| 2907 | + public $display_order_venue; |
|
| 2908 | 2908 | |
| 2909 | 2909 | |
| 2910 | - /** |
|
| 2911 | - * class constructor |
|
| 2912 | - */ |
|
| 2913 | - public function __construct() |
|
| 2914 | - { |
|
| 2915 | - $this->display_status_banner = 0; |
|
| 2916 | - $this->display_description = 1; |
|
| 2917 | - $this->display_ticket_selector = 0; |
|
| 2918 | - $this->display_datetimes = 1; |
|
| 2919 | - $this->display_venue = 0; |
|
| 2920 | - $this->display_expired_events = 0; |
|
| 2921 | - $this->use_sortable_display_order = false; |
|
| 2922 | - $this->display_order_tickets = 100; |
|
| 2923 | - $this->display_order_datetimes = 110; |
|
| 2924 | - $this->display_order_event = 120; |
|
| 2925 | - $this->display_order_venue = 130; |
|
| 2926 | - } |
|
| 2910 | + /** |
|
| 2911 | + * class constructor |
|
| 2912 | + */ |
|
| 2913 | + public function __construct() |
|
| 2914 | + { |
|
| 2915 | + $this->display_status_banner = 0; |
|
| 2916 | + $this->display_description = 1; |
|
| 2917 | + $this->display_ticket_selector = 0; |
|
| 2918 | + $this->display_datetimes = 1; |
|
| 2919 | + $this->display_venue = 0; |
|
| 2920 | + $this->display_expired_events = 0; |
|
| 2921 | + $this->use_sortable_display_order = false; |
|
| 2922 | + $this->display_order_tickets = 100; |
|
| 2923 | + $this->display_order_datetimes = 110; |
|
| 2924 | + $this->display_order_event = 120; |
|
| 2925 | + $this->display_order_venue = 130; |
|
| 2926 | + } |
|
| 2927 | 2927 | } |
| 2928 | 2928 | |
| 2929 | 2929 | /** |
@@ -2932,34 +2932,34 @@ discard block |
||
| 2932 | 2932 | class EE_Event_Single_Config extends EE_Config_Base |
| 2933 | 2933 | { |
| 2934 | 2934 | |
| 2935 | - public $display_status_banner_single; |
|
| 2935 | + public $display_status_banner_single; |
|
| 2936 | 2936 | |
| 2937 | - public $display_venue; |
|
| 2937 | + public $display_venue; |
|
| 2938 | 2938 | |
| 2939 | - public $use_sortable_display_order; |
|
| 2939 | + public $use_sortable_display_order; |
|
| 2940 | 2940 | |
| 2941 | - public $display_order_tickets; |
|
| 2941 | + public $display_order_tickets; |
|
| 2942 | 2942 | |
| 2943 | - public $display_order_datetimes; |
|
| 2943 | + public $display_order_datetimes; |
|
| 2944 | 2944 | |
| 2945 | - public $display_order_event; |
|
| 2945 | + public $display_order_event; |
|
| 2946 | 2946 | |
| 2947 | - public $display_order_venue; |
|
| 2947 | + public $display_order_venue; |
|
| 2948 | 2948 | |
| 2949 | 2949 | |
| 2950 | - /** |
|
| 2951 | - * class constructor |
|
| 2952 | - */ |
|
| 2953 | - public function __construct() |
|
| 2954 | - { |
|
| 2955 | - $this->display_status_banner_single = 0; |
|
| 2956 | - $this->display_venue = 1; |
|
| 2957 | - $this->use_sortable_display_order = false; |
|
| 2958 | - $this->display_order_tickets = 100; |
|
| 2959 | - $this->display_order_datetimes = 110; |
|
| 2960 | - $this->display_order_event = 120; |
|
| 2961 | - $this->display_order_venue = 130; |
|
| 2962 | - } |
|
| 2950 | + /** |
|
| 2951 | + * class constructor |
|
| 2952 | + */ |
|
| 2953 | + public function __construct() |
|
| 2954 | + { |
|
| 2955 | + $this->display_status_banner_single = 0; |
|
| 2956 | + $this->display_venue = 1; |
|
| 2957 | + $this->use_sortable_display_order = false; |
|
| 2958 | + $this->display_order_tickets = 100; |
|
| 2959 | + $this->display_order_datetimes = 110; |
|
| 2960 | + $this->display_order_event = 120; |
|
| 2961 | + $this->display_order_venue = 130; |
|
| 2962 | + } |
|
| 2963 | 2963 | } |
| 2964 | 2964 | |
| 2965 | 2965 | /** |
@@ -2968,146 +2968,146 @@ discard block |
||
| 2968 | 2968 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 2969 | 2969 | { |
| 2970 | 2970 | |
| 2971 | - /** |
|
| 2972 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2973 | - */ |
|
| 2974 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2975 | - |
|
| 2976 | - /** |
|
| 2977 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2978 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2979 | - */ |
|
| 2980 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2981 | - |
|
| 2982 | - /** |
|
| 2983 | - * @var boolean $show_ticket_sale_columns |
|
| 2984 | - */ |
|
| 2985 | - public $show_ticket_sale_columns; |
|
| 2986 | - |
|
| 2987 | - /** |
|
| 2988 | - * @var boolean $show_ticket_details |
|
| 2989 | - */ |
|
| 2990 | - public $show_ticket_details; |
|
| 2991 | - |
|
| 2992 | - /** |
|
| 2993 | - * @var boolean $show_expired_tickets |
|
| 2994 | - */ |
|
| 2995 | - public $show_expired_tickets; |
|
| 2996 | - |
|
| 2997 | - /** |
|
| 2998 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 2999 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 3000 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3001 | - * |
|
| 3002 | - * @var string $show_datetime_selector |
|
| 3003 | - */ |
|
| 3004 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3005 | - |
|
| 3006 | - /** |
|
| 3007 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3008 | - * |
|
| 3009 | - * @var int $datetime_selector_threshold |
|
| 3010 | - */ |
|
| 3011 | - private $datetime_selector_threshold = 3; |
|
| 3012 | - |
|
| 3013 | - |
|
| 3014 | - /** |
|
| 3015 | - * class constructor |
|
| 3016 | - */ |
|
| 3017 | - public function __construct() |
|
| 3018 | - { |
|
| 3019 | - $this->show_ticket_sale_columns = true; |
|
| 3020 | - $this->show_ticket_details = true; |
|
| 3021 | - $this->show_expired_tickets = true; |
|
| 3022 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3023 | - $this->datetime_selector_threshold = 3; |
|
| 3024 | - } |
|
| 3025 | - |
|
| 3026 | - |
|
| 3027 | - /** |
|
| 3028 | - * returns true if a datetime selector should be displayed |
|
| 3029 | - * |
|
| 3030 | - * @param array $datetimes |
|
| 3031 | - * @return bool |
|
| 3032 | - */ |
|
| 3033 | - public function showDatetimeSelector(array $datetimes) |
|
| 3034 | - { |
|
| 3035 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3036 | - return ! ( |
|
| 3037 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3038 | - || ( |
|
| 3039 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3040 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3041 | - ) |
|
| 3042 | - ); |
|
| 3043 | - } |
|
| 3044 | - |
|
| 3045 | - |
|
| 3046 | - /** |
|
| 3047 | - * @return string |
|
| 3048 | - */ |
|
| 3049 | - public function getShowDatetimeSelector() |
|
| 3050 | - { |
|
| 3051 | - return $this->show_datetime_selector; |
|
| 3052 | - } |
|
| 3053 | - |
|
| 3054 | - |
|
| 3055 | - /** |
|
| 3056 | - * @param bool $keys_only |
|
| 3057 | - * @return array |
|
| 3058 | - */ |
|
| 3059 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3060 | - { |
|
| 3061 | - return $keys_only |
|
| 3062 | - ? array( |
|
| 3063 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3064 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3065 | - ) |
|
| 3066 | - : array( |
|
| 3067 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3068 | - 'Do not show date & time filter', |
|
| 3069 | - 'event_espresso' |
|
| 3070 | - ), |
|
| 3071 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3072 | - 'Maybe show date & time filter', |
|
| 3073 | - 'event_espresso' |
|
| 3074 | - ), |
|
| 3075 | - ); |
|
| 3076 | - } |
|
| 3077 | - |
|
| 3078 | - |
|
| 3079 | - /** |
|
| 3080 | - * @param string $show_datetime_selector |
|
| 3081 | - */ |
|
| 3082 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3083 | - { |
|
| 3084 | - $this->show_datetime_selector = in_array( |
|
| 3085 | - $show_datetime_selector, |
|
| 3086 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3087 | - true |
|
| 3088 | - ) |
|
| 3089 | - ? $show_datetime_selector |
|
| 3090 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3091 | - } |
|
| 3092 | - |
|
| 3093 | - |
|
| 3094 | - /** |
|
| 3095 | - * @return int |
|
| 3096 | - */ |
|
| 3097 | - public function getDatetimeSelectorThreshold() |
|
| 3098 | - { |
|
| 3099 | - return $this->datetime_selector_threshold; |
|
| 3100 | - } |
|
| 3101 | - |
|
| 3102 | - |
|
| 3103 | - /** |
|
| 3104 | - * @param int $datetime_selector_threshold |
|
| 3105 | - */ |
|
| 3106 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3107 | - { |
|
| 3108 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3109 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3110 | - } |
|
| 2971 | + /** |
|
| 2972 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2973 | + */ |
|
| 2974 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2975 | + |
|
| 2976 | + /** |
|
| 2977 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2978 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2979 | + */ |
|
| 2980 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2981 | + |
|
| 2982 | + /** |
|
| 2983 | + * @var boolean $show_ticket_sale_columns |
|
| 2984 | + */ |
|
| 2985 | + public $show_ticket_sale_columns; |
|
| 2986 | + |
|
| 2987 | + /** |
|
| 2988 | + * @var boolean $show_ticket_details |
|
| 2989 | + */ |
|
| 2990 | + public $show_ticket_details; |
|
| 2991 | + |
|
| 2992 | + /** |
|
| 2993 | + * @var boolean $show_expired_tickets |
|
| 2994 | + */ |
|
| 2995 | + public $show_expired_tickets; |
|
| 2996 | + |
|
| 2997 | + /** |
|
| 2998 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 2999 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 3000 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3001 | + * |
|
| 3002 | + * @var string $show_datetime_selector |
|
| 3003 | + */ |
|
| 3004 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3005 | + |
|
| 3006 | + /** |
|
| 3007 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3008 | + * |
|
| 3009 | + * @var int $datetime_selector_threshold |
|
| 3010 | + */ |
|
| 3011 | + private $datetime_selector_threshold = 3; |
|
| 3012 | + |
|
| 3013 | + |
|
| 3014 | + /** |
|
| 3015 | + * class constructor |
|
| 3016 | + */ |
|
| 3017 | + public function __construct() |
|
| 3018 | + { |
|
| 3019 | + $this->show_ticket_sale_columns = true; |
|
| 3020 | + $this->show_ticket_details = true; |
|
| 3021 | + $this->show_expired_tickets = true; |
|
| 3022 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3023 | + $this->datetime_selector_threshold = 3; |
|
| 3024 | + } |
|
| 3025 | + |
|
| 3026 | + |
|
| 3027 | + /** |
|
| 3028 | + * returns true if a datetime selector should be displayed |
|
| 3029 | + * |
|
| 3030 | + * @param array $datetimes |
|
| 3031 | + * @return bool |
|
| 3032 | + */ |
|
| 3033 | + public function showDatetimeSelector(array $datetimes) |
|
| 3034 | + { |
|
| 3035 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3036 | + return ! ( |
|
| 3037 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3038 | + || ( |
|
| 3039 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3040 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3041 | + ) |
|
| 3042 | + ); |
|
| 3043 | + } |
|
| 3044 | + |
|
| 3045 | + |
|
| 3046 | + /** |
|
| 3047 | + * @return string |
|
| 3048 | + */ |
|
| 3049 | + public function getShowDatetimeSelector() |
|
| 3050 | + { |
|
| 3051 | + return $this->show_datetime_selector; |
|
| 3052 | + } |
|
| 3053 | + |
|
| 3054 | + |
|
| 3055 | + /** |
|
| 3056 | + * @param bool $keys_only |
|
| 3057 | + * @return array |
|
| 3058 | + */ |
|
| 3059 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3060 | + { |
|
| 3061 | + return $keys_only |
|
| 3062 | + ? array( |
|
| 3063 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3064 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3065 | + ) |
|
| 3066 | + : array( |
|
| 3067 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3068 | + 'Do not show date & time filter', |
|
| 3069 | + 'event_espresso' |
|
| 3070 | + ), |
|
| 3071 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3072 | + 'Maybe show date & time filter', |
|
| 3073 | + 'event_espresso' |
|
| 3074 | + ), |
|
| 3075 | + ); |
|
| 3076 | + } |
|
| 3077 | + |
|
| 3078 | + |
|
| 3079 | + /** |
|
| 3080 | + * @param string $show_datetime_selector |
|
| 3081 | + */ |
|
| 3082 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3083 | + { |
|
| 3084 | + $this->show_datetime_selector = in_array( |
|
| 3085 | + $show_datetime_selector, |
|
| 3086 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3087 | + true |
|
| 3088 | + ) |
|
| 3089 | + ? $show_datetime_selector |
|
| 3090 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3091 | + } |
|
| 3092 | + |
|
| 3093 | + |
|
| 3094 | + /** |
|
| 3095 | + * @return int |
|
| 3096 | + */ |
|
| 3097 | + public function getDatetimeSelectorThreshold() |
|
| 3098 | + { |
|
| 3099 | + return $this->datetime_selector_threshold; |
|
| 3100 | + } |
|
| 3101 | + |
|
| 3102 | + |
|
| 3103 | + /** |
|
| 3104 | + * @param int $datetime_selector_threshold |
|
| 3105 | + */ |
|
| 3106 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3107 | + { |
|
| 3108 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3109 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3110 | + } |
|
| 3111 | 3111 | } |
| 3112 | 3112 | |
| 3113 | 3113 | /** |
@@ -3120,81 +3120,81 @@ discard block |
||
| 3120 | 3120 | class EE_Environment_Config extends EE_Config_Base |
| 3121 | 3121 | { |
| 3122 | 3122 | |
| 3123 | - /** |
|
| 3124 | - * Hold any php environment variables that we want to track. |
|
| 3125 | - * |
|
| 3126 | - * @var stdClass; |
|
| 3127 | - */ |
|
| 3128 | - public $php; |
|
| 3129 | - |
|
| 3130 | - |
|
| 3131 | - /** |
|
| 3132 | - * constructor |
|
| 3133 | - */ |
|
| 3134 | - public function __construct() |
|
| 3135 | - { |
|
| 3136 | - $this->php = new stdClass(); |
|
| 3137 | - $this->_set_php_values(); |
|
| 3138 | - } |
|
| 3139 | - |
|
| 3140 | - |
|
| 3141 | - /** |
|
| 3142 | - * This sets the php environment variables. |
|
| 3143 | - * |
|
| 3144 | - * @since 4.4.0 |
|
| 3145 | - * @return void |
|
| 3146 | - */ |
|
| 3147 | - protected function _set_php_values() |
|
| 3148 | - { |
|
| 3149 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3150 | - $this->php->version = phpversion(); |
|
| 3151 | - } |
|
| 3152 | - |
|
| 3153 | - |
|
| 3154 | - /** |
|
| 3155 | - * helper method for determining whether input_count is |
|
| 3156 | - * reaching the potential maximum the server can handle |
|
| 3157 | - * according to max_input_vars |
|
| 3158 | - * |
|
| 3159 | - * @param int $input_count the count of input vars. |
|
| 3160 | - * @return array { |
|
| 3161 | - * An array that represents whether available space and if no available space the error |
|
| 3162 | - * message. |
|
| 3163 | - * @type bool $has_space whether more inputs can be added. |
|
| 3164 | - * @type string $msg Any message to be displayed. |
|
| 3165 | - * } |
|
| 3166 | - */ |
|
| 3167 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3168 | - { |
|
| 3169 | - if (! empty($this->php->max_input_vars) |
|
| 3170 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3171 | - && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3172 | - ) { |
|
| 3173 | - return sprintf( |
|
| 3174 | - __( |
|
| 3175 | - 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3176 | - 'event_espresso' |
|
| 3177 | - ), |
|
| 3178 | - '<br>', |
|
| 3179 | - $input_count, |
|
| 3180 | - $this->php->max_input_vars |
|
| 3181 | - ); |
|
| 3182 | - } else { |
|
| 3183 | - return ''; |
|
| 3184 | - } |
|
| 3185 | - } |
|
| 3186 | - |
|
| 3187 | - |
|
| 3188 | - /** |
|
| 3189 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3190 | - * |
|
| 3191 | - * @since 4.4.1 |
|
| 3192 | - * @return void |
|
| 3193 | - */ |
|
| 3194 | - public function recheck_values() |
|
| 3195 | - { |
|
| 3196 | - $this->_set_php_values(); |
|
| 3197 | - } |
|
| 3123 | + /** |
|
| 3124 | + * Hold any php environment variables that we want to track. |
|
| 3125 | + * |
|
| 3126 | + * @var stdClass; |
|
| 3127 | + */ |
|
| 3128 | + public $php; |
|
| 3129 | + |
|
| 3130 | + |
|
| 3131 | + /** |
|
| 3132 | + * constructor |
|
| 3133 | + */ |
|
| 3134 | + public function __construct() |
|
| 3135 | + { |
|
| 3136 | + $this->php = new stdClass(); |
|
| 3137 | + $this->_set_php_values(); |
|
| 3138 | + } |
|
| 3139 | + |
|
| 3140 | + |
|
| 3141 | + /** |
|
| 3142 | + * This sets the php environment variables. |
|
| 3143 | + * |
|
| 3144 | + * @since 4.4.0 |
|
| 3145 | + * @return void |
|
| 3146 | + */ |
|
| 3147 | + protected function _set_php_values() |
|
| 3148 | + { |
|
| 3149 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3150 | + $this->php->version = phpversion(); |
|
| 3151 | + } |
|
| 3152 | + |
|
| 3153 | + |
|
| 3154 | + /** |
|
| 3155 | + * helper method for determining whether input_count is |
|
| 3156 | + * reaching the potential maximum the server can handle |
|
| 3157 | + * according to max_input_vars |
|
| 3158 | + * |
|
| 3159 | + * @param int $input_count the count of input vars. |
|
| 3160 | + * @return array { |
|
| 3161 | + * An array that represents whether available space and if no available space the error |
|
| 3162 | + * message. |
|
| 3163 | + * @type bool $has_space whether more inputs can be added. |
|
| 3164 | + * @type string $msg Any message to be displayed. |
|
| 3165 | + * } |
|
| 3166 | + */ |
|
| 3167 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3168 | + { |
|
| 3169 | + if (! empty($this->php->max_input_vars) |
|
| 3170 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3171 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3172 | + ) { |
|
| 3173 | + return sprintf( |
|
| 3174 | + __( |
|
| 3175 | + 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3176 | + 'event_espresso' |
|
| 3177 | + ), |
|
| 3178 | + '<br>', |
|
| 3179 | + $input_count, |
|
| 3180 | + $this->php->max_input_vars |
|
| 3181 | + ); |
|
| 3182 | + } else { |
|
| 3183 | + return ''; |
|
| 3184 | + } |
|
| 3185 | + } |
|
| 3186 | + |
|
| 3187 | + |
|
| 3188 | + /** |
|
| 3189 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3190 | + * |
|
| 3191 | + * @since 4.4.1 |
|
| 3192 | + * @return void |
|
| 3193 | + */ |
|
| 3194 | + public function recheck_values() |
|
| 3195 | + { |
|
| 3196 | + $this->_set_php_values(); |
|
| 3197 | + } |
|
| 3198 | 3198 | } |
| 3199 | 3199 | |
| 3200 | 3200 | /** |
@@ -3207,21 +3207,21 @@ discard block |
||
| 3207 | 3207 | class EE_Tax_Config extends EE_Config_Base |
| 3208 | 3208 | { |
| 3209 | 3209 | |
| 3210 | - /* |
|
| 3210 | + /* |
|
| 3211 | 3211 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3212 | 3212 | * |
| 3213 | 3213 | * @var boolean $prices_displayed_including_taxes |
| 3214 | 3214 | */ |
| 3215 | - public $prices_displayed_including_taxes; |
|
| 3215 | + public $prices_displayed_including_taxes; |
|
| 3216 | 3216 | |
| 3217 | 3217 | |
| 3218 | - /** |
|
| 3219 | - * class constructor |
|
| 3220 | - */ |
|
| 3221 | - public function __construct() |
|
| 3222 | - { |
|
| 3223 | - $this->prices_displayed_including_taxes = true; |
|
| 3224 | - } |
|
| 3218 | + /** |
|
| 3219 | + * class constructor |
|
| 3220 | + */ |
|
| 3221 | + public function __construct() |
|
| 3222 | + { |
|
| 3223 | + $this->prices_displayed_including_taxes = true; |
|
| 3224 | + } |
|
| 3225 | 3225 | } |
| 3226 | 3226 | |
| 3227 | 3227 | /** |
@@ -3235,19 +3235,19 @@ discard block |
||
| 3235 | 3235 | class EE_Messages_Config extends EE_Config_Base |
| 3236 | 3236 | { |
| 3237 | 3237 | |
| 3238 | - /** |
|
| 3239 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3240 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3241 | - * |
|
| 3242 | - * @var integer |
|
| 3243 | - */ |
|
| 3244 | - public $delete_threshold; |
|
| 3238 | + /** |
|
| 3239 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3240 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3241 | + * |
|
| 3242 | + * @var integer |
|
| 3243 | + */ |
|
| 3244 | + public $delete_threshold; |
|
| 3245 | 3245 | |
| 3246 | 3246 | |
| 3247 | - public function __construct() |
|
| 3248 | - { |
|
| 3249 | - $this->delete_threshold = 0; |
|
| 3250 | - } |
|
| 3247 | + public function __construct() |
|
| 3248 | + { |
|
| 3249 | + $this->delete_threshold = 0; |
|
| 3250 | + } |
|
| 3251 | 3251 | } |
| 3252 | 3252 | |
| 3253 | 3253 | /** |
@@ -3258,31 +3258,31 @@ discard block |
||
| 3258 | 3258 | class EE_Gateway_Config extends EE_Config_Base |
| 3259 | 3259 | { |
| 3260 | 3260 | |
| 3261 | - /** |
|
| 3262 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3263 | - * with any config info the gateway wants to store |
|
| 3264 | - * |
|
| 3265 | - * @var array |
|
| 3266 | - */ |
|
| 3267 | - public $payment_settings; |
|
| 3268 | - |
|
| 3269 | - /** |
|
| 3270 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3271 | - * the gateway is stored in the uploads directory |
|
| 3272 | - * |
|
| 3273 | - * @var array |
|
| 3274 | - */ |
|
| 3275 | - public $active_gateways; |
|
| 3276 | - |
|
| 3277 | - |
|
| 3278 | - /** |
|
| 3279 | - * class constructor |
|
| 3280 | - * |
|
| 3281 | - * @deprecated |
|
| 3282 | - */ |
|
| 3283 | - public function __construct() |
|
| 3284 | - { |
|
| 3285 | - $this->payment_settings = array(); |
|
| 3286 | - $this->active_gateways = array('Invoice' => false); |
|
| 3287 | - } |
|
| 3261 | + /** |
|
| 3262 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3263 | + * with any config info the gateway wants to store |
|
| 3264 | + * |
|
| 3265 | + * @var array |
|
| 3266 | + */ |
|
| 3267 | + public $payment_settings; |
|
| 3268 | + |
|
| 3269 | + /** |
|
| 3270 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3271 | + * the gateway is stored in the uploads directory |
|
| 3272 | + * |
|
| 3273 | + * @var array |
|
| 3274 | + */ |
|
| 3275 | + public $active_gateways; |
|
| 3276 | + |
|
| 3277 | + |
|
| 3278 | + /** |
|
| 3279 | + * class constructor |
|
| 3280 | + * |
|
| 3281 | + * @deprecated |
|
| 3282 | + */ |
|
| 3283 | + public function __construct() |
|
| 3284 | + { |
|
| 3285 | + $this->payment_settings = array(); |
|
| 3286 | + $this->active_gateways = array('Invoice' => false); |
|
| 3287 | + } |
|
| 3288 | 3288 | } |
@@ -14,694 +14,694 @@ |
||
| 14 | 14 | { |
| 15 | 15 | |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @type string reference for sending action |
|
| 19 | - */ |
|
| 20 | - const action_sending = 'sending'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @type string reference for generation action |
|
| 24 | - */ |
|
| 25 | - const action_generating = 'generation'; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @type EE_Message_Repository $_message_repository |
|
| 30 | - */ |
|
| 31 | - protected $_message_repository; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Sets the limit of how many messages are generated per process. |
|
| 35 | - * |
|
| 36 | - * @type int |
|
| 37 | - */ |
|
| 38 | - protected $_batch_count; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * This is an array of cached queue items being stored in this object. |
|
| 43 | - * The array keys will be the ID of the EE_Message in the db if saved. If the EE_Message |
|
| 44 | - * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.) |
|
| 45 | - * |
|
| 46 | - * @type EE_Message[] |
|
| 47 | - */ |
|
| 48 | - protected $_cached_queue_items; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Tracks the number of unsaved queue items. |
|
| 52 | - * |
|
| 53 | - * @type int |
|
| 54 | - */ |
|
| 55 | - protected $_unsaved_count = 0; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * used to record if a do_messenger_hooks has already been called for a message type. This prevents multiple |
|
| 59 | - * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls. |
|
| 60 | - * |
|
| 61 | - * @type array |
|
| 62 | - */ |
|
| 63 | - protected $_did_hook = array(); |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Constructor. |
|
| 68 | - * Setup all the initial properties and load a EE_Message_Repository. |
|
| 69 | - * |
|
| 70 | - * @param \EE_Message_Repository $message_repository |
|
| 71 | - */ |
|
| 72 | - public function __construct(EE_Message_Repository $message_repository) |
|
| 73 | - { |
|
| 74 | - $this->_batch_count = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50); |
|
| 75 | - $this->_message_repository = $message_repository; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Add a EE_Message object to the queue |
|
| 81 | - * |
|
| 82 | - * @param EE_Message $message |
|
| 83 | - * @param array $data This will be an array of data to attach to the object in the repository. If the |
|
| 84 | - * object is persisted, this data will be saved on an extra_meta object related to |
|
| 85 | - * EE_Message. |
|
| 86 | - * @param bool $preview Whether this EE_Message represents a preview or not. |
|
| 87 | - * @param bool $test_send This indicates whether to do a test send instead of actual send. A test send will |
|
| 88 | - * use the messenger send method but typically is based on preview data. |
|
| 89 | - * @return bool Whether the message was successfully added to the repository or not. |
|
| 90 | - */ |
|
| 91 | - public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false) |
|
| 92 | - { |
|
| 93 | - $data['preview'] = $preview; |
|
| 94 | - $data['test_send'] = $test_send; |
|
| 95 | - return $this->_message_repository->add($message, $data); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message |
|
| 101 | - * |
|
| 102 | - * @param EE_Message $message The message to detach from the queue |
|
| 103 | - * @param bool $persist This flag indicates whether to attempt to delete the object from the db as well. |
|
| 104 | - * @return bool |
|
| 105 | - */ |
|
| 106 | - public function remove(EE_Message $message, $persist = false) |
|
| 107 | - { |
|
| 108 | - if ($persist && $this->_message_repository->current() !== $message) { |
|
| 109 | - // get pointer on right message |
|
| 110 | - if ($this->_message_repository->has($message)) { |
|
| 111 | - $this->_message_repository->rewind(); |
|
| 112 | - while ($this->_message_repository->valid()) { |
|
| 113 | - if ($this->_message_repository->current() === $message) { |
|
| 114 | - break; |
|
| 115 | - } |
|
| 116 | - $this->_message_repository->next(); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - return false; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Persists all queued EE_Message objects to the db. |
|
| 128 | - * |
|
| 129 | - * @param bool $do_hooks_only @see EE_Message_Repository::saveAll |
|
| 130 | - * @return array @see EE_Messages_Repository::saveAll() for return values. |
|
| 131 | - */ |
|
| 132 | - public function save($do_hooks_only = false) |
|
| 133 | - { |
|
| 134 | - return $this->_message_repository->saveAll($do_hooks_only); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return EE_Message_Repository |
|
| 140 | - */ |
|
| 141 | - public function get_message_repository() |
|
| 142 | - { |
|
| 143 | - return $this->_message_repository; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * This does the following things: |
|
| 149 | - * 1. Checks if there is a lock on generation (prevents race conditions). If there is a lock then exits (return |
|
| 150 | - * false). |
|
| 151 | - * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue |
|
| 152 | - * 3. Returns bool. True = batch ready. False = no batch ready (or nothing available for generation). |
|
| 153 | - * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from |
|
| 154 | - * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not |
|
| 155 | - * removed. |
|
| 156 | - * |
|
| 157 | - * @return bool true if successfully retrieved batch, false no batch ready. |
|
| 158 | - */ |
|
| 159 | - public function get_batch_to_generate() |
|
| 160 | - { |
|
| 161 | - if ($this->is_locked(EE_Messages_Queue::action_generating)) { |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // lock batch generation to prevent race conditions. |
|
| 166 | - $this->lock_queue(EE_Messages_Queue::action_generating); |
|
| 167 | - |
|
| 168 | - $query_args = array( |
|
| 169 | - // key 0 = where conditions |
|
| 170 | - 0 => array('STS_ID' => EEM_Message::status_incomplete), |
|
| 171 | - 'order_by' => $this->_get_priority_orderby(), |
|
| 172 | - 'limit' => $this->_batch_count, |
|
| 173 | - ); |
|
| 174 | - $messages = EEM_Message::instance()->get_all($query_args); |
|
| 175 | - |
|
| 176 | - if (! $messages) { |
|
| 177 | - return false; // nothing to generate |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - foreach ($messages as $message) { |
|
| 181 | - if ($message instanceof EE_Message) { |
|
| 182 | - $data = $message->all_extra_meta_array(); |
|
| 183 | - $this->add($message, $data); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - return true; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * This does the following things: |
|
| 192 | - * 1. Checks if there is a lock on sending (prevents race conditions). If there is a lock then exits (return |
|
| 193 | - * false). |
|
| 194 | - * 2. Grabs the allowed number of messages to send for the rate_limit. If cannot send any more messages, then |
|
| 195 | - * return false. |
|
| 196 | - * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution. |
|
| 197 | - * 3. On success or unsuccessful send, sets status appropriately. |
|
| 198 | - * 4. Saves messages via the queue |
|
| 199 | - * 5. Releases lock. |
|
| 200 | - * |
|
| 201 | - * @return bool true on success, false if something preventing sending (i.e. lock set). Note: true does not |
|
| 202 | - * necessarily mean that all messages were successfully sent. It just means that this method |
|
| 203 | - * successfully completed. On true, client may want to call $this->count_STS_in_queue( |
|
| 204 | - * EEM_Message::status_failed ) to see if any failed EE_Message objects. Each failed message object |
|
| 205 | - * will also have a saved error message on it to assist with notifying user. |
|
| 206 | - */ |
|
| 207 | - public function get_to_send_batch_and_send() |
|
| 208 | - { |
|
| 209 | - $rate_limit = $this->get_rate_limit(); |
|
| 210 | - if ($rate_limit < 1 |
|
| 211 | - || $this->is_locked(EE_Messages_Queue::action_sending)) { |
|
| 212 | - return false; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $this->lock_queue(EE_Messages_Queue::action_sending); |
|
| 216 | - |
|
| 217 | - $batch = $this->_batch_count < $rate_limit ? $this->_batch_count : $rate_limit; |
|
| 218 | - |
|
| 219 | - $query_args = array( |
|
| 220 | - // key 0 = where conditions |
|
| 221 | - 0 => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())), |
|
| 222 | - 'order_by' => $this->_get_priority_orderby(), |
|
| 223 | - 'limit' => $batch, |
|
| 224 | - ); |
|
| 225 | - |
|
| 226 | - $messages_to_send = EEM_Message::instance()->get_all($query_args); |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - // any to send? |
|
| 230 | - if (! $messages_to_send) { |
|
| 231 | - $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
| 232 | - return false; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $queue_count = 0; |
|
| 236 | - |
|
| 237 | - // add to queue. |
|
| 238 | - foreach ($messages_to_send as $message) { |
|
| 239 | - if ($message instanceof EE_Message) { |
|
| 240 | - $queue_count++; |
|
| 241 | - $this->add($message); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - // send messages (this also updates the rate limit) |
|
| 246 | - $this->execute(); |
|
| 247 | - |
|
| 248 | - // release lock |
|
| 249 | - $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
| 250 | - // update rate limit |
|
| 251 | - $this->set_rate_limit($queue_count); |
|
| 252 | - return true; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Locks the queue so that no other queues can call the "batch" methods. |
|
| 258 | - * |
|
| 259 | - * @param string $type The type of queue being locked. |
|
| 260 | - */ |
|
| 261 | - public function lock_queue($type = EE_Messages_Queue::action_generating) |
|
| 262 | - { |
|
| 263 | - update_option($this->_get_lock_key($type), $this->_get_lock_expiry($type)); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Unlocks the queue so that batch methods can be used. |
|
| 269 | - * |
|
| 270 | - * @param string $type The type of queue being unlocked. |
|
| 271 | - */ |
|
| 272 | - public function unlock_queue($type = EE_Messages_Queue::action_generating) |
|
| 273 | - { |
|
| 274 | - delete_option($this->_get_lock_key($type)); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Retrieve the key used for the lock transient. |
|
| 280 | - * |
|
| 281 | - * @param string $type The type of lock. |
|
| 282 | - * @return string |
|
| 283 | - */ |
|
| 284 | - protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
|
| 285 | - { |
|
| 286 | - return '_ee_lock_' . $type; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Retrieve the expiry time for the lock transient. |
|
| 292 | - * |
|
| 293 | - * @param string $type The type of lock |
|
| 294 | - * @return int time to expiry in seconds. |
|
| 295 | - */ |
|
| 296 | - protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating) |
|
| 297 | - { |
|
| 298 | - return time() + (int) apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Returns the key used for rate limit transient. |
|
| 304 | - * |
|
| 305 | - * @return string |
|
| 306 | - */ |
|
| 307 | - protected function _get_rate_limit_key() |
|
| 308 | - { |
|
| 309 | - return '_ee_rate_limit'; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Returns the rate limit expiry time. |
|
| 315 | - * |
|
| 316 | - * @return int |
|
| 317 | - */ |
|
| 318 | - protected function _get_rate_limit_expiry() |
|
| 319 | - { |
|
| 320 | - return time() + (int) apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Returns the default rate limit for sending messages. |
|
| 326 | - * |
|
| 327 | - * @return int |
|
| 328 | - */ |
|
| 329 | - protected function _default_rate_limit() |
|
| 330 | - { |
|
| 331 | - return (int) apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Return the orderby array for priority. |
|
| 337 | - * |
|
| 338 | - * @return array |
|
| 339 | - */ |
|
| 340 | - protected function _get_priority_orderby() |
|
| 341 | - { |
|
| 342 | - return array( |
|
| 343 | - 'MSG_priority' => 'ASC', |
|
| 344 | - 'MSG_modified' => 'DESC', |
|
| 345 | - ); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Returns whether batch methods are "locked" or not, and if models an currently be used to query the database. |
|
| 351 | - * Return true when batch methods should not be used; returns false when they can be. |
|
| 352 | - * |
|
| 353 | - * @param string $type The type of lock being checked for. |
|
| 354 | - * @return bool |
|
| 355 | - */ |
|
| 356 | - public function is_locked($type = EE_Messages_Queue::action_generating) |
|
| 357 | - { |
|
| 358 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 359 | - return true; |
|
| 360 | - } |
|
| 361 | - $lock = (int) get_option($this->_get_lock_key($type), 0); |
|
| 362 | - /** |
|
| 363 | - * This filters the default is_locked behaviour. |
|
| 364 | - */ |
|
| 365 | - $is_locked = filter_var( |
|
| 366 | - apply_filters( |
|
| 367 | - 'FHEE__EE_Messages_Queue__is_locked', |
|
| 368 | - $lock > time(), |
|
| 369 | - $this |
|
| 370 | - ), |
|
| 371 | - FILTER_VALIDATE_BOOLEAN |
|
| 372 | - ); |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method. |
|
| 376 | - * Also implemented here because messages processed on the same request should not have any locks applied. |
|
| 377 | - */ |
|
| 378 | - if (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
| 379 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 380 | - ) { |
|
| 381 | - $is_locked = false; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - return $is_locked; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Retrieves the rate limit that may be cached as a transient. |
|
| 391 | - * If the rate limit is not set, then this sets the default rate limit and expiry and returns it. |
|
| 392 | - * |
|
| 393 | - * @param bool $return_expiry If true then return the expiry time not the rate_limit. |
|
| 394 | - * @return int |
|
| 395 | - */ |
|
| 396 | - protected function get_rate_limit($return_expiry = false) |
|
| 397 | - { |
|
| 398 | - $stored_rate_info = get_option($this->_get_rate_limit_key(), array()); |
|
| 399 | - $rate_limit = isset($stored_rate_info[0]) |
|
| 400 | - ? (int) $stored_rate_info[0] |
|
| 401 | - : 0; |
|
| 402 | - $expiry = isset($stored_rate_info[1]) |
|
| 403 | - ? (int) $stored_rate_info[1] |
|
| 404 | - : 0; |
|
| 405 | - // set the default for tracking? |
|
| 406 | - if (empty($stored_rate_info) || time() > $expiry) { |
|
| 407 | - $expiry = $this->_get_rate_limit_expiry(); |
|
| 408 | - $rate_limit = $this->_default_rate_limit(); |
|
| 409 | - update_option($this->_get_rate_limit_key(), array($rate_limit, $expiry)); |
|
| 410 | - } |
|
| 411 | - return $return_expiry ? $expiry : $rate_limit; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * This updates existing rate limit with the new limit which is the old minus the batch. |
|
| 417 | - * |
|
| 418 | - * @param int $batch_completed This sets the new rate limit based on the given batch that was completed. |
|
| 419 | - */ |
|
| 420 | - protected function set_rate_limit($batch_completed) |
|
| 421 | - { |
|
| 422 | - // first get the most up to date rate limit (in case its expired and reset) |
|
| 423 | - $rate_limit = $this->get_rate_limit(); |
|
| 424 | - $expiry = $this->get_rate_limit(true); |
|
| 425 | - $new_limit = $rate_limit - $batch_completed; |
|
| 426 | - // updating the transient option directly to avoid resetting the expiry. |
|
| 427 | - |
|
| 428 | - update_option($this->_get_rate_limit_key(), array($new_limit, $expiry)); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in. |
|
| 434 | - * If that exists, then we immediately initiate a non-blocking request to do the requested action type. |
|
| 435 | - * Note: Keep in mind that there is the possibility that the request will not execute if there is already another |
|
| 436 | - * request running on a queue for the given task. |
|
| 437 | - * |
|
| 438 | - * @param string $task This indicates what type of request is going to be initiated. |
|
| 439 | - * @param int $priority This indicates the priority that triggers initiating the request. |
|
| 440 | - */ |
|
| 441 | - public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high) |
|
| 442 | - { |
|
| 443 | - // determine what status is matched with the priority as part of the trigger conditions. |
|
| 444 | - $status = $task == 'generate' |
|
| 445 | - ? EEM_Message::status_incomplete |
|
| 446 | - : EEM_Message::instance()->stati_indicating_to_send(); |
|
| 447 | - // always make sure we save because either this will get executed immediately on a separate request |
|
| 448 | - // or remains in the queue for the regularly scheduled queue batch. |
|
| 449 | - $this->save(); |
|
| 450 | - /** |
|
| 451 | - * This filter/option allows users to override processing of messages on separate requests and instead have everything |
|
| 452 | - * happen on the same request. If this is utilized remember: |
|
| 453 | - * - message priorities don't matter |
|
| 454 | - * - existing unprocessed messages in the queue will not get processed unless manually triggered. |
|
| 455 | - * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional |
|
| 456 | - * processing happening on the same request. |
|
| 457 | - * - any race condition protection (locks) are removed because they don't apply when things are processed on |
|
| 458 | - * the same request. |
|
| 459 | - */ |
|
| 460 | - if (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
| 461 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 462 | - ) { |
|
| 463 | - $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 464 | - if ($messages_processor instanceof EE_Messages_Processor) { |
|
| 465 | - return $messages_processor->process_immediately_from_queue($this); |
|
| 466 | - } |
|
| 467 | - // if we get here then that means the messages processor couldn't be loaded so messages will just remain |
|
| 468 | - // queued for manual triggering by end user. |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - if ($this->_message_repository->count_by_priority_and_status($priority, $status)) { |
|
| 472 | - EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task); |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message. |
|
| 479 | - * |
|
| 480 | - * @param bool $save Used to indicate whether to save the message queue after sending |
|
| 481 | - * (default will save). |
|
| 482 | - * @param mixed $sending_messenger (optional) When the sending messenger is different than |
|
| 483 | - * what is on the EE_Message object in the queue. |
|
| 484 | - * For instance, showing the browser view of an email message, |
|
| 485 | - * or giving a pdf generated view of an html document. |
|
| 486 | - * This should be an instance of EE_messenger but if you call this |
|
| 487 | - * method |
|
| 488 | - * intending it to be a sending messenger but a valid one could not be |
|
| 489 | - * retrieved then send in an instance of EE_Error that contains the |
|
| 490 | - * related error message. |
|
| 491 | - * @param bool|int $by_priority When set, this indicates that only messages |
|
| 492 | - * matching the given priority should be executed. |
|
| 493 | - * @return int Number of messages sent. Note, 0 does not mean that no messages were processed. |
|
| 494 | - * Also, if the messenger is an request type messenger (or a preview), |
|
| 495 | - * its entirely possible that the messenger will exit before |
|
| 496 | - */ |
|
| 497 | - public function execute($save = true, $sending_messenger = null, $by_priority = false) |
|
| 498 | - { |
|
| 499 | - $messages_sent = 0; |
|
| 500 | - $this->_did_hook = array(); |
|
| 501 | - $this->_message_repository->rewind(); |
|
| 502 | - |
|
| 503 | - while ($this->_message_repository->valid()) { |
|
| 504 | - $error_messages = array(); |
|
| 505 | - /** @type EE_Message $message */ |
|
| 506 | - $message = $this->_message_repository->current(); |
|
| 507 | - // only process things that are queued for sending |
|
| 508 | - if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
| 509 | - $this->_message_repository->next(); |
|
| 510 | - continue; |
|
| 511 | - } |
|
| 512 | - // if $by_priority is set and does not match then continue; |
|
| 513 | - if ($by_priority && $by_priority != $message->priority()) { |
|
| 514 | - $this->_message_repository->next(); |
|
| 515 | - continue; |
|
| 516 | - } |
|
| 517 | - // error checking |
|
| 518 | - if (! $message->valid_messenger()) { |
|
| 519 | - $error_messages[] = sprintf( |
|
| 520 | - __('The %s messenger is not active at time of sending.', 'event_espresso'), |
|
| 521 | - $message->messenger() |
|
| 522 | - ); |
|
| 523 | - } |
|
| 524 | - if (! $message->valid_message_type()) { |
|
| 525 | - $error_messages[] = sprintf( |
|
| 526 | - __('The %s message type is not active at the time of sending.', 'event_espresso'), |
|
| 527 | - $message->message_type() |
|
| 528 | - ); |
|
| 529 | - } |
|
| 530 | - // if there was supposed to be a sending messenger for this message, but it was invalid/inactive, |
|
| 531 | - // then it will instead be an EE_Error object, so let's check for that |
|
| 532 | - if ($sending_messenger instanceof EE_Error) { |
|
| 533 | - $error_messages[] = $sending_messenger->getMessage(); |
|
| 534 | - } |
|
| 535 | - // if there are no errors, then let's process the message |
|
| 536 | - if (empty($error_messages)) { |
|
| 537 | - if ($save) { |
|
| 538 | - $message->set_messenger_is_executing(); |
|
| 539 | - } |
|
| 540 | - if ($this->_process_message($message, $sending_messenger)) { |
|
| 541 | - $messages_sent++; |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - $this->_set_error_message($message, $error_messages); |
|
| 545 | - // add modified time |
|
| 546 | - $message->set_modified(time()); |
|
| 547 | - // we save each message after its processed to make sure its status persists in case PHP times-out or runs |
|
| 548 | - // out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281 |
|
| 549 | - if ($save) { |
|
| 550 | - $message->save(); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - $this->_message_repository->next(); |
|
| 554 | - } |
|
| 555 | - if ($save) { |
|
| 556 | - $this->save(true); |
|
| 557 | - } |
|
| 558 | - return $messages_sent; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * _process_message |
|
| 564 | - * |
|
| 565 | - * @param EE_Message $message |
|
| 566 | - * @param mixed $sending_messenger (optional) |
|
| 567 | - * @return bool |
|
| 568 | - */ |
|
| 569 | - protected function _process_message(EE_Message $message, $sending_messenger = null) |
|
| 570 | - { |
|
| 571 | - // these *should* have been validated in the execute() method above |
|
| 572 | - $messenger = $message->messenger_object(); |
|
| 573 | - $message_type = $message->message_type_object(); |
|
| 574 | - // do actions for sending messenger if it differs from generating messenger and swap values. |
|
| 575 | - if ($sending_messenger instanceof EE_messenger |
|
| 576 | - && $messenger instanceof EE_messenger |
|
| 577 | - && $sending_messenger->name != $messenger->name |
|
| 578 | - ) { |
|
| 579 | - $messenger->do_secondary_messenger_hooks($sending_messenger->name); |
|
| 580 | - $messenger = $sending_messenger; |
|
| 581 | - } |
|
| 582 | - // send using messenger, but double check objects |
|
| 583 | - if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) { |
|
| 584 | - // set hook for message type (but only if not using another messenger to send). |
|
| 585 | - if (! isset($this->_did_hook[ $message_type->name ])) { |
|
| 586 | - $message_type->do_messenger_hooks($messenger); |
|
| 587 | - $this->_did_hook[ $message_type->name ] = 1; |
|
| 588 | - } |
|
| 589 | - // if preview then use preview method |
|
| 590 | - return $this->_message_repository->is_preview() |
|
| 591 | - ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send()) |
|
| 592 | - : $this->_do_send($message, $messenger, $message_type); |
|
| 593 | - } |
|
| 594 | - return false; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * The intention of this method is to count how many EE_Message objects |
|
| 600 | - * are in the queue with a given status. |
|
| 601 | - * Example usage: |
|
| 602 | - * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed |
|
| 603 | - * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ). |
|
| 604 | - * |
|
| 605 | - * @param array|string $status Stati to check for in queue |
|
| 606 | - * @return int Count of EE_Message's matching the given status. |
|
| 607 | - */ |
|
| 608 | - public function count_STS_in_queue($status) |
|
| 609 | - { |
|
| 610 | - $count = 0; |
|
| 611 | - $status = is_array($status) ? $status : array($status); |
|
| 612 | - $this->_message_repository->rewind(); |
|
| 613 | - foreach ($this->_message_repository as $message) { |
|
| 614 | - if (in_array($message->STS_ID(), $status)) { |
|
| 615 | - $count++; |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - return $count; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * Executes the get_preview method on the provided messenger. |
|
| 624 | - * |
|
| 625 | - * @param EE_Message $message |
|
| 626 | - * @param EE_messenger $messenger |
|
| 627 | - * @param EE_message_type $message_type |
|
| 628 | - * @param $test_send |
|
| 629 | - * @return bool true means all went well, false means, not so much. |
|
| 630 | - */ |
|
| 631 | - protected function _do_preview( |
|
| 632 | - EE_Message $message, |
|
| 633 | - EE_messenger $messenger, |
|
| 634 | - EE_message_type $message_type, |
|
| 635 | - $test_send |
|
| 636 | - ) { |
|
| 637 | - if ($preview = $messenger->get_preview($message, $message_type, $test_send)) { |
|
| 638 | - if (! $test_send) { |
|
| 639 | - $message->set_content($preview); |
|
| 640 | - } |
|
| 641 | - $message->set_STS_ID(EEM_Message::status_sent); |
|
| 642 | - return true; |
|
| 643 | - } else { |
|
| 644 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
| 645 | - return false; |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * Executes the send method on the provided messenger |
|
| 652 | - * EE_Messengers are expected to: |
|
| 653 | - * - return true if the send was successful. |
|
| 654 | - * - return false if the send was unsuccessful but can be tried again. |
|
| 655 | - * - throw an Exception if the send was unsuccessful and cannot be tried again. |
|
| 656 | - * |
|
| 657 | - * @param EE_Message $message |
|
| 658 | - * @param EE_messenger $messenger |
|
| 659 | - * @param EE_message_type $message_type |
|
| 660 | - * @return bool true means all went well, false means, not so much. |
|
| 661 | - */ |
|
| 662 | - protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type) |
|
| 663 | - { |
|
| 664 | - try { |
|
| 665 | - if ($messenger->send_message($message, $message_type)) { |
|
| 666 | - $message->set_STS_ID(EEM_Message::status_sent); |
|
| 667 | - return true; |
|
| 668 | - } else { |
|
| 669 | - $message->set_STS_ID(EEM_Message::status_retry); |
|
| 670 | - return false; |
|
| 671 | - } |
|
| 672 | - } catch (SendMessageException $e) { |
|
| 673 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
| 674 | - $message->set_error_message($e->getMessage()); |
|
| 675 | - return false; |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * This sets any necessary error messages on the message object and its status to failed. |
|
| 682 | - * |
|
| 683 | - * @param EE_Message $message |
|
| 684 | - * @param array $error_messages the response from the messenger. |
|
| 685 | - */ |
|
| 686 | - protected function _set_error_message(EE_Message $message, $error_messages) |
|
| 687 | - { |
|
| 688 | - $error_messages = (array) $error_messages; |
|
| 689 | - if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) { |
|
| 690 | - $notices = EE_Error::has_notices(); |
|
| 691 | - $error_messages[] = __( |
|
| 692 | - 'Messenger and Message Type were valid and active, but the messenger send method failed.', |
|
| 693 | - 'event_espresso' |
|
| 694 | - ); |
|
| 695 | - if ($notices === 1) { |
|
| 696 | - $notices = EE_Error::get_vanilla_notices(); |
|
| 697 | - $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array(); |
|
| 698 | - $error_messages[] = implode("\n", $notices['errors']); |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - if (count($error_messages) > 0) { |
|
| 702 | - $msg = __('Message was not executed successfully.', 'event_espresso'); |
|
| 703 | - $msg = $msg . "\n" . implode("\n", $error_messages); |
|
| 704 | - $message->set_error_message($msg); |
|
| 705 | - } |
|
| 706 | - } |
|
| 17 | + /** |
|
| 18 | + * @type string reference for sending action |
|
| 19 | + */ |
|
| 20 | + const action_sending = 'sending'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @type string reference for generation action |
|
| 24 | + */ |
|
| 25 | + const action_generating = 'generation'; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @type EE_Message_Repository $_message_repository |
|
| 30 | + */ |
|
| 31 | + protected $_message_repository; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Sets the limit of how many messages are generated per process. |
|
| 35 | + * |
|
| 36 | + * @type int |
|
| 37 | + */ |
|
| 38 | + protected $_batch_count; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * This is an array of cached queue items being stored in this object. |
|
| 43 | + * The array keys will be the ID of the EE_Message in the db if saved. If the EE_Message |
|
| 44 | + * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.) |
|
| 45 | + * |
|
| 46 | + * @type EE_Message[] |
|
| 47 | + */ |
|
| 48 | + protected $_cached_queue_items; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Tracks the number of unsaved queue items. |
|
| 52 | + * |
|
| 53 | + * @type int |
|
| 54 | + */ |
|
| 55 | + protected $_unsaved_count = 0; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * used to record if a do_messenger_hooks has already been called for a message type. This prevents multiple |
|
| 59 | + * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls. |
|
| 60 | + * |
|
| 61 | + * @type array |
|
| 62 | + */ |
|
| 63 | + protected $_did_hook = array(); |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Constructor. |
|
| 68 | + * Setup all the initial properties and load a EE_Message_Repository. |
|
| 69 | + * |
|
| 70 | + * @param \EE_Message_Repository $message_repository |
|
| 71 | + */ |
|
| 72 | + public function __construct(EE_Message_Repository $message_repository) |
|
| 73 | + { |
|
| 74 | + $this->_batch_count = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50); |
|
| 75 | + $this->_message_repository = $message_repository; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Add a EE_Message object to the queue |
|
| 81 | + * |
|
| 82 | + * @param EE_Message $message |
|
| 83 | + * @param array $data This will be an array of data to attach to the object in the repository. If the |
|
| 84 | + * object is persisted, this data will be saved on an extra_meta object related to |
|
| 85 | + * EE_Message. |
|
| 86 | + * @param bool $preview Whether this EE_Message represents a preview or not. |
|
| 87 | + * @param bool $test_send This indicates whether to do a test send instead of actual send. A test send will |
|
| 88 | + * use the messenger send method but typically is based on preview data. |
|
| 89 | + * @return bool Whether the message was successfully added to the repository or not. |
|
| 90 | + */ |
|
| 91 | + public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false) |
|
| 92 | + { |
|
| 93 | + $data['preview'] = $preview; |
|
| 94 | + $data['test_send'] = $test_send; |
|
| 95 | + return $this->_message_repository->add($message, $data); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message |
|
| 101 | + * |
|
| 102 | + * @param EE_Message $message The message to detach from the queue |
|
| 103 | + * @param bool $persist This flag indicates whether to attempt to delete the object from the db as well. |
|
| 104 | + * @return bool |
|
| 105 | + */ |
|
| 106 | + public function remove(EE_Message $message, $persist = false) |
|
| 107 | + { |
|
| 108 | + if ($persist && $this->_message_repository->current() !== $message) { |
|
| 109 | + // get pointer on right message |
|
| 110 | + if ($this->_message_repository->has($message)) { |
|
| 111 | + $this->_message_repository->rewind(); |
|
| 112 | + while ($this->_message_repository->valid()) { |
|
| 113 | + if ($this->_message_repository->current() === $message) { |
|
| 114 | + break; |
|
| 115 | + } |
|
| 116 | + $this->_message_repository->next(); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + return false; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Persists all queued EE_Message objects to the db. |
|
| 128 | + * |
|
| 129 | + * @param bool $do_hooks_only @see EE_Message_Repository::saveAll |
|
| 130 | + * @return array @see EE_Messages_Repository::saveAll() for return values. |
|
| 131 | + */ |
|
| 132 | + public function save($do_hooks_only = false) |
|
| 133 | + { |
|
| 134 | + return $this->_message_repository->saveAll($do_hooks_only); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return EE_Message_Repository |
|
| 140 | + */ |
|
| 141 | + public function get_message_repository() |
|
| 142 | + { |
|
| 143 | + return $this->_message_repository; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * This does the following things: |
|
| 149 | + * 1. Checks if there is a lock on generation (prevents race conditions). If there is a lock then exits (return |
|
| 150 | + * false). |
|
| 151 | + * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue |
|
| 152 | + * 3. Returns bool. True = batch ready. False = no batch ready (or nothing available for generation). |
|
| 153 | + * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from |
|
| 154 | + * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not |
|
| 155 | + * removed. |
|
| 156 | + * |
|
| 157 | + * @return bool true if successfully retrieved batch, false no batch ready. |
|
| 158 | + */ |
|
| 159 | + public function get_batch_to_generate() |
|
| 160 | + { |
|
| 161 | + if ($this->is_locked(EE_Messages_Queue::action_generating)) { |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // lock batch generation to prevent race conditions. |
|
| 166 | + $this->lock_queue(EE_Messages_Queue::action_generating); |
|
| 167 | + |
|
| 168 | + $query_args = array( |
|
| 169 | + // key 0 = where conditions |
|
| 170 | + 0 => array('STS_ID' => EEM_Message::status_incomplete), |
|
| 171 | + 'order_by' => $this->_get_priority_orderby(), |
|
| 172 | + 'limit' => $this->_batch_count, |
|
| 173 | + ); |
|
| 174 | + $messages = EEM_Message::instance()->get_all($query_args); |
|
| 175 | + |
|
| 176 | + if (! $messages) { |
|
| 177 | + return false; // nothing to generate |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + foreach ($messages as $message) { |
|
| 181 | + if ($message instanceof EE_Message) { |
|
| 182 | + $data = $message->all_extra_meta_array(); |
|
| 183 | + $this->add($message, $data); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + return true; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * This does the following things: |
|
| 192 | + * 1. Checks if there is a lock on sending (prevents race conditions). If there is a lock then exits (return |
|
| 193 | + * false). |
|
| 194 | + * 2. Grabs the allowed number of messages to send for the rate_limit. If cannot send any more messages, then |
|
| 195 | + * return false. |
|
| 196 | + * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution. |
|
| 197 | + * 3. On success or unsuccessful send, sets status appropriately. |
|
| 198 | + * 4. Saves messages via the queue |
|
| 199 | + * 5. Releases lock. |
|
| 200 | + * |
|
| 201 | + * @return bool true on success, false if something preventing sending (i.e. lock set). Note: true does not |
|
| 202 | + * necessarily mean that all messages were successfully sent. It just means that this method |
|
| 203 | + * successfully completed. On true, client may want to call $this->count_STS_in_queue( |
|
| 204 | + * EEM_Message::status_failed ) to see if any failed EE_Message objects. Each failed message object |
|
| 205 | + * will also have a saved error message on it to assist with notifying user. |
|
| 206 | + */ |
|
| 207 | + public function get_to_send_batch_and_send() |
|
| 208 | + { |
|
| 209 | + $rate_limit = $this->get_rate_limit(); |
|
| 210 | + if ($rate_limit < 1 |
|
| 211 | + || $this->is_locked(EE_Messages_Queue::action_sending)) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $this->lock_queue(EE_Messages_Queue::action_sending); |
|
| 216 | + |
|
| 217 | + $batch = $this->_batch_count < $rate_limit ? $this->_batch_count : $rate_limit; |
|
| 218 | + |
|
| 219 | + $query_args = array( |
|
| 220 | + // key 0 = where conditions |
|
| 221 | + 0 => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())), |
|
| 222 | + 'order_by' => $this->_get_priority_orderby(), |
|
| 223 | + 'limit' => $batch, |
|
| 224 | + ); |
|
| 225 | + |
|
| 226 | + $messages_to_send = EEM_Message::instance()->get_all($query_args); |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + // any to send? |
|
| 230 | + if (! $messages_to_send) { |
|
| 231 | + $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
| 232 | + return false; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $queue_count = 0; |
|
| 236 | + |
|
| 237 | + // add to queue. |
|
| 238 | + foreach ($messages_to_send as $message) { |
|
| 239 | + if ($message instanceof EE_Message) { |
|
| 240 | + $queue_count++; |
|
| 241 | + $this->add($message); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + // send messages (this also updates the rate limit) |
|
| 246 | + $this->execute(); |
|
| 247 | + |
|
| 248 | + // release lock |
|
| 249 | + $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
| 250 | + // update rate limit |
|
| 251 | + $this->set_rate_limit($queue_count); |
|
| 252 | + return true; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Locks the queue so that no other queues can call the "batch" methods. |
|
| 258 | + * |
|
| 259 | + * @param string $type The type of queue being locked. |
|
| 260 | + */ |
|
| 261 | + public function lock_queue($type = EE_Messages_Queue::action_generating) |
|
| 262 | + { |
|
| 263 | + update_option($this->_get_lock_key($type), $this->_get_lock_expiry($type)); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Unlocks the queue so that batch methods can be used. |
|
| 269 | + * |
|
| 270 | + * @param string $type The type of queue being unlocked. |
|
| 271 | + */ |
|
| 272 | + public function unlock_queue($type = EE_Messages_Queue::action_generating) |
|
| 273 | + { |
|
| 274 | + delete_option($this->_get_lock_key($type)); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Retrieve the key used for the lock transient. |
|
| 280 | + * |
|
| 281 | + * @param string $type The type of lock. |
|
| 282 | + * @return string |
|
| 283 | + */ |
|
| 284 | + protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
|
| 285 | + { |
|
| 286 | + return '_ee_lock_' . $type; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Retrieve the expiry time for the lock transient. |
|
| 292 | + * |
|
| 293 | + * @param string $type The type of lock |
|
| 294 | + * @return int time to expiry in seconds. |
|
| 295 | + */ |
|
| 296 | + protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating) |
|
| 297 | + { |
|
| 298 | + return time() + (int) apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Returns the key used for rate limit transient. |
|
| 304 | + * |
|
| 305 | + * @return string |
|
| 306 | + */ |
|
| 307 | + protected function _get_rate_limit_key() |
|
| 308 | + { |
|
| 309 | + return '_ee_rate_limit'; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Returns the rate limit expiry time. |
|
| 315 | + * |
|
| 316 | + * @return int |
|
| 317 | + */ |
|
| 318 | + protected function _get_rate_limit_expiry() |
|
| 319 | + { |
|
| 320 | + return time() + (int) apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Returns the default rate limit for sending messages. |
|
| 326 | + * |
|
| 327 | + * @return int |
|
| 328 | + */ |
|
| 329 | + protected function _default_rate_limit() |
|
| 330 | + { |
|
| 331 | + return (int) apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Return the orderby array for priority. |
|
| 337 | + * |
|
| 338 | + * @return array |
|
| 339 | + */ |
|
| 340 | + protected function _get_priority_orderby() |
|
| 341 | + { |
|
| 342 | + return array( |
|
| 343 | + 'MSG_priority' => 'ASC', |
|
| 344 | + 'MSG_modified' => 'DESC', |
|
| 345 | + ); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Returns whether batch methods are "locked" or not, and if models an currently be used to query the database. |
|
| 351 | + * Return true when batch methods should not be used; returns false when they can be. |
|
| 352 | + * |
|
| 353 | + * @param string $type The type of lock being checked for. |
|
| 354 | + * @return bool |
|
| 355 | + */ |
|
| 356 | + public function is_locked($type = EE_Messages_Queue::action_generating) |
|
| 357 | + { |
|
| 358 | + if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 359 | + return true; |
|
| 360 | + } |
|
| 361 | + $lock = (int) get_option($this->_get_lock_key($type), 0); |
|
| 362 | + /** |
|
| 363 | + * This filters the default is_locked behaviour. |
|
| 364 | + */ |
|
| 365 | + $is_locked = filter_var( |
|
| 366 | + apply_filters( |
|
| 367 | + 'FHEE__EE_Messages_Queue__is_locked', |
|
| 368 | + $lock > time(), |
|
| 369 | + $this |
|
| 370 | + ), |
|
| 371 | + FILTER_VALIDATE_BOOLEAN |
|
| 372 | + ); |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method. |
|
| 376 | + * Also implemented here because messages processed on the same request should not have any locks applied. |
|
| 377 | + */ |
|
| 378 | + if (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
| 379 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 380 | + ) { |
|
| 381 | + $is_locked = false; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + return $is_locked; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Retrieves the rate limit that may be cached as a transient. |
|
| 391 | + * If the rate limit is not set, then this sets the default rate limit and expiry and returns it. |
|
| 392 | + * |
|
| 393 | + * @param bool $return_expiry If true then return the expiry time not the rate_limit. |
|
| 394 | + * @return int |
|
| 395 | + */ |
|
| 396 | + protected function get_rate_limit($return_expiry = false) |
|
| 397 | + { |
|
| 398 | + $stored_rate_info = get_option($this->_get_rate_limit_key(), array()); |
|
| 399 | + $rate_limit = isset($stored_rate_info[0]) |
|
| 400 | + ? (int) $stored_rate_info[0] |
|
| 401 | + : 0; |
|
| 402 | + $expiry = isset($stored_rate_info[1]) |
|
| 403 | + ? (int) $stored_rate_info[1] |
|
| 404 | + : 0; |
|
| 405 | + // set the default for tracking? |
|
| 406 | + if (empty($stored_rate_info) || time() > $expiry) { |
|
| 407 | + $expiry = $this->_get_rate_limit_expiry(); |
|
| 408 | + $rate_limit = $this->_default_rate_limit(); |
|
| 409 | + update_option($this->_get_rate_limit_key(), array($rate_limit, $expiry)); |
|
| 410 | + } |
|
| 411 | + return $return_expiry ? $expiry : $rate_limit; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * This updates existing rate limit with the new limit which is the old minus the batch. |
|
| 417 | + * |
|
| 418 | + * @param int $batch_completed This sets the new rate limit based on the given batch that was completed. |
|
| 419 | + */ |
|
| 420 | + protected function set_rate_limit($batch_completed) |
|
| 421 | + { |
|
| 422 | + // first get the most up to date rate limit (in case its expired and reset) |
|
| 423 | + $rate_limit = $this->get_rate_limit(); |
|
| 424 | + $expiry = $this->get_rate_limit(true); |
|
| 425 | + $new_limit = $rate_limit - $batch_completed; |
|
| 426 | + // updating the transient option directly to avoid resetting the expiry. |
|
| 427 | + |
|
| 428 | + update_option($this->_get_rate_limit_key(), array($new_limit, $expiry)); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in. |
|
| 434 | + * If that exists, then we immediately initiate a non-blocking request to do the requested action type. |
|
| 435 | + * Note: Keep in mind that there is the possibility that the request will not execute if there is already another |
|
| 436 | + * request running on a queue for the given task. |
|
| 437 | + * |
|
| 438 | + * @param string $task This indicates what type of request is going to be initiated. |
|
| 439 | + * @param int $priority This indicates the priority that triggers initiating the request. |
|
| 440 | + */ |
|
| 441 | + public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high) |
|
| 442 | + { |
|
| 443 | + // determine what status is matched with the priority as part of the trigger conditions. |
|
| 444 | + $status = $task == 'generate' |
|
| 445 | + ? EEM_Message::status_incomplete |
|
| 446 | + : EEM_Message::instance()->stati_indicating_to_send(); |
|
| 447 | + // always make sure we save because either this will get executed immediately on a separate request |
|
| 448 | + // or remains in the queue for the regularly scheduled queue batch. |
|
| 449 | + $this->save(); |
|
| 450 | + /** |
|
| 451 | + * This filter/option allows users to override processing of messages on separate requests and instead have everything |
|
| 452 | + * happen on the same request. If this is utilized remember: |
|
| 453 | + * - message priorities don't matter |
|
| 454 | + * - existing unprocessed messages in the queue will not get processed unless manually triggered. |
|
| 455 | + * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional |
|
| 456 | + * processing happening on the same request. |
|
| 457 | + * - any race condition protection (locks) are removed because they don't apply when things are processed on |
|
| 458 | + * the same request. |
|
| 459 | + */ |
|
| 460 | + if (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
| 461 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 462 | + ) { |
|
| 463 | + $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 464 | + if ($messages_processor instanceof EE_Messages_Processor) { |
|
| 465 | + return $messages_processor->process_immediately_from_queue($this); |
|
| 466 | + } |
|
| 467 | + // if we get here then that means the messages processor couldn't be loaded so messages will just remain |
|
| 468 | + // queued for manual triggering by end user. |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + if ($this->_message_repository->count_by_priority_and_status($priority, $status)) { |
|
| 472 | + EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task); |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message. |
|
| 479 | + * |
|
| 480 | + * @param bool $save Used to indicate whether to save the message queue after sending |
|
| 481 | + * (default will save). |
|
| 482 | + * @param mixed $sending_messenger (optional) When the sending messenger is different than |
|
| 483 | + * what is on the EE_Message object in the queue. |
|
| 484 | + * For instance, showing the browser view of an email message, |
|
| 485 | + * or giving a pdf generated view of an html document. |
|
| 486 | + * This should be an instance of EE_messenger but if you call this |
|
| 487 | + * method |
|
| 488 | + * intending it to be a sending messenger but a valid one could not be |
|
| 489 | + * retrieved then send in an instance of EE_Error that contains the |
|
| 490 | + * related error message. |
|
| 491 | + * @param bool|int $by_priority When set, this indicates that only messages |
|
| 492 | + * matching the given priority should be executed. |
|
| 493 | + * @return int Number of messages sent. Note, 0 does not mean that no messages were processed. |
|
| 494 | + * Also, if the messenger is an request type messenger (or a preview), |
|
| 495 | + * its entirely possible that the messenger will exit before |
|
| 496 | + */ |
|
| 497 | + public function execute($save = true, $sending_messenger = null, $by_priority = false) |
|
| 498 | + { |
|
| 499 | + $messages_sent = 0; |
|
| 500 | + $this->_did_hook = array(); |
|
| 501 | + $this->_message_repository->rewind(); |
|
| 502 | + |
|
| 503 | + while ($this->_message_repository->valid()) { |
|
| 504 | + $error_messages = array(); |
|
| 505 | + /** @type EE_Message $message */ |
|
| 506 | + $message = $this->_message_repository->current(); |
|
| 507 | + // only process things that are queued for sending |
|
| 508 | + if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
| 509 | + $this->_message_repository->next(); |
|
| 510 | + continue; |
|
| 511 | + } |
|
| 512 | + // if $by_priority is set and does not match then continue; |
|
| 513 | + if ($by_priority && $by_priority != $message->priority()) { |
|
| 514 | + $this->_message_repository->next(); |
|
| 515 | + continue; |
|
| 516 | + } |
|
| 517 | + // error checking |
|
| 518 | + if (! $message->valid_messenger()) { |
|
| 519 | + $error_messages[] = sprintf( |
|
| 520 | + __('The %s messenger is not active at time of sending.', 'event_espresso'), |
|
| 521 | + $message->messenger() |
|
| 522 | + ); |
|
| 523 | + } |
|
| 524 | + if (! $message->valid_message_type()) { |
|
| 525 | + $error_messages[] = sprintf( |
|
| 526 | + __('The %s message type is not active at the time of sending.', 'event_espresso'), |
|
| 527 | + $message->message_type() |
|
| 528 | + ); |
|
| 529 | + } |
|
| 530 | + // if there was supposed to be a sending messenger for this message, but it was invalid/inactive, |
|
| 531 | + // then it will instead be an EE_Error object, so let's check for that |
|
| 532 | + if ($sending_messenger instanceof EE_Error) { |
|
| 533 | + $error_messages[] = $sending_messenger->getMessage(); |
|
| 534 | + } |
|
| 535 | + // if there are no errors, then let's process the message |
|
| 536 | + if (empty($error_messages)) { |
|
| 537 | + if ($save) { |
|
| 538 | + $message->set_messenger_is_executing(); |
|
| 539 | + } |
|
| 540 | + if ($this->_process_message($message, $sending_messenger)) { |
|
| 541 | + $messages_sent++; |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + $this->_set_error_message($message, $error_messages); |
|
| 545 | + // add modified time |
|
| 546 | + $message->set_modified(time()); |
|
| 547 | + // we save each message after its processed to make sure its status persists in case PHP times-out or runs |
|
| 548 | + // out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281 |
|
| 549 | + if ($save) { |
|
| 550 | + $message->save(); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + $this->_message_repository->next(); |
|
| 554 | + } |
|
| 555 | + if ($save) { |
|
| 556 | + $this->save(true); |
|
| 557 | + } |
|
| 558 | + return $messages_sent; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * _process_message |
|
| 564 | + * |
|
| 565 | + * @param EE_Message $message |
|
| 566 | + * @param mixed $sending_messenger (optional) |
|
| 567 | + * @return bool |
|
| 568 | + */ |
|
| 569 | + protected function _process_message(EE_Message $message, $sending_messenger = null) |
|
| 570 | + { |
|
| 571 | + // these *should* have been validated in the execute() method above |
|
| 572 | + $messenger = $message->messenger_object(); |
|
| 573 | + $message_type = $message->message_type_object(); |
|
| 574 | + // do actions for sending messenger if it differs from generating messenger and swap values. |
|
| 575 | + if ($sending_messenger instanceof EE_messenger |
|
| 576 | + && $messenger instanceof EE_messenger |
|
| 577 | + && $sending_messenger->name != $messenger->name |
|
| 578 | + ) { |
|
| 579 | + $messenger->do_secondary_messenger_hooks($sending_messenger->name); |
|
| 580 | + $messenger = $sending_messenger; |
|
| 581 | + } |
|
| 582 | + // send using messenger, but double check objects |
|
| 583 | + if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) { |
|
| 584 | + // set hook for message type (but only if not using another messenger to send). |
|
| 585 | + if (! isset($this->_did_hook[ $message_type->name ])) { |
|
| 586 | + $message_type->do_messenger_hooks($messenger); |
|
| 587 | + $this->_did_hook[ $message_type->name ] = 1; |
|
| 588 | + } |
|
| 589 | + // if preview then use preview method |
|
| 590 | + return $this->_message_repository->is_preview() |
|
| 591 | + ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send()) |
|
| 592 | + : $this->_do_send($message, $messenger, $message_type); |
|
| 593 | + } |
|
| 594 | + return false; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * The intention of this method is to count how many EE_Message objects |
|
| 600 | + * are in the queue with a given status. |
|
| 601 | + * Example usage: |
|
| 602 | + * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed |
|
| 603 | + * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ). |
|
| 604 | + * |
|
| 605 | + * @param array|string $status Stati to check for in queue |
|
| 606 | + * @return int Count of EE_Message's matching the given status. |
|
| 607 | + */ |
|
| 608 | + public function count_STS_in_queue($status) |
|
| 609 | + { |
|
| 610 | + $count = 0; |
|
| 611 | + $status = is_array($status) ? $status : array($status); |
|
| 612 | + $this->_message_repository->rewind(); |
|
| 613 | + foreach ($this->_message_repository as $message) { |
|
| 614 | + if (in_array($message->STS_ID(), $status)) { |
|
| 615 | + $count++; |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + return $count; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * Executes the get_preview method on the provided messenger. |
|
| 624 | + * |
|
| 625 | + * @param EE_Message $message |
|
| 626 | + * @param EE_messenger $messenger |
|
| 627 | + * @param EE_message_type $message_type |
|
| 628 | + * @param $test_send |
|
| 629 | + * @return bool true means all went well, false means, not so much. |
|
| 630 | + */ |
|
| 631 | + protected function _do_preview( |
|
| 632 | + EE_Message $message, |
|
| 633 | + EE_messenger $messenger, |
|
| 634 | + EE_message_type $message_type, |
|
| 635 | + $test_send |
|
| 636 | + ) { |
|
| 637 | + if ($preview = $messenger->get_preview($message, $message_type, $test_send)) { |
|
| 638 | + if (! $test_send) { |
|
| 639 | + $message->set_content($preview); |
|
| 640 | + } |
|
| 641 | + $message->set_STS_ID(EEM_Message::status_sent); |
|
| 642 | + return true; |
|
| 643 | + } else { |
|
| 644 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
| 645 | + return false; |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * Executes the send method on the provided messenger |
|
| 652 | + * EE_Messengers are expected to: |
|
| 653 | + * - return true if the send was successful. |
|
| 654 | + * - return false if the send was unsuccessful but can be tried again. |
|
| 655 | + * - throw an Exception if the send was unsuccessful and cannot be tried again. |
|
| 656 | + * |
|
| 657 | + * @param EE_Message $message |
|
| 658 | + * @param EE_messenger $messenger |
|
| 659 | + * @param EE_message_type $message_type |
|
| 660 | + * @return bool true means all went well, false means, not so much. |
|
| 661 | + */ |
|
| 662 | + protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type) |
|
| 663 | + { |
|
| 664 | + try { |
|
| 665 | + if ($messenger->send_message($message, $message_type)) { |
|
| 666 | + $message->set_STS_ID(EEM_Message::status_sent); |
|
| 667 | + return true; |
|
| 668 | + } else { |
|
| 669 | + $message->set_STS_ID(EEM_Message::status_retry); |
|
| 670 | + return false; |
|
| 671 | + } |
|
| 672 | + } catch (SendMessageException $e) { |
|
| 673 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
| 674 | + $message->set_error_message($e->getMessage()); |
|
| 675 | + return false; |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * This sets any necessary error messages on the message object and its status to failed. |
|
| 682 | + * |
|
| 683 | + * @param EE_Message $message |
|
| 684 | + * @param array $error_messages the response from the messenger. |
|
| 685 | + */ |
|
| 686 | + protected function _set_error_message(EE_Message $message, $error_messages) |
|
| 687 | + { |
|
| 688 | + $error_messages = (array) $error_messages; |
|
| 689 | + if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) { |
|
| 690 | + $notices = EE_Error::has_notices(); |
|
| 691 | + $error_messages[] = __( |
|
| 692 | + 'Messenger and Message Type were valid and active, but the messenger send method failed.', |
|
| 693 | + 'event_espresso' |
|
| 694 | + ); |
|
| 695 | + if ($notices === 1) { |
|
| 696 | + $notices = EE_Error::get_vanilla_notices(); |
|
| 697 | + $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array(); |
|
| 698 | + $error_messages[] = implode("\n", $notices['errors']); |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + if (count($error_messages) > 0) { |
|
| 702 | + $msg = __('Message was not executed successfully.', 'event_espresso'); |
|
| 703 | + $msg = $msg . "\n" . implode("\n", $error_messages); |
|
| 704 | + $message->set_error_message($msg); |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | 707 | } |
@@ -171,9 +171,9 @@ discard block |
||
| 171 | 171 | 'order_by' => $this->_get_priority_orderby(), |
| 172 | 172 | 'limit' => $this->_batch_count, |
| 173 | 173 | ); |
| 174 | - $messages = EEM_Message::instance()->get_all($query_args); |
|
| 174 | + $messages = EEM_Message::instance()->get_all($query_args); |
|
| 175 | 175 | |
| 176 | - if (! $messages) { |
|
| 176 | + if ( ! $messages) { |
|
| 177 | 177 | return false; // nothing to generate |
| 178 | 178 | } |
| 179 | 179 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | |
| 228 | 228 | |
| 229 | 229 | // any to send? |
| 230 | - if (! $messages_to_send) { |
|
| 230 | + if ( ! $messages_to_send) { |
|
| 231 | 231 | $this->unlock_queue(EE_Messages_Queue::action_sending); |
| 232 | 232 | return false; |
| 233 | 233 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
| 285 | 285 | { |
| 286 | - return '_ee_lock_' . $type; |
|
| 286 | + return '_ee_lock_'.$type; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | */ |
| 356 | 356 | public function is_locked($type = EE_Messages_Queue::action_generating) |
| 357 | 357 | { |
| 358 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 358 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 359 | 359 | return true; |
| 360 | 360 | } |
| 361 | 361 | $lock = (int) get_option($this->_get_lock_key($type), 0); |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | /** @type EE_Message $message */ |
| 506 | 506 | $message = $this->_message_repository->current(); |
| 507 | 507 | // only process things that are queued for sending |
| 508 | - if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
| 508 | + if ( ! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
| 509 | 509 | $this->_message_repository->next(); |
| 510 | 510 | continue; |
| 511 | 511 | } |
@@ -515,13 +515,13 @@ discard block |
||
| 515 | 515 | continue; |
| 516 | 516 | } |
| 517 | 517 | // error checking |
| 518 | - if (! $message->valid_messenger()) { |
|
| 518 | + if ( ! $message->valid_messenger()) { |
|
| 519 | 519 | $error_messages[] = sprintf( |
| 520 | 520 | __('The %s messenger is not active at time of sending.', 'event_espresso'), |
| 521 | 521 | $message->messenger() |
| 522 | 522 | ); |
| 523 | 523 | } |
| 524 | - if (! $message->valid_message_type()) { |
|
| 524 | + if ( ! $message->valid_message_type()) { |
|
| 525 | 525 | $error_messages[] = sprintf( |
| 526 | 526 | __('The %s message type is not active at the time of sending.', 'event_espresso'), |
| 527 | 527 | $message->message_type() |
@@ -582,9 +582,9 @@ discard block |
||
| 582 | 582 | // send using messenger, but double check objects |
| 583 | 583 | if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) { |
| 584 | 584 | // set hook for message type (but only if not using another messenger to send). |
| 585 | - if (! isset($this->_did_hook[ $message_type->name ])) { |
|
| 585 | + if ( ! isset($this->_did_hook[$message_type->name])) { |
|
| 586 | 586 | $message_type->do_messenger_hooks($messenger); |
| 587 | - $this->_did_hook[ $message_type->name ] = 1; |
|
| 587 | + $this->_did_hook[$message_type->name] = 1; |
|
| 588 | 588 | } |
| 589 | 589 | // if preview then use preview method |
| 590 | 590 | return $this->_message_repository->is_preview() |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | $test_send |
| 636 | 636 | ) { |
| 637 | 637 | if ($preview = $messenger->get_preview($message, $message_type, $test_send)) { |
| 638 | - if (! $test_send) { |
|
| 638 | + if ( ! $test_send) { |
|
| 639 | 639 | $message->set_content($preview); |
| 640 | 640 | } |
| 641 | 641 | $message->set_STS_ID(EEM_Message::status_sent); |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | } |
| 701 | 701 | if (count($error_messages) > 0) { |
| 702 | 702 | $msg = __('Message was not executed successfully.', 'event_espresso'); |
| 703 | - $msg = $msg . "\n" . implode("\n", $error_messages); |
|
| 703 | + $msg = $msg."\n".implode("\n", $error_messages); |
|
| 704 | 704 | $message->set_error_message($msg); |
| 705 | 705 | } |
| 706 | 706 | } |
@@ -11,674 +11,674 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
| 13 | 13 | if (! function_exists('mb_strcut')) { |
| 14 | - /** |
|
| 15 | - * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
| 16 | - * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
| 17 | - * @param $string |
|
| 18 | - * @param $start |
|
| 19 | - * @param $length |
|
| 20 | - * @return bool|string |
|
| 21 | - */ |
|
| 22 | - function mb_strcut($string, $start, $length = null) |
|
| 23 | - { |
|
| 24 | - return mb_substr($string, $start, $length); |
|
| 25 | - } |
|
| 14 | + /** |
|
| 15 | + * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
| 16 | + * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
| 17 | + * @param $string |
|
| 18 | + * @param $start |
|
| 19 | + * @param $length |
|
| 20 | + * @return bool|string |
|
| 21 | + */ |
|
| 22 | + function mb_strcut($string, $start, $length = null) |
|
| 23 | + { |
|
| 24 | + return mb_substr($string, $start, $length); |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Merchant API Username. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $_api_username; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Merchant API Password. |
|
| 39 | - * |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - protected $_api_password; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * API Signature. |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - protected $_api_signature; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Request Shipping address on PP checkout page. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - protected $_request_shipping_addr; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Business/personal logo. |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - protected $_image_url; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * gateway URL variable |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - protected $_base_gateway_url = ''; |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * EEG_Paypal_Express constructor. |
|
| 76 | - */ |
|
| 77 | - public function __construct() |
|
| 78 | - { |
|
| 79 | - $this->_currencies_supported = array( |
|
| 80 | - 'USD', |
|
| 81 | - 'AUD', |
|
| 82 | - 'BRL', |
|
| 83 | - 'CAD', |
|
| 84 | - 'CZK', |
|
| 85 | - 'DKK', |
|
| 86 | - 'EUR', |
|
| 87 | - 'HKD', |
|
| 88 | - 'HUF', |
|
| 89 | - 'ILS', |
|
| 90 | - 'JPY', |
|
| 91 | - 'MYR', |
|
| 92 | - 'MXN', |
|
| 93 | - 'NOK', |
|
| 94 | - 'NZD', |
|
| 95 | - 'PHP', |
|
| 96 | - 'PLN', |
|
| 97 | - 'GBP', |
|
| 98 | - 'RUB', |
|
| 99 | - 'SGD', |
|
| 100 | - 'SEK', |
|
| 101 | - 'CHF', |
|
| 102 | - 'TWD', |
|
| 103 | - 'THB', |
|
| 104 | - 'TRY', |
|
| 105 | - 'INR', |
|
| 106 | - ); |
|
| 107 | - parent::__construct(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
| 114 | - * |
|
| 115 | - * @param array $settings_array |
|
| 116 | - */ |
|
| 117 | - public function set_settings($settings_array) |
|
| 118 | - { |
|
| 119 | - parent::set_settings($settings_array); |
|
| 120 | - // Redirect URL. |
|
| 121 | - $this->_base_gateway_url = $this->_debug_mode |
|
| 122 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
| 123 | - : 'https://api-3t.paypal.com/nvp'; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @param EEI_Payment $payment |
|
| 130 | - * @param array $billing_info |
|
| 131 | - * @param string $return_url |
|
| 132 | - * @param string $notify_url |
|
| 133 | - * @param string $cancel_url |
|
| 134 | - * @return \EE_Payment|\EEI_Payment |
|
| 135 | - * @throws \EE_Error |
|
| 136 | - */ |
|
| 137 | - public function set_redirection_info( |
|
| 138 | - $payment, |
|
| 139 | - $billing_info = array(), |
|
| 140 | - $return_url = null, |
|
| 141 | - $notify_url = null, |
|
| 142 | - $cancel_url = null |
|
| 143 | - ) { |
|
| 144 | - if (! $payment instanceof EEI_Payment) { |
|
| 145 | - $payment->set_gateway_response( |
|
| 146 | - esc_html__( |
|
| 147 | - 'Error. No associated payment was found.', |
|
| 148 | - 'event_espresso' |
|
| 149 | - ) |
|
| 150 | - ); |
|
| 151 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 152 | - return $payment; |
|
| 153 | - } |
|
| 154 | - $transaction = $payment->transaction(); |
|
| 155 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 156 | - $payment->set_gateway_response( |
|
| 157 | - esc_html__( |
|
| 158 | - 'Could not process this payment because it has no associated transaction.', |
|
| 159 | - 'event_espresso' |
|
| 160 | - ) |
|
| 161 | - ); |
|
| 162 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 163 | - return $payment; |
|
| 164 | - } |
|
| 165 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 166 | - $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
| 167 | - $primary_registration = $transaction->primary_registration(); |
|
| 168 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
| 169 | - ? $primary_registration->attendee() |
|
| 170 | - : false; |
|
| 171 | - $locale = explode('-', get_bloginfo('language')); |
|
| 172 | - // Gather request parameters. |
|
| 173 | - $token_request_dtls = array( |
|
| 174 | - 'METHOD' => 'SetExpressCheckout', |
|
| 175 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 176 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 177 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
| 178 | - 'RETURNURL' => $return_url, |
|
| 179 | - 'CANCELURL' => $cancel_url, |
|
| 180 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 181 | - // Buyer does not need to create a PayPal account to check out. |
|
| 182 | - // This is referred to as PayPal Account Optional. |
|
| 183 | - 'SOLUTIONTYPE' => 'Sole', |
|
| 184 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 185 | - 'LOCALECODE' => $locale[1] |
|
| 186 | - ); |
|
| 187 | - // Show itemized list. |
|
| 188 | - $itemized_list = $this->itemize_list($payment, $transaction); |
|
| 189 | - $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
| 190 | - // Automatically filling out shipping and contact information. |
|
| 191 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
| 192 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 193 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
| 194 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 195 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 196 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 197 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 198 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 199 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 200 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 201 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 202 | - } elseif (! $this->_request_shipping_addr) { |
|
| 203 | - // Do not request shipping details on the PP Checkout page. |
|
| 204 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
| 205 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
| 206 | - } |
|
| 207 | - // Used a business/personal logo on the PayPal page. |
|
| 208 | - if (! empty($this->_image_url)) { |
|
| 209 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
| 210 | - } |
|
| 211 | - $token_request_dtls = apply_filters( |
|
| 212 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
| 213 | - $token_request_dtls, |
|
| 214 | - $this |
|
| 215 | - ); |
|
| 216 | - // Request PayPal token. |
|
| 217 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
| 218 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
| 219 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
| 220 | - ? $token_rstatus['args'] |
|
| 221 | - : array(); |
|
| 222 | - if ($token_rstatus['status']) { |
|
| 223 | - // We got the Token so we may continue with the payment and redirect the client. |
|
| 224 | - $payment->set_details($response_args); |
|
| 225 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 226 | - $payment->set_redirect_url( |
|
| 227 | - $gateway_url |
|
| 228 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
| 229 | - . $response_args['TOKEN'] |
|
| 230 | - ); |
|
| 231 | - } else { |
|
| 232 | - if (isset($response_args['L_ERRORCODE'])) { |
|
| 233 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 234 | - } else { |
|
| 235 | - $payment->set_gateway_response( |
|
| 236 | - esc_html__( |
|
| 237 | - 'Error occurred while trying to setup the Express Checkout.', |
|
| 238 | - 'event_espresso' |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - $payment->set_details($response_args); |
|
| 243 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 244 | - } |
|
| 245 | - return $payment; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param array $update_info { |
|
| 252 | - * @type string $gateway_txn_id |
|
| 253 | - * @type string status an EEMI_Payment status |
|
| 254 | - * } |
|
| 255 | - * @param EEI_Transaction $transaction |
|
| 256 | - * @return EEI_Payment |
|
| 257 | - */ |
|
| 258 | - public function handle_payment_update($update_info, $transaction) |
|
| 259 | - { |
|
| 260 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
| 261 | - if ($payment instanceof EEI_Payment) { |
|
| 262 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
| 263 | - $transaction = $payment->transaction(); |
|
| 264 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 265 | - $payment->set_gateway_response( |
|
| 266 | - esc_html__( |
|
| 267 | - 'Could not process this payment because it has no associated transaction.', |
|
| 268 | - 'event_espresso' |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 272 | - return $payment; |
|
| 273 | - } |
|
| 274 | - $primary_registrant = $transaction->primary_registration(); |
|
| 275 | - $payment_details = $payment->details(); |
|
| 276 | - // Check if we still have the token. |
|
| 277 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 278 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 279 | - return $payment; |
|
| 280 | - } |
|
| 281 | - $cdetails_request_dtls = array( |
|
| 282 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
| 283 | - 'TOKEN' => $payment_details['TOKEN'], |
|
| 284 | - ); |
|
| 285 | - // Request Customer Details. |
|
| 286 | - $cdetails_request_response = $this->_ppExpress_request( |
|
| 287 | - $cdetails_request_dtls, |
|
| 288 | - 'Customer Details', |
|
| 289 | - $payment |
|
| 290 | - ); |
|
| 291 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
| 292 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
| 293 | - ? $cdetails_rstatus['args'] |
|
| 294 | - : array(); |
|
| 295 | - if ($cdetails_rstatus['status']) { |
|
| 296 | - // We got the PayerID so now we can Complete the transaction. |
|
| 297 | - $docheckout_request_dtls = array( |
|
| 298 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
| 299 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
| 300 | - 'TOKEN' => $payment_details['TOKEN'], |
|
| 301 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 302 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 303 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 304 | - ); |
|
| 305 | - // Include itemized list. |
|
| 306 | - $itemized_list = $this->itemize_list( |
|
| 307 | - $payment, |
|
| 308 | - $transaction, |
|
| 309 | - $cdata_response_args |
|
| 310 | - ); |
|
| 311 | - $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
| 312 | - // Payment Checkout/Capture. |
|
| 313 | - $docheckout_request_response = $this->_ppExpress_request( |
|
| 314 | - $docheckout_request_dtls, |
|
| 315 | - 'Do Payment', |
|
| 316 | - $payment |
|
| 317 | - ); |
|
| 318 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
| 319 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
| 320 | - ? $docheckout_rstatus['args'] |
|
| 321 | - : array(); |
|
| 322 | - if ($docheckout_rstatus['status']) { |
|
| 323 | - // All is well, payment approved. |
|
| 324 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
| 325 | - $primary_registrant->reg_code() |
|
| 326 | - : ''; |
|
| 327 | - $payment->set_extra_accntng($primary_registration_code); |
|
| 328 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
| 329 | - ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
| 330 | - : 0); |
|
| 331 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 332 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
| 333 | - : null); |
|
| 334 | - $payment->set_details($cdata_response_args); |
|
| 335 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
| 336 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
| 337 | - : ''); |
|
| 338 | - $payment->set_status($this->_pay_model->approved_status()); |
|
| 339 | - } else { |
|
| 340 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
| 341 | - $payment->set_gateway_response( |
|
| 342 | - $docheckout_response_args['L_ERRORCODE'] |
|
| 343 | - . '; ' |
|
| 344 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
| 345 | - ); |
|
| 346 | - } else { |
|
| 347 | - $payment->set_gateway_response( |
|
| 348 | - esc_html__( |
|
| 349 | - 'Error occurred while trying to Capture the funds.', |
|
| 350 | - 'event_espresso' |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - $payment->set_details($docheckout_response_args); |
|
| 355 | - $payment->set_status($this->_pay_model->declined_status()); |
|
| 356 | - } |
|
| 357 | - } else { |
|
| 358 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
| 359 | - $payment->set_gateway_response( |
|
| 360 | - $cdata_response_args['L_ERRORCODE'] |
|
| 361 | - . '; ' |
|
| 362 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
| 363 | - ); |
|
| 364 | - } else { |
|
| 365 | - $payment->set_gateway_response( |
|
| 366 | - esc_html__( |
|
| 367 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
| 368 | - 'event_espresso' |
|
| 369 | - ) |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - $payment->set_details($cdata_response_args); |
|
| 373 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 374 | - } |
|
| 375 | - } else { |
|
| 376 | - $payment->set_gateway_response( |
|
| 377 | - esc_html__( |
|
| 378 | - 'Error occurred while trying to process the payment.', |
|
| 379 | - 'event_espresso' |
|
| 380 | - ) |
|
| 381 | - ); |
|
| 382 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 383 | - } |
|
| 384 | - return $payment; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Make a list of items that are in the giver transaction. |
|
| 391 | - * |
|
| 392 | - * @param EEI_Payment $payment |
|
| 393 | - * @param EEI_Transaction $transaction |
|
| 394 | - * @param array $request_response_args Data from a previous communication with PP. |
|
| 395 | - * @return array |
|
| 396 | - */ |
|
| 397 | - public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
| 398 | - { |
|
| 399 | - $itemized_list = array(); |
|
| 400 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 401 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 402 | - if (! empty($request_response_args) |
|
| 403 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 404 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 405 | - ) { |
|
| 406 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 407 | - if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 408 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
| 409 | - ) { |
|
| 410 | - $itemized_list[ $arg_key ] = $arg_val; |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - // If we got only a few Items then something is not right. |
|
| 414 | - if (count($itemized_list) > 2) { |
|
| 415 | - return $itemized_list; |
|
| 416 | - } else { |
|
| 417 | - if (WP_DEBUG) { |
|
| 418 | - throw new EE_Error( |
|
| 419 | - sprintf( |
|
| 420 | - esc_html__( |
|
| 421 | - // @codingStandardsIgnoreStart |
|
| 422 | - 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
| 423 | - // @codingStandardsIgnoreEnd |
|
| 424 | - 'event_espresso' |
|
| 425 | - ), |
|
| 426 | - wp_json_encode($itemized_list) |
|
| 427 | - ) |
|
| 428 | - ); |
|
| 429 | - } |
|
| 430 | - // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
| 431 | - $itemized_list = array(); |
|
| 432 | - $this->log( |
|
| 433 | - array( |
|
| 434 | - esc_html__( |
|
| 435 | - 'Could not generate a proper item list with:', |
|
| 436 | - 'event_espresso' |
|
| 437 | - ) => $request_response_args |
|
| 438 | - ), |
|
| 439 | - $payment |
|
| 440 | - ); |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - // ...otherwise we generate a new list for this transaction. |
|
| 444 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 445 | - $item_num = 0; |
|
| 446 | - $itemized_sum = 0; |
|
| 447 | - $total_line_items = $transaction->total_line_item(); |
|
| 448 | - // Go through each item in the list. |
|
| 449 | - foreach ($total_line_items->get_items() as $line_item) { |
|
| 450 | - if ($line_item instanceof EE_Line_Item) { |
|
| 451 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 452 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
| 453 | - continue; |
|
| 454 | - } |
|
| 455 | - $unit_price = $line_item->unit_price(); |
|
| 456 | - $line_item_quantity = $line_item->quantity(); |
|
| 457 | - // This is a discount. |
|
| 458 | - if ($line_item->is_percent()) { |
|
| 459 | - $unit_price = $line_item->total(); |
|
| 460 | - $line_item_quantity = 1; |
|
| 461 | - } |
|
| 462 | - // Item Name. |
|
| 463 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 464 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 465 | - 0, |
|
| 466 | - 127 |
|
| 467 | - ); |
|
| 468 | - // Item description. |
|
| 469 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 470 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 471 | - 0, |
|
| 472 | - 127 |
|
| 473 | - ); |
|
| 474 | - // Cost of individual item. |
|
| 475 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 476 | - // Item Number. |
|
| 477 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 478 | - // Item quantity. |
|
| 479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 480 | - // Digital item is sold. |
|
| 481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 482 | - $itemized_sum += $line_item->total(); |
|
| 483 | - ++$item_num; |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - // Item's sales S/H and tax amount. |
|
| 487 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
| 488 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
| 489 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 490 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 491 | - $itemized_sum_diff_from_txn_total = round( |
|
| 492 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
| 493 | - 2 |
|
| 494 | - ); |
|
| 495 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 496 | - // add the difference as an extra line item. |
|
| 497 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
| 498 | - // Item Name. |
|
| 499 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 500 | - esc_html__( |
|
| 501 | - 'Other (promotion/surcharge/cancellation)', |
|
| 502 | - 'event_espresso' |
|
| 503 | - ), |
|
| 504 | - 0, |
|
| 505 | - 127 |
|
| 506 | - ); |
|
| 507 | - // Item description. |
|
| 508 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 509 | - // Cost of individual item. |
|
| 510 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 511 | - $itemized_sum_diff_from_txn_total |
|
| 512 | - ); |
|
| 513 | - // Item Number. |
|
| 514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 515 | - // Item quantity. |
|
| 516 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 517 | - // Digital item is sold. |
|
| 518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 519 | - $item_num++; |
|
| 520 | - } |
|
| 521 | - } else { |
|
| 522 | - // Just one Item. |
|
| 523 | - // Item Name. |
|
| 524 | - $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 525 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 526 | - 0, |
|
| 527 | - 127 |
|
| 528 | - ); |
|
| 529 | - // Item description. |
|
| 530 | - $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 531 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 532 | - 0, |
|
| 533 | - 127 |
|
| 534 | - ); |
|
| 535 | - // Cost of individual item. |
|
| 536 | - $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 537 | - // Item Number. |
|
| 538 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 539 | - // Item quantity. |
|
| 540 | - $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 541 | - // Digital item is sold. |
|
| 542 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 543 | - // Item's sales S/H and tax amount. |
|
| 544 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 545 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 546 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 547 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 548 | - } |
|
| 549 | - return $itemized_list; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Make the Express checkout request. |
|
| 556 | - * |
|
| 557 | - * @param array $request_params |
|
| 558 | - * @param string $request_text |
|
| 559 | - * @param EEI_Payment $payment |
|
| 560 | - * @return mixed |
|
| 561 | - */ |
|
| 562 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
| 563 | - { |
|
| 564 | - $request_dtls = array( |
|
| 565 | - 'VERSION' => '204.0', |
|
| 566 | - 'USER' => urlencode($this->_api_username), |
|
| 567 | - 'PWD' => urlencode($this->_api_password), |
|
| 568 | - 'SIGNATURE' => urlencode($this->_api_signature), |
|
| 569 | - // EE will blow up if you change this |
|
| 570 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 571 | - ); |
|
| 572 | - $dtls = array_merge($request_dtls, $request_params); |
|
| 573 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 574 | - // Request Customer Details. |
|
| 575 | - $request_response = wp_remote_post( |
|
| 576 | - $this->_base_gateway_url, |
|
| 577 | - array( |
|
| 578 | - 'method' => 'POST', |
|
| 579 | - 'timeout' => 45, |
|
| 580 | - 'httpversion' => '1.1', |
|
| 581 | - 'cookies' => array(), |
|
| 582 | - 'headers' => array(), |
|
| 583 | - 'body' => http_build_query($dtls, '', '&'), |
|
| 584 | - ) |
|
| 585 | - ); |
|
| 586 | - // Log the response. |
|
| 587 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 588 | - return $request_response; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * Check the response status. |
|
| 595 | - * |
|
| 596 | - * @param mixed $request_response |
|
| 597 | - * @return array |
|
| 598 | - */ |
|
| 599 | - public function _ppExpress_check_response($request_response) |
|
| 600 | - { |
|
| 601 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
| 602 | - // If we got here then there was an error in this request. |
|
| 603 | - return array('status' => false, 'args' => $request_response); |
|
| 604 | - } |
|
| 605 | - $response_args = array(); |
|
| 606 | - parse_str(urldecode($request_response['body']), $response_args); |
|
| 607 | - if (! isset($response_args['ACK'])) { |
|
| 608 | - return array('status' => false, 'args' => $request_response); |
|
| 609 | - } |
|
| 610 | - if (( |
|
| 611 | - isset($response_args['PAYERID']) |
|
| 612 | - || isset($response_args['TOKEN']) |
|
| 613 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 614 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
| 615 | - ) |
|
| 616 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
| 617 | - ) { |
|
| 618 | - // Response status OK, return response parameters for further processing. |
|
| 619 | - return array('status' => true, 'args' => $response_args); |
|
| 620 | - } |
|
| 621 | - $errors = $this->_get_errors($response_args); |
|
| 622 | - return array('status' => false, 'args' => $errors); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Log a "Cleared" request. |
|
| 629 | - * |
|
| 630 | - * @param array $request |
|
| 631 | - * @param EEI_Payment $payment |
|
| 632 | - * @param string $info |
|
| 633 | - * @return void |
|
| 634 | - */ |
|
| 635 | - private function _log_clean_request($request, $payment, $info) |
|
| 636 | - { |
|
| 637 | - $cleaned_request_data = $request; |
|
| 638 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
| 639 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * Get error from the response data. |
|
| 646 | - * |
|
| 647 | - * @param array $data_array |
|
| 648 | - * @return array |
|
| 649 | - */ |
|
| 650 | - private function _get_errors($data_array) |
|
| 651 | - { |
|
| 652 | - $errors = array(); |
|
| 653 | - $n = 0; |
|
| 654 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 655 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 656 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 657 | - : ''; |
|
| 658 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 659 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 660 | - : ''; |
|
| 661 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 662 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 663 | - : ''; |
|
| 664 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 665 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 666 | - : ''; |
|
| 667 | - if ($n === 0) { |
|
| 668 | - $errors = array( |
|
| 669 | - 'L_ERRORCODE' => $l_error_code, |
|
| 670 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
| 671 | - 'L_LONGMESSAGE' => $l_long_message, |
|
| 672 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
| 673 | - ); |
|
| 674 | - } else { |
|
| 675 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 676 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 677 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 678 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 679 | - } |
|
| 680 | - $n++; |
|
| 681 | - } |
|
| 682 | - return $errors; |
|
| 683 | - } |
|
| 30 | + /** |
|
| 31 | + * Merchant API Username. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $_api_username; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Merchant API Password. |
|
| 39 | + * |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + protected $_api_password; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * API Signature. |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + protected $_api_signature; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Request Shipping address on PP checkout page. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + protected $_request_shipping_addr; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Business/personal logo. |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + protected $_image_url; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * gateway URL variable |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + protected $_base_gateway_url = ''; |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * EEG_Paypal_Express constructor. |
|
| 76 | + */ |
|
| 77 | + public function __construct() |
|
| 78 | + { |
|
| 79 | + $this->_currencies_supported = array( |
|
| 80 | + 'USD', |
|
| 81 | + 'AUD', |
|
| 82 | + 'BRL', |
|
| 83 | + 'CAD', |
|
| 84 | + 'CZK', |
|
| 85 | + 'DKK', |
|
| 86 | + 'EUR', |
|
| 87 | + 'HKD', |
|
| 88 | + 'HUF', |
|
| 89 | + 'ILS', |
|
| 90 | + 'JPY', |
|
| 91 | + 'MYR', |
|
| 92 | + 'MXN', |
|
| 93 | + 'NOK', |
|
| 94 | + 'NZD', |
|
| 95 | + 'PHP', |
|
| 96 | + 'PLN', |
|
| 97 | + 'GBP', |
|
| 98 | + 'RUB', |
|
| 99 | + 'SGD', |
|
| 100 | + 'SEK', |
|
| 101 | + 'CHF', |
|
| 102 | + 'TWD', |
|
| 103 | + 'THB', |
|
| 104 | + 'TRY', |
|
| 105 | + 'INR', |
|
| 106 | + ); |
|
| 107 | + parent::__construct(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
| 114 | + * |
|
| 115 | + * @param array $settings_array |
|
| 116 | + */ |
|
| 117 | + public function set_settings($settings_array) |
|
| 118 | + { |
|
| 119 | + parent::set_settings($settings_array); |
|
| 120 | + // Redirect URL. |
|
| 121 | + $this->_base_gateway_url = $this->_debug_mode |
|
| 122 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
| 123 | + : 'https://api-3t.paypal.com/nvp'; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @param EEI_Payment $payment |
|
| 130 | + * @param array $billing_info |
|
| 131 | + * @param string $return_url |
|
| 132 | + * @param string $notify_url |
|
| 133 | + * @param string $cancel_url |
|
| 134 | + * @return \EE_Payment|\EEI_Payment |
|
| 135 | + * @throws \EE_Error |
|
| 136 | + */ |
|
| 137 | + public function set_redirection_info( |
|
| 138 | + $payment, |
|
| 139 | + $billing_info = array(), |
|
| 140 | + $return_url = null, |
|
| 141 | + $notify_url = null, |
|
| 142 | + $cancel_url = null |
|
| 143 | + ) { |
|
| 144 | + if (! $payment instanceof EEI_Payment) { |
|
| 145 | + $payment->set_gateway_response( |
|
| 146 | + esc_html__( |
|
| 147 | + 'Error. No associated payment was found.', |
|
| 148 | + 'event_espresso' |
|
| 149 | + ) |
|
| 150 | + ); |
|
| 151 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 152 | + return $payment; |
|
| 153 | + } |
|
| 154 | + $transaction = $payment->transaction(); |
|
| 155 | + if (! $transaction instanceof EEI_Transaction) { |
|
| 156 | + $payment->set_gateway_response( |
|
| 157 | + esc_html__( |
|
| 158 | + 'Could not process this payment because it has no associated transaction.', |
|
| 159 | + 'event_espresso' |
|
| 160 | + ) |
|
| 161 | + ); |
|
| 162 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 163 | + return $payment; |
|
| 164 | + } |
|
| 165 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 166 | + $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
| 167 | + $primary_registration = $transaction->primary_registration(); |
|
| 168 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
| 169 | + ? $primary_registration->attendee() |
|
| 170 | + : false; |
|
| 171 | + $locale = explode('-', get_bloginfo('language')); |
|
| 172 | + // Gather request parameters. |
|
| 173 | + $token_request_dtls = array( |
|
| 174 | + 'METHOD' => 'SetExpressCheckout', |
|
| 175 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 176 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 177 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
| 178 | + 'RETURNURL' => $return_url, |
|
| 179 | + 'CANCELURL' => $cancel_url, |
|
| 180 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 181 | + // Buyer does not need to create a PayPal account to check out. |
|
| 182 | + // This is referred to as PayPal Account Optional. |
|
| 183 | + 'SOLUTIONTYPE' => 'Sole', |
|
| 184 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 185 | + 'LOCALECODE' => $locale[1] |
|
| 186 | + ); |
|
| 187 | + // Show itemized list. |
|
| 188 | + $itemized_list = $this->itemize_list($payment, $transaction); |
|
| 189 | + $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
| 190 | + // Automatically filling out shipping and contact information. |
|
| 191 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
| 192 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 193 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
| 194 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 195 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 196 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 197 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 198 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 199 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 200 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 201 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 202 | + } elseif (! $this->_request_shipping_addr) { |
|
| 203 | + // Do not request shipping details on the PP Checkout page. |
|
| 204 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
| 205 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
| 206 | + } |
|
| 207 | + // Used a business/personal logo on the PayPal page. |
|
| 208 | + if (! empty($this->_image_url)) { |
|
| 209 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
| 210 | + } |
|
| 211 | + $token_request_dtls = apply_filters( |
|
| 212 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
| 213 | + $token_request_dtls, |
|
| 214 | + $this |
|
| 215 | + ); |
|
| 216 | + // Request PayPal token. |
|
| 217 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
| 218 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
| 219 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
| 220 | + ? $token_rstatus['args'] |
|
| 221 | + : array(); |
|
| 222 | + if ($token_rstatus['status']) { |
|
| 223 | + // We got the Token so we may continue with the payment and redirect the client. |
|
| 224 | + $payment->set_details($response_args); |
|
| 225 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 226 | + $payment->set_redirect_url( |
|
| 227 | + $gateway_url |
|
| 228 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
| 229 | + . $response_args['TOKEN'] |
|
| 230 | + ); |
|
| 231 | + } else { |
|
| 232 | + if (isset($response_args['L_ERRORCODE'])) { |
|
| 233 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 234 | + } else { |
|
| 235 | + $payment->set_gateway_response( |
|
| 236 | + esc_html__( |
|
| 237 | + 'Error occurred while trying to setup the Express Checkout.', |
|
| 238 | + 'event_espresso' |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + $payment->set_details($response_args); |
|
| 243 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 244 | + } |
|
| 245 | + return $payment; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param array $update_info { |
|
| 252 | + * @type string $gateway_txn_id |
|
| 253 | + * @type string status an EEMI_Payment status |
|
| 254 | + * } |
|
| 255 | + * @param EEI_Transaction $transaction |
|
| 256 | + * @return EEI_Payment |
|
| 257 | + */ |
|
| 258 | + public function handle_payment_update($update_info, $transaction) |
|
| 259 | + { |
|
| 260 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
| 261 | + if ($payment instanceof EEI_Payment) { |
|
| 262 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
| 263 | + $transaction = $payment->transaction(); |
|
| 264 | + if (! $transaction instanceof EEI_Transaction) { |
|
| 265 | + $payment->set_gateway_response( |
|
| 266 | + esc_html__( |
|
| 267 | + 'Could not process this payment because it has no associated transaction.', |
|
| 268 | + 'event_espresso' |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 272 | + return $payment; |
|
| 273 | + } |
|
| 274 | + $primary_registrant = $transaction->primary_registration(); |
|
| 275 | + $payment_details = $payment->details(); |
|
| 276 | + // Check if we still have the token. |
|
| 277 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 278 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 279 | + return $payment; |
|
| 280 | + } |
|
| 281 | + $cdetails_request_dtls = array( |
|
| 282 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
| 283 | + 'TOKEN' => $payment_details['TOKEN'], |
|
| 284 | + ); |
|
| 285 | + // Request Customer Details. |
|
| 286 | + $cdetails_request_response = $this->_ppExpress_request( |
|
| 287 | + $cdetails_request_dtls, |
|
| 288 | + 'Customer Details', |
|
| 289 | + $payment |
|
| 290 | + ); |
|
| 291 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
| 292 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
| 293 | + ? $cdetails_rstatus['args'] |
|
| 294 | + : array(); |
|
| 295 | + if ($cdetails_rstatus['status']) { |
|
| 296 | + // We got the PayerID so now we can Complete the transaction. |
|
| 297 | + $docheckout_request_dtls = array( |
|
| 298 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
| 299 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
| 300 | + 'TOKEN' => $payment_details['TOKEN'], |
|
| 301 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 302 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 303 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 304 | + ); |
|
| 305 | + // Include itemized list. |
|
| 306 | + $itemized_list = $this->itemize_list( |
|
| 307 | + $payment, |
|
| 308 | + $transaction, |
|
| 309 | + $cdata_response_args |
|
| 310 | + ); |
|
| 311 | + $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
| 312 | + // Payment Checkout/Capture. |
|
| 313 | + $docheckout_request_response = $this->_ppExpress_request( |
|
| 314 | + $docheckout_request_dtls, |
|
| 315 | + 'Do Payment', |
|
| 316 | + $payment |
|
| 317 | + ); |
|
| 318 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
| 319 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
| 320 | + ? $docheckout_rstatus['args'] |
|
| 321 | + : array(); |
|
| 322 | + if ($docheckout_rstatus['status']) { |
|
| 323 | + // All is well, payment approved. |
|
| 324 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
| 325 | + $primary_registrant->reg_code() |
|
| 326 | + : ''; |
|
| 327 | + $payment->set_extra_accntng($primary_registration_code); |
|
| 328 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
| 329 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
| 330 | + : 0); |
|
| 331 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 332 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
| 333 | + : null); |
|
| 334 | + $payment->set_details($cdata_response_args); |
|
| 335 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
| 336 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
| 337 | + : ''); |
|
| 338 | + $payment->set_status($this->_pay_model->approved_status()); |
|
| 339 | + } else { |
|
| 340 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
| 341 | + $payment->set_gateway_response( |
|
| 342 | + $docheckout_response_args['L_ERRORCODE'] |
|
| 343 | + . '; ' |
|
| 344 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
| 345 | + ); |
|
| 346 | + } else { |
|
| 347 | + $payment->set_gateway_response( |
|
| 348 | + esc_html__( |
|
| 349 | + 'Error occurred while trying to Capture the funds.', |
|
| 350 | + 'event_espresso' |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + $payment->set_details($docheckout_response_args); |
|
| 355 | + $payment->set_status($this->_pay_model->declined_status()); |
|
| 356 | + } |
|
| 357 | + } else { |
|
| 358 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
| 359 | + $payment->set_gateway_response( |
|
| 360 | + $cdata_response_args['L_ERRORCODE'] |
|
| 361 | + . '; ' |
|
| 362 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
| 363 | + ); |
|
| 364 | + } else { |
|
| 365 | + $payment->set_gateway_response( |
|
| 366 | + esc_html__( |
|
| 367 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
| 368 | + 'event_espresso' |
|
| 369 | + ) |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + $payment->set_details($cdata_response_args); |
|
| 373 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 374 | + } |
|
| 375 | + } else { |
|
| 376 | + $payment->set_gateway_response( |
|
| 377 | + esc_html__( |
|
| 378 | + 'Error occurred while trying to process the payment.', |
|
| 379 | + 'event_espresso' |
|
| 380 | + ) |
|
| 381 | + ); |
|
| 382 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 383 | + } |
|
| 384 | + return $payment; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Make a list of items that are in the giver transaction. |
|
| 391 | + * |
|
| 392 | + * @param EEI_Payment $payment |
|
| 393 | + * @param EEI_Transaction $transaction |
|
| 394 | + * @param array $request_response_args Data from a previous communication with PP. |
|
| 395 | + * @return array |
|
| 396 | + */ |
|
| 397 | + public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
| 398 | + { |
|
| 399 | + $itemized_list = array(); |
|
| 400 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 401 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 402 | + if (! empty($request_response_args) |
|
| 403 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 404 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 405 | + ) { |
|
| 406 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 407 | + if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 408 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
| 409 | + ) { |
|
| 410 | + $itemized_list[ $arg_key ] = $arg_val; |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + // If we got only a few Items then something is not right. |
|
| 414 | + if (count($itemized_list) > 2) { |
|
| 415 | + return $itemized_list; |
|
| 416 | + } else { |
|
| 417 | + if (WP_DEBUG) { |
|
| 418 | + throw new EE_Error( |
|
| 419 | + sprintf( |
|
| 420 | + esc_html__( |
|
| 421 | + // @codingStandardsIgnoreStart |
|
| 422 | + 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
| 423 | + // @codingStandardsIgnoreEnd |
|
| 424 | + 'event_espresso' |
|
| 425 | + ), |
|
| 426 | + wp_json_encode($itemized_list) |
|
| 427 | + ) |
|
| 428 | + ); |
|
| 429 | + } |
|
| 430 | + // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
| 431 | + $itemized_list = array(); |
|
| 432 | + $this->log( |
|
| 433 | + array( |
|
| 434 | + esc_html__( |
|
| 435 | + 'Could not generate a proper item list with:', |
|
| 436 | + 'event_espresso' |
|
| 437 | + ) => $request_response_args |
|
| 438 | + ), |
|
| 439 | + $payment |
|
| 440 | + ); |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + // ...otherwise we generate a new list for this transaction. |
|
| 444 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 445 | + $item_num = 0; |
|
| 446 | + $itemized_sum = 0; |
|
| 447 | + $total_line_items = $transaction->total_line_item(); |
|
| 448 | + // Go through each item in the list. |
|
| 449 | + foreach ($total_line_items->get_items() as $line_item) { |
|
| 450 | + if ($line_item instanceof EE_Line_Item) { |
|
| 451 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 452 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
| 453 | + continue; |
|
| 454 | + } |
|
| 455 | + $unit_price = $line_item->unit_price(); |
|
| 456 | + $line_item_quantity = $line_item->quantity(); |
|
| 457 | + // This is a discount. |
|
| 458 | + if ($line_item->is_percent()) { |
|
| 459 | + $unit_price = $line_item->total(); |
|
| 460 | + $line_item_quantity = 1; |
|
| 461 | + } |
|
| 462 | + // Item Name. |
|
| 463 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 464 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 465 | + 0, |
|
| 466 | + 127 |
|
| 467 | + ); |
|
| 468 | + // Item description. |
|
| 469 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 470 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 471 | + 0, |
|
| 472 | + 127 |
|
| 473 | + ); |
|
| 474 | + // Cost of individual item. |
|
| 475 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 476 | + // Item Number. |
|
| 477 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 478 | + // Item quantity. |
|
| 479 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 480 | + // Digital item is sold. |
|
| 481 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 482 | + $itemized_sum += $line_item->total(); |
|
| 483 | + ++$item_num; |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + // Item's sales S/H and tax amount. |
|
| 487 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
| 488 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
| 489 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 490 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 491 | + $itemized_sum_diff_from_txn_total = round( |
|
| 492 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
| 493 | + 2 |
|
| 494 | + ); |
|
| 495 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 496 | + // add the difference as an extra line item. |
|
| 497 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
| 498 | + // Item Name. |
|
| 499 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 500 | + esc_html__( |
|
| 501 | + 'Other (promotion/surcharge/cancellation)', |
|
| 502 | + 'event_espresso' |
|
| 503 | + ), |
|
| 504 | + 0, |
|
| 505 | + 127 |
|
| 506 | + ); |
|
| 507 | + // Item description. |
|
| 508 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 509 | + // Cost of individual item. |
|
| 510 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 511 | + $itemized_sum_diff_from_txn_total |
|
| 512 | + ); |
|
| 513 | + // Item Number. |
|
| 514 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 515 | + // Item quantity. |
|
| 516 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 517 | + // Digital item is sold. |
|
| 518 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 519 | + $item_num++; |
|
| 520 | + } |
|
| 521 | + } else { |
|
| 522 | + // Just one Item. |
|
| 523 | + // Item Name. |
|
| 524 | + $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 525 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 526 | + 0, |
|
| 527 | + 127 |
|
| 528 | + ); |
|
| 529 | + // Item description. |
|
| 530 | + $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 531 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 532 | + 0, |
|
| 533 | + 127 |
|
| 534 | + ); |
|
| 535 | + // Cost of individual item. |
|
| 536 | + $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 537 | + // Item Number. |
|
| 538 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 539 | + // Item quantity. |
|
| 540 | + $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 541 | + // Digital item is sold. |
|
| 542 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 543 | + // Item's sales S/H and tax amount. |
|
| 544 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 545 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 546 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 547 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 548 | + } |
|
| 549 | + return $itemized_list; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Make the Express checkout request. |
|
| 556 | + * |
|
| 557 | + * @param array $request_params |
|
| 558 | + * @param string $request_text |
|
| 559 | + * @param EEI_Payment $payment |
|
| 560 | + * @return mixed |
|
| 561 | + */ |
|
| 562 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
| 563 | + { |
|
| 564 | + $request_dtls = array( |
|
| 565 | + 'VERSION' => '204.0', |
|
| 566 | + 'USER' => urlencode($this->_api_username), |
|
| 567 | + 'PWD' => urlencode($this->_api_password), |
|
| 568 | + 'SIGNATURE' => urlencode($this->_api_signature), |
|
| 569 | + // EE will blow up if you change this |
|
| 570 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 571 | + ); |
|
| 572 | + $dtls = array_merge($request_dtls, $request_params); |
|
| 573 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 574 | + // Request Customer Details. |
|
| 575 | + $request_response = wp_remote_post( |
|
| 576 | + $this->_base_gateway_url, |
|
| 577 | + array( |
|
| 578 | + 'method' => 'POST', |
|
| 579 | + 'timeout' => 45, |
|
| 580 | + 'httpversion' => '1.1', |
|
| 581 | + 'cookies' => array(), |
|
| 582 | + 'headers' => array(), |
|
| 583 | + 'body' => http_build_query($dtls, '', '&'), |
|
| 584 | + ) |
|
| 585 | + ); |
|
| 586 | + // Log the response. |
|
| 587 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 588 | + return $request_response; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Check the response status. |
|
| 595 | + * |
|
| 596 | + * @param mixed $request_response |
|
| 597 | + * @return array |
|
| 598 | + */ |
|
| 599 | + public function _ppExpress_check_response($request_response) |
|
| 600 | + { |
|
| 601 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
| 602 | + // If we got here then there was an error in this request. |
|
| 603 | + return array('status' => false, 'args' => $request_response); |
|
| 604 | + } |
|
| 605 | + $response_args = array(); |
|
| 606 | + parse_str(urldecode($request_response['body']), $response_args); |
|
| 607 | + if (! isset($response_args['ACK'])) { |
|
| 608 | + return array('status' => false, 'args' => $request_response); |
|
| 609 | + } |
|
| 610 | + if (( |
|
| 611 | + isset($response_args['PAYERID']) |
|
| 612 | + || isset($response_args['TOKEN']) |
|
| 613 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 614 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
| 615 | + ) |
|
| 616 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
| 617 | + ) { |
|
| 618 | + // Response status OK, return response parameters for further processing. |
|
| 619 | + return array('status' => true, 'args' => $response_args); |
|
| 620 | + } |
|
| 621 | + $errors = $this->_get_errors($response_args); |
|
| 622 | + return array('status' => false, 'args' => $errors); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Log a "Cleared" request. |
|
| 629 | + * |
|
| 630 | + * @param array $request |
|
| 631 | + * @param EEI_Payment $payment |
|
| 632 | + * @param string $info |
|
| 633 | + * @return void |
|
| 634 | + */ |
|
| 635 | + private function _log_clean_request($request, $payment, $info) |
|
| 636 | + { |
|
| 637 | + $cleaned_request_data = $request; |
|
| 638 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
| 639 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * Get error from the response data. |
|
| 646 | + * |
|
| 647 | + * @param array $data_array |
|
| 648 | + * @return array |
|
| 649 | + */ |
|
| 650 | + private function _get_errors($data_array) |
|
| 651 | + { |
|
| 652 | + $errors = array(); |
|
| 653 | + $n = 0; |
|
| 654 | + while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 655 | + $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 656 | + ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 657 | + : ''; |
|
| 658 | + $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 659 | + ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 660 | + : ''; |
|
| 661 | + $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 662 | + ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 663 | + : ''; |
|
| 664 | + $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 665 | + ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 666 | + : ''; |
|
| 667 | + if ($n === 0) { |
|
| 668 | + $errors = array( |
|
| 669 | + 'L_ERRORCODE' => $l_error_code, |
|
| 670 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
| 671 | + 'L_LONGMESSAGE' => $l_long_message, |
|
| 672 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
| 673 | + ); |
|
| 674 | + } else { |
|
| 675 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 676 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 677 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 678 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 679 | + } |
|
| 680 | + $n++; |
|
| 681 | + } |
|
| 682 | + return $errors; |
|
| 683 | + } |
|
| 684 | 684 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * ---------------------------------------------- |
| 11 | 11 | */ |
| 12 | 12 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
| 13 | -if (! function_exists('mb_strcut')) { |
|
| 13 | +if ( ! function_exists('mb_strcut')) { |
|
| 14 | 14 | /** |
| 15 | 15 | * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
| 16 | 16 | * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $notify_url = null, |
| 142 | 142 | $cancel_url = null |
| 143 | 143 | ) { |
| 144 | - if (! $payment instanceof EEI_Payment) { |
|
| 144 | + if ( ! $payment instanceof EEI_Payment) { |
|
| 145 | 145 | $payment->set_gateway_response( |
| 146 | 146 | esc_html__( |
| 147 | 147 | 'Error. No associated payment was found.', |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | return $payment; |
| 153 | 153 | } |
| 154 | 154 | $transaction = $payment->transaction(); |
| 155 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 155 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
| 156 | 156 | $payment->set_gateway_response( |
| 157 | 157 | esc_html__( |
| 158 | 158 | 'Could not process this payment because it has no associated transaction.', |
@@ -199,13 +199,13 @@ discard block |
||
| 199 | 199 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
| 200 | 200 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
| 201 | 201 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
| 202 | - } elseif (! $this->_request_shipping_addr) { |
|
| 202 | + } elseif ( ! $this->_request_shipping_addr) { |
|
| 203 | 203 | // Do not request shipping details on the PP Checkout page. |
| 204 | 204 | $token_request_dtls['NOSHIPPING'] = '1'; |
| 205 | 205 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
| 206 | 206 | } |
| 207 | 207 | // Used a business/personal logo on the PayPal page. |
| 208 | - if (! empty($this->_image_url)) { |
|
| 208 | + if ( ! empty($this->_image_url)) { |
|
| 209 | 209 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
| 210 | 210 | } |
| 211 | 211 | $token_request_dtls = apply_filters( |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | ); |
| 231 | 231 | } else { |
| 232 | 232 | if (isset($response_args['L_ERRORCODE'])) { |
| 233 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 233 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
| 234 | 234 | } else { |
| 235 | 235 | $payment->set_gateway_response( |
| 236 | 236 | esc_html__( |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | if ($payment instanceof EEI_Payment) { |
| 262 | 262 | $this->log(array('Return from Authorization' => $update_info), $payment); |
| 263 | 263 | $transaction = $payment->transaction(); |
| 264 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 264 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
| 265 | 265 | $payment->set_gateway_response( |
| 266 | 266 | esc_html__( |
| 267 | 267 | 'Could not process this payment because it has no associated transaction.', |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | $primary_registrant = $transaction->primary_registration(); |
| 275 | 275 | $payment_details = $payment->details(); |
| 276 | 276 | // Check if we still have the token. |
| 277 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 277 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 278 | 278 | $payment->set_status($this->_pay_model->failed_status()); |
| 279 | 279 | return $payment; |
| 280 | 280 | } |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | $itemized_list = array(); |
| 400 | 400 | $gateway_formatter = $this->_get_gateway_formatter(); |
| 401 | 401 | // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
| 402 | - if (! empty($request_response_args) |
|
| 402 | + if ( ! empty($request_response_args) |
|
| 403 | 403 | && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
| 404 | 404 | && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
| 405 | 405 | ) { |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
| 408 | 408 | && strpos($arg_key, 'NOTIFYURL') === false |
| 409 | 409 | ) { |
| 410 | - $itemized_list[ $arg_key ] = $arg_val; |
|
| 410 | + $itemized_list[$arg_key] = $arg_val; |
|
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | 413 | // If we got only a few Items then something is not right. |
@@ -460,25 +460,25 @@ discard block |
||
| 460 | 460 | $line_item_quantity = 1; |
| 461 | 461 | } |
| 462 | 462 | // Item Name. |
| 463 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 463 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
| 464 | 464 | $gateway_formatter->formatLineItemName($line_item, $payment), |
| 465 | 465 | 0, |
| 466 | 466 | 127 |
| 467 | 467 | ); |
| 468 | 468 | // Item description. |
| 469 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 469 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = mb_strcut( |
|
| 470 | 470 | $gateway_formatter->formatLineItemDesc($line_item, $payment), |
| 471 | 471 | 0, |
| 472 | 472 | 127 |
| 473 | 473 | ); |
| 474 | 474 | // Cost of individual item. |
| 475 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 475 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency($unit_price); |
|
| 476 | 476 | // Item Number. |
| 477 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 477 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
| 478 | 478 | // Item quantity. |
| 479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 479 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity; |
|
| 480 | 480 | // Digital item is sold. |
| 481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 481 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
| 482 | 482 | $itemized_sum += $line_item->total(); |
| 483 | 483 | ++$item_num; |
| 484 | 484 | } |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | // add the difference as an extra line item. |
| 497 | 497 | if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
| 498 | 498 | // Item Name. |
| 499 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 499 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
| 500 | 500 | esc_html__( |
| 501 | 501 | 'Other (promotion/surcharge/cancellation)', |
| 502 | 502 | 'event_espresso' |
@@ -505,17 +505,17 @@ discard block |
||
| 505 | 505 | 127 |
| 506 | 506 | ); |
| 507 | 507 | // Item description. |
| 508 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 508 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
|
| 509 | 509 | // Cost of individual item. |
| 510 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 510 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency( |
|
| 511 | 511 | $itemized_sum_diff_from_txn_total |
| 512 | 512 | ); |
| 513 | 513 | // Item Number. |
| 514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 514 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
| 515 | 515 | // Item quantity. |
| 516 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 516 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
|
| 517 | 517 | // Digital item is sold. |
| 518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 518 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
| 519 | 519 | $item_num++; |
| 520 | 520 | } |
| 521 | 521 | } else { |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | 'BUTTONSOURCE' => 'EventEspresso_SP', |
| 571 | 571 | ); |
| 572 | 572 | $dtls = array_merge($request_dtls, $request_params); |
| 573 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 573 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
| 574 | 574 | // Request Customer Details. |
| 575 | 575 | $request_response = wp_remote_post( |
| 576 | 576 | $this->_base_gateway_url, |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | ) |
| 585 | 585 | ); |
| 586 | 586 | // Log the response. |
| 587 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 587 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
| 588 | 588 | return $request_response; |
| 589 | 589 | } |
| 590 | 590 | |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | } |
| 605 | 605 | $response_args = array(); |
| 606 | 606 | parse_str(urldecode($request_response['body']), $response_args); |
| 607 | - if (! isset($response_args['ACK'])) { |
|
| 607 | + if ( ! isset($response_args['ACK'])) { |
|
| 608 | 608 | return array('status' => false, 'args' => $request_response); |
| 609 | 609 | } |
| 610 | 610 | if (( |
@@ -651,18 +651,18 @@ discard block |
||
| 651 | 651 | { |
| 652 | 652 | $errors = array(); |
| 653 | 653 | $n = 0; |
| 654 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 655 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 656 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 654 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
| 655 | + $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
| 656 | + ? $data_array["L_ERRORCODE{$n}"] |
|
| 657 | 657 | : ''; |
| 658 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 659 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 658 | + $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
| 659 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
| 660 | 660 | : ''; |
| 661 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 662 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 661 | + $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
| 662 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
| 663 | 663 | : ''; |
| 664 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 665 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 664 | + $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
| 665 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
| 666 | 666 | : ''; |
| 667 | 667 | if ($n === 0) { |
| 668 | 668 | $errors = array( |
@@ -672,10 +672,10 @@ discard block |
||
| 672 | 672 | 'L_SEVERITYCODE' => $l_severity_code, |
| 673 | 673 | ); |
| 674 | 674 | } else { |
| 675 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 676 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 677 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 678 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 675 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
| 676 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
| 677 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
| 678 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
| 679 | 679 | } |
| 680 | 680 | $n++; |
| 681 | 681 | } |
@@ -11,59 +11,59 @@ |
||
| 11 | 11 | class EE_URL_Validation_Strategy extends EE_Validation_Strategy_Base |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var @boolean whether we should check if the file exists or not |
|
| 16 | - */ |
|
| 17 | - protected $check_file_exists; |
|
| 14 | + /** |
|
| 15 | + * @var @boolean whether we should check if the file exists or not |
|
| 16 | + */ |
|
| 17 | + protected $check_file_exists; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param null $validation_error_message |
|
| 21 | - * @param boolean $check_file_exists |
|
| 22 | - */ |
|
| 23 | - public function __construct($validation_error_message = null, $check_file_exists = false) |
|
| 24 | - { |
|
| 25 | - if (! $validation_error_message) { |
|
| 26 | - $validation_error_message = __("Please enter a valid URL. Eg https://eventespresso.com", "event_espresso"); |
|
| 27 | - } |
|
| 28 | - $this->check_file_exists = $check_file_exists; |
|
| 29 | - parent::__construct($validation_error_message); |
|
| 30 | - } |
|
| 19 | + /** |
|
| 20 | + * @param null $validation_error_message |
|
| 21 | + * @param boolean $check_file_exists |
|
| 22 | + */ |
|
| 23 | + public function __construct($validation_error_message = null, $check_file_exists = false) |
|
| 24 | + { |
|
| 25 | + if (! $validation_error_message) { |
|
| 26 | + $validation_error_message = __("Please enter a valid URL. Eg https://eventespresso.com", "event_espresso"); |
|
| 27 | + } |
|
| 28 | + $this->check_file_exists = $check_file_exists; |
|
| 29 | + parent::__construct($validation_error_message); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * just checks the field isn't blank |
|
| 36 | - * |
|
| 37 | - * @param $normalized_value |
|
| 38 | - * @return bool |
|
| 39 | - * @throws \EE_Validation_Error |
|
| 40 | - */ |
|
| 41 | - public function validate($normalized_value) |
|
| 42 | - { |
|
| 43 | - if ($normalized_value) { |
|
| 44 | - if (filter_var($normalized_value, FILTER_VALIDATE_URL) === false) { |
|
| 45 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'invalid_url'); |
|
| 46 | - } elseif (apply_filters('FHEE__EE_URL_Validation_Strategy__validate__check_remote_file_exists', $this->check_file_exists, $this->_input)) { |
|
| 47 | - if (! EEH_URL::remote_file_exists( |
|
| 48 | - $normalized_value, |
|
| 49 | - array( |
|
| 50 | - 'sslverify' => false, |
|
| 51 | - 'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
| 52 | - ) |
|
| 53 | - )) { |
|
| 54 | - throw new EE_Validation_Error(sprintf(__("That URL seems to be broken. Please enter a valid URL", "event_espresso"))); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - } |
|
| 34 | + /** |
|
| 35 | + * just checks the field isn't blank |
|
| 36 | + * |
|
| 37 | + * @param $normalized_value |
|
| 38 | + * @return bool |
|
| 39 | + * @throws \EE_Validation_Error |
|
| 40 | + */ |
|
| 41 | + public function validate($normalized_value) |
|
| 42 | + { |
|
| 43 | + if ($normalized_value) { |
|
| 44 | + if (filter_var($normalized_value, FILTER_VALIDATE_URL) === false) { |
|
| 45 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'invalid_url'); |
|
| 46 | + } elseif (apply_filters('FHEE__EE_URL_Validation_Strategy__validate__check_remote_file_exists', $this->check_file_exists, $this->_input)) { |
|
| 47 | + if (! EEH_URL::remote_file_exists( |
|
| 48 | + $normalized_value, |
|
| 49 | + array( |
|
| 50 | + 'sslverify' => false, |
|
| 51 | + 'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
| 52 | + ) |
|
| 53 | + )) { |
|
| 54 | + throw new EE_Validation_Error(sprintf(__("That URL seems to be broken. Please enter a valid URL", "event_espresso"))); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @return array |
|
| 64 | - */ |
|
| 65 | - public function get_jquery_validation_rule_array() |
|
| 66 | - { |
|
| 67 | - return array( 'validUrl'=>true, 'messages' => array( 'validUrl' => $this->get_validation_error_message() ) ); |
|
| 68 | - } |
|
| 62 | + /** |
|
| 63 | + * @return array |
|
| 64 | + */ |
|
| 65 | + public function get_jquery_validation_rule_array() |
|
| 66 | + { |
|
| 67 | + return array( 'validUrl'=>true, 'messages' => array( 'validUrl' => $this->get_validation_error_message() ) ); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public function __construct($validation_error_message = null, $check_file_exists = false) |
| 24 | 24 | { |
| 25 | - if (! $validation_error_message) { |
|
| 25 | + if ( ! $validation_error_message) { |
|
| 26 | 26 | $validation_error_message = __("Please enter a valid URL. Eg https://eventespresso.com", "event_espresso"); |
| 27 | 27 | } |
| 28 | 28 | $this->check_file_exists = $check_file_exists; |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | if (filter_var($normalized_value, FILTER_VALIDATE_URL) === false) { |
| 45 | 45 | throw new EE_Validation_Error($this->get_validation_error_message(), 'invalid_url'); |
| 46 | 46 | } elseif (apply_filters('FHEE__EE_URL_Validation_Strategy__validate__check_remote_file_exists', $this->check_file_exists, $this->_input)) { |
| 47 | - if (! EEH_URL::remote_file_exists( |
|
| 47 | + if ( ! EEH_URL::remote_file_exists( |
|
| 48 | 48 | $normalized_value, |
| 49 | 49 | array( |
| 50 | 50 | 'sslverify' => false, |
| 51 | - 'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
| 51 | + 'limit_response_size' => 4095, // we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
| 52 | 52 | ) |
| 53 | 53 | )) { |
| 54 | 54 | throw new EE_Validation_Error(sprintf(__("That URL seems to be broken. Please enter a valid URL", "event_espresso"))); |
@@ -64,6 +64,6 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function get_jquery_validation_rule_array() |
| 66 | 66 | { |
| 67 | - return array( 'validUrl'=>true, 'messages' => array( 'validUrl' => $this->get_validation_error_message() ) ); |
|
| 67 | + return array('validUrl'=>true, 'messages' => array('validUrl' => $this->get_validation_error_message())); |
|
| 68 | 68 | } |
| 69 | 69 | } |
@@ -11,21 +11,21 @@ |
||
| 11 | 11 | class EE_Admin_File_Uploader_Input extends EE_Form_Input_Base |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param array $input_settings |
|
| 16 | - */ |
|
| 17 | - public function __construct($input_settings = array()) |
|
| 18 | - { |
|
| 19 | - $this->_set_display_strategy(new EE_Admin_File_Uploader_Display_Strategy()); |
|
| 20 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
| 21 | - $this->_add_validation_strategy( |
|
| 22 | - new EE_URL_Validation_Strategy( |
|
| 23 | - isset($input_settings['validation_error_message']) |
|
| 24 | - ? $input_settings['validation_error_message'] |
|
| 25 | - : null, |
|
| 26 | - true |
|
| 27 | - ) |
|
| 28 | - ); |
|
| 29 | - parent::__construct($input_settings); |
|
| 30 | - } |
|
| 14 | + /** |
|
| 15 | + * @param array $input_settings |
|
| 16 | + */ |
|
| 17 | + public function __construct($input_settings = array()) |
|
| 18 | + { |
|
| 19 | + $this->_set_display_strategy(new EE_Admin_File_Uploader_Display_Strategy()); |
|
| 20 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
| 21 | + $this->_add_validation_strategy( |
|
| 22 | + new EE_URL_Validation_Strategy( |
|
| 23 | + isset($input_settings['validation_error_message']) |
|
| 24 | + ? $input_settings['validation_error_message'] |
|
| 25 | + : null, |
|
| 26 | + true |
|
| 27 | + ) |
|
| 28 | + ); |
|
| 29 | + parent::__construct($input_settings); |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -84,8 +84,6 @@ discard block |
||
| 84 | 84 | KEY `submitted` (`submitted`), |
| 85 | 85 | KEY `likes` (`likes`) |
| 86 | 86 | ) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8$$ |
| 87 | - |
|
| 88 | - |
|
| 89 | 87 | * |
| 90 | 88 | * 4.1 Event model: |
| 91 | 89 | * $this->_tables = array( |
@@ -124,7 +122,6 @@ discard block |
||
| 124 | 122 | 'EVT_donations'=>new EE_Boolean_Field('EVT_donations', __("Accept Donations?", "event_espresso"), false, false) |
| 125 | 123 | |
| 126 | 124 | )); |
| 127 | - |
|
| 128 | 125 | * |
| 129 | 126 | * 3.1's start end table |
| 130 | 127 | * |
@@ -137,8 +134,6 @@ discard block |
||
| 137 | 134 | PRIMARY KEY (`id`), |
| 138 | 135 | KEY `event_id` (`event_id`) |
| 139 | 136 | ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8$$ |
| 140 | - |
|
| 141 | - |
|
| 142 | 137 | * |
| 143 | 138 | * and 4.1 Datetime model's tables and fields: |
| 144 | 139 | * $this->_tables = array( |
@@ -160,172 +155,172 @@ discard block |
||
| 160 | 155 | */ |
| 161 | 156 | class EE_DMS_4_1_0_events extends EE_Data_Migration_Script_Stage |
| 162 | 157 | { |
| 163 | - private $_old_table; |
|
| 164 | - private $_old_start_end_table; |
|
| 165 | - private $_new_table; |
|
| 166 | - private $_new_meta_table; |
|
| 167 | - private $_new_datetime_table; |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Just initializes the status of the migration |
|
| 173 | - * @throws EE_Error |
|
| 174 | - */ |
|
| 175 | - public function __construct() |
|
| 176 | - { |
|
| 177 | - global $wpdb; |
|
| 178 | - $this->_old_table = $wpdb->prefix."events_detail"; |
|
| 179 | - $this->_old_start_end_table = $wpdb->prefix."events_start_end"; |
|
| 180 | - $this->_new_table = $wpdb->prefix."posts"; |
|
| 181 | - $this->_new_meta_table = $wpdb->prefix."esp_event_meta"; |
|
| 182 | - $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 183 | - $this->_pretty_name = __("Events", "event_espresso"); |
|
| 184 | - parent::__construct(); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Counts the records to migrate; the public version may cache it |
|
| 191 | - * @return int |
|
| 192 | - */ |
|
| 193 | - public function _count_records_to_migrate() |
|
| 194 | - { |
|
| 195 | - global $wpdb; |
|
| 196 | - $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table . ' WHERE event_status !="D"'); |
|
| 197 | - return intval($count); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly. |
|
| 204 | - * Note: it should not alter the count of items migrated. That is done in the public function that calls this. |
|
| 205 | - * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it |
|
| 206 | - * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50, |
|
| 207 | - * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated) |
|
| 208 | - * @param int $num_items_to_migrate |
|
| 209 | - * @return int number of items ACTUALLY migrated |
|
| 210 | - */ |
|
| 211 | - protected function _migration_step($num_items_to_migrate = 50) |
|
| 212 | - { |
|
| 213 | - global $wpdb; |
|
| 214 | - // because the migration of each event can be a LOT more work, make each step smaller |
|
| 215 | - $num_items_to_migrate = max(1, $num_items_to_migrate/5); |
|
| 216 | - $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A); |
|
| 217 | - $items_migrated_this_step = 0; |
|
| 218 | - |
|
| 219 | - foreach ($events as $event_row) { |
|
| 220 | - $guid = null; |
|
| 221 | - // insert new 4.1 Attendee object using $wpdb |
|
| 222 | - $post_id = $this->_insert_cpt($event_row); |
|
| 223 | - if ($post_id) { |
|
| 224 | - $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id); |
|
| 225 | - $meta_id = $this->_insert_event_meta($event_row, $post_id); |
|
| 226 | - if ($meta_id) { |
|
| 227 | - $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id); |
|
| 228 | - } |
|
| 229 | - $this->_convert_start_end_times($event_row, $post_id); |
|
| 230 | - $event_meta = maybe_unserialize($event_row['event_meta']); |
|
| 231 | - $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null; |
|
| 232 | - $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this); |
|
| 233 | - |
|
| 234 | - // maybe create a venue from info on the event? |
|
| 235 | - $new_venue_id = $this->_maybe_create_venue($event_row); |
|
| 236 | - if ($new_venue_id) { |
|
| 237 | - $this->_insert_new_venue_to_event($post_id, $new_venue_id); |
|
| 238 | - } |
|
| 239 | - $this->_add_post_metas($event_row, $post_id); |
|
| 240 | - } |
|
| 241 | - $items_migrated_this_step++; |
|
| 242 | - if ($guid) { |
|
| 243 | - // if we had to check for an image attachment |
|
| 244 | - // then let's call it a day (avoid timing out, because this took a long time) |
|
| 245 | - break; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) { |
|
| 249 | - $this->set_status(EE_Data_Migration_Manager::status_completed); |
|
| 250 | - } |
|
| 251 | - return $items_migrated_this_step; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Stores any extra 3.1 "event_meta" column things as post meta |
|
| 256 | - * @param array $old_event |
|
| 257 | - * @param int $post_id |
|
| 258 | - * @return void |
|
| 259 | - */ |
|
| 260 | - private function _add_post_metas($old_event, $post_id) |
|
| 261 | - { |
|
| 262 | - $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 263 | - if (! $event_meta || ! is_array($event_meta)) { |
|
| 264 | - return; |
|
| 265 | - } |
|
| 266 | - unset($event_meta['date_submitted']);// factored into CPT |
|
| 267 | - unset($event_meta['additional_attendee_reg_info']);// factored into event meta table |
|
| 268 | - unset($event_meta['default_payment_status']);// dido |
|
| 269 | - unset($event_meta['event_thumbnail_url']);// used to find post featured image |
|
| 270 | - foreach ($event_meta as $meta_key => $meta_value) { |
|
| 271 | - if ($meta_key) {// if the meta key is just an empty string, ignore it |
|
| 272 | - $success = add_post_meta($post_id, $meta_key, $meta_value, true); |
|
| 273 | - if (! $success) { |
|
| 274 | - $this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event))); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - if ($old_event['alt_email']) { |
|
| 279 | - add_post_meta($post_id, 'alt_email', $old_event['alt_email']); |
|
| 280 | - } |
|
| 281 | - if ($old_event['recurrence_id']) { |
|
| 282 | - add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Finds a unique slug for this event, given its name (we could have simply used |
|
| 290 | - * the old unique_identifier column, but it added a long string of seemingly random characters onto the end |
|
| 291 | - * and really wasn't that pretty for a slug, so we decided we'd make our own slug again) |
|
| 292 | - * @param string $event_name (the name of the event for reading by humans) |
|
| 293 | - * @param string $old_identifier the old EE3 identifier (a long unique string) |
|
| 294 | - * @param string $new_post_status a post status |
|
| 295 | - * @return string |
|
| 296 | - */ |
|
| 297 | - private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish') |
|
| 298 | - { |
|
| 299 | - $count = 0; |
|
| 300 | - $original_name = $event_name ? sanitize_title($event_name) : $old_identifier; |
|
| 301 | - return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * returns whether or not there is a post that has this same slug (post_title) |
|
| 306 | - * @global wpdb $wpdb |
|
| 307 | - * @param string $slug |
|
| 308 | - * @return boolean |
|
| 309 | - */ |
|
| 310 | - private function _other_post_exists_with_that_slug($slug) |
|
| 311 | - { |
|
| 312 | - global $wpdb; |
|
| 313 | - $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug); |
|
| 314 | - $count = $wpdb->get_var($query); |
|
| 315 | - return (boolean) intval($count); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * @param $old_event |
|
| 322 | - * @return int |
|
| 323 | - */ |
|
| 324 | - private function _insert_cpt($old_event) |
|
| 325 | - { |
|
| 326 | - global $wpdb; |
|
| 327 | - // convert 3.1 event status to 4.1 CPT status |
|
| 328 | - // for reference, 3.1 event stati available for setting are: |
|
| 158 | + private $_old_table; |
|
| 159 | + private $_old_start_end_table; |
|
| 160 | + private $_new_table; |
|
| 161 | + private $_new_meta_table; |
|
| 162 | + private $_new_datetime_table; |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Just initializes the status of the migration |
|
| 168 | + * @throws EE_Error |
|
| 169 | + */ |
|
| 170 | + public function __construct() |
|
| 171 | + { |
|
| 172 | + global $wpdb; |
|
| 173 | + $this->_old_table = $wpdb->prefix."events_detail"; |
|
| 174 | + $this->_old_start_end_table = $wpdb->prefix."events_start_end"; |
|
| 175 | + $this->_new_table = $wpdb->prefix."posts"; |
|
| 176 | + $this->_new_meta_table = $wpdb->prefix."esp_event_meta"; |
|
| 177 | + $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 178 | + $this->_pretty_name = __("Events", "event_espresso"); |
|
| 179 | + parent::__construct(); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Counts the records to migrate; the public version may cache it |
|
| 186 | + * @return int |
|
| 187 | + */ |
|
| 188 | + public function _count_records_to_migrate() |
|
| 189 | + { |
|
| 190 | + global $wpdb; |
|
| 191 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table . ' WHERE event_status !="D"'); |
|
| 192 | + return intval($count); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly. |
|
| 199 | + * Note: it should not alter the count of items migrated. That is done in the public function that calls this. |
|
| 200 | + * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it |
|
| 201 | + * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50, |
|
| 202 | + * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated) |
|
| 203 | + * @param int $num_items_to_migrate |
|
| 204 | + * @return int number of items ACTUALLY migrated |
|
| 205 | + */ |
|
| 206 | + protected function _migration_step($num_items_to_migrate = 50) |
|
| 207 | + { |
|
| 208 | + global $wpdb; |
|
| 209 | + // because the migration of each event can be a LOT more work, make each step smaller |
|
| 210 | + $num_items_to_migrate = max(1, $num_items_to_migrate/5); |
|
| 211 | + $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A); |
|
| 212 | + $items_migrated_this_step = 0; |
|
| 213 | + |
|
| 214 | + foreach ($events as $event_row) { |
|
| 215 | + $guid = null; |
|
| 216 | + // insert new 4.1 Attendee object using $wpdb |
|
| 217 | + $post_id = $this->_insert_cpt($event_row); |
|
| 218 | + if ($post_id) { |
|
| 219 | + $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id); |
|
| 220 | + $meta_id = $this->_insert_event_meta($event_row, $post_id); |
|
| 221 | + if ($meta_id) { |
|
| 222 | + $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id); |
|
| 223 | + } |
|
| 224 | + $this->_convert_start_end_times($event_row, $post_id); |
|
| 225 | + $event_meta = maybe_unserialize($event_row['event_meta']); |
|
| 226 | + $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null; |
|
| 227 | + $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this); |
|
| 228 | + |
|
| 229 | + // maybe create a venue from info on the event? |
|
| 230 | + $new_venue_id = $this->_maybe_create_venue($event_row); |
|
| 231 | + if ($new_venue_id) { |
|
| 232 | + $this->_insert_new_venue_to_event($post_id, $new_venue_id); |
|
| 233 | + } |
|
| 234 | + $this->_add_post_metas($event_row, $post_id); |
|
| 235 | + } |
|
| 236 | + $items_migrated_this_step++; |
|
| 237 | + if ($guid) { |
|
| 238 | + // if we had to check for an image attachment |
|
| 239 | + // then let's call it a day (avoid timing out, because this took a long time) |
|
| 240 | + break; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) { |
|
| 244 | + $this->set_status(EE_Data_Migration_Manager::status_completed); |
|
| 245 | + } |
|
| 246 | + return $items_migrated_this_step; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Stores any extra 3.1 "event_meta" column things as post meta |
|
| 251 | + * @param array $old_event |
|
| 252 | + * @param int $post_id |
|
| 253 | + * @return void |
|
| 254 | + */ |
|
| 255 | + private function _add_post_metas($old_event, $post_id) |
|
| 256 | + { |
|
| 257 | + $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 258 | + if (! $event_meta || ! is_array($event_meta)) { |
|
| 259 | + return; |
|
| 260 | + } |
|
| 261 | + unset($event_meta['date_submitted']);// factored into CPT |
|
| 262 | + unset($event_meta['additional_attendee_reg_info']);// factored into event meta table |
|
| 263 | + unset($event_meta['default_payment_status']);// dido |
|
| 264 | + unset($event_meta['event_thumbnail_url']);// used to find post featured image |
|
| 265 | + foreach ($event_meta as $meta_key => $meta_value) { |
|
| 266 | + if ($meta_key) {// if the meta key is just an empty string, ignore it |
|
| 267 | + $success = add_post_meta($post_id, $meta_key, $meta_value, true); |
|
| 268 | + if (! $success) { |
|
| 269 | + $this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event))); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + if ($old_event['alt_email']) { |
|
| 274 | + add_post_meta($post_id, 'alt_email', $old_event['alt_email']); |
|
| 275 | + } |
|
| 276 | + if ($old_event['recurrence_id']) { |
|
| 277 | + add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Finds a unique slug for this event, given its name (we could have simply used |
|
| 285 | + * the old unique_identifier column, but it added a long string of seemingly random characters onto the end |
|
| 286 | + * and really wasn't that pretty for a slug, so we decided we'd make our own slug again) |
|
| 287 | + * @param string $event_name (the name of the event for reading by humans) |
|
| 288 | + * @param string $old_identifier the old EE3 identifier (a long unique string) |
|
| 289 | + * @param string $new_post_status a post status |
|
| 290 | + * @return string |
|
| 291 | + */ |
|
| 292 | + private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish') |
|
| 293 | + { |
|
| 294 | + $count = 0; |
|
| 295 | + $original_name = $event_name ? sanitize_title($event_name) : $old_identifier; |
|
| 296 | + return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * returns whether or not there is a post that has this same slug (post_title) |
|
| 301 | + * @global wpdb $wpdb |
|
| 302 | + * @param string $slug |
|
| 303 | + * @return boolean |
|
| 304 | + */ |
|
| 305 | + private function _other_post_exists_with_that_slug($slug) |
|
| 306 | + { |
|
| 307 | + global $wpdb; |
|
| 308 | + $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug); |
|
| 309 | + $count = $wpdb->get_var($query); |
|
| 310 | + return (boolean) intval($count); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * @param $old_event |
|
| 317 | + * @return int |
|
| 318 | + */ |
|
| 319 | + private function _insert_cpt($old_event) |
|
| 320 | + { |
|
| 321 | + global $wpdb; |
|
| 322 | + // convert 3.1 event status to 4.1 CPT status |
|
| 323 | + // for reference, 3.1 event stati available for setting are: |
|
| 329 | 324 | // $status = array(array('id' => 'A', 'text' => __('Public', 'event_espresso')), array('id' => 'S', 'text' => __('Waitlist', 'event_espresso')), array('id' => 'O', 'text' => __('Ongoing', 'event_espresso')), array('id' => 'R', 'text' => __('Draft', 'event_espresso')), array('id' => 'D', 'text' => __('Deleted', 'event_espresso'))); |
| 330 | 325 | // and the json api uses the following to convert from 3.1 to 4.0 |
| 331 | 326 | // 'S'=>'secondary/waitlist', |
@@ -339,486 +334,486 @@ discard block |
||
| 339 | 334 | // 4.1 Event Post stati are the normal post statis |
| 340 | 335 | // (publish,future,draft,pending,private,trash,auto-draft,inherit) |
| 341 | 336 | // and 3 custom ones: cancelled,postponed,sold_out |
| 342 | - $status_conversions = array( |
|
| 343 | - 'R'=>'draft', |
|
| 344 | - 'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 345 | - 'P'=>'pending', |
|
| 346 | - 'IA'=>'draft',// draft and in the past |
|
| 337 | + $status_conversions = array( |
|
| 338 | + 'R'=>'draft', |
|
| 339 | + 'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 340 | + 'P'=>'pending', |
|
| 341 | + 'IA'=>'draft',// draft and in the past |
|
| 347 | 342 | // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated |
| 348 | - 'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 349 | - 'A'=>'publish', |
|
| 350 | - 'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 351 | - 'D'=>'trash', |
|
| 352 | - ); |
|
| 353 | - $post_status = $status_conversions[ $old_event['event_status'] ]; |
|
| 354 | - // check if we've sold out |
|
| 355 | - if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) { |
|
| 356 | - $post_status = 'sold_out'; |
|
| 357 | - } |
|
| 343 | + 'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 344 | + 'A'=>'publish', |
|
| 345 | + 'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 346 | + 'D'=>'trash', |
|
| 347 | + ); |
|
| 348 | + $post_status = $status_conversions[ $old_event['event_status'] ]; |
|
| 349 | + // check if we've sold out |
|
| 350 | + if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) { |
|
| 351 | + $post_status = 'sold_out'; |
|
| 352 | + } |
|
| 358 | 353 | // FYI postponed and cancelled don't exist in 3.1 |
| 359 | - $cols_n_values = array( |
|
| 360 | - 'post_title'=>stripslashes($old_event['event_name']),// EVT_name |
|
| 361 | - 'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc |
|
| 362 | - 'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug |
|
| 363 | - 'post_date'=>$old_event['submitted'],// EVT_created NOT |
|
| 364 | - 'post_date_gmt'=>get_gmt_from_date($old_event['submitted']), |
|
| 365 | - 'post_excerpt'=>'',// EVT_short_desc |
|
| 366 | - 'post_modified'=>$old_event['submitted'],// EVT_modified |
|
| 367 | - 'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']), |
|
| 368 | - 'post_author'=>$old_event['wp_user'],// EVT_wp_user |
|
| 369 | - 'post_parent'=>0,// parent maybe get this from some REM field? |
|
| 370 | - 'menu_order'=>0,// EVT_order |
|
| 371 | - 'post_type'=>'espresso_events',// post_type |
|
| 372 | - 'post_status'=>$post_status,// status |
|
| 373 | - ); |
|
| 374 | - $cols_n_values_with_no_invalid_text = array(); |
|
| 375 | - foreach ($cols_n_values as $col => $value) { |
|
| 376 | - $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value); |
|
| 377 | - if (! is_wp_error($value_sans_invalid_chars)) { |
|
| 378 | - $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars; |
|
| 379 | - } else { |
|
| 380 | - // otherwise leave it as-is. It will blow everything up and stop the migration |
|
| 381 | - $cols_n_values_with_no_invalid_text[ $col ] = $value; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - $cols_n_values = $cols_n_values_with_no_invalid_text; |
|
| 385 | - $datatypes = array( |
|
| 386 | - '%s',// EVT_name |
|
| 387 | - '%s',// EVT_desc |
|
| 388 | - '%s',// EVT_slug |
|
| 389 | - '%s',// EVT_created |
|
| 390 | - '%s', |
|
| 391 | - '%s',// EVT_short_desc |
|
| 392 | - '%s',// EVT_modified |
|
| 393 | - '%s', |
|
| 394 | - '%s',// EVT_wp_user |
|
| 395 | - '%d',// post_parent |
|
| 396 | - '%d',// EVT_order |
|
| 397 | - '%s',// post_type |
|
| 398 | - '%s',// status |
|
| 399 | - ); |
|
| 400 | - $success = $wpdb->insert( |
|
| 401 | - $this->_new_table, |
|
| 402 | - $cols_n_values, |
|
| 403 | - $datatypes |
|
| 404 | - ); |
|
| 405 | - if (! $success) { |
|
| 406 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 407 | - return 0; |
|
| 408 | - } |
|
| 409 | - return $wpdb->insert_id; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations) |
|
| 414 | - * @global wpdb $wpdb |
|
| 415 | - * @param int $event_id |
|
| 416 | - * @return int |
|
| 417 | - */ |
|
| 418 | - public static function count_registrations($event_id) |
|
| 419 | - { |
|
| 420 | - global $wpdb; |
|
| 421 | - $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id)); |
|
| 422 | - return intval($count); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @param $old_event |
|
| 429 | - * @param $new_cpt_id |
|
| 430 | - * @return int |
|
| 431 | - */ |
|
| 432 | - private function _insert_event_meta($old_event, $new_cpt_id) |
|
| 433 | - { |
|
| 434 | - global $wpdb; |
|
| 435 | - $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 354 | + $cols_n_values = array( |
|
| 355 | + 'post_title'=>stripslashes($old_event['event_name']),// EVT_name |
|
| 356 | + 'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc |
|
| 357 | + 'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug |
|
| 358 | + 'post_date'=>$old_event['submitted'],// EVT_created NOT |
|
| 359 | + 'post_date_gmt'=>get_gmt_from_date($old_event['submitted']), |
|
| 360 | + 'post_excerpt'=>'',// EVT_short_desc |
|
| 361 | + 'post_modified'=>$old_event['submitted'],// EVT_modified |
|
| 362 | + 'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']), |
|
| 363 | + 'post_author'=>$old_event['wp_user'],// EVT_wp_user |
|
| 364 | + 'post_parent'=>0,// parent maybe get this from some REM field? |
|
| 365 | + 'menu_order'=>0,// EVT_order |
|
| 366 | + 'post_type'=>'espresso_events',// post_type |
|
| 367 | + 'post_status'=>$post_status,// status |
|
| 368 | + ); |
|
| 369 | + $cols_n_values_with_no_invalid_text = array(); |
|
| 370 | + foreach ($cols_n_values as $col => $value) { |
|
| 371 | + $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value); |
|
| 372 | + if (! is_wp_error($value_sans_invalid_chars)) { |
|
| 373 | + $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars; |
|
| 374 | + } else { |
|
| 375 | + // otherwise leave it as-is. It will blow everything up and stop the migration |
|
| 376 | + $cols_n_values_with_no_invalid_text[ $col ] = $value; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + $cols_n_values = $cols_n_values_with_no_invalid_text; |
|
| 380 | + $datatypes = array( |
|
| 381 | + '%s',// EVT_name |
|
| 382 | + '%s',// EVT_desc |
|
| 383 | + '%s',// EVT_slug |
|
| 384 | + '%s',// EVT_created |
|
| 385 | + '%s', |
|
| 386 | + '%s',// EVT_short_desc |
|
| 387 | + '%s',// EVT_modified |
|
| 388 | + '%s', |
|
| 389 | + '%s',// EVT_wp_user |
|
| 390 | + '%d',// post_parent |
|
| 391 | + '%d',// EVT_order |
|
| 392 | + '%s',// post_type |
|
| 393 | + '%s',// status |
|
| 394 | + ); |
|
| 395 | + $success = $wpdb->insert( |
|
| 396 | + $this->_new_table, |
|
| 397 | + $cols_n_values, |
|
| 398 | + $datatypes |
|
| 399 | + ); |
|
| 400 | + if (! $success) { |
|
| 401 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 402 | + return 0; |
|
| 403 | + } |
|
| 404 | + return $wpdb->insert_id; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations) |
|
| 409 | + * @global wpdb $wpdb |
|
| 410 | + * @param int $event_id |
|
| 411 | + * @return int |
|
| 412 | + */ |
|
| 413 | + public static function count_registrations($event_id) |
|
| 414 | + { |
|
| 415 | + global $wpdb; |
|
| 416 | + $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id)); |
|
| 417 | + return intval($count); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * @param $old_event |
|
| 424 | + * @param $new_cpt_id |
|
| 425 | + * @return int |
|
| 426 | + */ |
|
| 427 | + private function _insert_event_meta($old_event, $new_cpt_id) |
|
| 428 | + { |
|
| 429 | + global $wpdb; |
|
| 430 | + $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 436 | 431 | // for reference, 3.1 'default_payment_status' are: $default_payment_status = array( |
| 437 | 432 | // array('id' => "", 'text' => 'No Change'), |
| 438 | 433 | // array('id' => 'Incomplete', 'text' => 'Incomplete'), |
| 439 | 434 | // array('id' => 'Pending', 'text' => 'Pending'), |
| 440 | 435 | // //array('id' => 'Completed', 'text' => 'Completed') |
| 441 | 436 | // ); |
| 442 | - $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval'])); |
|
| 443 | - $cols_n_values = array( |
|
| 444 | - 'EVT_ID'=>$new_cpt_id,// EVT_ID_fk |
|
| 445 | - 'EVT_display_desc'=> 'Y' == $old_event['display_desc'], |
|
| 446 | - 'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'], |
|
| 447 | - 'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used |
|
| 448 | - 'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'], |
|
| 449 | - 'EVT_default_registration_status' => $default_reg_status, |
|
| 450 | - 'EVT_member_only'=>$old_event['member_only'], |
|
| 451 | - 'EVT_phone'=> $old_event['phone'], |
|
| 452 | - 'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'], |
|
| 453 | - 'EVT_timezone_string'=> $old_event['timezone_string'], |
|
| 454 | - 'EVT_external_URL'=>$old_event['externalURL'], |
|
| 455 | - 'EVT_donations'=>false// doesnt exist in 3.1 |
|
| 456 | - |
|
| 457 | - ); |
|
| 458 | - $datatypes = array( |
|
| 459 | - '%s',// EVT_ID |
|
| 460 | - '%d',// EVT_display_desc |
|
| 461 | - '%d',// EVT_display_ticket_selector |
|
| 462 | - '%s',// EVT_visible_on |
|
| 463 | - '%d',// EVT_additional_limit |
|
| 464 | - '%s',// EVT_default_registration_status |
|
| 465 | - '%d',// EVT_member_only |
|
| 466 | - '%s',// EVT_phone |
|
| 467 | - '%d',// EVT_allow_overflow |
|
| 468 | - '%s',// EVT_timezone_string |
|
| 469 | - '%s',// EVT_external_URL |
|
| 470 | - '%d',// EVT_donations |
|
| 471 | - ); |
|
| 472 | - $success = $wpdb->insert( |
|
| 473 | - $this->_new_meta_table, |
|
| 474 | - $cols_n_values, |
|
| 475 | - $datatypes |
|
| 476 | - ); |
|
| 477 | - if (! $success) { |
|
| 478 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes)); |
|
| 479 | - return 0; |
|
| 480 | - } |
|
| 481 | - return $wpdb->insert_id; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @param $old_event |
|
| 488 | - * @return int |
|
| 489 | - */ |
|
| 490 | - private function _maybe_create_venue($old_event) |
|
| 491 | - { |
|
| 492 | - if ($old_event['address'] || |
|
| 493 | - $old_event['address2'] || |
|
| 494 | - $old_event['city'] || |
|
| 495 | - $old_event['state'] || |
|
| 496 | - $old_event['zip'] || |
|
| 497 | - $old_event['venue_title'] || |
|
| 498 | - $old_event['venue_url'] || |
|
| 499 | - $old_event['venue_image'] || |
|
| 500 | - $old_event['venue_phone'] || |
|
| 501 | - $old_event['virtual_url'] || |
|
| 502 | - $old_event['virtual_phone'] |
|
| 503 | - ) { |
|
| 504 | - $old_id = $this->_duplicate_venue_exists($old_event); |
|
| 505 | - if ($old_id) { |
|
| 506 | - return $old_id; |
|
| 507 | - } |
|
| 508 | - $new_id = $this->_insert_venue_into_posts($old_event); |
|
| 509 | - if ($new_id) { |
|
| 510 | - $this->_insert_venue_into_meta_table($new_id, $old_event); |
|
| 511 | - $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 512 | - $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
|
| 513 | - } |
|
| 514 | - // we don't bother recording the conversion from old events to venues as that |
|
| 515 | - // will complicate finding the conversion from old venues to new events |
|
| 516 | - return $new_id; |
|
| 517 | - } else { |
|
| 518 | - return 0; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it. |
|
| 524 | - * If so, return it. Otherwise return NULL. |
|
| 525 | - * @param array $old_event |
|
| 526 | - * @return int duplicate venue id |
|
| 527 | - */ |
|
| 528 | - private function _duplicate_venue_exists($old_event) |
|
| 529 | - { |
|
| 530 | - global $wpdb; |
|
| 531 | - $conditions = array( |
|
| 532 | - 'VNU_address' => $old_event ['address'], |
|
| 533 | - 'VNU_address2' => $old_event['address2'], |
|
| 534 | - 'VNU_city' => $old_event['city'], |
|
| 535 | - 'VNU_zip' => $old_event['zip'], |
|
| 536 | - 'post_title'=> $this->_get_venue_title_for_event($old_event), |
|
| 537 | - 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 538 | - 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 539 | - 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 540 | - 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 541 | - ); |
|
| 542 | - $sql_conditions = array(); |
|
| 543 | - foreach ($conditions as $column => $value) { |
|
| 544 | - $sql_conditions [] = $wpdb->prepare("$column = %s", $value); |
|
| 545 | - } |
|
| 546 | - $query = "SELECT VNU_ID |
|
| 437 | + $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval'])); |
|
| 438 | + $cols_n_values = array( |
|
| 439 | + 'EVT_ID'=>$new_cpt_id,// EVT_ID_fk |
|
| 440 | + 'EVT_display_desc'=> 'Y' == $old_event['display_desc'], |
|
| 441 | + 'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'], |
|
| 442 | + 'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used |
|
| 443 | + 'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'], |
|
| 444 | + 'EVT_default_registration_status' => $default_reg_status, |
|
| 445 | + 'EVT_member_only'=>$old_event['member_only'], |
|
| 446 | + 'EVT_phone'=> $old_event['phone'], |
|
| 447 | + 'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'], |
|
| 448 | + 'EVT_timezone_string'=> $old_event['timezone_string'], |
|
| 449 | + 'EVT_external_URL'=>$old_event['externalURL'], |
|
| 450 | + 'EVT_donations'=>false// doesnt exist in 3.1 |
|
| 451 | + |
|
| 452 | + ); |
|
| 453 | + $datatypes = array( |
|
| 454 | + '%s',// EVT_ID |
|
| 455 | + '%d',// EVT_display_desc |
|
| 456 | + '%d',// EVT_display_ticket_selector |
|
| 457 | + '%s',// EVT_visible_on |
|
| 458 | + '%d',// EVT_additional_limit |
|
| 459 | + '%s',// EVT_default_registration_status |
|
| 460 | + '%d',// EVT_member_only |
|
| 461 | + '%s',// EVT_phone |
|
| 462 | + '%d',// EVT_allow_overflow |
|
| 463 | + '%s',// EVT_timezone_string |
|
| 464 | + '%s',// EVT_external_URL |
|
| 465 | + '%d',// EVT_donations |
|
| 466 | + ); |
|
| 467 | + $success = $wpdb->insert( |
|
| 468 | + $this->_new_meta_table, |
|
| 469 | + $cols_n_values, |
|
| 470 | + $datatypes |
|
| 471 | + ); |
|
| 472 | + if (! $success) { |
|
| 473 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes)); |
|
| 474 | + return 0; |
|
| 475 | + } |
|
| 476 | + return $wpdb->insert_id; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @param $old_event |
|
| 483 | + * @return int |
|
| 484 | + */ |
|
| 485 | + private function _maybe_create_venue($old_event) |
|
| 486 | + { |
|
| 487 | + if ($old_event['address'] || |
|
| 488 | + $old_event['address2'] || |
|
| 489 | + $old_event['city'] || |
|
| 490 | + $old_event['state'] || |
|
| 491 | + $old_event['zip'] || |
|
| 492 | + $old_event['venue_title'] || |
|
| 493 | + $old_event['venue_url'] || |
|
| 494 | + $old_event['venue_image'] || |
|
| 495 | + $old_event['venue_phone'] || |
|
| 496 | + $old_event['virtual_url'] || |
|
| 497 | + $old_event['virtual_phone'] |
|
| 498 | + ) { |
|
| 499 | + $old_id = $this->_duplicate_venue_exists($old_event); |
|
| 500 | + if ($old_id) { |
|
| 501 | + return $old_id; |
|
| 502 | + } |
|
| 503 | + $new_id = $this->_insert_venue_into_posts($old_event); |
|
| 504 | + if ($new_id) { |
|
| 505 | + $this->_insert_venue_into_meta_table($new_id, $old_event); |
|
| 506 | + $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 507 | + $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
|
| 508 | + } |
|
| 509 | + // we don't bother recording the conversion from old events to venues as that |
|
| 510 | + // will complicate finding the conversion from old venues to new events |
|
| 511 | + return $new_id; |
|
| 512 | + } else { |
|
| 513 | + return 0; |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it. |
|
| 519 | + * If so, return it. Otherwise return NULL. |
|
| 520 | + * @param array $old_event |
|
| 521 | + * @return int duplicate venue id |
|
| 522 | + */ |
|
| 523 | + private function _duplicate_venue_exists($old_event) |
|
| 524 | + { |
|
| 525 | + global $wpdb; |
|
| 526 | + $conditions = array( |
|
| 527 | + 'VNU_address' => $old_event ['address'], |
|
| 528 | + 'VNU_address2' => $old_event['address2'], |
|
| 529 | + 'VNU_city' => $old_event['city'], |
|
| 530 | + 'VNU_zip' => $old_event['zip'], |
|
| 531 | + 'post_title'=> $this->_get_venue_title_for_event($old_event), |
|
| 532 | + 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 533 | + 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 534 | + 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 535 | + 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 536 | + ); |
|
| 537 | + $sql_conditions = array(); |
|
| 538 | + foreach ($conditions as $column => $value) { |
|
| 539 | + $sql_conditions [] = $wpdb->prepare("$column = %s", $value); |
|
| 540 | + } |
|
| 541 | + $query = "SELECT VNU_ID |
|
| 547 | 542 | FROM |
| 548 | 543 | {$wpdb->posts} as p INNER JOIN |
| 549 | 544 | {$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID |
| 550 | 545 | WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1"; |
| 551 | - $id = $wpdb->get_var($query); |
|
| 552 | - return $id; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Gets teh venue's title or makes one up if there is none |
|
| 557 | - * @param array $event_data_array keys are events_details columns and values are their values |
|
| 558 | - * @return string |
|
| 559 | - */ |
|
| 560 | - protected function _get_venue_title_for_event($event_data_array) |
|
| 561 | - { |
|
| 562 | - return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(__('Venue of %s', 'event_espresso'), $event_data_array['event_name'])); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Inserts the CPT |
|
| 567 | - * |
|
| 568 | - * @param array $old_event keys are cols, values are col values |
|
| 569 | - * @return int |
|
| 570 | - */ |
|
| 571 | - private function _insert_venue_into_posts($old_event) |
|
| 572 | - { |
|
| 573 | - global $wpdb; |
|
| 574 | - $insertion_array = array( |
|
| 575 | - 'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name |
|
| 576 | - 'post_content'=>'',// VNU_desc |
|
| 577 | - 'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier |
|
| 578 | - 'post_date'=>current_time('mysql'),// VNU_created |
|
| 579 | - 'post_date_gmt'=>get_gmt_from_date(current_time('mysql')), |
|
| 580 | - 'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters |
|
| 581 | - 'post_modified'=>current_time('mysql'),// VNU_modified |
|
| 582 | - 'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')), |
|
| 583 | - 'post_author'=>$old_event['wp_user'],// VNU_wp_user |
|
| 584 | - 'post_parent'=>0,// parent |
|
| 585 | - 'menu_order'=>0,// VNU_order |
|
| 586 | - 'post_type'=>'espresso_venues'// post_type |
|
| 587 | - ); |
|
| 588 | - $datatypes_array = array( |
|
| 589 | - '%s',// VNU_name |
|
| 590 | - '%s',// VNU_desc |
|
| 591 | - '%s',// VNU_identifier |
|
| 592 | - '%s',// VNU_created |
|
| 593 | - '%s', |
|
| 594 | - '%s',// VNU_short_desc |
|
| 595 | - '%s',// VNU_modified |
|
| 596 | - '%s', |
|
| 597 | - '%d',// VNU_wp_user |
|
| 598 | - '%d',// parent |
|
| 599 | - '%d',// VNU_order |
|
| 600 | - '%s',// post_type |
|
| 601 | - ); |
|
| 602 | - $success = $wpdb->insert( |
|
| 603 | - $wpdb->posts, |
|
| 604 | - $insertion_array, |
|
| 605 | - $datatypes_array |
|
| 606 | - ); |
|
| 607 | - if (! $success) { |
|
| 608 | - $this->add_error( |
|
| 609 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 610 | - $this->_old_table, |
|
| 611 | - $old_event, |
|
| 612 | - $this->_new_table, |
|
| 613 | - $insertion_array, |
|
| 614 | - $datatypes_array |
|
| 615 | - ) |
|
| 616 | - ); |
|
| 617 | - return 0; |
|
| 618 | - } |
|
| 619 | - return $wpdb->insert_id; |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * Inserts into the venue_meta table |
|
| 624 | - * @param int $cpt_id |
|
| 625 | - * @param array $old_event |
|
| 626 | - * @return int |
|
| 627 | - */ |
|
| 628 | - private function _insert_venue_into_meta_table($cpt_id, $old_event) |
|
| 629 | - { |
|
| 630 | - global $wpdb; |
|
| 631 | - |
|
| 632 | - // assume the country is the same as the organization's old settings |
|
| 633 | - $country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
| 634 | - // find the state from the venue, or the organization, or just guess california |
|
| 635 | - if (! $old_event['state']) { |
|
| 636 | - $old_org_options = get_option('events_organization_settings'); |
|
| 637 | - $state_name = stripslashes($old_org_options['organization_state']); |
|
| 638 | - } else { |
|
| 639 | - $state_name = $old_event['state']; |
|
| 640 | - } |
|
| 641 | - if (! $state_name) { |
|
| 642 | - $state_name = 'CA'; |
|
| 643 | - } |
|
| 644 | - // get a state ID with the same name, if possible |
|
| 645 | - try { |
|
| 646 | - $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso); |
|
| 647 | - $state_id = $state['STA_ID']; |
|
| 648 | - } catch (EE_Error $e) { |
|
| 649 | - $this->add_error($e->getMessage()); |
|
| 650 | - $state_id = 0; |
|
| 651 | - } |
|
| 652 | - // now insert into meta table |
|
| 653 | - $insertion_array = array( |
|
| 654 | - 'VNU_ID'=>$cpt_id,// VNU_ID_fk |
|
| 655 | - 'VNU_address'=>stripslashes($old_event['address']),// VNU_address |
|
| 656 | - 'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2 |
|
| 657 | - 'VNU_city'=>stripslashes($old_event['city']),// VNU_city |
|
| 658 | - 'STA_ID'=>$state_id,// STA_ID |
|
| 659 | - 'CNT_ISO'=>$country_iso,// CNT_ISO |
|
| 660 | - 'VNU_zip'=>$old_event['zip'],// VNU_zip |
|
| 661 | - 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 662 | - 'VNU_capacity'=>-1,// VNU_capacity |
|
| 663 | - 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 664 | - 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 665 | - 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 666 | - 'VNU_google_map_link'=>'',// VNU_google_map_link |
|
| 667 | - 'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap |
|
| 668 | - ); |
|
| 669 | - $datatypes = array( |
|
| 670 | - '%d',// VNU_ID_fk |
|
| 671 | - '%s',// VNU_address |
|
| 672 | - '%s',// VNU_address2 |
|
| 673 | - '%s',// VNU_city |
|
| 674 | - '%d',// STA_ID |
|
| 675 | - '%s',// CNT_ISO |
|
| 676 | - '%s',// VNU_zip |
|
| 677 | - '%s',// VNU_phone |
|
| 678 | - '%d',// VNU_capacity |
|
| 679 | - '%s',// VNU_url |
|
| 680 | - '%s',// VNU_virtual_phone |
|
| 681 | - '%s',// VNU_virtual_url |
|
| 682 | - '%s',// VNU_google_map_link |
|
| 683 | - '%d',// VNU_enable_for_gmap |
|
| 684 | - ); |
|
| 685 | - $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes); |
|
| 686 | - if (! $success) { |
|
| 687 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes)); |
|
| 688 | - return 0; |
|
| 689 | - } |
|
| 690 | - return $wpdb->insert_id; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * @param $new_event_id |
|
| 697 | - * @param $new_venue_id |
|
| 698 | - * @return int |
|
| 699 | - */ |
|
| 700 | - private function _insert_new_venue_to_event($new_event_id, $new_venue_id) |
|
| 701 | - { |
|
| 702 | - global $wpdb; |
|
| 703 | - if (! $new_event_id) { |
|
| 704 | - $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id)); |
|
| 705 | - return 0; |
|
| 706 | - } |
|
| 707 | - if (! $new_venue_id) { |
|
| 708 | - $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id)); |
|
| 709 | - return 0; |
|
| 710 | - } |
|
| 711 | - $cols_n_values = array( |
|
| 712 | - 'EVT_ID'=>$new_event_id, |
|
| 713 | - 'VNU_ID'=>$new_venue_id, |
|
| 714 | - 'EVV_primary'=>true |
|
| 715 | - ); |
|
| 716 | - $datatypes = array( |
|
| 717 | - '%d',// EVT_ID |
|
| 718 | - '%d',// VNU_ID |
|
| 719 | - '%d',// EVT_primary |
|
| 720 | - ); |
|
| 721 | - $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes); |
|
| 722 | - if (! $success) { |
|
| 723 | - $this->add_error( |
|
| 724 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 725 | - $this->_old_table, |
|
| 726 | - array(), |
|
| 727 | - $this->_new_table, |
|
| 728 | - $cols_n_values, |
|
| 729 | - $datatypes |
|
| 730 | - ) |
|
| 731 | - ); |
|
| 732 | - return 0; |
|
| 733 | - } |
|
| 734 | - return $wpdb->insert_id; |
|
| 735 | - } |
|
| 736 | - /** |
|
| 737 | - * Converts all the 3.1 start-end times for the event to 4.1 datetimes |
|
| 738 | - * @global wpdb $wpdb |
|
| 739 | - * @param array $old_event results of get_results(...,ARRAY_A) |
|
| 740 | - * @param int $new_cpt_id new post ID |
|
| 741 | - * @return void (if there are errors though, adds them to the stage's error list |
|
| 742 | - */ |
|
| 743 | - private function _convert_start_end_times($old_event, $new_cpt_id) |
|
| 744 | - { |
|
| 745 | - $start_end_times = $this->_get_old_start_end_times($old_event['id']); |
|
| 746 | - foreach ($start_end_times as $start_end_time) { |
|
| 747 | - $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id); |
|
| 748 | - if ($datetime_id) { |
|
| 749 | - $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id); |
|
| 750 | - } |
|
| 751 | - } |
|
| 752 | - } |
|
| 753 | - /** |
|
| 754 | - * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event |
|
| 755 | - * @global wpdb $wpdb |
|
| 756 | - * @param int $old_event_id |
|
| 757 | - * @return array |
|
| 758 | - */ |
|
| 759 | - private function _get_old_start_end_times($old_event_id) |
|
| 760 | - { |
|
| 761 | - global $wpdb; |
|
| 762 | - return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A); |
|
| 763 | - } |
|
| 764 | - /** |
|
| 765 | - * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row |
|
| 766 | - * @param array $start_end_time_row |
|
| 767 | - * @param array $old_event_row |
|
| 768 | - * @param int $new_cpt_id |
|
| 769 | - * @return int ID of new datetime |
|
| 770 | - */ |
|
| 771 | - private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id) |
|
| 772 | - { |
|
| 773 | - global $wpdb; |
|
| 774 | - $start_date = $old_event_row['start_date']; |
|
| 775 | - $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']); |
|
| 776 | - $end_date = $old_event_row['end_date']; |
|
| 777 | - $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']); |
|
| 778 | - $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id); |
|
| 779 | - $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']); |
|
| 780 | - $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']); |
|
| 781 | - $cols_n_values = array( |
|
| 782 | - 'EVT_ID'=>$new_cpt_id,// EVT_ID |
|
| 783 | - 'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start |
|
| 784 | - 'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end |
|
| 785 | - 'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit |
|
| 786 | - 'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration |
|
| 546 | + $id = $wpdb->get_var($query); |
|
| 547 | + return $id; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * Gets teh venue's title or makes one up if there is none |
|
| 552 | + * @param array $event_data_array keys are events_details columns and values are their values |
|
| 553 | + * @return string |
|
| 554 | + */ |
|
| 555 | + protected function _get_venue_title_for_event($event_data_array) |
|
| 556 | + { |
|
| 557 | + return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(__('Venue of %s', 'event_espresso'), $event_data_array['event_name'])); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Inserts the CPT |
|
| 562 | + * |
|
| 563 | + * @param array $old_event keys are cols, values are col values |
|
| 564 | + * @return int |
|
| 565 | + */ |
|
| 566 | + private function _insert_venue_into_posts($old_event) |
|
| 567 | + { |
|
| 568 | + global $wpdb; |
|
| 569 | + $insertion_array = array( |
|
| 570 | + 'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name |
|
| 571 | + 'post_content'=>'',// VNU_desc |
|
| 572 | + 'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier |
|
| 573 | + 'post_date'=>current_time('mysql'),// VNU_created |
|
| 574 | + 'post_date_gmt'=>get_gmt_from_date(current_time('mysql')), |
|
| 575 | + 'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters |
|
| 576 | + 'post_modified'=>current_time('mysql'),// VNU_modified |
|
| 577 | + 'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')), |
|
| 578 | + 'post_author'=>$old_event['wp_user'],// VNU_wp_user |
|
| 579 | + 'post_parent'=>0,// parent |
|
| 580 | + 'menu_order'=>0,// VNU_order |
|
| 581 | + 'post_type'=>'espresso_venues'// post_type |
|
| 582 | + ); |
|
| 583 | + $datatypes_array = array( |
|
| 584 | + '%s',// VNU_name |
|
| 585 | + '%s',// VNU_desc |
|
| 586 | + '%s',// VNU_identifier |
|
| 587 | + '%s',// VNU_created |
|
| 588 | + '%s', |
|
| 589 | + '%s',// VNU_short_desc |
|
| 590 | + '%s',// VNU_modified |
|
| 591 | + '%s', |
|
| 592 | + '%d',// VNU_wp_user |
|
| 593 | + '%d',// parent |
|
| 594 | + '%d',// VNU_order |
|
| 595 | + '%s',// post_type |
|
| 596 | + ); |
|
| 597 | + $success = $wpdb->insert( |
|
| 598 | + $wpdb->posts, |
|
| 599 | + $insertion_array, |
|
| 600 | + $datatypes_array |
|
| 601 | + ); |
|
| 602 | + if (! $success) { |
|
| 603 | + $this->add_error( |
|
| 604 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 605 | + $this->_old_table, |
|
| 606 | + $old_event, |
|
| 607 | + $this->_new_table, |
|
| 608 | + $insertion_array, |
|
| 609 | + $datatypes_array |
|
| 610 | + ) |
|
| 611 | + ); |
|
| 612 | + return 0; |
|
| 613 | + } |
|
| 614 | + return $wpdb->insert_id; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Inserts into the venue_meta table |
|
| 619 | + * @param int $cpt_id |
|
| 620 | + * @param array $old_event |
|
| 621 | + * @return int |
|
| 622 | + */ |
|
| 623 | + private function _insert_venue_into_meta_table($cpt_id, $old_event) |
|
| 624 | + { |
|
| 625 | + global $wpdb; |
|
| 626 | + |
|
| 627 | + // assume the country is the same as the organization's old settings |
|
| 628 | + $country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
| 629 | + // find the state from the venue, or the organization, or just guess california |
|
| 630 | + if (! $old_event['state']) { |
|
| 631 | + $old_org_options = get_option('events_organization_settings'); |
|
| 632 | + $state_name = stripslashes($old_org_options['organization_state']); |
|
| 633 | + } else { |
|
| 634 | + $state_name = $old_event['state']; |
|
| 635 | + } |
|
| 636 | + if (! $state_name) { |
|
| 637 | + $state_name = 'CA'; |
|
| 638 | + } |
|
| 639 | + // get a state ID with the same name, if possible |
|
| 640 | + try { |
|
| 641 | + $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso); |
|
| 642 | + $state_id = $state['STA_ID']; |
|
| 643 | + } catch (EE_Error $e) { |
|
| 644 | + $this->add_error($e->getMessage()); |
|
| 645 | + $state_id = 0; |
|
| 646 | + } |
|
| 647 | + // now insert into meta table |
|
| 648 | + $insertion_array = array( |
|
| 649 | + 'VNU_ID'=>$cpt_id,// VNU_ID_fk |
|
| 650 | + 'VNU_address'=>stripslashes($old_event['address']),// VNU_address |
|
| 651 | + 'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2 |
|
| 652 | + 'VNU_city'=>stripslashes($old_event['city']),// VNU_city |
|
| 653 | + 'STA_ID'=>$state_id,// STA_ID |
|
| 654 | + 'CNT_ISO'=>$country_iso,// CNT_ISO |
|
| 655 | + 'VNU_zip'=>$old_event['zip'],// VNU_zip |
|
| 656 | + 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 657 | + 'VNU_capacity'=>-1,// VNU_capacity |
|
| 658 | + 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 659 | + 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 660 | + 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 661 | + 'VNU_google_map_link'=>'',// VNU_google_map_link |
|
| 662 | + 'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap |
|
| 663 | + ); |
|
| 664 | + $datatypes = array( |
|
| 665 | + '%d',// VNU_ID_fk |
|
| 666 | + '%s',// VNU_address |
|
| 667 | + '%s',// VNU_address2 |
|
| 668 | + '%s',// VNU_city |
|
| 669 | + '%d',// STA_ID |
|
| 670 | + '%s',// CNT_ISO |
|
| 671 | + '%s',// VNU_zip |
|
| 672 | + '%s',// VNU_phone |
|
| 673 | + '%d',// VNU_capacity |
|
| 674 | + '%s',// VNU_url |
|
| 675 | + '%s',// VNU_virtual_phone |
|
| 676 | + '%s',// VNU_virtual_url |
|
| 677 | + '%s',// VNU_google_map_link |
|
| 678 | + '%d',// VNU_enable_for_gmap |
|
| 679 | + ); |
|
| 680 | + $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes); |
|
| 681 | + if (! $success) { |
|
| 682 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes)); |
|
| 683 | + return 0; |
|
| 684 | + } |
|
| 685 | + return $wpdb->insert_id; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * @param $new_event_id |
|
| 692 | + * @param $new_venue_id |
|
| 693 | + * @return int |
|
| 694 | + */ |
|
| 695 | + private function _insert_new_venue_to_event($new_event_id, $new_venue_id) |
|
| 696 | + { |
|
| 697 | + global $wpdb; |
|
| 698 | + if (! $new_event_id) { |
|
| 699 | + $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id)); |
|
| 700 | + return 0; |
|
| 701 | + } |
|
| 702 | + if (! $new_venue_id) { |
|
| 703 | + $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id)); |
|
| 704 | + return 0; |
|
| 705 | + } |
|
| 706 | + $cols_n_values = array( |
|
| 707 | + 'EVT_ID'=>$new_event_id, |
|
| 708 | + 'VNU_ID'=>$new_venue_id, |
|
| 709 | + 'EVV_primary'=>true |
|
| 710 | + ); |
|
| 711 | + $datatypes = array( |
|
| 712 | + '%d',// EVT_ID |
|
| 713 | + '%d',// VNU_ID |
|
| 714 | + '%d',// EVT_primary |
|
| 715 | + ); |
|
| 716 | + $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes); |
|
| 717 | + if (! $success) { |
|
| 718 | + $this->add_error( |
|
| 719 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 720 | + $this->_old_table, |
|
| 721 | + array(), |
|
| 722 | + $this->_new_table, |
|
| 723 | + $cols_n_values, |
|
| 724 | + $datatypes |
|
| 725 | + ) |
|
| 726 | + ); |
|
| 727 | + return 0; |
|
| 728 | + } |
|
| 729 | + return $wpdb->insert_id; |
|
| 730 | + } |
|
| 731 | + /** |
|
| 732 | + * Converts all the 3.1 start-end times for the event to 4.1 datetimes |
|
| 733 | + * @global wpdb $wpdb |
|
| 734 | + * @param array $old_event results of get_results(...,ARRAY_A) |
|
| 735 | + * @param int $new_cpt_id new post ID |
|
| 736 | + * @return void (if there are errors though, adds them to the stage's error list |
|
| 737 | + */ |
|
| 738 | + private function _convert_start_end_times($old_event, $new_cpt_id) |
|
| 739 | + { |
|
| 740 | + $start_end_times = $this->_get_old_start_end_times($old_event['id']); |
|
| 741 | + foreach ($start_end_times as $start_end_time) { |
|
| 742 | + $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id); |
|
| 743 | + if ($datetime_id) { |
|
| 744 | + $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id); |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + /** |
|
| 749 | + * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event |
|
| 750 | + * @global wpdb $wpdb |
|
| 751 | + * @param int $old_event_id |
|
| 752 | + * @return array |
|
| 753 | + */ |
|
| 754 | + private function _get_old_start_end_times($old_event_id) |
|
| 755 | + { |
|
| 756 | + global $wpdb; |
|
| 757 | + return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A); |
|
| 758 | + } |
|
| 759 | + /** |
|
| 760 | + * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row |
|
| 761 | + * @param array $start_end_time_row |
|
| 762 | + * @param array $old_event_row |
|
| 763 | + * @param int $new_cpt_id |
|
| 764 | + * @return int ID of new datetime |
|
| 765 | + */ |
|
| 766 | + private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id) |
|
| 767 | + { |
|
| 768 | + global $wpdb; |
|
| 769 | + $start_date = $old_event_row['start_date']; |
|
| 770 | + $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']); |
|
| 771 | + $end_date = $old_event_row['end_date']; |
|
| 772 | + $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']); |
|
| 773 | + $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id); |
|
| 774 | + $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']); |
|
| 775 | + $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']); |
|
| 776 | + $cols_n_values = array( |
|
| 777 | + 'EVT_ID'=>$new_cpt_id,// EVT_ID |
|
| 778 | + 'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start |
|
| 779 | + 'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end |
|
| 780 | + 'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit |
|
| 781 | + 'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration |
|
| 787 | 782 | // 'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary' |
| 788 | - 'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 789 | - 'DTT_parent'=>0, |
|
| 790 | - 'DTT_deleted'=>false |
|
| 791 | - ); |
|
| 792 | - $datatypes = array( |
|
| 793 | - '%d',// EVT_Id |
|
| 794 | - '%s',// DTT_EVT_start |
|
| 795 | - '%s',// DTT_EVT_end |
|
| 796 | - '%d',// DTT_reg_limit |
|
| 797 | - '%d',// DTT_sold |
|
| 783 | + 'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 784 | + 'DTT_parent'=>0, |
|
| 785 | + 'DTT_deleted'=>false |
|
| 786 | + ); |
|
| 787 | + $datatypes = array( |
|
| 788 | + '%d',// EVT_Id |
|
| 789 | + '%s',// DTT_EVT_start |
|
| 790 | + '%s',// DTT_EVT_end |
|
| 791 | + '%d',// DTT_reg_limit |
|
| 792 | + '%d',// DTT_sold |
|
| 798 | 793 | // '%d',//DTT_is_primary |
| 799 | - '%d',// DTT_order |
|
| 800 | - '%d',// DTT_parent |
|
| 801 | - '%d',// DTT_deleted |
|
| 802 | - ); |
|
| 803 | - $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes); |
|
| 804 | - if (! $success) { |
|
| 805 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes)); |
|
| 806 | - return 0; |
|
| 807 | - } |
|
| 808 | - return $wpdb->insert_id; |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * Checks if there's a 4.1 datetime for this event already. This is mostly only handy |
|
| 813 | - * when deciding whether a datetime we're about ot insert should be the 'primary' or not |
|
| 814 | - * @global wpdb $wpdb |
|
| 815 | - * @param int $cpt_event_id |
|
| 816 | - * @return int |
|
| 817 | - */ |
|
| 818 | - private function _count_other_datetimes_exist_for_new_event($cpt_event_id) |
|
| 819 | - { |
|
| 820 | - global $wpdb; |
|
| 821 | - $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id)); |
|
| 822 | - return intval($count); |
|
| 823 | - } |
|
| 794 | + '%d',// DTT_order |
|
| 795 | + '%d',// DTT_parent |
|
| 796 | + '%d',// DTT_deleted |
|
| 797 | + ); |
|
| 798 | + $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes); |
|
| 799 | + if (! $success) { |
|
| 800 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes)); |
|
| 801 | + return 0; |
|
| 802 | + } |
|
| 803 | + return $wpdb->insert_id; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * Checks if there's a 4.1 datetime for this event already. This is mostly only handy |
|
| 808 | + * when deciding whether a datetime we're about ot insert should be the 'primary' or not |
|
| 809 | + * @global wpdb $wpdb |
|
| 810 | + * @param int $cpt_event_id |
|
| 811 | + * @return int |
|
| 812 | + */ |
|
| 813 | + private function _count_other_datetimes_exist_for_new_event($cpt_event_id) |
|
| 814 | + { |
|
| 815 | + global $wpdb; |
|
| 816 | + $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id)); |
|
| 817 | + return intval($count); |
|
| 818 | + } |
|
| 824 | 819 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | public function _count_records_to_migrate() |
| 194 | 194 | { |
| 195 | 195 | global $wpdb; |
| 196 | - $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table . ' WHERE event_status !="D"'); |
|
| 196 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table.' WHERE event_status !="D"'); |
|
| 197 | 197 | return intval($count); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | global $wpdb; |
| 214 | 214 | // because the migration of each event can be a LOT more work, make each step smaller |
| 215 | - $num_items_to_migrate = max(1, $num_items_to_migrate/5); |
|
| 215 | + $num_items_to_migrate = max(1, $num_items_to_migrate / 5); |
|
| 216 | 216 | $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A); |
| 217 | 217 | $items_migrated_this_step = 0; |
| 218 | 218 | |
@@ -260,17 +260,17 @@ discard block |
||
| 260 | 260 | private function _add_post_metas($old_event, $post_id) |
| 261 | 261 | { |
| 262 | 262 | $event_meta = maybe_unserialize($old_event['event_meta']); |
| 263 | - if (! $event_meta || ! is_array($event_meta)) { |
|
| 263 | + if ( ! $event_meta || ! is_array($event_meta)) { |
|
| 264 | 264 | return; |
| 265 | 265 | } |
| 266 | - unset($event_meta['date_submitted']);// factored into CPT |
|
| 267 | - unset($event_meta['additional_attendee_reg_info']);// factored into event meta table |
|
| 268 | - unset($event_meta['default_payment_status']);// dido |
|
| 269 | - unset($event_meta['event_thumbnail_url']);// used to find post featured image |
|
| 266 | + unset($event_meta['date_submitted']); // factored into CPT |
|
| 267 | + unset($event_meta['additional_attendee_reg_info']); // factored into event meta table |
|
| 268 | + unset($event_meta['default_payment_status']); // dido |
|
| 269 | + unset($event_meta['event_thumbnail_url']); // used to find post featured image |
|
| 270 | 270 | foreach ($event_meta as $meta_key => $meta_value) { |
| 271 | 271 | if ($meta_key) {// if the meta key is just an empty string, ignore it |
| 272 | 272 | $success = add_post_meta($post_id, $meta_key, $meta_value, true); |
| 273 | - if (! $success) { |
|
| 273 | + if ( ! $success) { |
|
| 274 | 274 | $this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event))); |
| 275 | 275 | } |
| 276 | 276 | } |
@@ -341,68 +341,68 @@ discard block |
||
| 341 | 341 | // and 3 custom ones: cancelled,postponed,sold_out |
| 342 | 342 | $status_conversions = array( |
| 343 | 343 | 'R'=>'draft', |
| 344 | - 'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 344 | + 'X'=>'draft', // 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 345 | 345 | 'P'=>'pending', |
| 346 | - 'IA'=>'draft',// draft and in the past |
|
| 346 | + 'IA'=>'draft', // draft and in the past |
|
| 347 | 347 | // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated |
| 348 | - 'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 348 | + 'O'=>'publish', // @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 349 | 349 | 'A'=>'publish', |
| 350 | - 'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 350 | + 'S'=>'draft', // @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 351 | 351 | 'D'=>'trash', |
| 352 | 352 | ); |
| 353 | - $post_status = $status_conversions[ $old_event['event_status'] ]; |
|
| 353 | + $post_status = $status_conversions[$old_event['event_status']]; |
|
| 354 | 354 | // check if we've sold out |
| 355 | 355 | if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) { |
| 356 | 356 | $post_status = 'sold_out'; |
| 357 | 357 | } |
| 358 | 358 | // FYI postponed and cancelled don't exist in 3.1 |
| 359 | 359 | $cols_n_values = array( |
| 360 | - 'post_title'=>stripslashes($old_event['event_name']),// EVT_name |
|
| 361 | - 'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc |
|
| 362 | - 'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug |
|
| 363 | - 'post_date'=>$old_event['submitted'],// EVT_created NOT |
|
| 360 | + 'post_title'=>stripslashes($old_event['event_name']), // EVT_name |
|
| 361 | + 'post_content'=>stripslashes($old_event['event_desc']), // EVT_desc |
|
| 362 | + 'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status), // EVT_slug |
|
| 363 | + 'post_date'=>$old_event['submitted'], // EVT_created NOT |
|
| 364 | 364 | 'post_date_gmt'=>get_gmt_from_date($old_event['submitted']), |
| 365 | - 'post_excerpt'=>'',// EVT_short_desc |
|
| 366 | - 'post_modified'=>$old_event['submitted'],// EVT_modified |
|
| 365 | + 'post_excerpt'=>'', // EVT_short_desc |
|
| 366 | + 'post_modified'=>$old_event['submitted'], // EVT_modified |
|
| 367 | 367 | 'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']), |
| 368 | - 'post_author'=>$old_event['wp_user'],// EVT_wp_user |
|
| 369 | - 'post_parent'=>0,// parent maybe get this from some REM field? |
|
| 370 | - 'menu_order'=>0,// EVT_order |
|
| 371 | - 'post_type'=>'espresso_events',// post_type |
|
| 372 | - 'post_status'=>$post_status,// status |
|
| 368 | + 'post_author'=>$old_event['wp_user'], // EVT_wp_user |
|
| 369 | + 'post_parent'=>0, // parent maybe get this from some REM field? |
|
| 370 | + 'menu_order'=>0, // EVT_order |
|
| 371 | + 'post_type'=>'espresso_events', // post_type |
|
| 372 | + 'post_status'=>$post_status, // status |
|
| 373 | 373 | ); |
| 374 | 374 | $cols_n_values_with_no_invalid_text = array(); |
| 375 | 375 | foreach ($cols_n_values as $col => $value) { |
| 376 | 376 | $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value); |
| 377 | - if (! is_wp_error($value_sans_invalid_chars)) { |
|
| 378 | - $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars; |
|
| 377 | + if ( ! is_wp_error($value_sans_invalid_chars)) { |
|
| 378 | + $cols_n_values_with_no_invalid_text[$col] = $value_sans_invalid_chars; |
|
| 379 | 379 | } else { |
| 380 | 380 | // otherwise leave it as-is. It will blow everything up and stop the migration |
| 381 | - $cols_n_values_with_no_invalid_text[ $col ] = $value; |
|
| 381 | + $cols_n_values_with_no_invalid_text[$col] = $value; |
|
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | $cols_n_values = $cols_n_values_with_no_invalid_text; |
| 385 | 385 | $datatypes = array( |
| 386 | - '%s',// EVT_name |
|
| 387 | - '%s',// EVT_desc |
|
| 388 | - '%s',// EVT_slug |
|
| 389 | - '%s',// EVT_created |
|
| 386 | + '%s', // EVT_name |
|
| 387 | + '%s', // EVT_desc |
|
| 388 | + '%s', // EVT_slug |
|
| 389 | + '%s', // EVT_created |
|
| 390 | 390 | '%s', |
| 391 | - '%s',// EVT_short_desc |
|
| 392 | - '%s',// EVT_modified |
|
| 391 | + '%s', // EVT_short_desc |
|
| 392 | + '%s', // EVT_modified |
|
| 393 | 393 | '%s', |
| 394 | - '%s',// EVT_wp_user |
|
| 395 | - '%d',// post_parent |
|
| 396 | - '%d',// EVT_order |
|
| 397 | - '%s',// post_type |
|
| 398 | - '%s',// status |
|
| 394 | + '%s', // EVT_wp_user |
|
| 395 | + '%d', // post_parent |
|
| 396 | + '%d', // EVT_order |
|
| 397 | + '%s', // post_type |
|
| 398 | + '%s', // status |
|
| 399 | 399 | ); |
| 400 | 400 | $success = $wpdb->insert( |
| 401 | 401 | $this->_new_table, |
| 402 | 402 | $cols_n_values, |
| 403 | 403 | $datatypes |
| 404 | 404 | ); |
| 405 | - if (! $success) { |
|
| 405 | + if ( ! $success) { |
|
| 406 | 406 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
| 407 | 407 | return 0; |
| 408 | 408 | } |
@@ -441,10 +441,10 @@ discard block |
||
| 441 | 441 | // ); |
| 442 | 442 | $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval'])); |
| 443 | 443 | $cols_n_values = array( |
| 444 | - 'EVT_ID'=>$new_cpt_id,// EVT_ID_fk |
|
| 444 | + 'EVT_ID'=>$new_cpt_id, // EVT_ID_fk |
|
| 445 | 445 | 'EVT_display_desc'=> 'Y' == $old_event['display_desc'], |
| 446 | - 'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'], |
|
| 447 | - 'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used |
|
| 446 | + 'EVT_display_ticket_selector'=> 'Y' == $old_event['display_reg_form'], |
|
| 447 | + 'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']), // don't use the old 'visible_on', as it wasn't ever used |
|
| 448 | 448 | 'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'], |
| 449 | 449 | 'EVT_default_registration_status' => $default_reg_status, |
| 450 | 450 | 'EVT_member_only'=>$old_event['member_only'], |
@@ -456,25 +456,25 @@ discard block |
||
| 456 | 456 | |
| 457 | 457 | ); |
| 458 | 458 | $datatypes = array( |
| 459 | - '%s',// EVT_ID |
|
| 460 | - '%d',// EVT_display_desc |
|
| 461 | - '%d',// EVT_display_ticket_selector |
|
| 462 | - '%s',// EVT_visible_on |
|
| 463 | - '%d',// EVT_additional_limit |
|
| 464 | - '%s',// EVT_default_registration_status |
|
| 465 | - '%d',// EVT_member_only |
|
| 466 | - '%s',// EVT_phone |
|
| 467 | - '%d',// EVT_allow_overflow |
|
| 468 | - '%s',// EVT_timezone_string |
|
| 469 | - '%s',// EVT_external_URL |
|
| 470 | - '%d',// EVT_donations |
|
| 459 | + '%s', // EVT_ID |
|
| 460 | + '%d', // EVT_display_desc |
|
| 461 | + '%d', // EVT_display_ticket_selector |
|
| 462 | + '%s', // EVT_visible_on |
|
| 463 | + '%d', // EVT_additional_limit |
|
| 464 | + '%s', // EVT_default_registration_status |
|
| 465 | + '%d', // EVT_member_only |
|
| 466 | + '%s', // EVT_phone |
|
| 467 | + '%d', // EVT_allow_overflow |
|
| 468 | + '%s', // EVT_timezone_string |
|
| 469 | + '%s', // EVT_external_URL |
|
| 470 | + '%d', // EVT_donations |
|
| 471 | 471 | ); |
| 472 | 472 | $success = $wpdb->insert( |
| 473 | 473 | $this->_new_meta_table, |
| 474 | 474 | $cols_n_values, |
| 475 | 475 | $datatypes |
| 476 | 476 | ); |
| 477 | - if (! $success) { |
|
| 477 | + if ( ! $success) { |
|
| 478 | 478 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes)); |
| 479 | 479 | return 0; |
| 480 | 480 | } |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | $new_id = $this->_insert_venue_into_posts($old_event); |
| 509 | 509 | if ($new_id) { |
| 510 | 510 | $this->_insert_venue_into_meta_table($new_id, $old_event); |
| 511 | - $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 511 | + $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 512 | 512 | $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
| 513 | 513 | } |
| 514 | 514 | // we don't bother recording the conversion from old events to venues as that |
@@ -534,10 +534,10 @@ discard block |
||
| 534 | 534 | 'VNU_city' => $old_event['city'], |
| 535 | 535 | 'VNU_zip' => $old_event['zip'], |
| 536 | 536 | 'post_title'=> $this->_get_venue_title_for_event($old_event), |
| 537 | - 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 538 | - 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 539 | - 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 540 | - 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 537 | + 'VNU_phone'=>$old_event['venue_phone'], // VNU_phone |
|
| 538 | + 'VNU_url'=>$old_event['venue_url'], // VNU_url |
|
| 539 | + 'VNU_virtual_phone'=>$old_event['virtual_phone'], // VNU_virtual_phone |
|
| 540 | + 'VNU_virtual_url'=>$old_event['virtual_url'], // VNU_virtual_url |
|
| 541 | 541 | ); |
| 542 | 542 | $sql_conditions = array(); |
| 543 | 543 | foreach ($conditions as $column => $value) { |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | FROM |
| 548 | 548 | {$wpdb->posts} as p INNER JOIN |
| 549 | 549 | {$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID |
| 550 | - WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1"; |
|
| 550 | + WHERE ".implode(" AND ", $sql_conditions)." LIMIT 1"; |
|
| 551 | 551 | $id = $wpdb->get_var($query); |
| 552 | 552 | return $id; |
| 553 | 553 | } |
@@ -572,39 +572,39 @@ discard block |
||
| 572 | 572 | { |
| 573 | 573 | global $wpdb; |
| 574 | 574 | $insertion_array = array( |
| 575 | - 'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name |
|
| 576 | - 'post_content'=>'',// VNU_desc |
|
| 577 | - 'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier |
|
| 578 | - 'post_date'=>current_time('mysql'),// VNU_created |
|
| 575 | + 'post_title'=> $this->_get_venue_title_for_event($old_event), // VNU_name |
|
| 576 | + 'post_content'=>'', // VNU_desc |
|
| 577 | + 'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-'.$old_event['event_name'])), // VNU_identifier |
|
| 578 | + 'post_date'=>current_time('mysql'), // VNU_created |
|
| 579 | 579 | 'post_date_gmt'=>get_gmt_from_date(current_time('mysql')), |
| 580 | - 'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters |
|
| 581 | - 'post_modified'=>current_time('mysql'),// VNU_modified |
|
| 580 | + 'post_excerpt'=>'', // VNU_short_desc arbitrary only 50 characters |
|
| 581 | + 'post_modified'=>current_time('mysql'), // VNU_modified |
|
| 582 | 582 | 'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')), |
| 583 | - 'post_author'=>$old_event['wp_user'],// VNU_wp_user |
|
| 584 | - 'post_parent'=>0,// parent |
|
| 585 | - 'menu_order'=>0,// VNU_order |
|
| 583 | + 'post_author'=>$old_event['wp_user'], // VNU_wp_user |
|
| 584 | + 'post_parent'=>0, // parent |
|
| 585 | + 'menu_order'=>0, // VNU_order |
|
| 586 | 586 | 'post_type'=>'espresso_venues'// post_type |
| 587 | 587 | ); |
| 588 | 588 | $datatypes_array = array( |
| 589 | - '%s',// VNU_name |
|
| 590 | - '%s',// VNU_desc |
|
| 591 | - '%s',// VNU_identifier |
|
| 592 | - '%s',// VNU_created |
|
| 589 | + '%s', // VNU_name |
|
| 590 | + '%s', // VNU_desc |
|
| 591 | + '%s', // VNU_identifier |
|
| 592 | + '%s', // VNU_created |
|
| 593 | 593 | '%s', |
| 594 | - '%s',// VNU_short_desc |
|
| 595 | - '%s',// VNU_modified |
|
| 594 | + '%s', // VNU_short_desc |
|
| 595 | + '%s', // VNU_modified |
|
| 596 | 596 | '%s', |
| 597 | - '%d',// VNU_wp_user |
|
| 598 | - '%d',// parent |
|
| 599 | - '%d',// VNU_order |
|
| 600 | - '%s',// post_type |
|
| 597 | + '%d', // VNU_wp_user |
|
| 598 | + '%d', // parent |
|
| 599 | + '%d', // VNU_order |
|
| 600 | + '%s', // post_type |
|
| 601 | 601 | ); |
| 602 | 602 | $success = $wpdb->insert( |
| 603 | 603 | $wpdb->posts, |
| 604 | 604 | $insertion_array, |
| 605 | 605 | $datatypes_array |
| 606 | 606 | ); |
| 607 | - if (! $success) { |
|
| 607 | + if ( ! $success) { |
|
| 608 | 608 | $this->add_error( |
| 609 | 609 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
| 610 | 610 | $this->_old_table, |
@@ -632,13 +632,13 @@ discard block |
||
| 632 | 632 | // assume the country is the same as the organization's old settings |
| 633 | 633 | $country_iso = $this->get_migration_script()->get_default_country_iso(); |
| 634 | 634 | // find the state from the venue, or the organization, or just guess california |
| 635 | - if (! $old_event['state']) { |
|
| 635 | + if ( ! $old_event['state']) { |
|
| 636 | 636 | $old_org_options = get_option('events_organization_settings'); |
| 637 | 637 | $state_name = stripslashes($old_org_options['organization_state']); |
| 638 | 638 | } else { |
| 639 | 639 | $state_name = $old_event['state']; |
| 640 | 640 | } |
| 641 | - if (! $state_name) { |
|
| 641 | + if ( ! $state_name) { |
|
| 642 | 642 | $state_name = 'CA'; |
| 643 | 643 | } |
| 644 | 644 | // get a state ID with the same name, if possible |
@@ -651,39 +651,39 @@ discard block |
||
| 651 | 651 | } |
| 652 | 652 | // now insert into meta table |
| 653 | 653 | $insertion_array = array( |
| 654 | - 'VNU_ID'=>$cpt_id,// VNU_ID_fk |
|
| 655 | - 'VNU_address'=>stripslashes($old_event['address']),// VNU_address |
|
| 656 | - 'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2 |
|
| 657 | - 'VNU_city'=>stripslashes($old_event['city']),// VNU_city |
|
| 658 | - 'STA_ID'=>$state_id,// STA_ID |
|
| 659 | - 'CNT_ISO'=>$country_iso,// CNT_ISO |
|
| 660 | - 'VNU_zip'=>$old_event['zip'],// VNU_zip |
|
| 661 | - 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 662 | - 'VNU_capacity'=>-1,// VNU_capacity |
|
| 663 | - 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 664 | - 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 665 | - 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 666 | - 'VNU_google_map_link'=>'',// VNU_google_map_link |
|
| 654 | + 'VNU_ID'=>$cpt_id, // VNU_ID_fk |
|
| 655 | + 'VNU_address'=>stripslashes($old_event['address']), // VNU_address |
|
| 656 | + 'VNU_address2'=>stripslashes($old_event['address2']), // VNU_address2 |
|
| 657 | + 'VNU_city'=>stripslashes($old_event['city']), // VNU_city |
|
| 658 | + 'STA_ID'=>$state_id, // STA_ID |
|
| 659 | + 'CNT_ISO'=>$country_iso, // CNT_ISO |
|
| 660 | + 'VNU_zip'=>$old_event['zip'], // VNU_zip |
|
| 661 | + 'VNU_phone'=>$old_event['venue_phone'], // VNU_phone |
|
| 662 | + 'VNU_capacity'=>-1, // VNU_capacity |
|
| 663 | + 'VNU_url'=>$old_event['venue_url'], // VNU_url |
|
| 664 | + 'VNU_virtual_phone'=>$old_event['virtual_phone'], // VNU_virtual_phone |
|
| 665 | + 'VNU_virtual_url'=>$old_event['virtual_url'], // VNU_virtual_url |
|
| 666 | + 'VNU_google_map_link'=>'', // VNU_google_map_link |
|
| 667 | 667 | 'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap |
| 668 | 668 | ); |
| 669 | 669 | $datatypes = array( |
| 670 | - '%d',// VNU_ID_fk |
|
| 671 | - '%s',// VNU_address |
|
| 672 | - '%s',// VNU_address2 |
|
| 673 | - '%s',// VNU_city |
|
| 674 | - '%d',// STA_ID |
|
| 675 | - '%s',// CNT_ISO |
|
| 676 | - '%s',// VNU_zip |
|
| 677 | - '%s',// VNU_phone |
|
| 678 | - '%d',// VNU_capacity |
|
| 679 | - '%s',// VNU_url |
|
| 680 | - '%s',// VNU_virtual_phone |
|
| 681 | - '%s',// VNU_virtual_url |
|
| 682 | - '%s',// VNU_google_map_link |
|
| 683 | - '%d',// VNU_enable_for_gmap |
|
| 670 | + '%d', // VNU_ID_fk |
|
| 671 | + '%s', // VNU_address |
|
| 672 | + '%s', // VNU_address2 |
|
| 673 | + '%s', // VNU_city |
|
| 674 | + '%d', // STA_ID |
|
| 675 | + '%s', // CNT_ISO |
|
| 676 | + '%s', // VNU_zip |
|
| 677 | + '%s', // VNU_phone |
|
| 678 | + '%d', // VNU_capacity |
|
| 679 | + '%s', // VNU_url |
|
| 680 | + '%s', // VNU_virtual_phone |
|
| 681 | + '%s', // VNU_virtual_url |
|
| 682 | + '%s', // VNU_google_map_link |
|
| 683 | + '%d', // VNU_enable_for_gmap |
|
| 684 | 684 | ); |
| 685 | 685 | $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes); |
| 686 | - if (! $success) { |
|
| 686 | + if ( ! $success) { |
|
| 687 | 687 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes)); |
| 688 | 688 | return 0; |
| 689 | 689 | } |
@@ -700,11 +700,11 @@ discard block |
||
| 700 | 700 | private function _insert_new_venue_to_event($new_event_id, $new_venue_id) |
| 701 | 701 | { |
| 702 | 702 | global $wpdb; |
| 703 | - if (! $new_event_id) { |
|
| 703 | + if ( ! $new_event_id) { |
|
| 704 | 704 | $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id)); |
| 705 | 705 | return 0; |
| 706 | 706 | } |
| 707 | - if (! $new_venue_id) { |
|
| 707 | + if ( ! $new_venue_id) { |
|
| 708 | 708 | $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id)); |
| 709 | 709 | return 0; |
| 710 | 710 | } |
@@ -714,12 +714,12 @@ discard block |
||
| 714 | 714 | 'EVV_primary'=>true |
| 715 | 715 | ); |
| 716 | 716 | $datatypes = array( |
| 717 | - '%d',// EVT_ID |
|
| 718 | - '%d',// VNU_ID |
|
| 719 | - '%d',// EVT_primary |
|
| 717 | + '%d', // EVT_ID |
|
| 718 | + '%d', // VNU_ID |
|
| 719 | + '%d', // EVT_primary |
|
| 720 | 720 | ); |
| 721 | 721 | $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes); |
| 722 | - if (! $success) { |
|
| 722 | + if ( ! $success) { |
|
| 723 | 723 | $this->add_error( |
| 724 | 724 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
| 725 | 725 | $this->_old_table, |
@@ -779,29 +779,29 @@ discard block |
||
| 779 | 779 | $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']); |
| 780 | 780 | $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']); |
| 781 | 781 | $cols_n_values = array( |
| 782 | - 'EVT_ID'=>$new_cpt_id,// EVT_ID |
|
| 783 | - 'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start |
|
| 784 | - 'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end |
|
| 785 | - 'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit |
|
| 786 | - 'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration |
|
| 782 | + 'EVT_ID'=>$new_cpt_id, // EVT_ID |
|
| 783 | + 'DTT_EVT_start'=>$start_datetime_utc, // DTT_EVT_start |
|
| 784 | + 'DTT_EVT_end'=> $end_datetime_utc, // DTT_EVT_end |
|
| 785 | + 'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'], // DTT_reg_limit |
|
| 786 | + 'DTT_sold'=>0, // note: we will increment this as registrations are added during the migration |
|
| 787 | 787 | // 'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary' |
| 788 | - 'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 788 | + 'DTT_order'=> $existing_datetimes, // DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 789 | 789 | 'DTT_parent'=>0, |
| 790 | 790 | 'DTT_deleted'=>false |
| 791 | 791 | ); |
| 792 | 792 | $datatypes = array( |
| 793 | - '%d',// EVT_Id |
|
| 794 | - '%s',// DTT_EVT_start |
|
| 795 | - '%s',// DTT_EVT_end |
|
| 796 | - '%d',// DTT_reg_limit |
|
| 797 | - '%d',// DTT_sold |
|
| 793 | + '%d', // EVT_Id |
|
| 794 | + '%s', // DTT_EVT_start |
|
| 795 | + '%s', // DTT_EVT_end |
|
| 796 | + '%d', // DTT_reg_limit |
|
| 797 | + '%d', // DTT_sold |
|
| 798 | 798 | // '%d',//DTT_is_primary |
| 799 | - '%d',// DTT_order |
|
| 800 | - '%d',// DTT_parent |
|
| 801 | - '%d',// DTT_deleted |
|
| 799 | + '%d', // DTT_order |
|
| 800 | + '%d', // DTT_parent |
|
| 801 | + '%d', // DTT_deleted |
|
| 802 | 802 | ); |
| 803 | 803 | $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes); |
| 804 | - if (! $success) { |
|
| 804 | + if ( ! $success) { |
|
| 805 | 805 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes)); |
| 806 | 806 | return 0; |
| 807 | 807 | } |
@@ -26,132 +26,132 @@ |
||
| 26 | 26 | |
| 27 | 27 | class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table |
| 28 | 28 | { |
| 29 | - private $_new_table; |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - global $wpdb; |
|
| 33 | - $this->_pretty_name = __("Checkins", "event_espresso"); |
|
| 34 | - $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 35 | - $this->_extra_where_sql = 'AS att |
|
| 29 | + private $_new_table; |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + global $wpdb; |
|
| 33 | + $this->_pretty_name = __("Checkins", "event_espresso"); |
|
| 34 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 35 | + $this->_extra_where_sql = 'AS att |
|
| 36 | 36 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
| 37 | 37 | WHERE e.event_status!="D"'; |
| 38 | - $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
| 39 | - parent::__construct(); |
|
| 40 | - } |
|
| 41 | - protected function _migrate_old_row($old_row) |
|
| 42 | - { |
|
| 43 | - global $wpdb; |
|
| 44 | - $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 38 | + $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
| 39 | + parent::__construct(); |
|
| 40 | + } |
|
| 41 | + protected function _migrate_old_row($old_row) |
|
| 42 | + { |
|
| 43 | + global $wpdb; |
|
| 44 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 45 | 45 | |
| 46 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 46 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 47 | 47 | |
| 48 | - $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
| 49 | - if (! $new_registrations_for_attendee) { |
|
| 50 | - $new_registrations_for_attendee = array(); |
|
| 51 | - } |
|
| 52 | - $new_datetime = $this->_try_to_find_datetime($old_row); |
|
| 48 | + $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
| 49 | + if (! $new_registrations_for_attendee) { |
|
| 50 | + $new_registrations_for_attendee = array(); |
|
| 51 | + } |
|
| 52 | + $new_datetime = $this->_try_to_find_datetime($old_row); |
|
| 53 | 53 | |
| 54 | - // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
| 55 | - $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
| 56 | - $new_checkin_ids = array(); |
|
| 57 | - for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 59 | - if (! $new_reg_id) { |
|
| 60 | - $this->add_error(sprintf( |
|
| 61 | - __('It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', "event_espresso"), |
|
| 62 | - $this->_json_encode($old_row), |
|
| 63 | - abs($num_to_checkin_at_this_time), |
|
| 64 | - count($new_registrations_for_attendee), |
|
| 65 | - $this->_json_encode($new_registrations_for_attendee) |
|
| 66 | - )); |
|
| 67 | - break; |
|
| 68 | - } |
|
| 69 | - $new_last_checkin_record = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", $new_reg_id)); |
|
| 70 | - if (! $new_last_checkin_record) { |
|
| 71 | - $is_checked_in = false; |
|
| 72 | - } else { |
|
| 73 | - $is_checked_in = intval($new_last_checkin_record['CHK_in']); |
|
| 74 | - } |
|
| 75 | - $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
| 76 | - if ($new_id) { |
|
| 77 | - $new_checkin_ids[]= $new_id; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - if ($new_checkin_ids) { |
|
| 81 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_table, $new_checkin_ids); |
|
| 82 | - } |
|
| 83 | - } |
|
| 54 | + // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
| 55 | + $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
| 56 | + $new_checkin_ids = array(); |
|
| 57 | + for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | + $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 59 | + if (! $new_reg_id) { |
|
| 60 | + $this->add_error(sprintf( |
|
| 61 | + __('It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', "event_espresso"), |
|
| 62 | + $this->_json_encode($old_row), |
|
| 63 | + abs($num_to_checkin_at_this_time), |
|
| 64 | + count($new_registrations_for_attendee), |
|
| 65 | + $this->_json_encode($new_registrations_for_attendee) |
|
| 66 | + )); |
|
| 67 | + break; |
|
| 68 | + } |
|
| 69 | + $new_last_checkin_record = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", $new_reg_id)); |
|
| 70 | + if (! $new_last_checkin_record) { |
|
| 71 | + $is_checked_in = false; |
|
| 72 | + } else { |
|
| 73 | + $is_checked_in = intval($new_last_checkin_record['CHK_in']); |
|
| 74 | + } |
|
| 75 | + $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
| 76 | + if ($new_id) { |
|
| 77 | + $new_checkin_ids[]= $new_id; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + if ($new_checkin_ids) { |
|
| 81 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_table, $new_checkin_ids); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
| 88 | - * (because we know the attendee was for an event as a specific time, and we know |
|
| 89 | - * the event's OLD ID...) |
|
| 90 | - * @global type $wpdb |
|
| 91 | - * @param array $old_attendee_row |
|
| 92 | - * @return array row of datetime from DB |
|
| 93 | - */ |
|
| 94 | - private function _try_to_find_datetime($old_attendee) |
|
| 95 | - { |
|
| 96 | - global $wpdb; |
|
| 86 | + /** |
|
| 87 | + * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
| 88 | + * (because we know the attendee was for an event as a specific time, and we know |
|
| 89 | + * the event's OLD ID...) |
|
| 90 | + * @global type $wpdb |
|
| 91 | + * @param array $old_attendee_row |
|
| 92 | + * @return array row of datetime from DB |
|
| 93 | + */ |
|
| 94 | + private function _try_to_find_datetime($old_attendee) |
|
| 95 | + { |
|
| 96 | + global $wpdb; |
|
| 97 | 97 | |
| 98 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
| 99 | - if (! $new_event_id) { |
|
| 100 | - $this->add_error(sprintf(__("Could nto find new event ID with old event id '%d', on attendee row %s; and because of that couldnt find the correct datetime for Check-in", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
|
| 101 | - return 0; |
|
| 102 | - } |
|
| 103 | - $old_att_start_date = $old_attendee['start_date']; |
|
| 104 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 105 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 98 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
| 99 | + if (! $new_event_id) { |
|
| 100 | + $this->add_error(sprintf(__("Could nto find new event ID with old event id '%d', on attendee row %s; and because of that couldnt find the correct datetime for Check-in", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
|
| 101 | + return 0; |
|
| 102 | + } |
|
| 103 | + $old_att_start_date = $old_attendee['start_date']; |
|
| 104 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 105 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 106 | 106 | |
| 107 | - $datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 108 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 109 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
| 110 | - $conditions = array( |
|
| 111 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 112 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 113 | - ); |
|
| 114 | - // start running queries, widening search each time by removing a condition |
|
| 115 | - $datetime_found = null; |
|
| 116 | - do { |
|
| 117 | - $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 118 | - $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
| 119 | - array_shift($conditions); |
|
| 120 | - } while (! $datetime_found && $conditions); |
|
| 121 | - return $datetime_found; |
|
| 122 | - } |
|
| 107 | + $datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 108 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 109 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
| 110 | + $conditions = array( |
|
| 111 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 112 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 113 | + ); |
|
| 114 | + // start running queries, widening search each time by removing a condition |
|
| 115 | + $datetime_found = null; |
|
| 116 | + do { |
|
| 117 | + $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 118 | + $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
| 119 | + array_shift($conditions); |
|
| 120 | + } while (! $datetime_found && $conditions); |
|
| 121 | + return $datetime_found; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
| 126 | - * @param int $new_reg_id |
|
| 127 | - * @param int $new_datetime_id |
|
| 128 | - * @param string $timestamp mysql datetime |
|
| 129 | - * @return int new Check-in id |
|
| 130 | - */ |
|
| 131 | - private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
| 132 | - { |
|
| 133 | - global $wpdb; |
|
| 124 | + /** |
|
| 125 | + * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
| 126 | + * @param int $new_reg_id |
|
| 127 | + * @param int $new_datetime_id |
|
| 128 | + * @param string $timestamp mysql datetime |
|
| 129 | + * @return int new Check-in id |
|
| 130 | + */ |
|
| 131 | + private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
| 132 | + { |
|
| 133 | + global $wpdb; |
|
| 134 | 134 | |
| 135 | 135 | |
| 136 | - // ok we can actually do what we set out to do: add a checkin/checkout record |
|
| 137 | - $cols_n_values = array( |
|
| 138 | - 'REG_ID'=>$new_reg_id, |
|
| 139 | - 'DTT_ID'=>$new_datetime['DTT_ID'], |
|
| 140 | - 'CHK_in'=>true, |
|
| 141 | - 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
|
| 142 | - ); |
|
| 143 | - $datatypes = array( |
|
| 144 | - '%d',// REG_ID |
|
| 145 | - '%d',// DTT_ID |
|
| 146 | - '%d',// CHK_in |
|
| 147 | - '%s',// CHK_timestamp |
|
| 148 | - ); |
|
| 149 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 150 | - if (! $success) { |
|
| 151 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 152 | - return 0; |
|
| 153 | - } |
|
| 154 | - $new_id = $wpdb->insert_id; |
|
| 155 | - return $new_id; |
|
| 156 | - } |
|
| 136 | + // ok we can actually do what we set out to do: add a checkin/checkout record |
|
| 137 | + $cols_n_values = array( |
|
| 138 | + 'REG_ID'=>$new_reg_id, |
|
| 139 | + 'DTT_ID'=>$new_datetime['DTT_ID'], |
|
| 140 | + 'CHK_in'=>true, |
|
| 141 | + 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
|
| 142 | + ); |
|
| 143 | + $datatypes = array( |
|
| 144 | + '%d',// REG_ID |
|
| 145 | + '%d',// DTT_ID |
|
| 146 | + '%d',// CHK_in |
|
| 147 | + '%s',// CHK_timestamp |
|
| 148 | + ); |
|
| 149 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 150 | + if (! $success) { |
|
| 151 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 152 | + return 0; |
|
| 153 | + } |
|
| 154 | + $new_id = $wpdb->insert_id; |
|
| 155 | + return $new_id; |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $this->_pretty_name = __("Checkins", "event_espresso"); |
| 34 | 34 | $this->_old_table = $wpdb->prefix."events_attendee"; |
| 35 | 35 | $this->_extra_where_sql = 'AS att |
| 36 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
| 36 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
| 37 | 37 | WHERE e.event_status!="D"'; |
| 38 | 38 | $this->_new_table = $wpdb->prefix."esp_checkin"; |
| 39 | 39 | parent::__construct(); |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | global $wpdb; |
| 44 | 44 | $new_reg_table = $wpdb->prefix."esp_registration"; |
| 45 | 45 | |
| 46 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 46 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']), intval($old_row['checked_in']))); |
|
| 47 | 47 | |
| 48 | 48 | $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
| 49 | - if (! $new_registrations_for_attendee) { |
|
| 49 | + if ( ! $new_registrations_for_attendee) { |
|
| 50 | 50 | $new_registrations_for_attendee = array(); |
| 51 | 51 | } |
| 52 | 52 | $new_datetime = $this->_try_to_find_datetime($old_row); |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
| 55 | 55 | $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
| 56 | 56 | $new_checkin_ids = array(); |
| 57 | - for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 59 | - if (! $new_reg_id) { |
|
| 57 | + for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | + $new_reg_id = $new_registrations_for_attendee[$i]; |
|
| 59 | + if ( ! $new_reg_id) { |
|
| 60 | 60 | $this->add_error(sprintf( |
| 61 | 61 | __('It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', "event_espresso"), |
| 62 | 62 | $this->_json_encode($old_row), |
@@ -67,14 +67,14 @@ discard block |
||
| 67 | 67 | break; |
| 68 | 68 | } |
| 69 | 69 | $new_last_checkin_record = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", $new_reg_id)); |
| 70 | - if (! $new_last_checkin_record) { |
|
| 70 | + if ( ! $new_last_checkin_record) { |
|
| 71 | 71 | $is_checked_in = false; |
| 72 | 72 | } else { |
| 73 | 73 | $is_checked_in = intval($new_last_checkin_record['CHK_in']); |
| 74 | 74 | } |
| 75 | 75 | $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
| 76 | 76 | if ($new_id) { |
| 77 | - $new_checkin_ids[]= $new_id; |
|
| 77 | + $new_checkin_ids[] = $new_id; |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | if ($new_checkin_ids) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | global $wpdb; |
| 97 | 97 | |
| 98 | 98 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
| 99 | - if (! $new_event_id) { |
|
| 99 | + if ( ! $new_event_id) { |
|
| 100 | 100 | $this->add_error(sprintf(__("Could nto find new event ID with old event id '%d', on attendee row %s; and because of that couldnt find the correct datetime for Check-in", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
| 101 | 101 | return 0; |
| 102 | 102 | } |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
| 109 | 109 | // the most important condition should be last, as it will be array_shift'ed off last |
| 110 | 110 | $conditions = array( |
| 111 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 112 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 111 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
| 112 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
| 113 | 113 | ); |
| 114 | 114 | // start running queries, widening search each time by removing a condition |
| 115 | 115 | $datetime_found = null; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
| 118 | 118 | $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
| 119 | 119 | array_shift($conditions); |
| 120 | - } while (! $datetime_found && $conditions); |
|
| 120 | + }while ( ! $datetime_found && $conditions); |
|
| 121 | 121 | return $datetime_found; |
| 122 | 122 | } |
| 123 | 123 | |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
| 142 | 142 | ); |
| 143 | 143 | $datatypes = array( |
| 144 | - '%d',// REG_ID |
|
| 145 | - '%d',// DTT_ID |
|
| 146 | - '%d',// CHK_in |
|
| 147 | - '%s',// CHK_timestamp |
|
| 144 | + '%d', // REG_ID |
|
| 145 | + '%d', // DTT_ID |
|
| 146 | + '%d', // CHK_in |
|
| 147 | + '%s', // CHK_timestamp |
|
| 148 | 148 | ); |
| 149 | 149 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
| 150 | - if (! $success) { |
|
| 150 | + if ( ! $success) { |
|
| 151 | 151 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
| 152 | 152 | return 0; |
| 153 | 153 | } |
@@ -38,171 +38,171 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class EE_DMS_4_1_0_line_items extends EE_Data_Migration_Script_Stage_Table |
| 40 | 40 | { |
| 41 | - private $_new_line_table; |
|
| 42 | - private $_new_transaction_table; |
|
| 43 | - private $_new_reg_table; |
|
| 44 | - public function __construct() |
|
| 45 | - { |
|
| 46 | - global $wpdb; |
|
| 47 | - $this->_pretty_name = __("Line Items", "event_espresso"); |
|
| 48 | - $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 49 | - $this->_extra_where_sql = ' AS att |
|
| 41 | + private $_new_line_table; |
|
| 42 | + private $_new_transaction_table; |
|
| 43 | + private $_new_reg_table; |
|
| 44 | + public function __construct() |
|
| 45 | + { |
|
| 46 | + global $wpdb; |
|
| 47 | + $this->_pretty_name = __("Line Items", "event_espresso"); |
|
| 48 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 49 | + $this->_extra_where_sql = ' AS att |
|
| 50 | 50 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
| 51 | 51 | WHERE e.event_status!="D"'; |
| 52 | - $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
| 53 | - $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
| 54 | - $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 55 | - parent::__construct(); |
|
| 56 | - } |
|
| 52 | + $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
| 53 | + $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
| 54 | + $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 55 | + parent::__construct(); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - protected function _migrate_old_row($old_row) |
|
| 59 | - { |
|
| 60 | - // insert line items if its a primary id |
|
| 61 | - if (intval($old_row['is_primary'])) { |
|
| 62 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
|
| 63 | - if (! $txn_id) { |
|
| 64 | - $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row))); |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - $txn = $this->_get_txn($txn_id); |
|
| 68 | - $new_line_items = $this->_insert_new_line_items($txn, $old_row); |
|
| 69 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_line_table, $new_line_items); |
|
| 70 | - } |
|
| 71 | - } |
|
| 58 | + protected function _migrate_old_row($old_row) |
|
| 59 | + { |
|
| 60 | + // insert line items if its a primary id |
|
| 61 | + if (intval($old_row['is_primary'])) { |
|
| 62 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
|
| 63 | + if (! $txn_id) { |
|
| 64 | + $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row))); |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + $txn = $this->_get_txn($txn_id); |
|
| 68 | + $new_line_items = $this->_insert_new_line_items($txn, $old_row); |
|
| 69 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_line_table, $new_line_items); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - private function _get_txn($txn_id) |
|
| 74 | - { |
|
| 75 | - global $wpdb; |
|
| 76 | - $txn = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_transaction_table WHERE TXN_ID=%d", $txn_id), ARRAY_A); |
|
| 77 | - return $txn; |
|
| 78 | - } |
|
| 73 | + private function _get_txn($txn_id) |
|
| 74 | + { |
|
| 75 | + global $wpdb; |
|
| 76 | + $txn = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_transaction_table WHERE TXN_ID=%d", $txn_id), ARRAY_A); |
|
| 77 | + return $txn; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * In 4.1, we'd normally need more info than just the registrations to make the line items. Ie, we'd need |
|
| 82 | - * the transaction, and tax prices at the time of registration. (And probably promotions and other price factors). |
|
| 83 | - * But seeing how these are REGs created from 3.1 attendee data, which have |
|
| 84 | - * @param array $transaction |
|
| 85 | - * @return array new line item ids |
|
| 86 | - */ |
|
| 87 | - private function _insert_new_line_items($transaction, $old_attendee) |
|
| 88 | - { |
|
| 89 | - global $wpdb; |
|
| 90 | - $regs_on_this_transaction = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_new_reg_table." WHERE TXN_ID=%d", $transaction['TXN_ID']), ARRAY_A); |
|
| 91 | - $new_line_item_ids = array(); |
|
| 92 | - // create a totla line item |
|
| 93 | - $total_line_item_id = $this->_insert_new_line_item(array( |
|
| 94 | - 'LIN_code'=>'total', |
|
| 95 | - 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 96 | - 'LIN_name'=> __("Total", "event_espresso"), |
|
| 97 | - 'LIN_total'=>$transaction['TXN_total'], |
|
| 98 | - 'LIN_type'=>'total', |
|
| 99 | - 'OBJ_ID'=>$transaction['TXN_ID'], |
|
| 100 | - 'OBJ_type'=>'Transaction' |
|
| 101 | - ), $old_attendee); |
|
| 102 | - $new_line_item_ids[] = $total_line_item_id; |
|
| 103 | - // create a subtotal line item |
|
| 104 | - $reg_total = 0; |
|
| 105 | - foreach ($regs_on_this_transaction as $new_reg) { |
|
| 106 | - $reg_total += floatval($new_reg['REG_final_price']); |
|
| 107 | - } |
|
| 108 | - $subtotal_line_item_id = $this->_insert_new_line_item(array( |
|
| 109 | - 'LIN_code'=>'sub-total', |
|
| 110 | - 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 111 | - 'LIN_name'=> __("Subtotal", "event_espresso"), |
|
| 112 | - 'LIN_total'=>$reg_total, |
|
| 113 | - 'LIN_parent'=>$total_line_item_id, |
|
| 114 | - 'LIN_type'=>'sub-total', |
|
| 115 | - ), $old_attendee); |
|
| 116 | - $new_line_item_ids[] = $subtotal_line_item_id; |
|
| 117 | - // group REGs by TKT_ID |
|
| 118 | - $regs_by_tkt = array(); |
|
| 119 | - foreach ($regs_on_this_transaction as $new_reg) { |
|
| 120 | - $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
| 121 | - } |
|
| 80 | + /** |
|
| 81 | + * In 4.1, we'd normally need more info than just the registrations to make the line items. Ie, we'd need |
|
| 82 | + * the transaction, and tax prices at the time of registration. (And probably promotions and other price factors). |
|
| 83 | + * But seeing how these are REGs created from 3.1 attendee data, which have |
|
| 84 | + * @param array $transaction |
|
| 85 | + * @return array new line item ids |
|
| 86 | + */ |
|
| 87 | + private function _insert_new_line_items($transaction, $old_attendee) |
|
| 88 | + { |
|
| 89 | + global $wpdb; |
|
| 90 | + $regs_on_this_transaction = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_new_reg_table." WHERE TXN_ID=%d", $transaction['TXN_ID']), ARRAY_A); |
|
| 91 | + $new_line_item_ids = array(); |
|
| 92 | + // create a totla line item |
|
| 93 | + $total_line_item_id = $this->_insert_new_line_item(array( |
|
| 94 | + 'LIN_code'=>'total', |
|
| 95 | + 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 96 | + 'LIN_name'=> __("Total", "event_espresso"), |
|
| 97 | + 'LIN_total'=>$transaction['TXN_total'], |
|
| 98 | + 'LIN_type'=>'total', |
|
| 99 | + 'OBJ_ID'=>$transaction['TXN_ID'], |
|
| 100 | + 'OBJ_type'=>'Transaction' |
|
| 101 | + ), $old_attendee); |
|
| 102 | + $new_line_item_ids[] = $total_line_item_id; |
|
| 103 | + // create a subtotal line item |
|
| 104 | + $reg_total = 0; |
|
| 105 | + foreach ($regs_on_this_transaction as $new_reg) { |
|
| 106 | + $reg_total += floatval($new_reg['REG_final_price']); |
|
| 107 | + } |
|
| 108 | + $subtotal_line_item_id = $this->_insert_new_line_item(array( |
|
| 109 | + 'LIN_code'=>'sub-total', |
|
| 110 | + 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 111 | + 'LIN_name'=> __("Subtotal", "event_espresso"), |
|
| 112 | + 'LIN_total'=>$reg_total, |
|
| 113 | + 'LIN_parent'=>$total_line_item_id, |
|
| 114 | + 'LIN_type'=>'sub-total', |
|
| 115 | + ), $old_attendee); |
|
| 116 | + $new_line_item_ids[] = $subtotal_line_item_id; |
|
| 117 | + // group REGs by TKT_ID |
|
| 118 | + $regs_by_tkt = array(); |
|
| 119 | + foreach ($regs_on_this_transaction as $new_reg) { |
|
| 120 | + $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - // create individual line items |
|
| 123 | + // create individual line items |
|
| 124 | 124 | |
| 125 | - foreach ($regs_by_tkt as $ticket_id => $regs) { |
|
| 126 | - $count = count($regs); |
|
| 127 | - $line_total = 0; |
|
| 128 | - foreach ($regs as $new_reg) { |
|
| 129 | - $line_total += $new_reg['REG_final_price']; |
|
| 130 | - } |
|
| 131 | - $a_reg = reset($regs); |
|
| 132 | - $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
|
| 133 | - $reg_line_item_id = $this->_insert_new_line_item(array( |
|
| 134 | - 'LIN_code'=> md5('Ticket' . $ticket_id . time()), |
|
| 135 | - 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 136 | - 'LIN_name'=>$new_ticket['TKT_name'], |
|
| 137 | - 'LIN_unit_price'=>$a_reg['REG_final_price'], |
|
| 138 | - 'LIN_is_taxable'=>false, |
|
| 139 | - 'LIN_total'=>$line_total, |
|
| 140 | - 'LIN_quantity'=>$count, |
|
| 141 | - 'LIN_parent'=>$subtotal_line_item_id, |
|
| 142 | - 'OBJ_ID'=>$ticket_id, |
|
| 143 | - 'OBJ_type'=>'Ticket' |
|
| 144 | - ), $old_attendee); |
|
| 145 | - $new_line_item_ids[] = $reg_line_item_id; |
|
| 146 | - } |
|
| 125 | + foreach ($regs_by_tkt as $ticket_id => $regs) { |
|
| 126 | + $count = count($regs); |
|
| 127 | + $line_total = 0; |
|
| 128 | + foreach ($regs as $new_reg) { |
|
| 129 | + $line_total += $new_reg['REG_final_price']; |
|
| 130 | + } |
|
| 131 | + $a_reg = reset($regs); |
|
| 132 | + $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
|
| 133 | + $reg_line_item_id = $this->_insert_new_line_item(array( |
|
| 134 | + 'LIN_code'=> md5('Ticket' . $ticket_id . time()), |
|
| 135 | + 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 136 | + 'LIN_name'=>$new_ticket['TKT_name'], |
|
| 137 | + 'LIN_unit_price'=>$a_reg['REG_final_price'], |
|
| 138 | + 'LIN_is_taxable'=>false, |
|
| 139 | + 'LIN_total'=>$line_total, |
|
| 140 | + 'LIN_quantity'=>$count, |
|
| 141 | + 'LIN_parent'=>$subtotal_line_item_id, |
|
| 142 | + 'OBJ_ID'=>$ticket_id, |
|
| 143 | + 'OBJ_type'=>'Ticket' |
|
| 144 | + ), $old_attendee); |
|
| 145 | + $new_line_item_ids[] = $reg_line_item_id; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | 148 | |
| 149 | 149 | |
| 150 | - return $new_line_item_ids; |
|
| 151 | - } |
|
| 152 | - /** |
|
| 153 | - * Gets the full ticket by ID |
|
| 154 | - * @global type $wpdb |
|
| 155 | - * @param type $new_ticket_id |
|
| 156 | - * @return array |
|
| 157 | - */ |
|
| 158 | - private function _get_new_ticket_row($new_ticket_id) |
|
| 159 | - { |
|
| 160 | - global $wpdb; |
|
| 161 | - $ticket_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."esp_ticket WHERE TKT_ID=%d", $new_ticket_id), ARRAY_A); |
|
| 162 | - return $ticket_row; |
|
| 163 | - } |
|
| 150 | + return $new_line_item_ids; |
|
| 151 | + } |
|
| 152 | + /** |
|
| 153 | + * Gets the full ticket by ID |
|
| 154 | + * @global type $wpdb |
|
| 155 | + * @param type $new_ticket_id |
|
| 156 | + * @return array |
|
| 157 | + */ |
|
| 158 | + private function _get_new_ticket_row($new_ticket_id) |
|
| 159 | + { |
|
| 160 | + global $wpdb; |
|
| 161 | + $ticket_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."esp_ticket WHERE TKT_ID=%d", $new_ticket_id), ARRAY_A); |
|
| 162 | + return $ticket_row; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - private function _insert_new_line_item($cols_n_values, $old_attendee) |
|
| 166 | - { |
|
| 167 | - global $wpdb; |
|
| 168 | - $default_cols_n_values = array( |
|
| 169 | - 'LIN_code'=>'', |
|
| 170 | - 'TXN_ID'=>0, |
|
| 171 | - 'LIN_name'=>'', |
|
| 172 | - 'LIN_desc'=>'', |
|
| 173 | - 'LIN_unit_price'=>0, |
|
| 174 | - 'LIN_percent'=>0, |
|
| 175 | - 'LIN_is_taxable'=>false, |
|
| 176 | - 'LIN_order'=>0, |
|
| 177 | - 'LIN_total'=>0, |
|
| 178 | - 'LIN_quantity'=>null, |
|
| 179 | - 'LIN_parent'=>0, |
|
| 180 | - 'LIN_type'=>'line-item', |
|
| 181 | - 'OBJ_ID'=>null, |
|
| 182 | - 'OBJ_type'=>null |
|
| 183 | - ); |
|
| 184 | - $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
|
| 185 | - $datatypes = array( |
|
| 186 | - '%s',// LIN_code |
|
| 187 | - '%d',// TXN_ID |
|
| 188 | - '%s',// LIN_name |
|
| 189 | - '%s',// LIN_desc |
|
| 190 | - '%f',// LIN_unit_price |
|
| 191 | - '%f',// LIN_percent |
|
| 192 | - '%d',// LIN_is_taxable |
|
| 193 | - '%d',// LIN_order |
|
| 194 | - '%f',// LIN_total |
|
| 195 | - '%d',// LIN_quantity |
|
| 196 | - '%d',// LIN_parent |
|
| 197 | - '%s',// LIN_type |
|
| 198 | - '%d',// OBJ_ID |
|
| 199 | - '%s',// OBJ_type |
|
| 200 | - ); |
|
| 201 | - $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes); |
|
| 202 | - if (! $success) { |
|
| 203 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
|
| 204 | - return 0; |
|
| 205 | - } |
|
| 206 | - return $wpdb->insert_id; |
|
| 207 | - } |
|
| 165 | + private function _insert_new_line_item($cols_n_values, $old_attendee) |
|
| 166 | + { |
|
| 167 | + global $wpdb; |
|
| 168 | + $default_cols_n_values = array( |
|
| 169 | + 'LIN_code'=>'', |
|
| 170 | + 'TXN_ID'=>0, |
|
| 171 | + 'LIN_name'=>'', |
|
| 172 | + 'LIN_desc'=>'', |
|
| 173 | + 'LIN_unit_price'=>0, |
|
| 174 | + 'LIN_percent'=>0, |
|
| 175 | + 'LIN_is_taxable'=>false, |
|
| 176 | + 'LIN_order'=>0, |
|
| 177 | + 'LIN_total'=>0, |
|
| 178 | + 'LIN_quantity'=>null, |
|
| 179 | + 'LIN_parent'=>0, |
|
| 180 | + 'LIN_type'=>'line-item', |
|
| 181 | + 'OBJ_ID'=>null, |
|
| 182 | + 'OBJ_type'=>null |
|
| 183 | + ); |
|
| 184 | + $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
|
| 185 | + $datatypes = array( |
|
| 186 | + '%s',// LIN_code |
|
| 187 | + '%d',// TXN_ID |
|
| 188 | + '%s',// LIN_name |
|
| 189 | + '%s',// LIN_desc |
|
| 190 | + '%f',// LIN_unit_price |
|
| 191 | + '%f',// LIN_percent |
|
| 192 | + '%d',// LIN_is_taxable |
|
| 193 | + '%d',// LIN_order |
|
| 194 | + '%f',// LIN_total |
|
| 195 | + '%d',// LIN_quantity |
|
| 196 | + '%d',// LIN_parent |
|
| 197 | + '%s',// LIN_type |
|
| 198 | + '%d',// OBJ_ID |
|
| 199 | + '%s',// OBJ_type |
|
| 200 | + ); |
|
| 201 | + $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes); |
|
| 202 | + if (! $success) { |
|
| 203 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
|
| 204 | + return 0; |
|
| 205 | + } |
|
| 206 | + return $wpdb->insert_id; |
|
| 207 | + } |
|
| 208 | 208 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $this->_pretty_name = __("Line Items", "event_espresso"); |
| 48 | 48 | $this->_old_table = $wpdb->prefix."events_attendee"; |
| 49 | 49 | $this->_extra_where_sql = ' AS att |
| 50 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
| 50 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
| 51 | 51 | WHERE e.event_status!="D"'; |
| 52 | 52 | $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
| 53 | 53 | $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | // insert line items if its a primary id |
| 61 | 61 | if (intval($old_row['is_primary'])) { |
| 62 | 62 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
| 63 | - if (! $txn_id) { |
|
| 63 | + if ( ! $txn_id) { |
|
| 64 | 64 | $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row))); |
| 65 | 65 | return; |
| 66 | 66 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | // group REGs by TKT_ID |
| 118 | 118 | $regs_by_tkt = array(); |
| 119 | 119 | foreach ($regs_on_this_transaction as $new_reg) { |
| 120 | - $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
| 120 | + $regs_by_tkt[$new_reg['TKT_ID']][] = $new_reg; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | // create individual line items |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $a_reg = reset($regs); |
| 132 | 132 | $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
| 133 | 133 | $reg_line_item_id = $this->_insert_new_line_item(array( |
| 134 | - 'LIN_code'=> md5('Ticket' . $ticket_id . time()), |
|
| 134 | + 'LIN_code'=> md5('Ticket'.$ticket_id.time()), |
|
| 135 | 135 | 'TXN_ID'=>$transaction['TXN_ID'], |
| 136 | 136 | 'LIN_name'=>$new_ticket['TKT_name'], |
| 137 | 137 | 'LIN_unit_price'=>$a_reg['REG_final_price'], |
@@ -183,23 +183,23 @@ discard block |
||
| 183 | 183 | ); |
| 184 | 184 | $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
| 185 | 185 | $datatypes = array( |
| 186 | - '%s',// LIN_code |
|
| 187 | - '%d',// TXN_ID |
|
| 188 | - '%s',// LIN_name |
|
| 189 | - '%s',// LIN_desc |
|
| 190 | - '%f',// LIN_unit_price |
|
| 191 | - '%f',// LIN_percent |
|
| 192 | - '%d',// LIN_is_taxable |
|
| 193 | - '%d',// LIN_order |
|
| 194 | - '%f',// LIN_total |
|
| 195 | - '%d',// LIN_quantity |
|
| 196 | - '%d',// LIN_parent |
|
| 197 | - '%s',// LIN_type |
|
| 198 | - '%d',// OBJ_ID |
|
| 199 | - '%s',// OBJ_type |
|
| 186 | + '%s', // LIN_code |
|
| 187 | + '%d', // TXN_ID |
|
| 188 | + '%s', // LIN_name |
|
| 189 | + '%s', // LIN_desc |
|
| 190 | + '%f', // LIN_unit_price |
|
| 191 | + '%f', // LIN_percent |
|
| 192 | + '%d', // LIN_is_taxable |
|
| 193 | + '%d', // LIN_order |
|
| 194 | + '%f', // LIN_total |
|
| 195 | + '%d', // LIN_quantity |
|
| 196 | + '%d', // LIN_parent |
|
| 197 | + '%s', // LIN_type |
|
| 198 | + '%d', // OBJ_ID |
|
| 199 | + '%s', // OBJ_type |
|
| 200 | 200 | ); |
| 201 | 201 | $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes); |
| 202 | - if (! $success) { |
|
| 202 | + if ( ! $success) { |
|
| 203 | 203 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
| 204 | 204 | return 0; |
| 205 | 205 | } |
@@ -87,56 +87,56 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | class EE_DMS_4_1_0_prices extends EE_Data_Migration_Script_Stage_Table |
| 89 | 89 | { |
| 90 | - private $_new_price_table; |
|
| 91 | - private $_new_ticket_table; |
|
| 92 | - private $_new_ticket_price_table; |
|
| 93 | - private $_new_datetime_ticket_table; |
|
| 94 | - /** |
|
| 95 | - * A count of all the different tickets created, used for setting the new ones' TKT_Order |
|
| 96 | - * @var int |
|
| 97 | - */ |
|
| 98 | - private $_ticket_count = 0; |
|
| 99 | - const price_type_base = 1; |
|
| 100 | - const price_type_member_discount = 3; |
|
| 101 | - const price_type_percent_surcharge = 4; |
|
| 102 | - const price_type_flat_surcharge = 5; |
|
| 90 | + private $_new_price_table; |
|
| 91 | + private $_new_ticket_table; |
|
| 92 | + private $_new_ticket_price_table; |
|
| 93 | + private $_new_datetime_ticket_table; |
|
| 94 | + /** |
|
| 95 | + * A count of all the different tickets created, used for setting the new ones' TKT_Order |
|
| 96 | + * @var int |
|
| 97 | + */ |
|
| 98 | + private $_ticket_count = 0; |
|
| 99 | + const price_type_base = 1; |
|
| 100 | + const price_type_member_discount = 3; |
|
| 101 | + const price_type_percent_surcharge = 4; |
|
| 102 | + const price_type_flat_surcharge = 5; |
|
| 103 | 103 | |
| 104 | - public function __construct() |
|
| 105 | - { |
|
| 106 | - global $wpdb; |
|
| 107 | - $this->_pretty_name = __("Prices", "event_espresso"); |
|
| 108 | - $this->_old_table = $wpdb->prefix."events_prices"; |
|
| 109 | - $this->_extra_where_sql = ' AS p |
|
| 104 | + public function __construct() |
|
| 105 | + { |
|
| 106 | + global $wpdb; |
|
| 107 | + $this->_pretty_name = __("Prices", "event_espresso"); |
|
| 108 | + $this->_old_table = $wpdb->prefix."events_prices"; |
|
| 109 | + $this->_extra_where_sql = ' AS p |
|
| 110 | 110 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id |
| 111 | 111 | WHERE e.event_status!="D"'; |
| 112 | - $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
| 113 | - $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 114 | - $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 115 | - $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 116 | - parent::__construct(); |
|
| 117 | - } |
|
| 118 | - protected function _migrate_old_row($old_row) |
|
| 119 | - { |
|
| 120 | - // create the base price |
|
| 121 | - $new_price_id = $this->_insert_new_price($old_row); |
|
| 122 | - // create the member discount if there is any |
|
| 123 | - // commented-out because we may actually NOT be supporting this in 4.1 |
|
| 112 | + $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
| 113 | + $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 114 | + $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 115 | + $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 116 | + parent::__construct(); |
|
| 117 | + } |
|
| 118 | + protected function _migrate_old_row($old_row) |
|
| 119 | + { |
|
| 120 | + // create the base price |
|
| 121 | + $new_price_id = $this->_insert_new_price($old_row); |
|
| 122 | + // create the member discount if there is any |
|
| 123 | + // commented-out because we may actually NOT be supporting this in 4.1 |
|
| 124 | 124 | // if($old_row['event_cost'] != $old_row['member_price']){ |
| 125 | 125 | // $member_price_discount_id = $this->_insert_new_member_price($old_row); |
| 126 | 126 | // }else{ |
| 127 | 127 | // $member_price_discount_id = 0; |
| 128 | 128 | // } |
| 129 | - // create the surcharge if there is any |
|
| 130 | - if (floatval($old_row['surcharge']) >= 0.01) { |
|
| 131 | - $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
|
| 132 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
| 133 | - } else { |
|
| 134 | - $surcharge_price_id = 0; |
|
| 135 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
|
| 136 | - } |
|
| 137 | - // associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice. |
|
| 138 | - // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one) |
|
| 139 | - // create ticket |
|
| 129 | + // create the surcharge if there is any |
|
| 130 | + if (floatval($old_row['surcharge']) >= 0.01) { |
|
| 131 | + $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
|
| 132 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
| 133 | + } else { |
|
| 134 | + $surcharge_price_id = 0; |
|
| 135 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
|
| 136 | + } |
|
| 137 | + // associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice. |
|
| 138 | + // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one) |
|
| 139 | + // create ticket |
|
| 140 | 140 | // $ticket_id = $this->_insert_new_ticket($old_row); |
| 141 | 141 | // if($ticket_id){ |
| 142 | 142 | // $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $ticket_id); |
@@ -148,62 +148,62 @@ discard block |
||
| 148 | 148 | // $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
| 149 | 149 | // } |
| 150 | 150 | // } |
| 151 | - // create a ticket for each old price -old datetime combo |
|
| 152 | - $tickets_for_old_price = array(); |
|
| 153 | - foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) { |
|
| 154 | - $ticket_id = $this->_insert_new_ticket($old_row); |
|
| 155 | - $tickets_for_old_price[] = $ticket_id; |
|
| 156 | - // associate to old prices |
|
| 157 | - $this->_insert_ticket_price_relation($ticket_id, $new_price_id); |
|
| 158 | - $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id); |
|
| 159 | - $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
|
| 160 | - } |
|
| 161 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price); |
|
| 162 | - } |
|
| 163 | - /** |
|
| 164 | - * Creates a 4.1 price base type |
|
| 165 | - * @global type $wpdb |
|
| 166 | - * @param type $old_price |
|
| 167 | - * @return int |
|
| 168 | - */ |
|
| 169 | - private function _insert_new_price($old_price) |
|
| 170 | - { |
|
| 171 | - global $wpdb; |
|
| 172 | - $cols_n_values = array( |
|
| 173 | - 'PRT_ID'=>self::price_type_base, |
|
| 174 | - 'PRC_amount'=>floatval($old_price['event_cost']), |
|
| 175 | - 'PRC_name'=>$old_price['price_type'], |
|
| 176 | - 'PRC_is_default'=>false, |
|
| 177 | - 'PRC_overrides'=>false, |
|
| 178 | - 'PRC_order'=>0, |
|
| 179 | - 'PRC_deleted'=>false, |
|
| 180 | - 'PRC_parent'=>null |
|
| 151 | + // create a ticket for each old price -old datetime combo |
|
| 152 | + $tickets_for_old_price = array(); |
|
| 153 | + foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) { |
|
| 154 | + $ticket_id = $this->_insert_new_ticket($old_row); |
|
| 155 | + $tickets_for_old_price[] = $ticket_id; |
|
| 156 | + // associate to old prices |
|
| 157 | + $this->_insert_ticket_price_relation($ticket_id, $new_price_id); |
|
| 158 | + $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id); |
|
| 159 | + $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
|
| 160 | + } |
|
| 161 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price); |
|
| 162 | + } |
|
| 163 | + /** |
|
| 164 | + * Creates a 4.1 price base type |
|
| 165 | + * @global type $wpdb |
|
| 166 | + * @param type $old_price |
|
| 167 | + * @return int |
|
| 168 | + */ |
|
| 169 | + private function _insert_new_price($old_price) |
|
| 170 | + { |
|
| 171 | + global $wpdb; |
|
| 172 | + $cols_n_values = array( |
|
| 173 | + 'PRT_ID'=>self::price_type_base, |
|
| 174 | + 'PRC_amount'=>floatval($old_price['event_cost']), |
|
| 175 | + 'PRC_name'=>$old_price['price_type'], |
|
| 176 | + 'PRC_is_default'=>false, |
|
| 177 | + 'PRC_overrides'=>false, |
|
| 178 | + 'PRC_order'=>0, |
|
| 179 | + 'PRC_deleted'=>false, |
|
| 180 | + 'PRC_parent'=>null |
|
| 181 | 181 | |
| 182 | - ); |
|
| 183 | - $datatypes = array( |
|
| 184 | - '%d',// PRT_ID |
|
| 185 | - '%f',// PRT_amount |
|
| 186 | - '%s',// PRC_name |
|
| 187 | - '%d',// PRC_is_default |
|
| 188 | - '%d',// PRC_overrides |
|
| 189 | - '%d',// PRC_order |
|
| 190 | - '%d',// PRC_deleted |
|
| 191 | - '%d',// PRC_parent |
|
| 192 | - ); |
|
| 193 | - $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 194 | - if (! $success) { |
|
| 195 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
| 196 | - return 0; |
|
| 197 | - } |
|
| 198 | - $new_id = $wpdb->insert_id; |
|
| 199 | - return $new_id; |
|
| 200 | - } |
|
| 201 | - /** |
|
| 202 | - * Creates a 4.1 member price discount |
|
| 203 | - * @global type $wpdb |
|
| 204 | - * @param type $old_price |
|
| 205 | - * @return int |
|
| 206 | - */ |
|
| 182 | + ); |
|
| 183 | + $datatypes = array( |
|
| 184 | + '%d',// PRT_ID |
|
| 185 | + '%f',// PRT_amount |
|
| 186 | + '%s',// PRC_name |
|
| 187 | + '%d',// PRC_is_default |
|
| 188 | + '%d',// PRC_overrides |
|
| 189 | + '%d',// PRC_order |
|
| 190 | + '%d',// PRC_deleted |
|
| 191 | + '%d',// PRC_parent |
|
| 192 | + ); |
|
| 193 | + $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 194 | + if (! $success) { |
|
| 195 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
| 196 | + return 0; |
|
| 197 | + } |
|
| 198 | + $new_id = $wpdb->insert_id; |
|
| 199 | + return $new_id; |
|
| 200 | + } |
|
| 201 | + /** |
|
| 202 | + * Creates a 4.1 member price discount |
|
| 203 | + * @global type $wpdb |
|
| 204 | + * @param type $old_price |
|
| 205 | + * @return int |
|
| 206 | + */ |
|
| 207 | 207 | // private function _insert_new_member_price($old_price){ |
| 208 | 208 | // $discount_amount = floatval($old_price['event_cost']) - floatval($old_price['member_price']); |
| 209 | 209 | // global $wpdb; |
@@ -236,207 +236,207 @@ discard block |
||
| 236 | 236 | // $new_id = $wpdb->insert_id; |
| 237 | 237 | // return $new_id; |
| 238 | 238 | // } |
| 239 | - /** |
|
| 240 | - * Creates a 4.1 member price discount |
|
| 241 | - * @global type $wpdb |
|
| 242 | - * @param type $old_price |
|
| 243 | - * @return int |
|
| 244 | - */ |
|
| 245 | - private function _insert_new_surcharge_price($old_price) |
|
| 246 | - { |
|
| 239 | + /** |
|
| 240 | + * Creates a 4.1 member price discount |
|
| 241 | + * @global type $wpdb |
|
| 242 | + * @param type $old_price |
|
| 243 | + * @return int |
|
| 244 | + */ |
|
| 245 | + private function _insert_new_surcharge_price($old_price) |
|
| 246 | + { |
|
| 247 | 247 | |
| 248 | - if ($old_price['surcharge_type'] == 'flat_rate') { |
|
| 249 | - $price_type = self::price_type_flat_surcharge; |
|
| 250 | - } else { |
|
| 251 | - $price_type = self::price_type_percent_surcharge; |
|
| 252 | - } |
|
| 253 | - global $wpdb; |
|
| 254 | - $cols_n_values = array( |
|
| 255 | - 'PRT_ID'=>$price_type, |
|
| 256 | - 'PRC_amount'=>floatval($old_price['surcharge']), |
|
| 257 | - 'PRC_name'=> __("Surcharge", "event_espresso"), |
|
| 258 | - 'PRC_is_default'=>false, |
|
| 259 | - 'PRC_overrides'=>false, |
|
| 260 | - 'PRC_order'=>20, |
|
| 261 | - 'PRC_deleted'=>false, |
|
| 262 | - 'PRC_parent'=>null |
|
| 248 | + if ($old_price['surcharge_type'] == 'flat_rate') { |
|
| 249 | + $price_type = self::price_type_flat_surcharge; |
|
| 250 | + } else { |
|
| 251 | + $price_type = self::price_type_percent_surcharge; |
|
| 252 | + } |
|
| 253 | + global $wpdb; |
|
| 254 | + $cols_n_values = array( |
|
| 255 | + 'PRT_ID'=>$price_type, |
|
| 256 | + 'PRC_amount'=>floatval($old_price['surcharge']), |
|
| 257 | + 'PRC_name'=> __("Surcharge", "event_espresso"), |
|
| 258 | + 'PRC_is_default'=>false, |
|
| 259 | + 'PRC_overrides'=>false, |
|
| 260 | + 'PRC_order'=>20, |
|
| 261 | + 'PRC_deleted'=>false, |
|
| 262 | + 'PRC_parent'=>null |
|
| 263 | 263 | |
| 264 | - ); |
|
| 265 | - $datatypes = array( |
|
| 266 | - '%d',// PRT_ID |
|
| 267 | - '%f',// PRT_amount |
|
| 268 | - '%s',// PRC_name |
|
| 269 | - '%d',// PRC_is_default |
|
| 270 | - '%d',// PRC_overrides |
|
| 271 | - '%d',// PRC_order |
|
| 272 | - '%d',// PRC_deleted |
|
| 273 | - '%d',// PRC_parent |
|
| 274 | - ); |
|
| 275 | - $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 276 | - if (! $success) { |
|
| 277 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
| 278 | - return 0; |
|
| 279 | - } |
|
| 280 | - $new_id = $wpdb->insert_id; |
|
| 281 | - return $new_id; |
|
| 282 | - } |
|
| 283 | - /** |
|
| 284 | - * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price |
|
| 285 | - * @param $old_price_row array where keys are columns |
|
| 286 | - * @param $new_base_price_id int |
|
| 287 | - * @param $new_member_discount_id int |
|
| 288 | - * @param $new_surcharge_id int |
|
| 289 | - * @return int new ticket id |
|
| 290 | - */ |
|
| 291 | - private function _insert_new_ticket($old_price_row) |
|
| 292 | - { |
|
| 293 | - global $wpdb; |
|
| 294 | - $event_row = $this->_get_event_row($old_price_row['event_id']); |
|
| 295 | - if ($old_price_row['surcharge_type'] == 'flat_rate') { |
|
| 296 | - $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
|
| 297 | - } else {// percent surcharge |
|
| 298 | - $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
| 299 | - } |
|
| 300 | - $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
|
| 301 | - $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
|
| 302 | - $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']); |
|
| 303 | - $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']); |
|
| 304 | - $cols_n_values = array( |
|
| 305 | - 'TTM_ID'=>0, |
|
| 306 | - 'TKT_name'=>$old_price_row['price_type'], |
|
| 307 | - 'TKT_description'=>'', |
|
| 308 | - 'TKT_start_date'=>$start_date_utc, |
|
| 309 | - 'TKT_end_date'=>$end_date_utc, |
|
| 310 | - 'TKT_min'=>0, |
|
| 311 | - 'TKT_max'=>-1, |
|
| 312 | - 'TKT_price'=>$final_ticket_price, |
|
| 313 | - 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
| 314 | - 'TKT_qty'=> -1, |
|
| 315 | - 'TKT_uses'=> 1, |
|
| 316 | - 'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
| 317 | - 'TKT_is_default'=>false, |
|
| 318 | - 'TKT_order'=>$this->_get_ticket_count(), |
|
| 319 | - 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
| 320 | - 'TKT_deleted'=>false, |
|
| 321 | - 'TKT_parent'=>0 |
|
| 264 | + ); |
|
| 265 | + $datatypes = array( |
|
| 266 | + '%d',// PRT_ID |
|
| 267 | + '%f',// PRT_amount |
|
| 268 | + '%s',// PRC_name |
|
| 269 | + '%d',// PRC_is_default |
|
| 270 | + '%d',// PRC_overrides |
|
| 271 | + '%d',// PRC_order |
|
| 272 | + '%d',// PRC_deleted |
|
| 273 | + '%d',// PRC_parent |
|
| 274 | + ); |
|
| 275 | + $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 276 | + if (! $success) { |
|
| 277 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
| 278 | + return 0; |
|
| 279 | + } |
|
| 280 | + $new_id = $wpdb->insert_id; |
|
| 281 | + return $new_id; |
|
| 282 | + } |
|
| 283 | + /** |
|
| 284 | + * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price |
|
| 285 | + * @param $old_price_row array where keys are columns |
|
| 286 | + * @param $new_base_price_id int |
|
| 287 | + * @param $new_member_discount_id int |
|
| 288 | + * @param $new_surcharge_id int |
|
| 289 | + * @return int new ticket id |
|
| 290 | + */ |
|
| 291 | + private function _insert_new_ticket($old_price_row) |
|
| 292 | + { |
|
| 293 | + global $wpdb; |
|
| 294 | + $event_row = $this->_get_event_row($old_price_row['event_id']); |
|
| 295 | + if ($old_price_row['surcharge_type'] == 'flat_rate') { |
|
| 296 | + $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
|
| 297 | + } else {// percent surcharge |
|
| 298 | + $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
| 299 | + } |
|
| 300 | + $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
|
| 301 | + $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
|
| 302 | + $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']); |
|
| 303 | + $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']); |
|
| 304 | + $cols_n_values = array( |
|
| 305 | + 'TTM_ID'=>0, |
|
| 306 | + 'TKT_name'=>$old_price_row['price_type'], |
|
| 307 | + 'TKT_description'=>'', |
|
| 308 | + 'TKT_start_date'=>$start_date_utc, |
|
| 309 | + 'TKT_end_date'=>$end_date_utc, |
|
| 310 | + 'TKT_min'=>0, |
|
| 311 | + 'TKT_max'=>-1, |
|
| 312 | + 'TKT_price'=>$final_ticket_price, |
|
| 313 | + 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
| 314 | + 'TKT_qty'=> -1, |
|
| 315 | + 'TKT_uses'=> 1, |
|
| 316 | + 'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
| 317 | + 'TKT_is_default'=>false, |
|
| 318 | + 'TKT_order'=>$this->_get_ticket_count(), |
|
| 319 | + 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
| 320 | + 'TKT_deleted'=>false, |
|
| 321 | + 'TKT_parent'=>0 |
|
| 322 | 322 | |
| 323 | - ); |
|
| 324 | - $datatypes = array( |
|
| 325 | - '%d',// TTM_ID |
|
| 326 | - '%s',// TKT_name |
|
| 327 | - '%s',// TKT_description |
|
| 328 | - '%s',// TKT_start_date |
|
| 329 | - '%s',// TKT_end_date |
|
| 330 | - '%d',// TKT_min |
|
| 331 | - '%d',// TKT_max |
|
| 332 | - '%f',// TKT_price |
|
| 333 | - '%d',// TKT_sold |
|
| 334 | - '%d',// TKT_qty |
|
| 335 | - '%d',// TKT_uses |
|
| 336 | - '%d',// TKT_taxable |
|
| 337 | - '%d',// TKT_is_default |
|
| 338 | - '%d',// TKT_order |
|
| 339 | - '%d',// TKT_row |
|
| 340 | - '%d',// TKT_deleted |
|
| 341 | - '%d',// TKT_parent |
|
| 342 | - ); |
|
| 343 | - $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
|
| 344 | - if (! $success) { |
|
| 345 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes)); |
|
| 346 | - return 0; |
|
| 347 | - } |
|
| 348 | - $new_id = $wpdb->insert_id; |
|
| 349 | - return $new_id; |
|
| 350 | - } |
|
| 323 | + ); |
|
| 324 | + $datatypes = array( |
|
| 325 | + '%d',// TTM_ID |
|
| 326 | + '%s',// TKT_name |
|
| 327 | + '%s',// TKT_description |
|
| 328 | + '%s',// TKT_start_date |
|
| 329 | + '%s',// TKT_end_date |
|
| 330 | + '%d',// TKT_min |
|
| 331 | + '%d',// TKT_max |
|
| 332 | + '%f',// TKT_price |
|
| 333 | + '%d',// TKT_sold |
|
| 334 | + '%d',// TKT_qty |
|
| 335 | + '%d',// TKT_uses |
|
| 336 | + '%d',// TKT_taxable |
|
| 337 | + '%d',// TKT_is_default |
|
| 338 | + '%d',// TKT_order |
|
| 339 | + '%d',// TKT_row |
|
| 340 | + '%d',// TKT_deleted |
|
| 341 | + '%d',// TKT_parent |
|
| 342 | + ); |
|
| 343 | + $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
|
| 344 | + if (! $success) { |
|
| 345 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes)); |
|
| 346 | + return 0; |
|
| 347 | + } |
|
| 348 | + $new_id = $wpdb->insert_id; |
|
| 349 | + return $new_id; |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - /** |
|
| 353 | - * Adds a join between a ticket and a price |
|
| 354 | - * @global type $wpdb |
|
| 355 | - * @param type $new_ticket_id |
|
| 356 | - * @param type $new_price_id |
|
| 357 | - * @return int |
|
| 358 | - */ |
|
| 359 | - private function _insert_ticket_price_relation($new_ticket_id, $new_price_id) |
|
| 360 | - { |
|
| 361 | - global $wpdb; |
|
| 362 | - $cols_n_values = array( |
|
| 363 | - 'TKT_ID'=>$new_ticket_id, |
|
| 364 | - 'PRC_ID'=>$new_price_id, |
|
| 365 | - ); |
|
| 366 | - $datatypes = array( |
|
| 367 | - '%d',// TKT_ID |
|
| 368 | - '%d',// PRC_ID |
|
| 369 | - ); |
|
| 370 | - $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
|
| 371 | - if (! $success) { |
|
| 372 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
| 373 | - return 0; |
|
| 374 | - } |
|
| 375 | - $new_id = $wpdb->insert_id; |
|
| 376 | - return $new_id; |
|
| 377 | - } |
|
| 352 | + /** |
|
| 353 | + * Adds a join between a ticket and a price |
|
| 354 | + * @global type $wpdb |
|
| 355 | + * @param type $new_ticket_id |
|
| 356 | + * @param type $new_price_id |
|
| 357 | + * @return int |
|
| 358 | + */ |
|
| 359 | + private function _insert_ticket_price_relation($new_ticket_id, $new_price_id) |
|
| 360 | + { |
|
| 361 | + global $wpdb; |
|
| 362 | + $cols_n_values = array( |
|
| 363 | + 'TKT_ID'=>$new_ticket_id, |
|
| 364 | + 'PRC_ID'=>$new_price_id, |
|
| 365 | + ); |
|
| 366 | + $datatypes = array( |
|
| 367 | + '%d',// TKT_ID |
|
| 368 | + '%d',// PRC_ID |
|
| 369 | + ); |
|
| 370 | + $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
|
| 371 | + if (! $success) { |
|
| 372 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
| 373 | + return 0; |
|
| 374 | + } |
|
| 375 | + $new_id = $wpdb->insert_id; |
|
| 376 | + return $new_id; |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Adds a join between a ticket and a datetime |
|
| 381 | - * @global type $wpdb |
|
| 382 | - * @param type $new_ticket_id |
|
| 383 | - * @param type $new_price_id |
|
| 384 | - * @return int |
|
| 385 | - */ |
|
| 386 | - private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id) |
|
| 387 | - { |
|
| 388 | - global $wpdb; |
|
| 389 | - $cols_n_values = array( |
|
| 390 | - 'TKT_ID'=>$new_ticket_id, |
|
| 391 | - 'DTT_ID'=>$new_datetime_id, |
|
| 392 | - ); |
|
| 393 | - $datatypes = array( |
|
| 394 | - '%d',// TKT_ID |
|
| 395 | - '%d',// DTT_ID |
|
| 396 | - ); |
|
| 397 | - $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
|
| 398 | - if (! $success) { |
|
| 399 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
| 400 | - return 0; |
|
| 401 | - } |
|
| 402 | - $new_id = $wpdb->insert_id; |
|
| 403 | - return $new_id; |
|
| 404 | - } |
|
| 379 | + /** |
|
| 380 | + * Adds a join between a ticket and a datetime |
|
| 381 | + * @global type $wpdb |
|
| 382 | + * @param type $new_ticket_id |
|
| 383 | + * @param type $new_price_id |
|
| 384 | + * @return int |
|
| 385 | + */ |
|
| 386 | + private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id) |
|
| 387 | + { |
|
| 388 | + global $wpdb; |
|
| 389 | + $cols_n_values = array( |
|
| 390 | + 'TKT_ID'=>$new_ticket_id, |
|
| 391 | + 'DTT_ID'=>$new_datetime_id, |
|
| 392 | + ); |
|
| 393 | + $datatypes = array( |
|
| 394 | + '%d',// TKT_ID |
|
| 395 | + '%d',// DTT_ID |
|
| 396 | + ); |
|
| 397 | + $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
|
| 398 | + if (! $success) { |
|
| 399 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
| 400 | + return 0; |
|
| 401 | + } |
|
| 402 | + $new_id = $wpdb->insert_id; |
|
| 403 | + return $new_id; |
|
| 404 | + } |
|
| 405 | 405 | |
| 406 | - /** |
|
| 407 | - * Simply gets the 3.1 event row data |
|
| 408 | - * @global type $wpdb |
|
| 409 | - * @param type $event_id |
|
| 410 | - * @return array |
|
| 411 | - */ |
|
| 412 | - private function _get_event_row($event_id) |
|
| 413 | - { |
|
| 414 | - global $wpdb; |
|
| 415 | - $old_event_table = $wpdb->prefix."events_detail"; |
|
| 416 | - return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A); |
|
| 417 | - } |
|
| 418 | - /** |
|
| 419 | - * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests). |
|
| 420 | - * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too |
|
| 421 | - * @return int |
|
| 422 | - */ |
|
| 423 | - private function _get_ticket_count() |
|
| 424 | - { |
|
| 425 | - return $this->_ticket_count++; |
|
| 426 | - } |
|
| 406 | + /** |
|
| 407 | + * Simply gets the 3.1 event row data |
|
| 408 | + * @global type $wpdb |
|
| 409 | + * @param type $event_id |
|
| 410 | + * @return array |
|
| 411 | + */ |
|
| 412 | + private function _get_event_row($event_id) |
|
| 413 | + { |
|
| 414 | + global $wpdb; |
|
| 415 | + $old_event_table = $wpdb->prefix."events_detail"; |
|
| 416 | + return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A); |
|
| 417 | + } |
|
| 418 | + /** |
|
| 419 | + * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests). |
|
| 420 | + * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too |
|
| 421 | + * @return int |
|
| 422 | + */ |
|
| 423 | + private function _get_ticket_count() |
|
| 424 | + { |
|
| 425 | + return $this->_ticket_count++; |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | - /** |
|
| 429 | - * Using the 3.1 event id, gets the 4.1 datetimes for it |
|
| 430 | - * @param int $old_event_id |
|
| 431 | - * @return array where values are datetime ids |
|
| 432 | - */ |
|
| 433 | - private function _get_datetime_ids_for_old_event_id($old_event_id) |
|
| 434 | - { |
|
| 435 | - global $wpdb; |
|
| 436 | - $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts); |
|
| 437 | - $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id)); |
|
| 438 | - return $datetime_ids; |
|
| 439 | - } |
|
| 428 | + /** |
|
| 429 | + * Using the 3.1 event id, gets the 4.1 datetimes for it |
|
| 430 | + * @param int $old_event_id |
|
| 431 | + * @return array where values are datetime ids |
|
| 432 | + */ |
|
| 433 | + private function _get_datetime_ids_for_old_event_id($old_event_id) |
|
| 434 | + { |
|
| 435 | + global $wpdb; |
|
| 436 | + $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts); |
|
| 437 | + $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id)); |
|
| 438 | + return $datetime_ids; |
|
| 439 | + } |
|
| 440 | 440 | } |
| 441 | 441 | // @todo: tell users that in 3.1 the limit was on registration PER event,in 4.1 it's limit PER TICKET... SO, if they sell 2 different types of tickets |
| 442 | 442 | // |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | $this->_pretty_name = __("Prices", "event_espresso"); |
| 108 | 108 | $this->_old_table = $wpdb->prefix."events_prices"; |
| 109 | 109 | $this->_extra_where_sql = ' AS p |
| 110 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id |
|
| 110 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON p.event_id=e.id |
|
| 111 | 111 | WHERE e.event_status!="D"'; |
| 112 | 112 | $this->_new_price_table = $wpdb->prefix."esp_price"; |
| 113 | 113 | $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | // create the surcharge if there is any |
| 130 | 130 | if (floatval($old_row['surcharge']) >= 0.01) { |
| 131 | 131 | $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
| 132 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
| 132 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id, $surcharge_price_id)); |
|
| 133 | 133 | } else { |
| 134 | 134 | $surcharge_price_id = 0; |
| 135 | 135 | $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
@@ -181,17 +181,17 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | ); |
| 183 | 183 | $datatypes = array( |
| 184 | - '%d',// PRT_ID |
|
| 185 | - '%f',// PRT_amount |
|
| 186 | - '%s',// PRC_name |
|
| 187 | - '%d',// PRC_is_default |
|
| 188 | - '%d',// PRC_overrides |
|
| 189 | - '%d',// PRC_order |
|
| 190 | - '%d',// PRC_deleted |
|
| 191 | - '%d',// PRC_parent |
|
| 184 | + '%d', // PRT_ID |
|
| 185 | + '%f', // PRT_amount |
|
| 186 | + '%s', // PRC_name |
|
| 187 | + '%d', // PRC_is_default |
|
| 188 | + '%d', // PRC_overrides |
|
| 189 | + '%d', // PRC_order |
|
| 190 | + '%d', // PRC_deleted |
|
| 191 | + '%d', // PRC_parent |
|
| 192 | 192 | ); |
| 193 | 193 | $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
| 194 | - if (! $success) { |
|
| 194 | + if ( ! $success) { |
|
| 195 | 195 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
| 196 | 196 | return 0; |
| 197 | 197 | } |
@@ -263,17 +263,17 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | ); |
| 265 | 265 | $datatypes = array( |
| 266 | - '%d',// PRT_ID |
|
| 267 | - '%f',// PRT_amount |
|
| 268 | - '%s',// PRC_name |
|
| 269 | - '%d',// PRC_is_default |
|
| 270 | - '%d',// PRC_overrides |
|
| 271 | - '%d',// PRC_order |
|
| 272 | - '%d',// PRC_deleted |
|
| 273 | - '%d',// PRC_parent |
|
| 266 | + '%d', // PRT_ID |
|
| 267 | + '%f', // PRT_amount |
|
| 268 | + '%s', // PRC_name |
|
| 269 | + '%d', // PRC_is_default |
|
| 270 | + '%d', // PRC_overrides |
|
| 271 | + '%d', // PRC_order |
|
| 272 | + '%d', // PRC_deleted |
|
| 273 | + '%d', // PRC_parent |
|
| 274 | 274 | ); |
| 275 | 275 | $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
| 276 | - if (! $success) { |
|
| 276 | + if ( ! $success) { |
|
| 277 | 277 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
| 278 | 278 | return 0; |
| 279 | 279 | } |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | if ($old_price_row['surcharge_type'] == 'flat_rate') { |
| 296 | 296 | $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
| 297 | 297 | } else {// percent surcharge |
| 298 | - $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
| 298 | + $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge']) / 100); |
|
| 299 | 299 | } |
| 300 | 300 | $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
| 301 | 301 | $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
@@ -310,38 +310,38 @@ discard block |
||
| 310 | 310 | 'TKT_min'=>0, |
| 311 | 311 | 'TKT_max'=>-1, |
| 312 | 312 | 'TKT_price'=>$final_ticket_price, |
| 313 | - 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
| 313 | + 'TKT_sold'=> 0, // note: this will get calculated as we actually add registrations during the migration |
|
| 314 | 314 | 'TKT_qty'=> -1, |
| 315 | 315 | 'TKT_uses'=> 1, |
| 316 | - 'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
| 316 | + 'TKT_taxable'=>false, // so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
| 317 | 317 | 'TKT_is_default'=>false, |
| 318 | 318 | 'TKT_order'=>$this->_get_ticket_count(), |
| 319 | - 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
| 319 | + 'TKT_row'=>0, // doesn't matter because UI reset this on first save anyways |
|
| 320 | 320 | 'TKT_deleted'=>false, |
| 321 | 321 | 'TKT_parent'=>0 |
| 322 | 322 | |
| 323 | 323 | ); |
| 324 | 324 | $datatypes = array( |
| 325 | - '%d',// TTM_ID |
|
| 326 | - '%s',// TKT_name |
|
| 327 | - '%s',// TKT_description |
|
| 328 | - '%s',// TKT_start_date |
|
| 329 | - '%s',// TKT_end_date |
|
| 330 | - '%d',// TKT_min |
|
| 331 | - '%d',// TKT_max |
|
| 332 | - '%f',// TKT_price |
|
| 333 | - '%d',// TKT_sold |
|
| 334 | - '%d',// TKT_qty |
|
| 335 | - '%d',// TKT_uses |
|
| 336 | - '%d',// TKT_taxable |
|
| 337 | - '%d',// TKT_is_default |
|
| 338 | - '%d',// TKT_order |
|
| 339 | - '%d',// TKT_row |
|
| 340 | - '%d',// TKT_deleted |
|
| 341 | - '%d',// TKT_parent |
|
| 325 | + '%d', // TTM_ID |
|
| 326 | + '%s', // TKT_name |
|
| 327 | + '%s', // TKT_description |
|
| 328 | + '%s', // TKT_start_date |
|
| 329 | + '%s', // TKT_end_date |
|
| 330 | + '%d', // TKT_min |
|
| 331 | + '%d', // TKT_max |
|
| 332 | + '%f', // TKT_price |
|
| 333 | + '%d', // TKT_sold |
|
| 334 | + '%d', // TKT_qty |
|
| 335 | + '%d', // TKT_uses |
|
| 336 | + '%d', // TKT_taxable |
|
| 337 | + '%d', // TKT_is_default |
|
| 338 | + '%d', // TKT_order |
|
| 339 | + '%d', // TKT_row |
|
| 340 | + '%d', // TKT_deleted |
|
| 341 | + '%d', // TKT_parent |
|
| 342 | 342 | ); |
| 343 | 343 | $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
| 344 | - if (! $success) { |
|
| 344 | + if ( ! $success) { |
|
| 345 | 345 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes)); |
| 346 | 346 | return 0; |
| 347 | 347 | } |
@@ -364,12 +364,12 @@ discard block |
||
| 364 | 364 | 'PRC_ID'=>$new_price_id, |
| 365 | 365 | ); |
| 366 | 366 | $datatypes = array( |
| 367 | - '%d',// TKT_ID |
|
| 368 | - '%d',// PRC_ID |
|
| 367 | + '%d', // TKT_ID |
|
| 368 | + '%d', // PRC_ID |
|
| 369 | 369 | ); |
| 370 | 370 | $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
| 371 | - if (! $success) { |
|
| 372 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
| 371 | + if ( ! $success) { |
|
| 372 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
| 373 | 373 | return 0; |
| 374 | 374 | } |
| 375 | 375 | $new_id = $wpdb->insert_id; |
@@ -391,12 +391,12 @@ discard block |
||
| 391 | 391 | 'DTT_ID'=>$new_datetime_id, |
| 392 | 392 | ); |
| 393 | 393 | $datatypes = array( |
| 394 | - '%d',// TKT_ID |
|
| 395 | - '%d',// DTT_ID |
|
| 394 | + '%d', // TKT_ID |
|
| 395 | + '%d', // DTT_ID |
|
| 396 | 396 | ); |
| 397 | 397 | $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
| 398 | - if (! $success) { |
|
| 399 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
| 398 | + if ( ! $success) { |
|
| 399 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
| 400 | 400 | return 0; |
| 401 | 401 | } |
| 402 | 402 | $new_id = $wpdb->insert_id; |