Zen Cart Logo
Forums / Bug Reports / [Done v1.3.9b] Counter History issue in 1.3.9a

[Done v1.3.9b] Counter History issue in 1.3.9a

Locked

Views: 6,265

Results 1 to 20 of 25
This thread is locked. New replies are disabled.
26 Apr 2010, 8:29 PM
#1
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

[Done v1.3.9b] Counter History issue in 1.3.9a

Hi there,

I recently upgraded a site from 1.3.8a to 1.3.9a. The admin counter history looked like this after upgrading:

04/26/2010 1-1
04/26/2010 1-1
04/26/2010 1-1
04/26/2010 1-1
04/26/2010 1-1
04/26/2010 1-1
04/26/2010 1-1
04/26/2010 1-1
04/26/2010 1-1
04/26/2010 1-1

I compared the includes/counter.php file from v1.3.8a and v1.3.9a and found this code change:

1.3.8a

$counter_query = "select startdate, counter, session_counter from " . TABLE_COUNTER_HISTORY . " where startdate='" . $date_now . "'";
$counter = $db->Execute($counter_query);
if ($counter->RecordCount() <= 0) {
$date_now = date('Ymd');
$sql = "insert into " . TABLE_COUNTER_HISTORY . " (startdate, counter, session_counter) values ('" . $date_now . "', '1', '1')";
$db->Execute($sql);
$counter_startdate = $date_now;
$counter_now = 1;
} else {
$counter_startdate = $counter->fields['startdate'];
$counter_now = ($counter->fields['counter'] + 1);
$session_counter_now = ($counter->fields['session_counter'] + $session_counter);
$sql = "update " . TABLE_COUNTER_HISTORY . " set counter = '" . $counter_now . "', session_counter ='" . $session_counter_now . "' where startdate='" . $date_now . "'";
$db->Execute($sql);
}

1.3.9a

$sql = "insert into " . TABLE_COUNTER_HISTORY . " (startdate, counter, session_counter) values ('" . $date_now . "', '1', '1')
on duplicate key update counter = counter + 1, session_counter = session_counter + " . (int)$session_counter;
$db->Execute($sql);

I put 1.3.8a code back in, and now the counter works fine. I'm not sure what the change in code was for, but it doesn't seem to be working correctly.

Thanks!

Danielle

26 Apr 2010, 8:34 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

The code is working properly, but it requires that your database tables be updated properly first.

Thus, the symptoms you describe suggest that you didn't upgrade your database structure properly, so your database isn't properly handling the duplicates anymore.

It's important that you run zc_install to upgrade your database as part of the upgrade process.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 Apr 2010, 8:37 PM
#3
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

DrByte:

The code is working properly, but it requires that your database tables be updated properly first.

Thus, the symptoms you describe suggest that you didn't upgrade your database structure properly, so your database isn't properly handling the duplicates anymore.

It's important that you run zc_install to upgrade your database as part of the upgrade process.

Yes I did do that already, and in the admin it does say the Database Patch Level is 1.3.9a.

Danielle

26 Apr 2010, 8:40 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

When you did the database-upgrade, did it tell you that it skipped anything?

What messages are listed in your database's upgrade_exceptions table?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 Apr 2010, 8:44 PM
#5
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

DrByte:

When you did the database-upgrade, did it tell you that it skipped anything?

What messages are listed in your database's upgrade_exceptions table?

The only things skipped were the things mentioned in the upgrade thread, I can't remember what they were offhand, something to do with Paypal I believe?

All the messages in the upgrade_exceptions table are related to add-ons. There were no messages about the counter_history table.

Danielle

26 Apr 2010, 9:02 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

Use phpMyAdmin and Export the structure-only of your counter_history table. Output to screen. Paste it here.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 Apr 2010, 9:53 PM
#7
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

CREATE TABLE counter_history (
startdate char(8) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
counter int(12) DEFAULT NULL,
session_counter int(12) DEFAULT NULL,
PRIMARY KEY (startdate)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Danielle

26 Apr 2010, 10:20 PM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

Danielle:

I'm not sure what the change in code was for
http://www.zen-cart.com/forum/showthread.php?t=122543

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 Apr 2010, 10:23 PM
#9
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

DrByte:

http://www.zen-cart.com/forum/showthread.php?t=122543

Yes, I saw that thread already, but we didn't have any issue with duplicates until the upgrade to 1.3.9a. There were literally thousands of records per day since the upgrade, all with 1-1. Anyways, it seems to be working fine with the old code for now.

Thanks :)

Danielle

26 Apr 2010, 10:44 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

What version of MySQL?

The only reason it should be making those duplicates is if your primary key isn't actually being enforced properly to prevent duplicates.
In fact, it must not be enforced properly, because if it was, then the duplicates you reported would be impossible.

Either that, or you're using a very old version of MySQL. Thus the question about which version of MySQL you're using.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

27 Apr 2010, 11:19 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

