Hello
Does any one know of an easy way to produce an error report during the import process? I envisage something like:
Record: "string of relevant field details" Error Message
e.g.
Record: "string of relevant field details" Duplicate key
Record: "string of relevant field details" No price
Record: "string of relevant field details" No price
Record: "string of relevant field details" Duplicate key
Record: "string of relevant field details" No price
Record: "string of relevant field details" No brand
Records in 99999
Records dropped 99999
Records added 99999
Has anyone amended their includes/admin file to do anything like this? Thanks
Thank you David, I'll certainly give this a go.
Kind regards
Alastair
www.findawillonline.com - Find a Will Online in Our Worldwide Will Registry
I tried it and got the following error:
Warning: fopen(/ptadmin/import.log) [function.fopen]: failed to open stream: No such file or directory in /hermes/bosweb/web229/b2298/d5.amillsmcewan/public_html/includes/tapestry.php on line 66
I used notepad to create a .txt file called "import.log: and uploaded it to my admin directory, "ptadmin" so I'm not quite sure what I've done wrong
Kind regards
Alastair
www.findawillonline.com - Find a Will Online in Our Worldwide Will Registry
Hi Alastair,
2 things; firstly, the value of $tapestry_logFilename must be the full server path to the log file - which conveniently can be seen in the error message. Secondly, the directory must also be writeable by PHP. I would create a separate folder called "log" (in the main Price Tapestry directory), and then make it writable. The easiest way to do this is normally with your FTP program (which you can probably also use to create the directory). After making the new folder, right-click on the folder name in the remote window and look for a "Permissions..." or "Properties..." and then permissions. From there, you should be able to grant write access to all users. There's no danger in doing this; it doesn't give write access over the web in any way.
Then, set the value in the code as follows:
$tapestry_logFilename = "/hermes/bosweb/web229/b2298/d5.amillsmcewan/public_html/log/tapestry.log";
...and it should do the trick! You don't need to create the file first, it will be created the first time is it used.
Cheers,
David.
Thanks David
I done this now and it no longer has a PHP error (but neither is it logging any errors ). I'll check my test data and report back
I still can;t get it to write to the log. I replaced the write to the log with an echo statement and it seemed fine, reporting the two invalid records in my feed. The code is
(in tapestry)
function tapestry_log($text)
{
echo ($text) ;
global $tapestry_logFP;
$tapestry_logFilename = "/hermes/bosweb/web229/b2298/d5.amillsmcewan/public_html/importlog/import.log"; // must be writable by PHP!!
if (!$tapestry_logFP)
{
// open log file for append access if not already open
$tapestry_logFP = fopen($tapestry_logFilename,"a");
}
if ($tapestry_logFP)
{
fwrite($tapestry_logFP,$text."\n");
}
}
and in admin:
/* check member record for minimum required fields */
if (!$record[$admin_importFeed["field_UserName"]] ||
!$record[$admin_importFeed["field_Password"]] ||
!$record[$admin_importFeed["field_Email"]] ||
!$record[$admin_importFeed["field_FirstName"]] ||
!$record[$admin_importFeed["field_LastName"]] ||
!$record[$admin_importFeed["field_Sex"]] ||
!$record[$admin_importFeed["field_DateOfBirth"]] ||
!$record[$admin_importFeed["field_BirthCountry"]] ||
!$record[$admin_importFeed["field_BirthNationality"]] ||
!$record[$admin_importFeed["field_AddressStreet"]] ||
!$record[$admin_importFeed["field_AddressCity"]] ||
!$record[$admin_importFeed["field_AddressState"]] ||
!$record[$admin_importFeed["field_AddressZip"]] ||
!$record[$admin_importFeed["field_AddressCountry"]] ||
!$record[$admin_importFeed["field_WillLocation"]]
)
{
tapestry_log("Dropped - Missing Fields " . "|"
.$filename . "|"
.$Agent . "|"
.$record[$admin_importFeed["field_UserName"]] . "|"
.$record[$admin_importFeed["field_Email"]] . "|"
.$record[$admin_importFeed["field_FirstName"]] . "|"
.$record[$admin_importFeed["field_LastName"]] . "|"
.$record[$admin_importFeed["field_Sex"]] . "|"
.$record[$admin_importFeed["field_DateOfBirth"]] . "|"
.$record[$admin_importFeed["field_BirthCountry"]] . "|"
.$record[$admin_importFeed["field_BirthNationality"]] . "|"
.$record[$admin_importFeed["field_AddressStreet"]] . "|"
.$record[$admin_importFeed["field_AddressCity"]] . "|"
.$record[$admin_importFeed["field_AddressState"]] . "|"
.$record[$admin_importFeed["field_AddressZip"]] . "|"
.$record[$admin_importFeed["field_AddressCountry"]] . "|"
.$record[$admin_importFeed["field_WillLocation"]]
);
return;
}
I did wonder whether I have got the text string in the call to the function correct? Do I need some sort of a closing quote ?(though the last field in the concatenation is a text field)
Many thanks
Hi Alastair,
The code looks fine - no need for a closing quote or anything.
Does the log file get created? Try deleting any file that exists and then running import again and seeing if the script has been able to create the file. If not, this would indicate that PHP is not able to write to that directory; so double-check the permissions.
You could also write a quite test script to save you having to run an import each time; and to help isolate the problem (run this in the main Price Tapestry folder):
test.php
<?php
require("includes/common.php");
tapestry_log("Testing");
?>
Hope this helps!
Cheers,
David.
It helped thank you. Have to admit I'm not quite sure what was going wrong but it's fine now! Many thanks for the great support
Alastair
Hi David,
Is it possible to get the feed filename and merchant name into this log? How would I do that?
Many thanks!
Hi Chani,
Sure - the feed filename and merchant name are in these variables:
$admin_importFeed["filename"]
$admin_importFeed["merchant"]
You can use these variables in your call to the tapestry_log() function just as the product record variables are being used. If you're not sure how to incorporate this in to your code, if your could post your existing code where you call tapestry_log(....) i'll show you what changes to make...
Cheers,
David.
Hi David,
Wow, that was a quick reply! :)
I tried those two but they wouldn't work! Line is as follows:
<?php
>tapestry_log("Dropped - Missing Fields | ".$record[$admin_importFeed["field_sku"]]." | ".$adminImportFeed["filename"]."\n\n");<
?>
It displays field_sku, but not the filename (or merchant, when it's there).
In case it's relevant, I've also got the 'number of errors' mod in the script, which works fine:
http://www.pricetapestry.com/node/188
Yes, I'm coming back to this after a long break :)
Hi,
Based on the above, it should just be:
tapestry_log("Dropped - Missing Fields | ".$record[$admin_importFeed["field_sku"]]." | ".$admin_importFeed["filename"]." | ".$admin_importFeed["merchant"]."\n\n");
If that's not doing the trick, if you could email me your modified includes/admin.php i'll check it out for you..!
Cheers,
David.
Hi Alastair,
It's quite easy to create a simple logging function. I would add it to the includes/tapestry.php file as follows:
function tapestry_log($text)
{
global $tapestry_logFP;
$tapestry_logFilename = "/path/to/tapestry.log"; // must be writable by PHP!!
if (!$tapestry_logFP)
{
// open log file for append access if not already open
$tapestry_logFP = fopen($tapestry_logFilename,"a");
}
if ($tapestry_logFP)
{
fwrite($tapestry_logFP,$text."\n");
}
}
Now, with that in place, you can call tapestry_log("Text") from anywhere in the script. For example, to log that a record was dropped because not all the required fields were present, look for the following code beginning at line 155 of includes/admin.php:
/* check product record for minimum required fields */
if (!$record[$admin_importFeed["field_name"]] || !$record[$admin_importFeed["field_buy_url"]] || !$record[$admin_importFeed["field_price"]]) return;
...and replace this with:
/* check product record for minimum required fields */
if (!$record[$admin_importFeed["field_name"]] || !$record[$admin_importFeed["field_buy_url"]] || !$record[$admin_importFeed["field_price"]])
{
if (!$record[$admin_importFeed["field_name"]]) tapestry_log("Record dropped - No Product Name");
if (!$record[$admin_importFeed["field_buy_url"]]) tapestry_log("Record dropped - No Buy URL");
if (!$record[$admin_importFeed["field_price"]]) tapestry_log("Record dropped - No Price");
return;
}
Other types of logging could be added with a little more code and a few global variables - let me know what you want to add if you need more assistance with the code...
Cheers,
David.