This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

Ivanko

  • *****
  • 388 posts
[Bug] - Phone Clicks are not showing in User menu items
« on: March 04, 2017, 11:52:12 PM »
The phone statistic is always 0, zero in User Menu item  Listings.

In user-items.php you have query , about line 96

Code: [Select]
$query = "SELECT
sum(s.i_num_views) as views, sum(s.i_num_premium_views) as premium_views, sum(coalesce(e.i_num_phone_clicks, 0))
as
phone_clicks FROM {$db_prefix}t_item_stats s
LEFT OUTER JOIN
{$db_prefix}t_item_stats_veronika e
ON
(s.fk_i_item_id = e.fk_i_item_id
AND
s.dt_date = e.dt_date)
WHERE
s.fk_i_item_id = " . osc_item_id() . ";";

After clicking on call url the dt_date is not updated properly in table  _t_item_stats_veronika , see attached print screen , the date is always 0000-00-00. Which is creating problem for s.dt_date = e.dt_date
I have tried manually add one date, the problem was solved

question 1.
Please advise where to amend event in order to update date properly into the table
question 2.
Please advise you solution to UPDATE and SET missed dates directly using RAW query in sql.

When you get a time :)

as temporary solution I am using function
Code: [Select]
veronika_phone_clicks(osc_item_id());I am already cooked up today  :o :o :o
« Last Edit: March 05, 2017, 03:39:13 AM by Ivanko »

*

MB Themes

Re: [Bug] - Phone Clicks are not showing in User menu items
« Reply #1 on: March 05, 2017, 11:16:57 AM »
@Ivanko
We use same function for date input as osclass does for their views, so I assume you have problem with classic views as well, or?
- you cannot fix dates that already exists, because you do not know the date
- in functions.php there is function veronika_increase_clicks that handles clicks.
Problematic part for you is:
Code: [Select]
$query = "INSERT INTO {$db_prefix}t_item_stats_veronika (fk_i_item_id, dt_date, i_num_phone_clicks) VALUES ({$itemId}, \"{date('Y-m-d H:i:s')}\", 1) ON DUPLICATE KEY UPDATE  i_num_phone_clicks = i_num_phone_clicks + 1";
      return ItemStats::newInstance()->dao->query($query);

Same is in osclass core. As you can see PHP function is used: date('Y-m-d H:i:s'), so value you see in database is probably created by database itself (as result of incorrect format).

I found on demo there is same issue. Update works, but also incorrectly (do not take into account current date).
My tip is problem with unique index definition on db, but it seems that also date function is somehow incorrect.

I will take a look on it closer next week.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ivanko

  • *****
  • 388 posts
