/** * Resets the config * * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE * (default) leaves the database alone, and merely resets the EE_Config object to * reflect its state in the database * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave * $_instance as NULL. Useful in case you want to forget about the old instance on * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the * site was put into maintenance mode) * @return EE_Config */ public static function reset($hard_reset = false, $reinstantiate = true) { if ($hard_reset) { self::$_instance->_addon_option_names = array(); self::$_instance->_initialize_config(); self::$_instance->update_espresso_config(); } if (self::$_instance instanceof EE_Config) { self::$_instance->update_addon_option_names(); } self::$_instance = null; //we don't need to reset the static properties imo because those should //only change when a module is added or removed. Currently we don't //support removing a module during a request when it previously existed if ($reinstantiate) { return self::instance(); } else { return null; } }
/** * update_espresso_config * * @access public * @param bool $add_success * @param bool $add_error * @return bool */ public function update_espresso_config($add_success = FALSE, $add_error = TRUE) { $instance = self::$_instance; self::$_instance = NULL; do_action('AHEE__EE_Config__update_espresso_config__begin', $this); // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional but BEFORE the actual update occurs add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); // now update "ee_config" $saved = update_option('ee_config', $this); // if not saved... check if the hook we just added still exists; if it does, it means one of two things: // that update_option bailed at the ( $value === $old_value ) conditional, or... // the db update query returned 0 rows affected (probably because the data value was the same from it's perspective) // so the existence of the hook means that a negative result from update_option is NOT an error, but just means no update occurred, so don't display an error to the user. // BUT... if update_option returns FALSE, AND the hook is missing, then it means that something truly went wrong $saved = !$saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; // remove our action since we don't want it in the system anymore remove_action('update_option', array($this, 'double_check_config_comparison'), 1); do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); self::$_instance = $instance; unset($instance); // if config remains the same or was updated successfully if ($saved) { if ($add_success) { EE_Error::add_success(__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); } return TRUE; } else { if ($add_error) { EE_Error::add_error(__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); } return FALSE; } }