Try replacing the code with this:```
$date_now = date('Ymd');
$sql = "insert into " . TABLE_COUNTER_HISTORY . " (startdate, counter, session_counter) values ('" . $date_now . "', '1', '1')
on duplicate key update counter = counter + 1, session_counter = session_counter + " . (int)$session_counter;
$db->Execute($sql);

$counter_query = "select startdate, counter from " . TABLE_COUNTER;
$counter = $db->Execute($counter_query);
if ($counter->RecordCount() <= 0) {
$date_now = date('Ymd');
$sql = "insert into " . TABLE_COUNTER . " (startdate, counter) values ('" . $date_now . "', '1')";
$db->Execute($sql);
$counter_startdate = $date_now;
$counter_now = 1;
} else {
$counter_startdate = $counter->fields['startdate'];
$counter_now = ($counter->fields['counter'] + 1);
$sql = "update " . TABLE_COUNTER . " set counter = '" . $counter_now . "'";
$db->Execute($sql);
}

Would appreciate your feedback, as well as an indicator of which MySQL version you're using.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

29 Apr 2010, 4:36 AM
#12
loves2loop avatar

loves2loop

New Zenner

Join Date:
Apr 2010
Posts:
1
Plugin Contributions:
0

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

I had the same problem. Here is how I fixed it.

The new code won't work unless the startdate field is primary or indexed, and it was neither. When I tried to make it primary, it failed, due to duplicate entries for the same date, that occurred before upgrading zen cart. After deleting all duplicates, I was able to make the startdate field primary, and the counter history started working correctly.

29 Apr 2010, 5:58 AM
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

loves2loop:

I had the same problem. Here is how I fixed it.

The new code won't work unless the startdate field is primary or indexed, and it was neither. When I tried to make it primary, it failed, due to duplicate entries for the same date, that occurred before upgrading zen cart. After deleting all duplicates, I was able to make the startdate field primary, and the counter history started working correctly.
Okay, but, the zc_install upgrade process already takes care of fixing all those duplicate problems AND setting the primary key properly.
So, clearly you didn't use the published upgrade process.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Jun 2010, 3:14 PM
#14
rjspomer avatar

rjspomer

Zen Follower

Join Date:
Jan 2008
Posts:
173
Plugin Contributions:
0

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

I have the same issue I used the simple script in my cp panel to upgrade. My hosting tech suggested this as a way of upgrading. I do now have version 1.39c but the duplicate problems in the history.

DrByte:

Use phpMyAdmin and Export the structure-only of your counter_history table. Output to screen. Paste it here.

Where do I find the structure -only of the counter_history table?

Thanks

2 Jun 2010, 3:31 PM
#15
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

rjspomer:

I have the same issue I used the simple script in my cp panel to upgrade. My hosting tech suggested this as a way of upgrading. I do now have version 1.39c but the duplicate problems in the history.

Where do I find the structure -only of the counter_history table?

Thanks

Apparently your hosting tech has greater wisdom on upgrading than we do. Feel free to ask them for help since you followed their advice instead of ours.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Jun 2010, 4:13 PM
#16
rjspomer avatar

rjspomer

Zen Follower

Join Date:
Jan 2008
Posts:
173
Plugin Contributions:
0

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

DrByte:

Apparently your hosting tech has greater wisdom on upgrading than we do. Feel free to ask them for help since you followed their advice instead of ours.

OK I made a mistakes in using the simple script but I did not expect such a smartass remark. A lot of us are small business owners who do not have a lot of time or knowledge of scripts and not PHP gurus like you. Please don't talk down to us.

I know I am not worthy of your advise but can you try to help. :smile:

2 Jun 2010, 5:29 PM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

Sorry, I've just been dealing with too many cases where people did automated upgrades and broke things, instead of following the published upgrade instructions. I should have counted to 10 before replying.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Jun 2010, 5:39 PM
#18
rjspomer avatar

rjspomer

Zen Follower

Join Date:
Jan 2008
Posts:
173
Plugin Contributions:
0

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

No Problem :smile:

I appreciate the help and all you guys and gals do for nothing but a thank you.

Now that I have this messed up where do I start. I went into my counter history db and empty it. I had hundreds of duplicates over that last few days.

Thanks again

2 Jun 2010, 5:49 PM
#19
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

Given that you've already deleted all the data in the table, just recreate it:```
DROP TABLE IF EXISTS counter_history;
CREATE TABLE counter_history (
startdate char(8) default NULL,
counter int(12) default NULL,
session_counter int(12) default NULL,
PRIMARY KEY (startdate)
) ENGINE=MyISAM;

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Jun 2010, 5:59 PM
#20
rjspomer avatar

rjspomer

Zen Follower

Join Date:
Jan 2008
Posts:
173
Plugin Contributions:
0

Re: [Done v1.3.9b] Counter History issue in 1.3.9a

Yes I have 1.3.9c

Please bear with me where do I paste this code?