You are here:  » Feed format change email notification system


Feed format change email notification system

Submitted by wdekreij on Tue, 2010-12-14 16:44 in

Hi all,

I'm working on some sites that will use many, many merchants. I would say: too much to check them all by hand, each time.

Therefore I would like to make a system that - with each import - will check whether the first row is still the same as before. If it is: No problem! If not, it should send out a warning e-mail, including the old and new first row. Based on that email I can decide whether that merchant would need new feed-settings.

Any thoughts on this?

Submitted by support on Wed, 2010-12-15 09:28

Hi,

It could be done, but could potentially involve hundreds of emails in one go which might not be desirable... What about creating a update log post import (the process has to run after a full import in order to select the comparisons)?

Cheers,
David.
--
PriceTapestry.com

Submitted by wdekreij on Wed, 2010-12-15 10:25

You are right! That sounds very good :)

Submitted by support on Wed, 2010-12-15 11:14

Hi,

Sorry, I may have mis-understood - do you mean literally the first product row of each feed as it is imported, not the cheapest product of a product that is compared across multiple merchants?

In which case, this is slightly easier (and email alerting should be feasible). First, add a new field to the feeds table using the following dbmod.php script (run from your main Price Tapestry installation folder:

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."feeds`
            ADD `change_hash` VARCHAR(32) NOT NULL"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Next, within the import record handler function in includes/admin.php, look for the following code at the end of the function at around line 449:

    return ($admin_importProductCount == $admin_importLimit);

...and REPLACE that with:

    if ($admin_importProductCount==1)
    {
      $change_hash = md5(serialize($record));
      if ($change_hash <> $admin_importFeed["change_hash"])
      {
        $sql = "UPDATE `".$config_databaseTablePrefix."feeds` SET change_hash='".$change_hash."'";
        database_queryModify($sql,$result);
        mail(
          "you@example.com",
          "Feed Format Alert",
          "Feed: ".$admin_importFeed["filename"]." format may have changed!");
      }
    }
    return ($admin_importProductCount == $admin_importLimit);

Replace you@example.com with your email address as required. Most PHP installations seem to have mail enabled. Bear in mind that you will receive an email in the first instance for each feed whilst the change_hash value is populated - if that's undesirable comment out the mail() line until all feeds have been imported at least once...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by wdekreij on Wed, 2010-12-15 15:21

Thanks!

Indeed, I just want it to look at the first row.

If the first row was something like row1;row2;row3;, but has changed to rowA;rowB;rowC it should send me an email. I'm not exactly sure what your script (above) does. Is that what it does?

Submitted by Keeop on Wed, 2010-12-15 16:44

Hope you don't mind me interjecting.

Judging from what you've said in the first post, wdekreij, do you want to be informed if the merchant's feed structure has been changed? i.e. your imports will stop automatically running because the feed format has changed or the field names have changed? That would certainly be useful if you have sites that aren't checked often and there's nothing worse than a merchant, or network, changing feed parameters without notifying its own affiliates!

Cheers.
Keeop

Submitted by support on Wed, 2010-12-15 16:44

Nearly...!

The code above is based on the content of the first record, but can easily be based on the field names instead. To do this, REPLACE the following line from the mod:

      $change_hash = md5(serialize($record));

with:

      $change_hash_value = "";
      foreach($record as $k => $v)
      {
        $change_hash_value .= $k;
      }
      $change_hash = md5(serialize($change_hash_value));

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Mon, 2011-01-10 10:42

Hi David,

I can't seem to get this to work. Every time I import I get a warning, when the feed structure hasn't changed at all. Any ideas please?

if ($admin_importProductCount==1)
        {
          $change_hash_value = "";
          foreach($record as $k => $v)
          {
            $change_hash_value .= $k;
          }
          $change_hash = md5(serialize($change_hash_value));
          if ($change_hash <> $admin_importFeed["change_hash"])
       {
            $sql = "UPDATE `".$config_databaseTablePrefix."feeds` SET change_hash='".$change_hash."'";
            database_queryModify($sql,$result);
            mail(
              "admin@domain.com",
              "Feed Format Alert",
              "Feed: ".$admin_importFeed["filename"]." format may have changed!");
          }
        }

Cheers.
Keeop

Submitted by support on Mon, 2011-01-10 14:05

Hi Keeop,

Reviewing the code, this line:

          $change_hash = md5(serialize($change_hash_value));

...should actually be just:

          $change_hash = md5($change_hash_value);

...however, that shouldn't cause it not too work (it's just inefficient). After importing a feed, could you double check the feeds table via phpMyAdmin and make sure that change_hash for that feed has a value (32 random characters). Make a note of the value, then try re-importing, and compare the value to the last version after the second import...

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Mon, 2011-01-10 16:26

