Commit b8d93902 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

V1.2.2: Fix alloptions problem that prevented all counters from being loaded in the backend

parent b6e94e3a
BASE=ordernumbers
PLATTFORM=woocommerce
VENDOR=opentools
VERSION=1.2.1
VERSION=1.2.2
DIR = $(shell pwd)
SVNDIR=wordpress-plugin-svn
......
<!DOCTYPE html><title></title>
......@@ -49,11 +49,6 @@ div.ordernumber-ajax-loading img {
z-index:0;
}
img.ordernumber-loading {
display: none;
position: absolute;
......
<!DOCTYPE html><title></title>
<!DOCTYPE html><title></title>
<!DOCTYPE html><title></title>
......@@ -172,7 +172,6 @@ var ajaxAddCounter = function (btn, nrtype) {
error: function() { alert (String.Format(ajax_ordernumber.ORDERNUMBER_JS_ADD_FAILED, countername)); },
complete: function() { jQuery(loading).remove(); },
};
// console.log("Ajaxargs", ajaxargs);
if ('modifyAjaxArgs' in ajax_ordernumber) {
ajaxargs = ajax_ordernumber.modifyAjaxArgs(ajaxargs);
}
......
......@@ -326,15 +326,23 @@ class OrdernumberHelper {
}
}
protected function no_array($v) {
return !is_array($v);
}
protected function doReplacements ($fmt, $reps) {
// First, replace all random...[n] fields. This needs to be done with a regexp and a callback:
$fmt = preg_replace_callback ('/\[(random)(.*?)([0-9]*?)\]/i', array($this, 'replaceRandom'), $fmt);
// Only use string-valued variables for replacement (array-valued variables can be used in custom variable definitions!)
$reps = array_filter($reps, function($v) { return !is_array($v);} );
$reps = array_filter($reps, array($this, "no_array") );
return str_ireplace (array_keys($reps), array_values($reps), $fmt);
}
protected function extractCounterSettings ($fmt, $type, $ctrsettings) {
// Some e-Commerce systems use 'yes' for true, others use 1 => correct everything to 1
if ($ctrsettings["${type}_global"] == 'yes') {
$ctrsettings["${type}_global"] = 1;
}
$parts=array($fmt);
if ($this->getFlag('extract-counter-settings', true)) {
// First, extract all counter settings, i.e. all strings of the form [#####:startval/increment] or [####/increment:startval]
......@@ -374,7 +382,7 @@ class OrdernumberHelper {
$parts = explode ("|", $fmt);
}
$ctrsettings["${type}_format"] = $parts[0];
$ctrsettings["${type}_counter"] = ($ctrsettings["${type}_global"]=='yes')?"":$parts[(count($parts)>1)?1:0];
$ctrsettings["${type}_counter"] = ($ctrsettings["${type}_global"]==1)?"":$parts[(count($parts)>1)?1:0];
return $ctrsettings;
}
......
......@@ -77,13 +77,26 @@ class OrdernumberHelperWooCommerce extends OrdernumberHelper {
protected function get_all_options($prefix) {
global $wpdb;
$suppress = $wpdb->suppress_errors();
$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE `option_name` LIKE '$prefix%'" );
$wpdb->suppress_errors($suppress);
$alloptions = array();
foreach ( (array) $alloptions_db as $o ) {
$alloptions[$o->option_name] = $o->option_value;
}
return $alloptions;
}
function getAllCounters($type) {
$counters = array();
$pfxlen = strlen(self::$ordernumber_counter_prefix );
// TODO: BUG: wp_load_alloptions does NOT load non-autoload options.
// BUG: wp_load_alloptions does NOT load non-autoload options.
// However, we switched all counters to non-autoload, so they will not appear any more!
foreach (wp_load_alloptions() as $name => $value) {
// so we need to use our own function that directly accesses the database
foreach ($this->get_all_options(self::$ordernumber_counter_prefix) as $name => $value) {
if (substr($name, 0, $pfxlen) == self::$ordernumber_counter_prefix) {
$parts = explode('-', substr($name, $pfxlen), 2);
if (sizeof($parts)==1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment