/** * Restore the structured country data from the cache int the class * * @access private * * @since 3.8.14 * * @return none */ private function restore() { // force a class load in php $data = _wpsc_get_transient(self::transient_name()); $has_data = false; $transient_is_valid = is_array($data); foreach (self::$_maps_to_save_with_core_class as $map_name => $should_be_saved) { if ($should_be_saved) { if (null !== $data[$map_name] && !is_a($data[$map_name], 'WPSC_Data_Map')) { $transient_is_valid = false; _wpsc_delete_transient(self::transient_name()); break; } } } if ($transient_is_valid) { if (is_array($data)) { foreach ($data as $variable => $value) { if (property_exists($this, $variable)) { if (is_a($value, 'WPSC_Data_Map')) { $value->clear_dirty(); } self::${$variable} = $value; $has_data = true; } else { // something went wrong with save / restore $has_data = false; break; } } self::$_initialized = true; } } if ($transient_is_valid && !$has_data && $data !== false) { _wpsc_delete_transient(self::transient_name()); self::$_initialized = false; } self::$_dirty = false; return $this; }
/** * Make sure the data is available * * @access public * * @since 3.8.14 * * @return string a map name to uniquely identify this map so it can be saved and restored */ private function _confirm_data_ready() { if (!is_array($this->_map_data)) { // if this is a named map we can try to restore it from the transient store if (!empty($this->_map_name)) { // TODO: Maybe figure out why this causes problems with APC caches, or maybe it doesn't? // In any case because transients can be deleted at any time commenting this out should // merely force a rebuild. // see https://wordpress.org/support/topic/fatal-error-wpsc_countries/page/2?replies=49#post-6812338 $this->_map_data = _wpsc_get_transient($this->_map_name); } // if we still don't have a valid map and there is a constructor callback use it if (!is_array($this->_map_data) && !empty($this->_map_callback) && is_callable($this->_map_callback)) { static $already_invoking_callback = array(); // the callback could be a string or an array, we can keep track of // who's call we are processing tp avoid a recursion problem, just in case! $callback_unique_key = md5(json_encode($this->_map_callback)); if (!array_key_exists($callback_unique_key, $already_invoking_callback)) { $already_invoking_callback[$callback_unique_key] = true; $this->_map_data = array(); // callback has a single parameter, the data map call_user_func($this->_map_callback, $this); if (!is_array($this->_map_data)) { $this->_map_data = array(); } if (!empty($this->_map_name)) { _wpsc_set_transient($this->_map_name, $this->_map_data); } // we just loaded and saved the data, that makes it not dirty $this->_dirty = false; } else { if (is_array($this->_map_callback)) { $function = $this->_map_callback[0] . '::' . $this->_map_callback[1]; } else { $function = $this->_map_callback; } _wpsc_doing_it_wrong($function, __('WPSC_Data_Map map creation callback is recursively calling itself.', 'wpsc'), '3.8.14'); } unset($already_invoking_callback[$callback_unique_key]); } // if we still don't have valid map data create an empty array if (!is_array($this->_map_data)) { $this->_map_data = array(); } } return is_array($this->_map_data); }