Hmm, is it possibly because there's no WHERE clause on the UPDATE? Seems all my hash values are the same!

Cheers.
Keeop

Submitted by support on Mon, 2011-01-10 16:32

Yes - that will be it!

In place of:

$sql = "UPDATE `".$config_databaseTablePrefix."feeds` SET change_hash='".$change_hash."'";

...use:

$sql = "UPDATE `".$config_databaseTablePrefix."feeds` SET change_hash='".$change_hash."' WHERE filename='".database_safe($admin_importFeed["filename"])."'";

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Mon, 2011-01-10 16:36

Yep, sorted!

Cheers.
Keeop

Submitted by Convergence on Sun, 2013-04-07 19:49

v12/10B heavily modified

Greetings,

Looking for an email alert that will be sent when a merchant's feed does NOT import.
Example: when a merchant changes one of their fields in a filter that has been setup. Occasionally we get merchants that change their category structure and no products get imported. Therefore, an email alert notifying us that no products were imported for that merchant would be great.

Better yet, an email alert where we could setup a +/- 20% or whatever percentage we want would be nice.

Thanks!

Submitted by support on Mon, 2013-04-08 07:26

Hi,

This could be tied into the admin_import() function quite easily, where after an import has completed (and the SQL to get the new product count has been executed) the new product count is in the $productCount variable, and the old product count is in $admin_importFeed["products"], so a delta of +/- 20% can be checked for and an email alert sent if the import count has changed significantly.

To try this, look for the return statement at the end of that function at around line 525 of includes/admin.php:

    return "";

...and REPLACE with:

    $delta = intval(($admin_importFeed["products"]/100)*20);
    $deltaMin = $admin_importFeed["products"] - $delta;
    $deltaMax = $admin_importFeed["products"] + $delta;
    if (($productCount < $deltaMin) || ($productCount > $deltaMax))
    {
      mail(
        "you@example.com",
        "Import Delta Alert",
        "
        Feed: ".$admin_importFeed["filename"]."\n
        Previous Product Count: ".$admin_importFeed["products"]."\n
        New Product Count: ".$productCount."\n
        ");
    }
    return "";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Mon, 2013-04-08 14:03

Hi David,

Thanks!

Will email you our /includes/admin.php as it has been modified (we have a return ""; on line 61 and the next one is on line 618.

Just to be sure... :)

Submitted by Convergence on Mon, 2013-04-08 15:01

Hi David,

Thanks for the quick email response!

Submitted by Convergence on Sun, 2013-06-30 08:37

Hi David,

We had a merchant yesterday where their feed was 100% "jacked up". Not a single product imported. We did not receive an email alert.

Question: Does there need to be a change in the above code to account for ZERO products being imported versus just a difference of 20%?

Thanks!

Submitted by support on Mon, 2013-07-01 07:55

It might be best (due to rounding) to add a special case for zero - in place of this line:

     if (($productCount < $deltaMin) || ($productCount > $deltaMax))

...use:

     if (!$productCount || (($productCount < $deltaMin) || ($productCount > $deltaMax)))

Cheers,
David.
--
PriceTapestry.com