You are here:  » How to reset clicks shown in admin via daily CRON

Support Forum



How to reset clicks shown in admin via daily CRON

Submitted by Convergence on Fri, 2012-08-10 17:46 in

v12/10B

Greetings,

Is it possible to reset the clicks shown in admin via a CRON job? We would like to reset the clicks nightly.

Thank you.

Submitted by support on Sat, 2012-08-11 09:26

Sure - the PHP code that could be used within any existing script is just:

  $sql = "UPDATE `".$config_databaseTablePrefix."feeds` SET clicks=0";
  database_queryModify($sql,$result);

So if you're using cron.php as your main CRON job, simply insert the above code into the end of the script, just before the closing PHP tag.

Alternatively, to make a standalone scripts/resetclicks.php use the following code:

<?php
  
require("../includes/common.php");
  if (isset(
$_SERVER["REQUEST_METHOD"]))
  {
    
$password = (isset($_GET["password"])?$_GET["password"]:"");
    if (
$password != $config_adminPassword)
    {
      
header('HTTP/1.0 401 Unauthorized');
      print 
"<h1>401 Unauthorized</h1>";
      exit();
    }
    
header("Content-Type: text/plain");
  }
  else
  {
    
$config_adminPassword "";
    
$admin_checkPassword FALSE;
  }
  
$sql "UPDATE `".$config_databaseTablePrefix."feeds` SET clicks=0";
  
database_queryModify($sql,$result);
  exit();
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by Capricorn on Sat, 2012-08-11 23:13

Hi David,

Is it also possible to add a link to resetclicks on the admin page?

Thanks.

Submitted by support on Sun, 2012-08-12 13:20

Hi Capricorn,

Sure - first create the following new script as admin/resetclicks.php

<?php
  require("../includes/common.php");
  $admin_checkPassword = TRUE;
  require("../includes/admin.php");
  $sql = "UPDATE `".$config_databaseTablePrefix."feeds` SET clicks=0";
  database_queryModify($sql,$result);
  header("Location: ".$config_baseHREF."admin/");
  exit();
?>

With that in place, edit admin/admin_menu.php and add a new item for the new script, e.g.

  print "<a href='resetclicks.php'>Reset Clicks</a>&nbsp;&nbsp;";

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Sun, 2012-08-12 18:06

Thanks David,

Standalone CRON worked perfectly!

Submitted by IG on Sun, 2012-12-02 12:22

Hi David

I followed the instructions in the beginning of this thread and inserted the above code (2 lines) into the end of cron.php, just before the closing PHP tag. However, the clicks don't get reset when cron runs.

As I am using the zero-down time modification, I was wondering if the code should be different to make this work?

Cheers, IG

Submitted by support on Sun, 2012-12-02 12:25

Hi IG,

The last actual code line of scripts/cron.php is actually;

  exit();

...so nothing after that would be executed. To apply the change, REPLACE that line with:

  $sql = "UPDATE `".$config_databaseTablePrefix."feeds` SET clicks=0";
  database_queryModify($sql,$result);
  exit();

Cheers,
David.
--
PriceTapestry.com