Re: [Bug] - Phone Clicks are not showing in User menu items
« Reply #2 on: March 05, 2017, 06:08:39 PM »
Why just wan`t to use ?

Code: [Select]
   $query = "INSERT INTO {$db_prefix}t_item_stats_veronika (fk_i_item_id, dt_date, i_num_phone_clicks)
   VALUES ({$itemId}, now(), 1)
   ON DUPLICATE KEY UPDATE  i_num_phone_clicks = i_num_phone_clicks + 1";


Where the DATE goes else?

I had tried and found that after click on phone the dt_date updating properly in _t_item_stats_veronika , and shows properly in user menu items...
« Last Edit: March 05, 2017, 07:42:37 PM by Ivanko »

*

MB Themes

Re: [Bug] - Phone Clicks are not showing in User menu items
« Reply #3 on: March 05, 2017, 09:27:14 PM »
@Ivanko
I would not say this will fix it, but will test.
I am pretty sure if you remove date as column in select statement and on db change default value to current_timestamp, it will work.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ivanko

  • *****
  • 388 posts
Re: [Bug] - Phone Clicks are not showing in User menu items
« Reply #4 on: March 05, 2017, 11:08:21 PM »
Yeah, This is working too :

Code: [Select]
$query = "INSERT INTO {$db_prefix}t_item_stats_veronika (fk_i_item_id, i_num_phone_clicks)
  VALUES ({$itemId}, 1)
  ON DUPLICATE KEY UPDATE  i_num_phone_clicks = i_num_phone_clicks + 1";

When
dt_date    Type               Deafault
                   timestamp    CURRENT_TIMESTAMP
 

Only I need to clean all statistics where dt_date = 0000-00-00 , they are all :)

 frosticek what do you recommend, last option ?
« Last Edit: March 06, 2017, 04:16:24 AM by Ivanko »

Marked as best answer by frosticek on March 06, 2017, 09:11:03 AM
*

MB Themes

Re: [Bug] - Phone Clicks are not showing in User menu items
« Reply #5 on: March 06, 2017, 09:10:58 AM »
@Ivanko
You cannot set current_timestamp for date field. You can find also in MySQL configuration that this is not possible.

There were 2 issues:
- problem in function where date was not send correctly
- problem with definition of table

Function issue:
function must be replaced:
Code: [Select]
function veronika_increase_clicks($itemId, $itemUserId = NULL) {
  if($itemId > 0) {
    if($itemUserId == '' || $itemUserId == 0 || ($itemUserId <> '' && $itemUserId > 0 && $itemUserId <> osc_logged_user_id())) {
      $db_prefix = DB_TABLE_PREFIX;
      //$query = "INSERT INTO {$db_prefix}t_item_stats_veronika (fk_i_item_id, dt_date, i_num_phone_clicks) VALUES ({$itemId}, \"{date('Y-m-d')}\", 1) ON DUPLICATE KEY UPDATE  i_num_phone_clicks = i_num_phone_clicks + 1";
      $query = 'INSERT INTO ' . $db_prefix . 't_item_stats_veronika (fk_i_item_id, dt_date, i_num_phone_clicks) VALUES (' . $itemId . ', "' . date('Y-m-d') . '", 1) ON DUPLICATE KEY UPDATE  i_num_phone_clicks = i_num_phone_clicks + 1';
      return ItemStats::newInstance()->dao->query($query);
    }
  }
}

Then date is send correctly.


Table definition
Problem is with definition of fk_i_item_id as unique key. This cause that for each item there can be just 1 result no matter of date. (then all next clicks were assigned to first row for item id - first and only one row).

To fix this, remove unique key on fk_i_item_id or recreate table:
Code: [Select]
DROP TABLE IF EXISTS veronika_t_item_stats_veronika;
CREATE TABLE veronika_t_item_stats_veronika(
  fk_i_item_id INT(11) UNSIGNED NOT NULL,
  i_num_phone_clicks INT(10) DEFAULT 0,
  dt_date DATE,

  PRIMARY KEY (fk_i_item_id, dt_date),
  FOREIGN KEY (fk_i_item_id) REFERENCES veronika_t_item (pk_i_id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET 'UTF8' COLLATE 'UTF8_GENERAL_CI';


Thanks for your support Ivanko ;)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ivanko

  • *****
  • 388 posts
Re: [Bug] - Phone Clicks are not showing in User menu items
« Reply #6 on: March 06, 2017, 12:24:19 PM »
Yeah Good !
Working well :)
Welcome  ::)
« Last Edit: March 06, 2017, 12:44:43 PM by Ivanko »

*

mr-merk

  • **
  • 9 posts
Re: [Bug] - Phone Clicks are not showing in User menu items
« Reply #7 on: March 14, 2017, 12:43:04 PM »
Hello. It is work very nice but why graphic telephone,  very long in one click.


*

MB Themes

Re: [Bug] - Phone Clicks are not showing in User menu items
« Reply #8 on: March 14, 2017, 01:00:14 PM »
@mr-merk
Dual axis?
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mr-merk

  • **
  • 9 posts
Re: [Bug] - Phone Clicks are not showing in User menu items
« Reply #9 on: March 14, 2017, 08:42:30 PM »
@mr-merk
Dual axis?
do not understand

*

MB Themes

  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots