@@ -3,7 +3,6 @@ |
||
| 3 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
| 4 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 5 | 5 | use EventEspresso\core\interfaces\ResettableInterface; |
| 6 | - |
|
| 7 | 6 | use EventEspresso\core\services\database\TableManager; |
| 8 | 7 | use EventEspresso\core\services\database\TableAnalysis; |
| 9 | 8 | |
@@ -136,9 +136,9 @@ discard block |
||
| 136 | 136 | protected $script_migration_versions; |
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | - * @var EE_Data_Migration_Manager $_instance |
|
| 139 | + * @var EE_Data_Migration_Manager $_instance |
|
| 140 | 140 | * @access private |
| 141 | - */ |
|
| 141 | + */ |
|
| 142 | 142 | private static $_instance = NULL; |
| 143 | 143 | |
| 144 | 144 | |
@@ -322,9 +322,9 @@ discard block |
||
| 322 | 322 | */ |
| 323 | 323 | public function get_data_migration_script_folders(){ |
| 324 | 324 | return apply_filters( |
| 325 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 326 | - array('Core' => EE_CORE.'data_migration_scripts') |
|
| 327 | - ); |
|
| 325 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 326 | + array('Core' => EE_CORE.'data_migration_scripts') |
|
| 327 | + ); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -337,15 +337,15 @@ discard block |
||
| 337 | 337 | * @throws EE_Error |
| 338 | 338 | */ |
| 339 | 339 | public function script_migrates_to_version($migration_script_name, $eeAddonClass = ''){ |
| 340 | - if(isset($this->script_migration_versions[ $migration_script_name ])){ |
|
| 341 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 342 | - } |
|
| 340 | + if(isset($this->script_migration_versions[ $migration_script_name ])){ |
|
| 341 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
| 342 | + } |
|
| 343 | 343 | $dms_info = $this->parse_dms_classname($migration_script_name); |
| 344 | - $this->script_migration_versions[ $migration_script_name ] = array( |
|
| 344 | + $this->script_migration_versions[ $migration_script_name ] = array( |
|
| 345 | 345 | 'slug'=> $eeAddonClass !== '' ? $eeAddonClass : $dms_info[ 'slug' ], |
| 346 | 346 | 'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] |
| 347 | - ); |
|
| 348 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 347 | + ); |
|
| 348 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -736,60 +736,60 @@ discard block |
||
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | - /** |
|
| 740 | - * Gets all the data migration scripts available in the core folder and folders |
|
| 741 | - * in addons. Has the side effect of adding them for autoloading |
|
| 742 | - * |
|
| 743 | - * @return array keys are expected classnames, values are their filepaths |
|
| 744 | - * @throws InvalidInterfaceException |
|
| 745 | - * @throws InvalidDataTypeException |
|
| 746 | - * @throws EE_Error |
|
| 747 | - * @throws InvalidArgumentException |
|
| 748 | - */ |
|
| 749 | - public function get_all_data_migration_scripts_available() |
|
| 750 | - { |
|
| 751 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
| 752 | - $this->_data_migration_class_to_filepath_map = array(); |
|
| 753 | - foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
| 754 | - // strip any placeholders added to classname to make it a unique array key |
|
| 755 | - $eeAddonClass = trim($eeAddonClass, '*'); |
|
| 756 | - $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
| 757 | - ? $eeAddonClass |
|
| 758 | - : ''; |
|
| 759 | - $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
| 760 | - $files = glob($folder_path . '*.dms.php'); |
|
| 761 | - if (empty($files)) { |
|
| 762 | - continue; |
|
| 763 | - } |
|
| 764 | - foreach ($files as $file) { |
|
| 765 | - $pos_of_last_slash = strrpos($file, DS); |
|
| 766 | - $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
| 767 | - $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
| 768 | - $slug = $migrates_to['slug']; |
|
| 769 | - //check that the slug as contained in the DMS is associated with |
|
| 770 | - //the slug of an addon or core |
|
| 771 | - if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
| 772 | - EE_Error::doing_it_wrong( |
|
| 773 | - __FUNCTION__, |
|
| 774 | - sprintf( |
|
| 775 | - esc_html__( |
|
| 776 | - 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
| 777 | - 'event_espresso' |
|
| 778 | - ), |
|
| 779 | - $classname, |
|
| 780 | - $slug, |
|
| 781 | - implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
| 782 | - ), |
|
| 783 | - '4.3.0.alpha.019' |
|
| 784 | - ); |
|
| 785 | - } |
|
| 786 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
| 790 | - } |
|
| 791 | - return $this->_data_migration_class_to_filepath_map; |
|
| 792 | - } |
|
| 739 | + /** |
|
| 740 | + * Gets all the data migration scripts available in the core folder and folders |
|
| 741 | + * in addons. Has the side effect of adding them for autoloading |
|
| 742 | + * |
|
| 743 | + * @return array keys are expected classnames, values are their filepaths |
|
| 744 | + * @throws InvalidInterfaceException |
|
| 745 | + * @throws InvalidDataTypeException |
|
| 746 | + * @throws EE_Error |
|
| 747 | + * @throws InvalidArgumentException |
|
| 748 | + */ |
|
| 749 | + public function get_all_data_migration_scripts_available() |
|
| 750 | + { |
|
| 751 | + if (! $this->_data_migration_class_to_filepath_map) { |
|
| 752 | + $this->_data_migration_class_to_filepath_map = array(); |
|
| 753 | + foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
| 754 | + // strip any placeholders added to classname to make it a unique array key |
|
| 755 | + $eeAddonClass = trim($eeAddonClass, '*'); |
|
| 756 | + $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
| 757 | + ? $eeAddonClass |
|
| 758 | + : ''; |
|
| 759 | + $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
| 760 | + $files = glob($folder_path . '*.dms.php'); |
|
| 761 | + if (empty($files)) { |
|
| 762 | + continue; |
|
| 763 | + } |
|
| 764 | + foreach ($files as $file) { |
|
| 765 | + $pos_of_last_slash = strrpos($file, DS); |
|
| 766 | + $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
| 767 | + $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
| 768 | + $slug = $migrates_to['slug']; |
|
| 769 | + //check that the slug as contained in the DMS is associated with |
|
| 770 | + //the slug of an addon or core |
|
| 771 | + if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
| 772 | + EE_Error::doing_it_wrong( |
|
| 773 | + __FUNCTION__, |
|
| 774 | + sprintf( |
|
| 775 | + esc_html__( |
|
| 776 | + 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
| 777 | + 'event_espresso' |
|
| 778 | + ), |
|
| 779 | + $classname, |
|
| 780 | + $slug, |
|
| 781 | + implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
| 782 | + ), |
|
| 783 | + '4.3.0.alpha.019' |
|
| 784 | + ); |
|
| 785 | + } |
|
| 786 | + $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
| 790 | + } |
|
| 791 | + return $this->_data_migration_class_to_filepath_map; |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | 794 | |
| 795 | 795 | |
@@ -961,12 +961,12 @@ discard block |
||
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | /** |
| 964 | - * Resets the borked data migration scripts so they're no longer borked |
|
| 965 | - * so we can again attempt to migrate |
|
| 966 | - * |
|
| 967 | - * @return bool |
|
| 968 | - * @throws EE_Error |
|
| 969 | - */ |
|
| 964 | + * Resets the borked data migration scripts so they're no longer borked |
|
| 965 | + * so we can again attempt to migrate |
|
| 966 | + * |
|
| 967 | + * @return bool |
|
| 968 | + * @throws EE_Error |
|
| 969 | + */ |
|
| 970 | 970 | public function reattempt(){ |
| 971 | 971 | //find if the last-ran script was borked |
| 972 | 972 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * of this EE installation. Keys should be the name of the version the script upgraded to |
| 86 | 86 | * @var EE_Data_Migration_Script_Base[] |
| 87 | 87 | */ |
| 88 | - private $_data_migrations_ran =null; |
|
| 88 | + private $_data_migrations_ran = null; |
|
| 89 | 89 | /** |
| 90 | 90 | * The last ran script. It's nice to store this somewhere accessible, as its easiest |
| 91 | 91 | * to know which was the last run by which is the newest wp option; but in most of the code |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | public static function instance() { |
| 152 | 152 | // check if class object is instantiated |
| 153 | - if ( ! self::$_instance instanceof EE_Data_Migration_Manager ) { |
|
| 153 | + if ( ! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
| 154 | 154 | self::$_instance = new self(); |
| 155 | 155 | } |
| 156 | 156 | return self::$_instance; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * all new usages of the singleton should be made with Classname::instance()) and returns it |
| 161 | 161 | * @return EE_Data_Migration_Manager |
| 162 | 162 | */ |
| 163 | - public static function reset(){ |
|
| 163 | + public static function reset() { |
|
| 164 | 164 | self::$_instance = NULL; |
| 165 | 165 | return self::instance(); |
| 166 | 166 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | /** |
| 171 | 171 | * constructor |
| 172 | 172 | */ |
| 173 | - private function __construct(){ |
|
| 173 | + private function __construct() { |
|
| 174 | 174 | $this->stati_that_indicate_to_continue_migrations = array( |
| 175 | 175 | self::status_continue, |
| 176 | 176 | self::status_completed |
@@ -189,13 +189,13 @@ discard block |
||
| 189 | 189 | ); |
| 190 | 190 | //make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
| 191 | 191 | //to be defined, because right now it doesn't get autoloaded on its own |
| 192 | - EE_Registry::instance()->load_core( 'Data_Migration_Class_Base', array(), TRUE ); |
|
| 193 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Base', array(), TRUE ); |
|
| 194 | - EE_Registry::instance()->load_core( 'DMS_Unknown_1_0_0', array(), TRUE ); |
|
| 195 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage', array(), TRUE ); |
|
| 196 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage_Table', array(), TRUE ); |
|
| 197 | - $this->_table_manager = EE_Registry::instance()->create( 'TableManager', array(), true ); |
|
| 198 | - $this->_table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
|
| 192 | + EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), TRUE); |
|
| 193 | + EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), TRUE); |
|
| 194 | + EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), TRUE); |
|
| 195 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), TRUE); |
|
| 196 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), TRUE); |
|
| 197 | + $this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 198 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | |
@@ -208,21 +208,21 @@ discard block |
||
| 208 | 208 | * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
| 209 | 209 | * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of that plugin (eg '4.1.0') |
| 210 | 210 | */ |
| 211 | - private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name){ |
|
| 211 | + private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) { |
|
| 212 | 212 | $plugin_slug_and_version_string = str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_name); |
| 213 | 213 | //check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
| 214 | - $parts = explode(".",$plugin_slug_and_version_string); |
|
| 214 | + $parts = explode(".", $plugin_slug_and_version_string); |
|
| 215 | 215 | |
| 216 | - if(count($parts) == 4){ |
|
| 216 | + if (count($parts) == 4) { |
|
| 217 | 217 | //it's 4.2-style.eg Core.4.1.0 |
| 218 | - $plugin_slug = $parts[0];//eg Core |
|
| 218 | + $plugin_slug = $parts[0]; //eg Core |
|
| 219 | 219 | $version_string = $parts[1].".".$parts[2].".".$parts[3]; //eg 4.1.0 |
| 220 | - }else{ |
|
| 220 | + } else { |
|
| 221 | 221 | //it's 4.1-style: eg 4.1.0 |
| 222 | 222 | $plugin_slug = 'Core'; |
| 223 | - $version_string = $plugin_slug_and_version_string;//eg 4.1.0 |
|
| 223 | + $version_string = $plugin_slug_and_version_string; //eg 4.1.0 |
|
| 224 | 224 | } |
| 225 | - return array($plugin_slug,$version_string); |
|
| 225 | + return array($plugin_slug, $version_string); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -233,21 +233,21 @@ discard block |
||
| 233 | 233 | * @return EE_Data_Migration_Script_Base |
| 234 | 234 | * @throws EE_Error |
| 235 | 235 | */ |
| 236 | - private function _get_dms_class_from_wp_option($dms_option_name,$dms_option_value){ |
|
| 236 | + private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) { |
|
| 237 | 237 | $data_migration_data = maybe_unserialize($dms_option_value); |
| 238 | - if(isset($data_migration_data['class']) && class_exists($data_migration_data['class'])){ |
|
| 238 | + if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
| 239 | 239 | $class = new $data_migration_data['class']; |
| 240 | - if($class instanceof EE_Data_Migration_Script_Base){ |
|
| 240 | + if ($class instanceof EE_Data_Migration_Script_Base) { |
|
| 241 | 241 | $class->instantiate_from_array_of_properties($data_migration_data); |
| 242 | 242 | return $class; |
| 243 | - }else{ |
|
| 243 | + } else { |
|
| 244 | 244 | //huh, so its an object but not a data migration script?? that shouldn't happen |
| 245 | 245 | //just leave it as an array (which will probably just get ignored) |
| 246 | - throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'),$data_migration_data['class'])); |
|
| 246 | + throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'), $data_migration_data['class'])); |
|
| 247 | 247 | } |
| 248 | - }else{ |
|
| 248 | + } else { |
|
| 249 | 249 | //so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
| 250 | - throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'),$dms_option_name)); |
|
| 250 | + throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name)); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | /** |
@@ -255,34 +255,34 @@ discard block |
||
| 255 | 255 | * the last ran which hasn't finished yet |
| 256 | 256 | * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy arrays in there - which should probably be ignored) |
| 257 | 257 | */ |
| 258 | - public function get_data_migrations_ran(){ |
|
| 259 | - if( ! $this->_data_migrations_ran ){ |
|
| 258 | + public function get_data_migrations_ran() { |
|
| 259 | + if ( ! $this->_data_migrations_ran) { |
|
| 260 | 260 | //setup autoloaders for each of the scripts in there |
| 261 | 261 | $this->get_all_data_migration_scripts_available(); |
| 262 | - $data_migrations_options = $this->get_all_migration_script_options();//get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 262 | + $data_migrations_options = $this->get_all_migration_script_options(); //get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 263 | 263 | |
| 264 | 264 | $data_migrations_ran = array(); |
| 265 | 265 | //convert into data migration script classes where possible |
| 266 | - foreach($data_migrations_options as $data_migration_option){ |
|
| 267 | - list($plugin_slug,$version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
| 266 | + foreach ($data_migrations_options as $data_migration_option) { |
|
| 267 | + list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
| 268 | 268 | |
| 269 | - try{ |
|
| 270 | - $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'],$data_migration_option['option_value']); |
|
| 269 | + try { |
|
| 270 | + $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'], $data_migration_option['option_value']); |
|
| 271 | 271 | $data_migrations_ran[$plugin_slug][$version_string] = $class; |
| 272 | 272 | //ok so far THIS is the 'last-ran-script'... unless we find another on next iteration |
| 273 | 273 | $this->_last_ran_script = $class; |
| 274 | - if( ! $class->is_completed()){ |
|
| 274 | + if ( ! $class->is_completed()) { |
|
| 275 | 275 | //sometimes we also like to know which was the last incomplete script (or if there are any at all) |
| 276 | 276 | $this->_last_ran_incomplete_script = $class; |
| 277 | 277 | } |
| 278 | - }catch(EE_Error $e){ |
|
| 278 | + } catch (EE_Error $e) { |
|
| 279 | 279 | //ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
| 280 | 280 | $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize($data_migration_option['option_value']); |
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | //so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
| 284 | 284 | $this->_data_migrations_ran = $data_migrations_ran; |
| 285 | - if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran) ){ |
|
| 285 | + if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
| 286 | 286 | $this->_data_migrations_ran = array(); |
| 287 | 287 | } |
| 288 | 288 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @param $new_table |
| 300 | 300 | * @return mixed string or int |
| 301 | 301 | */ |
| 302 | - public function get_mapping_new_pk( $script_name, $old_table, $old_pk, $new_table){ |
|
| 302 | + public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) { |
|
| 303 | 303 | $script = EE_Registry::instance()->load_dms($script_name); |
| 304 | 304 | $mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
| 305 | 305 | return $mapping; |
@@ -310,9 +310,9 @@ discard block |
||
| 310 | 310 | * option returned in this array is the most-recently ran DMS option |
| 311 | 311 | * @return array |
| 312 | 312 | */ |
| 313 | - public function get_all_migration_script_options(){ |
|
| 313 | + public function get_all_migration_script_options() { |
|
| 314 | 314 | global $wpdb; |
| 315 | - return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC",ARRAY_A); |
|
| 315 | + return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC", ARRAY_A); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * @return array where each value is the full folder path of a folder containing data migration scripts, WITH slashes at the end of the |
| 321 | 321 | * folder name. |
| 322 | 322 | */ |
| 323 | - public function get_data_migration_script_folders(){ |
|
| 323 | + public function get_data_migration_script_folders() { |
|
| 324 | 324 | return apply_filters( |
| 325 | 325 | 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
| 326 | 326 | array('Core' => EE_CORE.'data_migration_scripts') |
@@ -336,16 +336,16 @@ discard block |
||
| 336 | 336 | * } |
| 337 | 337 | * @throws EE_Error |
| 338 | 338 | */ |
| 339 | - public function script_migrates_to_version($migration_script_name, $eeAddonClass = ''){ |
|
| 340 | - if(isset($this->script_migration_versions[ $migration_script_name ])){ |
|
| 341 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 339 | + public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') { |
|
| 340 | + if (isset($this->script_migration_versions[$migration_script_name])) { |
|
| 341 | + return $this->script_migration_versions[$migration_script_name]; |
|
| 342 | 342 | } |
| 343 | 343 | $dms_info = $this->parse_dms_classname($migration_script_name); |
| 344 | - $this->script_migration_versions[ $migration_script_name ] = array( |
|
| 345 | - 'slug'=> $eeAddonClass !== '' ? $eeAddonClass : $dms_info[ 'slug' ], |
|
| 346 | - 'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] |
|
| 344 | + $this->script_migration_versions[$migration_script_name] = array( |
|
| 345 | + 'slug'=> $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'], |
|
| 346 | + 'version'=> $dms_info['major_version'].".".$dms_info['minor_version'].".".$dms_info['micro_version'] |
|
| 347 | 347 | ); |
| 348 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 348 | + return $this->script_migration_versions[$migration_script_name]; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -354,13 +354,13 @@ discard block |
||
| 354 | 354 | * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints) |
| 355 | 355 | * @throws EE_Error |
| 356 | 356 | */ |
| 357 | - public function parse_dms_classname($classname){ |
|
| 357 | + public function parse_dms_classname($classname) { |
|
| 358 | 358 | $matches = array(); |
| 359 | - preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~',$classname,$matches); |
|
| 360 | - if( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))){ |
|
| 361 | - throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"),$classname)); |
|
| 359 | + preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
| 360 | + if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
| 361 | + throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"), $classname)); |
|
| 362 | 362 | } |
| 363 | - return array('slug'=>$matches[1],'major_version'=>intval($matches[2]),'minor_version'=>intval($matches[3]),'micro_version'=>intval($matches[4])); |
|
| 363 | + return array('slug'=>$matches[1], 'major_version'=>intval($matches[2]), 'minor_version'=>intval($matches[3]), 'micro_version'=>intval($matches[4])); |
|
| 364 | 364 | } |
| 365 | 365 | /** |
| 366 | 366 | * Ensures that the option indicating the current DB version is set. This should only be |
@@ -369,33 +369,33 @@ discard block |
||
| 369 | 369 | * to 4.1.x. |
| 370 | 370 | * @return string of current db state |
| 371 | 371 | */ |
| 372 | - public function ensure_current_database_state_is_set(){ |
|
| 373 | - $espresso_db_core_updates = get_option( 'espresso_db_update', array() ); |
|
| 372 | + public function ensure_current_database_state_is_set() { |
|
| 373 | + $espresso_db_core_updates = get_option('espresso_db_update', array()); |
|
| 374 | 374 | $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
| 375 | - if( ! $db_state ){ |
|
| 375 | + if ( ! $db_state) { |
|
| 376 | 376 | //mark the DB as being in the state as the last version in there. |
| 377 | 377 | //this is done to trigger maintenance mode and do data migration scripts |
| 378 | 378 | //if the admin installed this version of EE over 3.1.x or 4.0.x |
| 379 | 379 | //otherwise, the normal maintenance mode code is fine |
| 380 | 380 | $previous_versions_installed = array_keys($espresso_db_core_updates); |
| 381 | 381 | $previous_version_installed = end($previous_versions_installed); |
| 382 | - if(version_compare('4.1.0', $previous_version_installed)){ |
|
| 382 | + if (version_compare('4.1.0', $previous_version_installed)) { |
|
| 383 | 383 | //last installed version was less than 4.1 |
| 384 | 384 | //so we want the data migrations to happen. SO, we're going to say the DB is at that state |
| 385 | 385 | // echo "4.1.0 is greater than $previous_version_installed! update the option"; |
| 386 | 386 | $db_state = array('Core'=>$previous_version_installed); |
| 387 | - }else{ |
|
| 387 | + } else { |
|
| 388 | 388 | // echo "4.1.0 is SMALLER than $previous_version_installed"; |
| 389 | 389 | $db_state = array('Core'=>EVENT_ESPRESSO_VERSION); |
| 390 | 390 | } |
| 391 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
| 391 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 392 | 392 | } |
| 393 | 393 | //in 4.1, $db_state would have only been a simple string like '4.1.0', |
| 394 | 394 | //but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
| 395 | 395 | //db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
| 396 | - if( ! is_array($db_state)){ |
|
| 396 | + if ( ! is_array($db_state)) { |
|
| 397 | 397 | $db_state = array('Core'=>$db_state); |
| 398 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
| 398 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 399 | 399 | } |
| 400 | 400 | return $db_state; |
| 401 | 401 | } |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | * or they don't apply), returns an empty array |
| 407 | 407 | * @return EE_Data_Migration_Script_Base[] |
| 408 | 408 | */ |
| 409 | - public function check_for_applicable_data_migration_scripts(){ |
|
| 409 | + public function check_for_applicable_data_migration_scripts() { |
|
| 410 | 410 | //get the option describing what options have already run |
| 411 | 411 | $scripts_ran = $this->get_data_migrations_ran(); |
| 412 | 412 | //$scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
@@ -419,62 +419,62 @@ discard block |
||
| 419 | 419 | $iteration = 0; |
| 420 | 420 | $next_database_state_to_consider = $current_database_state; |
| 421 | 421 | $theoretical_database_state = NULL; |
| 422 | - do{ |
|
| 422 | + do { |
|
| 423 | 423 | //the next state after the currently-considered one will start off looking the same as the current, but we may make additions... |
| 424 | 424 | $theoretical_database_state = $next_database_state_to_consider; |
| 425 | 425 | //the next db state to consider is "what would the DB be like had we run all the scripts we found that applied last time?) |
| 426 | - foreach($script_class_and_filepaths_available as $classname => $filepath){ |
|
| 426 | + foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
| 427 | 427 | |
| 428 | 428 | $migrates_to_version = $this->script_migrates_to_version($classname); |
| 429 | - $script_converts_plugin_slug = $migrates_to_version[ 'slug' ]; |
|
| 430 | - $script_converts_to_version = $migrates_to_version[ 'version' ]; |
|
| 429 | + $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
| 430 | + $script_converts_to_version = $migrates_to_version['version']; |
|
| 431 | 431 | //check if this version script is DONE or not; or if it's never been ran |
| 432 | - if( ! $scripts_ran || |
|
| 432 | + if ( ! $scripts_ran || |
|
| 433 | 433 | ! isset($scripts_ran[$script_converts_plugin_slug]) || |
| 434 | - ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])){ |
|
| 434 | + ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])) { |
|
| 435 | 435 | //we haven't ran this conversion script before |
| 436 | 436 | //now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available |
| 437 | - $script = new $classname( $this->_get_table_manager(), $this->_get_table_analysis() ); |
|
| 437 | + $script = new $classname($this->_get_table_manager(), $this->_get_table_analysis()); |
|
| 438 | 438 | /* @var $script EE_Data_Migration_Script_Base */ |
| 439 | 439 | $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
| 440 | - if($can_migrate){ |
|
| 440 | + if ($can_migrate) { |
|
| 441 | 441 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
| 442 | 442 | $migrates_to_version = $script->migrates_to_version(); |
| 443 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
| 443 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
| 444 | 444 | unset($script_class_and_filepaths_available[$classname]); |
| 445 | 445 | } |
| 446 | - } elseif($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base){ |
|
| 446 | + } elseif ($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base) { |
|
| 447 | 447 | //this script has been ran, or at least started |
| 448 | 448 | $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]; |
| 449 | - if( $script->get_status() != self::status_completed){ |
|
| 449 | + if ($script->get_status() != self::status_completed) { |
|
| 450 | 450 | //this script is already underway... keep going with it |
| 451 | 451 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
| 452 | 452 | $migrates_to_version = $script->migrates_to_version(); |
| 453 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
| 453 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
| 454 | 454 | unset($script_class_and_filepaths_available[$classname]); |
| 455 | - }else{ |
|
| 455 | + } else { |
|
| 456 | 456 | //it must have a status that indicates it has finished, so we don't want to try and run it again |
| 457 | 457 | } |
| 458 | - }else{ |
|
| 458 | + } else { |
|
| 459 | 459 | //it exists but it's not a proper data migration script |
| 460 | 460 | //maybe the script got renamed? or was simply removed from EE? |
| 461 | 461 | //either way, its certainly not runnable! |
| 462 | 462 | } |
| 463 | 463 | } |
| 464 | 464 | $iteration++; |
| 465 | - }while( $next_database_state_to_consider != $theoretical_database_state && $iteration<6); |
|
| 465 | + }while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
| 466 | 466 | //ok we have all the scripts that should run, now let's make them into flat array |
| 467 | 467 | $scripts_that_should_run = array(); |
| 468 | - foreach($script_classes_that_should_run_per_iteration as $scripts_at_priority){ |
|
| 468 | + foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
| 469 | 469 | ksort($scripts_at_priority); |
| 470 | - foreach($scripts_at_priority as $scripts){ |
|
| 471 | - foreach($scripts as $script){ |
|
| 470 | + foreach ($scripts_at_priority as $scripts) { |
|
| 471 | + foreach ($scripts as $script) { |
|
| 472 | 472 | $scripts_that_should_run[get_class($script)] = $script; |
| 473 | 473 | } |
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - do_action( 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run ); |
|
| 477 | + do_action('AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run); |
|
| 478 | 478 | return $scripts_that_should_run; |
| 479 | 479 | } |
| 480 | 480 | |
@@ -488,14 +488,14 @@ discard block |
||
| 488 | 488 | * @param bool $include_completed_scripts |
| 489 | 489 | * @return EE_Data_Migration_Script_Base |
| 490 | 490 | */ |
| 491 | - public function get_last_ran_script($include_completed_scripts = false){ |
|
| 491 | + public function get_last_ran_script($include_completed_scripts = false) { |
|
| 492 | 492 | //make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script |
| 493 | - if( ! $this->_data_migrations_ran){ |
|
| 493 | + if ( ! $this->_data_migrations_ran) { |
|
| 494 | 494 | $this->get_data_migrations_ran(); |
| 495 | 495 | } |
| 496 | - if($include_completed_scripts){ |
|
| 496 | + if ($include_completed_scripts) { |
|
| 497 | 497 | return $this->_last_ran_script; |
| 498 | - }else{ |
|
| 498 | + } else { |
|
| 499 | 499 | return $this->_last_ran_incomplete_script; |
| 500 | 500 | } |
| 501 | 501 | } |
@@ -518,19 +518,19 @@ discard block |
||
| 518 | 518 | * @type string $message string describing what was done during this step |
| 519 | 519 | * } |
| 520 | 520 | */ |
| 521 | - public function migration_step( $step_size = 0 ){ |
|
| 521 | + public function migration_step($step_size = 0) { |
|
| 522 | 522 | |
| 523 | 523 | //bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
| 524 | - if ( class_exists( 'EE_CPT_Strategy' ) ) { |
|
| 525 | - remove_action( 'pre_get_posts', array( EE_CPT_Strategy::instance(), 'pre_get_posts' ), 5 ); |
|
| 524 | + if (class_exists('EE_CPT_Strategy')) { |
|
| 525 | + remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - try{ |
|
| 528 | + try { |
|
| 529 | 529 | $currently_executing_script = $this->get_last_ran_script(); |
| 530 | - if( ! $currently_executing_script){ |
|
| 530 | + if ( ! $currently_executing_script) { |
|
| 531 | 531 | //Find the next script that needs to execute |
| 532 | 532 | $scripts = $this->check_for_applicable_data_migration_scripts(); |
| 533 | - if( ! $scripts ){ |
|
| 533 | + if ( ! $scripts) { |
|
| 534 | 534 | //huh, no more scripts to run... apparently we're done! |
| 535 | 535 | //but dont forget to make sure initial data is there |
| 536 | 536 | //we should be good to allow them to exit maintenance mode now |
@@ -551,18 +551,18 @@ discard block |
||
| 551 | 551 | //and add to the array/wp option showing the scripts ran |
| 552 | 552 | // $this->_data_migrations_ran[$this->script_migrates_to_version(get_class($currently_executing_script))] = $currently_executing_script; |
| 553 | 553 | $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script)); |
| 554 | - $plugin_slug = $migrates_to[ 'slug' ]; |
|
| 555 | - $version = $migrates_to[ 'version' ]; |
|
| 554 | + $plugin_slug = $migrates_to['slug']; |
|
| 555 | + $version = $migrates_to['version']; |
|
| 556 | 556 | $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
| 557 | 557 | } |
| 558 | 558 | $current_script_name = get_class($currently_executing_script); |
| 559 | - }catch(Exception $e){ |
|
| 559 | + } catch (Exception $e) { |
|
| 560 | 560 | //an exception occurred while trying to get migration scripts |
| 561 | 561 | |
| 562 | - $message = sprintf( __("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage() . '<br>', $e->getTraceAsString() ); |
|
| 562 | + $message = sprintf(__("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage().'<br>', $e->getTraceAsString()); |
|
| 563 | 563 | //record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations |
| 564 | 564 | //but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
| 565 | - $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"),$message)); |
|
| 565 | + $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message)); |
|
| 566 | 566 | return array( |
| 567 | 567 | 'records_to_migrate'=>1, |
| 568 | 568 | 'records_migrated'=>0, |
@@ -572,16 +572,16 @@ discard block |
||
| 572 | 572 | ); |
| 573 | 573 | } |
| 574 | 574 | //ok so we definitely have a data migration script |
| 575 | - try{ |
|
| 575 | + try { |
|
| 576 | 576 | //how big of a bite do we want to take? Allow users to easily override via their wp-config |
| 577 | - if( ! absint( $step_size ) > 0 ){ |
|
| 578 | - $step_size = defined( 'EE_MIGRATION_STEP_SIZE' ) && absint( EE_MIGRATION_STEP_SIZE ) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
| 577 | + if ( ! absint($step_size) > 0) { |
|
| 578 | + $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
| 579 | 579 | } |
| 580 | 580 | //do what we came to do! |
| 581 | 581 | $currently_executing_script->migration_step($step_size); |
| 582 | 582 | //can we wrap it up and verify default data? |
| 583 | 583 | $init_dbs = false; |
| 584 | - switch($currently_executing_script->get_status()){ |
|
| 584 | + switch ($currently_executing_script->get_status()) { |
|
| 585 | 585 | case EE_Data_Migration_Manager::status_continue: |
| 586 | 586 | $response_array = array( |
| 587 | 587 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
@@ -593,16 +593,16 @@ discard block |
||
| 593 | 593 | case EE_Data_Migration_Manager::status_completed: |
| 594 | 594 | //ok so THAT script has completed |
| 595 | 595 | $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
| 596 | - $response_array = array( |
|
| 596 | + $response_array = array( |
|
| 597 | 597 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
| 598 | 598 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
| 599 | 599 | 'status'=> EE_Data_Migration_Manager::status_completed, |
| 600 | 600 | 'message'=>$currently_executing_script->get_feedback_message(), |
| 601 | - 'script'=> sprintf(__("%s Completed",'event_espresso'),$currently_executing_script->pretty_name()) |
|
| 601 | + 'script'=> sprintf(__("%s Completed", 'event_espresso'), $currently_executing_script->pretty_name()) |
|
| 602 | 602 | ); |
| 603 | 603 | //check if there are any more after this one. |
| 604 | 604 | $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
| 605 | - if( ! $scripts_remaining ){ |
|
| 605 | + if ( ! $scripts_remaining) { |
|
| 606 | 606 | //we should be good to allow them to exit maintenance mode now |
| 607 | 607 | EE_Maintenance_Mode::instance()->set_maintenance_level(intval(EE_Maintenance_Mode::level_0_not_in_maintenance)); |
| 608 | 608 | ////huh, no more scripts to run... apparently we're done! |
@@ -616,39 +616,39 @@ discard block |
||
| 616 | 616 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
| 617 | 617 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
| 618 | 618 | 'status'=> $currently_executing_script->get_status(), |
| 619 | - 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ",$currently_executing_script->get_errors())), |
|
| 619 | + 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ", $currently_executing_script->get_errors())), |
|
| 620 | 620 | 'script'=>$currently_executing_script->pretty_name() |
| 621 | 621 | ); |
| 622 | 622 | break; |
| 623 | 623 | } |
| 624 | - }catch(Exception $e){ |
|
| 624 | + } catch (Exception $e) { |
|
| 625 | 625 | //ok so some exception was thrown which killed the data migration script |
| 626 | 626 | //double-check we have a real script |
| 627 | - if($currently_executing_script instanceof EE_Data_Migration_Script_Base){ |
|
| 627 | + if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
| 628 | 628 | $script_name = $currently_executing_script->pretty_name(); |
| 629 | 629 | $currently_executing_script->set_broken(); |
| 630 | 630 | $currently_executing_script->add_error($e->getMessage()); |
| 631 | - }else{ |
|
| 631 | + } else { |
|
| 632 | 632 | $script_name = __("Error getting Migration Script", "event_espresso"); |
| 633 | 633 | } |
| 634 | 634 | $response_array = array( |
| 635 | 635 | 'records_to_migrate'=>1, |
| 636 | 636 | 'records_migrated'=>0, |
| 637 | 637 | 'status'=>self::status_fatal_error, |
| 638 | - 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"),$e->getMessage()), |
|
| 638 | + 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"), $e->getMessage()), |
|
| 639 | 639 | 'script'=>$script_name |
| 640 | 640 | ); |
| 641 | 641 | } |
| 642 | 642 | $successful_save = $this->_save_migrations_ran(); |
| 643 | - if($successful_save !== TRUE){ |
|
| 643 | + if ($successful_save !== TRUE) { |
|
| 644 | 644 | //ok so the current wp option didn't save. that's tricky, because we'd like to update it |
| 645 | 645 | //and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
| 646 | 646 | //however, if we throw an exception, and return that, then the next request |
| 647 | 647 | //won't have as much info in it, and it may be able to save |
| 648 | - throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"),$successful_save)); |
|
| 648 | + throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"), $successful_save)); |
|
| 649 | 649 | } |
| 650 | 650 | //if we're all done, initialize EE plugins' default data etc. |
| 651 | - if( $init_dbs ) { |
|
| 651 | + if ($init_dbs) { |
|
| 652 | 652 | $this->initialize_db_for_enqueued_ee_plugins(); |
| 653 | 653 | } |
| 654 | 654 | return $response_array; |
@@ -666,23 +666,23 @@ discard block |
||
| 666 | 666 | * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into errors, notifications, and successes |
| 667 | 667 | * 'script'=>a pretty name of the script currently running |
| 668 | 668 | */ |
| 669 | - public function response_to_migration_ajax_request(){ |
|
| 669 | + public function response_to_migration_ajax_request() { |
|
| 670 | 670 | // //start output buffer just to make sure we don't mess up the json |
| 671 | 671 | ob_start(); |
| 672 | - try{ |
|
| 672 | + try { |
|
| 673 | 673 | $response = $this->migration_step(); |
| 674 | - }catch(Exception $e){ |
|
| 674 | + } catch (Exception $e) { |
|
| 675 | 675 | $response = array( |
| 676 | 676 | 'records_to_migrate'=>0, |
| 677 | 677 | 'records_migrated'=>0, |
| 678 | 678 | 'status'=> EE_Data_Migration_Manager::status_fatal_error, |
| 679 | - 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"),$e->getMessage()), |
|
| 679 | + 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"), $e->getMessage()), |
|
| 680 | 680 | 'script'=>'Unknown'); |
| 681 | 681 | $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString()); |
| 682 | 682 | } |
| 683 | 683 | $warnings_etc = @ob_get_contents(); |
| 684 | 684 | ob_end_clean(); |
| 685 | - $response['message'] .=$warnings_etc; |
|
| 685 | + $response['message'] .= $warnings_etc; |
|
| 686 | 686 | return $response; |
| 687 | 687 | } |
| 688 | 688 | |
@@ -695,14 +695,14 @@ discard block |
||
| 695 | 695 | * } |
| 696 | 696 | * @return void |
| 697 | 697 | */ |
| 698 | - public function update_current_database_state_to($slug_and_version = null){ |
|
| 699 | - if( ! $slug_and_version ){ |
|
| 698 | + public function update_current_database_state_to($slug_and_version = null) { |
|
| 699 | + if ( ! $slug_and_version) { |
|
| 700 | 700 | //no version was provided, assume it should be at the current code version |
| 701 | 701 | $slug_and_version = array('slug' => 'Core', 'version' => espresso_version()); |
| 702 | 702 | } |
| 703 | 703 | $current_database_state = get_option(self::current_database_state); |
| 704 | - $current_database_state[ $slug_and_version[ 'slug' ] ]=$slug_and_version[ 'version' ]; |
|
| 705 | - update_option(self::current_database_state,$current_database_state); |
|
| 704 | + $current_database_state[$slug_and_version['slug']] = $slug_and_version['version']; |
|
| 705 | + update_option(self::current_database_state, $current_database_state); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -713,20 +713,20 @@ discard block |
||
| 713 | 713 | * } |
| 714 | 714 | * @return boolean |
| 715 | 715 | */ |
| 716 | - public function database_needs_updating_to( $slug_and_version ) { |
|
| 716 | + public function database_needs_updating_to($slug_and_version) { |
|
| 717 | 717 | |
| 718 | - $slug = $slug_and_version[ 'slug' ]; |
|
| 719 | - $version = $slug_and_version[ 'version' ]; |
|
| 718 | + $slug = $slug_and_version['slug']; |
|
| 719 | + $version = $slug_and_version['version']; |
|
| 720 | 720 | $current_database_state = get_option(self::current_database_state); |
| 721 | - if( ! isset( $current_database_state[ $slug ] ) ) { |
|
| 721 | + if ( ! isset($current_database_state[$slug])) { |
|
| 722 | 722 | return true; |
| 723 | - }else{ |
|
| 723 | + } else { |
|
| 724 | 724 | //just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
| 725 | - $version_parts_current_db_state = array_slice( explode('.', $current_database_state[ $slug ] ), 0, 3); |
|
| 726 | - $version_parts_of_provided_db_state = array_slice( explode( '.', $version ), 0, 3 ); |
|
| 725 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3); |
|
| 726 | + $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
| 727 | 727 | $needs_updating = false; |
| 728 | - foreach($version_parts_current_db_state as $offset => $version_part_in_current_db_state ) { |
|
| 729 | - if( $version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ] ) { |
|
| 728 | + foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
| 729 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) { |
|
| 730 | 730 | $needs_updating = true; |
| 731 | 731 | break; |
| 732 | 732 | } |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | */ |
| 749 | 749 | public function get_all_data_migration_scripts_available() |
| 750 | 750 | { |
| 751 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
| 751 | + if ( ! $this->_data_migration_class_to_filepath_map) { |
|
| 752 | 752 | $this->_data_migration_class_to_filepath_map = array(); |
| 753 | 753 | foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
| 754 | 754 | // strip any placeholders added to classname to make it a unique array key |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | ? $eeAddonClass |
| 758 | 758 | : ''; |
| 759 | 759 | $folder_path = EEH_File::end_with_directory_separator($folder_path); |
| 760 | - $files = glob($folder_path . '*.dms.php'); |
|
| 760 | + $files = glob($folder_path.'*.dms.php'); |
|
| 761 | 761 | if (empty($files)) { |
| 762 | 762 | continue; |
| 763 | 763 | } |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | '4.3.0.alpha.019' |
| 784 | 784 | ); |
| 785 | 785 | } |
| 786 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
| 786 | + $this->_data_migration_class_to_filepath_map[$classname] = $file; |
|
| 787 | 787 | } |
| 788 | 788 | } |
| 789 | 789 | EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | * from each addon, and check if they need updating, |
| 799 | 799 | * @return boolean |
| 800 | 800 | */ |
| 801 | - public function addons_need_updating(){ |
|
| 801 | + public function addons_need_updating() { |
|
| 802 | 802 | return false; |
| 803 | 803 | } |
| 804 | 804 | /** |
@@ -807,25 +807,25 @@ discard block |
||
| 807 | 807 | * @param string $error_message |
| 808 | 808 | * @throws EE_Error |
| 809 | 809 | */ |
| 810 | - public function add_error_to_migrations_ran($error_message){ |
|
| 810 | + public function add_error_to_migrations_ran($error_message) { |
|
| 811 | 811 | //get last-ran migration script |
| 812 | 812 | global $wpdb; |
| 813 | - $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1",ARRAY_A); |
|
| 813 | + $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1", ARRAY_A); |
|
| 814 | 814 | |
| 815 | 815 | $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
| 816 | 816 | //now, tread lightly because we're here because a FATAL non-catchable error |
| 817 | 817 | //was thrown last time when we were trying to run a data migration script |
| 818 | 818 | //so the fatal error could have happened while getting the migration script |
| 819 | 819 | //or doing running it... |
| 820 | - $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix,"",$last_migration_script_option['option_name']) : null; |
|
| 820 | + $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $last_migration_script_option['option_name']) : null; |
|
| 821 | 821 | |
| 822 | 822 | //check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet |
| 823 | 823 | //because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done) |
| 824 | - if(isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed){ |
|
| 824 | + if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) { |
|
| 825 | 825 | //ok then just add this error to its list of errors |
| 826 | 826 | $last_ran_migration_script_properties['_errors'][] = $error_message; |
| 827 | 827 | $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
| 828 | - }else{ |
|
| 828 | + } else { |
|
| 829 | 829 | //so we don't even know which script was last running |
| 830 | 830 | //use the data migration error stub, which is designed specifically for this type of thing |
| 831 | 831 | $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
@@ -835,39 +835,39 @@ discard block |
||
| 835 | 835 | $versions_migrated_to = 'Unknown.1.0.0'; |
| 836 | 836 | //now just to make sure appears as last (in case the were previously a fatal error like this) |
| 837 | 837 | //delete the old one |
| 838 | - delete_option( self::data_migration_script_option_prefix . $versions_migrated_to ); |
|
| 838 | + delete_option(self::data_migration_script_option_prefix.$versions_migrated_to); |
|
| 839 | 839 | } |
| 840 | - update_option(self::data_migration_script_option_prefix.$versions_migrated_to,$last_ran_migration_script_properties); |
|
| 840 | + update_option(self::data_migration_script_option_prefix.$versions_migrated_to, $last_ran_migration_script_properties); |
|
| 841 | 841 | |
| 842 | 842 | } |
| 843 | 843 | /** |
| 844 | 844 | * saves what data migrations have ran to the database |
| 845 | 845 | * @return mixed TRUE if successfully saved migrations ran, string if an error occurred |
| 846 | 846 | */ |
| 847 | - protected function _save_migrations_ran(){ |
|
| 848 | - if($this->_data_migrations_ran == null){ |
|
| 847 | + protected function _save_migrations_ran() { |
|
| 848 | + if ($this->_data_migrations_ran == null) { |
|
| 849 | 849 | $this->get_data_migrations_ran(); |
| 850 | 850 | } |
| 851 | 851 | //now, we don't want to save actual classes to the DB because that's messy |
| 852 | 852 | $successful_updates = true; |
| 853 | - foreach($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin){ |
|
| 854 | - foreach($migrations_ran_for_plugin as $version_string => $array_or_migration_obj){ |
|
| 853 | + foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
| 854 | + foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
| 855 | 855 | // echo "saving migration script to $version_string<br>"; |
| 856 | 856 | $plugin_slug_for_use_in_option_name = $plugin_slug."."; |
| 857 | 857 | $option_name = self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string; |
| 858 | 858 | $old_option_value = get_option($option_name); |
| 859 | - if($array_or_migration_obj instanceof EE_Data_Migration_Script_Base){ |
|
| 859 | + if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
| 860 | 860 | $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
| 861 | - if( $old_option_value != $script_array_for_saving){ |
|
| 862 | - $successful_updates = update_option($option_name,$script_array_for_saving); |
|
| 861 | + if ($old_option_value != $script_array_for_saving) { |
|
| 862 | + $successful_updates = update_option($option_name, $script_array_for_saving); |
|
| 863 | 863 | } |
| 864 | - }else{//we don't know what this array-thing is. So just save it as-is |
|
| 864 | + } else {//we don't know what this array-thing is. So just save it as-is |
|
| 865 | 865 | // $array_of_migrations[$version_string] = $array_or_migration_obj; |
| 866 | - if($old_option_value != $array_or_migration_obj){ |
|
| 867 | - $successful_updates = update_option($option_name,$array_or_migration_obj); |
|
| 866 | + if ($old_option_value != $array_or_migration_obj) { |
|
| 867 | + $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
| 868 | 868 | } |
| 869 | 869 | } |
| 870 | - if( ! $successful_updates ){ |
|
| 870 | + if ( ! $successful_updates) { |
|
| 871 | 871 | global $wpdb; |
| 872 | 872 | return $wpdb->last_error; |
| 873 | 873 | } |
@@ -891,17 +891,17 @@ discard block |
||
| 891 | 891 | * @return EE_Data_Migration_Script_Base |
| 892 | 892 | * @throws EE_Error |
| 893 | 893 | */ |
| 894 | - function _instantiate_script_from_properties_array($properties_array){ |
|
| 895 | - if( ! isset($properties_array['class'])){ |
|
| 896 | - throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"),implode(",",$properties_array))); |
|
| 894 | + function _instantiate_script_from_properties_array($properties_array) { |
|
| 895 | + if ( ! isset($properties_array['class'])) { |
|
| 896 | + throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), implode(",", $properties_array))); |
|
| 897 | 897 | } |
| 898 | 898 | $class_name = $properties_array['class']; |
| 899 | - if( ! class_exists($class_name)){ |
|
| 900 | - throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"),$class_name)); |
|
| 899 | + if ( ! class_exists($class_name)) { |
|
| 900 | + throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name)); |
|
| 901 | 901 | } |
| 902 | 902 | $class = new $class_name; |
| 903 | - if( ! $class instanceof EE_Data_Migration_Script_Base){ |
|
| 904 | - throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),$class_name,get_class($class))); |
|
| 903 | + if ( ! $class instanceof EE_Data_Migration_Script_Base) { |
|
| 904 | + throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), $class_name, get_class($class))); |
|
| 905 | 905 | } |
| 906 | 906 | $class->instantiate_from_array_of_properties($properties_array); |
| 907 | 907 | return $class; |
@@ -913,25 +913,25 @@ discard block |
||
| 913 | 913 | * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
| 914 | 914 | * @return string |
| 915 | 915 | */ |
| 916 | - public function get_most_up_to_date_dms($plugin_slug = 'Core'){ |
|
| 916 | + public function get_most_up_to_date_dms($plugin_slug = 'Core') { |
|
| 917 | 917 | $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
| 918 | 918 | $most_up_to_date_dms_classname = NULL; |
| 919 | - foreach($class_to_filepath_map as $classname => $filepath){ |
|
| 920 | - if($most_up_to_date_dms_classname === NULL){ |
|
| 919 | + foreach ($class_to_filepath_map as $classname => $filepath) { |
|
| 920 | + if ($most_up_to_date_dms_classname === NULL) { |
|
| 921 | 921 | $migrates_to = $this->script_migrates_to_version($classname); |
| 922 | - $this_plugin_slug = $migrates_to[ 'slug' ]; |
|
| 922 | + $this_plugin_slug = $migrates_to['slug']; |
|
| 923 | 923 | // $version_string = $migrates_to[ 'version' ]; |
| 924 | 924 | // $details = $this->parse_dms_classname($classname); |
| 925 | - if($this_plugin_slug == $plugin_slug){ |
|
| 925 | + if ($this_plugin_slug == $plugin_slug) { |
|
| 926 | 926 | //if it's for core, it wins |
| 927 | 927 | $most_up_to_date_dms_classname = $classname; |
| 928 | 928 | } |
| 929 | 929 | //if it wasn't for core, we must keep searching for one that is! |
| 930 | 930 | continue; |
| 931 | - }else{ |
|
| 932 | - $champion_migrates_to= $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
| 931 | + } else { |
|
| 932 | + $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
| 933 | 933 | $contender_migrates_to = $this->script_migrates_to_version($classname); |
| 934 | - if($contender_migrates_to[ 'slug' ] == $plugin_slug && version_compare($champion_migrates_to[ 'version' ], $contender_migrates_to[ 'version' ], '<')){ |
|
| 934 | + if ($contender_migrates_to['slug'] == $plugin_slug && version_compare($champion_migrates_to['version'], $contender_migrates_to['version'], '<')) { |
|
| 935 | 935 | //so the contenders version is higher and its for Core |
| 936 | 936 | $most_up_to_date_dms_classname = $classname; |
| 937 | 937 | } |
@@ -951,11 +951,11 @@ discard block |
||
| 951 | 951 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
| 952 | 952 | * @return EE_Data_Migration_Script_Base |
| 953 | 953 | */ |
| 954 | - public function get_migration_ran( $version, $plugin_slug = 'Core' ) { |
|
| 954 | + public function get_migration_ran($version, $plugin_slug = 'Core') { |
|
| 955 | 955 | $migrations_ran = $this->get_data_migrations_ran(); |
| 956 | - if( isset( $migrations_ran[ $plugin_slug ] ) && isset( $migrations_ran[ $plugin_slug ][ $version ] ) ){ |
|
| 957 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
| 958 | - }else{ |
|
| 956 | + if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) { |
|
| 957 | + return $migrations_ran[$plugin_slug][$version]; |
|
| 958 | + } else { |
|
| 959 | 959 | return NULL; |
| 960 | 960 | } |
| 961 | 961 | } |
@@ -967,20 +967,20 @@ discard block |
||
| 967 | 967 | * @return bool |
| 968 | 968 | * @throws EE_Error |
| 969 | 969 | */ |
| 970 | - public function reattempt(){ |
|
| 970 | + public function reattempt() { |
|
| 971 | 971 | //find if the last-ran script was borked |
| 972 | 972 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
| 973 | 973 | //add an 'error' saying that we attempted to reset |
| 974 | 974 | //does it have a stage that was borked too? if so make it no longer borked |
| 975 | 975 | //add an 'error' saying we attempted to reset |
| 976 | 976 | $last_ran_script = $this->get_last_ran_script(); |
| 977 | - if( $last_ran_script instanceof EE_DMS_Unknown_1_0_0 ){ |
|
| 977 | + if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
| 978 | 978 | //if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
| 979 | 979 | $last_ran_script->set_completed(); |
| 980 | - }elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) { |
|
| 980 | + }elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
| 981 | 981 | $last_ran_script->reattempt(); |
| 982 | - }else{ |
|
| 983 | - throw new EE_Error( sprintf( __( 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso' ), print_r( $last_ran_script, true ) ) ); |
|
| 982 | + } else { |
|
| 983 | + throw new EE_Error(sprintf(__('Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso'), print_r($last_ran_script, true))); |
|
| 984 | 984 | } |
| 985 | 985 | return $this->_save_migrations_ran(); |
| 986 | 986 | } |
@@ -990,19 +990,19 @@ discard block |
||
| 990 | 990 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
| 991 | 991 | * @return boolean |
| 992 | 992 | */ |
| 993 | - public function migration_has_ran( $version, $plugin_slug = 'Core' ) { |
|
| 994 | - return $this->get_migration_ran( $version, $plugin_slug ) !== NULL; |
|
| 993 | + public function migration_has_ran($version, $plugin_slug = 'Core') { |
|
| 994 | + return $this->get_migration_ran($version, $plugin_slug) !== NULL; |
|
| 995 | 995 | } |
| 996 | 996 | /** |
| 997 | 997 | * Enqueues this ee plugin to have its data initialized |
| 998 | 998 | * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
| 999 | 999 | */ |
| 1000 | - public function enqueue_db_initialization_for( $plugin_slug ) { |
|
| 1000 | + public function enqueue_db_initialization_for($plugin_slug) { |
|
| 1001 | 1001 | $queue = $this->get_db_initialization_queue(); |
| 1002 | - if( ! in_array( $plugin_slug, $queue ) ) { |
|
| 1002 | + if ( ! in_array($plugin_slug, $queue)) { |
|
| 1003 | 1003 | $queue[] = $plugin_slug; |
| 1004 | 1004 | } |
| 1005 | - update_option( self::db_init_queue_option_name, $queue ); |
|
| 1005 | + update_option(self::db_init_queue_option_name, $queue); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | /** |
| 1008 | 1008 | * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
@@ -1012,26 +1012,26 @@ discard block |
||
| 1012 | 1012 | public function initialize_db_for_enqueued_ee_plugins() { |
| 1013 | 1013 | // EEH_Debug_Tools::instance()->start_timer( 'initialize_db_for_enqueued_ee_plugins' ); |
| 1014 | 1014 | $queue = $this->get_db_initialization_queue(); |
| 1015 | - foreach( $queue as $plugin_slug ) { |
|
| 1016 | - $most_up_to_date_dms = $this->get_most_up_to_date_dms( $plugin_slug ); |
|
| 1017 | - if( ! $most_up_to_date_dms ) { |
|
| 1015 | + foreach ($queue as $plugin_slug) { |
|
| 1016 | + $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
| 1017 | + if ( ! $most_up_to_date_dms) { |
|
| 1018 | 1018 | //if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
| 1019 | 1019 | $verify_db = false; |
| 1020 | - }else{ |
|
| 1021 | - $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version( $most_up_to_date_dms ); |
|
| 1022 | - $verify_db = $this->database_needs_updating_to( $most_up_to_date_dms_migrates_to ); |
|
| 1020 | + } else { |
|
| 1021 | + $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
| 1022 | + $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
| 1023 | 1023 | } |
| 1024 | - if( $plugin_slug == 'Core' ){ |
|
| 1024 | + if ($plugin_slug == 'Core') { |
|
| 1025 | 1025 | EE_System::instance()->initialize_db_if_no_migrations_required( |
| 1026 | 1026 | false, |
| 1027 | 1027 | $verify_db |
| 1028 | 1028 | ); |
| 1029 | - }else{ |
|
| 1029 | + } else { |
|
| 1030 | 1030 | //just loop through the addons to make sure their database is setup |
| 1031 | - foreach( EE_Registry::instance()->addons as $addon ) { |
|
| 1032 | - if( $addon->name() == $plugin_slug ) { |
|
| 1031 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
| 1032 | + if ($addon->name() == $plugin_slug) { |
|
| 1033 | 1033 | |
| 1034 | - $addon->initialize_db_if_no_migrations_required( $verify_db ); |
|
| 1034 | + $addon->initialize_db_if_no_migrations_required($verify_db); |
|
| 1035 | 1035 | break; |
| 1036 | 1036 | } |
| 1037 | 1037 | } |
@@ -1041,7 +1041,7 @@ discard block |
||
| 1041 | 1041 | // EEH_Debug_Tools::instance()->show_times(); |
| 1042 | 1042 | //because we just initialized the DBs for the enqueued ee plugins |
| 1043 | 1043 | //we don't need to keep remembering which ones needed to be initialized |
| 1044 | - delete_option( self::db_init_queue_option_name ); |
|
| 1044 | + delete_option(self::db_init_queue_option_name); |
|
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | /** |
@@ -1050,8 +1050,8 @@ discard block |
||
| 1050 | 1050 | * 'Core', or the return value of EE_Addon::name() for an addon |
| 1051 | 1051 | * @return array |
| 1052 | 1052 | */ |
| 1053 | - public function get_db_initialization_queue(){ |
|
| 1054 | - return get_option ( self::db_init_queue_option_name, array() ); |
|
| 1053 | + public function get_db_initialization_queue() { |
|
| 1054 | + return get_option(self::db_init_queue_option_name, array()); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | /** |
@@ -1061,13 +1061,13 @@ discard block |
||
| 1061 | 1061 | * @throws EE_Error |
| 1062 | 1062 | */ |
| 1063 | 1063 | protected function _get_table_analysis() { |
| 1064 | - if( $this->_table_analysis instanceof TableAnalysis ) { |
|
| 1064 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 1065 | 1065 | return $this->_table_analysis; |
| 1066 | 1066 | } else { |
| 1067 | 1067 | throw new EE_Error( |
| 1068 | 1068 | sprintf( |
| 1069 | - __( 'Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1070 | - get_class( $this ) |
|
| 1069 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1070 | + get_class($this) |
|
| 1071 | 1071 | ) |
| 1072 | 1072 | ); |
| 1073 | 1073 | } |
@@ -1080,13 +1080,13 @@ discard block |
||
| 1080 | 1080 | * @throws EE_Error |
| 1081 | 1081 | */ |
| 1082 | 1082 | protected function _get_table_manager() { |
| 1083 | - if( $this->_table_manager instanceof TableManager ) { |
|
| 1083 | + if ($this->_table_manager instanceof TableManager) { |
|
| 1084 | 1084 | return $this->_table_manager; |
| 1085 | 1085 | } else { |
| 1086 | 1086 | throw new EE_Error( |
| 1087 | 1087 | sprintf( |
| 1088 | - __( 'Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1089 | - get_class( $this ) |
|
| 1088 | + __('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1089 | + get_class($this) |
|
| 1090 | 1090 | ) |
| 1091 | 1091 | ); |
| 1092 | 1092 | } |
@@ -25,1152 +25,1152 @@ |
||
| 25 | 25 | class EE_Register_Addon implements EEI_Plugin_API |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * possibly truncated version of the EE core version string |
|
| 30 | - * |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - protected static $_core_version = ''; |
|
| 28 | + /** |
|
| 29 | + * possibly truncated version of the EE core version string |
|
| 30 | + * |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + protected static $_core_version = ''; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Holds values for registered addons |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected static $_settings = array(); |
|
| 35 | + /** |
|
| 36 | + * Holds values for registered addons |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected static $_settings = array(); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
| 44 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 45 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 46 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
| 47 | - * EE core with knowledge of ALL the addons out there. |
|
| 48 | - * If you want NO versions of an addon to run with a certain version of core, |
|
| 49 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 50 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 51 | - * minimum plugin version. |
|
| 52 | - * @access protected |
|
| 53 | - */ |
|
| 54 | - protected static $_incompatible_addons = array( |
|
| 55 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 56 | - 'Promotions' => '1.0.0.rc.084', |
|
| 57 | - ); |
|
| 42 | + /** |
|
| 43 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
| 44 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 45 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 46 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
| 47 | + * EE core with knowledge of ALL the addons out there. |
|
| 48 | + * If you want NO versions of an addon to run with a certain version of core, |
|
| 49 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 50 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 51 | + * minimum plugin version. |
|
| 52 | + * @access protected |
|
| 53 | + */ |
|
| 54 | + protected static $_incompatible_addons = array( |
|
| 55 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 56 | + 'Promotions' => '1.0.0.rc.084', |
|
| 57 | + ); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 62 | - * not just '4.3.0'. |
|
| 63 | - * So if the addon developer doesn't provide that full version string, |
|
| 64 | - * fill in the blanks for them |
|
| 65 | - * |
|
| 66 | - * @param string $min_core_version |
|
| 67 | - * @return string always like '4.3.0.rc.000' |
|
| 68 | - */ |
|
| 69 | - protected static function _effective_version($min_core_version) |
|
| 70 | - { |
|
| 71 | - // versions: 4 . 3 . 1 . p . 123 |
|
| 72 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 73 | - $version_parts = explode('.', $min_core_version); |
|
| 74 | - //check they specified the micro version (after 2nd period) |
|
| 75 | - if (! isset($version_parts[2])) { |
|
| 76 | - $version_parts[2] = '0'; |
|
| 77 | - } |
|
| 78 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 79 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 80 | - if (! isset($version_parts[3])) { |
|
| 81 | - $version_parts[3] = 'dev'; |
|
| 82 | - } |
|
| 83 | - if (! isset($version_parts[4])) { |
|
| 84 | - $version_parts[4] = '000'; |
|
| 85 | - } |
|
| 86 | - return implode('.', $version_parts); |
|
| 87 | - } |
|
| 60 | + /** |
|
| 61 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 62 | + * not just '4.3.0'. |
|
| 63 | + * So if the addon developer doesn't provide that full version string, |
|
| 64 | + * fill in the blanks for them |
|
| 65 | + * |
|
| 66 | + * @param string $min_core_version |
|
| 67 | + * @return string always like '4.3.0.rc.000' |
|
| 68 | + */ |
|
| 69 | + protected static function _effective_version($min_core_version) |
|
| 70 | + { |
|
| 71 | + // versions: 4 . 3 . 1 . p . 123 |
|
| 72 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 73 | + $version_parts = explode('.', $min_core_version); |
|
| 74 | + //check they specified the micro version (after 2nd period) |
|
| 75 | + if (! isset($version_parts[2])) { |
|
| 76 | + $version_parts[2] = '0'; |
|
| 77 | + } |
|
| 78 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 79 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 80 | + if (! isset($version_parts[3])) { |
|
| 81 | + $version_parts[3] = 'dev'; |
|
| 82 | + } |
|
| 83 | + if (! isset($version_parts[4])) { |
|
| 84 | + $version_parts[4] = '000'; |
|
| 85 | + } |
|
| 86 | + return implode('.', $version_parts); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Returns whether or not the min core version requirement of the addon is met |
|
| 92 | - * |
|
| 93 | - * @param string $min_core_version the minimum core version required by the addon |
|
| 94 | - * @param string $actual_core_version the actual core version, optional |
|
| 95 | - * @return boolean |
|
| 96 | - */ |
|
| 97 | - public static function _meets_min_core_version_requirement( |
|
| 98 | - $min_core_version, |
|
| 99 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 100 | - ) { |
|
| 101 | - return version_compare( |
|
| 102 | - self::_effective_version($actual_core_version), |
|
| 103 | - self::_effective_version($min_core_version), |
|
| 104 | - '>=' |
|
| 105 | - ); |
|
| 106 | - } |
|
| 90 | + /** |
|
| 91 | + * Returns whether or not the min core version requirement of the addon is met |
|
| 92 | + * |
|
| 93 | + * @param string $min_core_version the minimum core version required by the addon |
|
| 94 | + * @param string $actual_core_version the actual core version, optional |
|
| 95 | + * @return boolean |
|
| 96 | + */ |
|
| 97 | + public static function _meets_min_core_version_requirement( |
|
| 98 | + $min_core_version, |
|
| 99 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 100 | + ) { |
|
| 101 | + return version_compare( |
|
| 102 | + self::_effective_version($actual_core_version), |
|
| 103 | + self::_effective_version($min_core_version), |
|
| 104 | + '>=' |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Method for registering new EE_Addons. |
|
| 111 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 112 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 113 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 114 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 115 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 116 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 117 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 118 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
| 119 | - * |
|
| 120 | - * @since 4.3.0 |
|
| 121 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
| 122 | - * @param array $setup_args { |
|
| 123 | - * An array of arguments provided for registering |
|
| 124 | - * the message type. |
|
| 125 | - * @type string $class_name the addon's main file name. |
|
| 126 | - * If left blank, generated from the addon name, |
|
| 127 | - * changes something like "calendar" to |
|
| 128 | - * "EE_Calendar" |
|
| 129 | - * @type string $min_core_version the minimum version of EE Core that the |
|
| 130 | - * addon will work with. eg "4.8.1.rc.084" |
|
| 131 | - * @type string $version the "software" version for the addon. eg |
|
| 132 | - * "1.0.0.p" for a first stable release, or |
|
| 133 | - * "1.0.0.rc.043" for a version in progress |
|
| 134 | - * @type string $main_file_path the full server path to the main file |
|
| 135 | - * loaded directly by WP |
|
| 136 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
| 137 | - * for the addon's Domain class |
|
| 138 | - * (see EventEspresso\core\domain\Domain) |
|
| 139 | - * @type string $admin_path full server path to the folder where the |
|
| 140 | - * addon\'s admin files reside |
|
| 141 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
| 142 | - * first invoked, can be used for hooking into |
|
| 143 | - * any admin page |
|
| 144 | - * @type string $config_section the section name for this addon's |
|
| 145 | - * configuration settings section |
|
| 146 | - * (defaults to "addons") |
|
| 147 | - * @type string $config_class the class name for this addon's |
|
| 148 | - * configuration settings object |
|
| 149 | - * @type string $config_name the class name for this addon's |
|
| 150 | - * configuration settings object |
|
| 151 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
| 152 | - * server paths to those files. |
|
| 153 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
| 154 | - * folders containing classes that might be |
|
| 155 | - * invoked by the addon |
|
| 156 | - * @type string $dms_paths [Required] an array of full server paths to |
|
| 157 | - * folders that contain data migration scripts. |
|
| 158 | - * The key should be the EE_Addon class name that |
|
| 159 | - * this set of data migration scripts belongs to. |
|
| 160 | - * If the EE_Addon class is namespaced, then this |
|
| 161 | - * needs to be the Fully Qualified Class Name |
|
| 162 | - * @type string $module_paths an array of full server paths to any |
|
| 163 | - * EED_Modules used by the addon |
|
| 164 | - * @type string $shortcode_paths an array of full server paths to folders |
|
| 165 | - * that contain EES_Shortcodes |
|
| 166 | - * @type string $widget_paths an array of full server paths to folders |
|
| 167 | - * that contain WP_Widgets |
|
| 168 | - * @type string $pue_options |
|
| 169 | - * @type array $capabilities an array indexed by role name |
|
| 170 | - * (i.e administrator,author ) and the values |
|
| 171 | - * are an array of caps to add to the role. |
|
| 172 | - * 'administrator' => array( |
|
| 173 | - * 'read_addon', |
|
| 174 | - * 'edit_addon', |
|
| 175 | - * etc. |
|
| 176 | - * ). |
|
| 177 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 178 | - * for any addons that need to register any |
|
| 179 | - * special meta mapped capabilities. Should |
|
| 180 | - * be indexed where the key is the |
|
| 181 | - * EE_Meta_Capability_Map class name and the |
|
| 182 | - * values are the arguments sent to the class. |
|
| 183 | - * @type array $model_paths array of folders containing DB models |
|
| 184 | - * @see EE_Register_Model |
|
| 185 | - * @type array $class_paths array of folders containing DB classes |
|
| 186 | - * @see EE_Register_Model |
|
| 187 | - * @type array $model_extension_paths array of folders containing DB model |
|
| 188 | - * extensions |
|
| 189 | - * @see EE_Register_Model_Extension |
|
| 190 | - * @type array $class_extension_paths array of folders containing DB class |
|
| 191 | - * extensions |
|
| 192 | - * @see EE_Register_Model_Extension |
|
| 193 | - * @type array message_types { |
|
| 194 | - * An array of message types with the key as |
|
| 195 | - * the message type name and the values as |
|
| 196 | - * below: |
|
| 197 | - * @type string $mtfilename [Required] The filename of the message type |
|
| 198 | - * being registered. This will be the main |
|
| 199 | - * EE_{Message Type Name}_message_type class. |
|
| 200 | - * for example: |
|
| 201 | - * EE_Declined_Registration_message_type.class.php |
|
| 202 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
| 203 | - * messages autoloader for the new message type. |
|
| 204 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 205 | - * type should activate with. Each value in |
|
| 206 | - * the |
|
| 207 | - * array |
|
| 208 | - * should match the name property of a |
|
| 209 | - * EE_messenger. Optional. |
|
| 210 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 211 | - * type should validate with. Each value in |
|
| 212 | - * the |
|
| 213 | - * array |
|
| 214 | - * should match the name property of an |
|
| 215 | - * EE_messenger. |
|
| 216 | - * Optional. |
|
| 217 | - * } |
|
| 218 | - * @type array $custom_post_types |
|
| 219 | - * @type array $custom_taxonomies |
|
| 220 | - * @type array $payment_method_paths each element is the folder containing the |
|
| 221 | - * EE_PMT_Base child class |
|
| 222 | - * (eg, |
|
| 223 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 224 | - * which contains the files |
|
| 225 | - * EE_PMT_Payomatic.pm.php) |
|
| 226 | - * @type array $default_terms |
|
| 227 | - * @type array $namespace { |
|
| 228 | - * An array with two items for registering the |
|
| 229 | - * addon's namespace. (If, for some reason, you |
|
| 230 | - * require additional namespaces, |
|
| 231 | - * use |
|
| 232 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 233 | - * directly) |
|
| 234 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 235 | - * @type string $FQNS the namespace prefix |
|
| 236 | - * @type string $DIR a base directory for class files in the |
|
| 237 | - * namespace. |
|
| 238 | - * } |
|
| 239 | - * } |
|
| 240 | - * @return void |
|
| 241 | - * @throws DomainException |
|
| 242 | - * @throws EE_Error |
|
| 243 | - * @throws InvalidArgumentException |
|
| 244 | - * @throws ReflectionException |
|
| 245 | - * @throws InvalidDataTypeException |
|
| 246 | - * @throws InvalidInterfaceException |
|
| 247 | - */ |
|
| 248 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 249 | - { |
|
| 250 | - // required fields MUST be present, so let's make sure they are. |
|
| 251 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 252 | - // get class name for addon |
|
| 253 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 254 | - //setup $_settings array from incoming values. |
|
| 255 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 256 | - // setup PUE |
|
| 257 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 258 | - // does this addon work with this version of core or WordPress ? |
|
| 259 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 260 | - return; |
|
| 261 | - } |
|
| 262 | - // register namespaces |
|
| 263 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 264 | - // check if this is an activation request |
|
| 265 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 266 | - // dont bother setting up the rest of the addon atm |
|
| 267 | - return; |
|
| 268 | - } |
|
| 269 | - // we need cars |
|
| 270 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 271 | - // register new models and extensions |
|
| 272 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 273 | - // setup DMS |
|
| 274 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 275 | - // if config_class is present let's register config. |
|
| 276 | - EE_Register_Addon::_register_config($addon_name); |
|
| 277 | - // register admin pages |
|
| 278 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 279 | - // add to list of modules to be registered |
|
| 280 | - EE_Register_Addon::_register_modules($addon_name); |
|
| 281 | - // add to list of shortcodes to be registered |
|
| 282 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 283 | - // add to list of widgets to be registered |
|
| 284 | - EE_Register_Addon::_register_widgets($addon_name); |
|
| 285 | - // register capability related stuff. |
|
| 286 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
| 287 | - // any message type to register? |
|
| 288 | - EE_Register_Addon::_register_message_types($addon_name); |
|
| 289 | - // any custom post type/ custom capabilities or default terms to register |
|
| 290 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 291 | - // and any payment methods |
|
| 292 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 293 | - // load and instantiate main addon class |
|
| 294 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 295 | - //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 296 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 297 | - } |
|
| 109 | + /** |
|
| 110 | + * Method for registering new EE_Addons. |
|
| 111 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 112 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 113 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 114 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 115 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 116 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 117 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 118 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
| 119 | + * |
|
| 120 | + * @since 4.3.0 |
|
| 121 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
| 122 | + * @param array $setup_args { |
|
| 123 | + * An array of arguments provided for registering |
|
| 124 | + * the message type. |
|
| 125 | + * @type string $class_name the addon's main file name. |
|
| 126 | + * If left blank, generated from the addon name, |
|
| 127 | + * changes something like "calendar" to |
|
| 128 | + * "EE_Calendar" |
|
| 129 | + * @type string $min_core_version the minimum version of EE Core that the |
|
| 130 | + * addon will work with. eg "4.8.1.rc.084" |
|
| 131 | + * @type string $version the "software" version for the addon. eg |
|
| 132 | + * "1.0.0.p" for a first stable release, or |
|
| 133 | + * "1.0.0.rc.043" for a version in progress |
|
| 134 | + * @type string $main_file_path the full server path to the main file |
|
| 135 | + * loaded directly by WP |
|
| 136 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
| 137 | + * for the addon's Domain class |
|
| 138 | + * (see EventEspresso\core\domain\Domain) |
|
| 139 | + * @type string $admin_path full server path to the folder where the |
|
| 140 | + * addon\'s admin files reside |
|
| 141 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
| 142 | + * first invoked, can be used for hooking into |
|
| 143 | + * any admin page |
|
| 144 | + * @type string $config_section the section name for this addon's |
|
| 145 | + * configuration settings section |
|
| 146 | + * (defaults to "addons") |
|
| 147 | + * @type string $config_class the class name for this addon's |
|
| 148 | + * configuration settings object |
|
| 149 | + * @type string $config_name the class name for this addon's |
|
| 150 | + * configuration settings object |
|
| 151 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
| 152 | + * server paths to those files. |
|
| 153 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
| 154 | + * folders containing classes that might be |
|
| 155 | + * invoked by the addon |
|
| 156 | + * @type string $dms_paths [Required] an array of full server paths to |
|
| 157 | + * folders that contain data migration scripts. |
|
| 158 | + * The key should be the EE_Addon class name that |
|
| 159 | + * this set of data migration scripts belongs to. |
|
| 160 | + * If the EE_Addon class is namespaced, then this |
|
| 161 | + * needs to be the Fully Qualified Class Name |
|
| 162 | + * @type string $module_paths an array of full server paths to any |
|
| 163 | + * EED_Modules used by the addon |
|
| 164 | + * @type string $shortcode_paths an array of full server paths to folders |
|
| 165 | + * that contain EES_Shortcodes |
|
| 166 | + * @type string $widget_paths an array of full server paths to folders |
|
| 167 | + * that contain WP_Widgets |
|
| 168 | + * @type string $pue_options |
|
| 169 | + * @type array $capabilities an array indexed by role name |
|
| 170 | + * (i.e administrator,author ) and the values |
|
| 171 | + * are an array of caps to add to the role. |
|
| 172 | + * 'administrator' => array( |
|
| 173 | + * 'read_addon', |
|
| 174 | + * 'edit_addon', |
|
| 175 | + * etc. |
|
| 176 | + * ). |
|
| 177 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 178 | + * for any addons that need to register any |
|
| 179 | + * special meta mapped capabilities. Should |
|
| 180 | + * be indexed where the key is the |
|
| 181 | + * EE_Meta_Capability_Map class name and the |
|
| 182 | + * values are the arguments sent to the class. |
|
| 183 | + * @type array $model_paths array of folders containing DB models |
|
| 184 | + * @see EE_Register_Model |
|
| 185 | + * @type array $class_paths array of folders containing DB classes |
|
| 186 | + * @see EE_Register_Model |
|
| 187 | + * @type array $model_extension_paths array of folders containing DB model |
|
| 188 | + * extensions |
|
| 189 | + * @see EE_Register_Model_Extension |
|
| 190 | + * @type array $class_extension_paths array of folders containing DB class |
|
| 191 | + * extensions |
|
| 192 | + * @see EE_Register_Model_Extension |
|
| 193 | + * @type array message_types { |
|
| 194 | + * An array of message types with the key as |
|
| 195 | + * the message type name and the values as |
|
| 196 | + * below: |
|
| 197 | + * @type string $mtfilename [Required] The filename of the message type |
|
| 198 | + * being registered. This will be the main |
|
| 199 | + * EE_{Message Type Name}_message_type class. |
|
| 200 | + * for example: |
|
| 201 | + * EE_Declined_Registration_message_type.class.php |
|
| 202 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
| 203 | + * messages autoloader for the new message type. |
|
| 204 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 205 | + * type should activate with. Each value in |
|
| 206 | + * the |
|
| 207 | + * array |
|
| 208 | + * should match the name property of a |
|
| 209 | + * EE_messenger. Optional. |
|
| 210 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 211 | + * type should validate with. Each value in |
|
| 212 | + * the |
|
| 213 | + * array |
|
| 214 | + * should match the name property of an |
|
| 215 | + * EE_messenger. |
|
| 216 | + * Optional. |
|
| 217 | + * } |
|
| 218 | + * @type array $custom_post_types |
|
| 219 | + * @type array $custom_taxonomies |
|
| 220 | + * @type array $payment_method_paths each element is the folder containing the |
|
| 221 | + * EE_PMT_Base child class |
|
| 222 | + * (eg, |
|
| 223 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 224 | + * which contains the files |
|
| 225 | + * EE_PMT_Payomatic.pm.php) |
|
| 226 | + * @type array $default_terms |
|
| 227 | + * @type array $namespace { |
|
| 228 | + * An array with two items for registering the |
|
| 229 | + * addon's namespace. (If, for some reason, you |
|
| 230 | + * require additional namespaces, |
|
| 231 | + * use |
|
| 232 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 233 | + * directly) |
|
| 234 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 235 | + * @type string $FQNS the namespace prefix |
|
| 236 | + * @type string $DIR a base directory for class files in the |
|
| 237 | + * namespace. |
|
| 238 | + * } |
|
| 239 | + * } |
|
| 240 | + * @return void |
|
| 241 | + * @throws DomainException |
|
| 242 | + * @throws EE_Error |
|
| 243 | + * @throws InvalidArgumentException |
|
| 244 | + * @throws ReflectionException |
|
| 245 | + * @throws InvalidDataTypeException |
|
| 246 | + * @throws InvalidInterfaceException |
|
| 247 | + */ |
|
| 248 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 249 | + { |
|
| 250 | + // required fields MUST be present, so let's make sure they are. |
|
| 251 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 252 | + // get class name for addon |
|
| 253 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 254 | + //setup $_settings array from incoming values. |
|
| 255 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 256 | + // setup PUE |
|
| 257 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 258 | + // does this addon work with this version of core or WordPress ? |
|
| 259 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 260 | + return; |
|
| 261 | + } |
|
| 262 | + // register namespaces |
|
| 263 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 264 | + // check if this is an activation request |
|
| 265 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 266 | + // dont bother setting up the rest of the addon atm |
|
| 267 | + return; |
|
| 268 | + } |
|
| 269 | + // we need cars |
|
| 270 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 271 | + // register new models and extensions |
|
| 272 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 273 | + // setup DMS |
|
| 274 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 275 | + // if config_class is present let's register config. |
|
| 276 | + EE_Register_Addon::_register_config($addon_name); |
|
| 277 | + // register admin pages |
|
| 278 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 279 | + // add to list of modules to be registered |
|
| 280 | + EE_Register_Addon::_register_modules($addon_name); |
|
| 281 | + // add to list of shortcodes to be registered |
|
| 282 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 283 | + // add to list of widgets to be registered |
|
| 284 | + EE_Register_Addon::_register_widgets($addon_name); |
|
| 285 | + // register capability related stuff. |
|
| 286 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
| 287 | + // any message type to register? |
|
| 288 | + EE_Register_Addon::_register_message_types($addon_name); |
|
| 289 | + // any custom post type/ custom capabilities or default terms to register |
|
| 290 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 291 | + // and any payment methods |
|
| 292 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 293 | + // load and instantiate main addon class |
|
| 294 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 295 | + //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 296 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * @param string $addon_name |
|
| 302 | - * @param array $setup_args |
|
| 303 | - * @return void |
|
| 304 | - * @throws EE_Error |
|
| 305 | - */ |
|
| 306 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
| 307 | - { |
|
| 308 | - // required fields MUST be present, so let's make sure they are. |
|
| 309 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 310 | - throw new EE_Error( |
|
| 311 | - __( |
|
| 312 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 313 | - 'event_espresso' |
|
| 314 | - ) |
|
| 315 | - ); |
|
| 316 | - } |
|
| 317 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 318 | - throw new EE_Error( |
|
| 319 | - sprintf( |
|
| 320 | - __( |
|
| 321 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 322 | - 'event_espresso' |
|
| 323 | - ), |
|
| 324 | - implode(',', array_keys($setup_args)) |
|
| 325 | - ) |
|
| 326 | - ); |
|
| 327 | - } |
|
| 328 | - // check that addon has not already been registered with that name |
|
| 329 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 330 | - throw new EE_Error( |
|
| 331 | - sprintf( |
|
| 332 | - __( |
|
| 333 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 334 | - 'event_espresso' |
|
| 335 | - ), |
|
| 336 | - $addon_name |
|
| 337 | - ) |
|
| 338 | - ); |
|
| 339 | - } |
|
| 340 | - } |
|
| 300 | + /** |
|
| 301 | + * @param string $addon_name |
|
| 302 | + * @param array $setup_args |
|
| 303 | + * @return void |
|
| 304 | + * @throws EE_Error |
|
| 305 | + */ |
|
| 306 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
| 307 | + { |
|
| 308 | + // required fields MUST be present, so let's make sure they are. |
|
| 309 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 310 | + throw new EE_Error( |
|
| 311 | + __( |
|
| 312 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 313 | + 'event_espresso' |
|
| 314 | + ) |
|
| 315 | + ); |
|
| 316 | + } |
|
| 317 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 318 | + throw new EE_Error( |
|
| 319 | + sprintf( |
|
| 320 | + __( |
|
| 321 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 322 | + 'event_espresso' |
|
| 323 | + ), |
|
| 324 | + implode(',', array_keys($setup_args)) |
|
| 325 | + ) |
|
| 326 | + ); |
|
| 327 | + } |
|
| 328 | + // check that addon has not already been registered with that name |
|
| 329 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 330 | + throw new EE_Error( |
|
| 331 | + sprintf( |
|
| 332 | + __( |
|
| 333 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 334 | + 'event_espresso' |
|
| 335 | + ), |
|
| 336 | + $addon_name |
|
| 337 | + ) |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * @param string $addon_name |
|
| 345 | - * @param array $setup_args |
|
| 346 | - * @return string |
|
| 347 | - */ |
|
| 348 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
| 349 | - { |
|
| 350 | - if (empty($setup_args['class_name'])) { |
|
| 351 | - // generate one by first separating name with spaces |
|
| 352 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 353 | - //capitalize, then replace spaces with underscores |
|
| 354 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 355 | - } else { |
|
| 356 | - $class_name = $setup_args['class_name']; |
|
| 357 | - } |
|
| 358 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 359 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 360 | - ? $class_name |
|
| 361 | - : 'EE_' . $class_name; |
|
| 362 | - } |
|
| 343 | + /** |
|
| 344 | + * @param string $addon_name |
|
| 345 | + * @param array $setup_args |
|
| 346 | + * @return string |
|
| 347 | + */ |
|
| 348 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
| 349 | + { |
|
| 350 | + if (empty($setup_args['class_name'])) { |
|
| 351 | + // generate one by first separating name with spaces |
|
| 352 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 353 | + //capitalize, then replace spaces with underscores |
|
| 354 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 355 | + } else { |
|
| 356 | + $class_name = $setup_args['class_name']; |
|
| 357 | + } |
|
| 358 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 359 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 360 | + ? $class_name |
|
| 361 | + : 'EE_' . $class_name; |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * @param string $class_name |
|
| 367 | - * @param array $setup_args |
|
| 368 | - * @return array |
|
| 369 | - */ |
|
| 370 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
| 371 | - { |
|
| 372 | - //setup $_settings array from incoming values. |
|
| 373 | - $addon_settings = array( |
|
| 374 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 375 | - 'class_name' => $class_name, |
|
| 376 | - // the addon slug for use in URLs, etc |
|
| 377 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 378 | - ? (string) $setup_args['plugin_slug'] |
|
| 379 | - : '', |
|
| 380 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 381 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 382 | - ? (string) $setup_args['plugin_action_slug'] |
|
| 383 | - : '', |
|
| 384 | - // the "software" version for the addon |
|
| 385 | - 'version' => isset($setup_args['version']) |
|
| 386 | - ? (string) $setup_args['version'] |
|
| 387 | - : '', |
|
| 388 | - // the minimum version of EE Core that the addon will work with |
|
| 389 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 390 | - ? (string) $setup_args['min_core_version'] |
|
| 391 | - : '', |
|
| 392 | - // the minimum version of WordPress that the addon will work with |
|
| 393 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 394 | - ? (string) $setup_args['min_wp_version'] |
|
| 395 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 396 | - // full server path to main file (file loaded directly by WP) |
|
| 397 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 398 | - ? (string) $setup_args['main_file_path'] |
|
| 399 | - : '', |
|
| 400 | - // Fully Qualified Class Name for the addon's Domain class |
|
| 401 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 402 | - ? (string) $setup_args['domain_fqcn'] |
|
| 403 | - : '', |
|
| 404 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 405 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 406 | - ? (string) $setup_args['admin_path'] : '', |
|
| 407 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 408 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 409 | - ? (string) $setup_args['admin_callback'] |
|
| 410 | - : '', |
|
| 411 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 412 | - 'config_section' => isset($setup_args['config_section']) |
|
| 413 | - ? (string) $setup_args['config_section'] |
|
| 414 | - : 'addons', |
|
| 415 | - // the class name for this addon's configuration settings object |
|
| 416 | - 'config_class' => isset($setup_args['config_class']) |
|
| 417 | - ? (string) $setup_args['config_class'] : '', |
|
| 418 | - //the name given to the config for this addons' configuration settings object (optional) |
|
| 419 | - 'config_name' => isset($setup_args['config_name']) |
|
| 420 | - ? (string) $setup_args['config_name'] : '', |
|
| 421 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 422 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 423 | - ? (array) $setup_args['autoloader_paths'] |
|
| 424 | - : array(), |
|
| 425 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 426 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 427 | - ? (array) $setup_args['autoloader_folders'] |
|
| 428 | - : array(), |
|
| 429 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
| 430 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
| 431 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 432 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 433 | - ? (array) $setup_args['dms_paths'] |
|
| 434 | - : array(), |
|
| 435 | - // array of full server paths to any EED_Modules used by the addon |
|
| 436 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 437 | - ? (array) $setup_args['module_paths'] |
|
| 438 | - : array(), |
|
| 439 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 440 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 441 | - ? (array) $setup_args['shortcode_paths'] |
|
| 442 | - : array(), |
|
| 443 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 444 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 445 | - : array(), |
|
| 446 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 447 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 448 | - ? (array) $setup_args['widget_paths'] |
|
| 449 | - : array(), |
|
| 450 | - // array of PUE options used by the addon |
|
| 451 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 452 | - ? (array) $setup_args['pue_options'] |
|
| 453 | - : array(), |
|
| 454 | - 'message_types' => isset($setup_args['message_types']) |
|
| 455 | - ? (array) $setup_args['message_types'] |
|
| 456 | - : array(), |
|
| 457 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 458 | - ? (array) $setup_args['capabilities'] |
|
| 459 | - : array(), |
|
| 460 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 461 | - ? (array) $setup_args['capability_maps'] |
|
| 462 | - : array(), |
|
| 463 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 464 | - ? (array) $setup_args['model_paths'] |
|
| 465 | - : array(), |
|
| 466 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 467 | - ? (array) $setup_args['class_paths'] |
|
| 468 | - : array(), |
|
| 469 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 470 | - ? (array) $setup_args['model_extension_paths'] |
|
| 471 | - : array(), |
|
| 472 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 473 | - ? (array) $setup_args['class_extension_paths'] |
|
| 474 | - : array(), |
|
| 475 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 476 | - ? (array) $setup_args['custom_post_types'] |
|
| 477 | - : array(), |
|
| 478 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 479 | - ? (array) $setup_args['custom_taxonomies'] |
|
| 480 | - : array(), |
|
| 481 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 482 | - ? (array) $setup_args['payment_method_paths'] |
|
| 483 | - : array(), |
|
| 484 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 485 | - ? (array) $setup_args['default_terms'] |
|
| 486 | - : array(), |
|
| 487 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 488 | - // that can be used for adding upgrading/marketing info |
|
| 489 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 490 | - ? $setup_args['plugins_page_row'] |
|
| 491 | - : '', |
|
| 492 | - 'namespace' => isset( |
|
| 493 | - $setup_args['namespace']['FQNS'], |
|
| 494 | - $setup_args['namespace']['DIR'] |
|
| 495 | - ) |
|
| 496 | - ? (array) $setup_args['namespace'] |
|
| 497 | - : array(), |
|
| 498 | - ); |
|
| 499 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 500 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 501 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 502 | - && ! empty($addon_settings['admin_path']) |
|
| 503 | - ? $addon_settings['plugin_slug'] |
|
| 504 | - : $addon_settings['plugin_action_slug']; |
|
| 505 | - // full server path to main file (file loaded directly by WP) |
|
| 506 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 507 | - return $addon_settings; |
|
| 508 | - } |
|
| 365 | + /** |
|
| 366 | + * @param string $class_name |
|
| 367 | + * @param array $setup_args |
|
| 368 | + * @return array |
|
| 369 | + */ |
|
| 370 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
| 371 | + { |
|
| 372 | + //setup $_settings array from incoming values. |
|
| 373 | + $addon_settings = array( |
|
| 374 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 375 | + 'class_name' => $class_name, |
|
| 376 | + // the addon slug for use in URLs, etc |
|
| 377 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 378 | + ? (string) $setup_args['plugin_slug'] |
|
| 379 | + : '', |
|
| 380 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 381 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 382 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 383 | + : '', |
|
| 384 | + // the "software" version for the addon |
|
| 385 | + 'version' => isset($setup_args['version']) |
|
| 386 | + ? (string) $setup_args['version'] |
|
| 387 | + : '', |
|
| 388 | + // the minimum version of EE Core that the addon will work with |
|
| 389 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 390 | + ? (string) $setup_args['min_core_version'] |
|
| 391 | + : '', |
|
| 392 | + // the minimum version of WordPress that the addon will work with |
|
| 393 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 394 | + ? (string) $setup_args['min_wp_version'] |
|
| 395 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 396 | + // full server path to main file (file loaded directly by WP) |
|
| 397 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 398 | + ? (string) $setup_args['main_file_path'] |
|
| 399 | + : '', |
|
| 400 | + // Fully Qualified Class Name for the addon's Domain class |
|
| 401 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 402 | + ? (string) $setup_args['domain_fqcn'] |
|
| 403 | + : '', |
|
| 404 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 405 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 406 | + ? (string) $setup_args['admin_path'] : '', |
|
| 407 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 408 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 409 | + ? (string) $setup_args['admin_callback'] |
|
| 410 | + : '', |
|
| 411 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 412 | + 'config_section' => isset($setup_args['config_section']) |
|
| 413 | + ? (string) $setup_args['config_section'] |
|
| 414 | + : 'addons', |
|
| 415 | + // the class name for this addon's configuration settings object |
|
| 416 | + 'config_class' => isset($setup_args['config_class']) |
|
| 417 | + ? (string) $setup_args['config_class'] : '', |
|
| 418 | + //the name given to the config for this addons' configuration settings object (optional) |
|
| 419 | + 'config_name' => isset($setup_args['config_name']) |
|
| 420 | + ? (string) $setup_args['config_name'] : '', |
|
| 421 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 422 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 423 | + ? (array) $setup_args['autoloader_paths'] |
|
| 424 | + : array(), |
|
| 425 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 426 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 427 | + ? (array) $setup_args['autoloader_folders'] |
|
| 428 | + : array(), |
|
| 429 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
| 430 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
| 431 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 432 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 433 | + ? (array) $setup_args['dms_paths'] |
|
| 434 | + : array(), |
|
| 435 | + // array of full server paths to any EED_Modules used by the addon |
|
| 436 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 437 | + ? (array) $setup_args['module_paths'] |
|
| 438 | + : array(), |
|
| 439 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 440 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 441 | + ? (array) $setup_args['shortcode_paths'] |
|
| 442 | + : array(), |
|
| 443 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 444 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 445 | + : array(), |
|
| 446 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 447 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 448 | + ? (array) $setup_args['widget_paths'] |
|
| 449 | + : array(), |
|
| 450 | + // array of PUE options used by the addon |
|
| 451 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 452 | + ? (array) $setup_args['pue_options'] |
|
| 453 | + : array(), |
|
| 454 | + 'message_types' => isset($setup_args['message_types']) |
|
| 455 | + ? (array) $setup_args['message_types'] |
|
| 456 | + : array(), |
|
| 457 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 458 | + ? (array) $setup_args['capabilities'] |
|
| 459 | + : array(), |
|
| 460 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 461 | + ? (array) $setup_args['capability_maps'] |
|
| 462 | + : array(), |
|
| 463 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 464 | + ? (array) $setup_args['model_paths'] |
|
| 465 | + : array(), |
|
| 466 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 467 | + ? (array) $setup_args['class_paths'] |
|
| 468 | + : array(), |
|
| 469 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 470 | + ? (array) $setup_args['model_extension_paths'] |
|
| 471 | + : array(), |
|
| 472 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 473 | + ? (array) $setup_args['class_extension_paths'] |
|
| 474 | + : array(), |
|
| 475 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 476 | + ? (array) $setup_args['custom_post_types'] |
|
| 477 | + : array(), |
|
| 478 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 479 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 480 | + : array(), |
|
| 481 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 482 | + ? (array) $setup_args['payment_method_paths'] |
|
| 483 | + : array(), |
|
| 484 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 485 | + ? (array) $setup_args['default_terms'] |
|
| 486 | + : array(), |
|
| 487 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 488 | + // that can be used for adding upgrading/marketing info |
|
| 489 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 490 | + ? $setup_args['plugins_page_row'] |
|
| 491 | + : '', |
|
| 492 | + 'namespace' => isset( |
|
| 493 | + $setup_args['namespace']['FQNS'], |
|
| 494 | + $setup_args['namespace']['DIR'] |
|
| 495 | + ) |
|
| 496 | + ? (array) $setup_args['namespace'] |
|
| 497 | + : array(), |
|
| 498 | + ); |
|
| 499 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 500 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 501 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 502 | + && ! empty($addon_settings['admin_path']) |
|
| 503 | + ? $addon_settings['plugin_slug'] |
|
| 504 | + : $addon_settings['plugin_action_slug']; |
|
| 505 | + // full server path to main file (file loaded directly by WP) |
|
| 506 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 507 | + return $addon_settings; |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | 510 | |
| 511 | - /** |
|
| 512 | - * @param string $addon_name |
|
| 513 | - * @param array $addon_settings |
|
| 514 | - * @return boolean |
|
| 515 | - */ |
|
| 516 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 517 | - { |
|
| 518 | - global $wp_version; |
|
| 519 | - $incompatibility_message = ''; |
|
| 520 | - //check whether this addon version is compatible with EE core |
|
| 521 | - if ( |
|
| 522 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 523 | - && ! self::_meets_min_core_version_requirement( |
|
| 524 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 525 | - $addon_settings['version'] |
|
| 526 | - ) |
|
| 527 | - ) { |
|
| 528 | - $incompatibility_message = sprintf( |
|
| 529 | - __( |
|
| 530 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 531 | - ), |
|
| 532 | - $addon_name, |
|
| 533 | - '<br />', |
|
| 534 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 535 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 536 | - '</span><br />' |
|
| 537 | - ); |
|
| 538 | - } elseif ( |
|
| 539 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 540 | - ) { |
|
| 541 | - $incompatibility_message = sprintf( |
|
| 542 | - __( |
|
| 543 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 544 | - 'event_espresso' |
|
| 545 | - ), |
|
| 546 | - $addon_name, |
|
| 547 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 548 | - self::_effective_version(espresso_version()), |
|
| 549 | - '<br />', |
|
| 550 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 551 | - '</span><br />' |
|
| 552 | - ); |
|
| 553 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 554 | - $incompatibility_message = sprintf( |
|
| 555 | - __( |
|
| 556 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 557 | - 'event_espresso' |
|
| 558 | - ), |
|
| 559 | - $addon_name, |
|
| 560 | - $addon_settings['min_wp_version'], |
|
| 561 | - '<br />', |
|
| 562 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 563 | - '</span><br />' |
|
| 564 | - ); |
|
| 565 | - } |
|
| 566 | - if (! empty($incompatibility_message)) { |
|
| 567 | - // remove 'activate' from the REQUEST |
|
| 568 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 569 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 570 | - if (current_user_can('activate_plugins')) { |
|
| 571 | - // show an error message indicating the plugin didn't activate properly |
|
| 572 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 573 | - } |
|
| 574 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 575 | - return false; |
|
| 576 | - } |
|
| 577 | - // addon IS compatible |
|
| 578 | - return true; |
|
| 579 | - } |
|
| 511 | + /** |
|
| 512 | + * @param string $addon_name |
|
| 513 | + * @param array $addon_settings |
|
| 514 | + * @return boolean |
|
| 515 | + */ |
|
| 516 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 517 | + { |
|
| 518 | + global $wp_version; |
|
| 519 | + $incompatibility_message = ''; |
|
| 520 | + //check whether this addon version is compatible with EE core |
|
| 521 | + if ( |
|
| 522 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 523 | + && ! self::_meets_min_core_version_requirement( |
|
| 524 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 525 | + $addon_settings['version'] |
|
| 526 | + ) |
|
| 527 | + ) { |
|
| 528 | + $incompatibility_message = sprintf( |
|
| 529 | + __( |
|
| 530 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 531 | + ), |
|
| 532 | + $addon_name, |
|
| 533 | + '<br />', |
|
| 534 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 535 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 536 | + '</span><br />' |
|
| 537 | + ); |
|
| 538 | + } elseif ( |
|
| 539 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 540 | + ) { |
|
| 541 | + $incompatibility_message = sprintf( |
|
| 542 | + __( |
|
| 543 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 544 | + 'event_espresso' |
|
| 545 | + ), |
|
| 546 | + $addon_name, |
|
| 547 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 548 | + self::_effective_version(espresso_version()), |
|
| 549 | + '<br />', |
|
| 550 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 551 | + '</span><br />' |
|
| 552 | + ); |
|
| 553 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 554 | + $incompatibility_message = sprintf( |
|
| 555 | + __( |
|
| 556 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 557 | + 'event_espresso' |
|
| 558 | + ), |
|
| 559 | + $addon_name, |
|
| 560 | + $addon_settings['min_wp_version'], |
|
| 561 | + '<br />', |
|
| 562 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 563 | + '</span><br />' |
|
| 564 | + ); |
|
| 565 | + } |
|
| 566 | + if (! empty($incompatibility_message)) { |
|
| 567 | + // remove 'activate' from the REQUEST |
|
| 568 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 569 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 570 | + if (current_user_can('activate_plugins')) { |
|
| 571 | + // show an error message indicating the plugin didn't activate properly |
|
| 572 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 573 | + } |
|
| 574 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 575 | + return false; |
|
| 576 | + } |
|
| 577 | + // addon IS compatible |
|
| 578 | + return true; |
|
| 579 | + } |
|
| 580 | 580 | |
| 581 | 581 | |
| 582 | - /** |
|
| 583 | - * if plugin update engine is being used for auto-updates, |
|
| 584 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 585 | - * (not needed if PUE is not being used) |
|
| 586 | - * |
|
| 587 | - * @param string $addon_name |
|
| 588 | - * @param string $class_name |
|
| 589 | - * @param array $setup_args |
|
| 590 | - * @return void |
|
| 591 | - */ |
|
| 592 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 593 | - { |
|
| 594 | - if (! empty($setup_args['pue_options'])) { |
|
| 595 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 596 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 597 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 598 | - : 'espresso_' . strtolower($class_name), |
|
| 599 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 600 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 601 | - : plugin_basename($setup_args['main_file_path']), |
|
| 602 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 603 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 604 | - : '24', |
|
| 605 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 606 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 607 | - : false, |
|
| 608 | - ); |
|
| 609 | - add_action( |
|
| 610 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 611 | - array('EE_Register_Addon', 'load_pue_update') |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - } |
|
| 582 | + /** |
|
| 583 | + * if plugin update engine is being used for auto-updates, |
|
| 584 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 585 | + * (not needed if PUE is not being used) |
|
| 586 | + * |
|
| 587 | + * @param string $addon_name |
|
| 588 | + * @param string $class_name |
|
| 589 | + * @param array $setup_args |
|
| 590 | + * @return void |
|
| 591 | + */ |
|
| 592 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 593 | + { |
|
| 594 | + if (! empty($setup_args['pue_options'])) { |
|
| 595 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 596 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 597 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 598 | + : 'espresso_' . strtolower($class_name), |
|
| 599 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 600 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 601 | + : plugin_basename($setup_args['main_file_path']), |
|
| 602 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 603 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 604 | + : '24', |
|
| 605 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 606 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 607 | + : false, |
|
| 608 | + ); |
|
| 609 | + add_action( |
|
| 610 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 611 | + array('EE_Register_Addon', 'load_pue_update') |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | 615 | |
| 616 | 616 | |
| 617 | - /** |
|
| 618 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 619 | - * |
|
| 620 | - * @param array $addon_settings |
|
| 621 | - * @return void |
|
| 622 | - */ |
|
| 623 | - private static function _setup_namespaces(array $addon_settings) |
|
| 624 | - { |
|
| 625 | - // |
|
| 626 | - if ( |
|
| 627 | - isset( |
|
| 628 | - $addon_settings['namespace']['FQNS'], |
|
| 629 | - $addon_settings['namespace']['DIR'] |
|
| 630 | - ) |
|
| 631 | - ) { |
|
| 632 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 633 | - $addon_settings['namespace']['FQNS'], |
|
| 634 | - $addon_settings['namespace']['DIR'] |
|
| 635 | - ); |
|
| 636 | - } |
|
| 637 | - } |
|
| 617 | + /** |
|
| 618 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 619 | + * |
|
| 620 | + * @param array $addon_settings |
|
| 621 | + * @return void |
|
| 622 | + */ |
|
| 623 | + private static function _setup_namespaces(array $addon_settings) |
|
| 624 | + { |
|
| 625 | + // |
|
| 626 | + if ( |
|
| 627 | + isset( |
|
| 628 | + $addon_settings['namespace']['FQNS'], |
|
| 629 | + $addon_settings['namespace']['DIR'] |
|
| 630 | + ) |
|
| 631 | + ) { |
|
| 632 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 633 | + $addon_settings['namespace']['FQNS'], |
|
| 634 | + $addon_settings['namespace']['DIR'] |
|
| 635 | + ); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | 638 | |
| 639 | 639 | |
| 640 | - /** |
|
| 641 | - * @param string $addon_name |
|
| 642 | - * @param array $addon_settings |
|
| 643 | - * @return bool |
|
| 644 | - * @throws EE_Error |
|
| 645 | - * @throws InvalidArgumentException |
|
| 646 | - * @throws ReflectionException |
|
| 647 | - * @throws InvalidDataTypeException |
|
| 648 | - * @throws InvalidInterfaceException |
|
| 649 | - */ |
|
| 650 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
| 651 | - { |
|
| 652 | - // this is an activation request |
|
| 653 | - if (did_action('activate_plugin')) { |
|
| 654 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 655 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 656 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 657 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 658 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 659 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 660 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 661 | - ) |
|
| 662 | - ) { |
|
| 663 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 664 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 665 | - $addon->set_activation_indicator_option(); |
|
| 666 | - // dont bother setting up the rest of the addon. |
|
| 667 | - // we know it was just activated and the request will end soon |
|
| 668 | - } |
|
| 669 | - return true; |
|
| 670 | - } |
|
| 671 | - // make sure this was called in the right place! |
|
| 672 | - if ( |
|
| 673 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 674 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 675 | - ) { |
|
| 676 | - EE_Error::doing_it_wrong( |
|
| 677 | - __METHOD__, |
|
| 678 | - sprintf( |
|
| 679 | - __( |
|
| 680 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 681 | - 'event_espresso' |
|
| 682 | - ), |
|
| 683 | - $addon_name |
|
| 684 | - ), |
|
| 685 | - '4.3.0' |
|
| 686 | - ); |
|
| 687 | - } |
|
| 688 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 689 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 690 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 691 | - } else { |
|
| 692 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 693 | - } |
|
| 694 | - return false; |
|
| 695 | - } |
|
| 640 | + /** |
|
| 641 | + * @param string $addon_name |
|
| 642 | + * @param array $addon_settings |
|
| 643 | + * @return bool |
|
| 644 | + * @throws EE_Error |
|
| 645 | + * @throws InvalidArgumentException |
|
| 646 | + * @throws ReflectionException |
|
| 647 | + * @throws InvalidDataTypeException |
|
| 648 | + * @throws InvalidInterfaceException |
|
| 649 | + */ |
|
| 650 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
| 651 | + { |
|
| 652 | + // this is an activation request |
|
| 653 | + if (did_action('activate_plugin')) { |
|
| 654 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 655 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 656 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 657 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 658 | + if (! isset(self::$_settings[ $addon_name ]) |
|
| 659 | + || (isset(self::$_settings[ $addon_name ]) |
|
| 660 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 661 | + ) |
|
| 662 | + ) { |
|
| 663 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 664 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 665 | + $addon->set_activation_indicator_option(); |
|
| 666 | + // dont bother setting up the rest of the addon. |
|
| 667 | + // we know it was just activated and the request will end soon |
|
| 668 | + } |
|
| 669 | + return true; |
|
| 670 | + } |
|
| 671 | + // make sure this was called in the right place! |
|
| 672 | + if ( |
|
| 673 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 674 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 675 | + ) { |
|
| 676 | + EE_Error::doing_it_wrong( |
|
| 677 | + __METHOD__, |
|
| 678 | + sprintf( |
|
| 679 | + __( |
|
| 680 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 681 | + 'event_espresso' |
|
| 682 | + ), |
|
| 683 | + $addon_name |
|
| 684 | + ), |
|
| 685 | + '4.3.0' |
|
| 686 | + ); |
|
| 687 | + } |
|
| 688 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 689 | + if (isset(self::$_settings[ $addon_name ])) { |
|
| 690 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
| 691 | + } else { |
|
| 692 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 693 | + } |
|
| 694 | + return false; |
|
| 695 | + } |
|
| 696 | 696 | |
| 697 | 697 | |
| 698 | - /** |
|
| 699 | - * @param string $addon_name |
|
| 700 | - * @return void |
|
| 701 | - * @throws EE_Error |
|
| 702 | - */ |
|
| 703 | - private static function _setup_autoloaders($addon_name) |
|
| 704 | - { |
|
| 705 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 706 | - // setup autoloader for single file |
|
| 707 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 708 | - } |
|
| 709 | - // setup autoloaders for folders |
|
| 710 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 711 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 712 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 713 | - } |
|
| 714 | - } |
|
| 715 | - } |
|
| 698 | + /** |
|
| 699 | + * @param string $addon_name |
|
| 700 | + * @return void |
|
| 701 | + * @throws EE_Error |
|
| 702 | + */ |
|
| 703 | + private static function _setup_autoloaders($addon_name) |
|
| 704 | + { |
|
| 705 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 706 | + // setup autoloader for single file |
|
| 707 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 708 | + } |
|
| 709 | + // setup autoloaders for folders |
|
| 710 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 711 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 712 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 713 | + } |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | 717 | |
| 718 | - /** |
|
| 719 | - * register new models and extensions |
|
| 720 | - * |
|
| 721 | - * @param string $addon_name |
|
| 722 | - * @return void |
|
| 723 | - * @throws EE_Error |
|
| 724 | - */ |
|
| 725 | - private static function _register_models_and_extensions($addon_name) |
|
| 726 | - { |
|
| 727 | - // register new models |
|
| 728 | - if ( |
|
| 729 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 730 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 731 | - ) { |
|
| 732 | - EE_Register_Model::register( |
|
| 733 | - $addon_name, |
|
| 734 | - array( |
|
| 735 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 736 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 737 | - ) |
|
| 738 | - ); |
|
| 739 | - } |
|
| 740 | - // register model extensions |
|
| 741 | - if ( |
|
| 742 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 743 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 744 | - ) { |
|
| 745 | - EE_Register_Model_Extensions::register( |
|
| 746 | - $addon_name, |
|
| 747 | - array( |
|
| 748 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 749 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 750 | - ) |
|
| 751 | - ); |
|
| 752 | - } |
|
| 753 | - } |
|
| 718 | + /** |
|
| 719 | + * register new models and extensions |
|
| 720 | + * |
|
| 721 | + * @param string $addon_name |
|
| 722 | + * @return void |
|
| 723 | + * @throws EE_Error |
|
| 724 | + */ |
|
| 725 | + private static function _register_models_and_extensions($addon_name) |
|
| 726 | + { |
|
| 727 | + // register new models |
|
| 728 | + if ( |
|
| 729 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 730 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 731 | + ) { |
|
| 732 | + EE_Register_Model::register( |
|
| 733 | + $addon_name, |
|
| 734 | + array( |
|
| 735 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 736 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 737 | + ) |
|
| 738 | + ); |
|
| 739 | + } |
|
| 740 | + // register model extensions |
|
| 741 | + if ( |
|
| 742 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 743 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 744 | + ) { |
|
| 745 | + EE_Register_Model_Extensions::register( |
|
| 746 | + $addon_name, |
|
| 747 | + array( |
|
| 748 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 749 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 750 | + ) |
|
| 751 | + ); |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | 755 | |
| 756 | - /** |
|
| 757 | - * @param string $addon_name |
|
| 758 | - * @return void |
|
| 759 | - * @throws EE_Error |
|
| 760 | - */ |
|
| 761 | - private static function _register_data_migration_scripts($addon_name) |
|
| 762 | - { |
|
| 763 | - // setup DMS |
|
| 764 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 765 | - EE_Register_Data_Migration_Scripts::register( |
|
| 766 | - $addon_name, |
|
| 767 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 768 | - ); |
|
| 769 | - } |
|
| 770 | - } |
|
| 756 | + /** |
|
| 757 | + * @param string $addon_name |
|
| 758 | + * @return void |
|
| 759 | + * @throws EE_Error |
|
| 760 | + */ |
|
| 761 | + private static function _register_data_migration_scripts($addon_name) |
|
| 762 | + { |
|
| 763 | + // setup DMS |
|
| 764 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 765 | + EE_Register_Data_Migration_Scripts::register( |
|
| 766 | + $addon_name, |
|
| 767 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 768 | + ); |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | 771 | |
| 772 | 772 | |
| 773 | - /** |
|
| 774 | - * @param string $addon_name |
|
| 775 | - * @return void |
|
| 776 | - * @throws EE_Error |
|
| 777 | - */ |
|
| 778 | - private static function _register_config($addon_name) |
|
| 779 | - { |
|
| 780 | - // if config_class is present let's register config. |
|
| 781 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 782 | - EE_Register_Config::register( |
|
| 783 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 784 | - array( |
|
| 785 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 786 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 787 | - ) |
|
| 788 | - ); |
|
| 789 | - } |
|
| 790 | - } |
|
| 773 | + /** |
|
| 774 | + * @param string $addon_name |
|
| 775 | + * @return void |
|
| 776 | + * @throws EE_Error |
|
| 777 | + */ |
|
| 778 | + private static function _register_config($addon_name) |
|
| 779 | + { |
|
| 780 | + // if config_class is present let's register config. |
|
| 781 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 782 | + EE_Register_Config::register( |
|
| 783 | + self::$_settings[ $addon_name ]['config_class'], |
|
| 784 | + array( |
|
| 785 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 786 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 787 | + ) |
|
| 788 | + ); |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | 791 | |
| 792 | 792 | |
| 793 | - /** |
|
| 794 | - * @param string $addon_name |
|
| 795 | - * @return void |
|
| 796 | - * @throws EE_Error |
|
| 797 | - */ |
|
| 798 | - private static function _register_admin_pages($addon_name) |
|
| 799 | - { |
|
| 800 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 801 | - EE_Register_Admin_Page::register( |
|
| 802 | - $addon_name, |
|
| 803 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 804 | - ); |
|
| 805 | - } |
|
| 806 | - } |
|
| 793 | + /** |
|
| 794 | + * @param string $addon_name |
|
| 795 | + * @return void |
|
| 796 | + * @throws EE_Error |
|
| 797 | + */ |
|
| 798 | + private static function _register_admin_pages($addon_name) |
|
| 799 | + { |
|
| 800 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 801 | + EE_Register_Admin_Page::register( |
|
| 802 | + $addon_name, |
|
| 803 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 804 | + ); |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | 807 | |
| 808 | 808 | |
| 809 | - /** |
|
| 810 | - * @param string $addon_name |
|
| 811 | - * @return void |
|
| 812 | - * @throws EE_Error |
|
| 813 | - */ |
|
| 814 | - private static function _register_modules($addon_name) |
|
| 815 | - { |
|
| 816 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 817 | - EE_Register_Module::register( |
|
| 818 | - $addon_name, |
|
| 819 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 820 | - ); |
|
| 821 | - } |
|
| 822 | - } |
|
| 809 | + /** |
|
| 810 | + * @param string $addon_name |
|
| 811 | + * @return void |
|
| 812 | + * @throws EE_Error |
|
| 813 | + */ |
|
| 814 | + private static function _register_modules($addon_name) |
|
| 815 | + { |
|
| 816 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 817 | + EE_Register_Module::register( |
|
| 818 | + $addon_name, |
|
| 819 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 820 | + ); |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | 823 | |
| 824 | 824 | |
| 825 | - /** |
|
| 826 | - * @param string $addon_name |
|
| 827 | - * @return void |
|
| 828 | - * @throws EE_Error |
|
| 829 | - */ |
|
| 830 | - private static function _register_shortcodes($addon_name) |
|
| 831 | - { |
|
| 832 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 833 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 834 | - ) { |
|
| 835 | - EE_Register_Shortcode::register( |
|
| 836 | - $addon_name, |
|
| 837 | - array( |
|
| 838 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 839 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 840 | - : array(), |
|
| 841 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 842 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 843 | - : array(), |
|
| 844 | - ) |
|
| 845 | - ); |
|
| 846 | - } |
|
| 847 | - } |
|
| 825 | + /** |
|
| 826 | + * @param string $addon_name |
|
| 827 | + * @return void |
|
| 828 | + * @throws EE_Error |
|
| 829 | + */ |
|
| 830 | + private static function _register_shortcodes($addon_name) |
|
| 831 | + { |
|
| 832 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 833 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 834 | + ) { |
|
| 835 | + EE_Register_Shortcode::register( |
|
| 836 | + $addon_name, |
|
| 837 | + array( |
|
| 838 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 839 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 840 | + : array(), |
|
| 841 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 842 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 843 | + : array(), |
|
| 844 | + ) |
|
| 845 | + ); |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | 848 | |
| 849 | 849 | |
| 850 | - /** |
|
| 851 | - * @param string $addon_name |
|
| 852 | - * @return void |
|
| 853 | - * @throws EE_Error |
|
| 854 | - */ |
|
| 855 | - private static function _register_widgets($addon_name) |
|
| 856 | - { |
|
| 857 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 858 | - EE_Register_Widget::register( |
|
| 859 | - $addon_name, |
|
| 860 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 861 | - ); |
|
| 862 | - } |
|
| 863 | - } |
|
| 850 | + /** |
|
| 851 | + * @param string $addon_name |
|
| 852 | + * @return void |
|
| 853 | + * @throws EE_Error |
|
| 854 | + */ |
|
| 855 | + private static function _register_widgets($addon_name) |
|
| 856 | + { |
|
| 857 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 858 | + EE_Register_Widget::register( |
|
| 859 | + $addon_name, |
|
| 860 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 861 | + ); |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | 865 | |
| 866 | - /** |
|
| 867 | - * @param string $addon_name |
|
| 868 | - * @return void |
|
| 869 | - * @throws EE_Error |
|
| 870 | - */ |
|
| 871 | - private static function _register_capabilities($addon_name) |
|
| 872 | - { |
|
| 873 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 874 | - EE_Register_Capabilities::register( |
|
| 875 | - $addon_name, |
|
| 876 | - array( |
|
| 877 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 878 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 879 | - ) |
|
| 880 | - ); |
|
| 881 | - } |
|
| 882 | - } |
|
| 866 | + /** |
|
| 867 | + * @param string $addon_name |
|
| 868 | + * @return void |
|
| 869 | + * @throws EE_Error |
|
| 870 | + */ |
|
| 871 | + private static function _register_capabilities($addon_name) |
|
| 872 | + { |
|
| 873 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 874 | + EE_Register_Capabilities::register( |
|
| 875 | + $addon_name, |
|
| 876 | + array( |
|
| 877 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 878 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 879 | + ) |
|
| 880 | + ); |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | 883 | |
| 884 | 884 | |
| 885 | - /** |
|
| 886 | - * @param string $addon_name |
|
| 887 | - * @return void |
|
| 888 | - * @throws EE_Error |
|
| 889 | - */ |
|
| 890 | - private static function _register_message_types($addon_name) |
|
| 891 | - { |
|
| 892 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 893 | - add_action( |
|
| 894 | - 'EE_Brewing_Regular___messages_caf', |
|
| 895 | - array('EE_Register_Addon', 'register_message_types') |
|
| 896 | - ); |
|
| 897 | - } |
|
| 898 | - } |
|
| 885 | + /** |
|
| 886 | + * @param string $addon_name |
|
| 887 | + * @return void |
|
| 888 | + * @throws EE_Error |
|
| 889 | + */ |
|
| 890 | + private static function _register_message_types($addon_name) |
|
| 891 | + { |
|
| 892 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 893 | + add_action( |
|
| 894 | + 'EE_Brewing_Regular___messages_caf', |
|
| 895 | + array('EE_Register_Addon', 'register_message_types') |
|
| 896 | + ); |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | 899 | |
| 900 | 900 | |
| 901 | - /** |
|
| 902 | - * @param string $addon_name |
|
| 903 | - * @return void |
|
| 904 | - * @throws EE_Error |
|
| 905 | - */ |
|
| 906 | - private static function _register_custom_post_types($addon_name) |
|
| 907 | - { |
|
| 908 | - if ( |
|
| 909 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 910 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 911 | - ) { |
|
| 912 | - EE_Register_CPT::register( |
|
| 913 | - $addon_name, |
|
| 914 | - array( |
|
| 915 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 916 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 917 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 918 | - ) |
|
| 919 | - ); |
|
| 920 | - } |
|
| 921 | - } |
|
| 901 | + /** |
|
| 902 | + * @param string $addon_name |
|
| 903 | + * @return void |
|
| 904 | + * @throws EE_Error |
|
| 905 | + */ |
|
| 906 | + private static function _register_custom_post_types($addon_name) |
|
| 907 | + { |
|
| 908 | + if ( |
|
| 909 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 910 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 911 | + ) { |
|
| 912 | + EE_Register_CPT::register( |
|
| 913 | + $addon_name, |
|
| 914 | + array( |
|
| 915 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 916 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 917 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 918 | + ) |
|
| 919 | + ); |
|
| 920 | + } |
|
| 921 | + } |
|
| 922 | 922 | |
| 923 | 923 | |
| 924 | - /** |
|
| 925 | - * @param string $addon_name |
|
| 926 | - * @return void |
|
| 927 | - * @throws InvalidArgumentException |
|
| 928 | - * @throws InvalidInterfaceException |
|
| 929 | - * @throws InvalidDataTypeException |
|
| 930 | - * @throws DomainException |
|
| 931 | - * @throws EE_Error |
|
| 932 | - */ |
|
| 933 | - private static function _register_payment_methods($addon_name) |
|
| 934 | - { |
|
| 935 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 936 | - EE_Register_Payment_Method::register( |
|
| 937 | - $addon_name, |
|
| 938 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 939 | - ); |
|
| 940 | - } |
|
| 941 | - } |
|
| 924 | + /** |
|
| 925 | + * @param string $addon_name |
|
| 926 | + * @return void |
|
| 927 | + * @throws InvalidArgumentException |
|
| 928 | + * @throws InvalidInterfaceException |
|
| 929 | + * @throws InvalidDataTypeException |
|
| 930 | + * @throws DomainException |
|
| 931 | + * @throws EE_Error |
|
| 932 | + */ |
|
| 933 | + private static function _register_payment_methods($addon_name) |
|
| 934 | + { |
|
| 935 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 936 | + EE_Register_Payment_Method::register( |
|
| 937 | + $addon_name, |
|
| 938 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 939 | + ); |
|
| 940 | + } |
|
| 941 | + } |
|
| 942 | 942 | |
| 943 | 943 | |
| 944 | - /** |
|
| 945 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 946 | - * |
|
| 947 | - * @param string $addon_name |
|
| 948 | - * @return EE_Addon |
|
| 949 | - * @throws InvalidArgumentException |
|
| 950 | - * @throws InvalidInterfaceException |
|
| 951 | - * @throws InvalidDataTypeException |
|
| 952 | - * @throws ReflectionException |
|
| 953 | - * @throws EE_Error |
|
| 954 | - */ |
|
| 955 | - private static function _load_and_init_addon_class($addon_name) |
|
| 956 | - { |
|
| 957 | - $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 958 | - $addon = $loader->getShared( |
|
| 959 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 960 | - array('EE_Registry::create(addon)' => true) |
|
| 961 | - ); |
|
| 962 | - // setter inject dep map if required |
|
| 963 | - if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
| 964 | - $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
| 965 | - } |
|
| 966 | - // setter inject domain if required |
|
| 967 | - if ( |
|
| 968 | - $addon instanceof RequiresDomainInterface |
|
| 969 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 970 | - && $addon->domain() === null |
|
| 971 | - ) { |
|
| 972 | - $addon->setDomain( |
|
| 973 | - $loader->getShared( |
|
| 974 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 975 | - array( |
|
| 976 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
| 977 | - self::$_settings[ $addon_name ]['version'], |
|
| 978 | - ) |
|
| 979 | - ) |
|
| 980 | - ); |
|
| 981 | - } |
|
| 982 | - $addon->set_name($addon_name); |
|
| 983 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 984 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 985 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 986 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 987 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 988 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 989 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 990 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 991 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 992 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 993 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 994 | - //the plugin mainfile's path upon construction. |
|
| 995 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 996 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 997 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 998 | - add_action( |
|
| 999 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 1000 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1001 | - ); |
|
| 1002 | - } |
|
| 1003 | - return $addon; |
|
| 1004 | - } |
|
| 944 | + /** |
|
| 945 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 946 | + * |
|
| 947 | + * @param string $addon_name |
|
| 948 | + * @return EE_Addon |
|
| 949 | + * @throws InvalidArgumentException |
|
| 950 | + * @throws InvalidInterfaceException |
|
| 951 | + * @throws InvalidDataTypeException |
|
| 952 | + * @throws ReflectionException |
|
| 953 | + * @throws EE_Error |
|
| 954 | + */ |
|
| 955 | + private static function _load_and_init_addon_class($addon_name) |
|
| 956 | + { |
|
| 957 | + $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 958 | + $addon = $loader->getShared( |
|
| 959 | + self::$_settings[ $addon_name ]['class_name'], |
|
| 960 | + array('EE_Registry::create(addon)' => true) |
|
| 961 | + ); |
|
| 962 | + // setter inject dep map if required |
|
| 963 | + if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
| 964 | + $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
| 965 | + } |
|
| 966 | + // setter inject domain if required |
|
| 967 | + if ( |
|
| 968 | + $addon instanceof RequiresDomainInterface |
|
| 969 | + && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 970 | + && $addon->domain() === null |
|
| 971 | + ) { |
|
| 972 | + $addon->setDomain( |
|
| 973 | + $loader->getShared( |
|
| 974 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 975 | + array( |
|
| 976 | + self::$_settings[ $addon_name ]['main_file_path'], |
|
| 977 | + self::$_settings[ $addon_name ]['version'], |
|
| 978 | + ) |
|
| 979 | + ) |
|
| 980 | + ); |
|
| 981 | + } |
|
| 982 | + $addon->set_name($addon_name); |
|
| 983 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 984 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 985 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 986 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 987 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 988 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 989 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 990 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 991 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 992 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 993 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 994 | + //the plugin mainfile's path upon construction. |
|
| 995 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 996 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 997 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 998 | + add_action( |
|
| 999 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 1000 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1001 | + ); |
|
| 1002 | + } |
|
| 1003 | + return $addon; |
|
| 1004 | + } |
|
| 1005 | 1005 | |
| 1006 | 1006 | |
| 1007 | - /** |
|
| 1008 | - * load_pue_update - Update notifications |
|
| 1009 | - * |
|
| 1010 | - * @return void |
|
| 1011 | - * @throws InvalidArgumentException |
|
| 1012 | - * @throws InvalidDataTypeException |
|
| 1013 | - * @throws InvalidInterfaceException |
|
| 1014 | - */ |
|
| 1015 | - public static function load_pue_update() |
|
| 1016 | - { |
|
| 1017 | - // load PUE client |
|
| 1018 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1019 | - // cycle thru settings |
|
| 1020 | - foreach (self::$_settings as $settings) { |
|
| 1021 | - if (! empty($settings['pue_options'])) { |
|
| 1022 | - // initiate the class and start the plugin update engine! |
|
| 1023 | - new PluginUpdateEngineChecker( |
|
| 1024 | - // host file URL |
|
| 1025 | - 'https://eventespresso.com', |
|
| 1026 | - // plugin slug(s) |
|
| 1027 | - array( |
|
| 1028 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1029 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1030 | - ), |
|
| 1031 | - // options |
|
| 1032 | - array( |
|
| 1033 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1034 | - 'lang_domain' => 'event_espresso', |
|
| 1035 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1036 | - 'option_key' => 'site_license_key', |
|
| 1037 | - 'options_page_slug' => 'event_espresso', |
|
| 1038 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1039 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1040 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1041 | - ) |
|
| 1042 | - ); |
|
| 1043 | - } |
|
| 1044 | - } |
|
| 1045 | - } |
|
| 1007 | + /** |
|
| 1008 | + * load_pue_update - Update notifications |
|
| 1009 | + * |
|
| 1010 | + * @return void |
|
| 1011 | + * @throws InvalidArgumentException |
|
| 1012 | + * @throws InvalidDataTypeException |
|
| 1013 | + * @throws InvalidInterfaceException |
|
| 1014 | + */ |
|
| 1015 | + public static function load_pue_update() |
|
| 1016 | + { |
|
| 1017 | + // load PUE client |
|
| 1018 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1019 | + // cycle thru settings |
|
| 1020 | + foreach (self::$_settings as $settings) { |
|
| 1021 | + if (! empty($settings['pue_options'])) { |
|
| 1022 | + // initiate the class and start the plugin update engine! |
|
| 1023 | + new PluginUpdateEngineChecker( |
|
| 1024 | + // host file URL |
|
| 1025 | + 'https://eventespresso.com', |
|
| 1026 | + // plugin slug(s) |
|
| 1027 | + array( |
|
| 1028 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1029 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1030 | + ), |
|
| 1031 | + // options |
|
| 1032 | + array( |
|
| 1033 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1034 | + 'lang_domain' => 'event_espresso', |
|
| 1035 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1036 | + 'option_key' => 'site_license_key', |
|
| 1037 | + 'options_page_slug' => 'event_espresso', |
|
| 1038 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1039 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1040 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1041 | + ) |
|
| 1042 | + ); |
|
| 1043 | + } |
|
| 1044 | + } |
|
| 1045 | + } |
|
| 1046 | 1046 | |
| 1047 | 1047 | |
| 1048 | - /** |
|
| 1049 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1050 | - * |
|
| 1051 | - * @since 4.4.0 |
|
| 1052 | - * @return void |
|
| 1053 | - * @throws EE_Error |
|
| 1054 | - */ |
|
| 1055 | - public static function register_message_types() |
|
| 1056 | - { |
|
| 1057 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 1058 | - if (! empty($settings['message_types'])) { |
|
| 1059 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1060 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - } |
|
| 1064 | - } |
|
| 1048 | + /** |
|
| 1049 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1050 | + * |
|
| 1051 | + * @since 4.4.0 |
|
| 1052 | + * @return void |
|
| 1053 | + * @throws EE_Error |
|
| 1054 | + */ |
|
| 1055 | + public static function register_message_types() |
|
| 1056 | + { |
|
| 1057 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 1058 | + if (! empty($settings['message_types'])) { |
|
| 1059 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1060 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + } |
|
| 1064 | + } |
|
| 1065 | 1065 | |
| 1066 | 1066 | |
| 1067 | - /** |
|
| 1068 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1069 | - * |
|
| 1070 | - * @since 4.3.0 |
|
| 1071 | - * @param string $addon_name the name for the addon that was previously registered |
|
| 1072 | - * @throws DomainException |
|
| 1073 | - * @throws EE_Error |
|
| 1074 | - * @throws InvalidArgumentException |
|
| 1075 | - * @throws InvalidDataTypeException |
|
| 1076 | - * @throws InvalidInterfaceException |
|
| 1077 | - */ |
|
| 1078 | - public static function deregister($addon_name = null) |
|
| 1079 | - { |
|
| 1080 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1081 | - try { |
|
| 1082 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1083 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1084 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1085 | - // setup DMS |
|
| 1086 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1087 | - } |
|
| 1088 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1089 | - // register admin page |
|
| 1090 | - EE_Register_Admin_Page::deregister($addon_name); |
|
| 1091 | - } |
|
| 1092 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1093 | - // add to list of modules to be registered |
|
| 1094 | - EE_Register_Module::deregister($addon_name); |
|
| 1095 | - } |
|
| 1096 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1097 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1098 | - ) { |
|
| 1099 | - // add to list of shortcodes to be registered |
|
| 1100 | - EE_Register_Shortcode::deregister($addon_name); |
|
| 1101 | - } |
|
| 1102 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1103 | - // if config_class present let's register config. |
|
| 1104 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1105 | - } |
|
| 1106 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1107 | - // add to list of widgets to be registered |
|
| 1108 | - EE_Register_Widget::deregister($addon_name); |
|
| 1109 | - } |
|
| 1110 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1111 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1112 | - ) { |
|
| 1113 | - // add to list of shortcodes to be registered |
|
| 1114 | - EE_Register_Model::deregister($addon_name); |
|
| 1115 | - } |
|
| 1116 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1117 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1118 | - ) { |
|
| 1119 | - // add to list of shortcodes to be registered |
|
| 1120 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1121 | - } |
|
| 1122 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1123 | - foreach ( |
|
| 1124 | - (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
| 1125 | - $message_type_settings |
|
| 1126 | - ) { |
|
| 1127 | - EE_Register_Message_Type::deregister($message_type); |
|
| 1128 | - } |
|
| 1129 | - } |
|
| 1130 | - //deregister capabilities for addon |
|
| 1131 | - if ( |
|
| 1132 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1133 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1134 | - ) { |
|
| 1135 | - EE_Register_Capabilities::deregister($addon_name); |
|
| 1136 | - } |
|
| 1137 | - //deregister custom_post_types for addon |
|
| 1138 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1139 | - EE_Register_CPT::deregister($addon_name); |
|
| 1140 | - } |
|
| 1141 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1142 | - EE_Register_Payment_Method::deregister($addon_name); |
|
| 1143 | - } |
|
| 1144 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1145 | - if ($addon instanceof EE_Addon) { |
|
| 1146 | - remove_action( |
|
| 1147 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1148 | - array($addon, 'deactivation') |
|
| 1149 | - ); |
|
| 1150 | - remove_action( |
|
| 1151 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1152 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1153 | - ); |
|
| 1154 | - //remove `after_registration` call |
|
| 1155 | - remove_action( |
|
| 1156 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1157 | - array($addon, 'after_registration'), |
|
| 1158 | - 999 |
|
| 1159 | - ); |
|
| 1160 | - } |
|
| 1161 | - EE_Registry::instance()->removeAddon($class_name); |
|
| 1162 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1163 | - // the add-on was not yet registered in the registry, |
|
| 1164 | - // so RegistryContainer::__get() throws this exception. |
|
| 1165 | - // also no need to worry about this or log it, |
|
| 1166 | - // it's ok to deregister an add-on before its registered in the registry |
|
| 1167 | - } catch (Exception $e) { |
|
| 1168 | - new ExceptionLogger($e); |
|
| 1169 | - } |
|
| 1170 | - unset(self::$_settings[ $addon_name ]); |
|
| 1171 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1172 | - } |
|
| 1173 | - } |
|
| 1067 | + /** |
|
| 1068 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1069 | + * |
|
| 1070 | + * @since 4.3.0 |
|
| 1071 | + * @param string $addon_name the name for the addon that was previously registered |
|
| 1072 | + * @throws DomainException |
|
| 1073 | + * @throws EE_Error |
|
| 1074 | + * @throws InvalidArgumentException |
|
| 1075 | + * @throws InvalidDataTypeException |
|
| 1076 | + * @throws InvalidInterfaceException |
|
| 1077 | + */ |
|
| 1078 | + public static function deregister($addon_name = null) |
|
| 1079 | + { |
|
| 1080 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1081 | + try { |
|
| 1082 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1083 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1084 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1085 | + // setup DMS |
|
| 1086 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1087 | + } |
|
| 1088 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1089 | + // register admin page |
|
| 1090 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 1091 | + } |
|
| 1092 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1093 | + // add to list of modules to be registered |
|
| 1094 | + EE_Register_Module::deregister($addon_name); |
|
| 1095 | + } |
|
| 1096 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1097 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1098 | + ) { |
|
| 1099 | + // add to list of shortcodes to be registered |
|
| 1100 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 1101 | + } |
|
| 1102 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1103 | + // if config_class present let's register config. |
|
| 1104 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1105 | + } |
|
| 1106 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1107 | + // add to list of widgets to be registered |
|
| 1108 | + EE_Register_Widget::deregister($addon_name); |
|
| 1109 | + } |
|
| 1110 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1111 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1112 | + ) { |
|
| 1113 | + // add to list of shortcodes to be registered |
|
| 1114 | + EE_Register_Model::deregister($addon_name); |
|
| 1115 | + } |
|
| 1116 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1117 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1118 | + ) { |
|
| 1119 | + // add to list of shortcodes to be registered |
|
| 1120 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1121 | + } |
|
| 1122 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1123 | + foreach ( |
|
| 1124 | + (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
| 1125 | + $message_type_settings |
|
| 1126 | + ) { |
|
| 1127 | + EE_Register_Message_Type::deregister($message_type); |
|
| 1128 | + } |
|
| 1129 | + } |
|
| 1130 | + //deregister capabilities for addon |
|
| 1131 | + if ( |
|
| 1132 | + ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1133 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1134 | + ) { |
|
| 1135 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 1136 | + } |
|
| 1137 | + //deregister custom_post_types for addon |
|
| 1138 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1139 | + EE_Register_CPT::deregister($addon_name); |
|
| 1140 | + } |
|
| 1141 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1142 | + EE_Register_Payment_Method::deregister($addon_name); |
|
| 1143 | + } |
|
| 1144 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1145 | + if ($addon instanceof EE_Addon) { |
|
| 1146 | + remove_action( |
|
| 1147 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1148 | + array($addon, 'deactivation') |
|
| 1149 | + ); |
|
| 1150 | + remove_action( |
|
| 1151 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1152 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1153 | + ); |
|
| 1154 | + //remove `after_registration` call |
|
| 1155 | + remove_action( |
|
| 1156 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1157 | + array($addon, 'after_registration'), |
|
| 1158 | + 999 |
|
| 1159 | + ); |
|
| 1160 | + } |
|
| 1161 | + EE_Registry::instance()->removeAddon($class_name); |
|
| 1162 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1163 | + // the add-on was not yet registered in the registry, |
|
| 1164 | + // so RegistryContainer::__get() throws this exception. |
|
| 1165 | + // also no need to worry about this or log it, |
|
| 1166 | + // it's ok to deregister an add-on before its registered in the registry |
|
| 1167 | + } catch (Exception $e) { |
|
| 1168 | + new ExceptionLogger($e); |
|
| 1169 | + } |
|
| 1170 | + unset(self::$_settings[ $addon_name ]); |
|
| 1171 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1172 | + } |
|
| 1173 | + } |
|
| 1174 | 1174 | } |
| 1175 | 1175 | // End of file EE_Register_Addon.lib.php |
| 1176 | 1176 | // Location: /core/libraries/plugin_api/EE_Register_Addon.lib.php |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 73 | 73 | $version_parts = explode('.', $min_core_version); |
| 74 | 74 | //check they specified the micro version (after 2nd period) |
| 75 | - if (! isset($version_parts[2])) { |
|
| 75 | + if ( ! isset($version_parts[2])) { |
|
| 76 | 76 | $version_parts[2] = '0'; |
| 77 | 77 | } |
| 78 | 78 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 79 | 79 | //soon we can assume that's 'rc', but this current version is 'alpha' |
| 80 | - if (! isset($version_parts[3])) { |
|
| 80 | + if ( ! isset($version_parts[3])) { |
|
| 81 | 81 | $version_parts[3] = 'dev'; |
| 82 | 82 | } |
| 83 | - if (! isset($version_parts[4])) { |
|
| 83 | + if ( ! isset($version_parts[4])) { |
|
| 84 | 84 | $version_parts[4] = '000'; |
| 85 | 85 | } |
| 86 | 86 | return implode('.', $version_parts); |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | // setup PUE |
| 257 | 257 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 258 | 258 | // does this addon work with this version of core or WordPress ? |
| 259 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 259 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 260 | 260 | return; |
| 261 | 261 | } |
| 262 | 262 | // register namespaces |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | ) |
| 315 | 315 | ); |
| 316 | 316 | } |
| 317 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 317 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 318 | 318 | throw new EE_Error( |
| 319 | 319 | sprintf( |
| 320 | 320 | __( |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | ); |
| 327 | 327 | } |
| 328 | 328 | // check that addon has not already been registered with that name |
| 329 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 329 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 330 | 330 | throw new EE_Error( |
| 331 | 331 | sprintf( |
| 332 | 332 | __( |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
| 359 | 359 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
| 360 | 360 | ? $class_name |
| 361 | - : 'EE_' . $class_name; |
|
| 361 | + : 'EE_'.$class_name; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
@@ -519,9 +519,9 @@ discard block |
||
| 519 | 519 | $incompatibility_message = ''; |
| 520 | 520 | //check whether this addon version is compatible with EE core |
| 521 | 521 | if ( |
| 522 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 522 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 523 | 523 | && ! self::_meets_min_core_version_requirement( |
| 524 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 524 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 525 | 525 | $addon_settings['version'] |
| 526 | 526 | ) |
| 527 | 527 | ) { |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | ), |
| 532 | 532 | $addon_name, |
| 533 | 533 | '<br />', |
| 534 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 534 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 535 | 535 | '<span style="font-weight: bold; color: #D54E21;">', |
| 536 | 536 | '</span><br />' |
| 537 | 537 | ); |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | '</span><br />' |
| 564 | 564 | ); |
| 565 | 565 | } |
| 566 | - if (! empty($incompatibility_message)) { |
|
| 566 | + if ( ! empty($incompatibility_message)) { |
|
| 567 | 567 | // remove 'activate' from the REQUEST |
| 568 | 568 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
| 569 | 569 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -591,11 +591,11 @@ discard block |
||
| 591 | 591 | */ |
| 592 | 592 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
| 593 | 593 | { |
| 594 | - if (! empty($setup_args['pue_options'])) { |
|
| 595 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 594 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 595 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
| 596 | 596 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 597 | 597 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
| 598 | - : 'espresso_' . strtolower($class_name), |
|
| 598 | + : 'espresso_'.strtolower($class_name), |
|
| 599 | 599 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 600 | 600 | ? (string) $setup_args['pue_options']['plugin_basename'] |
| 601 | 601 | : plugin_basename($setup_args['main_file_path']), |
@@ -655,12 +655,12 @@ discard block |
||
| 655 | 655 | //(as the newly-activated addon wasn't around the first time addons were registered). |
| 656 | 656 | //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
| 657 | 657 | //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
| 658 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 659 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 660 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 658 | + if ( ! isset(self::$_settings[$addon_name]) |
|
| 659 | + || (isset(self::$_settings[$addon_name]) |
|
| 660 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 661 | 661 | ) |
| 662 | 662 | ) { |
| 663 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 663 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 664 | 664 | $addon = self::_load_and_init_addon_class($addon_name); |
| 665 | 665 | $addon->set_activation_indicator_option(); |
| 666 | 666 | // dont bother setting up the rest of the addon. |
@@ -686,10 +686,10 @@ discard block |
||
| 686 | 686 | ); |
| 687 | 687 | } |
| 688 | 688 | // make sure addon settings are set correctly without overwriting anything existing |
| 689 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 690 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 689 | + if (isset(self::$_settings[$addon_name])) { |
|
| 690 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 691 | 691 | } else { |
| 692 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 692 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 693 | 693 | } |
| 694 | 694 | return false; |
| 695 | 695 | } |
@@ -702,13 +702,13 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | private static function _setup_autoloaders($addon_name) |
| 704 | 704 | { |
| 705 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 705 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 706 | 706 | // setup autoloader for single file |
| 707 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 707 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 708 | 708 | } |
| 709 | 709 | // setup autoloaders for folders |
| 710 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 711 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 710 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 711 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 712 | 712 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 713 | 713 | } |
| 714 | 714 | } |
@@ -726,27 +726,27 @@ discard block |
||
| 726 | 726 | { |
| 727 | 727 | // register new models |
| 728 | 728 | if ( |
| 729 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 730 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 729 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 730 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 731 | 731 | ) { |
| 732 | 732 | EE_Register_Model::register( |
| 733 | 733 | $addon_name, |
| 734 | 734 | array( |
| 735 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 736 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 735 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 736 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 737 | 737 | ) |
| 738 | 738 | ); |
| 739 | 739 | } |
| 740 | 740 | // register model extensions |
| 741 | 741 | if ( |
| 742 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 743 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 742 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 743 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 744 | 744 | ) { |
| 745 | 745 | EE_Register_Model_Extensions::register( |
| 746 | 746 | $addon_name, |
| 747 | 747 | array( |
| 748 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 749 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 748 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 749 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 750 | 750 | ) |
| 751 | 751 | ); |
| 752 | 752 | } |
@@ -761,10 +761,10 @@ discard block |
||
| 761 | 761 | private static function _register_data_migration_scripts($addon_name) |
| 762 | 762 | { |
| 763 | 763 | // setup DMS |
| 764 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 764 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 765 | 765 | EE_Register_Data_Migration_Scripts::register( |
| 766 | 766 | $addon_name, |
| 767 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 767 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 768 | 768 | ); |
| 769 | 769 | } |
| 770 | 770 | } |
@@ -778,12 +778,12 @@ discard block |
||
| 778 | 778 | private static function _register_config($addon_name) |
| 779 | 779 | { |
| 780 | 780 | // if config_class is present let's register config. |
| 781 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 781 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 782 | 782 | EE_Register_Config::register( |
| 783 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 783 | + self::$_settings[$addon_name]['config_class'], |
|
| 784 | 784 | array( |
| 785 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 786 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 785 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 786 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 787 | 787 | ) |
| 788 | 788 | ); |
| 789 | 789 | } |
@@ -797,10 +797,10 @@ discard block |
||
| 797 | 797 | */ |
| 798 | 798 | private static function _register_admin_pages($addon_name) |
| 799 | 799 | { |
| 800 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 800 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 801 | 801 | EE_Register_Admin_Page::register( |
| 802 | 802 | $addon_name, |
| 803 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 803 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 804 | 804 | ); |
| 805 | 805 | } |
| 806 | 806 | } |
@@ -813,10 +813,10 @@ discard block |
||
| 813 | 813 | */ |
| 814 | 814 | private static function _register_modules($addon_name) |
| 815 | 815 | { |
| 816 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 816 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 817 | 817 | EE_Register_Module::register( |
| 818 | 818 | $addon_name, |
| 819 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 819 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 820 | 820 | ); |
| 821 | 821 | } |
| 822 | 822 | } |
@@ -829,17 +829,17 @@ discard block |
||
| 829 | 829 | */ |
| 830 | 830 | private static function _register_shortcodes($addon_name) |
| 831 | 831 | { |
| 832 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 833 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 832 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 833 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 834 | 834 | ) { |
| 835 | 835 | EE_Register_Shortcode::register( |
| 836 | 836 | $addon_name, |
| 837 | 837 | array( |
| 838 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 839 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 838 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 839 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
| 840 | 840 | : array(), |
| 841 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 842 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 841 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 842 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
| 843 | 843 | : array(), |
| 844 | 844 | ) |
| 845 | 845 | ); |
@@ -854,10 +854,10 @@ discard block |
||
| 854 | 854 | */ |
| 855 | 855 | private static function _register_widgets($addon_name) |
| 856 | 856 | { |
| 857 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 857 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 858 | 858 | EE_Register_Widget::register( |
| 859 | 859 | $addon_name, |
| 860 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 860 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 861 | 861 | ); |
| 862 | 862 | } |
| 863 | 863 | } |
@@ -870,12 +870,12 @@ discard block |
||
| 870 | 870 | */ |
| 871 | 871 | private static function _register_capabilities($addon_name) |
| 872 | 872 | { |
| 873 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 873 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 874 | 874 | EE_Register_Capabilities::register( |
| 875 | 875 | $addon_name, |
| 876 | 876 | array( |
| 877 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 878 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 877 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 878 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 879 | 879 | ) |
| 880 | 880 | ); |
| 881 | 881 | } |
@@ -889,7 +889,7 @@ discard block |
||
| 889 | 889 | */ |
| 890 | 890 | private static function _register_message_types($addon_name) |
| 891 | 891 | { |
| 892 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 892 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 893 | 893 | add_action( |
| 894 | 894 | 'EE_Brewing_Regular___messages_caf', |
| 895 | 895 | array('EE_Register_Addon', 'register_message_types') |
@@ -906,15 +906,15 @@ discard block |
||
| 906 | 906 | private static function _register_custom_post_types($addon_name) |
| 907 | 907 | { |
| 908 | 908 | if ( |
| 909 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 910 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 909 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 910 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 911 | 911 | ) { |
| 912 | 912 | EE_Register_CPT::register( |
| 913 | 913 | $addon_name, |
| 914 | 914 | array( |
| 915 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 916 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 917 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 915 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 916 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 917 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 918 | 918 | ) |
| 919 | 919 | ); |
| 920 | 920 | } |
@@ -932,10 +932,10 @@ discard block |
||
| 932 | 932 | */ |
| 933 | 933 | private static function _register_payment_methods($addon_name) |
| 934 | 934 | { |
| 935 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 935 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 936 | 936 | EE_Register_Payment_Method::register( |
| 937 | 937 | $addon_name, |
| 938 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 938 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 939 | 939 | ); |
| 940 | 940 | } |
| 941 | 941 | } |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | { |
| 957 | 957 | $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
| 958 | 958 | $addon = $loader->getShared( |
| 959 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 959 | + self::$_settings[$addon_name]['class_name'], |
|
| 960 | 960 | array('EE_Registry::create(addon)' => true) |
| 961 | 961 | ); |
| 962 | 962 | // setter inject dep map if required |
@@ -966,38 +966,38 @@ discard block |
||
| 966 | 966 | // setter inject domain if required |
| 967 | 967 | if ( |
| 968 | 968 | $addon instanceof RequiresDomainInterface |
| 969 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 969 | + && self::$_settings[$addon_name]['domain_fqcn'] !== '' |
|
| 970 | 970 | && $addon->domain() === null |
| 971 | 971 | ) { |
| 972 | 972 | $addon->setDomain( |
| 973 | 973 | $loader->getShared( |
| 974 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 974 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
| 975 | 975 | array( |
| 976 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
| 977 | - self::$_settings[ $addon_name ]['version'], |
|
| 976 | + self::$_settings[$addon_name]['main_file_path'], |
|
| 977 | + self::$_settings[$addon_name]['version'], |
|
| 978 | 978 | ) |
| 979 | 979 | ) |
| 980 | 980 | ); |
| 981 | 981 | } |
| 982 | 982 | $addon->set_name($addon_name); |
| 983 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 984 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 985 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 986 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 987 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 988 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 989 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 990 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 991 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 992 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 983 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 984 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 985 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 986 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 987 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 988 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 989 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 990 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 991 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 992 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 993 | 993 | //unfortunately this can't be hooked in upon construction, because we don't have |
| 994 | 994 | //the plugin mainfile's path upon construction. |
| 995 | 995 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
| 996 | 996 | // call any additional admin_callback functions during load_admin_controller hook |
| 997 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 997 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 998 | 998 | add_action( |
| 999 | 999 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
| 1000 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1000 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 1001 | 1001 | ); |
| 1002 | 1002 | } |
| 1003 | 1003 | return $addon; |
@@ -1015,10 +1015,10 @@ discard block |
||
| 1015 | 1015 | public static function load_pue_update() |
| 1016 | 1016 | { |
| 1017 | 1017 | // load PUE client |
| 1018 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1018 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
| 1019 | 1019 | // cycle thru settings |
| 1020 | 1020 | foreach (self::$_settings as $settings) { |
| 1021 | - if (! empty($settings['pue_options'])) { |
|
| 1021 | + if ( ! empty($settings['pue_options'])) { |
|
| 1022 | 1022 | // initiate the class and start the plugin update engine! |
| 1023 | 1023 | new PluginUpdateEngineChecker( |
| 1024 | 1024 | // host file URL |
@@ -1026,7 +1026,7 @@ discard block |
||
| 1026 | 1026 | // plugin slug(s) |
| 1027 | 1027 | array( |
| 1028 | 1028 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
| 1029 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1029 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
| 1030 | 1030 | ), |
| 1031 | 1031 | // options |
| 1032 | 1032 | array( |
@@ -1055,7 +1055,7 @@ discard block |
||
| 1055 | 1055 | public static function register_message_types() |
| 1056 | 1056 | { |
| 1057 | 1057 | foreach (self::$_settings as $addon_name => $settings) { |
| 1058 | - if (! empty($settings['message_types'])) { |
|
| 1058 | + if ( ! empty($settings['message_types'])) { |
|
| 1059 | 1059 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
| 1060 | 1060 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 1061 | 1061 | } |
@@ -1077,51 +1077,51 @@ discard block |
||
| 1077 | 1077 | */ |
| 1078 | 1078 | public static function deregister($addon_name = null) |
| 1079 | 1079 | { |
| 1080 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1080 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
| 1081 | 1081 | try { |
| 1082 | 1082 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
| 1083 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1084 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1083 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 1084 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1085 | 1085 | // setup DMS |
| 1086 | 1086 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
| 1087 | 1087 | } |
| 1088 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1088 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1089 | 1089 | // register admin page |
| 1090 | 1090 | EE_Register_Admin_Page::deregister($addon_name); |
| 1091 | 1091 | } |
| 1092 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1092 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1093 | 1093 | // add to list of modules to be registered |
| 1094 | 1094 | EE_Register_Module::deregister($addon_name); |
| 1095 | 1095 | } |
| 1096 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1097 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1096 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1097 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 1098 | 1098 | ) { |
| 1099 | 1099 | // add to list of shortcodes to be registered |
| 1100 | 1100 | EE_Register_Shortcode::deregister($addon_name); |
| 1101 | 1101 | } |
| 1102 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1102 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1103 | 1103 | // if config_class present let's register config. |
| 1104 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1104 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1105 | 1105 | } |
| 1106 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1106 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1107 | 1107 | // add to list of widgets to be registered |
| 1108 | 1108 | EE_Register_Widget::deregister($addon_name); |
| 1109 | 1109 | } |
| 1110 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1111 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1110 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1111 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1112 | 1112 | ) { |
| 1113 | 1113 | // add to list of shortcodes to be registered |
| 1114 | 1114 | EE_Register_Model::deregister($addon_name); |
| 1115 | 1115 | } |
| 1116 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1117 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1116 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1117 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1118 | 1118 | ) { |
| 1119 | 1119 | // add to list of shortcodes to be registered |
| 1120 | 1120 | EE_Register_Model_Extensions::deregister($addon_name); |
| 1121 | 1121 | } |
| 1122 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1122 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1123 | 1123 | foreach ( |
| 1124 | - (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
| 1124 | + (array) self::$_settings[$addon_name]['message_types'] as $message_type => |
|
| 1125 | 1125 | $message_type_settings |
| 1126 | 1126 | ) { |
| 1127 | 1127 | EE_Register_Message_Type::deregister($message_type); |
@@ -1129,22 +1129,22 @@ discard block |
||
| 1129 | 1129 | } |
| 1130 | 1130 | //deregister capabilities for addon |
| 1131 | 1131 | if ( |
| 1132 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1133 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1132 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1133 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1134 | 1134 | ) { |
| 1135 | 1135 | EE_Register_Capabilities::deregister($addon_name); |
| 1136 | 1136 | } |
| 1137 | 1137 | //deregister custom_post_types for addon |
| 1138 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1138 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1139 | 1139 | EE_Register_CPT::deregister($addon_name); |
| 1140 | 1140 | } |
| 1141 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1141 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1142 | 1142 | EE_Register_Payment_Method::deregister($addon_name); |
| 1143 | 1143 | } |
| 1144 | 1144 | $addon = EE_Registry::instance()->getAddon($class_name); |
| 1145 | 1145 | if ($addon instanceof EE_Addon) { |
| 1146 | 1146 | remove_action( |
| 1147 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1147 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
| 1148 | 1148 | array($addon, 'deactivation') |
| 1149 | 1149 | ); |
| 1150 | 1150 | remove_action( |
@@ -1167,7 +1167,7 @@ discard block |
||
| 1167 | 1167 | } catch (Exception $e) { |
| 1168 | 1168 | new ExceptionLogger($e); |
| 1169 | 1169 | } |
| 1170 | - unset(self::$_settings[ $addon_name ]); |
|
| 1170 | + unset(self::$_settings[$addon_name]); |
|
| 1171 | 1171 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
| 1172 | 1172 | } |
| 1173 | 1173 | } |
@@ -18,99 +18,99 @@ |
||
| 18 | 18 | class EE_Register_Data_Migration_Scripts implements EEI_Plugin_API |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Holds values for registered DMSs |
|
| 23 | - * |
|
| 24 | - * @var array[][] |
|
| 25 | - */ |
|
| 26 | - protected static $_settings = array(); |
|
| 21 | + /** |
|
| 22 | + * Holds values for registered DMSs |
|
| 23 | + * |
|
| 24 | + * @var array[][] |
|
| 25 | + */ |
|
| 26 | + protected static $_settings = array(); |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Method for registering new Data Migration Scripts |
|
| 31 | - * |
|
| 32 | - * @since 4.3.0 |
|
| 33 | - * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 34 | - * If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 35 | - * @param array $setup_args { |
|
| 36 | - * @type string $dms_paths an array of full server paths to folders that contain data migration scripts |
|
| 37 | - * } |
|
| 38 | - * @throws EE_Error |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 41 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 42 | - { |
|
| 43 | - //required fields MUST be present, so let's make sure they are. |
|
| 44 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) { |
|
| 45 | - throw new EE_Error( |
|
| 46 | - esc_html__( |
|
| 47 | - 'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)', |
|
| 48 | - 'event_espresso' |
|
| 49 | - ) |
|
| 50 | - ); |
|
| 51 | - } |
|
| 52 | - //make sure we don't register twice |
|
| 53 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - //make sure this was called in the right place! |
|
| 57 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 58 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 59 | - ) { |
|
| 60 | - EE_Error::doing_it_wrong( |
|
| 61 | - __METHOD__, |
|
| 62 | - esc_html__( |
|
| 63 | - 'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.', |
|
| 64 | - 'event_espresso' |
|
| 65 | - ), |
|
| 66 | - '4.3.0' |
|
| 67 | - ); |
|
| 68 | - } |
|
| 69 | - //setup $_settings array from incoming values. |
|
| 70 | - self::$_settings[ $addon_name ] = array( |
|
| 71 | - 'dms_paths' => (array) $setup_args['dms_paths'] |
|
| 72 | - ); |
|
| 73 | - // setup DMS |
|
| 74 | - add_filter( |
|
| 75 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 76 | - array('EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders') |
|
| 77 | - ); |
|
| 78 | - } |
|
| 29 | + /** |
|
| 30 | + * Method for registering new Data Migration Scripts |
|
| 31 | + * |
|
| 32 | + * @since 4.3.0 |
|
| 33 | + * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 34 | + * If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 35 | + * @param array $setup_args { |
|
| 36 | + * @type string $dms_paths an array of full server paths to folders that contain data migration scripts |
|
| 37 | + * } |
|
| 38 | + * @throws EE_Error |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 42 | + { |
|
| 43 | + //required fields MUST be present, so let's make sure they are. |
|
| 44 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) { |
|
| 45 | + throw new EE_Error( |
|
| 46 | + esc_html__( |
|
| 47 | + 'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)', |
|
| 48 | + 'event_espresso' |
|
| 49 | + ) |
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | + //make sure we don't register twice |
|
| 53 | + if (isset(self::$_settings[ $addon_name ])) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + //make sure this was called in the right place! |
|
| 57 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 58 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 59 | + ) { |
|
| 60 | + EE_Error::doing_it_wrong( |
|
| 61 | + __METHOD__, |
|
| 62 | + esc_html__( |
|
| 63 | + 'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.', |
|
| 64 | + 'event_espresso' |
|
| 65 | + ), |
|
| 66 | + '4.3.0' |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | + //setup $_settings array from incoming values. |
|
| 70 | + self::$_settings[ $addon_name ] = array( |
|
| 71 | + 'dms_paths' => (array) $setup_args['dms_paths'] |
|
| 72 | + ); |
|
| 73 | + // setup DMS |
|
| 74 | + add_filter( |
|
| 75 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 76 | + array('EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders') |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @param array $dms_paths |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 85 | - public static function add_data_migration_script_folders($dms_paths = array()) |
|
| 86 | - { |
|
| 87 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 88 | - $wildcards = 0; |
|
| 89 | - foreach ($settings['dms_paths'] as $dms_path) { |
|
| 90 | - // since we are using the addon name for the array key |
|
| 91 | - // we need to ensure that the key is unique, |
|
| 92 | - // so if for some reason an addon has multiple dms paths, |
|
| 93 | - // we append one or more * to the classname |
|
| 94 | - // which will get stripped out later on |
|
| 95 | - $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
| 96 | - $wildcards++; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - return $dms_paths; |
|
| 100 | - } |
|
| 81 | + /** |
|
| 82 | + * @param array $dms_paths |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | + public static function add_data_migration_script_folders($dms_paths = array()) |
|
| 86 | + { |
|
| 87 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 88 | + $wildcards = 0; |
|
| 89 | + foreach ($settings['dms_paths'] as $dms_path) { |
|
| 90 | + // since we are using the addon name for the array key |
|
| 91 | + // we need to ensure that the key is unique, |
|
| 92 | + // so if for some reason an addon has multiple dms paths, |
|
| 93 | + // we append one or more * to the classname |
|
| 94 | + // which will get stripped out later on |
|
| 95 | + $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
| 96 | + $wildcards++; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + return $dms_paths; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id |
|
| 105 | - * |
|
| 106 | - * @since 4.3.0 |
|
| 107 | - * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 108 | - * @return void |
|
| 109 | - */ |
|
| 110 | - public static function deregister($addon_name = '') |
|
| 111 | - { |
|
| 112 | - unset(self::$_settings[ $addon_name ]); |
|
| 113 | - } |
|
| 103 | + /** |
|
| 104 | + * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id |
|
| 105 | + * |
|
| 106 | + * @since 4.3.0 |
|
| 107 | + * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 108 | + * @return void |
|
| 109 | + */ |
|
| 110 | + public static function deregister($addon_name = '') |
|
| 111 | + { |
|
| 112 | + unset(self::$_settings[ $addon_name ]); |
|
| 113 | + } |
|
| 114 | 114 | } |
| 115 | 115 | // End of file EE_Register_Data_Migration_Scripts.lib.php |
| 116 | 116 | // Location: /core/libraries/plugin_api/EE_Register_Data_Migration_Scripts.lib.php |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | //make sure we don't register twice |
| 53 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 53 | + if (isset(self::$_settings[$addon_name])) { |
|
| 54 | 54 | return; |
| 55 | 55 | } |
| 56 | 56 | //make sure this was called in the right place! |
| 57 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 57 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 58 | 58 | || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
| 59 | 59 | ) { |
| 60 | 60 | EE_Error::doing_it_wrong( |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | ); |
| 68 | 68 | } |
| 69 | 69 | //setup $_settings array from incoming values. |
| 70 | - self::$_settings[ $addon_name ] = array( |
|
| 70 | + self::$_settings[$addon_name] = array( |
|
| 71 | 71 | 'dms_paths' => (array) $setup_args['dms_paths'] |
| 72 | 72 | ); |
| 73 | 73 | // setup DMS |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | // so if for some reason an addon has multiple dms paths, |
| 93 | 93 | // we append one or more * to the classname |
| 94 | 94 | // which will get stripped out later on |
| 95 | - $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
| 95 | + $dms_paths[$addon_name.str_repeat('*', $wildcards)] = $dms_path; |
|
| 96 | 96 | $wildcards++; |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public static function deregister($addon_name = '') |
| 111 | 111 | { |
| 112 | - unset(self::$_settings[ $addon_name ]); |
|
| 112 | + unset(self::$_settings[$addon_name]); |
|
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | // End of file EE_Register_Data_Migration_Scripts.lib.php |
@@ -23,1593 +23,1593 @@ |
||
| 23 | 23 | class EE_Registry implements ResettableInterface |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EE_Registry $_instance |
|
| 28 | - */ |
|
| 29 | - private static $_instance; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EE_Dependency_Map $_dependency_map |
|
| 33 | - */ |
|
| 34 | - protected $_dependency_map; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var array $_class_abbreviations |
|
| 38 | - */ |
|
| 39 | - protected $_class_abbreviations = array(); |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var CommandBusInterface $BUS |
|
| 43 | - */ |
|
| 44 | - public $BUS; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EE_Cart $CART |
|
| 48 | - */ |
|
| 49 | - public $CART; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var EE_Config $CFG |
|
| 53 | - */ |
|
| 54 | - public $CFG; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var EE_Network_Config $NET_CFG |
|
| 58 | - */ |
|
| 59 | - public $NET_CFG; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * StdClass object for storing library classes in |
|
| 63 | - * |
|
| 64 | - * @var StdClass $LIB |
|
| 65 | - */ |
|
| 66 | - public $LIB; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var EE_Request_Handler $REQ |
|
| 70 | - */ |
|
| 71 | - public $REQ; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var EE_Session $SSN |
|
| 75 | - */ |
|
| 76 | - public $SSN; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @since 4.5.0 |
|
| 80 | - * @var EE_Capabilities $CAP |
|
| 81 | - */ |
|
| 82 | - public $CAP; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @since 4.9.0 |
|
| 86 | - * @var EE_Message_Resource_Manager $MRM |
|
| 87 | - */ |
|
| 88 | - public $MRM; |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @var Registry $AssetsRegistry |
|
| 93 | - */ |
|
| 94 | - public $AssetsRegistry; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 98 | - * |
|
| 99 | - * @var EE_Addon[] $addons |
|
| 100 | - */ |
|
| 101 | - public $addons; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 105 | - * |
|
| 106 | - * @var EEM_Base[] $models |
|
| 107 | - */ |
|
| 108 | - public $models = array(); |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @var EED_Module[] $modules |
|
| 112 | - */ |
|
| 113 | - public $modules; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var EES_Shortcode[] $shortcodes |
|
| 117 | - */ |
|
| 118 | - public $shortcodes; |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @var WP_Widget[] $widgets |
|
| 122 | - */ |
|
| 123 | - public $widgets; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 127 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 128 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 129 | - * classnames (eg "EEM_Event") |
|
| 130 | - * |
|
| 131 | - * @var array $non_abstract_db_models |
|
| 132 | - */ |
|
| 133 | - public $non_abstract_db_models = array(); |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * internationalization for JS strings |
|
| 138 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 139 | - * in js file: var translatedString = eei18n.string_key; |
|
| 140 | - * |
|
| 141 | - * @var array $i18n_js_strings |
|
| 142 | - */ |
|
| 143 | - public static $i18n_js_strings = array(); |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * $main_file - path to espresso.php |
|
| 148 | - * |
|
| 149 | - * @var array $main_file |
|
| 150 | - */ |
|
| 151 | - public $main_file; |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * array of ReflectionClass objects where the key is the class name |
|
| 155 | - * |
|
| 156 | - * @var ReflectionClass[] $_reflectors |
|
| 157 | - */ |
|
| 158 | - public $_reflectors; |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 162 | - * |
|
| 163 | - * @var boolean $_cache_on |
|
| 164 | - */ |
|
| 165 | - protected $_cache_on = true; |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @singleton method used to instantiate class object |
|
| 171 | - * @param EE_Dependency_Map $dependency_map |
|
| 172 | - * @return EE_Registry instance |
|
| 173 | - * @throws InvalidArgumentException |
|
| 174 | - * @throws InvalidInterfaceException |
|
| 175 | - * @throws InvalidDataTypeException |
|
| 176 | - */ |
|
| 177 | - public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 178 | - { |
|
| 179 | - // check if class object is instantiated |
|
| 180 | - if (! self::$_instance instanceof EE_Registry) { |
|
| 181 | - self::$_instance = new self($dependency_map); |
|
| 182 | - } |
|
| 183 | - return self::$_instance; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * protected constructor to prevent direct creation |
|
| 190 | - * |
|
| 191 | - * @Constructor |
|
| 192 | - * @param EE_Dependency_Map $dependency_map |
|
| 193 | - * @throws InvalidDataTypeException |
|
| 194 | - * @throws InvalidInterfaceException |
|
| 195 | - * @throws InvalidArgumentException |
|
| 196 | - */ |
|
| 197 | - protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 198 | - { |
|
| 199 | - $this->_dependency_map = $dependency_map; |
|
| 200 | - // $registry_container = new RegistryContainer(); |
|
| 201 | - $this->LIB = new RegistryContainer(); |
|
| 202 | - $this->addons = new RegistryContainer(); |
|
| 203 | - $this->modules = new RegistryContainer(); |
|
| 204 | - $this->shortcodes = new RegistryContainer(); |
|
| 205 | - $this->widgets = new RegistryContainer(); |
|
| 206 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * initialize |
|
| 213 | - * |
|
| 214 | - * @throws EE_Error |
|
| 215 | - * @throws ReflectionException |
|
| 216 | - */ |
|
| 217 | - public function initialize() |
|
| 218 | - { |
|
| 219 | - $this->_class_abbreviations = apply_filters( |
|
| 220 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 221 | - array( |
|
| 222 | - 'EE_Config' => 'CFG', |
|
| 223 | - 'EE_Session' => 'SSN', |
|
| 224 | - 'EE_Capabilities' => 'CAP', |
|
| 225 | - 'EE_Cart' => 'CART', |
|
| 226 | - 'EE_Network_Config' => 'NET_CFG', |
|
| 227 | - 'EE_Request_Handler' => 'REQ', |
|
| 228 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
| 229 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 230 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - $this->load_core('Base', array(), true); |
|
| 234 | - // add our request and response objects to the cache |
|
| 235 | - $request_loader = $this->_dependency_map->class_loader( |
|
| 236 | - 'EventEspresso\core\services\request\Request' |
|
| 237 | - ); |
|
| 238 | - $this->_set_cached_class( |
|
| 239 | - $request_loader(), |
|
| 240 | - 'EventEspresso\core\services\request\Request' |
|
| 241 | - ); |
|
| 242 | - $response_loader = $this->_dependency_map->class_loader( |
|
| 243 | - 'EventEspresso\core\services\request\Response' |
|
| 244 | - ); |
|
| 245 | - $this->_set_cached_class( |
|
| 246 | - $response_loader(), |
|
| 247 | - 'EventEspresso\core\services\request\Response' |
|
| 248 | - ); |
|
| 249 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - public function init() |
|
| 258 | - { |
|
| 259 | - // Get current page protocol |
|
| 260 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 261 | - // Output admin-ajax.php URL with same protocol as current page |
|
| 262 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 263 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * localize_i18n_js_strings |
|
| 270 | - * |
|
| 271 | - * @return string |
|
| 272 | - */ |
|
| 273 | - public static function localize_i18n_js_strings() |
|
| 274 | - { |
|
| 275 | - $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 276 | - foreach ($i18n_js_strings as $key => $value) { |
|
| 277 | - if (is_scalar($value)) { |
|
| 278 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param mixed string | EED_Module $module |
|
| 288 | - * @throws EE_Error |
|
| 289 | - * @throws ReflectionException |
|
| 290 | - */ |
|
| 291 | - public function add_module($module) |
|
| 292 | - { |
|
| 293 | - if ($module instanceof EED_Module) { |
|
| 294 | - $module_class = get_class($module); |
|
| 295 | - $this->modules->{$module_class} = $module; |
|
| 296 | - } else { |
|
| 297 | - if ( ! class_exists('EE_Module_Request_Router', false)) { |
|
| 298 | - $this->load_core('Module_Request_Router'); |
|
| 299 | - } |
|
| 300 | - EE_Module_Request_Router::module_factory($module); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * @param string $module_name |
|
| 308 | - * @return mixed EED_Module | NULL |
|
| 309 | - */ |
|
| 310 | - public function get_module($module_name = '') |
|
| 311 | - { |
|
| 312 | - return isset($this->modules->{$module_name}) |
|
| 313 | - ? $this->modules->{$module_name} |
|
| 314 | - : null; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * loads core classes - must be singletons |
|
| 321 | - * |
|
| 322 | - * @param string $class_name - simple class name ie: session |
|
| 323 | - * @param mixed $arguments |
|
| 324 | - * @param bool $load_only |
|
| 325 | - * @return mixed |
|
| 326 | - * @throws EE_Error |
|
| 327 | - * @throws ReflectionException |
|
| 328 | - */ |
|
| 329 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 330 | - { |
|
| 331 | - $core_paths = apply_filters( |
|
| 332 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
| 333 | - array( |
|
| 334 | - EE_CORE, |
|
| 335 | - EE_ADMIN, |
|
| 336 | - EE_CPTS, |
|
| 337 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 338 | - EE_CORE . 'capabilities' . DS, |
|
| 339 | - EE_CORE . 'request_stack' . DS, |
|
| 340 | - EE_CORE . 'middleware' . DS, |
|
| 341 | - ) |
|
| 342 | - ); |
|
| 343 | - // retrieve instantiated class |
|
| 344 | - return $this->_load( |
|
| 345 | - $core_paths, |
|
| 346 | - 'EE_', |
|
| 347 | - $class_name, |
|
| 348 | - 'core', |
|
| 349 | - $arguments, |
|
| 350 | - false, |
|
| 351 | - true, |
|
| 352 | - $load_only |
|
| 353 | - ); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * loads service classes |
|
| 360 | - * |
|
| 361 | - * @param string $class_name - simple class name ie: session |
|
| 362 | - * @param mixed $arguments |
|
| 363 | - * @param bool $load_only |
|
| 364 | - * @return mixed |
|
| 365 | - * @throws EE_Error |
|
| 366 | - * @throws ReflectionException |
|
| 367 | - */ |
|
| 368 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 369 | - { |
|
| 370 | - $service_paths = apply_filters( |
|
| 371 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
| 372 | - array( |
|
| 373 | - EE_CORE . 'services' . DS, |
|
| 374 | - ) |
|
| 375 | - ); |
|
| 376 | - // retrieve instantiated class |
|
| 377 | - return $this->_load( |
|
| 378 | - $service_paths, |
|
| 379 | - 'EE_', |
|
| 380 | - $class_name, |
|
| 381 | - 'class', |
|
| 382 | - $arguments, |
|
| 383 | - false, |
|
| 384 | - true, |
|
| 385 | - $load_only |
|
| 386 | - ); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * loads data_migration_scripts |
|
| 393 | - * |
|
| 394 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 395 | - * @param mixed $arguments |
|
| 396 | - * @return EE_Data_Migration_Script_Base|mixed |
|
| 397 | - * @throws EE_Error |
|
| 398 | - * @throws ReflectionException |
|
| 399 | - */ |
|
| 400 | - public function load_dms($class_name, $arguments = array()) |
|
| 401 | - { |
|
| 402 | - // retrieve instantiated class |
|
| 403 | - return $this->_load( |
|
| 404 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 405 | - 'EE_DMS_', |
|
| 406 | - $class_name, |
|
| 407 | - 'dms', |
|
| 408 | - $arguments, |
|
| 409 | - false, |
|
| 410 | - false |
|
| 411 | - ); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * loads object creating classes - must be singletons |
|
| 418 | - * |
|
| 419 | - * @param string $class_name - simple class name ie: attendee |
|
| 420 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
| 421 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 422 | - * instantiate |
|
| 423 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 424 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 425 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 426 | - * (default) |
|
| 427 | - * @return EE_Base_Class | bool |
|
| 428 | - * @throws EE_Error |
|
| 429 | - * @throws ReflectionException |
|
| 430 | - */ |
|
| 431 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 432 | - { |
|
| 433 | - $paths = apply_filters( |
|
| 434 | - 'FHEE__EE_Registry__load_class__paths', array( |
|
| 435 | - EE_CORE, |
|
| 436 | - EE_CLASSES, |
|
| 437 | - EE_BUSINESS, |
|
| 438 | - ) |
|
| 439 | - ); |
|
| 440 | - // retrieve instantiated class |
|
| 441 | - return $this->_load( |
|
| 442 | - $paths, |
|
| 443 | - 'EE_', |
|
| 444 | - $class_name, |
|
| 445 | - 'class', |
|
| 446 | - $arguments, |
|
| 447 | - $from_db, |
|
| 448 | - $cache, |
|
| 449 | - $load_only |
|
| 450 | - ); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * loads helper classes - must be singletons |
|
| 457 | - * |
|
| 458 | - * @param string $class_name - simple class name ie: price |
|
| 459 | - * @param mixed $arguments |
|
| 460 | - * @param bool $load_only |
|
| 461 | - * @return EEH_Base | bool |
|
| 462 | - * @throws EE_Error |
|
| 463 | - * @throws ReflectionException |
|
| 464 | - */ |
|
| 465 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 466 | - { |
|
| 467 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 468 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 469 | - // retrieve instantiated class |
|
| 470 | - return $this->_load( |
|
| 471 | - $helper_paths, |
|
| 472 | - 'EEH_', |
|
| 473 | - $class_name, |
|
| 474 | - 'helper', |
|
| 475 | - $arguments, |
|
| 476 | - false, |
|
| 477 | - true, |
|
| 478 | - $load_only |
|
| 479 | - ); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * loads core classes - must be singletons |
|
| 486 | - * |
|
| 487 | - * @param string $class_name - simple class name ie: session |
|
| 488 | - * @param mixed $arguments |
|
| 489 | - * @param bool $load_only |
|
| 490 | - * @param bool $cache whether to cache the object or not. |
|
| 491 | - * @return mixed |
|
| 492 | - * @throws EE_Error |
|
| 493 | - * @throws ReflectionException |
|
| 494 | - */ |
|
| 495 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 496 | - { |
|
| 497 | - $paths = array( |
|
| 498 | - EE_LIBRARIES, |
|
| 499 | - EE_LIBRARIES . 'messages' . DS, |
|
| 500 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 501 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 502 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 503 | - ); |
|
| 504 | - // retrieve instantiated class |
|
| 505 | - return $this->_load( |
|
| 506 | - $paths, |
|
| 507 | - 'EE_', |
|
| 508 | - $class_name, |
|
| 509 | - 'lib', |
|
| 510 | - $arguments, |
|
| 511 | - false, |
|
| 512 | - $cache, |
|
| 513 | - $load_only |
|
| 514 | - ); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * loads model classes - must be singletons |
|
| 521 | - * |
|
| 522 | - * @param string $class_name - simple class name ie: price |
|
| 523 | - * @param mixed $arguments |
|
| 524 | - * @param bool $load_only |
|
| 525 | - * @return EEM_Base | bool |
|
| 526 | - * @throws EE_Error |
|
| 527 | - * @throws ReflectionException |
|
| 528 | - */ |
|
| 529 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 530 | - { |
|
| 531 | - $paths = apply_filters( |
|
| 532 | - 'FHEE__EE_Registry__load_model__paths', array( |
|
| 533 | - EE_MODELS, |
|
| 534 | - EE_CORE, |
|
| 535 | - ) |
|
| 536 | - ); |
|
| 537 | - // retrieve instantiated class |
|
| 538 | - return $this->_load( |
|
| 539 | - $paths, |
|
| 540 | - 'EEM_', |
|
| 541 | - $class_name, |
|
| 542 | - 'model', |
|
| 543 | - $arguments, |
|
| 544 | - false, |
|
| 545 | - true, |
|
| 546 | - $load_only |
|
| 547 | - ); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * loads model classes - must be singletons |
|
| 554 | - * |
|
| 555 | - * @param string $class_name - simple class name ie: price |
|
| 556 | - * @param mixed $arguments |
|
| 557 | - * @param bool $load_only |
|
| 558 | - * @return mixed | bool |
|
| 559 | - * @throws EE_Error |
|
| 560 | - * @throws ReflectionException |
|
| 561 | - */ |
|
| 562 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 563 | - { |
|
| 564 | - $paths = array( |
|
| 565 | - EE_MODELS . 'fields' . DS, |
|
| 566 | - EE_MODELS . 'helpers' . DS, |
|
| 567 | - EE_MODELS . 'relations' . DS, |
|
| 568 | - EE_MODELS . 'strategies' . DS, |
|
| 569 | - ); |
|
| 570 | - // retrieve instantiated class |
|
| 571 | - return $this->_load( |
|
| 572 | - $paths, |
|
| 573 | - 'EE_', |
|
| 574 | - $class_name, |
|
| 575 | - '', |
|
| 576 | - $arguments, |
|
| 577 | - false, |
|
| 578 | - true, |
|
| 579 | - $load_only |
|
| 580 | - ); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * Determines if $model_name is the name of an actual EE model. |
|
| 587 | - * |
|
| 588 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 589 | - * @return boolean |
|
| 590 | - */ |
|
| 591 | - public function is_model_name($model_name) |
|
| 592 | - { |
|
| 593 | - return isset($this->models[$model_name]); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * generic class loader |
|
| 600 | - * |
|
| 601 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 602 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
| 603 | - * @param string $type - file type - core? class? helper? model? |
|
| 604 | - * @param mixed $arguments |
|
| 605 | - * @param bool $load_only |
|
| 606 | - * @return mixed |
|
| 607 | - * @throws EE_Error |
|
| 608 | - * @throws ReflectionException |
|
| 609 | - */ |
|
| 610 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 611 | - { |
|
| 612 | - // retrieve instantiated class |
|
| 613 | - return $this->_load( |
|
| 614 | - $path_to_file, |
|
| 615 | - '', |
|
| 616 | - $file_name, |
|
| 617 | - $type, |
|
| 618 | - $arguments, |
|
| 619 | - false, |
|
| 620 | - true, |
|
| 621 | - $load_only |
|
| 622 | - ); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 629 | - * @param string $class_name - full class name ie: My_Class |
|
| 630 | - * @param string $type - file type - core? class? helper? model? |
|
| 631 | - * @param mixed $arguments |
|
| 632 | - * @param bool $load_only |
|
| 633 | - * @return bool|EE_Addon|object |
|
| 634 | - * @throws EE_Error |
|
| 635 | - * @throws ReflectionException |
|
| 636 | - */ |
|
| 637 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 638 | - { |
|
| 639 | - // retrieve instantiated class |
|
| 640 | - return $this->_load( |
|
| 641 | - $path_to_file, |
|
| 642 | - 'addon', |
|
| 643 | - $class_name, |
|
| 644 | - $type, |
|
| 645 | - $arguments, |
|
| 646 | - false, |
|
| 647 | - true, |
|
| 648 | - $load_only |
|
| 649 | - ); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * instantiates, caches, and automatically resolves dependencies |
|
| 656 | - * for classes that use a Fully Qualified Class Name. |
|
| 657 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 658 | - * then you need to use one of the existing load_*() methods |
|
| 659 | - * which can resolve the classname and filepath from the passed arguments |
|
| 660 | - * |
|
| 661 | - * @param bool|string $class_name Fully Qualified Class Name |
|
| 662 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 663 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 664 | - * @param bool $from_db some classes are instantiated from the db |
|
| 665 | - * and thus call a different method to instantiate |
|
| 666 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 667 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 668 | - * @return bool|null|mixed null = failure to load or instantiate class object. |
|
| 669 | - * object = class loaded and instantiated successfully. |
|
| 670 | - * bool = fail or success when $load_only is true |
|
| 671 | - * @throws EE_Error |
|
| 672 | - * @throws ReflectionException |
|
| 673 | - */ |
|
| 674 | - public function create( |
|
| 675 | - $class_name = false, |
|
| 676 | - $arguments = array(), |
|
| 677 | - $cache = false, |
|
| 678 | - $from_db = false, |
|
| 679 | - $load_only = false, |
|
| 680 | - $addon = false |
|
| 681 | - ) { |
|
| 682 | - $class_name = ltrim($class_name, '\\'); |
|
| 683 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 684 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
| 685 | - // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
| 686 | - // or it could return null if the class just could not be found anywhere |
|
| 687 | - if ($class_exists instanceof $class_name || $class_exists === null){ |
|
| 688 | - // either way, return the results |
|
| 689 | - return $class_exists; |
|
| 690 | - } |
|
| 691 | - $class_name = $class_exists; |
|
| 692 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 693 | - if ($load_only) { |
|
| 694 | - return true; |
|
| 695 | - } |
|
| 696 | - $addon = $addon |
|
| 697 | - ? 'addon' |
|
| 698 | - : ''; |
|
| 699 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 700 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 701 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 702 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 703 | - // return object if it's already cached |
|
| 704 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 705 | - if ($cached_class !== null) { |
|
| 706 | - return $cached_class; |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - // obtain the loader method from the dependency map |
|
| 710 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
| 711 | - // instantiate the requested object |
|
| 712 | - if ($loader instanceof Closure) { |
|
| 713 | - $class_obj = $loader($arguments); |
|
| 714 | - } else if ($loader && method_exists($this, $loader)) { |
|
| 715 | - $class_obj = $this->{$loader}($class_name, $arguments); |
|
| 716 | - } else { |
|
| 717 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 718 | - } |
|
| 719 | - if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
| 720 | - // save it for later... kinda like gum { : $ |
|
| 721 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 722 | - } |
|
| 723 | - $this->_cache_on = true; |
|
| 724 | - return $class_obj; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
| 731 | - * |
|
| 732 | - * @param string $class_name |
|
| 733 | - * @param array $arguments |
|
| 734 | - * @param int $attempt |
|
| 735 | - * @return mixed |
|
| 736 | - */ |
|
| 737 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
| 738 | - if (is_object($class_name) || class_exists($class_name)) { |
|
| 739 | - return $class_name; |
|
| 740 | - } |
|
| 741 | - switch ($attempt) { |
|
| 742 | - case 1: |
|
| 743 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
| 744 | - $class_name = strpos($class_name, '\\') !== false |
|
| 745 | - ? '\\' . ltrim($class_name, '\\') |
|
| 746 | - : $class_name; |
|
| 747 | - break; |
|
| 748 | - case 2: |
|
| 749 | - // |
|
| 750 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
| 751 | - if ($loader && method_exists($this, $loader)) { |
|
| 752 | - return $this->{$loader}($class_name, $arguments); |
|
| 753 | - } |
|
| 754 | - break; |
|
| 755 | - case 3: |
|
| 756 | - default; |
|
| 757 | - return null; |
|
| 758 | - } |
|
| 759 | - $attempt++; |
|
| 760 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * instantiates, caches, and injects dependencies for classes |
|
| 767 | - * |
|
| 768 | - * @param array $file_paths an array of paths to folders to look in |
|
| 769 | - * @param string $class_prefix EE or EEM or... ??? |
|
| 770 | - * @param bool|string $class_name $class name |
|
| 771 | - * @param string $type file type - core? class? helper? model? |
|
| 772 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 773 | - * @param bool $from_db some classes are instantiated from the db |
|
| 774 | - * and thus call a different method to instantiate |
|
| 775 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 776 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 777 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
| 778 | - * object = class loaded and instantiated successfully. |
|
| 779 | - * bool = fail or success when $load_only is true |
|
| 780 | - * @throws EE_Error |
|
| 781 | - * @throws ReflectionException |
|
| 782 | - */ |
|
| 783 | - protected function _load( |
|
| 784 | - $file_paths = array(), |
|
| 785 | - $class_prefix = 'EE_', |
|
| 786 | - $class_name = false, |
|
| 787 | - $type = 'class', |
|
| 788 | - $arguments = array(), |
|
| 789 | - $from_db = false, |
|
| 790 | - $cache = true, |
|
| 791 | - $load_only = false |
|
| 792 | - ) { |
|
| 793 | - $class_name = ltrim($class_name, '\\'); |
|
| 794 | - // strip php file extension |
|
| 795 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
| 796 | - // does the class have a prefix ? |
|
| 797 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 798 | - // make sure $class_prefix is uppercase |
|
| 799 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
| 800 | - // add class prefix ONCE!!! |
|
| 801 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 802 | - } |
|
| 803 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 804 | - $class_exists = class_exists($class_name, false); |
|
| 805 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 806 | - if ($load_only && $class_exists) { |
|
| 807 | - return true; |
|
| 808 | - } |
|
| 809 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 810 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 811 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 812 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 813 | - // return object if it's already cached |
|
| 814 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 815 | - if ($cached_class !== null) { |
|
| 816 | - return $cached_class; |
|
| 817 | - } |
|
| 818 | - } |
|
| 819 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 820 | - if (! $class_exists) { |
|
| 821 | - // get full path to file |
|
| 822 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 823 | - // load the file |
|
| 824 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 825 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 826 | - if (! $loaded || $load_only) { |
|
| 827 | - // return boolean if only loading, or null if an object was expected |
|
| 828 | - return $load_only |
|
| 829 | - ? $loaded |
|
| 830 | - : null; |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - // instantiate the requested object |
|
| 834 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 835 | - if ($this->_cache_on && $cache) { |
|
| 836 | - // save it for later... kinda like gum { : $ |
|
| 837 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 838 | - } |
|
| 839 | - $this->_cache_on = true; |
|
| 840 | - return $class_obj; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - /** |
|
| 846 | - * @param string $class_name |
|
| 847 | - * @param string $default have to specify something, but not anything that will conflict |
|
| 848 | - * @return mixed|string |
|
| 849 | - */ |
|
| 850 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
| 851 | - { |
|
| 852 | - return isset($this->_class_abbreviations[$class_name]) |
|
| 853 | - ? $this->_class_abbreviations[$class_name] |
|
| 854 | - : $default; |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * attempts to find a cached version of the requested class |
|
| 859 | - * by looking in the following places: |
|
| 860 | - * $this->{$class_abbreviation} ie: $this->CART |
|
| 861 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 862 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 863 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 864 | - * |
|
| 865 | - * @param string $class_name |
|
| 866 | - * @param string $class_prefix |
|
| 867 | - * @return mixed |
|
| 868 | - * @throws OutOfBoundsException |
|
| 869 | - */ |
|
| 870 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 871 | - { |
|
| 872 | - if ($class_name === 'EE_Registry') { |
|
| 873 | - return $this; |
|
| 874 | - } |
|
| 875 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 876 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 877 | - // check if class has already been loaded, and return it if it has been |
|
| 878 | - if (isset($this->{$class_abbreviation})) { |
|
| 879 | - return $this->{$class_abbreviation}; |
|
| 880 | - } |
|
| 881 | - if (isset ($this->{$class_name})) { |
|
| 882 | - return $this->{$class_name}; |
|
| 883 | - } |
|
| 884 | - if (isset ($this->LIB->{$class_name})) { |
|
| 885 | - return $this->LIB->{$class_name}; |
|
| 886 | - } |
|
| 887 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 888 | - return $this->addons->{$class_name}; |
|
| 889 | - } |
|
| 890 | - return null; |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * removes a cached version of the requested class |
|
| 897 | - * |
|
| 898 | - * @param string $class_name |
|
| 899 | - * @param boolean $addon |
|
| 900 | - * @return boolean |
|
| 901 | - * @throws OutOfBoundsException |
|
| 902 | - */ |
|
| 903 | - public function clear_cached_class($class_name, $addon = false) |
|
| 904 | - { |
|
| 905 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 906 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 907 | - // check if class has already been loaded, and return it if it has been |
|
| 908 | - if (isset($this->{$class_abbreviation})) { |
|
| 909 | - $this->{$class_abbreviation} = null; |
|
| 910 | - return true; |
|
| 911 | - } |
|
| 912 | - if (isset($this->{$class_name})) { |
|
| 913 | - $this->{$class_name} = null; |
|
| 914 | - return true; |
|
| 915 | - } |
|
| 916 | - if (isset($this->LIB->{$class_name})) { |
|
| 917 | - unset($this->LIB->{$class_name}); |
|
| 918 | - return true; |
|
| 919 | - } |
|
| 920 | - if ($addon && isset($this->addons->{$class_name})) { |
|
| 921 | - unset($this->addons->{$class_name}); |
|
| 922 | - return true; |
|
| 923 | - } |
|
| 924 | - return false; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - |
|
| 929 | - /** |
|
| 930 | - * attempts to find a full valid filepath for the requested class. |
|
| 931 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 932 | - * then returns that path if the target file has been found and is readable |
|
| 933 | - * |
|
| 934 | - * @param string $class_name |
|
| 935 | - * @param string $type |
|
| 936 | - * @param array $file_paths |
|
| 937 | - * @return string | bool |
|
| 938 | - */ |
|
| 939 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 940 | - { |
|
| 941 | - // make sure $file_paths is an array |
|
| 942 | - $file_paths = is_array($file_paths) |
|
| 943 | - ? $file_paths |
|
| 944 | - : array($file_paths); |
|
| 945 | - // cycle thru paths |
|
| 946 | - foreach ($file_paths as $key => $file_path) { |
|
| 947 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 948 | - $file_path = $file_path |
|
| 949 | - ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 950 | - : EE_CLASSES; |
|
| 951 | - // prep file type |
|
| 952 | - $type = ! empty($type) |
|
| 953 | - ? trim($type, '.') . '.' |
|
| 954 | - : ''; |
|
| 955 | - // build full file path |
|
| 956 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 957 | - //does the file exist and can be read ? |
|
| 958 | - if (is_readable($file_paths[$key])) { |
|
| 959 | - return $file_paths[$key]; |
|
| 960 | - } |
|
| 961 | - } |
|
| 962 | - return false; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - |
|
| 967 | - /** |
|
| 968 | - * basically just performs a require_once() |
|
| 969 | - * but with some error handling |
|
| 970 | - * |
|
| 971 | - * @param string $path |
|
| 972 | - * @param string $class_name |
|
| 973 | - * @param string $type |
|
| 974 | - * @param array $file_paths |
|
| 975 | - * @return bool |
|
| 976 | - * @throws EE_Error |
|
| 977 | - * @throws ReflectionException |
|
| 978 | - */ |
|
| 979 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 980 | - { |
|
| 981 | - $this->resolve_legacy_class_parent($class_name); |
|
| 982 | - // don't give up! you gotta... |
|
| 983 | - try { |
|
| 984 | - //does the file exist and can it be read ? |
|
| 985 | - if (! $path) { |
|
| 986 | - // just in case the file has already been autoloaded, |
|
| 987 | - // but discrepancies in the naming schema are preventing it from |
|
| 988 | - // being loaded via one of the EE_Registry::load_*() methods, |
|
| 989 | - // then let's try one last hail mary before throwing an exception |
|
| 990 | - // and call class_exists() again, but with autoloading turned ON |
|
| 991 | - if(class_exists($class_name)) { |
|
| 992 | - return true; |
|
| 993 | - } |
|
| 994 | - // so sorry, can't find the file |
|
| 995 | - throw new EE_Error ( |
|
| 996 | - sprintf( |
|
| 997 | - esc_html__( |
|
| 998 | - 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
| 999 | - 'event_espresso' |
|
| 1000 | - ), |
|
| 1001 | - trim($type, '.'), |
|
| 1002 | - $class_name, |
|
| 1003 | - '<br />' . implode(',<br />', $file_paths) |
|
| 1004 | - ) |
|
| 1005 | - ); |
|
| 1006 | - } |
|
| 1007 | - // get the file |
|
| 1008 | - require_once($path); |
|
| 1009 | - // if the class isn't already declared somewhere |
|
| 1010 | - if (class_exists($class_name, false) === false) { |
|
| 1011 | - // so sorry, not a class |
|
| 1012 | - throw new EE_Error( |
|
| 1013 | - sprintf( |
|
| 1014 | - esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 1015 | - $type, |
|
| 1016 | - $path, |
|
| 1017 | - $class_name |
|
| 1018 | - ) |
|
| 1019 | - ); |
|
| 1020 | - } |
|
| 1021 | - } catch (EE_Error $e) { |
|
| 1022 | - $e->get_error(); |
|
| 1023 | - return false; |
|
| 1024 | - } |
|
| 1025 | - return true; |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
| 1032 | - * before their class declaration in order to ensure that the parent class was loaded. |
|
| 1033 | - * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
| 1034 | - * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
| 1035 | - * |
|
| 1036 | - * @param string $class_name |
|
| 1037 | - */ |
|
| 1038 | - protected function resolve_legacy_class_parent($class_name = '') |
|
| 1039 | - { |
|
| 1040 | - try { |
|
| 1041 | - $legacy_parent_class_map = array( |
|
| 1042 | - 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php' |
|
| 1043 | - ); |
|
| 1044 | - if(isset($legacy_parent_class_map[$class_name])) { |
|
| 1045 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name]; |
|
| 1046 | - } |
|
| 1047 | - } catch (Exception $exception) { |
|
| 1048 | - } |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - |
|
| 1052 | - |
|
| 1053 | - /** |
|
| 1054 | - * _create_object |
|
| 1055 | - * Attempts to instantiate the requested class via any of the |
|
| 1056 | - * commonly used instantiation methods employed throughout EE. |
|
| 1057 | - * The priority for instantiation is as follows: |
|
| 1058 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 1059 | - * - model objects via their 'new_instance_from_db' method |
|
| 1060 | - * - model objects via their 'new_instance' method |
|
| 1061 | - * - "singleton" classes" via their 'instance' method |
|
| 1062 | - * - standard instantiable classes via their __constructor |
|
| 1063 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 1064 | - * then the constructor for the requested class will be examined to determine |
|
| 1065 | - * if any dependencies exist, and if they can be injected. |
|
| 1066 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1067 | - * |
|
| 1068 | - * @param string $class_name |
|
| 1069 | - * @param array $arguments |
|
| 1070 | - * @param string $type |
|
| 1071 | - * @param bool $from_db |
|
| 1072 | - * @return null|object |
|
| 1073 | - * @throws EE_Error |
|
| 1074 | - * @throws ReflectionException |
|
| 1075 | - */ |
|
| 1076 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 1077 | - { |
|
| 1078 | - // create reflection |
|
| 1079 | - $reflector = $this->get_ReflectionClass($class_name); |
|
| 1080 | - // make sure arguments are an array |
|
| 1081 | - $arguments = is_array($arguments) |
|
| 1082 | - ? $arguments |
|
| 1083 | - : array($arguments); |
|
| 1084 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 1085 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 1086 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 1087 | - ? $arguments |
|
| 1088 | - : array($arguments); |
|
| 1089 | - // attempt to inject dependencies ? |
|
| 1090 | - if ($this->_dependency_map->has($class_name)) { |
|
| 1091 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1092 | - } |
|
| 1093 | - // instantiate the class if possible |
|
| 1094 | - if ($reflector->isAbstract()) { |
|
| 1095 | - // nothing to instantiate, loading file was enough |
|
| 1096 | - // does not throw an exception so $instantiation_mode is unused |
|
| 1097 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1098 | - return true; |
|
| 1099 | - } |
|
| 1100 | - if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1101 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1102 | - // $instantiation_mode = "2) no constructor but instantiable"; |
|
| 1103 | - return $reflector->newInstance(); |
|
| 1104 | - } |
|
| 1105 | - if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1106 | - // $instantiation_mode = "3) new_instance_from_db()"; |
|
| 1107 | - return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1108 | - } |
|
| 1109 | - if (method_exists($class_name, 'new_instance')) { |
|
| 1110 | - // $instantiation_mode = "4) new_instance()"; |
|
| 1111 | - return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1112 | - } |
|
| 1113 | - if (method_exists($class_name, 'instance')) { |
|
| 1114 | - // $instantiation_mode = "5) instance()"; |
|
| 1115 | - return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1116 | - } |
|
| 1117 | - if ($reflector->isInstantiable()) { |
|
| 1118 | - // $instantiation_mode = "6) constructor"; |
|
| 1119 | - return $reflector->newInstanceArgs($arguments); |
|
| 1120 | - } |
|
| 1121 | - // heh ? something's not right ! |
|
| 1122 | - throw new EE_Error( |
|
| 1123 | - sprintf( |
|
| 1124 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1125 | - $type, |
|
| 1126 | - $class_name |
|
| 1127 | - ) |
|
| 1128 | - ); |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1135 | - * @param array $array |
|
| 1136 | - * @return bool |
|
| 1137 | - */ |
|
| 1138 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1139 | - { |
|
| 1140 | - return ! empty($array) |
|
| 1141 | - ? array_keys($array) === range(0, count($array) - 1) |
|
| 1142 | - : true; |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - |
|
| 1146 | - |
|
| 1147 | - /** |
|
| 1148 | - * getReflectionClass |
|
| 1149 | - * checks if a ReflectionClass object has already been generated for a class |
|
| 1150 | - * and returns that instead of creating a new one |
|
| 1151 | - * |
|
| 1152 | - * @param string $class_name |
|
| 1153 | - * @return ReflectionClass |
|
| 1154 | - * @throws ReflectionException |
|
| 1155 | - */ |
|
| 1156 | - public function get_ReflectionClass($class_name) |
|
| 1157 | - { |
|
| 1158 | - if ( |
|
| 1159 | - ! isset($this->_reflectors[$class_name]) |
|
| 1160 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1161 | - ) { |
|
| 1162 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1163 | - } |
|
| 1164 | - return $this->_reflectors[$class_name]; |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - |
|
| 1168 | - |
|
| 1169 | - /** |
|
| 1170 | - * _resolve_dependencies |
|
| 1171 | - * examines the constructor for the requested class to determine |
|
| 1172 | - * if any dependencies exist, and if they can be injected. |
|
| 1173 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1174 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1175 | - * For example: |
|
| 1176 | - * if attempting to load a class "Foo" with the following constructor: |
|
| 1177 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1178 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1179 | - * but only IF they are NOT already present in the incoming arguments array, |
|
| 1180 | - * and the correct classes can be loaded |
|
| 1181 | - * |
|
| 1182 | - * @param ReflectionClass $reflector |
|
| 1183 | - * @param string $class_name |
|
| 1184 | - * @param array $arguments |
|
| 1185 | - * @return array |
|
| 1186 | - * @throws EE_Error |
|
| 1187 | - * @throws ReflectionException |
|
| 1188 | - */ |
|
| 1189 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1190 | - { |
|
| 1191 | - // let's examine the constructor |
|
| 1192 | - $constructor = $reflector->getConstructor(); |
|
| 1193 | - // whu? huh? nothing? |
|
| 1194 | - if (! $constructor) { |
|
| 1195 | - return $arguments; |
|
| 1196 | - } |
|
| 1197 | - // get constructor parameters |
|
| 1198 | - $params = $constructor->getParameters(); |
|
| 1199 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1200 | - $argument_keys = array_keys($arguments); |
|
| 1201 | - // now loop thru all of the constructors expected parameters |
|
| 1202 | - foreach ($params as $index => $param) { |
|
| 1203 | - // is this a dependency for a specific class ? |
|
| 1204 | - $param_class = $param->getClass() |
|
| 1205 | - ? $param->getClass()->name |
|
| 1206 | - : null; |
|
| 1207 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1208 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1209 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1210 | - : $param_class; |
|
| 1211 | - if ( |
|
| 1212 | - // param is not even a class |
|
| 1213 | - $param_class === null |
|
| 1214 | - // and something already exists in the incoming arguments for this param |
|
| 1215 | - && array_key_exists($index, $argument_keys) |
|
| 1216 | - && array_key_exists($argument_keys[$index], $arguments) |
|
| 1217 | - ) { |
|
| 1218 | - // so let's skip this argument and move on to the next |
|
| 1219 | - continue; |
|
| 1220 | - } |
|
| 1221 | - if ( |
|
| 1222 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1223 | - $param_class !== null |
|
| 1224 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1225 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1226 | - ) { |
|
| 1227 | - // skip this argument and move on to the next |
|
| 1228 | - continue; |
|
| 1229 | - } |
|
| 1230 | - if ( |
|
| 1231 | - // parameter is type hinted as a class, and should be injected |
|
| 1232 | - $param_class !== null |
|
| 1233 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1234 | - ) { |
|
| 1235 | - $arguments = $this->_resolve_dependency( |
|
| 1236 | - $class_name, |
|
| 1237 | - $param_class, |
|
| 1238 | - $arguments, |
|
| 1239 | - $index, |
|
| 1240 | - $argument_keys |
|
| 1241 | - ); |
|
| 1242 | - } else { |
|
| 1243 | - try { |
|
| 1244 | - $arguments[$index] = $param->isDefaultValueAvailable() |
|
| 1245 | - ? $param->getDefaultValue() |
|
| 1246 | - : null; |
|
| 1247 | - } catch (ReflectionException $e) { |
|
| 1248 | - throw new ReflectionException( |
|
| 1249 | - sprintf( |
|
| 1250 | - esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'), |
|
| 1251 | - $e->getMessage(), |
|
| 1252 | - $param->getName(), |
|
| 1253 | - $class_name |
|
| 1254 | - ) |
|
| 1255 | - ); |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - return $arguments; |
|
| 1260 | - } |
|
| 1261 | - |
|
| 1262 | - |
|
| 1263 | - |
|
| 1264 | - /** |
|
| 1265 | - * @param string $class_name |
|
| 1266 | - * @param string $param_class |
|
| 1267 | - * @param array $arguments |
|
| 1268 | - * @param mixed $index |
|
| 1269 | - * @param array $argument_keys |
|
| 1270 | - * @return array |
|
| 1271 | - * @throws EE_Error |
|
| 1272 | - * @throws ReflectionException |
|
| 1273 | - * @throws InvalidArgumentException |
|
| 1274 | - * @throws InvalidInterfaceException |
|
| 1275 | - * @throws InvalidDataTypeException |
|
| 1276 | - */ |
|
| 1277 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
| 1278 | - { |
|
| 1279 | - $dependency = null; |
|
| 1280 | - // should dependency be loaded from cache ? |
|
| 1281 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
| 1282 | - $class_name, |
|
| 1283 | - $param_class |
|
| 1284 | - ); |
|
| 1285 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
| 1286 | - // we might have a dependency... |
|
| 1287 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1288 | - $cached_class = $cache_on |
|
| 1289 | - ? $this->_get_cached_class($param_class) |
|
| 1290 | - : null; |
|
| 1291 | - // and grab it if it exists |
|
| 1292 | - if ($cached_class instanceof $param_class) { |
|
| 1293 | - $dependency = $cached_class; |
|
| 1294 | - } else if ($param_class !== $class_name) { |
|
| 1295 | - // obtain the loader method from the dependency map |
|
| 1296 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1297 | - // is loader a custom closure ? |
|
| 1298 | - if ($loader instanceof Closure) { |
|
| 1299 | - $dependency = $loader($arguments); |
|
| 1300 | - } else { |
|
| 1301 | - // set the cache on property for the recursive loading call |
|
| 1302 | - $this->_cache_on = $cache_on; |
|
| 1303 | - // if not, then let's try and load it via the registry |
|
| 1304 | - if ($loader && method_exists($this, $loader)) { |
|
| 1305 | - $dependency = $this->{$loader}($param_class); |
|
| 1306 | - } else { |
|
| 1307 | - $dependency = LoaderFactory::getLoader()->load( |
|
| 1308 | - $param_class, |
|
| 1309 | - array(), |
|
| 1310 | - $cache_on |
|
| 1311 | - ); |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - } |
|
| 1315 | - // did we successfully find the correct dependency ? |
|
| 1316 | - if ($dependency instanceof $param_class) { |
|
| 1317 | - // then let's inject it into the incoming array of arguments at the correct location |
|
| 1318 | - $arguments[$index] = $dependency; |
|
| 1319 | - } |
|
| 1320 | - return $arguments; |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - |
|
| 1324 | - |
|
| 1325 | - /** |
|
| 1326 | - * _set_cached_class |
|
| 1327 | - * attempts to cache the instantiated class locally |
|
| 1328 | - * in one of the following places, in the following order: |
|
| 1329 | - * $this->{class_abbreviation} ie: $this->CART |
|
| 1330 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 1331 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1332 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1333 | - * |
|
| 1334 | - * @param object $class_obj |
|
| 1335 | - * @param string $class_name |
|
| 1336 | - * @param string $class_prefix |
|
| 1337 | - * @param bool $from_db |
|
| 1338 | - * @return void |
|
| 1339 | - * @throws OutOfBoundsException |
|
| 1340 | - */ |
|
| 1341 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1342 | - { |
|
| 1343 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1344 | - return; |
|
| 1345 | - } |
|
| 1346 | - // return newly instantiated class |
|
| 1347 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
| 1348 | - if ($class_abbreviation) { |
|
| 1349 | - $this->{$class_abbreviation} = $class_obj; |
|
| 1350 | - return; |
|
| 1351 | - } |
|
| 1352 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1353 | - if (property_exists($this, $class_name)) { |
|
| 1354 | - $this->{$class_name} = $class_obj; |
|
| 1355 | - return; |
|
| 1356 | - } |
|
| 1357 | - if ($class_prefix === 'addon') { |
|
| 1358 | - $this->addons->{$class_name} = $class_obj; |
|
| 1359 | - return; |
|
| 1360 | - } |
|
| 1361 | - if (! $from_db) { |
|
| 1362 | - $this->LIB->{$class_name} = $class_obj; |
|
| 1363 | - } |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - /** |
|
| 1369 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1370 | - * |
|
| 1371 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1372 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1373 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1374 | - * @param array $arguments |
|
| 1375 | - * @return object |
|
| 1376 | - */ |
|
| 1377 | - public static function factory($classname, $arguments = array()) |
|
| 1378 | - { |
|
| 1379 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1380 | - if ($loader instanceof Closure) { |
|
| 1381 | - return $loader($arguments); |
|
| 1382 | - } |
|
| 1383 | - if (method_exists(self::instance(), $loader)) { |
|
| 1384 | - return self::instance()->{$loader}($classname, $arguments); |
|
| 1385 | - } |
|
| 1386 | - return null; |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - |
|
| 1390 | - |
|
| 1391 | - /** |
|
| 1392 | - * Gets the addon by its class name |
|
| 1393 | - * |
|
| 1394 | - * @param string $class_name |
|
| 1395 | - * @return EE_Addon |
|
| 1396 | - * @throws OutOfBoundsException |
|
| 1397 | - */ |
|
| 1398 | - public function getAddon($class_name) |
|
| 1399 | - { |
|
| 1400 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1401 | - return $this->addons->{$class_name}; |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - |
|
| 1405 | - /** |
|
| 1406 | - * removes the addon from the internal cache |
|
| 1407 | - * |
|
| 1408 | - * @param string $class_name |
|
| 1409 | - * @return void |
|
| 1410 | - */ |
|
| 1411 | - public function removeAddon($class_name) |
|
| 1412 | - { |
|
| 1413 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1414 | - unset($this->addons->{$class_name}); |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - |
|
| 1418 | - |
|
| 1419 | - /** |
|
| 1420 | - * Gets the addon by its name/slug (not classname. For that, just |
|
| 1421 | - * use the get_addon() method above |
|
| 1422 | - * |
|
| 1423 | - * @param string $name |
|
| 1424 | - * @return EE_Addon |
|
| 1425 | - */ |
|
| 1426 | - public function get_addon_by_name($name) |
|
| 1427 | - { |
|
| 1428 | - foreach ($this->addons as $addon) { |
|
| 1429 | - if ($addon->name() === $name) { |
|
| 1430 | - return $addon; |
|
| 1431 | - } |
|
| 1432 | - } |
|
| 1433 | - return null; |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - |
|
| 1437 | - |
|
| 1438 | - /** |
|
| 1439 | - * Gets an array of all the registered addons, where the keys are their names. |
|
| 1440 | - * (ie, what each returns for their name() function) |
|
| 1441 | - * They're already available on EE_Registry::instance()->addons as properties, |
|
| 1442 | - * where each property's name is the addon's classname, |
|
| 1443 | - * So if you just want to get the addon by classname, |
|
| 1444 | - * OR use the get_addon() method above. |
|
| 1445 | - * PLEASE NOTE: |
|
| 1446 | - * addons with Fully Qualified Class Names |
|
| 1447 | - * have had the namespace separators converted to underscores, |
|
| 1448 | - * so a classname like Fully\Qualified\ClassName |
|
| 1449 | - * would have been converted to Fully_Qualified_ClassName |
|
| 1450 | - * |
|
| 1451 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1452 | - */ |
|
| 1453 | - public function get_addons_by_name() |
|
| 1454 | - { |
|
| 1455 | - $addons = array(); |
|
| 1456 | - foreach ($this->addons as $addon) { |
|
| 1457 | - $addons[$addon->name()] = $addon; |
|
| 1458 | - } |
|
| 1459 | - return $addons; |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - |
|
| 1463 | - /** |
|
| 1464 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1465 | - * a stale copy of it around |
|
| 1466 | - * |
|
| 1467 | - * @param string $model_name |
|
| 1468 | - * @return \EEM_Base |
|
| 1469 | - * @throws \EE_Error |
|
| 1470 | - */ |
|
| 1471 | - public function reset_model($model_name) |
|
| 1472 | - { |
|
| 1473 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1474 | - ? "EEM_{$model_name}" |
|
| 1475 | - : $model_name; |
|
| 1476 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1477 | - return null; |
|
| 1478 | - } |
|
| 1479 | - //get that model reset it and make sure we nuke the old reference to it |
|
| 1480 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1481 | - && is_callable( |
|
| 1482 | - array($model_class_name, 'reset') |
|
| 1483 | - )) { |
|
| 1484 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1485 | - } else { |
|
| 1486 | - throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1487 | - } |
|
| 1488 | - return $this->LIB->{$model_class_name}; |
|
| 1489 | - } |
|
| 1490 | - |
|
| 1491 | - |
|
| 1492 | - |
|
| 1493 | - /** |
|
| 1494 | - * Resets the registry. |
|
| 1495 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1496 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1497 | - * - $_dependency_map |
|
| 1498 | - * - $_class_abbreviations |
|
| 1499 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1500 | - * - $REQ: Still on the same request so no need to change. |
|
| 1501 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1502 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1503 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1504 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1505 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1506 | - * switch or on the restore. |
|
| 1507 | - * - $modules |
|
| 1508 | - * - $shortcodes |
|
| 1509 | - * - $widgets |
|
| 1510 | - * |
|
| 1511 | - * @param boolean $hard [deprecated] |
|
| 1512 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1513 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1514 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1515 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1516 | - * client |
|
| 1517 | - * code instead can just change the model context to a different blog id if |
|
| 1518 | - * necessary |
|
| 1519 | - * @return EE_Registry |
|
| 1520 | - * @throws EE_Error |
|
| 1521 | - * @throws ReflectionException |
|
| 1522 | - */ |
|
| 1523 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1524 | - { |
|
| 1525 | - $instance = self::instance(); |
|
| 1526 | - $instance->_cache_on = true; |
|
| 1527 | - // reset some "special" classes |
|
| 1528 | - EEH_Activation::reset(); |
|
| 1529 | - $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1530 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1531 | - $instance->CART = null; |
|
| 1532 | - $instance->MRM = null; |
|
| 1533 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1534 | - //messages reset |
|
| 1535 | - EED_Messages::reset(); |
|
| 1536 | - //handle of objects cached on LIB |
|
| 1537 | - foreach (array('LIB', 'modules') as $cache) { |
|
| 1538 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1539 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1540 | - unset($instance->{$cache}->{$class_name}); |
|
| 1541 | - } |
|
| 1542 | - } |
|
| 1543 | - } |
|
| 1544 | - return $instance; |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - |
|
| 1548 | - |
|
| 1549 | - /** |
|
| 1550 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1551 | - * if passed object implements InterminableInterface, then return false, |
|
| 1552 | - * to indicate that it should NOT be cleared from the Registry cache |
|
| 1553 | - * |
|
| 1554 | - * @param $object |
|
| 1555 | - * @param bool $reset_models |
|
| 1556 | - * @return bool returns true if cached object should be unset |
|
| 1557 | - */ |
|
| 1558 | - private static function _reset_and_unset_object($object, $reset_models) |
|
| 1559 | - { |
|
| 1560 | - if (! is_object($object)) { |
|
| 1561 | - // don't unset anything that's not an object |
|
| 1562 | - return false; |
|
| 1563 | - } |
|
| 1564 | - if ($object instanceof EED_Module) { |
|
| 1565 | - $object::reset(); |
|
| 1566 | - // don't unset modules |
|
| 1567 | - return false; |
|
| 1568 | - } |
|
| 1569 | - if ($object instanceof ResettableInterface) { |
|
| 1570 | - if ($object instanceof EEM_Base) { |
|
| 1571 | - if ($reset_models) { |
|
| 1572 | - $object->reset(); |
|
| 1573 | - return true; |
|
| 1574 | - } |
|
| 1575 | - return false; |
|
| 1576 | - } |
|
| 1577 | - $object->reset(); |
|
| 1578 | - return true; |
|
| 1579 | - } |
|
| 1580 | - if (! $object instanceof InterminableInterface) { |
|
| 1581 | - return true; |
|
| 1582 | - } |
|
| 1583 | - return false; |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * Gets all the custom post type models defined |
|
| 1590 | - * |
|
| 1591 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1592 | - */ |
|
| 1593 | - public function cpt_models() |
|
| 1594 | - { |
|
| 1595 | - $cpt_models = array(); |
|
| 1596 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1597 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1598 | - $cpt_models[$short_name] = $classname; |
|
| 1599 | - } |
|
| 1600 | - } |
|
| 1601 | - return $cpt_models; |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - |
|
| 1605 | - |
|
| 1606 | - /** |
|
| 1607 | - * @return \EE_Config |
|
| 1608 | - */ |
|
| 1609 | - public static function CFG() |
|
| 1610 | - { |
|
| 1611 | - return self::instance()->CFG; |
|
| 1612 | - } |
|
| 26 | + /** |
|
| 27 | + * @var EE_Registry $_instance |
|
| 28 | + */ |
|
| 29 | + private static $_instance; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var EE_Dependency_Map $_dependency_map |
|
| 33 | + */ |
|
| 34 | + protected $_dependency_map; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var array $_class_abbreviations |
|
| 38 | + */ |
|
| 39 | + protected $_class_abbreviations = array(); |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var CommandBusInterface $BUS |
|
| 43 | + */ |
|
| 44 | + public $BUS; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EE_Cart $CART |
|
| 48 | + */ |
|
| 49 | + public $CART; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var EE_Config $CFG |
|
| 53 | + */ |
|
| 54 | + public $CFG; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var EE_Network_Config $NET_CFG |
|
| 58 | + */ |
|
| 59 | + public $NET_CFG; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * StdClass object for storing library classes in |
|
| 63 | + * |
|
| 64 | + * @var StdClass $LIB |
|
| 65 | + */ |
|
| 66 | + public $LIB; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var EE_Request_Handler $REQ |
|
| 70 | + */ |
|
| 71 | + public $REQ; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var EE_Session $SSN |
|
| 75 | + */ |
|
| 76 | + public $SSN; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @since 4.5.0 |
|
| 80 | + * @var EE_Capabilities $CAP |
|
| 81 | + */ |
|
| 82 | + public $CAP; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @since 4.9.0 |
|
| 86 | + * @var EE_Message_Resource_Manager $MRM |
|
| 87 | + */ |
|
| 88 | + public $MRM; |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var Registry $AssetsRegistry |
|
| 93 | + */ |
|
| 94 | + public $AssetsRegistry; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 98 | + * |
|
| 99 | + * @var EE_Addon[] $addons |
|
| 100 | + */ |
|
| 101 | + public $addons; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 105 | + * |
|
| 106 | + * @var EEM_Base[] $models |
|
| 107 | + */ |
|
| 108 | + public $models = array(); |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @var EED_Module[] $modules |
|
| 112 | + */ |
|
| 113 | + public $modules; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var EES_Shortcode[] $shortcodes |
|
| 117 | + */ |
|
| 118 | + public $shortcodes; |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @var WP_Widget[] $widgets |
|
| 122 | + */ |
|
| 123 | + public $widgets; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 127 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 128 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 129 | + * classnames (eg "EEM_Event") |
|
| 130 | + * |
|
| 131 | + * @var array $non_abstract_db_models |
|
| 132 | + */ |
|
| 133 | + public $non_abstract_db_models = array(); |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * internationalization for JS strings |
|
| 138 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 139 | + * in js file: var translatedString = eei18n.string_key; |
|
| 140 | + * |
|
| 141 | + * @var array $i18n_js_strings |
|
| 142 | + */ |
|
| 143 | + public static $i18n_js_strings = array(); |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * $main_file - path to espresso.php |
|
| 148 | + * |
|
| 149 | + * @var array $main_file |
|
| 150 | + */ |
|
| 151 | + public $main_file; |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * array of ReflectionClass objects where the key is the class name |
|
| 155 | + * |
|
| 156 | + * @var ReflectionClass[] $_reflectors |
|
| 157 | + */ |
|
| 158 | + public $_reflectors; |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 162 | + * |
|
| 163 | + * @var boolean $_cache_on |
|
| 164 | + */ |
|
| 165 | + protected $_cache_on = true; |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @singleton method used to instantiate class object |
|
| 171 | + * @param EE_Dependency_Map $dependency_map |
|
| 172 | + * @return EE_Registry instance |
|
| 173 | + * @throws InvalidArgumentException |
|
| 174 | + * @throws InvalidInterfaceException |
|
| 175 | + * @throws InvalidDataTypeException |
|
| 176 | + */ |
|
| 177 | + public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 178 | + { |
|
| 179 | + // check if class object is instantiated |
|
| 180 | + if (! self::$_instance instanceof EE_Registry) { |
|
| 181 | + self::$_instance = new self($dependency_map); |
|
| 182 | + } |
|
| 183 | + return self::$_instance; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * protected constructor to prevent direct creation |
|
| 190 | + * |
|
| 191 | + * @Constructor |
|
| 192 | + * @param EE_Dependency_Map $dependency_map |
|
| 193 | + * @throws InvalidDataTypeException |
|
| 194 | + * @throws InvalidInterfaceException |
|
| 195 | + * @throws InvalidArgumentException |
|
| 196 | + */ |
|
| 197 | + protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 198 | + { |
|
| 199 | + $this->_dependency_map = $dependency_map; |
|
| 200 | + // $registry_container = new RegistryContainer(); |
|
| 201 | + $this->LIB = new RegistryContainer(); |
|
| 202 | + $this->addons = new RegistryContainer(); |
|
| 203 | + $this->modules = new RegistryContainer(); |
|
| 204 | + $this->shortcodes = new RegistryContainer(); |
|
| 205 | + $this->widgets = new RegistryContainer(); |
|
| 206 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * initialize |
|
| 213 | + * |
|
| 214 | + * @throws EE_Error |
|
| 215 | + * @throws ReflectionException |
|
| 216 | + */ |
|
| 217 | + public function initialize() |
|
| 218 | + { |
|
| 219 | + $this->_class_abbreviations = apply_filters( |
|
| 220 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 221 | + array( |
|
| 222 | + 'EE_Config' => 'CFG', |
|
| 223 | + 'EE_Session' => 'SSN', |
|
| 224 | + 'EE_Capabilities' => 'CAP', |
|
| 225 | + 'EE_Cart' => 'CART', |
|
| 226 | + 'EE_Network_Config' => 'NET_CFG', |
|
| 227 | + 'EE_Request_Handler' => 'REQ', |
|
| 228 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
| 229 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 230 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + $this->load_core('Base', array(), true); |
|
| 234 | + // add our request and response objects to the cache |
|
| 235 | + $request_loader = $this->_dependency_map->class_loader( |
|
| 236 | + 'EventEspresso\core\services\request\Request' |
|
| 237 | + ); |
|
| 238 | + $this->_set_cached_class( |
|
| 239 | + $request_loader(), |
|
| 240 | + 'EventEspresso\core\services\request\Request' |
|
| 241 | + ); |
|
| 242 | + $response_loader = $this->_dependency_map->class_loader( |
|
| 243 | + 'EventEspresso\core\services\request\Response' |
|
| 244 | + ); |
|
| 245 | + $this->_set_cached_class( |
|
| 246 | + $response_loader(), |
|
| 247 | + 'EventEspresso\core\services\request\Response' |
|
| 248 | + ); |
|
| 249 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + public function init() |
|
| 258 | + { |
|
| 259 | + // Get current page protocol |
|
| 260 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 261 | + // Output admin-ajax.php URL with same protocol as current page |
|
| 262 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 263 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * localize_i18n_js_strings |
|
| 270 | + * |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public static function localize_i18n_js_strings() |
|
| 274 | + { |
|
| 275 | + $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 276 | + foreach ($i18n_js_strings as $key => $value) { |
|
| 277 | + if (is_scalar($value)) { |
|
| 278 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param mixed string | EED_Module $module |
|
| 288 | + * @throws EE_Error |
|
| 289 | + * @throws ReflectionException |
|
| 290 | + */ |
|
| 291 | + public function add_module($module) |
|
| 292 | + { |
|
| 293 | + if ($module instanceof EED_Module) { |
|
| 294 | + $module_class = get_class($module); |
|
| 295 | + $this->modules->{$module_class} = $module; |
|
| 296 | + } else { |
|
| 297 | + if ( ! class_exists('EE_Module_Request_Router', false)) { |
|
| 298 | + $this->load_core('Module_Request_Router'); |
|
| 299 | + } |
|
| 300 | + EE_Module_Request_Router::module_factory($module); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * @param string $module_name |
|
| 308 | + * @return mixed EED_Module | NULL |
|
| 309 | + */ |
|
| 310 | + public function get_module($module_name = '') |
|
| 311 | + { |
|
| 312 | + return isset($this->modules->{$module_name}) |
|
| 313 | + ? $this->modules->{$module_name} |
|
| 314 | + : null; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * loads core classes - must be singletons |
|
| 321 | + * |
|
| 322 | + * @param string $class_name - simple class name ie: session |
|
| 323 | + * @param mixed $arguments |
|
| 324 | + * @param bool $load_only |
|
| 325 | + * @return mixed |
|
| 326 | + * @throws EE_Error |
|
| 327 | + * @throws ReflectionException |
|
| 328 | + */ |
|
| 329 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 330 | + { |
|
| 331 | + $core_paths = apply_filters( |
|
| 332 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
| 333 | + array( |
|
| 334 | + EE_CORE, |
|
| 335 | + EE_ADMIN, |
|
| 336 | + EE_CPTS, |
|
| 337 | + EE_CORE . 'data_migration_scripts' . DS, |
|
| 338 | + EE_CORE . 'capabilities' . DS, |
|
| 339 | + EE_CORE . 'request_stack' . DS, |
|
| 340 | + EE_CORE . 'middleware' . DS, |
|
| 341 | + ) |
|
| 342 | + ); |
|
| 343 | + // retrieve instantiated class |
|
| 344 | + return $this->_load( |
|
| 345 | + $core_paths, |
|
| 346 | + 'EE_', |
|
| 347 | + $class_name, |
|
| 348 | + 'core', |
|
| 349 | + $arguments, |
|
| 350 | + false, |
|
| 351 | + true, |
|
| 352 | + $load_only |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * loads service classes |
|
| 360 | + * |
|
| 361 | + * @param string $class_name - simple class name ie: session |
|
| 362 | + * @param mixed $arguments |
|
| 363 | + * @param bool $load_only |
|
| 364 | + * @return mixed |
|
| 365 | + * @throws EE_Error |
|
| 366 | + * @throws ReflectionException |
|
| 367 | + */ |
|
| 368 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 369 | + { |
|
| 370 | + $service_paths = apply_filters( |
|
| 371 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
| 372 | + array( |
|
| 373 | + EE_CORE . 'services' . DS, |
|
| 374 | + ) |
|
| 375 | + ); |
|
| 376 | + // retrieve instantiated class |
|
| 377 | + return $this->_load( |
|
| 378 | + $service_paths, |
|
| 379 | + 'EE_', |
|
| 380 | + $class_name, |
|
| 381 | + 'class', |
|
| 382 | + $arguments, |
|
| 383 | + false, |
|
| 384 | + true, |
|
| 385 | + $load_only |
|
| 386 | + ); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * loads data_migration_scripts |
|
| 393 | + * |
|
| 394 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 395 | + * @param mixed $arguments |
|
| 396 | + * @return EE_Data_Migration_Script_Base|mixed |
|
| 397 | + * @throws EE_Error |
|
| 398 | + * @throws ReflectionException |
|
| 399 | + */ |
|
| 400 | + public function load_dms($class_name, $arguments = array()) |
|
| 401 | + { |
|
| 402 | + // retrieve instantiated class |
|
| 403 | + return $this->_load( |
|
| 404 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 405 | + 'EE_DMS_', |
|
| 406 | + $class_name, |
|
| 407 | + 'dms', |
|
| 408 | + $arguments, |
|
| 409 | + false, |
|
| 410 | + false |
|
| 411 | + ); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * loads object creating classes - must be singletons |
|
| 418 | + * |
|
| 419 | + * @param string $class_name - simple class name ie: attendee |
|
| 420 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
| 421 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 422 | + * instantiate |
|
| 423 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 424 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 425 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 426 | + * (default) |
|
| 427 | + * @return EE_Base_Class | bool |
|
| 428 | + * @throws EE_Error |
|
| 429 | + * @throws ReflectionException |
|
| 430 | + */ |
|
| 431 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 432 | + { |
|
| 433 | + $paths = apply_filters( |
|
| 434 | + 'FHEE__EE_Registry__load_class__paths', array( |
|
| 435 | + EE_CORE, |
|
| 436 | + EE_CLASSES, |
|
| 437 | + EE_BUSINESS, |
|
| 438 | + ) |
|
| 439 | + ); |
|
| 440 | + // retrieve instantiated class |
|
| 441 | + return $this->_load( |
|
| 442 | + $paths, |
|
| 443 | + 'EE_', |
|
| 444 | + $class_name, |
|
| 445 | + 'class', |
|
| 446 | + $arguments, |
|
| 447 | + $from_db, |
|
| 448 | + $cache, |
|
| 449 | + $load_only |
|
| 450 | + ); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * loads helper classes - must be singletons |
|
| 457 | + * |
|
| 458 | + * @param string $class_name - simple class name ie: price |
|
| 459 | + * @param mixed $arguments |
|
| 460 | + * @param bool $load_only |
|
| 461 | + * @return EEH_Base | bool |
|
| 462 | + * @throws EE_Error |
|
| 463 | + * @throws ReflectionException |
|
| 464 | + */ |
|
| 465 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 466 | + { |
|
| 467 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 468 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 469 | + // retrieve instantiated class |
|
| 470 | + return $this->_load( |
|
| 471 | + $helper_paths, |
|
| 472 | + 'EEH_', |
|
| 473 | + $class_name, |
|
| 474 | + 'helper', |
|
| 475 | + $arguments, |
|
| 476 | + false, |
|
| 477 | + true, |
|
| 478 | + $load_only |
|
| 479 | + ); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * loads core classes - must be singletons |
|
| 486 | + * |
|
| 487 | + * @param string $class_name - simple class name ie: session |
|
| 488 | + * @param mixed $arguments |
|
| 489 | + * @param bool $load_only |
|
| 490 | + * @param bool $cache whether to cache the object or not. |
|
| 491 | + * @return mixed |
|
| 492 | + * @throws EE_Error |
|
| 493 | + * @throws ReflectionException |
|
| 494 | + */ |
|
| 495 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 496 | + { |
|
| 497 | + $paths = array( |
|
| 498 | + EE_LIBRARIES, |
|
| 499 | + EE_LIBRARIES . 'messages' . DS, |
|
| 500 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
| 501 | + EE_LIBRARIES . 'qtips' . DS, |
|
| 502 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
| 503 | + ); |
|
| 504 | + // retrieve instantiated class |
|
| 505 | + return $this->_load( |
|
| 506 | + $paths, |
|
| 507 | + 'EE_', |
|
| 508 | + $class_name, |
|
| 509 | + 'lib', |
|
| 510 | + $arguments, |
|
| 511 | + false, |
|
| 512 | + $cache, |
|
| 513 | + $load_only |
|
| 514 | + ); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * loads model classes - must be singletons |
|
| 521 | + * |
|
| 522 | + * @param string $class_name - simple class name ie: price |
|
| 523 | + * @param mixed $arguments |
|
| 524 | + * @param bool $load_only |
|
| 525 | + * @return EEM_Base | bool |
|
| 526 | + * @throws EE_Error |
|
| 527 | + * @throws ReflectionException |
|
| 528 | + */ |
|
| 529 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 530 | + { |
|
| 531 | + $paths = apply_filters( |
|
| 532 | + 'FHEE__EE_Registry__load_model__paths', array( |
|
| 533 | + EE_MODELS, |
|
| 534 | + EE_CORE, |
|
| 535 | + ) |
|
| 536 | + ); |
|
| 537 | + // retrieve instantiated class |
|
| 538 | + return $this->_load( |
|
| 539 | + $paths, |
|
| 540 | + 'EEM_', |
|
| 541 | + $class_name, |
|
| 542 | + 'model', |
|
| 543 | + $arguments, |
|
| 544 | + false, |
|
| 545 | + true, |
|
| 546 | + $load_only |
|
| 547 | + ); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * loads model classes - must be singletons |
|
| 554 | + * |
|
| 555 | + * @param string $class_name - simple class name ie: price |
|
| 556 | + * @param mixed $arguments |
|
| 557 | + * @param bool $load_only |
|
| 558 | + * @return mixed | bool |
|
| 559 | + * @throws EE_Error |
|
| 560 | + * @throws ReflectionException |
|
| 561 | + */ |
|
| 562 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 563 | + { |
|
| 564 | + $paths = array( |
|
| 565 | + EE_MODELS . 'fields' . DS, |
|
| 566 | + EE_MODELS . 'helpers' . DS, |
|
| 567 | + EE_MODELS . 'relations' . DS, |
|
| 568 | + EE_MODELS . 'strategies' . DS, |
|
| 569 | + ); |
|
| 570 | + // retrieve instantiated class |
|
| 571 | + return $this->_load( |
|
| 572 | + $paths, |
|
| 573 | + 'EE_', |
|
| 574 | + $class_name, |
|
| 575 | + '', |
|
| 576 | + $arguments, |
|
| 577 | + false, |
|
| 578 | + true, |
|
| 579 | + $load_only |
|
| 580 | + ); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * Determines if $model_name is the name of an actual EE model. |
|
| 587 | + * |
|
| 588 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 589 | + * @return boolean |
|
| 590 | + */ |
|
| 591 | + public function is_model_name($model_name) |
|
| 592 | + { |
|
| 593 | + return isset($this->models[$model_name]); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * generic class loader |
|
| 600 | + * |
|
| 601 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 602 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
| 603 | + * @param string $type - file type - core? class? helper? model? |
|
| 604 | + * @param mixed $arguments |
|
| 605 | + * @param bool $load_only |
|
| 606 | + * @return mixed |
|
| 607 | + * @throws EE_Error |
|
| 608 | + * @throws ReflectionException |
|
| 609 | + */ |
|
| 610 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 611 | + { |
|
| 612 | + // retrieve instantiated class |
|
| 613 | + return $this->_load( |
|
| 614 | + $path_to_file, |
|
| 615 | + '', |
|
| 616 | + $file_name, |
|
| 617 | + $type, |
|
| 618 | + $arguments, |
|
| 619 | + false, |
|
| 620 | + true, |
|
| 621 | + $load_only |
|
| 622 | + ); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 629 | + * @param string $class_name - full class name ie: My_Class |
|
| 630 | + * @param string $type - file type - core? class? helper? model? |
|
| 631 | + * @param mixed $arguments |
|
| 632 | + * @param bool $load_only |
|
| 633 | + * @return bool|EE_Addon|object |
|
| 634 | + * @throws EE_Error |
|
| 635 | + * @throws ReflectionException |
|
| 636 | + */ |
|
| 637 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 638 | + { |
|
| 639 | + // retrieve instantiated class |
|
| 640 | + return $this->_load( |
|
| 641 | + $path_to_file, |
|
| 642 | + 'addon', |
|
| 643 | + $class_name, |
|
| 644 | + $type, |
|
| 645 | + $arguments, |
|
| 646 | + false, |
|
| 647 | + true, |
|
| 648 | + $load_only |
|
| 649 | + ); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * instantiates, caches, and automatically resolves dependencies |
|
| 656 | + * for classes that use a Fully Qualified Class Name. |
|
| 657 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 658 | + * then you need to use one of the existing load_*() methods |
|
| 659 | + * which can resolve the classname and filepath from the passed arguments |
|
| 660 | + * |
|
| 661 | + * @param bool|string $class_name Fully Qualified Class Name |
|
| 662 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 663 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 664 | + * @param bool $from_db some classes are instantiated from the db |
|
| 665 | + * and thus call a different method to instantiate |
|
| 666 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 667 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 668 | + * @return bool|null|mixed null = failure to load or instantiate class object. |
|
| 669 | + * object = class loaded and instantiated successfully. |
|
| 670 | + * bool = fail or success when $load_only is true |
|
| 671 | + * @throws EE_Error |
|
| 672 | + * @throws ReflectionException |
|
| 673 | + */ |
|
| 674 | + public function create( |
|
| 675 | + $class_name = false, |
|
| 676 | + $arguments = array(), |
|
| 677 | + $cache = false, |
|
| 678 | + $from_db = false, |
|
| 679 | + $load_only = false, |
|
| 680 | + $addon = false |
|
| 681 | + ) { |
|
| 682 | + $class_name = ltrim($class_name, '\\'); |
|
| 683 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 684 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
| 685 | + // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
| 686 | + // or it could return null if the class just could not be found anywhere |
|
| 687 | + if ($class_exists instanceof $class_name || $class_exists === null){ |
|
| 688 | + // either way, return the results |
|
| 689 | + return $class_exists; |
|
| 690 | + } |
|
| 691 | + $class_name = $class_exists; |
|
| 692 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 693 | + if ($load_only) { |
|
| 694 | + return true; |
|
| 695 | + } |
|
| 696 | + $addon = $addon |
|
| 697 | + ? 'addon' |
|
| 698 | + : ''; |
|
| 699 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 700 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 701 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 702 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 703 | + // return object if it's already cached |
|
| 704 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 705 | + if ($cached_class !== null) { |
|
| 706 | + return $cached_class; |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + // obtain the loader method from the dependency map |
|
| 710 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
| 711 | + // instantiate the requested object |
|
| 712 | + if ($loader instanceof Closure) { |
|
| 713 | + $class_obj = $loader($arguments); |
|
| 714 | + } else if ($loader && method_exists($this, $loader)) { |
|
| 715 | + $class_obj = $this->{$loader}($class_name, $arguments); |
|
| 716 | + } else { |
|
| 717 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 718 | + } |
|
| 719 | + if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
| 720 | + // save it for later... kinda like gum { : $ |
|
| 721 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 722 | + } |
|
| 723 | + $this->_cache_on = true; |
|
| 724 | + return $class_obj; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
| 731 | + * |
|
| 732 | + * @param string $class_name |
|
| 733 | + * @param array $arguments |
|
| 734 | + * @param int $attempt |
|
| 735 | + * @return mixed |
|
| 736 | + */ |
|
| 737 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
| 738 | + if (is_object($class_name) || class_exists($class_name)) { |
|
| 739 | + return $class_name; |
|
| 740 | + } |
|
| 741 | + switch ($attempt) { |
|
| 742 | + case 1: |
|
| 743 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
| 744 | + $class_name = strpos($class_name, '\\') !== false |
|
| 745 | + ? '\\' . ltrim($class_name, '\\') |
|
| 746 | + : $class_name; |
|
| 747 | + break; |
|
| 748 | + case 2: |
|
| 749 | + // |
|
| 750 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
| 751 | + if ($loader && method_exists($this, $loader)) { |
|
| 752 | + return $this->{$loader}($class_name, $arguments); |
|
| 753 | + } |
|
| 754 | + break; |
|
| 755 | + case 3: |
|
| 756 | + default; |
|
| 757 | + return null; |
|
| 758 | + } |
|
| 759 | + $attempt++; |
|
| 760 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * instantiates, caches, and injects dependencies for classes |
|
| 767 | + * |
|
| 768 | + * @param array $file_paths an array of paths to folders to look in |
|
| 769 | + * @param string $class_prefix EE or EEM or... ??? |
|
| 770 | + * @param bool|string $class_name $class name |
|
| 771 | + * @param string $type file type - core? class? helper? model? |
|
| 772 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 773 | + * @param bool $from_db some classes are instantiated from the db |
|
| 774 | + * and thus call a different method to instantiate |
|
| 775 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 776 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 777 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
| 778 | + * object = class loaded and instantiated successfully. |
|
| 779 | + * bool = fail or success when $load_only is true |
|
| 780 | + * @throws EE_Error |
|
| 781 | + * @throws ReflectionException |
|
| 782 | + */ |
|
| 783 | + protected function _load( |
|
| 784 | + $file_paths = array(), |
|
| 785 | + $class_prefix = 'EE_', |
|
| 786 | + $class_name = false, |
|
| 787 | + $type = 'class', |
|
| 788 | + $arguments = array(), |
|
| 789 | + $from_db = false, |
|
| 790 | + $cache = true, |
|
| 791 | + $load_only = false |
|
| 792 | + ) { |
|
| 793 | + $class_name = ltrim($class_name, '\\'); |
|
| 794 | + // strip php file extension |
|
| 795 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
| 796 | + // does the class have a prefix ? |
|
| 797 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 798 | + // make sure $class_prefix is uppercase |
|
| 799 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
| 800 | + // add class prefix ONCE!!! |
|
| 801 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 802 | + } |
|
| 803 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 804 | + $class_exists = class_exists($class_name, false); |
|
| 805 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 806 | + if ($load_only && $class_exists) { |
|
| 807 | + return true; |
|
| 808 | + } |
|
| 809 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 810 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 811 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 812 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 813 | + // return object if it's already cached |
|
| 814 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 815 | + if ($cached_class !== null) { |
|
| 816 | + return $cached_class; |
|
| 817 | + } |
|
| 818 | + } |
|
| 819 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 820 | + if (! $class_exists) { |
|
| 821 | + // get full path to file |
|
| 822 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 823 | + // load the file |
|
| 824 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 825 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 826 | + if (! $loaded || $load_only) { |
|
| 827 | + // return boolean if only loading, or null if an object was expected |
|
| 828 | + return $load_only |
|
| 829 | + ? $loaded |
|
| 830 | + : null; |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + // instantiate the requested object |
|
| 834 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 835 | + if ($this->_cache_on && $cache) { |
|
| 836 | + // save it for later... kinda like gum { : $ |
|
| 837 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 838 | + } |
|
| 839 | + $this->_cache_on = true; |
|
| 840 | + return $class_obj; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + /** |
|
| 846 | + * @param string $class_name |
|
| 847 | + * @param string $default have to specify something, but not anything that will conflict |
|
| 848 | + * @return mixed|string |
|
| 849 | + */ |
|
| 850 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
| 851 | + { |
|
| 852 | + return isset($this->_class_abbreviations[$class_name]) |
|
| 853 | + ? $this->_class_abbreviations[$class_name] |
|
| 854 | + : $default; |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * attempts to find a cached version of the requested class |
|
| 859 | + * by looking in the following places: |
|
| 860 | + * $this->{$class_abbreviation} ie: $this->CART |
|
| 861 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 862 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 863 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 864 | + * |
|
| 865 | + * @param string $class_name |
|
| 866 | + * @param string $class_prefix |
|
| 867 | + * @return mixed |
|
| 868 | + * @throws OutOfBoundsException |
|
| 869 | + */ |
|
| 870 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 871 | + { |
|
| 872 | + if ($class_name === 'EE_Registry') { |
|
| 873 | + return $this; |
|
| 874 | + } |
|
| 875 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 876 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 877 | + // check if class has already been loaded, and return it if it has been |
|
| 878 | + if (isset($this->{$class_abbreviation})) { |
|
| 879 | + return $this->{$class_abbreviation}; |
|
| 880 | + } |
|
| 881 | + if (isset ($this->{$class_name})) { |
|
| 882 | + return $this->{$class_name}; |
|
| 883 | + } |
|
| 884 | + if (isset ($this->LIB->{$class_name})) { |
|
| 885 | + return $this->LIB->{$class_name}; |
|
| 886 | + } |
|
| 887 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 888 | + return $this->addons->{$class_name}; |
|
| 889 | + } |
|
| 890 | + return null; |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * removes a cached version of the requested class |
|
| 897 | + * |
|
| 898 | + * @param string $class_name |
|
| 899 | + * @param boolean $addon |
|
| 900 | + * @return boolean |
|
| 901 | + * @throws OutOfBoundsException |
|
| 902 | + */ |
|
| 903 | + public function clear_cached_class($class_name, $addon = false) |
|
| 904 | + { |
|
| 905 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 906 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 907 | + // check if class has already been loaded, and return it if it has been |
|
| 908 | + if (isset($this->{$class_abbreviation})) { |
|
| 909 | + $this->{$class_abbreviation} = null; |
|
| 910 | + return true; |
|
| 911 | + } |
|
| 912 | + if (isset($this->{$class_name})) { |
|
| 913 | + $this->{$class_name} = null; |
|
| 914 | + return true; |
|
| 915 | + } |
|
| 916 | + if (isset($this->LIB->{$class_name})) { |
|
| 917 | + unset($this->LIB->{$class_name}); |
|
| 918 | + return true; |
|
| 919 | + } |
|
| 920 | + if ($addon && isset($this->addons->{$class_name})) { |
|
| 921 | + unset($this->addons->{$class_name}); |
|
| 922 | + return true; |
|
| 923 | + } |
|
| 924 | + return false; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + |
|
| 929 | + /** |
|
| 930 | + * attempts to find a full valid filepath for the requested class. |
|
| 931 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 932 | + * then returns that path if the target file has been found and is readable |
|
| 933 | + * |
|
| 934 | + * @param string $class_name |
|
| 935 | + * @param string $type |
|
| 936 | + * @param array $file_paths |
|
| 937 | + * @return string | bool |
|
| 938 | + */ |
|
| 939 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 940 | + { |
|
| 941 | + // make sure $file_paths is an array |
|
| 942 | + $file_paths = is_array($file_paths) |
|
| 943 | + ? $file_paths |
|
| 944 | + : array($file_paths); |
|
| 945 | + // cycle thru paths |
|
| 946 | + foreach ($file_paths as $key => $file_path) { |
|
| 947 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 948 | + $file_path = $file_path |
|
| 949 | + ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 950 | + : EE_CLASSES; |
|
| 951 | + // prep file type |
|
| 952 | + $type = ! empty($type) |
|
| 953 | + ? trim($type, '.') . '.' |
|
| 954 | + : ''; |
|
| 955 | + // build full file path |
|
| 956 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 957 | + //does the file exist and can be read ? |
|
| 958 | + if (is_readable($file_paths[$key])) { |
|
| 959 | + return $file_paths[$key]; |
|
| 960 | + } |
|
| 961 | + } |
|
| 962 | + return false; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + |
|
| 967 | + /** |
|
| 968 | + * basically just performs a require_once() |
|
| 969 | + * but with some error handling |
|
| 970 | + * |
|
| 971 | + * @param string $path |
|
| 972 | + * @param string $class_name |
|
| 973 | + * @param string $type |
|
| 974 | + * @param array $file_paths |
|
| 975 | + * @return bool |
|
| 976 | + * @throws EE_Error |
|
| 977 | + * @throws ReflectionException |
|
| 978 | + */ |
|
| 979 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 980 | + { |
|
| 981 | + $this->resolve_legacy_class_parent($class_name); |
|
| 982 | + // don't give up! you gotta... |
|
| 983 | + try { |
|
| 984 | + //does the file exist and can it be read ? |
|
| 985 | + if (! $path) { |
|
| 986 | + // just in case the file has already been autoloaded, |
|
| 987 | + // but discrepancies in the naming schema are preventing it from |
|
| 988 | + // being loaded via one of the EE_Registry::load_*() methods, |
|
| 989 | + // then let's try one last hail mary before throwing an exception |
|
| 990 | + // and call class_exists() again, but with autoloading turned ON |
|
| 991 | + if(class_exists($class_name)) { |
|
| 992 | + return true; |
|
| 993 | + } |
|
| 994 | + // so sorry, can't find the file |
|
| 995 | + throw new EE_Error ( |
|
| 996 | + sprintf( |
|
| 997 | + esc_html__( |
|
| 998 | + 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
| 999 | + 'event_espresso' |
|
| 1000 | + ), |
|
| 1001 | + trim($type, '.'), |
|
| 1002 | + $class_name, |
|
| 1003 | + '<br />' . implode(',<br />', $file_paths) |
|
| 1004 | + ) |
|
| 1005 | + ); |
|
| 1006 | + } |
|
| 1007 | + // get the file |
|
| 1008 | + require_once($path); |
|
| 1009 | + // if the class isn't already declared somewhere |
|
| 1010 | + if (class_exists($class_name, false) === false) { |
|
| 1011 | + // so sorry, not a class |
|
| 1012 | + throw new EE_Error( |
|
| 1013 | + sprintf( |
|
| 1014 | + esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 1015 | + $type, |
|
| 1016 | + $path, |
|
| 1017 | + $class_name |
|
| 1018 | + ) |
|
| 1019 | + ); |
|
| 1020 | + } |
|
| 1021 | + } catch (EE_Error $e) { |
|
| 1022 | + $e->get_error(); |
|
| 1023 | + return false; |
|
| 1024 | + } |
|
| 1025 | + return true; |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
| 1032 | + * before their class declaration in order to ensure that the parent class was loaded. |
|
| 1033 | + * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
| 1034 | + * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
| 1035 | + * |
|
| 1036 | + * @param string $class_name |
|
| 1037 | + */ |
|
| 1038 | + protected function resolve_legacy_class_parent($class_name = '') |
|
| 1039 | + { |
|
| 1040 | + try { |
|
| 1041 | + $legacy_parent_class_map = array( |
|
| 1042 | + 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php' |
|
| 1043 | + ); |
|
| 1044 | + if(isset($legacy_parent_class_map[$class_name])) { |
|
| 1045 | + require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name]; |
|
| 1046 | + } |
|
| 1047 | + } catch (Exception $exception) { |
|
| 1048 | + } |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + |
|
| 1052 | + |
|
| 1053 | + /** |
|
| 1054 | + * _create_object |
|
| 1055 | + * Attempts to instantiate the requested class via any of the |
|
| 1056 | + * commonly used instantiation methods employed throughout EE. |
|
| 1057 | + * The priority for instantiation is as follows: |
|
| 1058 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 1059 | + * - model objects via their 'new_instance_from_db' method |
|
| 1060 | + * - model objects via their 'new_instance' method |
|
| 1061 | + * - "singleton" classes" via their 'instance' method |
|
| 1062 | + * - standard instantiable classes via their __constructor |
|
| 1063 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 1064 | + * then the constructor for the requested class will be examined to determine |
|
| 1065 | + * if any dependencies exist, and if they can be injected. |
|
| 1066 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1067 | + * |
|
| 1068 | + * @param string $class_name |
|
| 1069 | + * @param array $arguments |
|
| 1070 | + * @param string $type |
|
| 1071 | + * @param bool $from_db |
|
| 1072 | + * @return null|object |
|
| 1073 | + * @throws EE_Error |
|
| 1074 | + * @throws ReflectionException |
|
| 1075 | + */ |
|
| 1076 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 1077 | + { |
|
| 1078 | + // create reflection |
|
| 1079 | + $reflector = $this->get_ReflectionClass($class_name); |
|
| 1080 | + // make sure arguments are an array |
|
| 1081 | + $arguments = is_array($arguments) |
|
| 1082 | + ? $arguments |
|
| 1083 | + : array($arguments); |
|
| 1084 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 1085 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 1086 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 1087 | + ? $arguments |
|
| 1088 | + : array($arguments); |
|
| 1089 | + // attempt to inject dependencies ? |
|
| 1090 | + if ($this->_dependency_map->has($class_name)) { |
|
| 1091 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1092 | + } |
|
| 1093 | + // instantiate the class if possible |
|
| 1094 | + if ($reflector->isAbstract()) { |
|
| 1095 | + // nothing to instantiate, loading file was enough |
|
| 1096 | + // does not throw an exception so $instantiation_mode is unused |
|
| 1097 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1098 | + return true; |
|
| 1099 | + } |
|
| 1100 | + if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1101 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1102 | + // $instantiation_mode = "2) no constructor but instantiable"; |
|
| 1103 | + return $reflector->newInstance(); |
|
| 1104 | + } |
|
| 1105 | + if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1106 | + // $instantiation_mode = "3) new_instance_from_db()"; |
|
| 1107 | + return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1108 | + } |
|
| 1109 | + if (method_exists($class_name, 'new_instance')) { |
|
| 1110 | + // $instantiation_mode = "4) new_instance()"; |
|
| 1111 | + return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1112 | + } |
|
| 1113 | + if (method_exists($class_name, 'instance')) { |
|
| 1114 | + // $instantiation_mode = "5) instance()"; |
|
| 1115 | + return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1116 | + } |
|
| 1117 | + if ($reflector->isInstantiable()) { |
|
| 1118 | + // $instantiation_mode = "6) constructor"; |
|
| 1119 | + return $reflector->newInstanceArgs($arguments); |
|
| 1120 | + } |
|
| 1121 | + // heh ? something's not right ! |
|
| 1122 | + throw new EE_Error( |
|
| 1123 | + sprintf( |
|
| 1124 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1125 | + $type, |
|
| 1126 | + $class_name |
|
| 1127 | + ) |
|
| 1128 | + ); |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1135 | + * @param array $array |
|
| 1136 | + * @return bool |
|
| 1137 | + */ |
|
| 1138 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1139 | + { |
|
| 1140 | + return ! empty($array) |
|
| 1141 | + ? array_keys($array) === range(0, count($array) - 1) |
|
| 1142 | + : true; |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + |
|
| 1146 | + |
|
| 1147 | + /** |
|
| 1148 | + * getReflectionClass |
|
| 1149 | + * checks if a ReflectionClass object has already been generated for a class |
|
| 1150 | + * and returns that instead of creating a new one |
|
| 1151 | + * |
|
| 1152 | + * @param string $class_name |
|
| 1153 | + * @return ReflectionClass |
|
| 1154 | + * @throws ReflectionException |
|
| 1155 | + */ |
|
| 1156 | + public function get_ReflectionClass($class_name) |
|
| 1157 | + { |
|
| 1158 | + if ( |
|
| 1159 | + ! isset($this->_reflectors[$class_name]) |
|
| 1160 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1161 | + ) { |
|
| 1162 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1163 | + } |
|
| 1164 | + return $this->_reflectors[$class_name]; |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + |
|
| 1168 | + |
|
| 1169 | + /** |
|
| 1170 | + * _resolve_dependencies |
|
| 1171 | + * examines the constructor for the requested class to determine |
|
| 1172 | + * if any dependencies exist, and if they can be injected. |
|
| 1173 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1174 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1175 | + * For example: |
|
| 1176 | + * if attempting to load a class "Foo" with the following constructor: |
|
| 1177 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1178 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1179 | + * but only IF they are NOT already present in the incoming arguments array, |
|
| 1180 | + * and the correct classes can be loaded |
|
| 1181 | + * |
|
| 1182 | + * @param ReflectionClass $reflector |
|
| 1183 | + * @param string $class_name |
|
| 1184 | + * @param array $arguments |
|
| 1185 | + * @return array |
|
| 1186 | + * @throws EE_Error |
|
| 1187 | + * @throws ReflectionException |
|
| 1188 | + */ |
|
| 1189 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1190 | + { |
|
| 1191 | + // let's examine the constructor |
|
| 1192 | + $constructor = $reflector->getConstructor(); |
|
| 1193 | + // whu? huh? nothing? |
|
| 1194 | + if (! $constructor) { |
|
| 1195 | + return $arguments; |
|
| 1196 | + } |
|
| 1197 | + // get constructor parameters |
|
| 1198 | + $params = $constructor->getParameters(); |
|
| 1199 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1200 | + $argument_keys = array_keys($arguments); |
|
| 1201 | + // now loop thru all of the constructors expected parameters |
|
| 1202 | + foreach ($params as $index => $param) { |
|
| 1203 | + // is this a dependency for a specific class ? |
|
| 1204 | + $param_class = $param->getClass() |
|
| 1205 | + ? $param->getClass()->name |
|
| 1206 | + : null; |
|
| 1207 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1208 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1209 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1210 | + : $param_class; |
|
| 1211 | + if ( |
|
| 1212 | + // param is not even a class |
|
| 1213 | + $param_class === null |
|
| 1214 | + // and something already exists in the incoming arguments for this param |
|
| 1215 | + && array_key_exists($index, $argument_keys) |
|
| 1216 | + && array_key_exists($argument_keys[$index], $arguments) |
|
| 1217 | + ) { |
|
| 1218 | + // so let's skip this argument and move on to the next |
|
| 1219 | + continue; |
|
| 1220 | + } |
|
| 1221 | + if ( |
|
| 1222 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1223 | + $param_class !== null |
|
| 1224 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1225 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1226 | + ) { |
|
| 1227 | + // skip this argument and move on to the next |
|
| 1228 | + continue; |
|
| 1229 | + } |
|
| 1230 | + if ( |
|
| 1231 | + // parameter is type hinted as a class, and should be injected |
|
| 1232 | + $param_class !== null |
|
| 1233 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1234 | + ) { |
|
| 1235 | + $arguments = $this->_resolve_dependency( |
|
| 1236 | + $class_name, |
|
| 1237 | + $param_class, |
|
| 1238 | + $arguments, |
|
| 1239 | + $index, |
|
| 1240 | + $argument_keys |
|
| 1241 | + ); |
|
| 1242 | + } else { |
|
| 1243 | + try { |
|
| 1244 | + $arguments[$index] = $param->isDefaultValueAvailable() |
|
| 1245 | + ? $param->getDefaultValue() |
|
| 1246 | + : null; |
|
| 1247 | + } catch (ReflectionException $e) { |
|
| 1248 | + throw new ReflectionException( |
|
| 1249 | + sprintf( |
|
| 1250 | + esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'), |
|
| 1251 | + $e->getMessage(), |
|
| 1252 | + $param->getName(), |
|
| 1253 | + $class_name |
|
| 1254 | + ) |
|
| 1255 | + ); |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + return $arguments; |
|
| 1260 | + } |
|
| 1261 | + |
|
| 1262 | + |
|
| 1263 | + |
|
| 1264 | + /** |
|
| 1265 | + * @param string $class_name |
|
| 1266 | + * @param string $param_class |
|
| 1267 | + * @param array $arguments |
|
| 1268 | + * @param mixed $index |
|
| 1269 | + * @param array $argument_keys |
|
| 1270 | + * @return array |
|
| 1271 | + * @throws EE_Error |
|
| 1272 | + * @throws ReflectionException |
|
| 1273 | + * @throws InvalidArgumentException |
|
| 1274 | + * @throws InvalidInterfaceException |
|
| 1275 | + * @throws InvalidDataTypeException |
|
| 1276 | + */ |
|
| 1277 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
| 1278 | + { |
|
| 1279 | + $dependency = null; |
|
| 1280 | + // should dependency be loaded from cache ? |
|
| 1281 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
| 1282 | + $class_name, |
|
| 1283 | + $param_class |
|
| 1284 | + ); |
|
| 1285 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
| 1286 | + // we might have a dependency... |
|
| 1287 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1288 | + $cached_class = $cache_on |
|
| 1289 | + ? $this->_get_cached_class($param_class) |
|
| 1290 | + : null; |
|
| 1291 | + // and grab it if it exists |
|
| 1292 | + if ($cached_class instanceof $param_class) { |
|
| 1293 | + $dependency = $cached_class; |
|
| 1294 | + } else if ($param_class !== $class_name) { |
|
| 1295 | + // obtain the loader method from the dependency map |
|
| 1296 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1297 | + // is loader a custom closure ? |
|
| 1298 | + if ($loader instanceof Closure) { |
|
| 1299 | + $dependency = $loader($arguments); |
|
| 1300 | + } else { |
|
| 1301 | + // set the cache on property for the recursive loading call |
|
| 1302 | + $this->_cache_on = $cache_on; |
|
| 1303 | + // if not, then let's try and load it via the registry |
|
| 1304 | + if ($loader && method_exists($this, $loader)) { |
|
| 1305 | + $dependency = $this->{$loader}($param_class); |
|
| 1306 | + } else { |
|
| 1307 | + $dependency = LoaderFactory::getLoader()->load( |
|
| 1308 | + $param_class, |
|
| 1309 | + array(), |
|
| 1310 | + $cache_on |
|
| 1311 | + ); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + } |
|
| 1315 | + // did we successfully find the correct dependency ? |
|
| 1316 | + if ($dependency instanceof $param_class) { |
|
| 1317 | + // then let's inject it into the incoming array of arguments at the correct location |
|
| 1318 | + $arguments[$index] = $dependency; |
|
| 1319 | + } |
|
| 1320 | + return $arguments; |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + |
|
| 1324 | + |
|
| 1325 | + /** |
|
| 1326 | + * _set_cached_class |
|
| 1327 | + * attempts to cache the instantiated class locally |
|
| 1328 | + * in one of the following places, in the following order: |
|
| 1329 | + * $this->{class_abbreviation} ie: $this->CART |
|
| 1330 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 1331 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1332 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1333 | + * |
|
| 1334 | + * @param object $class_obj |
|
| 1335 | + * @param string $class_name |
|
| 1336 | + * @param string $class_prefix |
|
| 1337 | + * @param bool $from_db |
|
| 1338 | + * @return void |
|
| 1339 | + * @throws OutOfBoundsException |
|
| 1340 | + */ |
|
| 1341 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1342 | + { |
|
| 1343 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1344 | + return; |
|
| 1345 | + } |
|
| 1346 | + // return newly instantiated class |
|
| 1347 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
| 1348 | + if ($class_abbreviation) { |
|
| 1349 | + $this->{$class_abbreviation} = $class_obj; |
|
| 1350 | + return; |
|
| 1351 | + } |
|
| 1352 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1353 | + if (property_exists($this, $class_name)) { |
|
| 1354 | + $this->{$class_name} = $class_obj; |
|
| 1355 | + return; |
|
| 1356 | + } |
|
| 1357 | + if ($class_prefix === 'addon') { |
|
| 1358 | + $this->addons->{$class_name} = $class_obj; |
|
| 1359 | + return; |
|
| 1360 | + } |
|
| 1361 | + if (! $from_db) { |
|
| 1362 | + $this->LIB->{$class_name} = $class_obj; |
|
| 1363 | + } |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + /** |
|
| 1369 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1370 | + * |
|
| 1371 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1372 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1373 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1374 | + * @param array $arguments |
|
| 1375 | + * @return object |
|
| 1376 | + */ |
|
| 1377 | + public static function factory($classname, $arguments = array()) |
|
| 1378 | + { |
|
| 1379 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1380 | + if ($loader instanceof Closure) { |
|
| 1381 | + return $loader($arguments); |
|
| 1382 | + } |
|
| 1383 | + if (method_exists(self::instance(), $loader)) { |
|
| 1384 | + return self::instance()->{$loader}($classname, $arguments); |
|
| 1385 | + } |
|
| 1386 | + return null; |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + |
|
| 1390 | + |
|
| 1391 | + /** |
|
| 1392 | + * Gets the addon by its class name |
|
| 1393 | + * |
|
| 1394 | + * @param string $class_name |
|
| 1395 | + * @return EE_Addon |
|
| 1396 | + * @throws OutOfBoundsException |
|
| 1397 | + */ |
|
| 1398 | + public function getAddon($class_name) |
|
| 1399 | + { |
|
| 1400 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1401 | + return $this->addons->{$class_name}; |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + |
|
| 1405 | + /** |
|
| 1406 | + * removes the addon from the internal cache |
|
| 1407 | + * |
|
| 1408 | + * @param string $class_name |
|
| 1409 | + * @return void |
|
| 1410 | + */ |
|
| 1411 | + public function removeAddon($class_name) |
|
| 1412 | + { |
|
| 1413 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1414 | + unset($this->addons->{$class_name}); |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + |
|
| 1418 | + |
|
| 1419 | + /** |
|
| 1420 | + * Gets the addon by its name/slug (not classname. For that, just |
|
| 1421 | + * use the get_addon() method above |
|
| 1422 | + * |
|
| 1423 | + * @param string $name |
|
| 1424 | + * @return EE_Addon |
|
| 1425 | + */ |
|
| 1426 | + public function get_addon_by_name($name) |
|
| 1427 | + { |
|
| 1428 | + foreach ($this->addons as $addon) { |
|
| 1429 | + if ($addon->name() === $name) { |
|
| 1430 | + return $addon; |
|
| 1431 | + } |
|
| 1432 | + } |
|
| 1433 | + return null; |
|
| 1434 | + } |
|
| 1435 | + |
|
| 1436 | + |
|
| 1437 | + |
|
| 1438 | + /** |
|
| 1439 | + * Gets an array of all the registered addons, where the keys are their names. |
|
| 1440 | + * (ie, what each returns for their name() function) |
|
| 1441 | + * They're already available on EE_Registry::instance()->addons as properties, |
|
| 1442 | + * where each property's name is the addon's classname, |
|
| 1443 | + * So if you just want to get the addon by classname, |
|
| 1444 | + * OR use the get_addon() method above. |
|
| 1445 | + * PLEASE NOTE: |
|
| 1446 | + * addons with Fully Qualified Class Names |
|
| 1447 | + * have had the namespace separators converted to underscores, |
|
| 1448 | + * so a classname like Fully\Qualified\ClassName |
|
| 1449 | + * would have been converted to Fully_Qualified_ClassName |
|
| 1450 | + * |
|
| 1451 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1452 | + */ |
|
| 1453 | + public function get_addons_by_name() |
|
| 1454 | + { |
|
| 1455 | + $addons = array(); |
|
| 1456 | + foreach ($this->addons as $addon) { |
|
| 1457 | + $addons[$addon->name()] = $addon; |
|
| 1458 | + } |
|
| 1459 | + return $addons; |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + |
|
| 1463 | + /** |
|
| 1464 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1465 | + * a stale copy of it around |
|
| 1466 | + * |
|
| 1467 | + * @param string $model_name |
|
| 1468 | + * @return \EEM_Base |
|
| 1469 | + * @throws \EE_Error |
|
| 1470 | + */ |
|
| 1471 | + public function reset_model($model_name) |
|
| 1472 | + { |
|
| 1473 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1474 | + ? "EEM_{$model_name}" |
|
| 1475 | + : $model_name; |
|
| 1476 | + if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1477 | + return null; |
|
| 1478 | + } |
|
| 1479 | + //get that model reset it and make sure we nuke the old reference to it |
|
| 1480 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1481 | + && is_callable( |
|
| 1482 | + array($model_class_name, 'reset') |
|
| 1483 | + )) { |
|
| 1484 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1485 | + } else { |
|
| 1486 | + throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1487 | + } |
|
| 1488 | + return $this->LIB->{$model_class_name}; |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + |
|
| 1492 | + |
|
| 1493 | + /** |
|
| 1494 | + * Resets the registry. |
|
| 1495 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1496 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1497 | + * - $_dependency_map |
|
| 1498 | + * - $_class_abbreviations |
|
| 1499 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1500 | + * - $REQ: Still on the same request so no need to change. |
|
| 1501 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1502 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1503 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1504 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1505 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1506 | + * switch or on the restore. |
|
| 1507 | + * - $modules |
|
| 1508 | + * - $shortcodes |
|
| 1509 | + * - $widgets |
|
| 1510 | + * |
|
| 1511 | + * @param boolean $hard [deprecated] |
|
| 1512 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1513 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1514 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1515 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1516 | + * client |
|
| 1517 | + * code instead can just change the model context to a different blog id if |
|
| 1518 | + * necessary |
|
| 1519 | + * @return EE_Registry |
|
| 1520 | + * @throws EE_Error |
|
| 1521 | + * @throws ReflectionException |
|
| 1522 | + */ |
|
| 1523 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1524 | + { |
|
| 1525 | + $instance = self::instance(); |
|
| 1526 | + $instance->_cache_on = true; |
|
| 1527 | + // reset some "special" classes |
|
| 1528 | + EEH_Activation::reset(); |
|
| 1529 | + $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1530 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1531 | + $instance->CART = null; |
|
| 1532 | + $instance->MRM = null; |
|
| 1533 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1534 | + //messages reset |
|
| 1535 | + EED_Messages::reset(); |
|
| 1536 | + //handle of objects cached on LIB |
|
| 1537 | + foreach (array('LIB', 'modules') as $cache) { |
|
| 1538 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1539 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1540 | + unset($instance->{$cache}->{$class_name}); |
|
| 1541 | + } |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + return $instance; |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + |
|
| 1548 | + |
|
| 1549 | + /** |
|
| 1550 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1551 | + * if passed object implements InterminableInterface, then return false, |
|
| 1552 | + * to indicate that it should NOT be cleared from the Registry cache |
|
| 1553 | + * |
|
| 1554 | + * @param $object |
|
| 1555 | + * @param bool $reset_models |
|
| 1556 | + * @return bool returns true if cached object should be unset |
|
| 1557 | + */ |
|
| 1558 | + private static function _reset_and_unset_object($object, $reset_models) |
|
| 1559 | + { |
|
| 1560 | + if (! is_object($object)) { |
|
| 1561 | + // don't unset anything that's not an object |
|
| 1562 | + return false; |
|
| 1563 | + } |
|
| 1564 | + if ($object instanceof EED_Module) { |
|
| 1565 | + $object::reset(); |
|
| 1566 | + // don't unset modules |
|
| 1567 | + return false; |
|
| 1568 | + } |
|
| 1569 | + if ($object instanceof ResettableInterface) { |
|
| 1570 | + if ($object instanceof EEM_Base) { |
|
| 1571 | + if ($reset_models) { |
|
| 1572 | + $object->reset(); |
|
| 1573 | + return true; |
|
| 1574 | + } |
|
| 1575 | + return false; |
|
| 1576 | + } |
|
| 1577 | + $object->reset(); |
|
| 1578 | + return true; |
|
| 1579 | + } |
|
| 1580 | + if (! $object instanceof InterminableInterface) { |
|
| 1581 | + return true; |
|
| 1582 | + } |
|
| 1583 | + return false; |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * Gets all the custom post type models defined |
|
| 1590 | + * |
|
| 1591 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1592 | + */ |
|
| 1593 | + public function cpt_models() |
|
| 1594 | + { |
|
| 1595 | + $cpt_models = array(); |
|
| 1596 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1597 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1598 | + $cpt_models[$short_name] = $classname; |
|
| 1599 | + } |
|
| 1600 | + } |
|
| 1601 | + return $cpt_models; |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + |
|
| 1605 | + |
|
| 1606 | + /** |
|
| 1607 | + * @return \EE_Config |
|
| 1608 | + */ |
|
| 1609 | + public static function CFG() |
|
| 1610 | + { |
|
| 1611 | + return self::instance()->CFG; |
|
| 1612 | + } |
|
| 1613 | 1613 | |
| 1614 | 1614 | |
| 1615 | 1615 | } |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | /** |
| 543 | 543 | * @initiate session |
| 544 | 544 | * @access private |
| 545 | - * @return TRUE on success, FALSE on fail |
|
| 545 | + * @return boolean on success, FALSE on fail |
|
| 546 | 546 | * @throws EE_Error |
| 547 | 547 | * @throws InvalidArgumentException |
| 548 | 548 | * @throws InvalidDataTypeException |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | * @update session data prior to saving to the db |
| 779 | 779 | * @access public |
| 780 | 780 | * @param bool $new_session |
| 781 | - * @return TRUE on success, FALSE on fail |
|
| 781 | + * @return boolean on success, FALSE on fail |
|
| 782 | 782 | * @throws EE_Error |
| 783 | 783 | * @throws InvalidArgumentException |
| 784 | 784 | * @throws InvalidDataTypeException |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | * _save_session_to_db |
| 880 | 880 | * |
| 881 | 881 | * @param bool $clear_session |
| 882 | - * @return string |
|
| 882 | + * @return boolean |
|
| 883 | 883 | * @throws EE_Error |
| 884 | 884 | * @throws InvalidArgumentException |
| 885 | 885 | * @throws InvalidDataTypeException |
@@ -22,1213 +22,1213 @@ discard block |
||
| 22 | 22 | class EE_Session implements SessionIdentifierInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - const session_id_prefix = 'ee_ssn_'; |
|
| 26 | - |
|
| 27 | - const hash_check_prefix = 'ee_shc_'; |
|
| 28 | - |
|
| 29 | - const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
| 30 | - |
|
| 31 | - const STATUS_CLOSED = 0; |
|
| 32 | - |
|
| 33 | - const STATUS_OPEN = 1; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * instance of the EE_Session object |
|
| 37 | - * |
|
| 38 | - * @var EE_Session |
|
| 39 | - */ |
|
| 40 | - private static $_instance; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var CacheStorageInterface $cache_storage |
|
| 44 | - */ |
|
| 45 | - protected $cache_storage; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * EE_Encryption object |
|
| 49 | - * |
|
| 50 | - * @var EE_Encryption |
|
| 51 | - */ |
|
| 52 | - protected $encryption; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * the session id |
|
| 56 | - * |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - private $_sid; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * session id salt |
|
| 63 | - * |
|
| 64 | - * @var string |
|
| 65 | - */ |
|
| 66 | - private $_sid_salt; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * session data |
|
| 70 | - * |
|
| 71 | - * @var array |
|
| 72 | - */ |
|
| 73 | - private $_session_data = array(); |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * how long an EE session lasts |
|
| 77 | - * default session lifespan of 1 hour (for not so instant IPNs) |
|
| 78 | - * |
|
| 79 | - * @var SessionLifespan $session_lifespan |
|
| 80 | - */ |
|
| 81 | - private $session_lifespan; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * session expiration time as Unix timestamp in GMT |
|
| 85 | - * |
|
| 86 | - * @var int |
|
| 87 | - */ |
|
| 88 | - private $_expiration; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * whether or not session has expired at some point |
|
| 92 | - * |
|
| 93 | - * @var boolean |
|
| 94 | - */ |
|
| 95 | - private $_expired = false; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * current time as Unix timestamp in GMT |
|
| 99 | - * |
|
| 100 | - * @var int |
|
| 101 | - */ |
|
| 102 | - private $_time; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * whether to encrypt session data |
|
| 106 | - * |
|
| 107 | - * @var bool |
|
| 108 | - */ |
|
| 109 | - private $_use_encryption; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * well... according to the server... |
|
| 113 | - * |
|
| 114 | - * @var null |
|
| 115 | - */ |
|
| 116 | - private $_user_agent; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * do you really trust the server ? |
|
| 120 | - * |
|
| 121 | - * @var null |
|
| 122 | - */ |
|
| 123 | - private $_ip_address; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * current WP user_id |
|
| 127 | - * |
|
| 128 | - * @var null |
|
| 129 | - */ |
|
| 130 | - private $_wp_user_id; |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * array for defining default session vars |
|
| 134 | - * |
|
| 135 | - * @var array |
|
| 136 | - */ |
|
| 137 | - private $_default_session_vars = array( |
|
| 138 | - 'id' => null, |
|
| 139 | - 'user_id' => null, |
|
| 140 | - 'ip_address' => null, |
|
| 141 | - 'user_agent' => null, |
|
| 142 | - 'init_access' => null, |
|
| 143 | - 'last_access' => null, |
|
| 144 | - 'expiration' => null, |
|
| 145 | - 'pages_visited' => array(), |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * timestamp for when last garbage collection cycle was performed |
|
| 150 | - * |
|
| 151 | - * @var int $_last_gc |
|
| 152 | - */ |
|
| 153 | - private $_last_gc; |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @var RequestInterface $request |
|
| 157 | - */ |
|
| 158 | - protected $request; |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * whether session is active or not |
|
| 162 | - * |
|
| 163 | - * @var int $status |
|
| 164 | - */ |
|
| 165 | - private $status = EE_Session::STATUS_CLOSED; |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @singleton method used to instantiate class object |
|
| 171 | - * @param CacheStorageInterface $cache_storage |
|
| 172 | - * @param SessionLifespan|null $lifespan |
|
| 173 | - * @param RequestInterface $request |
|
| 174 | - * @param EE_Encryption $encryption |
|
| 175 | - * @return EE_Session |
|
| 176 | - * @throws InvalidArgumentException |
|
| 177 | - * @throws InvalidDataTypeException |
|
| 178 | - * @throws InvalidInterfaceException |
|
| 179 | - */ |
|
| 180 | - public static function instance( |
|
| 181 | - CacheStorageInterface $cache_storage = null, |
|
| 182 | - SessionLifespan $lifespan = null, |
|
| 183 | - RequestInterface $request = null, |
|
| 184 | - EE_Encryption $encryption = null |
|
| 185 | - ) { |
|
| 186 | - // check if class object is instantiated |
|
| 187 | - // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
| 188 | - // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 189 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 190 | - self::$_instance = new self( |
|
| 191 | - $cache_storage, |
|
| 192 | - $lifespan, |
|
| 193 | - $request, |
|
| 194 | - $encryption |
|
| 195 | - ); |
|
| 196 | - } |
|
| 197 | - return self::$_instance; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * protected constructor to prevent direct creation |
|
| 203 | - * |
|
| 204 | - * @param CacheStorageInterface $cache_storage |
|
| 205 | - * @param SessionLifespan $lifespan |
|
| 206 | - * @param RequestInterface $request |
|
| 207 | - * @param EE_Encryption $encryption |
|
| 208 | - * @throws InvalidArgumentException |
|
| 209 | - * @throws InvalidDataTypeException |
|
| 210 | - * @throws InvalidInterfaceException |
|
| 211 | - */ |
|
| 212 | - protected function __construct( |
|
| 213 | - CacheStorageInterface $cache_storage, |
|
| 214 | - SessionLifespan $lifespan, |
|
| 215 | - RequestInterface $request, |
|
| 216 | - EE_Encryption $encryption = null |
|
| 217 | - ) { |
|
| 218 | - // session loading is turned ON by default, |
|
| 219 | - // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
| 220 | - // (which currently fires on the init hook at priority 9), |
|
| 221 | - // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 222 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 223 | - return; |
|
| 224 | - } |
|
| 225 | - $this->session_lifespan = $lifespan; |
|
| 226 | - $this->request = $request; |
|
| 227 | - if (! defined('ESPRESSO_SESSION')) { |
|
| 228 | - define('ESPRESSO_SESSION', true); |
|
| 229 | - } |
|
| 230 | - // retrieve session options from db |
|
| 231 | - $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 232 | - if (! empty($session_settings)) { |
|
| 233 | - // cycle though existing session options |
|
| 234 | - foreach ($session_settings as $var_name => $session_setting) { |
|
| 235 | - // set values for class properties |
|
| 236 | - $var_name = '_' . $var_name; |
|
| 237 | - $this->{$var_name} = $session_setting; |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - $this->cache_storage = $cache_storage; |
|
| 241 | - // are we using encryption? |
|
| 242 | - $this->_use_encryption = $encryption instanceof EE_Encryption |
|
| 243 | - && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
| 244 | - // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__); |
|
| 245 | - // encrypt data via: $this->encryption->encrypt(); |
|
| 246 | - $this->encryption = $encryption; |
|
| 247 | - // filter hook allows outside functions/classes/plugins to change default empty cart |
|
| 248 | - $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
| 249 | - array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
| 250 | - // apply default session vars |
|
| 251 | - $this->_set_defaults(); |
|
| 252 | - add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
| 253 | - // check request for 'clear_session' param |
|
| 254 | - add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
| 255 | - // once everything is all said and done, |
|
| 256 | - add_action('shutdown', array($this, 'update'), 100); |
|
| 257 | - add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
| 258 | - $this->configure_garbage_collection_filters(); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @return bool |
|
| 264 | - * @throws InvalidArgumentException |
|
| 265 | - * @throws InvalidDataTypeException |
|
| 266 | - * @throws InvalidInterfaceException |
|
| 267 | - */ |
|
| 268 | - public static function isLoadedAndActive() |
|
| 269 | - { |
|
| 270 | - return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
| 271 | - && EE_Session::instance() instanceof EE_Session |
|
| 272 | - && EE_Session::instance()->isActive(); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @return bool |
|
| 278 | - */ |
|
| 279 | - public function isActive() |
|
| 280 | - { |
|
| 281 | - return $this->status === EE_Session::STATUS_OPEN; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @return void |
|
| 288 | - * @throws EE_Error |
|
| 289 | - * @throws InvalidArgumentException |
|
| 290 | - * @throws InvalidDataTypeException |
|
| 291 | - * @throws InvalidInterfaceException |
|
| 292 | - * @throws InvalidSessionDataException |
|
| 293 | - */ |
|
| 294 | - public function open_session() |
|
| 295 | - { |
|
| 296 | - // check for existing session and retrieve it from db |
|
| 297 | - if (! $this->_espresso_session()) { |
|
| 298 | - // or just start a new one |
|
| 299 | - $this->_create_espresso_session(); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @return bool |
|
| 307 | - */ |
|
| 308 | - public function expired() |
|
| 309 | - { |
|
| 310 | - return $this->_expired; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * @return void |
|
| 317 | - */ |
|
| 318 | - public function reset_expired() |
|
| 319 | - { |
|
| 320 | - $this->_expired = false; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * @return int |
|
| 326 | - */ |
|
| 327 | - public function expiration() |
|
| 328 | - { |
|
| 329 | - return $this->_expiration; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * @return int |
|
| 336 | - */ |
|
| 337 | - public function extension() |
|
| 338 | - { |
|
| 339 | - return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * @param int $time number of seconds to add to session expiration |
|
| 346 | - */ |
|
| 347 | - public function extend_expiration($time = 0) |
|
| 348 | - { |
|
| 349 | - $time = $time ? $time : $this->extension(); |
|
| 350 | - $this->_expiration += absint($time); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * @return int |
|
| 357 | - */ |
|
| 358 | - public function lifespan() |
|
| 359 | - { |
|
| 360 | - return $this->session_lifespan->inSeconds(); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * This just sets some defaults for the _session data property |
|
| 367 | - * |
|
| 368 | - * @access private |
|
| 369 | - * @return void |
|
| 370 | - */ |
|
| 371 | - private function _set_defaults() |
|
| 372 | - { |
|
| 373 | - // set some defaults |
|
| 374 | - foreach ($this->_default_session_vars as $key => $default_var) { |
|
| 375 | - if (is_array($default_var)) { |
|
| 376 | - $this->_session_data[ $key ] = array(); |
|
| 377 | - } else { |
|
| 378 | - $this->_session_data[ $key ] = ''; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - } |
|
| 25 | + const session_id_prefix = 'ee_ssn_'; |
|
| 26 | + |
|
| 27 | + const hash_check_prefix = 'ee_shc_'; |
|
| 28 | + |
|
| 29 | + const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
| 30 | + |
|
| 31 | + const STATUS_CLOSED = 0; |
|
| 32 | + |
|
| 33 | + const STATUS_OPEN = 1; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * instance of the EE_Session object |
|
| 37 | + * |
|
| 38 | + * @var EE_Session |
|
| 39 | + */ |
|
| 40 | + private static $_instance; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var CacheStorageInterface $cache_storage |
|
| 44 | + */ |
|
| 45 | + protected $cache_storage; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * EE_Encryption object |
|
| 49 | + * |
|
| 50 | + * @var EE_Encryption |
|
| 51 | + */ |
|
| 52 | + protected $encryption; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * the session id |
|
| 56 | + * |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + private $_sid; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * session id salt |
|
| 63 | + * |
|
| 64 | + * @var string |
|
| 65 | + */ |
|
| 66 | + private $_sid_salt; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * session data |
|
| 70 | + * |
|
| 71 | + * @var array |
|
| 72 | + */ |
|
| 73 | + private $_session_data = array(); |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * how long an EE session lasts |
|
| 77 | + * default session lifespan of 1 hour (for not so instant IPNs) |
|
| 78 | + * |
|
| 79 | + * @var SessionLifespan $session_lifespan |
|
| 80 | + */ |
|
| 81 | + private $session_lifespan; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * session expiration time as Unix timestamp in GMT |
|
| 85 | + * |
|
| 86 | + * @var int |
|
| 87 | + */ |
|
| 88 | + private $_expiration; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * whether or not session has expired at some point |
|
| 92 | + * |
|
| 93 | + * @var boolean |
|
| 94 | + */ |
|
| 95 | + private $_expired = false; |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * current time as Unix timestamp in GMT |
|
| 99 | + * |
|
| 100 | + * @var int |
|
| 101 | + */ |
|
| 102 | + private $_time; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * whether to encrypt session data |
|
| 106 | + * |
|
| 107 | + * @var bool |
|
| 108 | + */ |
|
| 109 | + private $_use_encryption; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * well... according to the server... |
|
| 113 | + * |
|
| 114 | + * @var null |
|
| 115 | + */ |
|
| 116 | + private $_user_agent; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * do you really trust the server ? |
|
| 120 | + * |
|
| 121 | + * @var null |
|
| 122 | + */ |
|
| 123 | + private $_ip_address; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * current WP user_id |
|
| 127 | + * |
|
| 128 | + * @var null |
|
| 129 | + */ |
|
| 130 | + private $_wp_user_id; |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * array for defining default session vars |
|
| 134 | + * |
|
| 135 | + * @var array |
|
| 136 | + */ |
|
| 137 | + private $_default_session_vars = array( |
|
| 138 | + 'id' => null, |
|
| 139 | + 'user_id' => null, |
|
| 140 | + 'ip_address' => null, |
|
| 141 | + 'user_agent' => null, |
|
| 142 | + 'init_access' => null, |
|
| 143 | + 'last_access' => null, |
|
| 144 | + 'expiration' => null, |
|
| 145 | + 'pages_visited' => array(), |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * timestamp for when last garbage collection cycle was performed |
|
| 150 | + * |
|
| 151 | + * @var int $_last_gc |
|
| 152 | + */ |
|
| 153 | + private $_last_gc; |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @var RequestInterface $request |
|
| 157 | + */ |
|
| 158 | + protected $request; |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * whether session is active or not |
|
| 162 | + * |
|
| 163 | + * @var int $status |
|
| 164 | + */ |
|
| 165 | + private $status = EE_Session::STATUS_CLOSED; |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @singleton method used to instantiate class object |
|
| 171 | + * @param CacheStorageInterface $cache_storage |
|
| 172 | + * @param SessionLifespan|null $lifespan |
|
| 173 | + * @param RequestInterface $request |
|
| 174 | + * @param EE_Encryption $encryption |
|
| 175 | + * @return EE_Session |
|
| 176 | + * @throws InvalidArgumentException |
|
| 177 | + * @throws InvalidDataTypeException |
|
| 178 | + * @throws InvalidInterfaceException |
|
| 179 | + */ |
|
| 180 | + public static function instance( |
|
| 181 | + CacheStorageInterface $cache_storage = null, |
|
| 182 | + SessionLifespan $lifespan = null, |
|
| 183 | + RequestInterface $request = null, |
|
| 184 | + EE_Encryption $encryption = null |
|
| 185 | + ) { |
|
| 186 | + // check if class object is instantiated |
|
| 187 | + // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
| 188 | + // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 189 | + if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 190 | + self::$_instance = new self( |
|
| 191 | + $cache_storage, |
|
| 192 | + $lifespan, |
|
| 193 | + $request, |
|
| 194 | + $encryption |
|
| 195 | + ); |
|
| 196 | + } |
|
| 197 | + return self::$_instance; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * protected constructor to prevent direct creation |
|
| 203 | + * |
|
| 204 | + * @param CacheStorageInterface $cache_storage |
|
| 205 | + * @param SessionLifespan $lifespan |
|
| 206 | + * @param RequestInterface $request |
|
| 207 | + * @param EE_Encryption $encryption |
|
| 208 | + * @throws InvalidArgumentException |
|
| 209 | + * @throws InvalidDataTypeException |
|
| 210 | + * @throws InvalidInterfaceException |
|
| 211 | + */ |
|
| 212 | + protected function __construct( |
|
| 213 | + CacheStorageInterface $cache_storage, |
|
| 214 | + SessionLifespan $lifespan, |
|
| 215 | + RequestInterface $request, |
|
| 216 | + EE_Encryption $encryption = null |
|
| 217 | + ) { |
|
| 218 | + // session loading is turned ON by default, |
|
| 219 | + // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
| 220 | + // (which currently fires on the init hook at priority 9), |
|
| 221 | + // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 222 | + if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 223 | + return; |
|
| 224 | + } |
|
| 225 | + $this->session_lifespan = $lifespan; |
|
| 226 | + $this->request = $request; |
|
| 227 | + if (! defined('ESPRESSO_SESSION')) { |
|
| 228 | + define('ESPRESSO_SESSION', true); |
|
| 229 | + } |
|
| 230 | + // retrieve session options from db |
|
| 231 | + $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 232 | + if (! empty($session_settings)) { |
|
| 233 | + // cycle though existing session options |
|
| 234 | + foreach ($session_settings as $var_name => $session_setting) { |
|
| 235 | + // set values for class properties |
|
| 236 | + $var_name = '_' . $var_name; |
|
| 237 | + $this->{$var_name} = $session_setting; |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + $this->cache_storage = $cache_storage; |
|
| 241 | + // are we using encryption? |
|
| 242 | + $this->_use_encryption = $encryption instanceof EE_Encryption |
|
| 243 | + && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
| 244 | + // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__); |
|
| 245 | + // encrypt data via: $this->encryption->encrypt(); |
|
| 246 | + $this->encryption = $encryption; |
|
| 247 | + // filter hook allows outside functions/classes/plugins to change default empty cart |
|
| 248 | + $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
| 249 | + array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
| 250 | + // apply default session vars |
|
| 251 | + $this->_set_defaults(); |
|
| 252 | + add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
| 253 | + // check request for 'clear_session' param |
|
| 254 | + add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
| 255 | + // once everything is all said and done, |
|
| 256 | + add_action('shutdown', array($this, 'update'), 100); |
|
| 257 | + add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
| 258 | + $this->configure_garbage_collection_filters(); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @return bool |
|
| 264 | + * @throws InvalidArgumentException |
|
| 265 | + * @throws InvalidDataTypeException |
|
| 266 | + * @throws InvalidInterfaceException |
|
| 267 | + */ |
|
| 268 | + public static function isLoadedAndActive() |
|
| 269 | + { |
|
| 270 | + return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
| 271 | + && EE_Session::instance() instanceof EE_Session |
|
| 272 | + && EE_Session::instance()->isActive(); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @return bool |
|
| 278 | + */ |
|
| 279 | + public function isActive() |
|
| 280 | + { |
|
| 281 | + return $this->status === EE_Session::STATUS_OPEN; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @return void |
|
| 288 | + * @throws EE_Error |
|
| 289 | + * @throws InvalidArgumentException |
|
| 290 | + * @throws InvalidDataTypeException |
|
| 291 | + * @throws InvalidInterfaceException |
|
| 292 | + * @throws InvalidSessionDataException |
|
| 293 | + */ |
|
| 294 | + public function open_session() |
|
| 295 | + { |
|
| 296 | + // check for existing session and retrieve it from db |
|
| 297 | + if (! $this->_espresso_session()) { |
|
| 298 | + // or just start a new one |
|
| 299 | + $this->_create_espresso_session(); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @return bool |
|
| 307 | + */ |
|
| 308 | + public function expired() |
|
| 309 | + { |
|
| 310 | + return $this->_expired; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * @return void |
|
| 317 | + */ |
|
| 318 | + public function reset_expired() |
|
| 319 | + { |
|
| 320 | + $this->_expired = false; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * @return int |
|
| 326 | + */ |
|
| 327 | + public function expiration() |
|
| 328 | + { |
|
| 329 | + return $this->_expiration; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * @return int |
|
| 336 | + */ |
|
| 337 | + public function extension() |
|
| 338 | + { |
|
| 339 | + return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * @param int $time number of seconds to add to session expiration |
|
| 346 | + */ |
|
| 347 | + public function extend_expiration($time = 0) |
|
| 348 | + { |
|
| 349 | + $time = $time ? $time : $this->extension(); |
|
| 350 | + $this->_expiration += absint($time); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * @return int |
|
| 357 | + */ |
|
| 358 | + public function lifespan() |
|
| 359 | + { |
|
| 360 | + return $this->session_lifespan->inSeconds(); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * This just sets some defaults for the _session data property |
|
| 367 | + * |
|
| 368 | + * @access private |
|
| 369 | + * @return void |
|
| 370 | + */ |
|
| 371 | + private function _set_defaults() |
|
| 372 | + { |
|
| 373 | + // set some defaults |
|
| 374 | + foreach ($this->_default_session_vars as $key => $default_var) { |
|
| 375 | + if (is_array($default_var)) { |
|
| 376 | + $this->_session_data[ $key ] = array(); |
|
| 377 | + } else { |
|
| 378 | + $this->_session_data[ $key ] = ''; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | 383 | |
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * @retrieve session data |
|
| 387 | - * @access public |
|
| 388 | - * @return string |
|
| 389 | - */ |
|
| 390 | - public function id() |
|
| 391 | - { |
|
| 392 | - return $this->_sid; |
|
| 393 | - } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * @retrieve session data |
|
| 387 | + * @access public |
|
| 388 | + * @return string |
|
| 389 | + */ |
|
| 390 | + public function id() |
|
| 391 | + { |
|
| 392 | + return $this->_sid; |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | 395 | |
| 396 | 396 | |
| 397 | - /** |
|
| 398 | - * @param \EE_Cart $cart |
|
| 399 | - * @return bool |
|
| 400 | - */ |
|
| 401 | - public function set_cart(EE_Cart $cart) |
|
| 402 | - { |
|
| 403 | - $this->_session_data['cart'] = $cart; |
|
| 404 | - return true; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * reset_cart |
|
| 411 | - */ |
|
| 412 | - public function reset_cart() |
|
| 413 | - { |
|
| 414 | - do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
| 415 | - $this->_session_data['cart'] = null; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * @return \EE_Cart |
|
| 422 | - */ |
|
| 423 | - public function cart() |
|
| 424 | - { |
|
| 425 | - return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
| 426 | - ? $this->_session_data['cart'] |
|
| 427 | - : null; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * @param \EE_Checkout $checkout |
|
| 434 | - * @return bool |
|
| 435 | - */ |
|
| 436 | - public function set_checkout(EE_Checkout $checkout) |
|
| 437 | - { |
|
| 438 | - $this->_session_data['checkout'] = $checkout; |
|
| 439 | - return true; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * reset_checkout |
|
| 446 | - */ |
|
| 447 | - public function reset_checkout() |
|
| 448 | - { |
|
| 449 | - do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
| 450 | - $this->_session_data['checkout'] = null; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * @return \EE_Checkout |
|
| 457 | - */ |
|
| 458 | - public function checkout() |
|
| 459 | - { |
|
| 460 | - return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
| 461 | - ? $this->_session_data['checkout'] |
|
| 462 | - : null; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * @param \EE_Transaction $transaction |
|
| 469 | - * @return bool |
|
| 470 | - * @throws EE_Error |
|
| 471 | - */ |
|
| 472 | - public function set_transaction(EE_Transaction $transaction) |
|
| 473 | - { |
|
| 474 | - // first remove the session from the transaction before we save the transaction in the session |
|
| 475 | - $transaction->set_txn_session_data(null); |
|
| 476 | - $this->_session_data['transaction'] = $transaction; |
|
| 477 | - return true; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * reset_transaction |
|
| 484 | - */ |
|
| 485 | - public function reset_transaction() |
|
| 486 | - { |
|
| 487 | - do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
| 488 | - $this->_session_data['transaction'] = null; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * @return \EE_Transaction |
|
| 495 | - */ |
|
| 496 | - public function transaction() |
|
| 497 | - { |
|
| 498 | - return isset($this->_session_data['transaction']) |
|
| 499 | - && $this->_session_data['transaction'] instanceof EE_Transaction |
|
| 500 | - ? $this->_session_data['transaction'] |
|
| 501 | - : null; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * retrieve session data |
|
| 507 | - * |
|
| 508 | - * @param null $key |
|
| 509 | - * @param bool $reset_cache |
|
| 510 | - * @return array |
|
| 511 | - */ |
|
| 512 | - public function get_session_data($key = null, $reset_cache = false) |
|
| 513 | - { |
|
| 514 | - if ($reset_cache) { |
|
| 515 | - $this->reset_cart(); |
|
| 516 | - $this->reset_checkout(); |
|
| 517 | - $this->reset_transaction(); |
|
| 518 | - } |
|
| 519 | - if (! empty($key)) { |
|
| 520 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
| 521 | - } |
|
| 522 | - return $this->_session_data; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Returns TRUE on success, FALSE on fail |
|
| 528 | - * |
|
| 529 | - * @param array $data |
|
| 530 | - * @return bool |
|
| 531 | - */ |
|
| 532 | - public function set_session_data($data) |
|
| 533 | - { |
|
| 534 | - |
|
| 535 | - // nothing ??? bad data ??? go home! |
|
| 536 | - if (empty($data) || ! is_array($data)) { |
|
| 537 | - EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, |
|
| 538 | - __FUNCTION__, __LINE__); |
|
| 539 | - return false; |
|
| 540 | - } |
|
| 541 | - foreach ($data as $key => $value) { |
|
| 542 | - if (isset($this->_default_session_vars[ $key ])) { |
|
| 543 | - EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
| 544 | - 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__); |
|
| 545 | - return false; |
|
| 546 | - } |
|
| 547 | - $this->_session_data[ $key ] = $value; |
|
| 548 | - } |
|
| 549 | - return true; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * @initiate session |
|
| 556 | - * @access private |
|
| 557 | - * @return TRUE on success, FALSE on fail |
|
| 558 | - * @throws EE_Error |
|
| 559 | - * @throws InvalidArgumentException |
|
| 560 | - * @throws InvalidDataTypeException |
|
| 561 | - * @throws InvalidInterfaceException |
|
| 562 | - * @throws InvalidSessionDataException |
|
| 563 | - */ |
|
| 564 | - private function _espresso_session() |
|
| 565 | - { |
|
| 566 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 567 | - // check that session has started |
|
| 568 | - if (session_id() === '') { |
|
| 569 | - //starts a new session if one doesn't already exist, or re-initiates an existing one |
|
| 570 | - session_start(); |
|
| 571 | - } |
|
| 572 | - $this->status = EE_Session::STATUS_OPEN; |
|
| 573 | - // get our modified session ID |
|
| 574 | - $this->_sid = $this->_generate_session_id(); |
|
| 575 | - // and the visitors IP |
|
| 576 | - $this->_ip_address = $this->request->ipAddress(); |
|
| 577 | - // set the "user agent" |
|
| 578 | - $this->_user_agent = $this->request->userAgent(); |
|
| 579 | - // now let's retrieve what's in the db |
|
| 580 | - $session_data = $this->_retrieve_session_data(); |
|
| 581 | - if (! empty($session_data)) { |
|
| 582 | - // get the current time in UTC |
|
| 583 | - $this->_time = $this->_time !== null ? $this->_time : time(); |
|
| 584 | - // and reset the session expiration |
|
| 585 | - $this->_expiration = isset($session_data['expiration']) |
|
| 586 | - ? $session_data['expiration'] |
|
| 587 | - : $this->_time + $this->session_lifespan->inSeconds(); |
|
| 588 | - } else { |
|
| 589 | - // set initial site access time and the session expiration |
|
| 590 | - $this->_set_init_access_and_expiration(); |
|
| 591 | - // set referer |
|
| 592 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
| 593 | - ? esc_attr($_SERVER['HTTP_REFERER']) |
|
| 594 | - : ''; |
|
| 595 | - // no previous session = go back and create one (on top of the data above) |
|
| 596 | - return false; |
|
| 597 | - } |
|
| 598 | - // now the user agent |
|
| 599 | - if ($session_data['user_agent'] !== $this->_user_agent) { |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - // wait a minute... how old are you? |
|
| 603 | - if ($this->_time > $this->_expiration) { |
|
| 604 | - // yer too old fer me! |
|
| 605 | - $this->_expired = true; |
|
| 606 | - // wipe out everything that isn't a default session datum |
|
| 607 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 608 | - } |
|
| 609 | - // make event espresso session data available to plugin |
|
| 610 | - $this->_session_data = array_merge($this->_session_data, $session_data); |
|
| 611 | - return true; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * _get_session_data |
|
| 618 | - * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
| 619 | - * databases |
|
| 620 | - * |
|
| 621 | - * @return array |
|
| 622 | - * @throws EE_Error |
|
| 623 | - * @throws InvalidArgumentException |
|
| 624 | - * @throws InvalidSessionDataException |
|
| 625 | - * @throws InvalidDataTypeException |
|
| 626 | - * @throws InvalidInterfaceException |
|
| 627 | - */ |
|
| 628 | - protected function _retrieve_session_data() |
|
| 629 | - { |
|
| 630 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 631 | - try { |
|
| 632 | - // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
| 633 | - $session_data = $this->cache_storage->get($ssn_key, false); |
|
| 634 | - if (empty($session_data)) { |
|
| 635 | - return array(); |
|
| 636 | - } |
|
| 637 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 638 | - $hash_check = $this->cache_storage->get( |
|
| 639 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 640 | - false |
|
| 641 | - ); |
|
| 642 | - if ($hash_check && $hash_check !== md5($session_data)) { |
|
| 643 | - EE_Error::add_error( |
|
| 644 | - sprintf( |
|
| 645 | - __( |
|
| 646 | - 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
| 647 | - 'event_espresso' |
|
| 648 | - ), |
|
| 649 | - EE_Session::session_id_prefix . $this->_sid |
|
| 650 | - ), |
|
| 651 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 652 | - ); |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - } catch (Exception $e) { |
|
| 656 | - // let's just eat that error for now and attempt to correct any corrupted data |
|
| 657 | - global $wpdb; |
|
| 658 | - $row = $wpdb->get_row( |
|
| 659 | - $wpdb->prepare( |
|
| 660 | - "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
| 661 | - '_transient_' . $ssn_key |
|
| 662 | - ) |
|
| 663 | - ); |
|
| 664 | - $session_data = is_object($row) ? $row->option_value : null; |
|
| 665 | - if ($session_data) { |
|
| 666 | - $session_data = preg_replace_callback( |
|
| 667 | - '!s:(d+):"(.*?)";!', |
|
| 668 | - function ($match) |
|
| 669 | - { |
|
| 670 | - return $match[1] === strlen($match[2]) |
|
| 671 | - ? $match[0] |
|
| 672 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 673 | - }, |
|
| 674 | - $session_data |
|
| 675 | - ); |
|
| 676 | - } |
|
| 677 | - $session_data = maybe_unserialize($session_data); |
|
| 678 | - } |
|
| 679 | - // in case the data is encoded... try to decode it |
|
| 680 | - $session_data = $this->encryption instanceof EE_Encryption |
|
| 681 | - ? $this->encryption->base64_string_decode($session_data) |
|
| 682 | - : $session_data; |
|
| 683 | - if (! is_array($session_data)) { |
|
| 684 | - try { |
|
| 685 | - $session_data = maybe_unserialize($session_data); |
|
| 686 | - } catch (Exception $e) { |
|
| 687 | - $msg = esc_html__( |
|
| 688 | - 'An error occurred while attempting to unserialize the session data.', |
|
| 689 | - 'event_espresso' |
|
| 690 | - ); |
|
| 691 | - $msg .= WP_DEBUG |
|
| 692 | - ? '<br><pre>' |
|
| 693 | - . print_r($session_data, true) |
|
| 694 | - . '</pre><br>' |
|
| 695 | - . $this->find_serialize_error($session_data) |
|
| 696 | - : ''; |
|
| 697 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 698 | - throw new InvalidSessionDataException($msg, 0, $e); |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - // just a check to make sure the session array is indeed an array |
|
| 702 | - if (! is_array($session_data)) { |
|
| 703 | - // no?!?! then something is wrong |
|
| 704 | - $msg = esc_html__( |
|
| 705 | - 'The session data is missing, invalid, or corrupted.', |
|
| 706 | - 'event_espresso' |
|
| 707 | - ); |
|
| 708 | - $msg .= WP_DEBUG |
|
| 709 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 710 | - : ''; |
|
| 711 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 712 | - throw new InvalidSessionDataException($msg); |
|
| 713 | - } |
|
| 714 | - if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
| 715 | - $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
| 716 | - $session_data['transaction'] |
|
| 717 | - ); |
|
| 718 | - } |
|
| 719 | - return $session_data; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * _generate_session_id |
|
| 726 | - * Retrieves the PHP session id either directly from the PHP session, |
|
| 727 | - * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
| 728 | - * The session id is then salted and hashed (mmm sounds tasty) |
|
| 729 | - * so that it can be safely used as a $_REQUEST param |
|
| 730 | - * |
|
| 731 | - * @return string |
|
| 732 | - */ |
|
| 733 | - protected function _generate_session_id() |
|
| 734 | - { |
|
| 735 | - // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
| 736 | - if (isset($_REQUEST['EESID'])) { |
|
| 737 | - $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
| 738 | - } else { |
|
| 739 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
| 740 | - } |
|
| 741 | - return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * _get_sid_salt |
|
| 748 | - * |
|
| 749 | - * @return string |
|
| 750 | - */ |
|
| 751 | - protected function _get_sid_salt() |
|
| 752 | - { |
|
| 753 | - // was session id salt already saved to db ? |
|
| 754 | - if (empty($this->_sid_salt)) { |
|
| 755 | - // no? then maybe use WP defined constant |
|
| 756 | - if (defined('AUTH_SALT')) { |
|
| 757 | - $this->_sid_salt = AUTH_SALT; |
|
| 758 | - } |
|
| 759 | - // if salt doesn't exist or is too short |
|
| 760 | - if (strlen($this->_sid_salt) < 32) { |
|
| 761 | - // create a new one |
|
| 762 | - $this->_sid_salt = wp_generate_password(64); |
|
| 763 | - } |
|
| 764 | - // and save it as a permanent session setting |
|
| 765 | - $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
| 766 | - } |
|
| 767 | - return $this->_sid_salt; |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * _set_init_access_and_expiration |
|
| 774 | - * |
|
| 775 | - * @return void |
|
| 776 | - */ |
|
| 777 | - protected function _set_init_access_and_expiration() |
|
| 778 | - { |
|
| 779 | - $this->_time = time(); |
|
| 780 | - $this->_expiration = $this->_time + $this->session_lifespan->inSeconds(); |
|
| 781 | - // set initial site access time |
|
| 782 | - $this->_session_data['init_access'] = $this->_time; |
|
| 783 | - // and the session expiration |
|
| 784 | - $this->_session_data['expiration'] = $this->_expiration; |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * @update session data prior to saving to the db |
|
| 791 | - * @access public |
|
| 792 | - * @param bool $new_session |
|
| 793 | - * @return TRUE on success, FALSE on fail |
|
| 794 | - * @throws EE_Error |
|
| 795 | - * @throws InvalidArgumentException |
|
| 796 | - * @throws InvalidDataTypeException |
|
| 797 | - * @throws InvalidInterfaceException |
|
| 798 | - */ |
|
| 799 | - public function update($new_session = false) |
|
| 800 | - { |
|
| 801 | - $this->_session_data = $this->_session_data !== null |
|
| 802 | - && is_array($this->_session_data) |
|
| 803 | - && isset($this->_session_data['id']) |
|
| 804 | - ? $this->_session_data |
|
| 805 | - : array(); |
|
| 806 | - if (empty($this->_session_data)) { |
|
| 807 | - $this->_set_defaults(); |
|
| 808 | - } |
|
| 809 | - $session_data = array(); |
|
| 810 | - foreach ($this->_session_data as $key => $value) { |
|
| 811 | - |
|
| 812 | - switch ($key) { |
|
| 813 | - |
|
| 814 | - case 'id' : |
|
| 815 | - // session ID |
|
| 816 | - $session_data['id'] = $this->_sid; |
|
| 817 | - break; |
|
| 818 | - case 'ip_address' : |
|
| 819 | - // visitor ip address |
|
| 820 | - $session_data['ip_address'] = $this->request->ipAddress(); |
|
| 821 | - break; |
|
| 822 | - case 'user_agent' : |
|
| 823 | - // visitor user_agent |
|
| 824 | - $session_data['user_agent'] = $this->_user_agent; |
|
| 825 | - break; |
|
| 826 | - case 'init_access' : |
|
| 827 | - $session_data['init_access'] = absint($value); |
|
| 828 | - break; |
|
| 829 | - case 'last_access' : |
|
| 830 | - // current access time |
|
| 831 | - $session_data['last_access'] = $this->_time; |
|
| 832 | - break; |
|
| 833 | - case 'expiration' : |
|
| 834 | - // when the session expires |
|
| 835 | - $session_data['expiration'] = ! empty($this->_expiration) |
|
| 836 | - ? $this->_expiration |
|
| 837 | - : $session_data['init_access'] + $this->session_lifespan->inSeconds(); |
|
| 838 | - break; |
|
| 839 | - case 'user_id' : |
|
| 840 | - // current user if logged in |
|
| 841 | - $session_data['user_id'] = $this->_wp_user_id(); |
|
| 842 | - break; |
|
| 843 | - case 'pages_visited' : |
|
| 844 | - $page_visit = $this->_get_page_visit(); |
|
| 845 | - if ($page_visit) { |
|
| 846 | - // set pages visited where the first will be the http referrer |
|
| 847 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
| 848 | - // we'll only save the last 10 page visits. |
|
| 849 | - $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
| 850 | - } |
|
| 851 | - break; |
|
| 852 | - default : |
|
| 853 | - // carry any other data over |
|
| 854 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - $this->_session_data = $session_data; |
|
| 858 | - // creating a new session does not require saving to the db just yet |
|
| 859 | - if (! $new_session) { |
|
| 860 | - // ready? let's save |
|
| 861 | - if ($this->_save_session_to_db()) { |
|
| 862 | - return true; |
|
| 863 | - } |
|
| 864 | - return false; |
|
| 865 | - } |
|
| 866 | - // meh, why not? |
|
| 867 | - return true; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * @create session data array |
|
| 874 | - * @access public |
|
| 875 | - * @return bool |
|
| 876 | - * @throws EE_Error |
|
| 877 | - * @throws InvalidArgumentException |
|
| 878 | - * @throws InvalidDataTypeException |
|
| 879 | - * @throws InvalidInterfaceException |
|
| 880 | - */ |
|
| 881 | - private function _create_espresso_session() |
|
| 882 | - { |
|
| 883 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
| 884 | - // use the update function for now with $new_session arg set to TRUE |
|
| 885 | - return $this->update(true) ? true : false; |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * _save_session_to_db |
|
| 892 | - * |
|
| 893 | - * @param bool $clear_session |
|
| 894 | - * @return string |
|
| 895 | - * @throws EE_Error |
|
| 896 | - * @throws InvalidArgumentException |
|
| 897 | - * @throws InvalidDataTypeException |
|
| 898 | - * @throws InvalidInterfaceException |
|
| 899 | - */ |
|
| 900 | - private function _save_session_to_db($clear_session = false) |
|
| 901 | - { |
|
| 902 | - // don't save sessions for crawlers |
|
| 903 | - // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
| 904 | - if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 905 | - return false; |
|
| 906 | - } |
|
| 907 | - $transaction = $this->transaction(); |
|
| 908 | - if ($transaction instanceof EE_Transaction) { |
|
| 909 | - if (! $transaction->ID()) { |
|
| 910 | - $transaction->save(); |
|
| 911 | - } |
|
| 912 | - $this->_session_data['transaction'] = $transaction->ID(); |
|
| 913 | - } |
|
| 914 | - // then serialize all of our session data |
|
| 915 | - $session_data = serialize($this->_session_data); |
|
| 916 | - // do we need to also encode it to avoid corrupted data when saved to the db? |
|
| 917 | - $session_data = $this->_use_encryption |
|
| 918 | - ? $this->encryption->base64_string_encode($session_data) |
|
| 919 | - : $session_data; |
|
| 920 | - // maybe save hash check |
|
| 921 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 922 | - $this->cache_storage->add( |
|
| 923 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 924 | - md5($session_data), |
|
| 925 | - $this->session_lifespan->inSeconds() |
|
| 926 | - ); |
|
| 927 | - } |
|
| 928 | - // we're using the Transient API for storing session data, |
|
| 929 | - return $this->cache_storage->add( |
|
| 930 | - EE_Session::session_id_prefix . $this->_sid, |
|
| 931 | - $session_data, |
|
| 932 | - $this->session_lifespan->inSeconds() |
|
| 933 | - ); |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - |
|
| 937 | - /** |
|
| 938 | - * @get the full page request the visitor is accessing |
|
| 939 | - * @access public |
|
| 940 | - * @return string |
|
| 941 | - */ |
|
| 942 | - public function _get_page_visit() |
|
| 943 | - { |
|
| 944 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
| 945 | - // check for request url |
|
| 946 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 947 | - $http_host = ''; |
|
| 948 | - $page_id = '?'; |
|
| 949 | - $e_reg = ''; |
|
| 950 | - $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
| 951 | - $ru_bits = explode('?', $request_uri); |
|
| 952 | - $request_uri = $ru_bits[0]; |
|
| 953 | - // check for and grab host as well |
|
| 954 | - if (isset($_SERVER['HTTP_HOST'])) { |
|
| 955 | - $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
| 956 | - } |
|
| 957 | - // check for page_id in SERVER REQUEST |
|
| 958 | - if (isset($_REQUEST['page_id'])) { |
|
| 959 | - // rebuild $e_reg without any of the extra parameters |
|
| 960 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
| 961 | - } |
|
| 962 | - // check for $e_reg in SERVER REQUEST |
|
| 963 | - if (isset($_REQUEST['ee'])) { |
|
| 964 | - // rebuild $e_reg without any of the extra parameters |
|
| 965 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
| 966 | - } |
|
| 967 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
| 968 | - } |
|
| 969 | - return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * @the current wp user id |
|
| 976 | - * @access public |
|
| 977 | - * @return int |
|
| 978 | - */ |
|
| 979 | - public function _wp_user_id() |
|
| 980 | - { |
|
| 981 | - // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
| 982 | - $this->_wp_user_id = get_current_user_id(); |
|
| 983 | - return $this->_wp_user_id; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * Clear EE_Session data |
|
| 990 | - * |
|
| 991 | - * @access public |
|
| 992 | - * @param string $class |
|
| 993 | - * @param string $function |
|
| 994 | - * @return void |
|
| 995 | - * @throws EE_Error |
|
| 996 | - * @throws InvalidArgumentException |
|
| 997 | - * @throws InvalidDataTypeException |
|
| 998 | - * @throws InvalidInterfaceException |
|
| 999 | - */ |
|
| 1000 | - public function clear_session($class = '', $function = '') |
|
| 1001 | - { |
|
| 1002 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
| 1003 | - $this->reset_cart(); |
|
| 1004 | - $this->reset_checkout(); |
|
| 1005 | - $this->reset_transaction(); |
|
| 1006 | - // wipe out everything that isn't a default session datum |
|
| 1007 | - $this->reset_data(array_keys($this->_session_data)); |
|
| 1008 | - // reset initial site access time and the session expiration |
|
| 1009 | - $this->_set_init_access_and_expiration(); |
|
| 1010 | - $this->_save_session_to_db(true); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
| 1016 | - * |
|
| 1017 | - * @param array|mixed $data_to_reset |
|
| 1018 | - * @param bool $show_all_notices |
|
| 1019 | - * @return bool |
|
| 1020 | - */ |
|
| 1021 | - public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
| 1022 | - { |
|
| 1023 | - // if $data_to_reset is not in an array, then put it in one |
|
| 1024 | - if (! is_array($data_to_reset)) { |
|
| 1025 | - $data_to_reset = array($data_to_reset); |
|
| 1026 | - } |
|
| 1027 | - // nothing ??? go home! |
|
| 1028 | - if (empty($data_to_reset)) { |
|
| 1029 | - EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', |
|
| 1030 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1031 | - return false; |
|
| 1032 | - } |
|
| 1033 | - $return_value = true; |
|
| 1034 | - // since $data_to_reset is an array, cycle through the values |
|
| 1035 | - foreach ($data_to_reset as $reset) { |
|
| 1036 | - |
|
| 1037 | - // first check to make sure it is a valid session var |
|
| 1038 | - if (isset($this->_session_data[ $reset ])) { |
|
| 1039 | - // then check to make sure it is not a default var |
|
| 1040 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1041 | - // remove session var |
|
| 1042 | - unset($this->_session_data[ $reset ]); |
|
| 1043 | - if ($show_all_notices) { |
|
| 1044 | - EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
|
| 1045 | - $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1046 | - } |
|
| 1047 | - } else { |
|
| 1048 | - // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
| 1049 | - if ($show_all_notices) { |
|
| 1050 | - EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
| 1051 | - 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1052 | - } |
|
| 1053 | - $return_value = false; |
|
| 1054 | - } |
|
| 1055 | - } elseif ($show_all_notices) { |
|
| 1056 | - // oops! that session var does not exist! |
|
| 1057 | - EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', |
|
| 1058 | - 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1059 | - $return_value = false; |
|
| 1060 | - } |
|
| 1061 | - } // end of foreach |
|
| 1062 | - return $return_value; |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - |
|
| 1066 | - |
|
| 1067 | - /** |
|
| 1068 | - * wp_loaded |
|
| 1069 | - * |
|
| 1070 | - * @access public |
|
| 1071 | - * @throws EE_Error |
|
| 1072 | - * @throws InvalidDataTypeException |
|
| 1073 | - * @throws InvalidInterfaceException |
|
| 1074 | - * @throws InvalidArgumentException |
|
| 1075 | - */ |
|
| 1076 | - public function wp_loaded() |
|
| 1077 | - { |
|
| 1078 | - if ($this->request->requestParamIsSet('clear_session')) { |
|
| 1079 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * Used to reset the entire object (for tests). |
|
| 1087 | - * |
|
| 1088 | - * @since 4.3.0 |
|
| 1089 | - * @throws EE_Error |
|
| 1090 | - * @throws InvalidDataTypeException |
|
| 1091 | - * @throws InvalidInterfaceException |
|
| 1092 | - * @throws InvalidArgumentException |
|
| 1093 | - */ |
|
| 1094 | - public function reset_instance() |
|
| 1095 | - { |
|
| 1096 | - $this->clear_session(); |
|
| 1097 | - self::$_instance = null; |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - |
|
| 1101 | - |
|
| 1102 | - public function configure_garbage_collection_filters() |
|
| 1103 | - { |
|
| 1104 | - // run old filter we had for controlling session cleanup |
|
| 1105 | - $expired_session_transient_delete_query_limit = absint( |
|
| 1106 | - apply_filters( |
|
| 1107 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1108 | - 50 |
|
| 1109 | - ) |
|
| 1110 | - ); |
|
| 1111 | - // is there a value? or one that is different than the default 50 records? |
|
| 1112 | - if ($expired_session_transient_delete_query_limit === 0) { |
|
| 1113 | - // hook into TransientCacheStorage in case Session cleanup was turned off |
|
| 1114 | - add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
| 1115 | - } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
| 1116 | - // or use that for the new transient cleanup query limit |
|
| 1117 | - add_filter( |
|
| 1118 | - 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
| 1119 | - function () use ($expired_session_transient_delete_query_limit) |
|
| 1120 | - { |
|
| 1121 | - return $expired_session_transient_delete_query_limit; |
|
| 1122 | - } |
|
| 1123 | - ); |
|
| 1124 | - } |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - /** |
|
| 1130 | - * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
| 1131 | - * @param $data1 |
|
| 1132 | - * @return string |
|
| 1133 | - */ |
|
| 1134 | - private function find_serialize_error($data1) |
|
| 1135 | - { |
|
| 1136 | - $error = '<pre>'; |
|
| 1137 | - $data2 = preg_replace_callback( |
|
| 1138 | - '!s:(\d+):"(.*?)";!', |
|
| 1139 | - function ($match) |
|
| 1140 | - { |
|
| 1141 | - return ($match[1] === strlen($match[2])) |
|
| 1142 | - ? $match[0] |
|
| 1143 | - : 's:' |
|
| 1144 | - . strlen($match[2]) |
|
| 1145 | - . ':"' |
|
| 1146 | - . $match[2] |
|
| 1147 | - . '";'; |
|
| 1148 | - }, |
|
| 1149 | - $data1 |
|
| 1150 | - ); |
|
| 1151 | - $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1152 | - $error .= $data1 . PHP_EOL; |
|
| 1153 | - $error .= $data2 . PHP_EOL; |
|
| 1154 | - for ($i = 0; $i < $max; $i++) { |
|
| 1155 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
| 1156 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
| 1157 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
| 1158 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
| 1159 | - $start = ($i - 20); |
|
| 1160 | - $start = ($start < 0) ? 0 : $start; |
|
| 1161 | - $length = 40; |
|
| 1162 | - $point = $max - $i; |
|
| 1163 | - if ($point < 20) { |
|
| 1164 | - $rlength = 1; |
|
| 1165 | - $rpoint = -$point; |
|
| 1166 | - } else { |
|
| 1167 | - $rpoint = $length - 20; |
|
| 1168 | - $rlength = 1; |
|
| 1169 | - } |
|
| 1170 | - $error .= "\t-> Section Data1 = "; |
|
| 1171 | - $error .= substr_replace( |
|
| 1172 | - substr($data1, $start, $length), |
|
| 1173 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
| 1174 | - $rpoint, |
|
| 1175 | - $rlength |
|
| 1176 | - ); |
|
| 1177 | - $error .= PHP_EOL; |
|
| 1178 | - $error .= "\t-> Section Data2 = "; |
|
| 1179 | - $error .= substr_replace( |
|
| 1180 | - substr($data2, $start, $length), |
|
| 1181 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
| 1182 | - $rpoint, |
|
| 1183 | - $rlength |
|
| 1184 | - ); |
|
| 1185 | - $error .= PHP_EOL; |
|
| 1186 | - } |
|
| 1187 | - } |
|
| 1188 | - $error .= '</pre>'; |
|
| 1189 | - return $error; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - |
|
| 1193 | - /** |
|
| 1194 | - * Saves an array of settings used for configuring aspects of session behaviour |
|
| 1195 | - * |
|
| 1196 | - * @param array $updated_settings |
|
| 1197 | - */ |
|
| 1198 | - private function updateSessionSettings(array $updated_settings = array()) |
|
| 1199 | - { |
|
| 1200 | - // add existing settings, but only if not included in incoming $updated_settings array |
|
| 1201 | - $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 1202 | - update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - |
|
| 1206 | - /** |
|
| 1207 | - * garbage_collection |
|
| 1208 | - */ |
|
| 1209 | - public function garbageCollection() |
|
| 1210 | - { |
|
| 1211 | - // only perform during regular requests if last garbage collection was over an hour ago |
|
| 1212 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1213 | - $this->_last_gc = time(); |
|
| 1214 | - $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
| 1215 | - /** @type WPDB $wpdb */ |
|
| 1216 | - global $wpdb; |
|
| 1217 | - // filter the query limit. Set to 0 to turn off garbage collection |
|
| 1218 | - $expired_session_transient_delete_query_limit = absint( |
|
| 1219 | - apply_filters( |
|
| 1220 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1221 | - 50 |
|
| 1222 | - ) |
|
| 1223 | - ); |
|
| 1224 | - // non-zero LIMIT means take out the trash |
|
| 1225 | - if ($expired_session_transient_delete_query_limit) { |
|
| 1226 | - $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
| 1227 | - $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
| 1228 | - // since transient expiration timestamps are set in the future, we can compare against NOW |
|
| 1229 | - // but we only want to pick up any trash that's been around for more than a day |
|
| 1230 | - $expiration = time() - DAY_IN_SECONDS; |
|
| 1231 | - $SQL = " |
|
| 397 | + /** |
|
| 398 | + * @param \EE_Cart $cart |
|
| 399 | + * @return bool |
|
| 400 | + */ |
|
| 401 | + public function set_cart(EE_Cart $cart) |
|
| 402 | + { |
|
| 403 | + $this->_session_data['cart'] = $cart; |
|
| 404 | + return true; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * reset_cart |
|
| 411 | + */ |
|
| 412 | + public function reset_cart() |
|
| 413 | + { |
|
| 414 | + do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
| 415 | + $this->_session_data['cart'] = null; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * @return \EE_Cart |
|
| 422 | + */ |
|
| 423 | + public function cart() |
|
| 424 | + { |
|
| 425 | + return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
| 426 | + ? $this->_session_data['cart'] |
|
| 427 | + : null; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * @param \EE_Checkout $checkout |
|
| 434 | + * @return bool |
|
| 435 | + */ |
|
| 436 | + public function set_checkout(EE_Checkout $checkout) |
|
| 437 | + { |
|
| 438 | + $this->_session_data['checkout'] = $checkout; |
|
| 439 | + return true; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * reset_checkout |
|
| 446 | + */ |
|
| 447 | + public function reset_checkout() |
|
| 448 | + { |
|
| 449 | + do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
| 450 | + $this->_session_data['checkout'] = null; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * @return \EE_Checkout |
|
| 457 | + */ |
|
| 458 | + public function checkout() |
|
| 459 | + { |
|
| 460 | + return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
| 461 | + ? $this->_session_data['checkout'] |
|
| 462 | + : null; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * @param \EE_Transaction $transaction |
|
| 469 | + * @return bool |
|
| 470 | + * @throws EE_Error |
|
| 471 | + */ |
|
| 472 | + public function set_transaction(EE_Transaction $transaction) |
|
| 473 | + { |
|
| 474 | + // first remove the session from the transaction before we save the transaction in the session |
|
| 475 | + $transaction->set_txn_session_data(null); |
|
| 476 | + $this->_session_data['transaction'] = $transaction; |
|
| 477 | + return true; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * reset_transaction |
|
| 484 | + */ |
|
| 485 | + public function reset_transaction() |
|
| 486 | + { |
|
| 487 | + do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
| 488 | + $this->_session_data['transaction'] = null; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * @return \EE_Transaction |
|
| 495 | + */ |
|
| 496 | + public function transaction() |
|
| 497 | + { |
|
| 498 | + return isset($this->_session_data['transaction']) |
|
| 499 | + && $this->_session_data['transaction'] instanceof EE_Transaction |
|
| 500 | + ? $this->_session_data['transaction'] |
|
| 501 | + : null; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * retrieve session data |
|
| 507 | + * |
|
| 508 | + * @param null $key |
|
| 509 | + * @param bool $reset_cache |
|
| 510 | + * @return array |
|
| 511 | + */ |
|
| 512 | + public function get_session_data($key = null, $reset_cache = false) |
|
| 513 | + { |
|
| 514 | + if ($reset_cache) { |
|
| 515 | + $this->reset_cart(); |
|
| 516 | + $this->reset_checkout(); |
|
| 517 | + $this->reset_transaction(); |
|
| 518 | + } |
|
| 519 | + if (! empty($key)) { |
|
| 520 | + return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
| 521 | + } |
|
| 522 | + return $this->_session_data; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Returns TRUE on success, FALSE on fail |
|
| 528 | + * |
|
| 529 | + * @param array $data |
|
| 530 | + * @return bool |
|
| 531 | + */ |
|
| 532 | + public function set_session_data($data) |
|
| 533 | + { |
|
| 534 | + |
|
| 535 | + // nothing ??? bad data ??? go home! |
|
| 536 | + if (empty($data) || ! is_array($data)) { |
|
| 537 | + EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, |
|
| 538 | + __FUNCTION__, __LINE__); |
|
| 539 | + return false; |
|
| 540 | + } |
|
| 541 | + foreach ($data as $key => $value) { |
|
| 542 | + if (isset($this->_default_session_vars[ $key ])) { |
|
| 543 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
| 544 | + 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__); |
|
| 545 | + return false; |
|
| 546 | + } |
|
| 547 | + $this->_session_data[ $key ] = $value; |
|
| 548 | + } |
|
| 549 | + return true; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * @initiate session |
|
| 556 | + * @access private |
|
| 557 | + * @return TRUE on success, FALSE on fail |
|
| 558 | + * @throws EE_Error |
|
| 559 | + * @throws InvalidArgumentException |
|
| 560 | + * @throws InvalidDataTypeException |
|
| 561 | + * @throws InvalidInterfaceException |
|
| 562 | + * @throws InvalidSessionDataException |
|
| 563 | + */ |
|
| 564 | + private function _espresso_session() |
|
| 565 | + { |
|
| 566 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 567 | + // check that session has started |
|
| 568 | + if (session_id() === '') { |
|
| 569 | + //starts a new session if one doesn't already exist, or re-initiates an existing one |
|
| 570 | + session_start(); |
|
| 571 | + } |
|
| 572 | + $this->status = EE_Session::STATUS_OPEN; |
|
| 573 | + // get our modified session ID |
|
| 574 | + $this->_sid = $this->_generate_session_id(); |
|
| 575 | + // and the visitors IP |
|
| 576 | + $this->_ip_address = $this->request->ipAddress(); |
|
| 577 | + // set the "user agent" |
|
| 578 | + $this->_user_agent = $this->request->userAgent(); |
|
| 579 | + // now let's retrieve what's in the db |
|
| 580 | + $session_data = $this->_retrieve_session_data(); |
|
| 581 | + if (! empty($session_data)) { |
|
| 582 | + // get the current time in UTC |
|
| 583 | + $this->_time = $this->_time !== null ? $this->_time : time(); |
|
| 584 | + // and reset the session expiration |
|
| 585 | + $this->_expiration = isset($session_data['expiration']) |
|
| 586 | + ? $session_data['expiration'] |
|
| 587 | + : $this->_time + $this->session_lifespan->inSeconds(); |
|
| 588 | + } else { |
|
| 589 | + // set initial site access time and the session expiration |
|
| 590 | + $this->_set_init_access_and_expiration(); |
|
| 591 | + // set referer |
|
| 592 | + $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
| 593 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
| 594 | + : ''; |
|
| 595 | + // no previous session = go back and create one (on top of the data above) |
|
| 596 | + return false; |
|
| 597 | + } |
|
| 598 | + // now the user agent |
|
| 599 | + if ($session_data['user_agent'] !== $this->_user_agent) { |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + // wait a minute... how old are you? |
|
| 603 | + if ($this->_time > $this->_expiration) { |
|
| 604 | + // yer too old fer me! |
|
| 605 | + $this->_expired = true; |
|
| 606 | + // wipe out everything that isn't a default session datum |
|
| 607 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 608 | + } |
|
| 609 | + // make event espresso session data available to plugin |
|
| 610 | + $this->_session_data = array_merge($this->_session_data, $session_data); |
|
| 611 | + return true; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * _get_session_data |
|
| 618 | + * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
| 619 | + * databases |
|
| 620 | + * |
|
| 621 | + * @return array |
|
| 622 | + * @throws EE_Error |
|
| 623 | + * @throws InvalidArgumentException |
|
| 624 | + * @throws InvalidSessionDataException |
|
| 625 | + * @throws InvalidDataTypeException |
|
| 626 | + * @throws InvalidInterfaceException |
|
| 627 | + */ |
|
| 628 | + protected function _retrieve_session_data() |
|
| 629 | + { |
|
| 630 | + $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 631 | + try { |
|
| 632 | + // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
| 633 | + $session_data = $this->cache_storage->get($ssn_key, false); |
|
| 634 | + if (empty($session_data)) { |
|
| 635 | + return array(); |
|
| 636 | + } |
|
| 637 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 638 | + $hash_check = $this->cache_storage->get( |
|
| 639 | + EE_Session::hash_check_prefix . $this->_sid, |
|
| 640 | + false |
|
| 641 | + ); |
|
| 642 | + if ($hash_check && $hash_check !== md5($session_data)) { |
|
| 643 | + EE_Error::add_error( |
|
| 644 | + sprintf( |
|
| 645 | + __( |
|
| 646 | + 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
| 647 | + 'event_espresso' |
|
| 648 | + ), |
|
| 649 | + EE_Session::session_id_prefix . $this->_sid |
|
| 650 | + ), |
|
| 651 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 652 | + ); |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + } catch (Exception $e) { |
|
| 656 | + // let's just eat that error for now and attempt to correct any corrupted data |
|
| 657 | + global $wpdb; |
|
| 658 | + $row = $wpdb->get_row( |
|
| 659 | + $wpdb->prepare( |
|
| 660 | + "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
| 661 | + '_transient_' . $ssn_key |
|
| 662 | + ) |
|
| 663 | + ); |
|
| 664 | + $session_data = is_object($row) ? $row->option_value : null; |
|
| 665 | + if ($session_data) { |
|
| 666 | + $session_data = preg_replace_callback( |
|
| 667 | + '!s:(d+):"(.*?)";!', |
|
| 668 | + function ($match) |
|
| 669 | + { |
|
| 670 | + return $match[1] === strlen($match[2]) |
|
| 671 | + ? $match[0] |
|
| 672 | + : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 673 | + }, |
|
| 674 | + $session_data |
|
| 675 | + ); |
|
| 676 | + } |
|
| 677 | + $session_data = maybe_unserialize($session_data); |
|
| 678 | + } |
|
| 679 | + // in case the data is encoded... try to decode it |
|
| 680 | + $session_data = $this->encryption instanceof EE_Encryption |
|
| 681 | + ? $this->encryption->base64_string_decode($session_data) |
|
| 682 | + : $session_data; |
|
| 683 | + if (! is_array($session_data)) { |
|
| 684 | + try { |
|
| 685 | + $session_data = maybe_unserialize($session_data); |
|
| 686 | + } catch (Exception $e) { |
|
| 687 | + $msg = esc_html__( |
|
| 688 | + 'An error occurred while attempting to unserialize the session data.', |
|
| 689 | + 'event_espresso' |
|
| 690 | + ); |
|
| 691 | + $msg .= WP_DEBUG |
|
| 692 | + ? '<br><pre>' |
|
| 693 | + . print_r($session_data, true) |
|
| 694 | + . '</pre><br>' |
|
| 695 | + . $this->find_serialize_error($session_data) |
|
| 696 | + : ''; |
|
| 697 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 698 | + throw new InvalidSessionDataException($msg, 0, $e); |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + // just a check to make sure the session array is indeed an array |
|
| 702 | + if (! is_array($session_data)) { |
|
| 703 | + // no?!?! then something is wrong |
|
| 704 | + $msg = esc_html__( |
|
| 705 | + 'The session data is missing, invalid, or corrupted.', |
|
| 706 | + 'event_espresso' |
|
| 707 | + ); |
|
| 708 | + $msg .= WP_DEBUG |
|
| 709 | + ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 710 | + : ''; |
|
| 711 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 712 | + throw new InvalidSessionDataException($msg); |
|
| 713 | + } |
|
| 714 | + if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
| 715 | + $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
| 716 | + $session_data['transaction'] |
|
| 717 | + ); |
|
| 718 | + } |
|
| 719 | + return $session_data; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * _generate_session_id |
|
| 726 | + * Retrieves the PHP session id either directly from the PHP session, |
|
| 727 | + * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
| 728 | + * The session id is then salted and hashed (mmm sounds tasty) |
|
| 729 | + * so that it can be safely used as a $_REQUEST param |
|
| 730 | + * |
|
| 731 | + * @return string |
|
| 732 | + */ |
|
| 733 | + protected function _generate_session_id() |
|
| 734 | + { |
|
| 735 | + // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
| 736 | + if (isset($_REQUEST['EESID'])) { |
|
| 737 | + $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
| 738 | + } else { |
|
| 739 | + $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
| 740 | + } |
|
| 741 | + return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * _get_sid_salt |
|
| 748 | + * |
|
| 749 | + * @return string |
|
| 750 | + */ |
|
| 751 | + protected function _get_sid_salt() |
|
| 752 | + { |
|
| 753 | + // was session id salt already saved to db ? |
|
| 754 | + if (empty($this->_sid_salt)) { |
|
| 755 | + // no? then maybe use WP defined constant |
|
| 756 | + if (defined('AUTH_SALT')) { |
|
| 757 | + $this->_sid_salt = AUTH_SALT; |
|
| 758 | + } |
|
| 759 | + // if salt doesn't exist or is too short |
|
| 760 | + if (strlen($this->_sid_salt) < 32) { |
|
| 761 | + // create a new one |
|
| 762 | + $this->_sid_salt = wp_generate_password(64); |
|
| 763 | + } |
|
| 764 | + // and save it as a permanent session setting |
|
| 765 | + $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
| 766 | + } |
|
| 767 | + return $this->_sid_salt; |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * _set_init_access_and_expiration |
|
| 774 | + * |
|
| 775 | + * @return void |
|
| 776 | + */ |
|
| 777 | + protected function _set_init_access_and_expiration() |
|
| 778 | + { |
|
| 779 | + $this->_time = time(); |
|
| 780 | + $this->_expiration = $this->_time + $this->session_lifespan->inSeconds(); |
|
| 781 | + // set initial site access time |
|
| 782 | + $this->_session_data['init_access'] = $this->_time; |
|
| 783 | + // and the session expiration |
|
| 784 | + $this->_session_data['expiration'] = $this->_expiration; |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * @update session data prior to saving to the db |
|
| 791 | + * @access public |
|
| 792 | + * @param bool $new_session |
|
| 793 | + * @return TRUE on success, FALSE on fail |
|
| 794 | + * @throws EE_Error |
|
| 795 | + * @throws InvalidArgumentException |
|
| 796 | + * @throws InvalidDataTypeException |
|
| 797 | + * @throws InvalidInterfaceException |
|
| 798 | + */ |
|
| 799 | + public function update($new_session = false) |
|
| 800 | + { |
|
| 801 | + $this->_session_data = $this->_session_data !== null |
|
| 802 | + && is_array($this->_session_data) |
|
| 803 | + && isset($this->_session_data['id']) |
|
| 804 | + ? $this->_session_data |
|
| 805 | + : array(); |
|
| 806 | + if (empty($this->_session_data)) { |
|
| 807 | + $this->_set_defaults(); |
|
| 808 | + } |
|
| 809 | + $session_data = array(); |
|
| 810 | + foreach ($this->_session_data as $key => $value) { |
|
| 811 | + |
|
| 812 | + switch ($key) { |
|
| 813 | + |
|
| 814 | + case 'id' : |
|
| 815 | + // session ID |
|
| 816 | + $session_data['id'] = $this->_sid; |
|
| 817 | + break; |
|
| 818 | + case 'ip_address' : |
|
| 819 | + // visitor ip address |
|
| 820 | + $session_data['ip_address'] = $this->request->ipAddress(); |
|
| 821 | + break; |
|
| 822 | + case 'user_agent' : |
|
| 823 | + // visitor user_agent |
|
| 824 | + $session_data['user_agent'] = $this->_user_agent; |
|
| 825 | + break; |
|
| 826 | + case 'init_access' : |
|
| 827 | + $session_data['init_access'] = absint($value); |
|
| 828 | + break; |
|
| 829 | + case 'last_access' : |
|
| 830 | + // current access time |
|
| 831 | + $session_data['last_access'] = $this->_time; |
|
| 832 | + break; |
|
| 833 | + case 'expiration' : |
|
| 834 | + // when the session expires |
|
| 835 | + $session_data['expiration'] = ! empty($this->_expiration) |
|
| 836 | + ? $this->_expiration |
|
| 837 | + : $session_data['init_access'] + $this->session_lifespan->inSeconds(); |
|
| 838 | + break; |
|
| 839 | + case 'user_id' : |
|
| 840 | + // current user if logged in |
|
| 841 | + $session_data['user_id'] = $this->_wp_user_id(); |
|
| 842 | + break; |
|
| 843 | + case 'pages_visited' : |
|
| 844 | + $page_visit = $this->_get_page_visit(); |
|
| 845 | + if ($page_visit) { |
|
| 846 | + // set pages visited where the first will be the http referrer |
|
| 847 | + $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
| 848 | + // we'll only save the last 10 page visits. |
|
| 849 | + $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
| 850 | + } |
|
| 851 | + break; |
|
| 852 | + default : |
|
| 853 | + // carry any other data over |
|
| 854 | + $session_data[ $key ] = $this->_session_data[ $key ]; |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + $this->_session_data = $session_data; |
|
| 858 | + // creating a new session does not require saving to the db just yet |
|
| 859 | + if (! $new_session) { |
|
| 860 | + // ready? let's save |
|
| 861 | + if ($this->_save_session_to_db()) { |
|
| 862 | + return true; |
|
| 863 | + } |
|
| 864 | + return false; |
|
| 865 | + } |
|
| 866 | + // meh, why not? |
|
| 867 | + return true; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * @create session data array |
|
| 874 | + * @access public |
|
| 875 | + * @return bool |
|
| 876 | + * @throws EE_Error |
|
| 877 | + * @throws InvalidArgumentException |
|
| 878 | + * @throws InvalidDataTypeException |
|
| 879 | + * @throws InvalidInterfaceException |
|
| 880 | + */ |
|
| 881 | + private function _create_espresso_session() |
|
| 882 | + { |
|
| 883 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
| 884 | + // use the update function for now with $new_session arg set to TRUE |
|
| 885 | + return $this->update(true) ? true : false; |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * _save_session_to_db |
|
| 892 | + * |
|
| 893 | + * @param bool $clear_session |
|
| 894 | + * @return string |
|
| 895 | + * @throws EE_Error |
|
| 896 | + * @throws InvalidArgumentException |
|
| 897 | + * @throws InvalidDataTypeException |
|
| 898 | + * @throws InvalidInterfaceException |
|
| 899 | + */ |
|
| 900 | + private function _save_session_to_db($clear_session = false) |
|
| 901 | + { |
|
| 902 | + // don't save sessions for crawlers |
|
| 903 | + // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
| 904 | + if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 905 | + return false; |
|
| 906 | + } |
|
| 907 | + $transaction = $this->transaction(); |
|
| 908 | + if ($transaction instanceof EE_Transaction) { |
|
| 909 | + if (! $transaction->ID()) { |
|
| 910 | + $transaction->save(); |
|
| 911 | + } |
|
| 912 | + $this->_session_data['transaction'] = $transaction->ID(); |
|
| 913 | + } |
|
| 914 | + // then serialize all of our session data |
|
| 915 | + $session_data = serialize($this->_session_data); |
|
| 916 | + // do we need to also encode it to avoid corrupted data when saved to the db? |
|
| 917 | + $session_data = $this->_use_encryption |
|
| 918 | + ? $this->encryption->base64_string_encode($session_data) |
|
| 919 | + : $session_data; |
|
| 920 | + // maybe save hash check |
|
| 921 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 922 | + $this->cache_storage->add( |
|
| 923 | + EE_Session::hash_check_prefix . $this->_sid, |
|
| 924 | + md5($session_data), |
|
| 925 | + $this->session_lifespan->inSeconds() |
|
| 926 | + ); |
|
| 927 | + } |
|
| 928 | + // we're using the Transient API for storing session data, |
|
| 929 | + return $this->cache_storage->add( |
|
| 930 | + EE_Session::session_id_prefix . $this->_sid, |
|
| 931 | + $session_data, |
|
| 932 | + $this->session_lifespan->inSeconds() |
|
| 933 | + ); |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + |
|
| 937 | + /** |
|
| 938 | + * @get the full page request the visitor is accessing |
|
| 939 | + * @access public |
|
| 940 | + * @return string |
|
| 941 | + */ |
|
| 942 | + public function _get_page_visit() |
|
| 943 | + { |
|
| 944 | + $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
| 945 | + // check for request url |
|
| 946 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 947 | + $http_host = ''; |
|
| 948 | + $page_id = '?'; |
|
| 949 | + $e_reg = ''; |
|
| 950 | + $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
| 951 | + $ru_bits = explode('?', $request_uri); |
|
| 952 | + $request_uri = $ru_bits[0]; |
|
| 953 | + // check for and grab host as well |
|
| 954 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
| 955 | + $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
| 956 | + } |
|
| 957 | + // check for page_id in SERVER REQUEST |
|
| 958 | + if (isset($_REQUEST['page_id'])) { |
|
| 959 | + // rebuild $e_reg without any of the extra parameters |
|
| 960 | + $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
| 961 | + } |
|
| 962 | + // check for $e_reg in SERVER REQUEST |
|
| 963 | + if (isset($_REQUEST['ee'])) { |
|
| 964 | + // rebuild $e_reg without any of the extra parameters |
|
| 965 | + $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
| 966 | + } |
|
| 967 | + $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
| 968 | + } |
|
| 969 | + return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * @the current wp user id |
|
| 976 | + * @access public |
|
| 977 | + * @return int |
|
| 978 | + */ |
|
| 979 | + public function _wp_user_id() |
|
| 980 | + { |
|
| 981 | + // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
| 982 | + $this->_wp_user_id = get_current_user_id(); |
|
| 983 | + return $this->_wp_user_id; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * Clear EE_Session data |
|
| 990 | + * |
|
| 991 | + * @access public |
|
| 992 | + * @param string $class |
|
| 993 | + * @param string $function |
|
| 994 | + * @return void |
|
| 995 | + * @throws EE_Error |
|
| 996 | + * @throws InvalidArgumentException |
|
| 997 | + * @throws InvalidDataTypeException |
|
| 998 | + * @throws InvalidInterfaceException |
|
| 999 | + */ |
|
| 1000 | + public function clear_session($class = '', $function = '') |
|
| 1001 | + { |
|
| 1002 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
| 1003 | + $this->reset_cart(); |
|
| 1004 | + $this->reset_checkout(); |
|
| 1005 | + $this->reset_transaction(); |
|
| 1006 | + // wipe out everything that isn't a default session datum |
|
| 1007 | + $this->reset_data(array_keys($this->_session_data)); |
|
| 1008 | + // reset initial site access time and the session expiration |
|
| 1009 | + $this->_set_init_access_and_expiration(); |
|
| 1010 | + $this->_save_session_to_db(true); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
| 1016 | + * |
|
| 1017 | + * @param array|mixed $data_to_reset |
|
| 1018 | + * @param bool $show_all_notices |
|
| 1019 | + * @return bool |
|
| 1020 | + */ |
|
| 1021 | + public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
| 1022 | + { |
|
| 1023 | + // if $data_to_reset is not in an array, then put it in one |
|
| 1024 | + if (! is_array($data_to_reset)) { |
|
| 1025 | + $data_to_reset = array($data_to_reset); |
|
| 1026 | + } |
|
| 1027 | + // nothing ??? go home! |
|
| 1028 | + if (empty($data_to_reset)) { |
|
| 1029 | + EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', |
|
| 1030 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1031 | + return false; |
|
| 1032 | + } |
|
| 1033 | + $return_value = true; |
|
| 1034 | + // since $data_to_reset is an array, cycle through the values |
|
| 1035 | + foreach ($data_to_reset as $reset) { |
|
| 1036 | + |
|
| 1037 | + // first check to make sure it is a valid session var |
|
| 1038 | + if (isset($this->_session_data[ $reset ])) { |
|
| 1039 | + // then check to make sure it is not a default var |
|
| 1040 | + if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1041 | + // remove session var |
|
| 1042 | + unset($this->_session_data[ $reset ]); |
|
| 1043 | + if ($show_all_notices) { |
|
| 1044 | + EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
|
| 1045 | + $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1046 | + } |
|
| 1047 | + } else { |
|
| 1048 | + // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
| 1049 | + if ($show_all_notices) { |
|
| 1050 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
| 1051 | + 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1052 | + } |
|
| 1053 | + $return_value = false; |
|
| 1054 | + } |
|
| 1055 | + } elseif ($show_all_notices) { |
|
| 1056 | + // oops! that session var does not exist! |
|
| 1057 | + EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', |
|
| 1058 | + 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1059 | + $return_value = false; |
|
| 1060 | + } |
|
| 1061 | + } // end of foreach |
|
| 1062 | + return $return_value; |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + |
|
| 1066 | + |
|
| 1067 | + /** |
|
| 1068 | + * wp_loaded |
|
| 1069 | + * |
|
| 1070 | + * @access public |
|
| 1071 | + * @throws EE_Error |
|
| 1072 | + * @throws InvalidDataTypeException |
|
| 1073 | + * @throws InvalidInterfaceException |
|
| 1074 | + * @throws InvalidArgumentException |
|
| 1075 | + */ |
|
| 1076 | + public function wp_loaded() |
|
| 1077 | + { |
|
| 1078 | + if ($this->request->requestParamIsSet('clear_session')) { |
|
| 1079 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * Used to reset the entire object (for tests). |
|
| 1087 | + * |
|
| 1088 | + * @since 4.3.0 |
|
| 1089 | + * @throws EE_Error |
|
| 1090 | + * @throws InvalidDataTypeException |
|
| 1091 | + * @throws InvalidInterfaceException |
|
| 1092 | + * @throws InvalidArgumentException |
|
| 1093 | + */ |
|
| 1094 | + public function reset_instance() |
|
| 1095 | + { |
|
| 1096 | + $this->clear_session(); |
|
| 1097 | + self::$_instance = null; |
|
| 1098 | + } |
|
| 1099 | + |
|
| 1100 | + |
|
| 1101 | + |
|
| 1102 | + public function configure_garbage_collection_filters() |
|
| 1103 | + { |
|
| 1104 | + // run old filter we had for controlling session cleanup |
|
| 1105 | + $expired_session_transient_delete_query_limit = absint( |
|
| 1106 | + apply_filters( |
|
| 1107 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1108 | + 50 |
|
| 1109 | + ) |
|
| 1110 | + ); |
|
| 1111 | + // is there a value? or one that is different than the default 50 records? |
|
| 1112 | + if ($expired_session_transient_delete_query_limit === 0) { |
|
| 1113 | + // hook into TransientCacheStorage in case Session cleanup was turned off |
|
| 1114 | + add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
| 1115 | + } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
| 1116 | + // or use that for the new transient cleanup query limit |
|
| 1117 | + add_filter( |
|
| 1118 | + 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
| 1119 | + function () use ($expired_session_transient_delete_query_limit) |
|
| 1120 | + { |
|
| 1121 | + return $expired_session_transient_delete_query_limit; |
|
| 1122 | + } |
|
| 1123 | + ); |
|
| 1124 | + } |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + /** |
|
| 1130 | + * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
| 1131 | + * @param $data1 |
|
| 1132 | + * @return string |
|
| 1133 | + */ |
|
| 1134 | + private function find_serialize_error($data1) |
|
| 1135 | + { |
|
| 1136 | + $error = '<pre>'; |
|
| 1137 | + $data2 = preg_replace_callback( |
|
| 1138 | + '!s:(\d+):"(.*?)";!', |
|
| 1139 | + function ($match) |
|
| 1140 | + { |
|
| 1141 | + return ($match[1] === strlen($match[2])) |
|
| 1142 | + ? $match[0] |
|
| 1143 | + : 's:' |
|
| 1144 | + . strlen($match[2]) |
|
| 1145 | + . ':"' |
|
| 1146 | + . $match[2] |
|
| 1147 | + . '";'; |
|
| 1148 | + }, |
|
| 1149 | + $data1 |
|
| 1150 | + ); |
|
| 1151 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1152 | + $error .= $data1 . PHP_EOL; |
|
| 1153 | + $error .= $data2 . PHP_EOL; |
|
| 1154 | + for ($i = 0; $i < $max; $i++) { |
|
| 1155 | + if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
| 1156 | + $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
| 1157 | + $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
| 1158 | + $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
| 1159 | + $start = ($i - 20); |
|
| 1160 | + $start = ($start < 0) ? 0 : $start; |
|
| 1161 | + $length = 40; |
|
| 1162 | + $point = $max - $i; |
|
| 1163 | + if ($point < 20) { |
|
| 1164 | + $rlength = 1; |
|
| 1165 | + $rpoint = -$point; |
|
| 1166 | + } else { |
|
| 1167 | + $rpoint = $length - 20; |
|
| 1168 | + $rlength = 1; |
|
| 1169 | + } |
|
| 1170 | + $error .= "\t-> Section Data1 = "; |
|
| 1171 | + $error .= substr_replace( |
|
| 1172 | + substr($data1, $start, $length), |
|
| 1173 | + "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
| 1174 | + $rpoint, |
|
| 1175 | + $rlength |
|
| 1176 | + ); |
|
| 1177 | + $error .= PHP_EOL; |
|
| 1178 | + $error .= "\t-> Section Data2 = "; |
|
| 1179 | + $error .= substr_replace( |
|
| 1180 | + substr($data2, $start, $length), |
|
| 1181 | + "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
| 1182 | + $rpoint, |
|
| 1183 | + $rlength |
|
| 1184 | + ); |
|
| 1185 | + $error .= PHP_EOL; |
|
| 1186 | + } |
|
| 1187 | + } |
|
| 1188 | + $error .= '</pre>'; |
|
| 1189 | + return $error; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + |
|
| 1193 | + /** |
|
| 1194 | + * Saves an array of settings used for configuring aspects of session behaviour |
|
| 1195 | + * |
|
| 1196 | + * @param array $updated_settings |
|
| 1197 | + */ |
|
| 1198 | + private function updateSessionSettings(array $updated_settings = array()) |
|
| 1199 | + { |
|
| 1200 | + // add existing settings, but only if not included in incoming $updated_settings array |
|
| 1201 | + $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 1202 | + update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + |
|
| 1206 | + /** |
|
| 1207 | + * garbage_collection |
|
| 1208 | + */ |
|
| 1209 | + public function garbageCollection() |
|
| 1210 | + { |
|
| 1211 | + // only perform during regular requests if last garbage collection was over an hour ago |
|
| 1212 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1213 | + $this->_last_gc = time(); |
|
| 1214 | + $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
| 1215 | + /** @type WPDB $wpdb */ |
|
| 1216 | + global $wpdb; |
|
| 1217 | + // filter the query limit. Set to 0 to turn off garbage collection |
|
| 1218 | + $expired_session_transient_delete_query_limit = absint( |
|
| 1219 | + apply_filters( |
|
| 1220 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1221 | + 50 |
|
| 1222 | + ) |
|
| 1223 | + ); |
|
| 1224 | + // non-zero LIMIT means take out the trash |
|
| 1225 | + if ($expired_session_transient_delete_query_limit) { |
|
| 1226 | + $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
| 1227 | + $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
| 1228 | + // since transient expiration timestamps are set in the future, we can compare against NOW |
|
| 1229 | + // but we only want to pick up any trash that's been around for more than a day |
|
| 1230 | + $expiration = time() - DAY_IN_SECONDS; |
|
| 1231 | + $SQL = " |
|
| 1232 | 1232 | SELECT option_name |
| 1233 | 1233 | FROM {$wpdb->options} |
| 1234 | 1234 | WHERE |
@@ -1237,19 +1237,19 @@ discard block |
||
| 1237 | 1237 | AND option_value < {$expiration} |
| 1238 | 1238 | LIMIT {$expired_session_transient_delete_query_limit} |
| 1239 | 1239 | "; |
| 1240 | - // produces something like: |
|
| 1241 | - // SELECT option_name FROM wp_options |
|
| 1242 | - // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
| 1243 | - // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
| 1244 | - // AND option_value < 1508368198 LIMIT 50 |
|
| 1245 | - $expired_sessions = $wpdb->get_col($SQL); |
|
| 1246 | - // valid results? |
|
| 1247 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1248 | - $this->cache_storage->deleteMany($expired_sessions, true); |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - } |
|
| 1252 | - } |
|
| 1240 | + // produces something like: |
|
| 1241 | + // SELECT option_name FROM wp_options |
|
| 1242 | + // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
| 1243 | + // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
| 1244 | + // AND option_value < 1508368198 LIMIT 50 |
|
| 1245 | + $expired_sessions = $wpdb->get_col($SQL); |
|
| 1246 | + // valid results? |
|
| 1247 | + if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1248 | + $this->cache_storage->deleteMany($expired_sessions, true); |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1251 | + } |
|
| 1252 | + } |
|
| 1253 | 1253 | |
| 1254 | 1254 | |
| 1255 | 1255 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | // check if class object is instantiated |
| 187 | 187 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
| 188 | 188 | // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
| 189 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 189 | + if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 190 | 190 | self::$_instance = new self( |
| 191 | 191 | $cache_storage, |
| 192 | 192 | $lifespan, |
@@ -219,21 +219,21 @@ discard block |
||
| 219 | 219 | // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
| 220 | 220 | // (which currently fires on the init hook at priority 9), |
| 221 | 221 | // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
| 222 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 222 | + if ( ! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 223 | 223 | return; |
| 224 | 224 | } |
| 225 | 225 | $this->session_lifespan = $lifespan; |
| 226 | 226 | $this->request = $request; |
| 227 | - if (! defined('ESPRESSO_SESSION')) { |
|
| 227 | + if ( ! defined('ESPRESSO_SESSION')) { |
|
| 228 | 228 | define('ESPRESSO_SESSION', true); |
| 229 | 229 | } |
| 230 | 230 | // retrieve session options from db |
| 231 | 231 | $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
| 232 | - if (! empty($session_settings)) { |
|
| 232 | + if ( ! empty($session_settings)) { |
|
| 233 | 233 | // cycle though existing session options |
| 234 | 234 | foreach ($session_settings as $var_name => $session_setting) { |
| 235 | 235 | // set values for class properties |
| 236 | - $var_name = '_' . $var_name; |
|
| 236 | + $var_name = '_'.$var_name; |
|
| 237 | 237 | $this->{$var_name} = $session_setting; |
| 238 | 238 | } |
| 239 | 239 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | public function open_session() |
| 295 | 295 | { |
| 296 | 296 | // check for existing session and retrieve it from db |
| 297 | - if (! $this->_espresso_session()) { |
|
| 297 | + if ( ! $this->_espresso_session()) { |
|
| 298 | 298 | // or just start a new one |
| 299 | 299 | $this->_create_espresso_session(); |
| 300 | 300 | } |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | */ |
| 347 | 347 | public function extend_expiration($time = 0) |
| 348 | 348 | { |
| 349 | - $time = $time ? $time : $this->extension(); |
|
| 349 | + $time = $time ? $time : $this->extension(); |
|
| 350 | 350 | $this->_expiration += absint($time); |
| 351 | 351 | } |
| 352 | 352 | |
@@ -373,9 +373,9 @@ discard block |
||
| 373 | 373 | // set some defaults |
| 374 | 374 | foreach ($this->_default_session_vars as $key => $default_var) { |
| 375 | 375 | if (is_array($default_var)) { |
| 376 | - $this->_session_data[ $key ] = array(); |
|
| 376 | + $this->_session_data[$key] = array(); |
|
| 377 | 377 | } else { |
| 378 | - $this->_session_data[ $key ] = ''; |
|
| 378 | + $this->_session_data[$key] = ''; |
|
| 379 | 379 | } |
| 380 | 380 | } |
| 381 | 381 | } |
@@ -516,8 +516,8 @@ discard block |
||
| 516 | 516 | $this->reset_checkout(); |
| 517 | 517 | $this->reset_transaction(); |
| 518 | 518 | } |
| 519 | - if (! empty($key)) { |
|
| 520 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
| 519 | + if ( ! empty($key)) { |
|
| 520 | + return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null; |
|
| 521 | 521 | } |
| 522 | 522 | return $this->_session_data; |
| 523 | 523 | } |
@@ -539,12 +539,12 @@ discard block |
||
| 539 | 539 | return false; |
| 540 | 540 | } |
| 541 | 541 | foreach ($data as $key => $value) { |
| 542 | - if (isset($this->_default_session_vars[ $key ])) { |
|
| 542 | + if (isset($this->_default_session_vars[$key])) { |
|
| 543 | 543 | EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
| 544 | 544 | 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__); |
| 545 | 545 | return false; |
| 546 | 546 | } |
| 547 | - $this->_session_data[ $key ] = $value; |
|
| 547 | + $this->_session_data[$key] = $value; |
|
| 548 | 548 | } |
| 549 | 549 | return true; |
| 550 | 550 | } |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | $this->_user_agent = $this->request->userAgent(); |
| 579 | 579 | // now let's retrieve what's in the db |
| 580 | 580 | $session_data = $this->_retrieve_session_data(); |
| 581 | - if (! empty($session_data)) { |
|
| 581 | + if ( ! empty($session_data)) { |
|
| 582 | 582 | // get the current time in UTC |
| 583 | 583 | $this->_time = $this->_time !== null ? $this->_time : time(); |
| 584 | 584 | // and reset the session expiration |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | // set initial site access time and the session expiration |
| 590 | 590 | $this->_set_init_access_and_expiration(); |
| 591 | 591 | // set referer |
| 592 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
| 592 | + $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER']) |
|
| 593 | 593 | ? esc_attr($_SERVER['HTTP_REFERER']) |
| 594 | 594 | : ''; |
| 595 | 595 | // no previous session = go back and create one (on top of the data above) |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | */ |
| 628 | 628 | protected function _retrieve_session_data() |
| 629 | 629 | { |
| 630 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 630 | + $ssn_key = EE_Session::session_id_prefix.$this->_sid; |
|
| 631 | 631 | try { |
| 632 | 632 | // we're using WP's Transient API to store session data using the PHP session ID as the option name |
| 633 | 633 | $session_data = $this->cache_storage->get($ssn_key, false); |
@@ -636,7 +636,7 @@ discard block |
||
| 636 | 636 | } |
| 637 | 637 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
| 638 | 638 | $hash_check = $this->cache_storage->get( |
| 639 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 639 | + EE_Session::hash_check_prefix.$this->_sid, |
|
| 640 | 640 | false |
| 641 | 641 | ); |
| 642 | 642 | if ($hash_check && $hash_check !== md5($session_data)) { |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
| 647 | 647 | 'event_espresso' |
| 648 | 648 | ), |
| 649 | - EE_Session::session_id_prefix . $this->_sid |
|
| 649 | + EE_Session::session_id_prefix.$this->_sid |
|
| 650 | 650 | ), |
| 651 | 651 | __FILE__, __FUNCTION__, __LINE__ |
| 652 | 652 | ); |
@@ -655,21 +655,21 @@ discard block |
||
| 655 | 655 | } catch (Exception $e) { |
| 656 | 656 | // let's just eat that error for now and attempt to correct any corrupted data |
| 657 | 657 | global $wpdb; |
| 658 | - $row = $wpdb->get_row( |
|
| 658 | + $row = $wpdb->get_row( |
|
| 659 | 659 | $wpdb->prepare( |
| 660 | 660 | "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
| 661 | - '_transient_' . $ssn_key |
|
| 661 | + '_transient_'.$ssn_key |
|
| 662 | 662 | ) |
| 663 | 663 | ); |
| 664 | 664 | $session_data = is_object($row) ? $row->option_value : null; |
| 665 | 665 | if ($session_data) { |
| 666 | 666 | $session_data = preg_replace_callback( |
| 667 | 667 | '!s:(d+):"(.*?)";!', |
| 668 | - function ($match) |
|
| 668 | + function($match) |
|
| 669 | 669 | { |
| 670 | 670 | return $match[1] === strlen($match[2]) |
| 671 | 671 | ? $match[0] |
| 672 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 672 | + : 's:'.strlen($match[2]).':"'.$match[2].'";'; |
|
| 673 | 673 | }, |
| 674 | 674 | $session_data |
| 675 | 675 | ); |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | $session_data = $this->encryption instanceof EE_Encryption |
| 681 | 681 | ? $this->encryption->base64_string_decode($session_data) |
| 682 | 682 | : $session_data; |
| 683 | - if (! is_array($session_data)) { |
|
| 683 | + if ( ! is_array($session_data)) { |
|
| 684 | 684 | try { |
| 685 | 685 | $session_data = maybe_unserialize($session_data); |
| 686 | 686 | } catch (Exception $e) { |
@@ -694,21 +694,21 @@ discard block |
||
| 694 | 694 | . '</pre><br>' |
| 695 | 695 | . $this->find_serialize_error($session_data) |
| 696 | 696 | : ''; |
| 697 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 697 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
| 698 | 698 | throw new InvalidSessionDataException($msg, 0, $e); |
| 699 | 699 | } |
| 700 | 700 | } |
| 701 | 701 | // just a check to make sure the session array is indeed an array |
| 702 | - if (! is_array($session_data)) { |
|
| 702 | + if ( ! is_array($session_data)) { |
|
| 703 | 703 | // no?!?! then something is wrong |
| 704 | 704 | $msg = esc_html__( |
| 705 | 705 | 'The session data is missing, invalid, or corrupted.', |
| 706 | 706 | 'event_espresso' |
| 707 | 707 | ); |
| 708 | 708 | $msg .= WP_DEBUG |
| 709 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 709 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
| 710 | 710 | : ''; |
| 711 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 711 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
| 712 | 712 | throw new InvalidSessionDataException($msg); |
| 713 | 713 | } |
| 714 | 714 | if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | if (isset($_REQUEST['EESID'])) { |
| 737 | 737 | $session_id = sanitize_text_field($_REQUEST['EESID']); |
| 738 | 738 | } else { |
| 739 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
| 739 | + $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt()); |
|
| 740 | 740 | } |
| 741 | 741 | return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
| 742 | 742 | } |
@@ -844,19 +844,19 @@ discard block |
||
| 844 | 844 | $page_visit = $this->_get_page_visit(); |
| 845 | 845 | if ($page_visit) { |
| 846 | 846 | // set pages visited where the first will be the http referrer |
| 847 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
| 847 | + $this->_session_data['pages_visited'][$this->_time] = $page_visit; |
|
| 848 | 848 | // we'll only save the last 10 page visits. |
| 849 | 849 | $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
| 850 | 850 | } |
| 851 | 851 | break; |
| 852 | 852 | default : |
| 853 | 853 | // carry any other data over |
| 854 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
| 854 | + $session_data[$key] = $this->_session_data[$key]; |
|
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | $this->_session_data = $session_data; |
| 858 | 858 | // creating a new session does not require saving to the db just yet |
| 859 | - if (! $new_session) { |
|
| 859 | + if ( ! $new_session) { |
|
| 860 | 860 | // ready? let's save |
| 861 | 861 | if ($this->_save_session_to_db()) { |
| 862 | 862 | return true; |
@@ -901,12 +901,12 @@ discard block |
||
| 901 | 901 | { |
| 902 | 902 | // don't save sessions for crawlers |
| 903 | 903 | // and unless we're deleting the session data, don't save anything if there isn't a cart |
| 904 | - if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 904 | + if ($this->request->isBot() || ( ! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 905 | 905 | return false; |
| 906 | 906 | } |
| 907 | 907 | $transaction = $this->transaction(); |
| 908 | 908 | if ($transaction instanceof EE_Transaction) { |
| 909 | - if (! $transaction->ID()) { |
|
| 909 | + if ( ! $transaction->ID()) { |
|
| 910 | 910 | $transaction->save(); |
| 911 | 911 | } |
| 912 | 912 | $this->_session_data['transaction'] = $transaction->ID(); |
@@ -920,14 +920,14 @@ discard block |
||
| 920 | 920 | // maybe save hash check |
| 921 | 921 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
| 922 | 922 | $this->cache_storage->add( |
| 923 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 923 | + EE_Session::hash_check_prefix.$this->_sid, |
|
| 924 | 924 | md5($session_data), |
| 925 | 925 | $this->session_lifespan->inSeconds() |
| 926 | 926 | ); |
| 927 | 927 | } |
| 928 | 928 | // we're using the Transient API for storing session data, |
| 929 | 929 | return $this->cache_storage->add( |
| 930 | - EE_Session::session_id_prefix . $this->_sid, |
|
| 930 | + EE_Session::session_id_prefix.$this->_sid, |
|
| 931 | 931 | $session_data, |
| 932 | 932 | $this->session_lifespan->inSeconds() |
| 933 | 933 | ); |
@@ -941,7 +941,7 @@ discard block |
||
| 941 | 941 | */ |
| 942 | 942 | public function _get_page_visit() |
| 943 | 943 | { |
| 944 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
| 944 | + $page_visit = home_url('/').'wp-admin/admin-ajax.php'; |
|
| 945 | 945 | // check for request url |
| 946 | 946 | if (isset($_SERVER['REQUEST_URI'])) { |
| 947 | 947 | $http_host = ''; |
@@ -957,14 +957,14 @@ discard block |
||
| 957 | 957 | // check for page_id in SERVER REQUEST |
| 958 | 958 | if (isset($_REQUEST['page_id'])) { |
| 959 | 959 | // rebuild $e_reg without any of the extra parameters |
| 960 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
| 960 | + $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&'; |
|
| 961 | 961 | } |
| 962 | 962 | // check for $e_reg in SERVER REQUEST |
| 963 | 963 | if (isset($_REQUEST['ee'])) { |
| 964 | 964 | // rebuild $e_reg without any of the extra parameters |
| 965 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
| 965 | + $e_reg = 'ee='.esc_attr($_REQUEST['ee']); |
|
| 966 | 966 | } |
| 967 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
| 967 | + $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?'); |
|
| 968 | 968 | } |
| 969 | 969 | return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
| 970 | 970 | } |
@@ -999,7 +999,7 @@ discard block |
||
| 999 | 999 | */ |
| 1000 | 1000 | public function clear_session($class = '', $function = '') |
| 1001 | 1001 | { |
| 1002 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
| 1002 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()'); |
|
| 1003 | 1003 | $this->reset_cart(); |
| 1004 | 1004 | $this->reset_checkout(); |
| 1005 | 1005 | $this->reset_transaction(); |
@@ -1021,7 +1021,7 @@ discard block |
||
| 1021 | 1021 | public function reset_data($data_to_reset = array(), $show_all_notices = false) |
| 1022 | 1022 | { |
| 1023 | 1023 | // if $data_to_reset is not in an array, then put it in one |
| 1024 | - if (! is_array($data_to_reset)) { |
|
| 1024 | + if ( ! is_array($data_to_reset)) { |
|
| 1025 | 1025 | $data_to_reset = array($data_to_reset); |
| 1026 | 1026 | } |
| 1027 | 1027 | // nothing ??? go home! |
@@ -1035,11 +1035,11 @@ discard block |
||
| 1035 | 1035 | foreach ($data_to_reset as $reset) { |
| 1036 | 1036 | |
| 1037 | 1037 | // first check to make sure it is a valid session var |
| 1038 | - if (isset($this->_session_data[ $reset ])) { |
|
| 1038 | + if (isset($this->_session_data[$reset])) { |
|
| 1039 | 1039 | // then check to make sure it is not a default var |
| 1040 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1040 | + if ( ! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1041 | 1041 | // remove session var |
| 1042 | - unset($this->_session_data[ $reset ]); |
|
| 1042 | + unset($this->_session_data[$reset]); |
|
| 1043 | 1043 | if ($show_all_notices) { |
| 1044 | 1044 | EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
| 1045 | 1045 | $reset), __FILE__, __FUNCTION__, __LINE__); |
@@ -1116,7 +1116,7 @@ discard block |
||
| 1116 | 1116 | // or use that for the new transient cleanup query limit |
| 1117 | 1117 | add_filter( |
| 1118 | 1118 | 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
| 1119 | - function () use ($expired_session_transient_delete_query_limit) |
|
| 1119 | + function() use ($expired_session_transient_delete_query_limit) |
|
| 1120 | 1120 | { |
| 1121 | 1121 | return $expired_session_transient_delete_query_limit; |
| 1122 | 1122 | } |
@@ -1136,7 +1136,7 @@ discard block |
||
| 1136 | 1136 | $error = '<pre>'; |
| 1137 | 1137 | $data2 = preg_replace_callback( |
| 1138 | 1138 | '!s:(\d+):"(.*?)";!', |
| 1139 | - function ($match) |
|
| 1139 | + function($match) |
|
| 1140 | 1140 | { |
| 1141 | 1141 | return ($match[1] === strlen($match[2])) |
| 1142 | 1142 | ? $match[0] |
@@ -1148,14 +1148,14 @@ discard block |
||
| 1148 | 1148 | }, |
| 1149 | 1149 | $data1 |
| 1150 | 1150 | ); |
| 1151 | - $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1152 | - $error .= $data1 . PHP_EOL; |
|
| 1153 | - $error .= $data2 . PHP_EOL; |
|
| 1151 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1152 | + $error .= $data1.PHP_EOL; |
|
| 1153 | + $error .= $data2.PHP_EOL; |
|
| 1154 | 1154 | for ($i = 0; $i < $max; $i++) { |
| 1155 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
| 1156 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
| 1157 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
| 1158 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
| 1155 | + if (@$data1[$i] !== @$data2[$i]) { |
|
| 1156 | + $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL; |
|
| 1157 | + $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL; |
|
| 1158 | + $error .= "\t-> Line Number = $i".PHP_EOL; |
|
| 1159 | 1159 | $start = ($i - 20); |
| 1160 | 1160 | $start = ($start < 0) ? 0 : $start; |
| 1161 | 1161 | $length = 40; |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | $error .= "\t-> Section Data1 = "; |
| 1171 | 1171 | $error .= substr_replace( |
| 1172 | 1172 | substr($data1, $start, $length), |
| 1173 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
| 1173 | + "<b style=\"color:green\">{$data1[$i]}</b>", |
|
| 1174 | 1174 | $rpoint, |
| 1175 | 1175 | $rlength |
| 1176 | 1176 | ); |
@@ -1178,7 +1178,7 @@ discard block |
||
| 1178 | 1178 | $error .= "\t-> Section Data2 = "; |
| 1179 | 1179 | $error .= substr_replace( |
| 1180 | 1180 | substr($data2, $start, $length), |
| 1181 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
| 1181 | + "<b style=\"color:red\">{$data2[$i]}</b>", |
|
| 1182 | 1182 | $rpoint, |
| 1183 | 1183 | $rlength |
| 1184 | 1184 | ); |
@@ -1209,7 +1209,7 @@ discard block |
||
| 1209 | 1209 | public function garbageCollection() |
| 1210 | 1210 | { |
| 1211 | 1211 | // only perform during regular requests if last garbage collection was over an hour ago |
| 1212 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1212 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1213 | 1213 | $this->_last_gc = time(); |
| 1214 | 1214 | $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
| 1215 | 1215 | /** @type WPDB $wpdb */ |
@@ -1244,7 +1244,7 @@ discard block |
||
| 1244 | 1244 | // AND option_value < 1508368198 LIMIT 50 |
| 1245 | 1245 | $expired_sessions = $wpdb->get_col($SQL); |
| 1246 | 1246 | // valid results? |
| 1247 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1247 | + if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1248 | 1248 | $this->cache_storage->deleteMany($expired_sessions, true); |
| 1249 | 1249 | } |
| 1250 | 1250 | } |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | default : |
| 103 | 103 | $to = get_option('admin_email'); |
| 104 | 104 | } |
| 105 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 105 | + $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url(); |
|
| 106 | 106 | $msg = EE_Error::_format_error($type, $message, $file, $line); |
| 107 | 107 | if (function_exists('wp_mail')) { |
| 108 | 108 | add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
| 109 | 109 | wp_mail($to, $subject, $msg); |
| 110 | 110 | } |
| 111 | 111 | echo '<div id="message" class="espresso-notices error"><p>'; |
| 112 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 112 | + echo $type.': '.$message.'<br />'.$file.' line '.$line; |
|
| 113 | 113 | echo '<br /></p></div>'; |
| 114 | 114 | } |
| 115 | 115 | |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | </style> |
| 336 | 336 | <div id="ee-error-message" class="error">'; |
| 337 | - if (! WP_DEBUG) { |
|
| 337 | + if ( ! WP_DEBUG) { |
|
| 338 | 338 | $output .= ' |
| 339 | 339 | <p>'; |
| 340 | 340 | } |
@@ -393,14 +393,14 @@ discard block |
||
| 393 | 393 | $class_dsply = ! empty($class) ? $class : ' '; |
| 394 | 394 | $type_dsply = ! empty($type) ? $type : ' '; |
| 395 | 395 | $function_dsply = ! empty($function) ? $function : ' '; |
| 396 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 396 | + $args_dsply = ! empty($args) ? '( '.$args.' )' : ''; |
|
| 397 | 397 | $trace_details .= ' |
| 398 | 398 | <tr> |
| 399 | - <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
|
| 400 | - <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
|
| 401 | - <td align="left" class="' . $zebra . '">' . $file_dsply . '</td> |
|
| 402 | - <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
|
| 403 | - <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
|
| 399 | + <td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td> |
|
| 400 | + <td align="right" class="' . $zebra.'">'.$line_dsply.'</td> |
|
| 401 | + <td align="left" class="' . $zebra.'">'.$file_dsply.'</td> |
|
| 402 | + <td align="left" class="' . $zebra.'">'.$class_dsply.'</td> |
|
| 403 | + <td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td> |
|
| 404 | 404 | </tr>'; |
| 405 | 405 | } |
| 406 | 406 | $trace_details .= ' |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | } |
| 410 | 410 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
| 411 | 411 | // add generic non-identifying messages for non-privileged users |
| 412 | - if (! WP_DEBUG) { |
|
| 412 | + if ( ! WP_DEBUG) { |
|
| 413 | 413 | $output .= '<span class="ee-error-user-msg-spn">' |
| 414 | 414 | . trim($ex['msg']) |
| 415 | 415 | . '</span> <sup>' |
@@ -451,14 +451,14 @@ discard block |
||
| 451 | 451 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
| 452 | 452 | ' |
| 453 | 453 | . $trace_details; |
| 454 | - if (! empty($class)) { |
|
| 454 | + if ( ! empty($class)) { |
|
| 455 | 455 | $output .= ' |
| 456 | 456 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
| 457 | 457 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
| 458 | 458 | <h3>Class Details</h3>'; |
| 459 | 459 | $a = new ReflectionClass($class); |
| 460 | 460 | $output .= ' |
| 461 | - <pre>' . $a . '</pre> |
|
| 461 | + <pre>' . $a.'</pre> |
|
| 462 | 462 | </div> |
| 463 | 463 | </div>'; |
| 464 | 464 | } |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | } |
| 472 | 472 | // remove last linebreak |
| 473 | 473 | $output = substr($output, 0, -6); |
| 474 | - if (! WP_DEBUG) { |
|
| 474 | + if ( ! WP_DEBUG) { |
|
| 475 | 475 | $output .= ' |
| 476 | 476 | </p>'; |
| 477 | 477 | } |
@@ -498,20 +498,20 @@ discard block |
||
| 498 | 498 | private function _convert_args_to_string($arguments = array(), $array = false) |
| 499 | 499 | { |
| 500 | 500 | $arg_string = ''; |
| 501 | - if (! empty($arguments)) { |
|
| 501 | + if ( ! empty($arguments)) { |
|
| 502 | 502 | $args = array(); |
| 503 | 503 | foreach ($arguments as $arg) { |
| 504 | - if (! empty($arg)) { |
|
| 504 | + if ( ! empty($arg)) { |
|
| 505 | 505 | if (is_string($arg)) { |
| 506 | - $args[] = " '" . $arg . "'"; |
|
| 506 | + $args[] = " '".$arg."'"; |
|
| 507 | 507 | } elseif (is_array($arg)) { |
| 508 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 508 | + $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true); |
|
| 509 | 509 | } elseif ($arg === null) { |
| 510 | 510 | $args[] = ' NULL'; |
| 511 | 511 | } elseif (is_bool($arg)) { |
| 512 | 512 | $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
| 513 | 513 | } elseif (is_object($arg)) { |
| 514 | - $args[] = ' OBJECT ' . get_class($arg); |
|
| 514 | + $args[] = ' OBJECT '.get_class($arg); |
|
| 515 | 515 | } elseif (is_resource($arg)) { |
| 516 | 516 | $args[] = get_resource_type($arg); |
| 517 | 517 | } else { |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | { |
| 615 | 615 | if (empty($msg)) { |
| 616 | 616 | EE_Error::doing_it_wrong( |
| 617 | - 'EE_Error::add_' . $type . '()', |
|
| 617 | + 'EE_Error::add_'.$type.'()', |
|
| 618 | 618 | sprintf( |
| 619 | 619 | __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
| 620 | 620 | 'event_espresso'), |
@@ -650,11 +650,11 @@ discard block |
||
| 650 | 650 | do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
| 651 | 651 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
| 652 | 652 | // add notice if message exists |
| 653 | - if (! empty($msg)) { |
|
| 653 | + if ( ! empty($msg)) { |
|
| 654 | 654 | // get error code |
| 655 | 655 | $notice_code = EE_Error::generate_error_code($file, $func, $line); |
| 656 | 656 | if (WP_DEBUG && $type === 'errors') { |
| 657 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 657 | + $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>'; |
|
| 658 | 658 | } |
| 659 | 659 | // add notice. Index by code if it's not blank |
| 660 | 660 | if ($notice_code) { |
@@ -868,13 +868,13 @@ discard block |
||
| 868 | 868 | if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
| 869 | 869 | // combine messages |
| 870 | 870 | $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
| 871 | - $print_scripts = true; |
|
| 871 | + $print_scripts = true; |
|
| 872 | 872 | } |
| 873 | 873 | // check for attention messages |
| 874 | 874 | if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
| 875 | 875 | // combine messages |
| 876 | 876 | $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
| 877 | - $print_scripts = true; |
|
| 877 | + $print_scripts = true; |
|
| 878 | 878 | } |
| 879 | 879 | // check for error messages |
| 880 | 880 | if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | : __('An error has occurred:<br />', 'event_espresso'); |
| 884 | 884 | // combine messages |
| 885 | 885 | $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
| 886 | - $print_scripts = true; |
|
| 886 | + $print_scripts = true; |
|
| 887 | 887 | } |
| 888 | 888 | if ($format_output) { |
| 889 | 889 | $notices = EE_Error::formatNoticesOutput( |
@@ -924,16 +924,16 @@ discard block |
||
| 924 | 924 | $print_scripts = false; |
| 925 | 925 | // grab any notices that have been previously saved |
| 926 | 926 | $notices = EE_Error::getStoredNotices(); |
| 927 | - if (! empty($notices)) { |
|
| 927 | + if ( ! empty($notices)) { |
|
| 928 | 928 | foreach ($notices as $type => $notice) { |
| 929 | 929 | if (is_array($notice) && ! empty($notice)) { |
| 930 | 930 | // make sure that existing notice type is an array |
| 931 | - self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
| 932 | - && ! empty(self::$_espresso_notices[ $type ]) |
|
| 933 | - ? self::$_espresso_notices[ $type ] |
|
| 931 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
| 932 | + && ! empty(self::$_espresso_notices[$type]) |
|
| 933 | + ? self::$_espresso_notices[$type] |
|
| 934 | 934 | : array(); |
| 935 | 935 | // add newly created notices to existing ones |
| 936 | - self::$_espresso_notices[ $type ] += $notice; |
|
| 936 | + self::$_espresso_notices[$type] += $notice; |
|
| 937 | 937 | $print_scripts = true; |
| 938 | 938 | } |
| 939 | 939 | } |
@@ -960,10 +960,10 @@ discard block |
||
| 960 | 960 | $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
| 961 | 961 | $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
| 962 | 962 | //showMessage( $success_messages ); |
| 963 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 964 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 963 | + $notices .= '<div id="'.$css_id.'" ' |
|
| 964 | + . 'class="espresso-notices '.$css_class.'" ' |
|
| 965 | 965 | . 'style="display:none;">' |
| 966 | - . '<p>' . $success_messages . '</p>' |
|
| 966 | + . '<p>'.$success_messages.'</p>' |
|
| 967 | 967 | . $close |
| 968 | 968 | . '</div>'; |
| 969 | 969 | } |
@@ -971,10 +971,10 @@ discard block |
||
| 971 | 971 | $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
| 972 | 972 | $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
| 973 | 973 | //showMessage( $error_messages, TRUE ); |
| 974 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 975 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 974 | + $notices .= '<div id="'.$css_id.'" ' |
|
| 975 | + . 'class="espresso-notices '.$css_class.'" ' |
|
| 976 | 976 | . 'style="display:none;">' |
| 977 | - . '<p>' . $attention_messages . '</p>' |
|
| 977 | + . '<p>'.$attention_messages.'</p>' |
|
| 978 | 978 | . $close |
| 979 | 979 | . '</div>'; |
| 980 | 980 | } |
@@ -982,10 +982,10 @@ discard block |
||
| 982 | 982 | $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
| 983 | 983 | $css_class = is_admin() ? 'error' : 'error fade-away'; |
| 984 | 984 | //showMessage( $error_messages, TRUE ); |
| 985 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 986 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 985 | + $notices .= '<div id="'.$css_id.'" ' |
|
| 986 | + . 'class="espresso-notices '.$css_class.'" ' |
|
| 987 | 987 | . 'style="display:none;">' |
| 988 | - . '<p>' . $error_messages . '</p>' |
|
| 988 | + . '<p>'.$error_messages.'</p>' |
|
| 989 | 989 | . $close |
| 990 | 990 | . '</div>'; |
| 991 | 991 | } |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | */ |
| 1004 | 1004 | private static function _print_scripts($force_print = false) |
| 1005 | 1005 | { |
| 1006 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1006 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1007 | 1007 | if (wp_script_is('ee_error_js', 'enqueued')) { |
| 1008 | 1008 | return ''; |
| 1009 | 1009 | } |
@@ -1017,12 +1017,12 @@ discard block |
||
| 1017 | 1017 | return ' |
| 1018 | 1018 | <script> |
| 1019 | 1019 | /* <![CDATA[ */ |
| 1020 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
| 1020 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
| 1021 | 1021 | /* ]]> */ |
| 1022 | 1022 | </script> |
| 1023 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
| 1024 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
| 1025 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
| 1023 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
| 1024 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
| 1025 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
| 1026 | 1026 | '; |
| 1027 | 1027 | } |
| 1028 | 1028 | return ''; |
@@ -1053,8 +1053,8 @@ discard block |
||
| 1053 | 1053 | { |
| 1054 | 1054 | $file = explode('.', basename($file)); |
| 1055 | 1055 | $error_code = ! empty($file[0]) ? $file[0] : ''; |
| 1056 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1057 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1056 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
| 1057 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
| 1058 | 1058 | return $error_code; |
| 1059 | 1059 | } |
| 1060 | 1060 | |
@@ -1074,18 +1074,18 @@ discard block |
||
| 1074 | 1074 | if (empty($ex)) { |
| 1075 | 1075 | return; |
| 1076 | 1076 | } |
| 1077 | - if (! $time) { |
|
| 1077 | + if ( ! $time) { |
|
| 1078 | 1078 | $time = time(); |
| 1079 | 1079 | } |
| 1080 | 1080 | $exception_log = '----------------------------------------------------------------------------------------' |
| 1081 | 1081 | . PHP_EOL; |
| 1082 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1083 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1084 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1085 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1086 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1087 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1088 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1082 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
| 1083 | + $exception_log .= 'Message: '.$ex['msg'].PHP_EOL; |
|
| 1084 | + $exception_log .= 'Code: '.$ex['code'].PHP_EOL; |
|
| 1085 | + $exception_log .= 'File: '.$ex['file'].PHP_EOL; |
|
| 1086 | + $exception_log .= 'Line No: '.$ex['line'].PHP_EOL; |
|
| 1087 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
| 1088 | + $exception_log .= $ex['string'].PHP_EOL; |
|
| 1089 | 1089 | $exception_log .= '----------------------------------------------------------------------------------------' |
| 1090 | 1090 | . PHP_EOL; |
| 1091 | 1091 | try { |
@@ -1258,14 +1258,14 @@ discard block |
||
| 1258 | 1258 | // js for error handling |
| 1259 | 1259 | wp_register_script( |
| 1260 | 1260 | 'espresso_core', |
| 1261 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1261 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 1262 | 1262 | array('jquery'), |
| 1263 | 1263 | EVENT_ESPRESSO_VERSION, |
| 1264 | 1264 | false |
| 1265 | 1265 | ); |
| 1266 | 1266 | wp_register_script( |
| 1267 | 1267 | 'ee_error_js', |
| 1268 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1268 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
| 1269 | 1269 | array('espresso_core'), |
| 1270 | 1270 | EVENT_ESPRESSO_VERSION, |
| 1271 | 1271 | false |
@@ -11,8 +11,8 @@ discard block |
||
| 11 | 11 | // if you're a dev and want to receive all errors via email |
| 12 | 12 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
| 13 | 13 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
| 14 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
| 15 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
| 14 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
| 15 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | |
@@ -27,258 +27,258 @@ discard block |
||
| 27 | 27 | class EE_Error extends Exception |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * name of the file to log exceptions to |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * stores details for all exception |
|
| 42 | - * |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - private static $_all_exceptions = array(); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * tracks number of errors |
|
| 49 | - * |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 52 | - private static $_error_count = 0; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var array $_espresso_notices |
|
| 56 | - */ |
|
| 57 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @override default exception handling |
|
| 63 | - * @param string $message |
|
| 64 | - * @param int $code |
|
| 65 | - * @param Exception|null $previous |
|
| 66 | - */ |
|
| 67 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
| 68 | - { |
|
| 69 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
| 70 | - parent::__construct($message, $code); |
|
| 71 | - } else { |
|
| 72 | - parent::__construct($message, $code, $previous); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * error_handler |
|
| 79 | - * |
|
| 80 | - * @param $code |
|
| 81 | - * @param $message |
|
| 82 | - * @param $file |
|
| 83 | - * @param $line |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public static function error_handler($code, $message, $file, $line) |
|
| 87 | - { |
|
| 88 | - $type = EE_Error::error_type($code); |
|
| 89 | - $site = site_url(); |
|
| 90 | - switch ($site) { |
|
| 91 | - case 'http://ee4.eventespresso.com/' : |
|
| 92 | - case 'http://ee4decaf.eventespresso.com/' : |
|
| 93 | - case 'http://ee4hf.eventespresso.com/' : |
|
| 94 | - case 'http://ee4a.eventespresso.com/' : |
|
| 95 | - case 'http://ee4ad.eventespresso.com/' : |
|
| 96 | - case 'http://ee4b.eventespresso.com/' : |
|
| 97 | - case 'http://ee4bd.eventespresso.com/' : |
|
| 98 | - case 'http://ee4d.eventespresso.com/' : |
|
| 99 | - case 'http://ee4dd.eventespresso.com/' : |
|
| 100 | - $to = '[email protected]'; |
|
| 101 | - break; |
|
| 102 | - default : |
|
| 103 | - $to = get_option('admin_email'); |
|
| 104 | - } |
|
| 105 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 106 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
| 107 | - if (function_exists('wp_mail')) { |
|
| 108 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 109 | - wp_mail($to, $subject, $msg); |
|
| 110 | - } |
|
| 111 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
| 112 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 113 | - echo '<br /></p></div>'; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * error_type |
|
| 120 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
| 121 | - * |
|
| 122 | - * @param $code |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - public static function error_type($code) |
|
| 126 | - { |
|
| 127 | - switch ($code) { |
|
| 128 | - case E_ERROR: // 1 // |
|
| 129 | - return 'E_ERROR'; |
|
| 130 | - case E_WARNING: // 2 // |
|
| 131 | - return 'E_WARNING'; |
|
| 132 | - case E_PARSE: // 4 // |
|
| 133 | - return 'E_PARSE'; |
|
| 134 | - case E_NOTICE: // 8 // |
|
| 135 | - return 'E_NOTICE'; |
|
| 136 | - case E_CORE_ERROR: // 16 // |
|
| 137 | - return 'E_CORE_ERROR'; |
|
| 138 | - case E_CORE_WARNING: // 32 // |
|
| 139 | - return 'E_CORE_WARNING'; |
|
| 140 | - case E_COMPILE_ERROR: // 64 // |
|
| 141 | - return 'E_COMPILE_ERROR'; |
|
| 142 | - case E_COMPILE_WARNING: // 128 // |
|
| 143 | - return 'E_COMPILE_WARNING'; |
|
| 144 | - case E_USER_ERROR: // 256 // |
|
| 145 | - return 'E_USER_ERROR'; |
|
| 146 | - case E_USER_WARNING: // 512 // |
|
| 147 | - return 'E_USER_WARNING'; |
|
| 148 | - case E_USER_NOTICE: // 1024 // |
|
| 149 | - return 'E_USER_NOTICE'; |
|
| 150 | - case E_STRICT: // 2048 // |
|
| 151 | - return 'E_STRICT'; |
|
| 152 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
| 153 | - return 'E_RECOVERABLE_ERROR'; |
|
| 154 | - case E_DEPRECATED: // 8192 // |
|
| 155 | - return 'E_DEPRECATED'; |
|
| 156 | - case E_USER_DEPRECATED: // 16384 // |
|
| 157 | - return 'E_USER_DEPRECATED'; |
|
| 158 | - case E_ALL: // 16384 // |
|
| 159 | - return 'E_ALL'; |
|
| 160 | - } |
|
| 161 | - return ''; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * fatal_error_handler |
|
| 168 | - * |
|
| 169 | - * @return void |
|
| 170 | - */ |
|
| 171 | - public static function fatal_error_handler() |
|
| 172 | - { |
|
| 173 | - $last_error = error_get_last(); |
|
| 174 | - if ($last_error['type'] === E_ERROR) { |
|
| 175 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * _format_error |
|
| 183 | - * |
|
| 184 | - * @param $code |
|
| 185 | - * @param $message |
|
| 186 | - * @param $file |
|
| 187 | - * @param $line |
|
| 188 | - * @return string |
|
| 189 | - */ |
|
| 190 | - private static function _format_error($code, $message, $file, $line) |
|
| 191 | - { |
|
| 192 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
| 193 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
| 194 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
| 195 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
| 196 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
| 197 | - $html .= '</tbody></table>'; |
|
| 198 | - return $html; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * set_content_type |
|
| 205 | - * |
|
| 206 | - * @param $content_type |
|
| 207 | - * @return string |
|
| 208 | - */ |
|
| 209 | - public static function set_content_type($content_type) |
|
| 210 | - { |
|
| 211 | - return 'text/html'; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @return void |
|
| 218 | - * @throws EE_Error |
|
| 219 | - * @throws ReflectionException |
|
| 220 | - */ |
|
| 221 | - public function get_error() |
|
| 222 | - { |
|
| 223 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
| 224 | - throw $this; |
|
| 225 | - } |
|
| 226 | - // get separate user and developer messages if they exist |
|
| 227 | - $msg = explode('||', $this->getMessage()); |
|
| 228 | - $user_msg = $msg[0]; |
|
| 229 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 230 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 231 | - // add details to _all_exceptions array |
|
| 232 | - $x_time = time(); |
|
| 233 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
| 234 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
| 235 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
| 236 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
| 237 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
| 238 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
| 239 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
| 240 | - self::$_error_count++; |
|
| 241 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
| 242 | - $this->display_errors(); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param bool $check_stored |
|
| 248 | - * @param string $type_to_check |
|
| 249 | - * @return bool |
|
| 250 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 251 | - * @throws \InvalidArgumentException |
|
| 252 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 253 | - * @throws InvalidInterfaceException |
|
| 254 | - */ |
|
| 255 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
| 256 | - { |
|
| 257 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
| 258 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
| 259 | - ? true |
|
| 260 | - : false; |
|
| 261 | - if ($check_stored && ! $has_error) { |
|
| 262 | - $notices = EE_Error::getStoredNotices(); |
|
| 263 | - foreach ($notices as $type => $notice) { |
|
| 264 | - if ($type === $type_to_check && $notice) { |
|
| 265 | - return true; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - return $has_error; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * @echo string |
|
| 276 | - * @throws \ReflectionException |
|
| 277 | - */ |
|
| 278 | - public function display_errors() |
|
| 279 | - { |
|
| 280 | - $trace_details = ''; |
|
| 281 | - $output = ' |
|
| 30 | + const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * name of the file to log exceptions to |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * stores details for all exception |
|
| 42 | + * |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + private static $_all_exceptions = array(); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * tracks number of errors |
|
| 49 | + * |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | + private static $_error_count = 0; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var array $_espresso_notices |
|
| 56 | + */ |
|
| 57 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @override default exception handling |
|
| 63 | + * @param string $message |
|
| 64 | + * @param int $code |
|
| 65 | + * @param Exception|null $previous |
|
| 66 | + */ |
|
| 67 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
| 68 | + { |
|
| 69 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
| 70 | + parent::__construct($message, $code); |
|
| 71 | + } else { |
|
| 72 | + parent::__construct($message, $code, $previous); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * error_handler |
|
| 79 | + * |
|
| 80 | + * @param $code |
|
| 81 | + * @param $message |
|
| 82 | + * @param $file |
|
| 83 | + * @param $line |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public static function error_handler($code, $message, $file, $line) |
|
| 87 | + { |
|
| 88 | + $type = EE_Error::error_type($code); |
|
| 89 | + $site = site_url(); |
|
| 90 | + switch ($site) { |
|
| 91 | + case 'http://ee4.eventespresso.com/' : |
|
| 92 | + case 'http://ee4decaf.eventespresso.com/' : |
|
| 93 | + case 'http://ee4hf.eventespresso.com/' : |
|
| 94 | + case 'http://ee4a.eventespresso.com/' : |
|
| 95 | + case 'http://ee4ad.eventespresso.com/' : |
|
| 96 | + case 'http://ee4b.eventespresso.com/' : |
|
| 97 | + case 'http://ee4bd.eventespresso.com/' : |
|
| 98 | + case 'http://ee4d.eventespresso.com/' : |
|
| 99 | + case 'http://ee4dd.eventespresso.com/' : |
|
| 100 | + $to = '[email protected]'; |
|
| 101 | + break; |
|
| 102 | + default : |
|
| 103 | + $to = get_option('admin_email'); |
|
| 104 | + } |
|
| 105 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 106 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
| 107 | + if (function_exists('wp_mail')) { |
|
| 108 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 109 | + wp_mail($to, $subject, $msg); |
|
| 110 | + } |
|
| 111 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
| 112 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 113 | + echo '<br /></p></div>'; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * error_type |
|
| 120 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
| 121 | + * |
|
| 122 | + * @param $code |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + public static function error_type($code) |
|
| 126 | + { |
|
| 127 | + switch ($code) { |
|
| 128 | + case E_ERROR: // 1 // |
|
| 129 | + return 'E_ERROR'; |
|
| 130 | + case E_WARNING: // 2 // |
|
| 131 | + return 'E_WARNING'; |
|
| 132 | + case E_PARSE: // 4 // |
|
| 133 | + return 'E_PARSE'; |
|
| 134 | + case E_NOTICE: // 8 // |
|
| 135 | + return 'E_NOTICE'; |
|
| 136 | + case E_CORE_ERROR: // 16 // |
|
| 137 | + return 'E_CORE_ERROR'; |
|
| 138 | + case E_CORE_WARNING: // 32 // |
|
| 139 | + return 'E_CORE_WARNING'; |
|
| 140 | + case E_COMPILE_ERROR: // 64 // |
|
| 141 | + return 'E_COMPILE_ERROR'; |
|
| 142 | + case E_COMPILE_WARNING: // 128 // |
|
| 143 | + return 'E_COMPILE_WARNING'; |
|
| 144 | + case E_USER_ERROR: // 256 // |
|
| 145 | + return 'E_USER_ERROR'; |
|
| 146 | + case E_USER_WARNING: // 512 // |
|
| 147 | + return 'E_USER_WARNING'; |
|
| 148 | + case E_USER_NOTICE: // 1024 // |
|
| 149 | + return 'E_USER_NOTICE'; |
|
| 150 | + case E_STRICT: // 2048 // |
|
| 151 | + return 'E_STRICT'; |
|
| 152 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
| 153 | + return 'E_RECOVERABLE_ERROR'; |
|
| 154 | + case E_DEPRECATED: // 8192 // |
|
| 155 | + return 'E_DEPRECATED'; |
|
| 156 | + case E_USER_DEPRECATED: // 16384 // |
|
| 157 | + return 'E_USER_DEPRECATED'; |
|
| 158 | + case E_ALL: // 16384 // |
|
| 159 | + return 'E_ALL'; |
|
| 160 | + } |
|
| 161 | + return ''; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * fatal_error_handler |
|
| 168 | + * |
|
| 169 | + * @return void |
|
| 170 | + */ |
|
| 171 | + public static function fatal_error_handler() |
|
| 172 | + { |
|
| 173 | + $last_error = error_get_last(); |
|
| 174 | + if ($last_error['type'] === E_ERROR) { |
|
| 175 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * _format_error |
|
| 183 | + * |
|
| 184 | + * @param $code |
|
| 185 | + * @param $message |
|
| 186 | + * @param $file |
|
| 187 | + * @param $line |
|
| 188 | + * @return string |
|
| 189 | + */ |
|
| 190 | + private static function _format_error($code, $message, $file, $line) |
|
| 191 | + { |
|
| 192 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
| 193 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
| 194 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
| 195 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
| 196 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
| 197 | + $html .= '</tbody></table>'; |
|
| 198 | + return $html; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * set_content_type |
|
| 205 | + * |
|
| 206 | + * @param $content_type |
|
| 207 | + * @return string |
|
| 208 | + */ |
|
| 209 | + public static function set_content_type($content_type) |
|
| 210 | + { |
|
| 211 | + return 'text/html'; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @return void |
|
| 218 | + * @throws EE_Error |
|
| 219 | + * @throws ReflectionException |
|
| 220 | + */ |
|
| 221 | + public function get_error() |
|
| 222 | + { |
|
| 223 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
| 224 | + throw $this; |
|
| 225 | + } |
|
| 226 | + // get separate user and developer messages if they exist |
|
| 227 | + $msg = explode('||', $this->getMessage()); |
|
| 228 | + $user_msg = $msg[0]; |
|
| 229 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 230 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 231 | + // add details to _all_exceptions array |
|
| 232 | + $x_time = time(); |
|
| 233 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
| 234 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
| 235 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
| 236 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
| 237 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
| 238 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
| 239 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
| 240 | + self::$_error_count++; |
|
| 241 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
| 242 | + $this->display_errors(); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param bool $check_stored |
|
| 248 | + * @param string $type_to_check |
|
| 249 | + * @return bool |
|
| 250 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 251 | + * @throws \InvalidArgumentException |
|
| 252 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 253 | + * @throws InvalidInterfaceException |
|
| 254 | + */ |
|
| 255 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
| 256 | + { |
|
| 257 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
| 258 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
| 259 | + ? true |
|
| 260 | + : false; |
|
| 261 | + if ($check_stored && ! $has_error) { |
|
| 262 | + $notices = EE_Error::getStoredNotices(); |
|
| 263 | + foreach ($notices as $type => $notice) { |
|
| 264 | + if ($type === $type_to_check && $notice) { |
|
| 265 | + return true; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + return $has_error; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @echo string |
|
| 276 | + * @throws \ReflectionException |
|
| 277 | + */ |
|
| 278 | + public function display_errors() |
|
| 279 | + { |
|
| 280 | + $trace_details = ''; |
|
| 281 | + $output = ' |
|
| 282 | 282 | <style type="text/css"> |
| 283 | 283 | #ee-error-message { |
| 284 | 284 | max-width:90% !important; |
@@ -334,21 +334,21 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | </style> |
| 336 | 336 | <div id="ee-error-message" class="error">'; |
| 337 | - if (! WP_DEBUG) { |
|
| 338 | - $output .= ' |
|
| 337 | + if (! WP_DEBUG) { |
|
| 338 | + $output .= ' |
|
| 339 | 339 | <p>'; |
| 340 | - } |
|
| 341 | - // cycle thru errors |
|
| 342 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
| 343 | - $error_code = ''; |
|
| 344 | - // process trace info |
|
| 345 | - if (empty($ex['trace'])) { |
|
| 346 | - $trace_details .= __( |
|
| 347 | - 'Sorry, but no trace information was available for this exception.', |
|
| 348 | - 'event_espresso' |
|
| 349 | - ); |
|
| 350 | - } else { |
|
| 351 | - $trace_details .= ' |
|
| 340 | + } |
|
| 341 | + // cycle thru errors |
|
| 342 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
| 343 | + $error_code = ''; |
|
| 344 | + // process trace info |
|
| 345 | + if (empty($ex['trace'])) { |
|
| 346 | + $trace_details .= __( |
|
| 347 | + 'Sorry, but no trace information was available for this exception.', |
|
| 348 | + 'event_espresso' |
|
| 349 | + ); |
|
| 350 | + } else { |
|
| 351 | + $trace_details .= ' |
|
| 352 | 352 | <div id="ee-trace-details"> |
| 353 | 353 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
| 354 | 354 | <tr> |
@@ -358,43 +358,43 @@ discard block |
||
| 358 | 358 | <th scope="col" align="left">Class</th> |
| 359 | 359 | <th scope="col" align="left">Method( arguments )</th> |
| 360 | 360 | </tr>'; |
| 361 | - $last_on_stack = count($ex['trace']) - 1; |
|
| 362 | - // reverse array so that stack is in proper chronological order |
|
| 363 | - $sorted_trace = array_reverse($ex['trace']); |
|
| 364 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
| 365 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
| 366 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
| 367 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
| 368 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
| 369 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
| 370 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
| 371 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
| 372 | - if (empty($file) && ! empty($class)) { |
|
| 373 | - $a = new ReflectionClass($class); |
|
| 374 | - $file = $a->getFileName(); |
|
| 375 | - if (empty($line) && ! empty($function)) { |
|
| 376 | - try { |
|
| 377 | - //if $function is a closure, this throws an exception |
|
| 378 | - $b = new ReflectionMethod($class, $function); |
|
| 379 | - $line = $b->getStartLine(); |
|
| 380 | - } catch (Exception $closure_exception) { |
|
| 381 | - $line = 'unknown'; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - if ($nmbr === $last_on_stack) { |
|
| 386 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
| 387 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
| 388 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
| 389 | - } |
|
| 390 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
| 391 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
| 392 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
| 393 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
| 394 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
| 395 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
| 396 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 397 | - $trace_details .= ' |
|
| 361 | + $last_on_stack = count($ex['trace']) - 1; |
|
| 362 | + // reverse array so that stack is in proper chronological order |
|
| 363 | + $sorted_trace = array_reverse($ex['trace']); |
|
| 364 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
| 365 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
| 366 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
| 367 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
| 368 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
| 369 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
| 370 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
| 371 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
| 372 | + if (empty($file) && ! empty($class)) { |
|
| 373 | + $a = new ReflectionClass($class); |
|
| 374 | + $file = $a->getFileName(); |
|
| 375 | + if (empty($line) && ! empty($function)) { |
|
| 376 | + try { |
|
| 377 | + //if $function is a closure, this throws an exception |
|
| 378 | + $b = new ReflectionMethod($class, $function); |
|
| 379 | + $line = $b->getStartLine(); |
|
| 380 | + } catch (Exception $closure_exception) { |
|
| 381 | + $line = 'unknown'; |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + if ($nmbr === $last_on_stack) { |
|
| 386 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
| 387 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
| 388 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
| 389 | + } |
|
| 390 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
| 391 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
| 392 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
| 393 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
| 394 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
| 395 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
| 396 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 397 | + $trace_details .= ' |
|
| 398 | 398 | <tr> |
| 399 | 399 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
| 400 | 400 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -402,633 +402,633 @@ discard block |
||
| 402 | 402 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
| 403 | 403 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
| 404 | 404 | </tr>'; |
| 405 | - } |
|
| 406 | - $trace_details .= ' |
|
| 405 | + } |
|
| 406 | + $trace_details .= ' |
|
| 407 | 407 | </table> |
| 408 | 408 | </div>'; |
| 409 | - } |
|
| 410 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
| 411 | - // add generic non-identifying messages for non-privileged users |
|
| 412 | - if (! WP_DEBUG) { |
|
| 413 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
| 414 | - . trim($ex['msg']) |
|
| 415 | - . '</span> <sup>' |
|
| 416 | - . $ex['code'] |
|
| 417 | - . '</sup><br />'; |
|
| 418 | - } else { |
|
| 419 | - // or helpful developer messages if debugging is on |
|
| 420 | - $output .= ' |
|
| 409 | + } |
|
| 410 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
| 411 | + // add generic non-identifying messages for non-privileged users |
|
| 412 | + if (! WP_DEBUG) { |
|
| 413 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
| 414 | + . trim($ex['msg']) |
|
| 415 | + . '</span> <sup>' |
|
| 416 | + . $ex['code'] |
|
| 417 | + . '</sup><br />'; |
|
| 418 | + } else { |
|
| 419 | + // or helpful developer messages if debugging is on |
|
| 420 | + $output .= ' |
|
| 421 | 421 | <div class="ee-error-dev-msg-dv"> |
| 422 | 422 | <p class="ee-error-dev-msg-pg"> |
| 423 | 423 | <strong class="ee-error-dev-msg-str">An ' |
| 424 | - . $ex['name'] |
|
| 425 | - . ' exception was thrown!</strong> <span>code: ' |
|
| 426 | - . $ex['code'] |
|
| 427 | - . '</span><br /> |
|
| 424 | + . $ex['name'] |
|
| 425 | + . ' exception was thrown!</strong> <span>code: ' |
|
| 426 | + . $ex['code'] |
|
| 427 | + . '</span><br /> |
|
| 428 | 428 | <span class="big-text">"' |
| 429 | - . trim($ex['msg']) |
|
| 430 | - . '"</span><br/> |
|
| 429 | + . trim($ex['msg']) |
|
| 430 | + . '"</span><br/> |
|
| 431 | 431 | <a id="display-ee-error-trace-' |
| 432 | - . self::$_error_count |
|
| 433 | - . $time |
|
| 434 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
| 435 | - . self::$_error_count |
|
| 436 | - . $time |
|
| 437 | - . '"> |
|
| 432 | + . self::$_error_count |
|
| 433 | + . $time |
|
| 434 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
| 435 | + . self::$_error_count |
|
| 436 | + . $time |
|
| 437 | + . '"> |
|
| 438 | 438 | ' |
| 439 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
| 440 | - . ' |
|
| 439 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
| 440 | + . ' |
|
| 441 | 441 | </a><br /> |
| 442 | 442 | <span class="small-text lt-grey-text">' |
| 443 | - . $ex['file'] |
|
| 444 | - . ' ( line no: ' |
|
| 445 | - . $ex['line'] |
|
| 446 | - . ' )</span> |
|
| 443 | + . $ex['file'] |
|
| 444 | + . ' ( line no: ' |
|
| 445 | + . $ex['line'] |
|
| 446 | + . ' )</span> |
|
| 447 | 447 | </p> |
| 448 | 448 | <div id="ee-error-trace-' |
| 449 | - . self::$_error_count |
|
| 450 | - . $time |
|
| 451 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
| 449 | + . self::$_error_count |
|
| 450 | + . $time |
|
| 451 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
| 452 | 452 | ' |
| 453 | - . $trace_details; |
|
| 454 | - if (! empty($class)) { |
|
| 455 | - $output .= ' |
|
| 453 | + . $trace_details; |
|
| 454 | + if (! empty($class)) { |
|
| 455 | + $output .= ' |
|
| 456 | 456 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
| 457 | 457 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
| 458 | 458 | <h3>Class Details</h3>'; |
| 459 | - $a = new ReflectionClass($class); |
|
| 460 | - $output .= ' |
|
| 459 | + $a = new ReflectionClass($class); |
|
| 460 | + $output .= ' |
|
| 461 | 461 | <pre>' . $a . '</pre> |
| 462 | 462 | </div> |
| 463 | 463 | </div>'; |
| 464 | - } |
|
| 465 | - $output .= ' |
|
| 464 | + } |
|
| 465 | + $output .= ' |
|
| 466 | 466 | </div> |
| 467 | 467 | </div> |
| 468 | 468 | <br />'; |
| 469 | - } |
|
| 470 | - $this->write_to_error_log($time, $ex); |
|
| 471 | - } |
|
| 472 | - // remove last linebreak |
|
| 473 | - $output = substr($output, 0, -6); |
|
| 474 | - if (! WP_DEBUG) { |
|
| 475 | - $output .= ' |
|
| 469 | + } |
|
| 470 | + $this->write_to_error_log($time, $ex); |
|
| 471 | + } |
|
| 472 | + // remove last linebreak |
|
| 473 | + $output = substr($output, 0, -6); |
|
| 474 | + if (! WP_DEBUG) { |
|
| 475 | + $output .= ' |
|
| 476 | 476 | </p>'; |
| 477 | - } |
|
| 478 | - $output .= ' |
|
| 477 | + } |
|
| 478 | + $output .= ' |
|
| 479 | 479 | </div>'; |
| 480 | - $output .= self::_print_scripts(true); |
|
| 481 | - if (defined('DOING_AJAX')) { |
|
| 482 | - echo wp_json_encode(array('error' => $output)); |
|
| 483 | - exit(); |
|
| 484 | - } |
|
| 485 | - echo $output; |
|
| 486 | - die(); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * generate string from exception trace args |
|
| 493 | - * |
|
| 494 | - * @param array $arguments |
|
| 495 | - * @param bool $array |
|
| 496 | - * @return string |
|
| 497 | - */ |
|
| 498 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
| 499 | - { |
|
| 500 | - $arg_string = ''; |
|
| 501 | - if (! empty($arguments)) { |
|
| 502 | - $args = array(); |
|
| 503 | - foreach ($arguments as $arg) { |
|
| 504 | - if (! empty($arg)) { |
|
| 505 | - if (is_string($arg)) { |
|
| 506 | - $args[] = " '" . $arg . "'"; |
|
| 507 | - } elseif (is_array($arg)) { |
|
| 508 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 509 | - } elseif ($arg === null) { |
|
| 510 | - $args[] = ' NULL'; |
|
| 511 | - } elseif (is_bool($arg)) { |
|
| 512 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
| 513 | - } elseif (is_object($arg)) { |
|
| 514 | - $args[] = ' OBJECT ' . get_class($arg); |
|
| 515 | - } elseif (is_resource($arg)) { |
|
| 516 | - $args[] = get_resource_type($arg); |
|
| 517 | - } else { |
|
| 518 | - $args[] = $arg; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - $arg_string = implode(', ', $args); |
|
| 523 | - } |
|
| 524 | - if ($array) { |
|
| 525 | - $arg_string .= ' )'; |
|
| 526 | - } |
|
| 527 | - return $arg_string; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * add error message |
|
| 534 | - * |
|
| 535 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 536 | - * separate messages for user || dev |
|
| 537 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 538 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 539 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 540 | - * @return void |
|
| 541 | - */ |
|
| 542 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
| 543 | - { |
|
| 544 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
| 545 | - self::$_error_count++; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
| 552 | - * adds an error |
|
| 553 | - * |
|
| 554 | - * @param string $msg |
|
| 555 | - * @param string $file |
|
| 556 | - * @param string $func |
|
| 557 | - * @param string $line |
|
| 558 | - * @throws EE_Error |
|
| 559 | - */ |
|
| 560 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
| 561 | - { |
|
| 562 | - if (WP_DEBUG) { |
|
| 563 | - throw new EE_Error($msg); |
|
| 564 | - } |
|
| 565 | - EE_Error::add_error($msg, $file, $func, $line); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * add success message |
|
| 572 | - * |
|
| 573 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 574 | - * separate messages for user || dev |
|
| 575 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 576 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 577 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 578 | - * @return void |
|
| 579 | - */ |
|
| 580 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
| 581 | - { |
|
| 582 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * add attention message |
|
| 589 | - * |
|
| 590 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 591 | - * separate messages for user || dev |
|
| 592 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 593 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 594 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 595 | - * @return void |
|
| 596 | - */ |
|
| 597 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
| 598 | - { |
|
| 599 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * @param string $type whether the message is for a success or error notification |
|
| 606 | - * @param string $msg the message to display to users or developers |
|
| 607 | - * - adding a double pipe || (OR) creates separate messages for user || dev |
|
| 608 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 609 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 610 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 611 | - * @return void |
|
| 612 | - */ |
|
| 613 | - private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
| 614 | - { |
|
| 615 | - if (empty($msg)) { |
|
| 616 | - EE_Error::doing_it_wrong( |
|
| 617 | - 'EE_Error::add_' . $type . '()', |
|
| 618 | - sprintf( |
|
| 619 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
| 620 | - 'event_espresso'), |
|
| 621 | - $type, |
|
| 622 | - $file, |
|
| 623 | - $line |
|
| 624 | - ), |
|
| 625 | - EVENT_ESPRESSO_VERSION |
|
| 626 | - ); |
|
| 627 | - } |
|
| 628 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
| 629 | - EE_Error::doing_it_wrong( |
|
| 630 | - 'EE_Error::add_error()', |
|
| 631 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
| 632 | - 'event_espresso'), |
|
| 633 | - EVENT_ESPRESSO_VERSION |
|
| 634 | - ); |
|
| 635 | - } |
|
| 636 | - // get separate user and developer messages if they exist |
|
| 637 | - $msg = explode('||', $msg); |
|
| 638 | - $user_msg = $msg[0]; |
|
| 639 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 640 | - /** |
|
| 641 | - * Do an action so other code can be triggered when a notice is created |
|
| 642 | - * |
|
| 643 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
| 644 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
| 645 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
| 646 | - * @param string $file file where error was generated |
|
| 647 | - * @param string $func function where error was generated |
|
| 648 | - * @param string $line line where error was generated |
|
| 649 | - */ |
|
| 650 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
| 651 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 652 | - // add notice if message exists |
|
| 653 | - if (! empty($msg)) { |
|
| 654 | - // get error code |
|
| 655 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
| 656 | - if (WP_DEBUG && $type === 'errors') { |
|
| 657 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 658 | - } |
|
| 659 | - // add notice. Index by code if it's not blank |
|
| 660 | - if ($notice_code) { |
|
| 661 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
| 662 | - } else { |
|
| 663 | - self::$_espresso_notices[$type][] = $msg; |
|
| 664 | - } |
|
| 665 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * in some case it may be necessary to overwrite the existing success messages |
|
| 672 | - * |
|
| 673 | - * @return void |
|
| 674 | - */ |
|
| 675 | - public static function overwrite_success() |
|
| 676 | - { |
|
| 677 | - self::$_espresso_notices['success'] = false; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * in some case it may be necessary to overwrite the existing attention messages |
|
| 684 | - * |
|
| 685 | - * @return void |
|
| 686 | - */ |
|
| 687 | - public static function overwrite_attention() |
|
| 688 | - { |
|
| 689 | - self::$_espresso_notices['attention'] = false; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * in some case it may be necessary to overwrite the existing error messages |
|
| 696 | - * |
|
| 697 | - * @return void |
|
| 698 | - */ |
|
| 699 | - public static function overwrite_errors() |
|
| 700 | - { |
|
| 701 | - self::$_espresso_notices['errors'] = false; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * @return void |
|
| 708 | - */ |
|
| 709 | - public static function reset_notices() |
|
| 710 | - { |
|
| 711 | - self::$_espresso_notices['success'] = false; |
|
| 712 | - self::$_espresso_notices['attention'] = false; |
|
| 713 | - self::$_espresso_notices['errors'] = false; |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * @return int |
|
| 720 | - */ |
|
| 721 | - public static function has_notices() |
|
| 722 | - { |
|
| 723 | - $has_notices = 0; |
|
| 724 | - // check for success messages |
|
| 725 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
| 726 | - ? 3 |
|
| 727 | - : $has_notices; |
|
| 728 | - // check for attention messages |
|
| 729 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
| 730 | - ? 2 |
|
| 731 | - : $has_notices; |
|
| 732 | - // check for error messages |
|
| 733 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
| 734 | - ? 1 |
|
| 735 | - : $has_notices; |
|
| 736 | - return $has_notices; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
| 742 | - * |
|
| 743 | - * @since 4.9.0 |
|
| 744 | - * @return array |
|
| 745 | - */ |
|
| 746 | - public static function get_vanilla_notices() |
|
| 747 | - { |
|
| 748 | - return array( |
|
| 749 | - 'success' => isset(self::$_espresso_notices['success']) |
|
| 750 | - ? self::$_espresso_notices['success'] |
|
| 751 | - : array(), |
|
| 752 | - 'attention' => isset(self::$_espresso_notices['attention']) |
|
| 753 | - ? self::$_espresso_notices['attention'] |
|
| 754 | - : array(), |
|
| 755 | - 'errors' => isset(self::$_espresso_notices['errors']) |
|
| 756 | - ? self::$_espresso_notices['errors'] |
|
| 757 | - : array(), |
|
| 758 | - ); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * @return array |
|
| 764 | - * @throws InvalidArgumentException |
|
| 765 | - * @throws InvalidDataTypeException |
|
| 766 | - * @throws InvalidInterfaceException |
|
| 767 | - */ |
|
| 768 | - public static function getStoredNotices() |
|
| 769 | - { |
|
| 770 | - if ($user_id = get_current_user_id()) { |
|
| 771 | - // get notices for logged in user |
|
| 772 | - $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id); |
|
| 773 | - return is_array($notices) ? $notices : array(); |
|
| 774 | - } |
|
| 775 | - if (EE_Session::isLoadedAndActive()) { |
|
| 776 | - // get notices for user currently engaged in a session |
|
| 777 | - $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 778 | - return is_array($session_data) ? $session_data : array(); |
|
| 779 | - } |
|
| 780 | - // get global notices and hope they apply to the current site visitor |
|
| 781 | - $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 782 | - return is_array($notices) ? $notices : array(); |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - |
|
| 786 | - /** |
|
| 787 | - * @param array $notices |
|
| 788 | - * @return bool |
|
| 789 | - * @throws InvalidArgumentException |
|
| 790 | - * @throws InvalidDataTypeException |
|
| 791 | - * @throws InvalidInterfaceException |
|
| 792 | - */ |
|
| 793 | - public static function storeNotices(array $notices) |
|
| 794 | - { |
|
| 795 | - if ($user_id = get_current_user_id()) { |
|
| 796 | - // store notices for logged in user |
|
| 797 | - return (bool) update_user_option( |
|
| 798 | - $user_id, |
|
| 799 | - EE_Error::OPTIONS_KEY_NOTICES, |
|
| 800 | - $notices |
|
| 801 | - ); |
|
| 802 | - } |
|
| 803 | - if (EE_Session::isLoadedAndActive()) { |
|
| 804 | - // store notices for user currently engaged in a session |
|
| 805 | - return EE_Session::instance()->set_session_data( |
|
| 806 | - array(EE_Error::OPTIONS_KEY_NOTICES => $notices) |
|
| 807 | - ); |
|
| 808 | - } |
|
| 809 | - // store global notices and hope they apply to the same site visitor on the next request |
|
| 810 | - return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * @return bool|TRUE |
|
| 816 | - * @throws InvalidArgumentException |
|
| 817 | - * @throws InvalidDataTypeException |
|
| 818 | - * @throws InvalidInterfaceException |
|
| 819 | - */ |
|
| 820 | - public static function clearNotices() |
|
| 821 | - { |
|
| 822 | - if ($user_id = get_current_user_id()) { |
|
| 823 | - // clear notices for logged in user |
|
| 824 | - return (bool) update_user_option( |
|
| 825 | - $user_id, |
|
| 826 | - EE_Error::OPTIONS_KEY_NOTICES, |
|
| 827 | - array() |
|
| 828 | - ); |
|
| 829 | - } |
|
| 830 | - if (EE_Session::isLoadedAndActive()) { |
|
| 831 | - // clear notices for user currently engaged in a session |
|
| 832 | - return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 833 | - } |
|
| 834 | - // clear global notices and hope none belonged to some for some other site visitor |
|
| 835 | - return update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * saves notices to the db for retrieval on next request |
|
| 841 | - * |
|
| 842 | - * @return void |
|
| 843 | - * @throws InvalidArgumentException |
|
| 844 | - * @throws InvalidDataTypeException |
|
| 845 | - * @throws InvalidInterfaceException |
|
| 846 | - */ |
|
| 847 | - public static function stashNoticesBeforeRedirect() |
|
| 848 | - { |
|
| 849 | - EE_Error::get_notices(false, true); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * compile all error or success messages into one string |
|
| 855 | - * |
|
| 856 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
| 857 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
| 858 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
| 859 | - * - ONLY do this just before redirecting |
|
| 860 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
| 861 | - * @return array |
|
| 862 | - * @throws InvalidArgumentException |
|
| 863 | - * @throws InvalidDataTypeException |
|
| 864 | - * @throws InvalidInterfaceException |
|
| 865 | - */ |
|
| 866 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
| 867 | - { |
|
| 868 | - $success_messages = ''; |
|
| 869 | - $attention_messages = ''; |
|
| 870 | - $error_messages = ''; |
|
| 871 | - // either save notices to the db |
|
| 872 | - if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
| 873 | - self::$_espresso_notices = array_merge( |
|
| 874 | - EE_Error::getStoredNotices(), |
|
| 875 | - self::$_espresso_notices |
|
| 876 | - ); |
|
| 877 | - EE_Error::storeNotices(self::$_espresso_notices); |
|
| 878 | - return array(); |
|
| 879 | - } |
|
| 880 | - $print_scripts = EE_Error::combineExistingAndNewNotices(); |
|
| 881 | - // check for success messages |
|
| 882 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
| 883 | - // combine messages |
|
| 884 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
| 885 | - $print_scripts = true; |
|
| 886 | - } |
|
| 887 | - // check for attention messages |
|
| 888 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
| 889 | - // combine messages |
|
| 890 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
| 891 | - $print_scripts = true; |
|
| 892 | - } |
|
| 893 | - // check for error messages |
|
| 894 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
| 895 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
| 896 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
| 897 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
| 898 | - // combine messages |
|
| 899 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
| 900 | - $print_scripts = true; |
|
| 901 | - } |
|
| 902 | - if ($format_output) { |
|
| 903 | - $notices = EE_Error::formatNoticesOutput( |
|
| 904 | - $success_messages, |
|
| 905 | - $attention_messages, |
|
| 906 | - $error_messages |
|
| 907 | - ); |
|
| 908 | - } else { |
|
| 909 | - $notices = array( |
|
| 910 | - 'success' => $success_messages, |
|
| 911 | - 'attention' => $attention_messages, |
|
| 912 | - 'errors' => $error_messages, |
|
| 913 | - ); |
|
| 914 | - if ($remove_empty) { |
|
| 915 | - // remove empty notices |
|
| 916 | - foreach ($notices as $type => $notice) { |
|
| 917 | - if (empty($notice)) { |
|
| 918 | - unset($notices[$type]); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | - if ($print_scripts) { |
|
| 924 | - self::_print_scripts(); |
|
| 925 | - } |
|
| 926 | - return $notices; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * @return bool |
|
| 932 | - * @throws InvalidArgumentException |
|
| 933 | - * @throws InvalidDataTypeException |
|
| 934 | - * @throws InvalidInterfaceException |
|
| 935 | - */ |
|
| 936 | - private static function combineExistingAndNewNotices() |
|
| 937 | - { |
|
| 938 | - $print_scripts = false; |
|
| 939 | - // grab any notices that have been previously saved |
|
| 940 | - $notices = EE_Error::getStoredNotices(); |
|
| 941 | - if (! empty($notices)) { |
|
| 942 | - foreach ($notices as $type => $notice) { |
|
| 943 | - if (is_array($notice) && ! empty($notice)) { |
|
| 944 | - // make sure that existing notice type is an array |
|
| 945 | - self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
| 946 | - && ! empty(self::$_espresso_notices[ $type ]) |
|
| 947 | - ? self::$_espresso_notices[ $type ] |
|
| 948 | - : array(); |
|
| 949 | - // add newly created notices to existing ones |
|
| 950 | - self::$_espresso_notices[ $type ] += $notice; |
|
| 951 | - $print_scripts = true; |
|
| 952 | - } |
|
| 953 | - } |
|
| 954 | - // now clear any stored notices |
|
| 955 | - EE_Error::clearNotices(); |
|
| 956 | - } |
|
| 957 | - return $print_scripts; |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - |
|
| 961 | - /** |
|
| 962 | - * @param string $success_messages |
|
| 963 | - * @param string $attention_messages |
|
| 964 | - * @param string $error_messages |
|
| 965 | - * @return string |
|
| 966 | - */ |
|
| 967 | - private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages) |
|
| 968 | - { |
|
| 969 | - $notices = '<div id="espresso-notices">'; |
|
| 970 | - $close = is_admin() |
|
| 971 | - ? '' |
|
| 972 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>'; |
|
| 973 | - if ($success_messages !== '') { |
|
| 974 | - $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
| 975 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
| 976 | - //showMessage( $success_messages ); |
|
| 977 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 978 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 979 | - . 'style="display:none;">' |
|
| 980 | - . '<p>' . $success_messages . '</p>' |
|
| 981 | - . $close |
|
| 982 | - . '</div>'; |
|
| 983 | - } |
|
| 984 | - if ($attention_messages !== '') { |
|
| 985 | - $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
| 986 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
| 987 | - //showMessage( $error_messages, TRUE ); |
|
| 988 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 989 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 990 | - . 'style="display:none;">' |
|
| 991 | - . '<p>' . $attention_messages . '</p>' |
|
| 992 | - . $close |
|
| 993 | - . '</div>'; |
|
| 994 | - } |
|
| 995 | - if ($error_messages !== '') { |
|
| 996 | - $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
| 997 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
| 998 | - //showMessage( $error_messages, TRUE ); |
|
| 999 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 1000 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 1001 | - . 'style="display:none;">' |
|
| 1002 | - . '<p>' . $error_messages . '</p>' |
|
| 1003 | - . $close |
|
| 1004 | - . '</div>'; |
|
| 1005 | - } |
|
| 1006 | - $notices .= '</div>'; |
|
| 1007 | - return $notices; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - |
|
| 1012 | - /** |
|
| 1013 | - * _print_scripts |
|
| 1014 | - * |
|
| 1015 | - * @param bool $force_print |
|
| 1016 | - * @return string |
|
| 1017 | - */ |
|
| 1018 | - private static function _print_scripts($force_print = false) |
|
| 1019 | - { |
|
| 1020 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1021 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
| 1022 | - return ''; |
|
| 1023 | - } |
|
| 1024 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
| 1025 | - wp_enqueue_style('espresso_default'); |
|
| 1026 | - wp_enqueue_style('espresso_custom_css'); |
|
| 1027 | - wp_enqueue_script('ee_error_js'); |
|
| 1028 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
| 1029 | - } |
|
| 1030 | - } else { |
|
| 1031 | - return ' |
|
| 480 | + $output .= self::_print_scripts(true); |
|
| 481 | + if (defined('DOING_AJAX')) { |
|
| 482 | + echo wp_json_encode(array('error' => $output)); |
|
| 483 | + exit(); |
|
| 484 | + } |
|
| 485 | + echo $output; |
|
| 486 | + die(); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * generate string from exception trace args |
|
| 493 | + * |
|
| 494 | + * @param array $arguments |
|
| 495 | + * @param bool $array |
|
| 496 | + * @return string |
|
| 497 | + */ |
|
| 498 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
| 499 | + { |
|
| 500 | + $arg_string = ''; |
|
| 501 | + if (! empty($arguments)) { |
|
| 502 | + $args = array(); |
|
| 503 | + foreach ($arguments as $arg) { |
|
| 504 | + if (! empty($arg)) { |
|
| 505 | + if (is_string($arg)) { |
|
| 506 | + $args[] = " '" . $arg . "'"; |
|
| 507 | + } elseif (is_array($arg)) { |
|
| 508 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 509 | + } elseif ($arg === null) { |
|
| 510 | + $args[] = ' NULL'; |
|
| 511 | + } elseif (is_bool($arg)) { |
|
| 512 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
| 513 | + } elseif (is_object($arg)) { |
|
| 514 | + $args[] = ' OBJECT ' . get_class($arg); |
|
| 515 | + } elseif (is_resource($arg)) { |
|
| 516 | + $args[] = get_resource_type($arg); |
|
| 517 | + } else { |
|
| 518 | + $args[] = $arg; |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + $arg_string = implode(', ', $args); |
|
| 523 | + } |
|
| 524 | + if ($array) { |
|
| 525 | + $arg_string .= ' )'; |
|
| 526 | + } |
|
| 527 | + return $arg_string; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * add error message |
|
| 534 | + * |
|
| 535 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 536 | + * separate messages for user || dev |
|
| 537 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 538 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 539 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 540 | + * @return void |
|
| 541 | + */ |
|
| 542 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
| 543 | + { |
|
| 544 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
| 545 | + self::$_error_count++; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
| 552 | + * adds an error |
|
| 553 | + * |
|
| 554 | + * @param string $msg |
|
| 555 | + * @param string $file |
|
| 556 | + * @param string $func |
|
| 557 | + * @param string $line |
|
| 558 | + * @throws EE_Error |
|
| 559 | + */ |
|
| 560 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
| 561 | + { |
|
| 562 | + if (WP_DEBUG) { |
|
| 563 | + throw new EE_Error($msg); |
|
| 564 | + } |
|
| 565 | + EE_Error::add_error($msg, $file, $func, $line); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * add success message |
|
| 572 | + * |
|
| 573 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 574 | + * separate messages for user || dev |
|
| 575 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 576 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 577 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 578 | + * @return void |
|
| 579 | + */ |
|
| 580 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
| 581 | + { |
|
| 582 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * add attention message |
|
| 589 | + * |
|
| 590 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 591 | + * separate messages for user || dev |
|
| 592 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 593 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 594 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 595 | + * @return void |
|
| 596 | + */ |
|
| 597 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
| 598 | + { |
|
| 599 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * @param string $type whether the message is for a success or error notification |
|
| 606 | + * @param string $msg the message to display to users or developers |
|
| 607 | + * - adding a double pipe || (OR) creates separate messages for user || dev |
|
| 608 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 609 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 610 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 611 | + * @return void |
|
| 612 | + */ |
|
| 613 | + private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
| 614 | + { |
|
| 615 | + if (empty($msg)) { |
|
| 616 | + EE_Error::doing_it_wrong( |
|
| 617 | + 'EE_Error::add_' . $type . '()', |
|
| 618 | + sprintf( |
|
| 619 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
| 620 | + 'event_espresso'), |
|
| 621 | + $type, |
|
| 622 | + $file, |
|
| 623 | + $line |
|
| 624 | + ), |
|
| 625 | + EVENT_ESPRESSO_VERSION |
|
| 626 | + ); |
|
| 627 | + } |
|
| 628 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
| 629 | + EE_Error::doing_it_wrong( |
|
| 630 | + 'EE_Error::add_error()', |
|
| 631 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
| 632 | + 'event_espresso'), |
|
| 633 | + EVENT_ESPRESSO_VERSION |
|
| 634 | + ); |
|
| 635 | + } |
|
| 636 | + // get separate user and developer messages if they exist |
|
| 637 | + $msg = explode('||', $msg); |
|
| 638 | + $user_msg = $msg[0]; |
|
| 639 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 640 | + /** |
|
| 641 | + * Do an action so other code can be triggered when a notice is created |
|
| 642 | + * |
|
| 643 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
| 644 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
| 645 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
| 646 | + * @param string $file file where error was generated |
|
| 647 | + * @param string $func function where error was generated |
|
| 648 | + * @param string $line line where error was generated |
|
| 649 | + */ |
|
| 650 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
| 651 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 652 | + // add notice if message exists |
|
| 653 | + if (! empty($msg)) { |
|
| 654 | + // get error code |
|
| 655 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
| 656 | + if (WP_DEBUG && $type === 'errors') { |
|
| 657 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 658 | + } |
|
| 659 | + // add notice. Index by code if it's not blank |
|
| 660 | + if ($notice_code) { |
|
| 661 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
| 662 | + } else { |
|
| 663 | + self::$_espresso_notices[$type][] = $msg; |
|
| 664 | + } |
|
| 665 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * in some case it may be necessary to overwrite the existing success messages |
|
| 672 | + * |
|
| 673 | + * @return void |
|
| 674 | + */ |
|
| 675 | + public static function overwrite_success() |
|
| 676 | + { |
|
| 677 | + self::$_espresso_notices['success'] = false; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * in some case it may be necessary to overwrite the existing attention messages |
|
| 684 | + * |
|
| 685 | + * @return void |
|
| 686 | + */ |
|
| 687 | + public static function overwrite_attention() |
|
| 688 | + { |
|
| 689 | + self::$_espresso_notices['attention'] = false; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * in some case it may be necessary to overwrite the existing error messages |
|
| 696 | + * |
|
| 697 | + * @return void |
|
| 698 | + */ |
|
| 699 | + public static function overwrite_errors() |
|
| 700 | + { |
|
| 701 | + self::$_espresso_notices['errors'] = false; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * @return void |
|
| 708 | + */ |
|
| 709 | + public static function reset_notices() |
|
| 710 | + { |
|
| 711 | + self::$_espresso_notices['success'] = false; |
|
| 712 | + self::$_espresso_notices['attention'] = false; |
|
| 713 | + self::$_espresso_notices['errors'] = false; |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * @return int |
|
| 720 | + */ |
|
| 721 | + public static function has_notices() |
|
| 722 | + { |
|
| 723 | + $has_notices = 0; |
|
| 724 | + // check for success messages |
|
| 725 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
| 726 | + ? 3 |
|
| 727 | + : $has_notices; |
|
| 728 | + // check for attention messages |
|
| 729 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
| 730 | + ? 2 |
|
| 731 | + : $has_notices; |
|
| 732 | + // check for error messages |
|
| 733 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
| 734 | + ? 1 |
|
| 735 | + : $has_notices; |
|
| 736 | + return $has_notices; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
| 742 | + * |
|
| 743 | + * @since 4.9.0 |
|
| 744 | + * @return array |
|
| 745 | + */ |
|
| 746 | + public static function get_vanilla_notices() |
|
| 747 | + { |
|
| 748 | + return array( |
|
| 749 | + 'success' => isset(self::$_espresso_notices['success']) |
|
| 750 | + ? self::$_espresso_notices['success'] |
|
| 751 | + : array(), |
|
| 752 | + 'attention' => isset(self::$_espresso_notices['attention']) |
|
| 753 | + ? self::$_espresso_notices['attention'] |
|
| 754 | + : array(), |
|
| 755 | + 'errors' => isset(self::$_espresso_notices['errors']) |
|
| 756 | + ? self::$_espresso_notices['errors'] |
|
| 757 | + : array(), |
|
| 758 | + ); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * @return array |
|
| 764 | + * @throws InvalidArgumentException |
|
| 765 | + * @throws InvalidDataTypeException |
|
| 766 | + * @throws InvalidInterfaceException |
|
| 767 | + */ |
|
| 768 | + public static function getStoredNotices() |
|
| 769 | + { |
|
| 770 | + if ($user_id = get_current_user_id()) { |
|
| 771 | + // get notices for logged in user |
|
| 772 | + $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id); |
|
| 773 | + return is_array($notices) ? $notices : array(); |
|
| 774 | + } |
|
| 775 | + if (EE_Session::isLoadedAndActive()) { |
|
| 776 | + // get notices for user currently engaged in a session |
|
| 777 | + $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 778 | + return is_array($session_data) ? $session_data : array(); |
|
| 779 | + } |
|
| 780 | + // get global notices and hope they apply to the current site visitor |
|
| 781 | + $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 782 | + return is_array($notices) ? $notices : array(); |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + |
|
| 786 | + /** |
|
| 787 | + * @param array $notices |
|
| 788 | + * @return bool |
|
| 789 | + * @throws InvalidArgumentException |
|
| 790 | + * @throws InvalidDataTypeException |
|
| 791 | + * @throws InvalidInterfaceException |
|
| 792 | + */ |
|
| 793 | + public static function storeNotices(array $notices) |
|
| 794 | + { |
|
| 795 | + if ($user_id = get_current_user_id()) { |
|
| 796 | + // store notices for logged in user |
|
| 797 | + return (bool) update_user_option( |
|
| 798 | + $user_id, |
|
| 799 | + EE_Error::OPTIONS_KEY_NOTICES, |
|
| 800 | + $notices |
|
| 801 | + ); |
|
| 802 | + } |
|
| 803 | + if (EE_Session::isLoadedAndActive()) { |
|
| 804 | + // store notices for user currently engaged in a session |
|
| 805 | + return EE_Session::instance()->set_session_data( |
|
| 806 | + array(EE_Error::OPTIONS_KEY_NOTICES => $notices) |
|
| 807 | + ); |
|
| 808 | + } |
|
| 809 | + // store global notices and hope they apply to the same site visitor on the next request |
|
| 810 | + return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * @return bool|TRUE |
|
| 816 | + * @throws InvalidArgumentException |
|
| 817 | + * @throws InvalidDataTypeException |
|
| 818 | + * @throws InvalidInterfaceException |
|
| 819 | + */ |
|
| 820 | + public static function clearNotices() |
|
| 821 | + { |
|
| 822 | + if ($user_id = get_current_user_id()) { |
|
| 823 | + // clear notices for logged in user |
|
| 824 | + return (bool) update_user_option( |
|
| 825 | + $user_id, |
|
| 826 | + EE_Error::OPTIONS_KEY_NOTICES, |
|
| 827 | + array() |
|
| 828 | + ); |
|
| 829 | + } |
|
| 830 | + if (EE_Session::isLoadedAndActive()) { |
|
| 831 | + // clear notices for user currently engaged in a session |
|
| 832 | + return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 833 | + } |
|
| 834 | + // clear global notices and hope none belonged to some for some other site visitor |
|
| 835 | + return update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * saves notices to the db for retrieval on next request |
|
| 841 | + * |
|
| 842 | + * @return void |
|
| 843 | + * @throws InvalidArgumentException |
|
| 844 | + * @throws InvalidDataTypeException |
|
| 845 | + * @throws InvalidInterfaceException |
|
| 846 | + */ |
|
| 847 | + public static function stashNoticesBeforeRedirect() |
|
| 848 | + { |
|
| 849 | + EE_Error::get_notices(false, true); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * compile all error or success messages into one string |
|
| 855 | + * |
|
| 856 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
| 857 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
| 858 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
| 859 | + * - ONLY do this just before redirecting |
|
| 860 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
| 861 | + * @return array |
|
| 862 | + * @throws InvalidArgumentException |
|
| 863 | + * @throws InvalidDataTypeException |
|
| 864 | + * @throws InvalidInterfaceException |
|
| 865 | + */ |
|
| 866 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
| 867 | + { |
|
| 868 | + $success_messages = ''; |
|
| 869 | + $attention_messages = ''; |
|
| 870 | + $error_messages = ''; |
|
| 871 | + // either save notices to the db |
|
| 872 | + if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
| 873 | + self::$_espresso_notices = array_merge( |
|
| 874 | + EE_Error::getStoredNotices(), |
|
| 875 | + self::$_espresso_notices |
|
| 876 | + ); |
|
| 877 | + EE_Error::storeNotices(self::$_espresso_notices); |
|
| 878 | + return array(); |
|
| 879 | + } |
|
| 880 | + $print_scripts = EE_Error::combineExistingAndNewNotices(); |
|
| 881 | + // check for success messages |
|
| 882 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
| 883 | + // combine messages |
|
| 884 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
| 885 | + $print_scripts = true; |
|
| 886 | + } |
|
| 887 | + // check for attention messages |
|
| 888 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
| 889 | + // combine messages |
|
| 890 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
| 891 | + $print_scripts = true; |
|
| 892 | + } |
|
| 893 | + // check for error messages |
|
| 894 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
| 895 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
| 896 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
| 897 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
| 898 | + // combine messages |
|
| 899 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
| 900 | + $print_scripts = true; |
|
| 901 | + } |
|
| 902 | + if ($format_output) { |
|
| 903 | + $notices = EE_Error::formatNoticesOutput( |
|
| 904 | + $success_messages, |
|
| 905 | + $attention_messages, |
|
| 906 | + $error_messages |
|
| 907 | + ); |
|
| 908 | + } else { |
|
| 909 | + $notices = array( |
|
| 910 | + 'success' => $success_messages, |
|
| 911 | + 'attention' => $attention_messages, |
|
| 912 | + 'errors' => $error_messages, |
|
| 913 | + ); |
|
| 914 | + if ($remove_empty) { |
|
| 915 | + // remove empty notices |
|
| 916 | + foreach ($notices as $type => $notice) { |
|
| 917 | + if (empty($notice)) { |
|
| 918 | + unset($notices[$type]); |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | + if ($print_scripts) { |
|
| 924 | + self::_print_scripts(); |
|
| 925 | + } |
|
| 926 | + return $notices; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * @return bool |
|
| 932 | + * @throws InvalidArgumentException |
|
| 933 | + * @throws InvalidDataTypeException |
|
| 934 | + * @throws InvalidInterfaceException |
|
| 935 | + */ |
|
| 936 | + private static function combineExistingAndNewNotices() |
|
| 937 | + { |
|
| 938 | + $print_scripts = false; |
|
| 939 | + // grab any notices that have been previously saved |
|
| 940 | + $notices = EE_Error::getStoredNotices(); |
|
| 941 | + if (! empty($notices)) { |
|
| 942 | + foreach ($notices as $type => $notice) { |
|
| 943 | + if (is_array($notice) && ! empty($notice)) { |
|
| 944 | + // make sure that existing notice type is an array |
|
| 945 | + self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
| 946 | + && ! empty(self::$_espresso_notices[ $type ]) |
|
| 947 | + ? self::$_espresso_notices[ $type ] |
|
| 948 | + : array(); |
|
| 949 | + // add newly created notices to existing ones |
|
| 950 | + self::$_espresso_notices[ $type ] += $notice; |
|
| 951 | + $print_scripts = true; |
|
| 952 | + } |
|
| 953 | + } |
|
| 954 | + // now clear any stored notices |
|
| 955 | + EE_Error::clearNotices(); |
|
| 956 | + } |
|
| 957 | + return $print_scripts; |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + |
|
| 961 | + /** |
|
| 962 | + * @param string $success_messages |
|
| 963 | + * @param string $attention_messages |
|
| 964 | + * @param string $error_messages |
|
| 965 | + * @return string |
|
| 966 | + */ |
|
| 967 | + private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages) |
|
| 968 | + { |
|
| 969 | + $notices = '<div id="espresso-notices">'; |
|
| 970 | + $close = is_admin() |
|
| 971 | + ? '' |
|
| 972 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>'; |
|
| 973 | + if ($success_messages !== '') { |
|
| 974 | + $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
| 975 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
| 976 | + //showMessage( $success_messages ); |
|
| 977 | + $notices .= '<div id="' . $css_id . '" ' |
|
| 978 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
| 979 | + . 'style="display:none;">' |
|
| 980 | + . '<p>' . $success_messages . '</p>' |
|
| 981 | + . $close |
|
| 982 | + . '</div>'; |
|
| 983 | + } |
|
| 984 | + if ($attention_messages !== '') { |
|
| 985 | + $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
| 986 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
| 987 | + //showMessage( $error_messages, TRUE ); |
|
| 988 | + $notices .= '<div id="' . $css_id . '" ' |
|
| 989 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
| 990 | + . 'style="display:none;">' |
|
| 991 | + . '<p>' . $attention_messages . '</p>' |
|
| 992 | + . $close |
|
| 993 | + . '</div>'; |
|
| 994 | + } |
|
| 995 | + if ($error_messages !== '') { |
|
| 996 | + $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
| 997 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
| 998 | + //showMessage( $error_messages, TRUE ); |
|
| 999 | + $notices .= '<div id="' . $css_id . '" ' |
|
| 1000 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
| 1001 | + . 'style="display:none;">' |
|
| 1002 | + . '<p>' . $error_messages . '</p>' |
|
| 1003 | + . $close |
|
| 1004 | + . '</div>'; |
|
| 1005 | + } |
|
| 1006 | + $notices .= '</div>'; |
|
| 1007 | + return $notices; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + |
|
| 1012 | + /** |
|
| 1013 | + * _print_scripts |
|
| 1014 | + * |
|
| 1015 | + * @param bool $force_print |
|
| 1016 | + * @return string |
|
| 1017 | + */ |
|
| 1018 | + private static function _print_scripts($force_print = false) |
|
| 1019 | + { |
|
| 1020 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1021 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
| 1022 | + return ''; |
|
| 1023 | + } |
|
| 1024 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
| 1025 | + wp_enqueue_style('espresso_default'); |
|
| 1026 | + wp_enqueue_style('espresso_custom_css'); |
|
| 1027 | + wp_enqueue_script('ee_error_js'); |
|
| 1028 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
| 1029 | + } |
|
| 1030 | + } else { |
|
| 1031 | + return ' |
|
| 1032 | 1032 | <script> |
| 1033 | 1033 | /* <![CDATA[ */ |
| 1034 | 1034 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -1038,223 +1038,223 @@ discard block |
||
| 1038 | 1038 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
| 1039 | 1039 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
| 1040 | 1040 | '; |
| 1041 | - } |
|
| 1042 | - return ''; |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - /** |
|
| 1048 | - * @return void |
|
| 1049 | - */ |
|
| 1050 | - public static function enqueue_error_scripts() |
|
| 1051 | - { |
|
| 1052 | - self::_print_scripts(); |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - |
|
| 1057 | - /** |
|
| 1058 | - * create error code from filepath, function name, |
|
| 1059 | - * and line number where exception or error was thrown |
|
| 1060 | - * |
|
| 1061 | - * @param string $file |
|
| 1062 | - * @param string $func |
|
| 1063 | - * @param string $line |
|
| 1064 | - * @return string |
|
| 1065 | - */ |
|
| 1066 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
| 1067 | - { |
|
| 1068 | - $file = explode('.', basename($file)); |
|
| 1069 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
| 1070 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1071 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1072 | - return $error_code; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * write exception details to log file |
|
| 1079 | - * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
| 1080 | - * |
|
| 1081 | - * @param int $time |
|
| 1082 | - * @param array $ex |
|
| 1083 | - * @param bool $clear |
|
| 1084 | - * @return void |
|
| 1085 | - */ |
|
| 1086 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
| 1087 | - { |
|
| 1088 | - if (empty($ex)) { |
|
| 1089 | - return; |
|
| 1090 | - } |
|
| 1091 | - if (! $time) { |
|
| 1092 | - $time = time(); |
|
| 1093 | - } |
|
| 1094 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
| 1095 | - . PHP_EOL; |
|
| 1096 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1097 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1098 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1099 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1100 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1101 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1102 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1103 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
| 1104 | - . PHP_EOL; |
|
| 1105 | - try { |
|
| 1106 | - error_log($exception_log); |
|
| 1107 | - } catch (EE_Error $e) { |
|
| 1108 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
| 1109 | - 'event_espresso'), $e->getMessage())); |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - |
|
| 1115 | - /** |
|
| 1116 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
| 1117 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
| 1118 | - * but the code execution is done in a manner that could lead to unexpected results |
|
| 1119 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
| 1120 | - * A good test for knowing whether to use this method is: |
|
| 1121 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
| 1122 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
| 1123 | - * 2. If this is loaded before something else, it won't break anything, |
|
| 1124 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
| 1125 | - * |
|
| 1126 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
| 1127 | - * @param string $function The function that was called |
|
| 1128 | - * @param string $message A message explaining what has been done incorrectly |
|
| 1129 | - * @param string $version The version of Event Espresso where the error was added |
|
| 1130 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 1131 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
| 1132 | - * but not have any notices appear until a later version. This allows developers |
|
| 1133 | - * extra time to update their code before notices appear. |
|
| 1134 | - * @param int $error_type |
|
| 1135 | - */ |
|
| 1136 | - public static function doing_it_wrong( |
|
| 1137 | - $function, |
|
| 1138 | - $message, |
|
| 1139 | - $version, |
|
| 1140 | - $applies_when = '', |
|
| 1141 | - $error_type = null |
|
| 1142 | - ) { |
|
| 1143 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 1144 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
| 1152 | - * |
|
| 1153 | - * @return array { |
|
| 1154 | - * @type array $success all the success messages |
|
| 1155 | - * @type array $errors all the error messages |
|
| 1156 | - * @type array $attention all the attention messages |
|
| 1157 | - * } |
|
| 1158 | - */ |
|
| 1159 | - public static function get_raw_notices() |
|
| 1160 | - { |
|
| 1161 | - return self::$_espresso_notices; |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - /** |
|
| 1167 | - * @deprecated 4.9.27 |
|
| 1168 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1169 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1170 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
| 1171 | - * @return void |
|
| 1172 | - * @throws InvalidDataTypeException |
|
| 1173 | - */ |
|
| 1174 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
| 1175 | - { |
|
| 1176 | - new PersistentAdminNotice( |
|
| 1177 | - $pan_name, |
|
| 1178 | - $pan_message, |
|
| 1179 | - $force_update |
|
| 1180 | - ); |
|
| 1181 | - EE_Error::doing_it_wrong( |
|
| 1182 | - __METHOD__, |
|
| 1183 | - sprintf( |
|
| 1184 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1185 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
| 1186 | - ), |
|
| 1187 | - '4.9.27' |
|
| 1188 | - ); |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - |
|
| 1193 | - /** |
|
| 1194 | - * @deprecated 4.9.27 |
|
| 1195 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
| 1196 | - * @param bool $purge |
|
| 1197 | - * @param bool $return |
|
| 1198 | - * @throws DomainException |
|
| 1199 | - * @throws InvalidInterfaceException |
|
| 1200 | - * @throws InvalidDataTypeException |
|
| 1201 | - * @throws ServiceNotFoundException |
|
| 1202 | - * @throws InvalidArgumentException |
|
| 1203 | - */ |
|
| 1204 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
| 1205 | - { |
|
| 1206 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 1207 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 1208 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1209 | - ); |
|
| 1210 | - $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
| 1211 | - EE_Error::doing_it_wrong( |
|
| 1212 | - __METHOD__, |
|
| 1213 | - sprintf( |
|
| 1214 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1215 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1216 | - ), |
|
| 1217 | - '4.9.27' |
|
| 1218 | - ); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * @deprecated 4.9.27 |
|
| 1225 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1226 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1227 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
| 1228 | - */ |
|
| 1229 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
| 1230 | - { |
|
| 1231 | - EE_Error::doing_it_wrong( |
|
| 1232 | - __METHOD__, |
|
| 1233 | - sprintf( |
|
| 1234 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1235 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1236 | - ), |
|
| 1237 | - '4.9.27' |
|
| 1238 | - ); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * @deprecated 4.9.27 |
|
| 1245 | - * @param string $return_url |
|
| 1246 | - */ |
|
| 1247 | - public static function get_persistent_admin_notices($return_url = '') |
|
| 1248 | - { |
|
| 1249 | - EE_Error::doing_it_wrong( |
|
| 1250 | - __METHOD__, |
|
| 1251 | - sprintf( |
|
| 1252 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1253 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1254 | - ), |
|
| 1255 | - '4.9.27' |
|
| 1256 | - ); |
|
| 1257 | - } |
|
| 1041 | + } |
|
| 1042 | + return ''; |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + /** |
|
| 1048 | + * @return void |
|
| 1049 | + */ |
|
| 1050 | + public static function enqueue_error_scripts() |
|
| 1051 | + { |
|
| 1052 | + self::_print_scripts(); |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + |
|
| 1057 | + /** |
|
| 1058 | + * create error code from filepath, function name, |
|
| 1059 | + * and line number where exception or error was thrown |
|
| 1060 | + * |
|
| 1061 | + * @param string $file |
|
| 1062 | + * @param string $func |
|
| 1063 | + * @param string $line |
|
| 1064 | + * @return string |
|
| 1065 | + */ |
|
| 1066 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
| 1067 | + { |
|
| 1068 | + $file = explode('.', basename($file)); |
|
| 1069 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
| 1070 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1071 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1072 | + return $error_code; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * write exception details to log file |
|
| 1079 | + * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
| 1080 | + * |
|
| 1081 | + * @param int $time |
|
| 1082 | + * @param array $ex |
|
| 1083 | + * @param bool $clear |
|
| 1084 | + * @return void |
|
| 1085 | + */ |
|
| 1086 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
| 1087 | + { |
|
| 1088 | + if (empty($ex)) { |
|
| 1089 | + return; |
|
| 1090 | + } |
|
| 1091 | + if (! $time) { |
|
| 1092 | + $time = time(); |
|
| 1093 | + } |
|
| 1094 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
| 1095 | + . PHP_EOL; |
|
| 1096 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1097 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1098 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1099 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1100 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1101 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1102 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1103 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
| 1104 | + . PHP_EOL; |
|
| 1105 | + try { |
|
| 1106 | + error_log($exception_log); |
|
| 1107 | + } catch (EE_Error $e) { |
|
| 1108 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
| 1109 | + 'event_espresso'), $e->getMessage())); |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + |
|
| 1115 | + /** |
|
| 1116 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
| 1117 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
| 1118 | + * but the code execution is done in a manner that could lead to unexpected results |
|
| 1119 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
| 1120 | + * A good test for knowing whether to use this method is: |
|
| 1121 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
| 1122 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
| 1123 | + * 2. If this is loaded before something else, it won't break anything, |
|
| 1124 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
| 1125 | + * |
|
| 1126 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
| 1127 | + * @param string $function The function that was called |
|
| 1128 | + * @param string $message A message explaining what has been done incorrectly |
|
| 1129 | + * @param string $version The version of Event Espresso where the error was added |
|
| 1130 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 1131 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
| 1132 | + * but not have any notices appear until a later version. This allows developers |
|
| 1133 | + * extra time to update their code before notices appear. |
|
| 1134 | + * @param int $error_type |
|
| 1135 | + */ |
|
| 1136 | + public static function doing_it_wrong( |
|
| 1137 | + $function, |
|
| 1138 | + $message, |
|
| 1139 | + $version, |
|
| 1140 | + $applies_when = '', |
|
| 1141 | + $error_type = null |
|
| 1142 | + ) { |
|
| 1143 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 1144 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
| 1152 | + * |
|
| 1153 | + * @return array { |
|
| 1154 | + * @type array $success all the success messages |
|
| 1155 | + * @type array $errors all the error messages |
|
| 1156 | + * @type array $attention all the attention messages |
|
| 1157 | + * } |
|
| 1158 | + */ |
|
| 1159 | + public static function get_raw_notices() |
|
| 1160 | + { |
|
| 1161 | + return self::$_espresso_notices; |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + /** |
|
| 1167 | + * @deprecated 4.9.27 |
|
| 1168 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1169 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1170 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
| 1171 | + * @return void |
|
| 1172 | + * @throws InvalidDataTypeException |
|
| 1173 | + */ |
|
| 1174 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
| 1175 | + { |
|
| 1176 | + new PersistentAdminNotice( |
|
| 1177 | + $pan_name, |
|
| 1178 | + $pan_message, |
|
| 1179 | + $force_update |
|
| 1180 | + ); |
|
| 1181 | + EE_Error::doing_it_wrong( |
|
| 1182 | + __METHOD__, |
|
| 1183 | + sprintf( |
|
| 1184 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1185 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
| 1186 | + ), |
|
| 1187 | + '4.9.27' |
|
| 1188 | + ); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + |
|
| 1193 | + /** |
|
| 1194 | + * @deprecated 4.9.27 |
|
| 1195 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
| 1196 | + * @param bool $purge |
|
| 1197 | + * @param bool $return |
|
| 1198 | + * @throws DomainException |
|
| 1199 | + * @throws InvalidInterfaceException |
|
| 1200 | + * @throws InvalidDataTypeException |
|
| 1201 | + * @throws ServiceNotFoundException |
|
| 1202 | + * @throws InvalidArgumentException |
|
| 1203 | + */ |
|
| 1204 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
| 1205 | + { |
|
| 1206 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 1207 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 1208 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1209 | + ); |
|
| 1210 | + $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
| 1211 | + EE_Error::doing_it_wrong( |
|
| 1212 | + __METHOD__, |
|
| 1213 | + sprintf( |
|
| 1214 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1215 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1216 | + ), |
|
| 1217 | + '4.9.27' |
|
| 1218 | + ); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + |
|
| 1223 | + /** |
|
| 1224 | + * @deprecated 4.9.27 |
|
| 1225 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1226 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1227 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
| 1228 | + */ |
|
| 1229 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
| 1230 | + { |
|
| 1231 | + EE_Error::doing_it_wrong( |
|
| 1232 | + __METHOD__, |
|
| 1233 | + sprintf( |
|
| 1234 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1235 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1236 | + ), |
|
| 1237 | + '4.9.27' |
|
| 1238 | + ); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * @deprecated 4.9.27 |
|
| 1245 | + * @param string $return_url |
|
| 1246 | + */ |
|
| 1247 | + public static function get_persistent_admin_notices($return_url = '') |
|
| 1248 | + { |
|
| 1249 | + EE_Error::doing_it_wrong( |
|
| 1250 | + __METHOD__, |
|
| 1251 | + sprintf( |
|
| 1252 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1253 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1254 | + ), |
|
| 1255 | + '4.9.27' |
|
| 1256 | + ); |
|
| 1257 | + } |
|
| 1258 | 1258 | |
| 1259 | 1259 | |
| 1260 | 1260 | |
@@ -1269,27 +1269,27 @@ discard block |
||
| 1269 | 1269 | */ |
| 1270 | 1270 | function espresso_error_enqueue_scripts() |
| 1271 | 1271 | { |
| 1272 | - // js for error handling |
|
| 1273 | - wp_register_script( |
|
| 1274 | - 'espresso_core', |
|
| 1275 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1276 | - array('jquery'), |
|
| 1277 | - EVENT_ESPRESSO_VERSION, |
|
| 1278 | - false |
|
| 1279 | - ); |
|
| 1280 | - wp_register_script( |
|
| 1281 | - 'ee_error_js', |
|
| 1282 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1283 | - array('espresso_core'), |
|
| 1284 | - EVENT_ESPRESSO_VERSION, |
|
| 1285 | - false |
|
| 1286 | - ); |
|
| 1272 | + // js for error handling |
|
| 1273 | + wp_register_script( |
|
| 1274 | + 'espresso_core', |
|
| 1275 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1276 | + array('jquery'), |
|
| 1277 | + EVENT_ESPRESSO_VERSION, |
|
| 1278 | + false |
|
| 1279 | + ); |
|
| 1280 | + wp_register_script( |
|
| 1281 | + 'ee_error_js', |
|
| 1282 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1283 | + array('espresso_core'), |
|
| 1284 | + EVENT_ESPRESSO_VERSION, |
|
| 1285 | + false |
|
| 1286 | + ); |
|
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | 1289 | if (is_admin()) { |
| 1290 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1290 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1291 | 1291 | } else { |
| 1292 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1292 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | |
@@ -416,7 +416,7 @@ |
||
| 416 | 416 | * If $expired is set to true, then only line items for expired sessions will be returned. |
| 417 | 417 | * If $expired is set to false, then only line items for active sessions will be returned. |
| 418 | 418 | * |
| 419 | - * @param null $expired |
|
| 419 | + * @param boolean $expired |
|
| 420 | 420 | * @return EE_Base_Class[]|EE_Line_Item[] |
| 421 | 421 | * @throws EE_Error |
| 422 | 422 | * @throws InvalidArgumentException |
@@ -47,431 +47,431 @@ |
||
| 47 | 47 | class EEM_Line_Item extends EEM_Base |
| 48 | 48 | { |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Tax sub-total is just the total of all the taxes, which should be children |
|
| 52 | - * of this line item. There should only ever be one tax sub-total, and it should |
|
| 53 | - * be a direct child of |
|
| 54 | - */ |
|
| 55 | - const type_tax_sub_total = 'tax-sub-total'; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Tax line items indicate a tax applied to all the taxable line items. |
|
| 59 | - * Should not have any children line items. |
|
| 60 | - */ |
|
| 61 | - const type_tax = 'tax'; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Indicating individual items purchased, or discounts or surcharges. |
|
| 65 | - * The sum of all the regular line items plus the tax items should equal |
|
| 66 | - * the grand total. |
|
| 67 | - * Possible children fo sub-line-items and cancellations. |
|
| 68 | - */ |
|
| 69 | - const type_line_item = 'line-item'; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * line item indicating all the factors that make a single line item. |
|
| 73 | - * Sub-line items should have NO children line items. |
|
| 74 | - */ |
|
| 75 | - const type_sub_line_item = 'sub-item'; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * line item indicating a sub-total (eg total for an event, or before taxes). |
|
| 79 | - * Direct children can be line items and other sub-totals |
|
| 80 | - * |
|
| 81 | - */ |
|
| 82 | - const type_sub_total = 'sub-total'; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * line item for teh grand total of an order. Its direct children |
|
| 86 | - * should be tax subtotals and subtotals, and possibly a regular line item |
|
| 87 | - * indicating a transaction-wide discount/surcharge |
|
| 88 | - */ |
|
| 89 | - const type_total = 'total'; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
| 93 | - * should be created, indicating the quantity that were cancelled |
|
| 94 | - * (because a line item could have a quantity of 1, and its cancellation item |
|
| 95 | - * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
| 96 | - * cancelled, and only one remains). |
|
| 97 | - * When items are refunded, a cancellation line item should be made, which points |
|
| 98 | - * to teh payment model object which actually refunded the payment. |
|
| 99 | - * Cancellations should NOT have any children line items; the should NOT affect |
|
| 100 | - * any calculations, and are only meant as a record that cancellations have occurred. |
|
| 101 | - */ |
|
| 102 | - const type_cancellation = 'cancellation'; |
|
| 103 | - |
|
| 104 | - // private instance of the EEM_Line_Item object |
|
| 105 | - protected static $_instance = NULL; |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * private constructor to prevent direct creation |
|
| 110 | - * @Constructor |
|
| 111 | - * @access protected |
|
| 112 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 113 | - * @return \EEM_Line_Item |
|
| 114 | - */ |
|
| 115 | - protected function __construct($timezone) |
|
| 116 | - { |
|
| 117 | - $this->singular_item = __('Line Item', 'event_espresso'); |
|
| 118 | - $this->plural_item = __('Line Items', 'event_espresso'); |
|
| 119 | - |
|
| 120 | - $this->_tables = array( |
|
| 121 | - 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
| 122 | - ); |
|
| 123 | - $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
| 124 | - $this->_fields = array( |
|
| 125 | - 'Line_Item' => array( |
|
| 126 | - 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
| 127 | - 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE), |
|
| 128 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'), |
|
| 129 | - 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''), |
|
| 130 | - 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE), |
|
| 131 | - 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0), |
|
| 132 | - 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0), |
|
| 133 | - 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE), |
|
| 134 | - 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1), |
|
| 135 | - 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0), |
|
| 136 | - 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1), |
|
| 137 | - 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL), |
|
| 138 | - 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array( |
|
| 139 | - self::type_line_item => __("Line Item", "event_espresso"), |
|
| 140 | - self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
|
| 141 | - self::type_sub_total => __("Subtotal", "event_espresso"), |
|
| 142 | - self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
|
| 143 | - self::type_tax => __("Tax", "event_espresso"), |
|
| 144 | - self::type_total => __("Total", "event_espresso"), |
|
| 145 | - self::type_cancellation => __('Cancellation', 'event_espresso') |
|
| 146 | - ) |
|
| 147 | - ), |
|
| 148 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for), |
|
| 149 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for), |
|
| 150 | - 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
| 151 | - ) |
|
| 152 | - ); |
|
| 153 | - $this->_model_relations = array( |
|
| 154 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
| 155 | - 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
| 156 | - 'Price' => new EE_Belongs_To_Any_Relation(), |
|
| 157 | - 'Event' => new EE_Belongs_To_Any_Relation() |
|
| 158 | - ); |
|
| 159 | - $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
| 160 | - $this->_caps_slug = 'transactions'; |
|
| 161 | - parent::__construct($timezone); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Gets all the line items for this transaction of the given type |
|
| 167 | - * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
| 168 | - * @param EE_Transaction|int $transaction |
|
| 169 | - * @return EE_Line_Item[] |
|
| 170 | - */ |
|
| 171 | - public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
| 172 | - { |
|
| 173 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
| 174 | - return $this->get_all(array(array( |
|
| 175 | - 'LIN_type' => $line_item_type, |
|
| 176 | - 'TXN_ID' => $transaction |
|
| 177 | - ))); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Gets all line items unrelated to tickets that are normal line items |
|
| 183 | - * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
| 184 | - * @param EE_Transaction|int $transaction |
|
| 185 | - * @return EE_Line_Item[] |
|
| 186 | - */ |
|
| 187 | - public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
| 188 | - { |
|
| 189 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
| 190 | - return $this->get_all(array(array( |
|
| 191 | - 'LIN_type' => self::type_line_item, |
|
| 192 | - 'TXN_ID' => $transaction, |
|
| 193 | - 'OR' => array( |
|
| 194 | - 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
| 195 | - 'OBJ_type*null' => array('IS_NULL')) |
|
| 196 | - ))); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
| 201 | - * This needs to be very efficient |
|
| 202 | - * because if there are spam bots afoot there will be LOTS of line items |
|
| 203 | - * @return int count of how many deleted |
|
| 204 | - */ |
|
| 205 | - public function delete_line_items_with_no_transaction() |
|
| 206 | - { |
|
| 207 | - /** @type WPDB $wpdb */ |
|
| 208 | - global $wpdb; |
|
| 209 | - $time_to_leave_alone = apply_filters( |
|
| 210 | - 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', WEEK_IN_SECONDS |
|
| 211 | - ); |
|
| 212 | - $query = $wpdb->prepare( |
|
| 213 | - 'DELETE li |
|
| 50 | + /** |
|
| 51 | + * Tax sub-total is just the total of all the taxes, which should be children |
|
| 52 | + * of this line item. There should only ever be one tax sub-total, and it should |
|
| 53 | + * be a direct child of |
|
| 54 | + */ |
|
| 55 | + const type_tax_sub_total = 'tax-sub-total'; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Tax line items indicate a tax applied to all the taxable line items. |
|
| 59 | + * Should not have any children line items. |
|
| 60 | + */ |
|
| 61 | + const type_tax = 'tax'; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Indicating individual items purchased, or discounts or surcharges. |
|
| 65 | + * The sum of all the regular line items plus the tax items should equal |
|
| 66 | + * the grand total. |
|
| 67 | + * Possible children fo sub-line-items and cancellations. |
|
| 68 | + */ |
|
| 69 | + const type_line_item = 'line-item'; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * line item indicating all the factors that make a single line item. |
|
| 73 | + * Sub-line items should have NO children line items. |
|
| 74 | + */ |
|
| 75 | + const type_sub_line_item = 'sub-item'; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * line item indicating a sub-total (eg total for an event, or before taxes). |
|
| 79 | + * Direct children can be line items and other sub-totals |
|
| 80 | + * |
|
| 81 | + */ |
|
| 82 | + const type_sub_total = 'sub-total'; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * line item for teh grand total of an order. Its direct children |
|
| 86 | + * should be tax subtotals and subtotals, and possibly a regular line item |
|
| 87 | + * indicating a transaction-wide discount/surcharge |
|
| 88 | + */ |
|
| 89 | + const type_total = 'total'; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
| 93 | + * should be created, indicating the quantity that were cancelled |
|
| 94 | + * (because a line item could have a quantity of 1, and its cancellation item |
|
| 95 | + * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
| 96 | + * cancelled, and only one remains). |
|
| 97 | + * When items are refunded, a cancellation line item should be made, which points |
|
| 98 | + * to teh payment model object which actually refunded the payment. |
|
| 99 | + * Cancellations should NOT have any children line items; the should NOT affect |
|
| 100 | + * any calculations, and are only meant as a record that cancellations have occurred. |
|
| 101 | + */ |
|
| 102 | + const type_cancellation = 'cancellation'; |
|
| 103 | + |
|
| 104 | + // private instance of the EEM_Line_Item object |
|
| 105 | + protected static $_instance = NULL; |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * private constructor to prevent direct creation |
|
| 110 | + * @Constructor |
|
| 111 | + * @access protected |
|
| 112 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 113 | + * @return \EEM_Line_Item |
|
| 114 | + */ |
|
| 115 | + protected function __construct($timezone) |
|
| 116 | + { |
|
| 117 | + $this->singular_item = __('Line Item', 'event_espresso'); |
|
| 118 | + $this->plural_item = __('Line Items', 'event_espresso'); |
|
| 119 | + |
|
| 120 | + $this->_tables = array( |
|
| 121 | + 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
| 122 | + ); |
|
| 123 | + $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
| 124 | + $this->_fields = array( |
|
| 125 | + 'Line_Item' => array( |
|
| 126 | + 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
| 127 | + 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE), |
|
| 128 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'), |
|
| 129 | + 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''), |
|
| 130 | + 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE), |
|
| 131 | + 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0), |
|
| 132 | + 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0), |
|
| 133 | + 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE), |
|
| 134 | + 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1), |
|
| 135 | + 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0), |
|
| 136 | + 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1), |
|
| 137 | + 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL), |
|
| 138 | + 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array( |
|
| 139 | + self::type_line_item => __("Line Item", "event_espresso"), |
|
| 140 | + self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
|
| 141 | + self::type_sub_total => __("Subtotal", "event_espresso"), |
|
| 142 | + self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
|
| 143 | + self::type_tax => __("Tax", "event_espresso"), |
|
| 144 | + self::type_total => __("Total", "event_espresso"), |
|
| 145 | + self::type_cancellation => __('Cancellation', 'event_espresso') |
|
| 146 | + ) |
|
| 147 | + ), |
|
| 148 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for), |
|
| 149 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for), |
|
| 150 | + 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
| 151 | + ) |
|
| 152 | + ); |
|
| 153 | + $this->_model_relations = array( |
|
| 154 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
| 155 | + 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
| 156 | + 'Price' => new EE_Belongs_To_Any_Relation(), |
|
| 157 | + 'Event' => new EE_Belongs_To_Any_Relation() |
|
| 158 | + ); |
|
| 159 | + $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
| 160 | + $this->_caps_slug = 'transactions'; |
|
| 161 | + parent::__construct($timezone); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Gets all the line items for this transaction of the given type |
|
| 167 | + * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
| 168 | + * @param EE_Transaction|int $transaction |
|
| 169 | + * @return EE_Line_Item[] |
|
| 170 | + */ |
|
| 171 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
| 172 | + { |
|
| 173 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
| 174 | + return $this->get_all(array(array( |
|
| 175 | + 'LIN_type' => $line_item_type, |
|
| 176 | + 'TXN_ID' => $transaction |
|
| 177 | + ))); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Gets all line items unrelated to tickets that are normal line items |
|
| 183 | + * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
| 184 | + * @param EE_Transaction|int $transaction |
|
| 185 | + * @return EE_Line_Item[] |
|
| 186 | + */ |
|
| 187 | + public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
| 188 | + { |
|
| 189 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
| 190 | + return $this->get_all(array(array( |
|
| 191 | + 'LIN_type' => self::type_line_item, |
|
| 192 | + 'TXN_ID' => $transaction, |
|
| 193 | + 'OR' => array( |
|
| 194 | + 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
| 195 | + 'OBJ_type*null' => array('IS_NULL')) |
|
| 196 | + ))); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
| 201 | + * This needs to be very efficient |
|
| 202 | + * because if there are spam bots afoot there will be LOTS of line items |
|
| 203 | + * @return int count of how many deleted |
|
| 204 | + */ |
|
| 205 | + public function delete_line_items_with_no_transaction() |
|
| 206 | + { |
|
| 207 | + /** @type WPDB $wpdb */ |
|
| 208 | + global $wpdb; |
|
| 209 | + $time_to_leave_alone = apply_filters( |
|
| 210 | + 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', WEEK_IN_SECONDS |
|
| 211 | + ); |
|
| 212 | + $query = $wpdb->prepare( |
|
| 213 | + 'DELETE li |
|
| 214 | 214 | FROM ' . $this->table() . ' li |
| 215 | 215 | LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
| 216 | 216 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
| 217 | - // use GMT time because that's what TXN_timestamps are in |
|
| 218 | - date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
| 219 | - ); |
|
| 220 | - return $wpdb->query($query); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * get_line_item_for_transaction_object |
|
| 226 | - * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
| 227 | - * |
|
| 228 | - * @param int $TXN_ID |
|
| 229 | - * @param \EE_Base_Class $object |
|
| 230 | - * @return EE_Line_Item[] |
|
| 231 | - */ |
|
| 232 | - public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
| 233 | - { |
|
| 234 | - return $this->get_all(array(array( |
|
| 235 | - 'TXN_ID' => $TXN_ID, |
|
| 236 | - 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
| 237 | - 'OBJ_ID' => $object->ID() |
|
| 238 | - ))); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * get_object_line_items_for_transaction |
|
| 244 | - * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
| 245 | - * |
|
| 246 | - * @param int $TXN_ID |
|
| 247 | - * @param string $OBJ_type |
|
| 248 | - * @param array $OBJ_IDs |
|
| 249 | - * @return EE_Line_Item[] |
|
| 250 | - */ |
|
| 251 | - public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) |
|
| 252 | - { |
|
| 253 | - $query_params = array( |
|
| 254 | - 'OBJ_type' => $OBJ_type, |
|
| 255 | - // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
| 256 | - 'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
| 257 | - ); |
|
| 258 | - if ($TXN_ID) { |
|
| 259 | - $query_params['TXN_ID'] = $TXN_ID; |
|
| 260 | - } |
|
| 261 | - return $this->get_all(array($query_params)); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * get_all_ticket_line_items_for_transaction |
|
| 267 | - * |
|
| 268 | - * @param EE_Transaction $transaction |
|
| 269 | - * @return EE_Line_Item[] |
|
| 270 | - */ |
|
| 271 | - public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
| 272 | - { |
|
| 273 | - return $this->get_all(array( |
|
| 274 | - array( |
|
| 275 | - 'TXN_ID' => $transaction->ID(), |
|
| 276 | - 'OBJ_type' => 'Ticket', |
|
| 277 | - ) |
|
| 278 | - )); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * get_ticket_line_item_for_transaction |
|
| 284 | - * |
|
| 285 | - * @param int $TXN_ID |
|
| 286 | - * @param int $TKT_ID |
|
| 287 | - * @return \EE_Line_Item |
|
| 288 | - */ |
|
| 289 | - public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
| 290 | - { |
|
| 291 | - return $this->get_one(array( |
|
| 292 | - array( |
|
| 293 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
| 294 | - 'OBJ_ID' => $TKT_ID, |
|
| 295 | - 'OBJ_type' => 'Ticket', |
|
| 296 | - ) |
|
| 297 | - )); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * get_existing_promotion_line_item |
|
| 303 | - * searches the cart for existing line items for the specified promotion |
|
| 304 | - * |
|
| 305 | - * @since 1.0.0 |
|
| 306 | - * |
|
| 307 | - * @param EE_Line_Item $parent_line_item |
|
| 308 | - * @param EE_Promotion $promotion |
|
| 309 | - * @return EE_Line_Item |
|
| 310 | - */ |
|
| 311 | - public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
| 312 | - { |
|
| 313 | - return $this->get_one(array( |
|
| 314 | - array( |
|
| 315 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
| 316 | - 'LIN_parent' => $parent_line_item->ID(), |
|
| 317 | - 'OBJ_type' => 'Promotion', |
|
| 318 | - 'OBJ_ID' => $promotion->ID() |
|
| 319 | - ) |
|
| 320 | - )); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * get_all_promotion_line_items |
|
| 326 | - * searches the cart for any and all existing promotion line items |
|
| 327 | - * |
|
| 328 | - * @since 1.0.0 |
|
| 329 | - * |
|
| 330 | - * @param EE_Line_Item $parent_line_item |
|
| 331 | - * @return EE_Line_Item[] |
|
| 332 | - */ |
|
| 333 | - public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
| 334 | - { |
|
| 335 | - return $this->get_all(array( |
|
| 336 | - array( |
|
| 337 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
| 338 | - 'LIN_parent' => $parent_line_item->ID(), |
|
| 339 | - 'OBJ_type' => 'Promotion' |
|
| 340 | - ) |
|
| 341 | - )); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Gets the registration's corresponding line item. |
|
| 346 | - * Note: basically does NOT support having multiple line items for a single ticket, |
|
| 347 | - * which would happen if some of the registrations had a price modifier while others didn't. |
|
| 348 | - * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
| 349 | - * @param EE_Registration $registration |
|
| 350 | - * @return EE_Line_ITem |
|
| 351 | - */ |
|
| 352 | - public function get_line_item_for_registration(EE_Registration $registration) |
|
| 353 | - { |
|
| 354 | - return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Gets the query params used to retrieve a specific line item for the given registration |
|
| 359 | - * @param EE_Registration $registration |
|
| 360 | - * @param array $original_query_params any extra query params you'd like to be merged with |
|
| 361 | - * @return array like EEM_Base::get_all()'s $query_params |
|
| 362 | - */ |
|
| 363 | - public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) |
|
| 364 | - { |
|
| 365 | - return array_replace_recursive($original_query_params, array( |
|
| 366 | - array( |
|
| 367 | - 'OBJ_ID' => $registration->ticket_ID(), |
|
| 368 | - 'OBJ_type' => 'Ticket', |
|
| 369 | - 'TXN_ID' => $registration->transaction_ID() |
|
| 370 | - ) |
|
| 371 | - )); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 377 | - * @throws InvalidInterfaceException |
|
| 378 | - * @throws InvalidDataTypeException |
|
| 379 | - * @throws EE_Error |
|
| 380 | - * @throws InvalidArgumentException |
|
| 381 | - */ |
|
| 382 | - public function get_total_line_items_with_no_transaction() |
|
| 383 | - { |
|
| 384 | - return $this->get_total_line_items_for_carts(); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 390 | - * @throws InvalidInterfaceException |
|
| 391 | - * @throws InvalidDataTypeException |
|
| 392 | - * @throws EE_Error |
|
| 393 | - * @throws InvalidArgumentException |
|
| 394 | - */ |
|
| 395 | - public function get_total_line_items_for_active_carts() |
|
| 396 | - { |
|
| 397 | - return $this->get_total_line_items_for_carts(false); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 403 | - * @throws InvalidInterfaceException |
|
| 404 | - * @throws InvalidDataTypeException |
|
| 405 | - * @throws EE_Error |
|
| 406 | - * @throws InvalidArgumentException |
|
| 407 | - */ |
|
| 408 | - public function get_total_line_items_for_expired_carts() |
|
| 409 | - { |
|
| 410 | - return $this->get_total_line_items_for_carts(true); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
| 416 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
| 417 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
| 418 | - * |
|
| 419 | - * @param null $expired |
|
| 420 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 421 | - * @throws EE_Error |
|
| 422 | - * @throws InvalidArgumentException |
|
| 423 | - * @throws InvalidDataTypeException |
|
| 424 | - * @throws InvalidInterfaceException |
|
| 425 | - */ |
|
| 426 | - private function get_total_line_items_for_carts($expired = null) |
|
| 427 | - { |
|
| 428 | - $where_params = array( |
|
| 429 | - 'TXN_ID' => 0, |
|
| 430 | - 'LIN_type' => 'total', |
|
| 431 | - ); |
|
| 432 | - if ($expired !== null) { |
|
| 433 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 434 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 435 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 436 | - ); |
|
| 437 | - $where_params['LIN_timestamp'] = array( |
|
| 438 | - $expired ? '<=' : '>', |
|
| 439 | - $session_lifespan->expiration(), |
|
| 440 | - ); |
|
| 441 | - } |
|
| 442 | - return $this->get_all(array($where_params)); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * Returns an array of ticket total line items where the TXN_ID is 0 |
|
| 448 | - * AND the timestamp is older than the session lifespan. |
|
| 449 | - * |
|
| 450 | - * @param int $timestamp |
|
| 451 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 452 | - * @throws EE_Error |
|
| 453 | - * @throws InvalidArgumentException |
|
| 454 | - * @throws InvalidDataTypeException |
|
| 455 | - * @throws InvalidInterfaceException |
|
| 456 | - */ |
|
| 457 | - public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
| 458 | - { |
|
| 459 | - if(! absint($timestamp)) { |
|
| 460 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 461 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 462 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 463 | - ); |
|
| 464 | - $timestamp = $session_lifespan->expiration(); |
|
| 465 | - } |
|
| 466 | - return $this->get_all( |
|
| 467 | - array( |
|
| 468 | - array( |
|
| 469 | - 'TXN_ID' => 0, |
|
| 470 | - 'OBJ_type' => 'Ticket', |
|
| 471 | - 'LIN_timestamp' => array('<=', $timestamp), |
|
| 472 | - ) |
|
| 473 | - ) |
|
| 474 | - ); |
|
| 475 | - } |
|
| 217 | + // use GMT time because that's what TXN_timestamps are in |
|
| 218 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
| 219 | + ); |
|
| 220 | + return $wpdb->query($query); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * get_line_item_for_transaction_object |
|
| 226 | + * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
| 227 | + * |
|
| 228 | + * @param int $TXN_ID |
|
| 229 | + * @param \EE_Base_Class $object |
|
| 230 | + * @return EE_Line_Item[] |
|
| 231 | + */ |
|
| 232 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
| 233 | + { |
|
| 234 | + return $this->get_all(array(array( |
|
| 235 | + 'TXN_ID' => $TXN_ID, |
|
| 236 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
| 237 | + 'OBJ_ID' => $object->ID() |
|
| 238 | + ))); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * get_object_line_items_for_transaction |
|
| 244 | + * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
| 245 | + * |
|
| 246 | + * @param int $TXN_ID |
|
| 247 | + * @param string $OBJ_type |
|
| 248 | + * @param array $OBJ_IDs |
|
| 249 | + * @return EE_Line_Item[] |
|
| 250 | + */ |
|
| 251 | + public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) |
|
| 252 | + { |
|
| 253 | + $query_params = array( |
|
| 254 | + 'OBJ_type' => $OBJ_type, |
|
| 255 | + // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
| 256 | + 'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
| 257 | + ); |
|
| 258 | + if ($TXN_ID) { |
|
| 259 | + $query_params['TXN_ID'] = $TXN_ID; |
|
| 260 | + } |
|
| 261 | + return $this->get_all(array($query_params)); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * get_all_ticket_line_items_for_transaction |
|
| 267 | + * |
|
| 268 | + * @param EE_Transaction $transaction |
|
| 269 | + * @return EE_Line_Item[] |
|
| 270 | + */ |
|
| 271 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
| 272 | + { |
|
| 273 | + return $this->get_all(array( |
|
| 274 | + array( |
|
| 275 | + 'TXN_ID' => $transaction->ID(), |
|
| 276 | + 'OBJ_type' => 'Ticket', |
|
| 277 | + ) |
|
| 278 | + )); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * get_ticket_line_item_for_transaction |
|
| 284 | + * |
|
| 285 | + * @param int $TXN_ID |
|
| 286 | + * @param int $TKT_ID |
|
| 287 | + * @return \EE_Line_Item |
|
| 288 | + */ |
|
| 289 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
| 290 | + { |
|
| 291 | + return $this->get_one(array( |
|
| 292 | + array( |
|
| 293 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
| 294 | + 'OBJ_ID' => $TKT_ID, |
|
| 295 | + 'OBJ_type' => 'Ticket', |
|
| 296 | + ) |
|
| 297 | + )); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * get_existing_promotion_line_item |
|
| 303 | + * searches the cart for existing line items for the specified promotion |
|
| 304 | + * |
|
| 305 | + * @since 1.0.0 |
|
| 306 | + * |
|
| 307 | + * @param EE_Line_Item $parent_line_item |
|
| 308 | + * @param EE_Promotion $promotion |
|
| 309 | + * @return EE_Line_Item |
|
| 310 | + */ |
|
| 311 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
| 312 | + { |
|
| 313 | + return $this->get_one(array( |
|
| 314 | + array( |
|
| 315 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
| 316 | + 'LIN_parent' => $parent_line_item->ID(), |
|
| 317 | + 'OBJ_type' => 'Promotion', |
|
| 318 | + 'OBJ_ID' => $promotion->ID() |
|
| 319 | + ) |
|
| 320 | + )); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * get_all_promotion_line_items |
|
| 326 | + * searches the cart for any and all existing promotion line items |
|
| 327 | + * |
|
| 328 | + * @since 1.0.0 |
|
| 329 | + * |
|
| 330 | + * @param EE_Line_Item $parent_line_item |
|
| 331 | + * @return EE_Line_Item[] |
|
| 332 | + */ |
|
| 333 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
| 334 | + { |
|
| 335 | + return $this->get_all(array( |
|
| 336 | + array( |
|
| 337 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
| 338 | + 'LIN_parent' => $parent_line_item->ID(), |
|
| 339 | + 'OBJ_type' => 'Promotion' |
|
| 340 | + ) |
|
| 341 | + )); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Gets the registration's corresponding line item. |
|
| 346 | + * Note: basically does NOT support having multiple line items for a single ticket, |
|
| 347 | + * which would happen if some of the registrations had a price modifier while others didn't. |
|
| 348 | + * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
| 349 | + * @param EE_Registration $registration |
|
| 350 | + * @return EE_Line_ITem |
|
| 351 | + */ |
|
| 352 | + public function get_line_item_for_registration(EE_Registration $registration) |
|
| 353 | + { |
|
| 354 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Gets the query params used to retrieve a specific line item for the given registration |
|
| 359 | + * @param EE_Registration $registration |
|
| 360 | + * @param array $original_query_params any extra query params you'd like to be merged with |
|
| 361 | + * @return array like EEM_Base::get_all()'s $query_params |
|
| 362 | + */ |
|
| 363 | + public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) |
|
| 364 | + { |
|
| 365 | + return array_replace_recursive($original_query_params, array( |
|
| 366 | + array( |
|
| 367 | + 'OBJ_ID' => $registration->ticket_ID(), |
|
| 368 | + 'OBJ_type' => 'Ticket', |
|
| 369 | + 'TXN_ID' => $registration->transaction_ID() |
|
| 370 | + ) |
|
| 371 | + )); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 377 | + * @throws InvalidInterfaceException |
|
| 378 | + * @throws InvalidDataTypeException |
|
| 379 | + * @throws EE_Error |
|
| 380 | + * @throws InvalidArgumentException |
|
| 381 | + */ |
|
| 382 | + public function get_total_line_items_with_no_transaction() |
|
| 383 | + { |
|
| 384 | + return $this->get_total_line_items_for_carts(); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 390 | + * @throws InvalidInterfaceException |
|
| 391 | + * @throws InvalidDataTypeException |
|
| 392 | + * @throws EE_Error |
|
| 393 | + * @throws InvalidArgumentException |
|
| 394 | + */ |
|
| 395 | + public function get_total_line_items_for_active_carts() |
|
| 396 | + { |
|
| 397 | + return $this->get_total_line_items_for_carts(false); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 403 | + * @throws InvalidInterfaceException |
|
| 404 | + * @throws InvalidDataTypeException |
|
| 405 | + * @throws EE_Error |
|
| 406 | + * @throws InvalidArgumentException |
|
| 407 | + */ |
|
| 408 | + public function get_total_line_items_for_expired_carts() |
|
| 409 | + { |
|
| 410 | + return $this->get_total_line_items_for_carts(true); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
| 416 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
| 417 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
| 418 | + * |
|
| 419 | + * @param null $expired |
|
| 420 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 421 | + * @throws EE_Error |
|
| 422 | + * @throws InvalidArgumentException |
|
| 423 | + * @throws InvalidDataTypeException |
|
| 424 | + * @throws InvalidInterfaceException |
|
| 425 | + */ |
|
| 426 | + private function get_total_line_items_for_carts($expired = null) |
|
| 427 | + { |
|
| 428 | + $where_params = array( |
|
| 429 | + 'TXN_ID' => 0, |
|
| 430 | + 'LIN_type' => 'total', |
|
| 431 | + ); |
|
| 432 | + if ($expired !== null) { |
|
| 433 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 434 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 435 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 436 | + ); |
|
| 437 | + $where_params['LIN_timestamp'] = array( |
|
| 438 | + $expired ? '<=' : '>', |
|
| 439 | + $session_lifespan->expiration(), |
|
| 440 | + ); |
|
| 441 | + } |
|
| 442 | + return $this->get_all(array($where_params)); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * Returns an array of ticket total line items where the TXN_ID is 0 |
|
| 448 | + * AND the timestamp is older than the session lifespan. |
|
| 449 | + * |
|
| 450 | + * @param int $timestamp |
|
| 451 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 452 | + * @throws EE_Error |
|
| 453 | + * @throws InvalidArgumentException |
|
| 454 | + * @throws InvalidDataTypeException |
|
| 455 | + * @throws InvalidInterfaceException |
|
| 456 | + */ |
|
| 457 | + public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
| 458 | + { |
|
| 459 | + if(! absint($timestamp)) { |
|
| 460 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 461 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 462 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 463 | + ); |
|
| 464 | + $timestamp = $session_lifespan->expiration(); |
|
| 465 | + } |
|
| 466 | + return $this->get_all( |
|
| 467 | + array( |
|
| 468 | + array( |
|
| 469 | + 'TXN_ID' => 0, |
|
| 470 | + 'OBJ_type' => 'Ticket', |
|
| 471 | + 'LIN_timestamp' => array('<=', $timestamp), |
|
| 472 | + ) |
|
| 473 | + ) |
|
| 474 | + ); |
|
| 475 | + } |
|
| 476 | 476 | |
| 477 | 477 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 5 | 5 | use EventEspresso\core\services\loaders\LoaderFactory; |
| 6 | 6 | |
| 7 | -if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 7 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Event Espresso |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | ); |
| 212 | 212 | $query = $wpdb->prepare( |
| 213 | 213 | 'DELETE li |
| 214 | - FROM ' . $this->table() . ' li |
|
| 215 | - LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
|
| 214 | + FROM ' . $this->table().' li |
|
| 215 | + LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID |
|
| 216 | 216 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
| 217 | 217 | // use GMT time because that's what TXN_timestamps are in |
| 218 | 218 | date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | $query_params = array( |
| 254 | 254 | 'OBJ_type' => $OBJ_type, |
| 255 | 255 | // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
| 256 | - 'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
| 256 | + 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
| 257 | 257 | ); |
| 258 | 258 | if ($TXN_ID) { |
| 259 | 259 | $query_params['TXN_ID'] = $TXN_ID; |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | */ |
| 457 | 457 | public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
| 458 | 458 | { |
| 459 | - if(! absint($timestamp)) { |
|
| 459 | + if ( ! absint($timestamp)) { |
|
| 460 | 460 | /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
| 461 | 461 | $session_lifespan = LoaderFactory::getLoader()->getShared( |
| 462 | 462 | 'EventEspresso\core\domain\values\session\SessionLifespan' |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | |
| 64 | 64 | } else { |
| 65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 67 | - /** |
|
| 68 | - * espresso_minimum_php_version_error |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 67 | + /** |
|
| 68 | + * espresso_minimum_php_version_error |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.051'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.051'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -24,1073 +24,1073 @@ |
||
| 24 | 24 | class EED_Ticket_Sales_Monitor extends EED_Module |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - const debug = false; // true false |
|
| 28 | - |
|
| 29 | - private static $nl = ''; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * an array of raw ticket data from EED_Ticket_Selector |
|
| 33 | - * |
|
| 34 | - * @var array $ticket_selections |
|
| 35 | - */ |
|
| 36 | - protected $ticket_selections = array(); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
| 40 | - * according to how they are displayed in the actual Ticket_Selector |
|
| 41 | - * this tracks the current row being processed |
|
| 42 | - * |
|
| 43 | - * @var int $current_row |
|
| 44 | - */ |
|
| 45 | - protected $current_row = 0; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * an array for tracking names of tickets that have sold out |
|
| 49 | - * |
|
| 50 | - * @var array $sold_out_tickets |
|
| 51 | - */ |
|
| 52 | - protected $sold_out_tickets = array(); |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * an array for tracking names of tickets that have had their quantities reduced |
|
| 56 | - * |
|
| 57 | - * @var array $decremented_tickets |
|
| 58 | - */ |
|
| 59 | - protected $decremented_tickets = array(); |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public static function set_hooks() |
|
| 69 | - { |
|
| 70 | - self::$nl = defined('EE_TESTS_DIR')? "\n" : '<br />'; |
|
| 71 | - // release tickets for expired carts |
|
| 72 | - add_action( |
|
| 73 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 74 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
| 75 | - 1 |
|
| 76 | - ); |
|
| 77 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
| 78 | - add_filter( |
|
| 79 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
| 80 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
| 81 | - 20, |
|
| 82 | - 3 |
|
| 83 | - ); |
|
| 84 | - // add notices for sold out tickets |
|
| 85 | - add_action( |
|
| 86 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 87 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
| 88 | - 10 |
|
| 89 | - ); |
|
| 90 | - // handle ticket quantities adjusted in cart |
|
| 91 | - //add_action( |
|
| 92 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
| 93 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
| 94 | - // 10, 2 |
|
| 95 | - //); |
|
| 96 | - // handle tickets deleted from cart |
|
| 97 | - add_action( |
|
| 98 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
| 99 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
| 100 | - 10, |
|
| 101 | - 2 |
|
| 102 | - ); |
|
| 103 | - // handle emptied carts |
|
| 104 | - add_action( |
|
| 105 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
| 106 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 107 | - 10, |
|
| 108 | - 1 |
|
| 109 | - ); |
|
| 110 | - add_action( |
|
| 111 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
| 112 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 113 | - 10, |
|
| 114 | - 1 |
|
| 115 | - ); |
|
| 116 | - // handle cancelled registrations |
|
| 117 | - add_action( |
|
| 118 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
| 119 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
| 120 | - 10, |
|
| 121 | - 1 |
|
| 122 | - ); |
|
| 123 | - // cron tasks |
|
| 124 | - add_action( |
|
| 125 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 126 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 127 | - 10, |
|
| 128 | - 1 |
|
| 129 | - ); |
|
| 130 | - add_action( |
|
| 131 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 132 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 133 | - 10, |
|
| 134 | - 1 |
|
| 135 | - ); |
|
| 136 | - add_action( |
|
| 137 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 138 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
| 139 | - 10, |
|
| 140 | - 1 |
|
| 141 | - ); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 148 | - * |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - public static function set_hooks_admin() |
|
| 152 | - { |
|
| 153 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
| 160 | - */ |
|
| 161 | - public static function instance() |
|
| 162 | - { |
|
| 163 | - return parent::get_instance(__CLASS__); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @param WP_Query $WP_Query |
|
| 170 | - * @return void |
|
| 171 | - */ |
|
| 172 | - public function run($WP_Query) |
|
| 173 | - { |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Retrieves grand totals from the line items that have no TXN ID |
|
| 184 | - * and timestamps less than the current time minus the session lifespan. |
|
| 185 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
| 186 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
| 187 | - * |
|
| 188 | - * @return void |
|
| 189 | - * @throws DomainException |
|
| 190 | - * @throws EE_Error |
|
| 191 | - * @throws InvalidArgumentException |
|
| 192 | - * @throws InvalidDataTypeException |
|
| 193 | - * @throws InvalidInterfaceException |
|
| 194 | - * @throws UnexpectedEntityException |
|
| 195 | - */ |
|
| 196 | - public static function release_tickets_for_expired_carts() |
|
| 197 | - { |
|
| 198 | - if (self::debug) { |
|
| 199 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 200 | - } |
|
| 201 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
| 202 | - $expired_ticket_IDs = array(); |
|
| 203 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 204 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 205 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 206 | - ); |
|
| 207 | - $timestamp = $session_lifespan->expiration(); |
|
| 208 | - $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
| 209 | - if (self::debug) { |
|
| 210 | - echo self::$nl . ' . time(): ' . time(); |
|
| 211 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
| 212 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
| 213 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
| 214 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
| 215 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
| 216 | - } |
|
| 217 | - if (! empty($expired_ticket_line_items)) { |
|
| 218 | - foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
| 219 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
| 220 | - continue; |
|
| 221 | - } |
|
| 222 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
| 223 | - if (self::debug) { |
|
| 224 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
| 225 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' . date('Y-m-d h:i a', |
|
| 226 | - $expired_ticket_line_item->timestamp(true)); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - if (! empty($expired_ticket_IDs)) { |
|
| 230 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 231 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
| 232 | - array(), |
|
| 233 | - __FUNCTION__ |
|
| 234 | - ); |
|
| 235 | - // now let's get rid of expired line items so that they can't interfere with tracking |
|
| 236 | - EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - do_action( |
|
| 240 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 241 | - $expired_ticket_IDs, |
|
| 242 | - $expired_ticket_line_items |
|
| 243 | - ); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
| 254 | - * |
|
| 255 | - * @param int $qty |
|
| 256 | - * @param EE_Ticket $ticket |
|
| 257 | - * @return bool |
|
| 258 | - * @throws UnexpectedEntityException |
|
| 259 | - * @throws EE_Error |
|
| 260 | - */ |
|
| 261 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
| 262 | - { |
|
| 263 | - $qty = absint($qty); |
|
| 264 | - if ($qty > 0) { |
|
| 265 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
| 266 | - } |
|
| 267 | - if (self::debug) { |
|
| 268 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 269 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 270 | - } |
|
| 271 | - return $qty; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
| 278 | - * |
|
| 279 | - * @param EE_Ticket $ticket |
|
| 280 | - * @param int $qty |
|
| 281 | - * @return int |
|
| 282 | - * @throws UnexpectedEntityException |
|
| 283 | - * @throws EE_Error |
|
| 284 | - */ |
|
| 285 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
| 286 | - { |
|
| 287 | - if (self::debug) { |
|
| 288 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 289 | - } |
|
| 290 | - if (! $ticket instanceof EE_Ticket) { |
|
| 291 | - return 0; |
|
| 292 | - } |
|
| 293 | - if (self::debug) { |
|
| 294 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 295 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
| 296 | - } |
|
| 297 | - $ticket->refresh_from_db(); |
|
| 298 | - // first let's determine the ticket availability based on sales |
|
| 299 | - $available = $ticket->qty('saleable'); |
|
| 300 | - if (self::debug) { |
|
| 301 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
| 302 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
| 303 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 304 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 305 | - echo self::$nl . ' . . . available: ' . $available; |
|
| 306 | - } |
|
| 307 | - if ($available < 1) { |
|
| 308 | - $this->_ticket_sold_out($ticket); |
|
| 309 | - return 0; |
|
| 310 | - } |
|
| 311 | - if (self::debug) { |
|
| 312 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
| 313 | - } |
|
| 314 | - if ($available < $qty) { |
|
| 315 | - $qty = $available; |
|
| 316 | - if (self::debug) { |
|
| 317 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
| 318 | - } |
|
| 319 | - $this->_ticket_quantity_decremented($ticket); |
|
| 320 | - } |
|
| 321 | - $this->_reserve_ticket($ticket, $qty); |
|
| 322 | - return $qty; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * increments ticket reserved based on quantity passed |
|
| 329 | - * |
|
| 330 | - * @param EE_Ticket $ticket |
|
| 331 | - * @param int $quantity |
|
| 332 | - * @return bool |
|
| 333 | - * @throws EE_Error |
|
| 334 | - */ |
|
| 335 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 336 | - { |
|
| 337 | - if (self::debug) { |
|
| 338 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
| 339 | - } |
|
| 340 | - $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
| 341 | - return $ticket->save(); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @param EE_Ticket $ticket |
|
| 348 | - * @param int $quantity |
|
| 349 | - * @return bool |
|
| 350 | - * @throws EE_Error |
|
| 351 | - */ |
|
| 352 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 353 | - { |
|
| 354 | - if (self::debug) { |
|
| 355 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
| 356 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 357 | - } |
|
| 358 | - $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 359 | - if (self::debug) { |
|
| 360 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 361 | - } |
|
| 362 | - return $ticket->save() ? 1 : 0; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * removes quantities within the ticket selector based on zero ticket availability |
|
| 369 | - * |
|
| 370 | - * @param EE_Ticket $ticket |
|
| 371 | - * @return void |
|
| 372 | - * @throws UnexpectedEntityException |
|
| 373 | - * @throws EE_Error |
|
| 374 | - */ |
|
| 375 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
| 376 | - { |
|
| 377 | - if (self::debug) { |
|
| 378 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 379 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 380 | - } |
|
| 381 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
| 388 | - * |
|
| 389 | - * @param EE_Ticket $ticket |
|
| 390 | - * @return void |
|
| 391 | - * @throws UnexpectedEntityException |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
| 395 | - { |
|
| 396 | - if (self::debug) { |
|
| 397 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 398 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 399 | - } |
|
| 400 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * builds string out of ticket and event name |
|
| 407 | - * |
|
| 408 | - * @param EE_Ticket $ticket |
|
| 409 | - * @return string |
|
| 410 | - * @throws UnexpectedEntityException |
|
| 411 | - * @throws EE_Error |
|
| 412 | - */ |
|
| 413 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
| 414 | - { |
|
| 415 | - $event = $ticket->get_related_event(); |
|
| 416 | - if ($event instanceof EE_Event) { |
|
| 417 | - $ticket_name = sprintf( |
|
| 418 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
| 419 | - $ticket->name(), |
|
| 420 | - $event->name() |
|
| 421 | - ); |
|
| 422 | - } else { |
|
| 423 | - $ticket_name = $ticket->name(); |
|
| 424 | - } |
|
| 425 | - return $ticket_name; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /********************************** EVENT CART **********************************/ |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * releases or reserves ticket(s) based on quantity passed |
|
| 436 | - * |
|
| 437 | - * @param EE_Line_Item $line_item |
|
| 438 | - * @param int $quantity |
|
| 439 | - * @return void |
|
| 440 | - * @throws EE_Error |
|
| 441 | - * @throws InvalidArgumentException |
|
| 442 | - * @throws InvalidDataTypeException |
|
| 443 | - * @throws InvalidInterfaceException |
|
| 444 | - */ |
|
| 445 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
| 446 | - { |
|
| 447 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
| 448 | - if ($ticket instanceof EE_Ticket) { |
|
| 449 | - $ticket->add_extra_meta( |
|
| 450 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 451 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 452 | - ); |
|
| 453 | - if ($quantity > 0) { |
|
| 454 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
| 455 | - } else { |
|
| 456 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * releases reserved ticket(s) based on quantity passed |
|
| 465 | - * |
|
| 466 | - * @param EE_Ticket $ticket |
|
| 467 | - * @param int $quantity |
|
| 468 | - * @return void |
|
| 469 | - * @throws EE_Error |
|
| 470 | - */ |
|
| 471 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
| 472 | - { |
|
| 473 | - $ticket->add_extra_meta( |
|
| 474 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 475 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 476 | - ); |
|
| 477 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /********************************** POST_NOTICES **********************************/ |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @return void |
|
| 488 | - * @throws EE_Error |
|
| 489 | - * @throws InvalidArgumentException |
|
| 490 | - * @throws ReflectionException |
|
| 491 | - * @throws InvalidDataTypeException |
|
| 492 | - * @throws InvalidInterfaceException |
|
| 493 | - */ |
|
| 494 | - public static function post_notices() |
|
| 495 | - { |
|
| 496 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @return void |
|
| 503 | - * @throws EE_Error |
|
| 504 | - * @throws InvalidArgumentException |
|
| 505 | - * @throws ReflectionException |
|
| 506 | - * @throws InvalidDataTypeException |
|
| 507 | - * @throws InvalidInterfaceException |
|
| 508 | - */ |
|
| 509 | - protected function _post_notices() |
|
| 510 | - { |
|
| 511 | - if (self::debug) { |
|
| 512 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 513 | - } |
|
| 514 | - $refresh_msg = ''; |
|
| 515 | - $none_added_msg = ''; |
|
| 516 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 517 | - $refresh_msg = __( |
|
| 518 | - 'Please refresh the page to view updated ticket quantities.', |
|
| 519 | - 'event_espresso' |
|
| 520 | - ); |
|
| 521 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
| 522 | - } |
|
| 523 | - if (! empty($this->sold_out_tickets)) { |
|
| 524 | - EE_Error::add_attention( |
|
| 525 | - sprintf( |
|
| 526 | - apply_filters( |
|
| 527 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
| 528 | - __( |
|
| 529 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 530 | - 'event_espresso' |
|
| 531 | - ) |
|
| 532 | - ), |
|
| 533 | - '<br />', |
|
| 534 | - implode('<br />', $this->sold_out_tickets), |
|
| 535 | - $none_added_msg, |
|
| 536 | - $refresh_msg |
|
| 537 | - ) |
|
| 538 | - ); |
|
| 539 | - // alter code flow in the Ticket Selector for better UX |
|
| 540 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
| 541 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
| 542 | - $this->sold_out_tickets = array(); |
|
| 543 | - // and reset the cart |
|
| 544 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
| 545 | - } |
|
| 546 | - if (! empty($this->decremented_tickets)) { |
|
| 547 | - EE_Error::add_attention( |
|
| 548 | - sprintf( |
|
| 549 | - apply_filters( |
|
| 550 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
| 551 | - __( |
|
| 552 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 553 | - 'event_espresso' |
|
| 554 | - ) |
|
| 555 | - ), |
|
| 556 | - '<br />', |
|
| 557 | - implode('<br />', $this->decremented_tickets), |
|
| 558 | - $none_added_msg, |
|
| 559 | - $refresh_msg |
|
| 560 | - ) |
|
| 561 | - ); |
|
| 562 | - $this->decremented_tickets = array(); |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
| 574 | - * by default, will NOT release tickets for finalized transactions |
|
| 575 | - * |
|
| 576 | - * @param EE_Transaction $transaction |
|
| 577 | - * @return int |
|
| 578 | - * @throws EE_Error |
|
| 579 | - * @throws InvalidSessionDataException |
|
| 580 | - */ |
|
| 581 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
| 582 | - { |
|
| 583 | - if (self::debug) { |
|
| 584 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 585 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
| 586 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
| 587 | - } |
|
| 588 | - // check if 'finalize_registration' step has been completed... |
|
| 589 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 590 | - if (self::debug) { |
|
| 591 | - // DEBUG LOG |
|
| 592 | - EEH_Debug_Tools::log( |
|
| 593 | - __CLASS__, |
|
| 594 | - __FUNCTION__, |
|
| 595 | - __LINE__, |
|
| 596 | - array('finalized' => $finalized), |
|
| 597 | - false, |
|
| 598 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - // how many tickets were released |
|
| 602 | - $count = 0; |
|
| 603 | - if (self::debug) { |
|
| 604 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
| 605 | - } |
|
| 606 | - $release_tickets_with_TXN_status = array( |
|
| 607 | - EEM_Transaction::failed_status_code, |
|
| 608 | - EEM_Transaction::abandoned_status_code, |
|
| 609 | - EEM_Transaction::incomplete_status_code, |
|
| 610 | - ); |
|
| 611 | - $events = array(); |
|
| 612 | - // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
| 613 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 614 | - // cancel any reserved tickets for registrations that were not approved |
|
| 615 | - $registrations = $transaction->registrations(); |
|
| 616 | - if (self::debug) { |
|
| 617 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
| 618 | - $reg = reset($registrations); |
|
| 619 | - $ticket = $reg->ticket(); |
|
| 620 | - if ($ticket instanceof EE_Ticket) { |
|
| 621 | - $ticket->add_extra_meta( |
|
| 622 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 623 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 624 | - ); |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - if (! empty($registrations)) { |
|
| 628 | - foreach ($registrations as $registration) { |
|
| 629 | - if ( |
|
| 630 | - $registration instanceof EE_Registration |
|
| 631 | - && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
| 632 | - ) { |
|
| 633 | - $count++; |
|
| 634 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - if ($events !== array()) { |
|
| 640 | - foreach ($events as $event) { |
|
| 641 | - /** @var EE_Event $event */ |
|
| 642 | - $event->perform_sold_out_status_check(); |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - return $count; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * releases reserved tickets for an EE_Registration |
|
| 652 | - * by default, will NOT release tickets for APPROVED registrations |
|
| 653 | - * |
|
| 654 | - * @param EE_Registration $registration |
|
| 655 | - * @param EE_Transaction $transaction |
|
| 656 | - * @return int |
|
| 657 | - * @throws EE_Error |
|
| 658 | - */ |
|
| 659 | - protected function _release_reserved_ticket_for_registration( |
|
| 660 | - EE_Registration $registration, |
|
| 661 | - EE_Transaction $transaction |
|
| 662 | - ) { |
|
| 663 | - $STS_ID = $transaction->status_ID(); |
|
| 664 | - if (self::debug) { |
|
| 665 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 666 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
| 667 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
| 668 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
| 669 | - } |
|
| 670 | - if ( |
|
| 671 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
| 672 | - $STS_ID === EEM_Transaction::failed_status_code |
|
| 673 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
| 674 | - || ( |
|
| 675 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
| 676 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
| 677 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 678 | - ) |
|
| 679 | - ) { |
|
| 680 | - if (self::debug) { |
|
| 681 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
| 682 | - $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
| 683 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 684 | - var_dump($rsrvd); |
|
| 685 | - } |
|
| 686 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
| 687 | - return 1; |
|
| 688 | - } |
|
| 689 | - return 0; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /********************************** SESSION_CART_RESET **********************************/ |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
| 700 | - * |
|
| 701 | - * @param EE_Session $session |
|
| 702 | - * @return void |
|
| 703 | - * @throws EE_Error |
|
| 704 | - * @throws InvalidArgumentException |
|
| 705 | - * @throws ReflectionException |
|
| 706 | - * @throws InvalidDataTypeException |
|
| 707 | - * @throws InvalidInterfaceException |
|
| 708 | - */ |
|
| 709 | - public static function session_cart_reset(EE_Session $session) |
|
| 710 | - { |
|
| 711 | - if (self::debug) { |
|
| 712 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 713 | - } |
|
| 714 | - // first check of the session has a valid Checkout object |
|
| 715 | - $checkout = $session->checkout(); |
|
| 716 | - if ($checkout instanceof EE_Checkout) { |
|
| 717 | - // and use that to clear ticket reservations because it will update the associated registration meta data |
|
| 718 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 719 | - return; |
|
| 720 | - } |
|
| 721 | - $cart = $session->cart(); |
|
| 722 | - if ($cart instanceof EE_Cart) { |
|
| 723 | - if (self::debug) { |
|
| 724 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
| 725 | - } |
|
| 726 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
| 727 | - } else { |
|
| 728 | - if (self::debug) { |
|
| 729 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
| 730 | - var_export($cart, true); |
|
| 731 | - } |
|
| 732 | - } |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * releases reserved tickets in the EE_Cart |
|
| 739 | - * |
|
| 740 | - * @param EE_Cart $cart |
|
| 741 | - * @return void |
|
| 742 | - * @throws EE_Error |
|
| 743 | - * @throws InvalidArgumentException |
|
| 744 | - * @throws ReflectionException |
|
| 745 | - * @throws InvalidDataTypeException |
|
| 746 | - * @throws InvalidInterfaceException |
|
| 747 | - */ |
|
| 748 | - protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
| 749 | - { |
|
| 750 | - if (self::debug) { |
|
| 751 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 752 | - } |
|
| 753 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
| 754 | - $ticket_line_items = $cart->get_tickets(); |
|
| 755 | - if (empty($ticket_line_items)) { |
|
| 756 | - return; |
|
| 757 | - } |
|
| 758 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 759 | - if (self::debug) { |
|
| 760 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 761 | - } |
|
| 762 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
| 763 | - if (self::debug) { |
|
| 764 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 765 | - } |
|
| 766 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
| 767 | - if ($ticket instanceof EE_Ticket) { |
|
| 768 | - if (self::debug) { |
|
| 769 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
| 770 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 771 | - } |
|
| 772 | - $ticket->add_extra_meta( |
|
| 773 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 774 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 775 | - ); |
|
| 776 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - if (self::debug) { |
|
| 781 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
| 793 | - * |
|
| 794 | - * @param EE_Session $session |
|
| 795 | - * @return void |
|
| 796 | - * @throws EE_Error |
|
| 797 | - * @throws InvalidSessionDataException |
|
| 798 | - */ |
|
| 799 | - public static function session_checkout_reset(EE_Session $session) |
|
| 800 | - { |
|
| 801 | - $checkout = $session->checkout(); |
|
| 802 | - if ($checkout instanceof EE_Checkout) { |
|
| 803 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * releases reserved tickets for the EE_Checkout->transaction |
|
| 811 | - * |
|
| 812 | - * @param EE_Checkout $checkout |
|
| 813 | - * @return void |
|
| 814 | - * @throws EE_Error |
|
| 815 | - * @throws InvalidSessionDataException |
|
| 816 | - */ |
|
| 817 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
| 818 | - { |
|
| 819 | - if (self::debug) { |
|
| 820 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 821 | - } |
|
| 822 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
| 823 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
| 824 | - return; |
|
| 825 | - } |
|
| 826 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - |
|
| 830 | - |
|
| 831 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
| 832 | - |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * @param EE_Session $session |
|
| 837 | - * @return void |
|
| 838 | - */ |
|
| 839 | - public static function session_expired_reset(EE_Session $session) |
|
| 840 | - { |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
| 851 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
| 852 | - * |
|
| 853 | - * @param EE_Transaction $transaction |
|
| 854 | - * @return void |
|
| 855 | - * @throws EE_Error |
|
| 856 | - * @throws InvalidSessionDataException |
|
| 857 | - */ |
|
| 858 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
| 859 | - { |
|
| 860 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
| 861 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
| 862 | - if (self::debug) { |
|
| 863 | - // DEBUG LOG |
|
| 864 | - EEH_Debug_Tools::log( |
|
| 865 | - __CLASS__, |
|
| 866 | - __FUNCTION__, |
|
| 867 | - __LINE__, |
|
| 868 | - array($transaction), |
|
| 869 | - false, |
|
| 870 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 871 | - ); |
|
| 872 | - } |
|
| 873 | - return; |
|
| 874 | - } |
|
| 875 | - // have their been any successful payments made ? |
|
| 876 | - $payments = $transaction->payments(); |
|
| 877 | - foreach ($payments as $payment) { |
|
| 878 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
| 879 | - if (self::debug) { |
|
| 880 | - // DEBUG LOG |
|
| 881 | - EEH_Debug_Tools::log( |
|
| 882 | - __CLASS__, |
|
| 883 | - __FUNCTION__, |
|
| 884 | - __LINE__, |
|
| 885 | - array($payment), |
|
| 886 | - false, |
|
| 887 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 888 | - ); |
|
| 889 | - } |
|
| 890 | - return; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - // since you haven't even attempted to pay for your ticket... |
|
| 894 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
| 905 | - * |
|
| 906 | - * @param EE_Transaction $transaction |
|
| 907 | - * @return void |
|
| 908 | - * @throws EE_Error |
|
| 909 | - * @throws InvalidSessionDataException |
|
| 910 | - */ |
|
| 911 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
| 912 | - { |
|
| 913 | - // since you haven't even attempted to pay for your ticket... |
|
| 914 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - |
|
| 918 | - |
|
| 919 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
| 920 | - |
|
| 921 | - |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * Resets all ticket and datetime reserved counts to zero |
|
| 925 | - * Tickets that are currently associated with a Transaction that is in progress |
|
| 926 | - * |
|
| 927 | - * @throws EE_Error |
|
| 928 | - * @throws DomainException |
|
| 929 | - * @throws InvalidDataTypeException |
|
| 930 | - * @throws InvalidInterfaceException |
|
| 931 | - * @throws InvalidArgumentException |
|
| 932 | - * @throws UnexpectedEntityException |
|
| 933 | - */ |
|
| 934 | - public static function reset_reservation_counts() |
|
| 935 | - { |
|
| 936 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 937 | - $valid_reserved_tickets = array(); |
|
| 938 | - /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
| 939 | - $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
| 940 | - foreach ($transactions_not_in_progress as $transaction) { |
|
| 941 | - // if this TXN has been fully completed, then skip it |
|
| 942 | - if ($transaction->reg_step_completed('finalize_registration')) { |
|
| 943 | - continue; |
|
| 944 | - } |
|
| 945 | - $total_line_item = $transaction->total_line_item(); |
|
| 946 | - // $transaction_in_progress->line |
|
| 947 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
| 948 | - throw new DomainException( |
|
| 949 | - esc_html__( |
|
| 950 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
| 951 | - 'event_espresso' |
|
| 952 | - ) |
|
| 953 | - ); |
|
| 954 | - } |
|
| 955 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 956 | - $total_line_item |
|
| 957 | - ); |
|
| 958 | - } |
|
| 959 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
| 960 | - foreach ($total_line_items as $total_line_item) { |
|
| 961 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 962 | - $total_line_item |
|
| 963 | - ); |
|
| 964 | - } |
|
| 965 | - $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
| 966 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 967 | - $tickets_with_reservations, |
|
| 968 | - $valid_reserved_tickets, |
|
| 969 | - __FUNCTION__ |
|
| 970 | - ); |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - |
|
| 975 | - /** |
|
| 976 | - * @param EE_Line_Item $total_line_item |
|
| 977 | - * @return EE_Line_Item[] |
|
| 978 | - */ |
|
| 979 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
| 980 | - { |
|
| 981 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 982 | - $valid_reserved_tickets = array(); |
|
| 983 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 984 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 985 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
| 986 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - return $valid_reserved_tickets; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - |
|
| 994 | - /** |
|
| 995 | - * @param EE_Ticket[] $tickets_with_reservations |
|
| 996 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
| 997 | - * @return int |
|
| 998 | - * @throws UnexpectedEntityException |
|
| 999 | - * @throws DomainException |
|
| 1000 | - * @throws EE_Error |
|
| 1001 | - */ |
|
| 1002 | - private static function release_reservations_for_tickets( |
|
| 1003 | - array $tickets_with_reservations, |
|
| 1004 | - array $valid_reserved_ticket_line_items = array(), |
|
| 1005 | - $source |
|
| 1006 | - ) { |
|
| 1007 | - if (self::debug) { |
|
| 1008 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 1009 | - } |
|
| 1010 | - $total_tickets_released = 0; |
|
| 1011 | - $sold_out_events = array(); |
|
| 1012 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
| 1013 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1014 | - continue; |
|
| 1015 | - } |
|
| 1016 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
| 1017 | - if (self::debug) { |
|
| 1018 | - echo self::$nl . ' . $ticket_with_reservations->ID(): ' . $ticket_with_reservations->ID(); |
|
| 1019 | - echo self::$nl . ' . $reserved_qty: ' . $reserved_qty; |
|
| 1020 | - } |
|
| 1021 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
| 1022 | - if ( |
|
| 1023 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
| 1024 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
| 1025 | - ) { |
|
| 1026 | - if (self::debug) { |
|
| 1027 | - echo self::$nl . ' . $valid_reserved_ticket_line_item->quantity(): ' . $valid_reserved_ticket_line_item->quantity(); |
|
| 1028 | - } |
|
| 1029 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1032 | - if ($reserved_qty > 0) { |
|
| 1033 | - $ticket_with_reservations->add_extra_meta( |
|
| 1034 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 1035 | - __LINE__ . ') ' . $source . '()' |
|
| 1036 | - ); |
|
| 1037 | - $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 1038 | - $ticket_with_reservations->save(); |
|
| 1039 | - $total_tickets_released += $reserved_qty; |
|
| 1040 | - $event = $ticket_with_reservations->get_related_event(); |
|
| 1041 | - // track sold out events |
|
| 1042 | - if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
| 1043 | - $sold_out_events[] = $event; |
|
| 1044 | - } |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1047 | - if (self::debug) { |
|
| 1048 | - echo self::$nl . ' . $total_tickets_released: ' . $total_tickets_released; |
|
| 1049 | - } |
|
| 1050 | - // double check whether sold out events should remain sold out after releasing tickets |
|
| 1051 | - if($sold_out_events !== array()){ |
|
| 1052 | - foreach ($sold_out_events as $sold_out_event) { |
|
| 1053 | - /** @var EE_Event $sold_out_event */ |
|
| 1054 | - $sold_out_event->perform_sold_out_status_check(); |
|
| 1055 | - } |
|
| 1056 | - } |
|
| 1057 | - return $total_tickets_released; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - |
|
| 1062 | - /********************************** SHUTDOWN **********************************/ |
|
| 1063 | - |
|
| 1064 | - |
|
| 1065 | - |
|
| 1066 | - /** |
|
| 1067 | - * @param int $timestamp |
|
| 1068 | - * @return false|int |
|
| 1069 | - * @throws EE_Error |
|
| 1070 | - * @throws InvalidArgumentException |
|
| 1071 | - * @throws InvalidDataTypeException |
|
| 1072 | - * @throws InvalidInterfaceException |
|
| 1073 | - */ |
|
| 1074 | - public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
| 1075 | - { |
|
| 1076 | - /** @type WPDB $wpdb */ |
|
| 1077 | - global $wpdb; |
|
| 1078 | - if (! absint($timestamp)) { |
|
| 1079 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 1080 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 1081 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 1082 | - ); |
|
| 1083 | - $timestamp = $session_lifespan->expiration(); |
|
| 1084 | - } |
|
| 1085 | - return $wpdb->query( |
|
| 1086 | - $wpdb->prepare( |
|
| 1087 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 27 | + const debug = false; // true false |
|
| 28 | + |
|
| 29 | + private static $nl = ''; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * an array of raw ticket data from EED_Ticket_Selector |
|
| 33 | + * |
|
| 34 | + * @var array $ticket_selections |
|
| 35 | + */ |
|
| 36 | + protected $ticket_selections = array(); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
| 40 | + * according to how they are displayed in the actual Ticket_Selector |
|
| 41 | + * this tracks the current row being processed |
|
| 42 | + * |
|
| 43 | + * @var int $current_row |
|
| 44 | + */ |
|
| 45 | + protected $current_row = 0; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * an array for tracking names of tickets that have sold out |
|
| 49 | + * |
|
| 50 | + * @var array $sold_out_tickets |
|
| 51 | + */ |
|
| 52 | + protected $sold_out_tickets = array(); |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * an array for tracking names of tickets that have had their quantities reduced |
|
| 56 | + * |
|
| 57 | + * @var array $decremented_tickets |
|
| 58 | + */ |
|
| 59 | + protected $decremented_tickets = array(); |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public static function set_hooks() |
|
| 69 | + { |
|
| 70 | + self::$nl = defined('EE_TESTS_DIR')? "\n" : '<br />'; |
|
| 71 | + // release tickets for expired carts |
|
| 72 | + add_action( |
|
| 73 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 74 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
| 75 | + 1 |
|
| 76 | + ); |
|
| 77 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
| 78 | + add_filter( |
|
| 79 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
| 80 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
| 81 | + 20, |
|
| 82 | + 3 |
|
| 83 | + ); |
|
| 84 | + // add notices for sold out tickets |
|
| 85 | + add_action( |
|
| 86 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 87 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
| 88 | + 10 |
|
| 89 | + ); |
|
| 90 | + // handle ticket quantities adjusted in cart |
|
| 91 | + //add_action( |
|
| 92 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
| 93 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
| 94 | + // 10, 2 |
|
| 95 | + //); |
|
| 96 | + // handle tickets deleted from cart |
|
| 97 | + add_action( |
|
| 98 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
| 99 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
| 100 | + 10, |
|
| 101 | + 2 |
|
| 102 | + ); |
|
| 103 | + // handle emptied carts |
|
| 104 | + add_action( |
|
| 105 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
| 106 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 107 | + 10, |
|
| 108 | + 1 |
|
| 109 | + ); |
|
| 110 | + add_action( |
|
| 111 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
| 112 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 113 | + 10, |
|
| 114 | + 1 |
|
| 115 | + ); |
|
| 116 | + // handle cancelled registrations |
|
| 117 | + add_action( |
|
| 118 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
| 119 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
| 120 | + 10, |
|
| 121 | + 1 |
|
| 122 | + ); |
|
| 123 | + // cron tasks |
|
| 124 | + add_action( |
|
| 125 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 126 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 127 | + 10, |
|
| 128 | + 1 |
|
| 129 | + ); |
|
| 130 | + add_action( |
|
| 131 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 132 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 133 | + 10, |
|
| 134 | + 1 |
|
| 135 | + ); |
|
| 136 | + add_action( |
|
| 137 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 138 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
| 139 | + 10, |
|
| 140 | + 1 |
|
| 141 | + ); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 148 | + * |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + public static function set_hooks_admin() |
|
| 152 | + { |
|
| 153 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
| 160 | + */ |
|
| 161 | + public static function instance() |
|
| 162 | + { |
|
| 163 | + return parent::get_instance(__CLASS__); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @param WP_Query $WP_Query |
|
| 170 | + * @return void |
|
| 171 | + */ |
|
| 172 | + public function run($WP_Query) |
|
| 173 | + { |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Retrieves grand totals from the line items that have no TXN ID |
|
| 184 | + * and timestamps less than the current time minus the session lifespan. |
|
| 185 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
| 186 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
| 187 | + * |
|
| 188 | + * @return void |
|
| 189 | + * @throws DomainException |
|
| 190 | + * @throws EE_Error |
|
| 191 | + * @throws InvalidArgumentException |
|
| 192 | + * @throws InvalidDataTypeException |
|
| 193 | + * @throws InvalidInterfaceException |
|
| 194 | + * @throws UnexpectedEntityException |
|
| 195 | + */ |
|
| 196 | + public static function release_tickets_for_expired_carts() |
|
| 197 | + { |
|
| 198 | + if (self::debug) { |
|
| 199 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 200 | + } |
|
| 201 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
| 202 | + $expired_ticket_IDs = array(); |
|
| 203 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 204 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 205 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 206 | + ); |
|
| 207 | + $timestamp = $session_lifespan->expiration(); |
|
| 208 | + $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
| 209 | + if (self::debug) { |
|
| 210 | + echo self::$nl . ' . time(): ' . time(); |
|
| 211 | + echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
| 212 | + echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
| 213 | + echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
| 214 | + echo self::$nl . ' . timestamp: ' . $timestamp; |
|
| 215 | + echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
| 216 | + } |
|
| 217 | + if (! empty($expired_ticket_line_items)) { |
|
| 218 | + foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
| 219 | + if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
| 220 | + continue; |
|
| 221 | + } |
|
| 222 | + $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
| 223 | + if (self::debug) { |
|
| 224 | + echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
| 225 | + echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' . date('Y-m-d h:i a', |
|
| 226 | + $expired_ticket_line_item->timestamp(true)); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + if (! empty($expired_ticket_IDs)) { |
|
| 230 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 231 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
| 232 | + array(), |
|
| 233 | + __FUNCTION__ |
|
| 234 | + ); |
|
| 235 | + // now let's get rid of expired line items so that they can't interfere with tracking |
|
| 236 | + EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + do_action( |
|
| 240 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 241 | + $expired_ticket_IDs, |
|
| 242 | + $expired_ticket_line_items |
|
| 243 | + ); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
| 254 | + * |
|
| 255 | + * @param int $qty |
|
| 256 | + * @param EE_Ticket $ticket |
|
| 257 | + * @return bool |
|
| 258 | + * @throws UnexpectedEntityException |
|
| 259 | + * @throws EE_Error |
|
| 260 | + */ |
|
| 261 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
| 262 | + { |
|
| 263 | + $qty = absint($qty); |
|
| 264 | + if ($qty > 0) { |
|
| 265 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
| 266 | + } |
|
| 267 | + if (self::debug) { |
|
| 268 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 269 | + echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 270 | + } |
|
| 271 | + return $qty; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
| 278 | + * |
|
| 279 | + * @param EE_Ticket $ticket |
|
| 280 | + * @param int $qty |
|
| 281 | + * @return int |
|
| 282 | + * @throws UnexpectedEntityException |
|
| 283 | + * @throws EE_Error |
|
| 284 | + */ |
|
| 285 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
| 286 | + { |
|
| 287 | + if (self::debug) { |
|
| 288 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 289 | + } |
|
| 290 | + if (! $ticket instanceof EE_Ticket) { |
|
| 291 | + return 0; |
|
| 292 | + } |
|
| 293 | + if (self::debug) { |
|
| 294 | + echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 295 | + echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
| 296 | + } |
|
| 297 | + $ticket->refresh_from_db(); |
|
| 298 | + // first let's determine the ticket availability based on sales |
|
| 299 | + $available = $ticket->qty('saleable'); |
|
| 300 | + if (self::debug) { |
|
| 301 | + echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
| 302 | + echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
| 303 | + echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 304 | + echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 305 | + echo self::$nl . ' . . . available: ' . $available; |
|
| 306 | + } |
|
| 307 | + if ($available < 1) { |
|
| 308 | + $this->_ticket_sold_out($ticket); |
|
| 309 | + return 0; |
|
| 310 | + } |
|
| 311 | + if (self::debug) { |
|
| 312 | + echo self::$nl . ' . . . qty: ' . $qty; |
|
| 313 | + } |
|
| 314 | + if ($available < $qty) { |
|
| 315 | + $qty = $available; |
|
| 316 | + if (self::debug) { |
|
| 317 | + echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
| 318 | + } |
|
| 319 | + $this->_ticket_quantity_decremented($ticket); |
|
| 320 | + } |
|
| 321 | + $this->_reserve_ticket($ticket, $qty); |
|
| 322 | + return $qty; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * increments ticket reserved based on quantity passed |
|
| 329 | + * |
|
| 330 | + * @param EE_Ticket $ticket |
|
| 331 | + * @param int $quantity |
|
| 332 | + * @return bool |
|
| 333 | + * @throws EE_Error |
|
| 334 | + */ |
|
| 335 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 336 | + { |
|
| 337 | + if (self::debug) { |
|
| 338 | + echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
| 339 | + } |
|
| 340 | + $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
| 341 | + return $ticket->save(); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @param EE_Ticket $ticket |
|
| 348 | + * @param int $quantity |
|
| 349 | + * @return bool |
|
| 350 | + * @throws EE_Error |
|
| 351 | + */ |
|
| 352 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 353 | + { |
|
| 354 | + if (self::debug) { |
|
| 355 | + echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
| 356 | + echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 357 | + } |
|
| 358 | + $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 359 | + if (self::debug) { |
|
| 360 | + echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 361 | + } |
|
| 362 | + return $ticket->save() ? 1 : 0; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * removes quantities within the ticket selector based on zero ticket availability |
|
| 369 | + * |
|
| 370 | + * @param EE_Ticket $ticket |
|
| 371 | + * @return void |
|
| 372 | + * @throws UnexpectedEntityException |
|
| 373 | + * @throws EE_Error |
|
| 374 | + */ |
|
| 375 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
| 376 | + { |
|
| 377 | + if (self::debug) { |
|
| 378 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 379 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 380 | + } |
|
| 381 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
| 388 | + * |
|
| 389 | + * @param EE_Ticket $ticket |
|
| 390 | + * @return void |
|
| 391 | + * @throws UnexpectedEntityException |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
| 395 | + { |
|
| 396 | + if (self::debug) { |
|
| 397 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 398 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 399 | + } |
|
| 400 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * builds string out of ticket and event name |
|
| 407 | + * |
|
| 408 | + * @param EE_Ticket $ticket |
|
| 409 | + * @return string |
|
| 410 | + * @throws UnexpectedEntityException |
|
| 411 | + * @throws EE_Error |
|
| 412 | + */ |
|
| 413 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
| 414 | + { |
|
| 415 | + $event = $ticket->get_related_event(); |
|
| 416 | + if ($event instanceof EE_Event) { |
|
| 417 | + $ticket_name = sprintf( |
|
| 418 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
| 419 | + $ticket->name(), |
|
| 420 | + $event->name() |
|
| 421 | + ); |
|
| 422 | + } else { |
|
| 423 | + $ticket_name = $ticket->name(); |
|
| 424 | + } |
|
| 425 | + return $ticket_name; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /********************************** EVENT CART **********************************/ |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * releases or reserves ticket(s) based on quantity passed |
|
| 436 | + * |
|
| 437 | + * @param EE_Line_Item $line_item |
|
| 438 | + * @param int $quantity |
|
| 439 | + * @return void |
|
| 440 | + * @throws EE_Error |
|
| 441 | + * @throws InvalidArgumentException |
|
| 442 | + * @throws InvalidDataTypeException |
|
| 443 | + * @throws InvalidInterfaceException |
|
| 444 | + */ |
|
| 445 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
| 446 | + { |
|
| 447 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
| 448 | + if ($ticket instanceof EE_Ticket) { |
|
| 449 | + $ticket->add_extra_meta( |
|
| 450 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 451 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
| 452 | + ); |
|
| 453 | + if ($quantity > 0) { |
|
| 454 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
| 455 | + } else { |
|
| 456 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * releases reserved ticket(s) based on quantity passed |
|
| 465 | + * |
|
| 466 | + * @param EE_Ticket $ticket |
|
| 467 | + * @param int $quantity |
|
| 468 | + * @return void |
|
| 469 | + * @throws EE_Error |
|
| 470 | + */ |
|
| 471 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
| 472 | + { |
|
| 473 | + $ticket->add_extra_meta( |
|
| 474 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 475 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
| 476 | + ); |
|
| 477 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /********************************** POST_NOTICES **********************************/ |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * @return void |
|
| 488 | + * @throws EE_Error |
|
| 489 | + * @throws InvalidArgumentException |
|
| 490 | + * @throws ReflectionException |
|
| 491 | + * @throws InvalidDataTypeException |
|
| 492 | + * @throws InvalidInterfaceException |
|
| 493 | + */ |
|
| 494 | + public static function post_notices() |
|
| 495 | + { |
|
| 496 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @return void |
|
| 503 | + * @throws EE_Error |
|
| 504 | + * @throws InvalidArgumentException |
|
| 505 | + * @throws ReflectionException |
|
| 506 | + * @throws InvalidDataTypeException |
|
| 507 | + * @throws InvalidInterfaceException |
|
| 508 | + */ |
|
| 509 | + protected function _post_notices() |
|
| 510 | + { |
|
| 511 | + if (self::debug) { |
|
| 512 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 513 | + } |
|
| 514 | + $refresh_msg = ''; |
|
| 515 | + $none_added_msg = ''; |
|
| 516 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 517 | + $refresh_msg = __( |
|
| 518 | + 'Please refresh the page to view updated ticket quantities.', |
|
| 519 | + 'event_espresso' |
|
| 520 | + ); |
|
| 521 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
| 522 | + } |
|
| 523 | + if (! empty($this->sold_out_tickets)) { |
|
| 524 | + EE_Error::add_attention( |
|
| 525 | + sprintf( |
|
| 526 | + apply_filters( |
|
| 527 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
| 528 | + __( |
|
| 529 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 530 | + 'event_espresso' |
|
| 531 | + ) |
|
| 532 | + ), |
|
| 533 | + '<br />', |
|
| 534 | + implode('<br />', $this->sold_out_tickets), |
|
| 535 | + $none_added_msg, |
|
| 536 | + $refresh_msg |
|
| 537 | + ) |
|
| 538 | + ); |
|
| 539 | + // alter code flow in the Ticket Selector for better UX |
|
| 540 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
| 541 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
| 542 | + $this->sold_out_tickets = array(); |
|
| 543 | + // and reset the cart |
|
| 544 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
| 545 | + } |
|
| 546 | + if (! empty($this->decremented_tickets)) { |
|
| 547 | + EE_Error::add_attention( |
|
| 548 | + sprintf( |
|
| 549 | + apply_filters( |
|
| 550 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
| 551 | + __( |
|
| 552 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 553 | + 'event_espresso' |
|
| 554 | + ) |
|
| 555 | + ), |
|
| 556 | + '<br />', |
|
| 557 | + implode('<br />', $this->decremented_tickets), |
|
| 558 | + $none_added_msg, |
|
| 559 | + $refresh_msg |
|
| 560 | + ) |
|
| 561 | + ); |
|
| 562 | + $this->decremented_tickets = array(); |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
| 574 | + * by default, will NOT release tickets for finalized transactions |
|
| 575 | + * |
|
| 576 | + * @param EE_Transaction $transaction |
|
| 577 | + * @return int |
|
| 578 | + * @throws EE_Error |
|
| 579 | + * @throws InvalidSessionDataException |
|
| 580 | + */ |
|
| 581 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
| 582 | + { |
|
| 583 | + if (self::debug) { |
|
| 584 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 585 | + echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
| 586 | + echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
| 587 | + } |
|
| 588 | + // check if 'finalize_registration' step has been completed... |
|
| 589 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 590 | + if (self::debug) { |
|
| 591 | + // DEBUG LOG |
|
| 592 | + EEH_Debug_Tools::log( |
|
| 593 | + __CLASS__, |
|
| 594 | + __FUNCTION__, |
|
| 595 | + __LINE__, |
|
| 596 | + array('finalized' => $finalized), |
|
| 597 | + false, |
|
| 598 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + // how many tickets were released |
|
| 602 | + $count = 0; |
|
| 603 | + if (self::debug) { |
|
| 604 | + echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
| 605 | + } |
|
| 606 | + $release_tickets_with_TXN_status = array( |
|
| 607 | + EEM_Transaction::failed_status_code, |
|
| 608 | + EEM_Transaction::abandoned_status_code, |
|
| 609 | + EEM_Transaction::incomplete_status_code, |
|
| 610 | + ); |
|
| 611 | + $events = array(); |
|
| 612 | + // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
| 613 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 614 | + // cancel any reserved tickets for registrations that were not approved |
|
| 615 | + $registrations = $transaction->registrations(); |
|
| 616 | + if (self::debug) { |
|
| 617 | + echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
| 618 | + $reg = reset($registrations); |
|
| 619 | + $ticket = $reg->ticket(); |
|
| 620 | + if ($ticket instanceof EE_Ticket) { |
|
| 621 | + $ticket->add_extra_meta( |
|
| 622 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 623 | + __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 624 | + ); |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + if (! empty($registrations)) { |
|
| 628 | + foreach ($registrations as $registration) { |
|
| 629 | + if ( |
|
| 630 | + $registration instanceof EE_Registration |
|
| 631 | + && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
| 632 | + ) { |
|
| 633 | + $count++; |
|
| 634 | + $events[ $registration->event_ID() ] = $registration->event(); |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + if ($events !== array()) { |
|
| 640 | + foreach ($events as $event) { |
|
| 641 | + /** @var EE_Event $event */ |
|
| 642 | + $event->perform_sold_out_status_check(); |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + return $count; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * releases reserved tickets for an EE_Registration |
|
| 652 | + * by default, will NOT release tickets for APPROVED registrations |
|
| 653 | + * |
|
| 654 | + * @param EE_Registration $registration |
|
| 655 | + * @param EE_Transaction $transaction |
|
| 656 | + * @return int |
|
| 657 | + * @throws EE_Error |
|
| 658 | + */ |
|
| 659 | + protected function _release_reserved_ticket_for_registration( |
|
| 660 | + EE_Registration $registration, |
|
| 661 | + EE_Transaction $transaction |
|
| 662 | + ) { |
|
| 663 | + $STS_ID = $transaction->status_ID(); |
|
| 664 | + if (self::debug) { |
|
| 665 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 666 | + echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
| 667 | + echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
| 668 | + echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
| 669 | + } |
|
| 670 | + if ( |
|
| 671 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
| 672 | + $STS_ID === EEM_Transaction::failed_status_code |
|
| 673 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
| 674 | + || ( |
|
| 675 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
| 676 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
| 677 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 678 | + ) |
|
| 679 | + ) { |
|
| 680 | + if (self::debug) { |
|
| 681 | + echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
| 682 | + $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
| 683 | + echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 684 | + var_dump($rsrvd); |
|
| 685 | + } |
|
| 686 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
| 687 | + return 1; |
|
| 688 | + } |
|
| 689 | + return 0; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /********************************** SESSION_CART_RESET **********************************/ |
|
| 695 | + |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
| 700 | + * |
|
| 701 | + * @param EE_Session $session |
|
| 702 | + * @return void |
|
| 703 | + * @throws EE_Error |
|
| 704 | + * @throws InvalidArgumentException |
|
| 705 | + * @throws ReflectionException |
|
| 706 | + * @throws InvalidDataTypeException |
|
| 707 | + * @throws InvalidInterfaceException |
|
| 708 | + */ |
|
| 709 | + public static function session_cart_reset(EE_Session $session) |
|
| 710 | + { |
|
| 711 | + if (self::debug) { |
|
| 712 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 713 | + } |
|
| 714 | + // first check of the session has a valid Checkout object |
|
| 715 | + $checkout = $session->checkout(); |
|
| 716 | + if ($checkout instanceof EE_Checkout) { |
|
| 717 | + // and use that to clear ticket reservations because it will update the associated registration meta data |
|
| 718 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 719 | + return; |
|
| 720 | + } |
|
| 721 | + $cart = $session->cart(); |
|
| 722 | + if ($cart instanceof EE_Cart) { |
|
| 723 | + if (self::debug) { |
|
| 724 | + echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
| 725 | + } |
|
| 726 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
| 727 | + } else { |
|
| 728 | + if (self::debug) { |
|
| 729 | + echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
| 730 | + var_export($cart, true); |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * releases reserved tickets in the EE_Cart |
|
| 739 | + * |
|
| 740 | + * @param EE_Cart $cart |
|
| 741 | + * @return void |
|
| 742 | + * @throws EE_Error |
|
| 743 | + * @throws InvalidArgumentException |
|
| 744 | + * @throws ReflectionException |
|
| 745 | + * @throws InvalidDataTypeException |
|
| 746 | + * @throws InvalidInterfaceException |
|
| 747 | + */ |
|
| 748 | + protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
| 749 | + { |
|
| 750 | + if (self::debug) { |
|
| 751 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 752 | + } |
|
| 753 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
| 754 | + $ticket_line_items = $cart->get_tickets(); |
|
| 755 | + if (empty($ticket_line_items)) { |
|
| 756 | + return; |
|
| 757 | + } |
|
| 758 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 759 | + if (self::debug) { |
|
| 760 | + echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 761 | + } |
|
| 762 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
| 763 | + if (self::debug) { |
|
| 764 | + echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 765 | + } |
|
| 766 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
| 767 | + if ($ticket instanceof EE_Ticket) { |
|
| 768 | + if (self::debug) { |
|
| 769 | + echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
| 770 | + echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 771 | + } |
|
| 772 | + $ticket->add_extra_meta( |
|
| 773 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 774 | + __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 775 | + ); |
|
| 776 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + if (self::debug) { |
|
| 781 | + echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
| 793 | + * |
|
| 794 | + * @param EE_Session $session |
|
| 795 | + * @return void |
|
| 796 | + * @throws EE_Error |
|
| 797 | + * @throws InvalidSessionDataException |
|
| 798 | + */ |
|
| 799 | + public static function session_checkout_reset(EE_Session $session) |
|
| 800 | + { |
|
| 801 | + $checkout = $session->checkout(); |
|
| 802 | + if ($checkout instanceof EE_Checkout) { |
|
| 803 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * releases reserved tickets for the EE_Checkout->transaction |
|
| 811 | + * |
|
| 812 | + * @param EE_Checkout $checkout |
|
| 813 | + * @return void |
|
| 814 | + * @throws EE_Error |
|
| 815 | + * @throws InvalidSessionDataException |
|
| 816 | + */ |
|
| 817 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
| 818 | + { |
|
| 819 | + if (self::debug) { |
|
| 820 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 821 | + } |
|
| 822 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
| 823 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
| 824 | + return; |
|
| 825 | + } |
|
| 826 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + |
|
| 830 | + |
|
| 831 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
| 832 | + |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * @param EE_Session $session |
|
| 837 | + * @return void |
|
| 838 | + */ |
|
| 839 | + public static function session_expired_reset(EE_Session $session) |
|
| 840 | + { |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
| 851 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
| 852 | + * |
|
| 853 | + * @param EE_Transaction $transaction |
|
| 854 | + * @return void |
|
| 855 | + * @throws EE_Error |
|
| 856 | + * @throws InvalidSessionDataException |
|
| 857 | + */ |
|
| 858 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
| 859 | + { |
|
| 860 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
| 861 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
| 862 | + if (self::debug) { |
|
| 863 | + // DEBUG LOG |
|
| 864 | + EEH_Debug_Tools::log( |
|
| 865 | + __CLASS__, |
|
| 866 | + __FUNCTION__, |
|
| 867 | + __LINE__, |
|
| 868 | + array($transaction), |
|
| 869 | + false, |
|
| 870 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 871 | + ); |
|
| 872 | + } |
|
| 873 | + return; |
|
| 874 | + } |
|
| 875 | + // have their been any successful payments made ? |
|
| 876 | + $payments = $transaction->payments(); |
|
| 877 | + foreach ($payments as $payment) { |
|
| 878 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
| 879 | + if (self::debug) { |
|
| 880 | + // DEBUG LOG |
|
| 881 | + EEH_Debug_Tools::log( |
|
| 882 | + __CLASS__, |
|
| 883 | + __FUNCTION__, |
|
| 884 | + __LINE__, |
|
| 885 | + array($payment), |
|
| 886 | + false, |
|
| 887 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 888 | + ); |
|
| 889 | + } |
|
| 890 | + return; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + // since you haven't even attempted to pay for your ticket... |
|
| 894 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
| 905 | + * |
|
| 906 | + * @param EE_Transaction $transaction |
|
| 907 | + * @return void |
|
| 908 | + * @throws EE_Error |
|
| 909 | + * @throws InvalidSessionDataException |
|
| 910 | + */ |
|
| 911 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
| 912 | + { |
|
| 913 | + // since you haven't even attempted to pay for your ticket... |
|
| 914 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + |
|
| 918 | + |
|
| 919 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
| 920 | + |
|
| 921 | + |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * Resets all ticket and datetime reserved counts to zero |
|
| 925 | + * Tickets that are currently associated with a Transaction that is in progress |
|
| 926 | + * |
|
| 927 | + * @throws EE_Error |
|
| 928 | + * @throws DomainException |
|
| 929 | + * @throws InvalidDataTypeException |
|
| 930 | + * @throws InvalidInterfaceException |
|
| 931 | + * @throws InvalidArgumentException |
|
| 932 | + * @throws UnexpectedEntityException |
|
| 933 | + */ |
|
| 934 | + public static function reset_reservation_counts() |
|
| 935 | + { |
|
| 936 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 937 | + $valid_reserved_tickets = array(); |
|
| 938 | + /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
| 939 | + $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
| 940 | + foreach ($transactions_not_in_progress as $transaction) { |
|
| 941 | + // if this TXN has been fully completed, then skip it |
|
| 942 | + if ($transaction->reg_step_completed('finalize_registration')) { |
|
| 943 | + continue; |
|
| 944 | + } |
|
| 945 | + $total_line_item = $transaction->total_line_item(); |
|
| 946 | + // $transaction_in_progress->line |
|
| 947 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
| 948 | + throw new DomainException( |
|
| 949 | + esc_html__( |
|
| 950 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
| 951 | + 'event_espresso' |
|
| 952 | + ) |
|
| 953 | + ); |
|
| 954 | + } |
|
| 955 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 956 | + $total_line_item |
|
| 957 | + ); |
|
| 958 | + } |
|
| 959 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
| 960 | + foreach ($total_line_items as $total_line_item) { |
|
| 961 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 962 | + $total_line_item |
|
| 963 | + ); |
|
| 964 | + } |
|
| 965 | + $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
| 966 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 967 | + $tickets_with_reservations, |
|
| 968 | + $valid_reserved_tickets, |
|
| 969 | + __FUNCTION__ |
|
| 970 | + ); |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + |
|
| 975 | + /** |
|
| 976 | + * @param EE_Line_Item $total_line_item |
|
| 977 | + * @return EE_Line_Item[] |
|
| 978 | + */ |
|
| 979 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
| 980 | + { |
|
| 981 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 982 | + $valid_reserved_tickets = array(); |
|
| 983 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 984 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 985 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
| 986 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + return $valid_reserved_tickets; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + |
|
| 994 | + /** |
|
| 995 | + * @param EE_Ticket[] $tickets_with_reservations |
|
| 996 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
| 997 | + * @return int |
|
| 998 | + * @throws UnexpectedEntityException |
|
| 999 | + * @throws DomainException |
|
| 1000 | + * @throws EE_Error |
|
| 1001 | + */ |
|
| 1002 | + private static function release_reservations_for_tickets( |
|
| 1003 | + array $tickets_with_reservations, |
|
| 1004 | + array $valid_reserved_ticket_line_items = array(), |
|
| 1005 | + $source |
|
| 1006 | + ) { |
|
| 1007 | + if (self::debug) { |
|
| 1008 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 1009 | + } |
|
| 1010 | + $total_tickets_released = 0; |
|
| 1011 | + $sold_out_events = array(); |
|
| 1012 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
| 1013 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1014 | + continue; |
|
| 1015 | + } |
|
| 1016 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
| 1017 | + if (self::debug) { |
|
| 1018 | + echo self::$nl . ' . $ticket_with_reservations->ID(): ' . $ticket_with_reservations->ID(); |
|
| 1019 | + echo self::$nl . ' . $reserved_qty: ' . $reserved_qty; |
|
| 1020 | + } |
|
| 1021 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
| 1022 | + if ( |
|
| 1023 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
| 1024 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
| 1025 | + ) { |
|
| 1026 | + if (self::debug) { |
|
| 1027 | + echo self::$nl . ' . $valid_reserved_ticket_line_item->quantity(): ' . $valid_reserved_ticket_line_item->quantity(); |
|
| 1028 | + } |
|
| 1029 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | + if ($reserved_qty > 0) { |
|
| 1033 | + $ticket_with_reservations->add_extra_meta( |
|
| 1034 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 1035 | + __LINE__ . ') ' . $source . '()' |
|
| 1036 | + ); |
|
| 1037 | + $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 1038 | + $ticket_with_reservations->save(); |
|
| 1039 | + $total_tickets_released += $reserved_qty; |
|
| 1040 | + $event = $ticket_with_reservations->get_related_event(); |
|
| 1041 | + // track sold out events |
|
| 1042 | + if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
| 1043 | + $sold_out_events[] = $event; |
|
| 1044 | + } |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | + if (self::debug) { |
|
| 1048 | + echo self::$nl . ' . $total_tickets_released: ' . $total_tickets_released; |
|
| 1049 | + } |
|
| 1050 | + // double check whether sold out events should remain sold out after releasing tickets |
|
| 1051 | + if($sold_out_events !== array()){ |
|
| 1052 | + foreach ($sold_out_events as $sold_out_event) { |
|
| 1053 | + /** @var EE_Event $sold_out_event */ |
|
| 1054 | + $sold_out_event->perform_sold_out_status_check(); |
|
| 1055 | + } |
|
| 1056 | + } |
|
| 1057 | + return $total_tickets_released; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + |
|
| 1062 | + /********************************** SHUTDOWN **********************************/ |
|
| 1063 | + |
|
| 1064 | + |
|
| 1065 | + |
|
| 1066 | + /** |
|
| 1067 | + * @param int $timestamp |
|
| 1068 | + * @return false|int |
|
| 1069 | + * @throws EE_Error |
|
| 1070 | + * @throws InvalidArgumentException |
|
| 1071 | + * @throws InvalidDataTypeException |
|
| 1072 | + * @throws InvalidInterfaceException |
|
| 1073 | + */ |
|
| 1074 | + public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
| 1075 | + { |
|
| 1076 | + /** @type WPDB $wpdb */ |
|
| 1077 | + global $wpdb; |
|
| 1078 | + if (! absint($timestamp)) { |
|
| 1079 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 1080 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 1081 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 1082 | + ); |
|
| 1083 | + $timestamp = $session_lifespan->expiration(); |
|
| 1084 | + } |
|
| 1085 | + return $wpdb->query( |
|
| 1086 | + $wpdb->prepare( |
|
| 1087 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 1088 | 1088 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
| 1089 | - // use GMT time because that's what LIN_timestamps are in |
|
| 1090 | - date('Y-m-d H:i:s', $timestamp) |
|
| 1091 | - ) |
|
| 1092 | - ); |
|
| 1093 | - } |
|
| 1089 | + // use GMT time because that's what LIN_timestamps are in |
|
| 1090 | + date('Y-m-d H:i:s', $timestamp) |
|
| 1091 | + ) |
|
| 1092 | + ); |
|
| 1093 | + } |
|
| 1094 | 1094 | |
| 1095 | 1095 | } |
| 1096 | 1096 | // End of file EED_Ticket_Sales_Monitor.module.php |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | class EED_Ticket_Sales_Monitor extends EED_Module |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - const debug = false; // true false |
|
| 27 | + const debug = false; // true false |
|
| 28 | 28 | |
| 29 | 29 | private static $nl = ''; |
| 30 | 30 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public static function set_hooks() |
| 69 | 69 | { |
| 70 | - self::$nl = defined('EE_TESTS_DIR')? "\n" : '<br />'; |
|
| 70 | + self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
| 71 | 71 | // release tickets for expired carts |
| 72 | 72 | add_action( |
| 73 | 73 | 'EED_Ticket_Selector__process_ticket_selections__before', |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | public static function release_tickets_for_expired_carts() |
| 197 | 197 | { |
| 198 | 198 | if (self::debug) { |
| 199 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 199 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
| 200 | 200 | } |
| 201 | 201 | do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
| 202 | 202 | $expired_ticket_IDs = array(); |
@@ -207,26 +207,26 @@ discard block |
||
| 207 | 207 | $timestamp = $session_lifespan->expiration(); |
| 208 | 208 | $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
| 209 | 209 | if (self::debug) { |
| 210 | - echo self::$nl . ' . time(): ' . time(); |
|
| 211 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
| 212 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
| 213 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
| 214 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
| 215 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
| 210 | + echo self::$nl.' . time(): '.time(); |
|
| 211 | + echo self::$nl.' . time() as date: '.date('Y-m-d H:i a'); |
|
| 212 | + echo self::$nl.' . session expiration: '.$session_lifespan->expiration(); |
|
| 213 | + echo self::$nl.' . session expiration as date: '.date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
| 214 | + echo self::$nl.' . timestamp: '.$timestamp; |
|
| 215 | + echo self::$nl.' . $expired_ticket_line_items: '.count($expired_ticket_line_items); |
|
| 216 | 216 | } |
| 217 | - if (! empty($expired_ticket_line_items)) { |
|
| 217 | + if ( ! empty($expired_ticket_line_items)) { |
|
| 218 | 218 | foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
| 219 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
| 219 | + if ( ! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
| 220 | 220 | continue; |
| 221 | 221 | } |
| 222 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
| 222 | + $expired_ticket_IDs[$expired_ticket_line_item->OBJ_ID()] = $expired_ticket_line_item->OBJ_ID(); |
|
| 223 | 223 | if (self::debug) { |
| 224 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
| 225 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' . date('Y-m-d h:i a', |
|
| 224 | + echo self::$nl.' . $expired_ticket_line_item->OBJ_ID(): '.$expired_ticket_line_item->OBJ_ID(); |
|
| 225 | + echo self::$nl.' . $expired_ticket_line_item->timestamp(): '.date('Y-m-d h:i a', |
|
| 226 | 226 | $expired_ticket_line_item->timestamp(true)); |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | - if (! empty($expired_ticket_IDs)) { |
|
| 229 | + if ( ! empty($expired_ticket_IDs)) { |
|
| 230 | 230 | EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
| 231 | 231 | \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
| 232 | 232 | array(), |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
| 266 | 266 | } |
| 267 | 267 | if (self::debug) { |
| 268 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 269 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 268 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
| 269 | + echo self::$nl.self::$nl.'<b> RETURNED QTY: '.$qty.'</b>'; |
|
| 270 | 270 | } |
| 271 | 271 | return $qty; |
| 272 | 272 | } |
@@ -285,36 +285,36 @@ discard block |
||
| 285 | 285 | protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
| 286 | 286 | { |
| 287 | 287 | if (self::debug) { |
| 288 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 288 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 289 | 289 | } |
| 290 | - if (! $ticket instanceof EE_Ticket) { |
|
| 290 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 291 | 291 | return 0; |
| 292 | 292 | } |
| 293 | 293 | if (self::debug) { |
| 294 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 295 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
| 294 | + echo self::$nl.'<b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
| 295 | + echo self::$nl.' . original ticket->reserved: '.$ticket->reserved(); |
|
| 296 | 296 | } |
| 297 | 297 | $ticket->refresh_from_db(); |
| 298 | 298 | // first let's determine the ticket availability based on sales |
| 299 | 299 | $available = $ticket->qty('saleable'); |
| 300 | 300 | if (self::debug) { |
| 301 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
| 302 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
| 303 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 304 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 305 | - echo self::$nl . ' . . . available: ' . $available; |
|
| 301 | + echo self::$nl.' . . . ticket->qty: '.$ticket->qty(); |
|
| 302 | + echo self::$nl.' . . . ticket->sold: '.$ticket->sold(); |
|
| 303 | + echo self::$nl.' . . . ticket->reserved: '.$ticket->reserved(); |
|
| 304 | + echo self::$nl.' . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
| 305 | + echo self::$nl.' . . . available: '.$available; |
|
| 306 | 306 | } |
| 307 | 307 | if ($available < 1) { |
| 308 | 308 | $this->_ticket_sold_out($ticket); |
| 309 | 309 | return 0; |
| 310 | 310 | } |
| 311 | 311 | if (self::debug) { |
| 312 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
| 312 | + echo self::$nl.' . . . qty: '.$qty; |
|
| 313 | 313 | } |
| 314 | 314 | if ($available < $qty) { |
| 315 | 315 | $qty = $available; |
| 316 | 316 | if (self::debug) { |
| 317 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
| 317 | + echo self::$nl.' . . . QTY ADJUSTED: '.$qty; |
|
| 318 | 318 | } |
| 319 | 319 | $this->_ticket_quantity_decremented($ticket); |
| 320 | 320 | } |
@@ -335,9 +335,9 @@ discard block |
||
| 335 | 335 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
| 336 | 336 | { |
| 337 | 337 | if (self::debug) { |
| 338 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
| 338 | + echo self::$nl.self::$nl.' . . . INCREASE RESERVED: '.$quantity; |
|
| 339 | 339 | } |
| 340 | - $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
| 340 | + $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'.__LINE__); |
|
| 341 | 341 | return $ticket->save(); |
| 342 | 342 | } |
| 343 | 343 | |
@@ -352,12 +352,12 @@ discard block |
||
| 352 | 352 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
| 353 | 353 | { |
| 354 | 354 | if (self::debug) { |
| 355 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
| 356 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 355 | + echo self::$nl.' . . . ticket->ID: '.$ticket->ID(); |
|
| 356 | + echo self::$nl.' . . . ticket->reserved: '.$ticket->reserved(); |
|
| 357 | 357 | } |
| 358 | - $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 358 | + $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'.__LINE__); |
|
| 359 | 359 | if (self::debug) { |
| 360 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 360 | + echo self::$nl.' . . . ticket->reserved: '.$ticket->reserved(); |
|
| 361 | 361 | } |
| 362 | 362 | return $ticket->save() ? 1 : 0; |
| 363 | 363 | } |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | protected function _ticket_sold_out(EE_Ticket $ticket) |
| 376 | 376 | { |
| 377 | 377 | if (self::debug) { |
| 378 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 379 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 378 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 379 | + echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
| 380 | 380 | } |
| 381 | 381 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
| 382 | 382 | } |
@@ -394,8 +394,8 @@ discard block |
||
| 394 | 394 | protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
| 395 | 395 | { |
| 396 | 396 | if (self::debug) { |
| 397 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 398 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 397 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 398 | + echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
| 399 | 399 | } |
| 400 | 400 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
| 401 | 401 | } |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | if ($ticket instanceof EE_Ticket) { |
| 449 | 449 | $ticket->add_extra_meta( |
| 450 | 450 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 451 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 451 | + __LINE__.') '.__METHOD__.'()' |
|
| 452 | 452 | ); |
| 453 | 453 | if ($quantity > 0) { |
| 454 | 454 | EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | { |
| 473 | 473 | $ticket->add_extra_meta( |
| 474 | 474 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 475 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 475 | + __LINE__.') '.__METHOD__.'()' |
|
| 476 | 476 | ); |
| 477 | 477 | EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
| 478 | 478 | } |
@@ -509,18 +509,18 @@ discard block |
||
| 509 | 509 | protected function _post_notices() |
| 510 | 510 | { |
| 511 | 511 | if (self::debug) { |
| 512 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 512 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 513 | 513 | } |
| 514 | 514 | $refresh_msg = ''; |
| 515 | 515 | $none_added_msg = ''; |
| 516 | 516 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 517 | - $refresh_msg = __( |
|
| 517 | + $refresh_msg = __( |
|
| 518 | 518 | 'Please refresh the page to view updated ticket quantities.', |
| 519 | 519 | 'event_espresso' |
| 520 | 520 | ); |
| 521 | 521 | $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
| 522 | 522 | } |
| 523 | - if (! empty($this->sold_out_tickets)) { |
|
| 523 | + if ( ! empty($this->sold_out_tickets)) { |
|
| 524 | 524 | EE_Error::add_attention( |
| 525 | 525 | sprintf( |
| 526 | 526 | apply_filters( |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | // and reset the cart |
| 544 | 544 | EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
| 545 | 545 | } |
| 546 | - if (! empty($this->decremented_tickets)) { |
|
| 546 | + if ( ! empty($this->decremented_tickets)) { |
|
| 547 | 547 | EE_Error::add_attention( |
| 548 | 548 | sprintf( |
| 549 | 549 | apply_filters( |
@@ -581,9 +581,9 @@ discard block |
||
| 581 | 581 | protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
| 582 | 582 | { |
| 583 | 583 | if (self::debug) { |
| 584 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 585 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
| 586 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
| 584 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 585 | + echo self::$nl.' . transaction->ID: '.$transaction->ID(); |
|
| 586 | + echo self::$nl.' . TXN status_ID: '.$transaction->status_ID(); |
|
| 587 | 587 | } |
| 588 | 588 | // check if 'finalize_registration' step has been completed... |
| 589 | 589 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -595,13 +595,13 @@ discard block |
||
| 595 | 595 | __LINE__, |
| 596 | 596 | array('finalized' => $finalized), |
| 597 | 597 | false, |
| 598 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 598 | + 'EE_Transaction: '.$transaction->ID() |
|
| 599 | 599 | ); |
| 600 | 600 | } |
| 601 | 601 | // how many tickets were released |
| 602 | 602 | $count = 0; |
| 603 | 603 | if (self::debug) { |
| 604 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
| 604 | + echo self::$nl.' . . . TXN finalized: '.$finalized; |
|
| 605 | 605 | } |
| 606 | 606 | $release_tickets_with_TXN_status = array( |
| 607 | 607 | EEM_Transaction::failed_status_code, |
@@ -610,28 +610,28 @@ discard block |
||
| 610 | 610 | ); |
| 611 | 611 | $events = array(); |
| 612 | 612 | // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
| 613 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 613 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 614 | 614 | // cancel any reserved tickets for registrations that were not approved |
| 615 | 615 | $registrations = $transaction->registrations(); |
| 616 | 616 | if (self::debug) { |
| 617 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
| 617 | + echo self::$nl.' . . . # registrations: '.count($registrations); |
|
| 618 | 618 | $reg = reset($registrations); |
| 619 | 619 | $ticket = $reg->ticket(); |
| 620 | 620 | if ($ticket instanceof EE_Ticket) { |
| 621 | 621 | $ticket->add_extra_meta( |
| 622 | 622 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 623 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 623 | + __LINE__.') Release All Tickets TXN:'.$transaction->ID() |
|
| 624 | 624 | ); |
| 625 | 625 | } |
| 626 | 626 | } |
| 627 | - if (! empty($registrations)) { |
|
| 627 | + if ( ! empty($registrations)) { |
|
| 628 | 628 | foreach ($registrations as $registration) { |
| 629 | 629 | if ( |
| 630 | 630 | $registration instanceof EE_Registration |
| 631 | 631 | && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
| 632 | 632 | ) { |
| 633 | 633 | $count++; |
| 634 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
| 634 | + $events[$registration->event_ID()] = $registration->event(); |
|
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | 637 | } |
@@ -662,10 +662,10 @@ discard block |
||
| 662 | 662 | ) { |
| 663 | 663 | $STS_ID = $transaction->status_ID(); |
| 664 | 664 | if (self::debug) { |
| 665 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 666 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
| 667 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
| 668 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
| 665 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 666 | + echo self::$nl.' . . registration->ID: '.$registration->ID(); |
|
| 667 | + echo self::$nl.' . . registration->status_ID: '.$registration->status_ID(); |
|
| 668 | + echo self::$nl.' . . transaction->status_ID(): '.$STS_ID; |
|
| 669 | 669 | } |
| 670 | 670 | if ( |
| 671 | 671 | // release Tickets for Failed Transactions and Abandoned Transactions |
@@ -678,12 +678,12 @@ discard block |
||
| 678 | 678 | ) |
| 679 | 679 | ) { |
| 680 | 680 | if (self::debug) { |
| 681 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
| 681 | + echo self::$nl.self::$nl.' . . RELEASE RESERVED TICKET'; |
|
| 682 | 682 | $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
| 683 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 683 | + echo self::$nl.' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 684 | 684 | var_dump($rsrvd); |
| 685 | 685 | } |
| 686 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
| 686 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'.__LINE__); |
|
| 687 | 687 | return 1; |
| 688 | 688 | } |
| 689 | 689 | return 0; |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | public static function session_cart_reset(EE_Session $session) |
| 710 | 710 | { |
| 711 | 711 | if (self::debug) { |
| 712 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 712 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 713 | 713 | } |
| 714 | 714 | // first check of the session has a valid Checkout object |
| 715 | 715 | $checkout = $session->checkout(); |
@@ -721,12 +721,12 @@ discard block |
||
| 721 | 721 | $cart = $session->cart(); |
| 722 | 722 | if ($cart instanceof EE_Cart) { |
| 723 | 723 | if (self::debug) { |
| 724 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
| 724 | + echo self::$nl.self::$nl.' cart instance of EE_Cart: '; |
|
| 725 | 725 | } |
| 726 | 726 | EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
| 727 | 727 | } else { |
| 728 | 728 | if (self::debug) { |
| 729 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
| 729 | + echo self::$nl.self::$nl.' invalid EE_Cart: '; |
|
| 730 | 730 | var_export($cart, true); |
| 731 | 731 | } |
| 732 | 732 | } |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
| 749 | 749 | { |
| 750 | 750 | if (self::debug) { |
| 751 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 751 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 752 | 752 | } |
| 753 | 753 | EE_Registry::instance()->load_helper('Line_Item'); |
| 754 | 754 | $ticket_line_items = $cart->get_tickets(); |
@@ -757,28 +757,28 @@ discard block |
||
| 757 | 757 | } |
| 758 | 758 | foreach ($ticket_line_items as $ticket_line_item) { |
| 759 | 759 | if (self::debug) { |
| 760 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 760 | + echo self::$nl.' . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
| 761 | 761 | } |
| 762 | 762 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
| 763 | 763 | if (self::debug) { |
| 764 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 764 | + echo self::$nl.' . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
| 765 | 765 | } |
| 766 | 766 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
| 767 | 767 | if ($ticket instanceof EE_Ticket) { |
| 768 | 768 | if (self::debug) { |
| 769 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
| 770 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 769 | + echo self::$nl.' . . ticket->ID(): '.$ticket->ID(); |
|
| 770 | + echo self::$nl.' . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
| 771 | 771 | } |
| 772 | 772 | $ticket->add_extra_meta( |
| 773 | 773 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 774 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 774 | + __LINE__.') '.__METHOD__.'() SID = '.$session->id() |
|
| 775 | 775 | ); |
| 776 | 776 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
| 777 | 777 | } |
| 778 | 778 | } |
| 779 | 779 | } |
| 780 | 780 | if (self::debug) { |
| 781 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
| 781 | + echo self::$nl.self::$nl.' RESET COMPLETED '; |
|
| 782 | 782 | } |
| 783 | 783 | } |
| 784 | 784 | |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | protected function _session_checkout_reset(EE_Checkout $checkout) |
| 818 | 818 | { |
| 819 | 819 | if (self::debug) { |
| 820 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 820 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
| 821 | 821 | } |
| 822 | 822 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
| 823 | 823 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | __LINE__, |
| 868 | 868 | array($transaction), |
| 869 | 869 | false, |
| 870 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 870 | + 'EE_Transaction: '.$transaction->ID() |
|
| 871 | 871 | ); |
| 872 | 872 | } |
| 873 | 873 | return; |
@@ -884,7 +884,7 @@ discard block |
||
| 884 | 884 | __LINE__, |
| 885 | 885 | array($payment), |
| 886 | 886 | false, |
| 887 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 887 | + 'EE_Transaction: '.$transaction->ID() |
|
| 888 | 888 | ); |
| 889 | 889 | } |
| 890 | 890 | return; |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | } |
| 945 | 945 | $total_line_item = $transaction->total_line_item(); |
| 946 | 946 | // $transaction_in_progress->line |
| 947 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
| 947 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
| 948 | 948 | throw new DomainException( |
| 949 | 949 | esc_html__( |
| 950 | 950 | 'Transaction does not have a valid Total Line Item associated with it.', |
@@ -1005,18 +1005,18 @@ discard block |
||
| 1005 | 1005 | $source |
| 1006 | 1006 | ) { |
| 1007 | 1007 | if (self::debug) { |
| 1008 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 1008 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
| 1009 | 1009 | } |
| 1010 | 1010 | $total_tickets_released = 0; |
| 1011 | 1011 | $sold_out_events = array(); |
| 1012 | 1012 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
| 1013 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1013 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1014 | 1014 | continue; |
| 1015 | 1015 | } |
| 1016 | 1016 | $reserved_qty = $ticket_with_reservations->reserved(); |
| 1017 | 1017 | if (self::debug) { |
| 1018 | - echo self::$nl . ' . $ticket_with_reservations->ID(): ' . $ticket_with_reservations->ID(); |
|
| 1019 | - echo self::$nl . ' . $reserved_qty: ' . $reserved_qty; |
|
| 1018 | + echo self::$nl.' . $ticket_with_reservations->ID(): '.$ticket_with_reservations->ID(); |
|
| 1019 | + echo self::$nl.' . $reserved_qty: '.$reserved_qty; |
|
| 1020 | 1020 | } |
| 1021 | 1021 | foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
| 1022 | 1022 | if ( |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
| 1025 | 1025 | ) { |
| 1026 | 1026 | if (self::debug) { |
| 1027 | - echo self::$nl . ' . $valid_reserved_ticket_line_item->quantity(): ' . $valid_reserved_ticket_line_item->quantity(); |
|
| 1027 | + echo self::$nl.' . $valid_reserved_ticket_line_item->quantity(): '.$valid_reserved_ticket_line_item->quantity(); |
|
| 1028 | 1028 | } |
| 1029 | 1029 | $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
| 1030 | 1030 | } |
@@ -1032,9 +1032,9 @@ discard block |
||
| 1032 | 1032 | if ($reserved_qty > 0) { |
| 1033 | 1033 | $ticket_with_reservations->add_extra_meta( |
| 1034 | 1034 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 1035 | - __LINE__ . ') ' . $source . '()' |
|
| 1035 | + __LINE__.') '.$source.'()' |
|
| 1036 | 1036 | ); |
| 1037 | - $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 1037 | + $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'.__LINE__); |
|
| 1038 | 1038 | $ticket_with_reservations->save(); |
| 1039 | 1039 | $total_tickets_released += $reserved_qty; |
| 1040 | 1040 | $event = $ticket_with_reservations->get_related_event(); |
@@ -1045,10 +1045,10 @@ discard block |
||
| 1045 | 1045 | } |
| 1046 | 1046 | } |
| 1047 | 1047 | if (self::debug) { |
| 1048 | - echo self::$nl . ' . $total_tickets_released: ' . $total_tickets_released; |
|
| 1048 | + echo self::$nl.' . $total_tickets_released: '.$total_tickets_released; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | // double check whether sold out events should remain sold out after releasing tickets |
| 1051 | - if($sold_out_events !== array()){ |
|
| 1051 | + if ($sold_out_events !== array()) { |
|
| 1052 | 1052 | foreach ($sold_out_events as $sold_out_event) { |
| 1053 | 1053 | /** @var EE_Event $sold_out_event */ |
| 1054 | 1054 | $sold_out_event->perform_sold_out_status_check(); |
@@ -1075,7 +1075,7 @@ discard block |
||
| 1075 | 1075 | { |
| 1076 | 1076 | /** @type WPDB $wpdb */ |
| 1077 | 1077 | global $wpdb; |
| 1078 | - if (! absint($timestamp)) { |
|
| 1078 | + if ( ! absint($timestamp)) { |
|
| 1079 | 1079 | /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
| 1080 | 1080 | $session_lifespan = LoaderFactory::getLoader()->getShared( |
| 1081 | 1081 | 'EventEspresso\core\domain\values\session\SessionLifespan' |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | } |
| 1085 | 1085 | return $wpdb->query( |
| 1086 | 1086 | $wpdb->prepare( |
| 1087 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 1087 | + 'DELETE FROM '.EEM_Line_Item::instance()->table().' |
|
| 1088 | 1088 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
| 1089 | 1089 | // use GMT time because that's what LIN_timestamps are in |
| 1090 | 1090 | date('Y-m-d H:i:s', $timestamp) |