/** * save the contents of this class as a transient * * @access private * * @since 3.8.14 * * @return none */ public static function save() { if (self::_dirty()) { $mydata = array(); // This all about which maps to we want to have available as soon as this class is initialized? // Serialize those maps into the saved verison of this object. $mydata['_maps_to_save_with_core_class'] = self::$_maps_to_save_with_core_class; foreach (self::$_maps_to_save_with_core_class as $map_name => $save_map) { if ($save_map) { self::${$map_name}->clear_dirty(); $mydata[$map_name] = self::${$map_name}; } } _wpsc_set_transient(self::transient_name(), $mydata); self::$_dirty = false; } }
/** * 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); }