No, it is much simpler than that.
Your analogy is wrong - it is like opening a zip with a text editor, the editor allowing you to open the file, and edit it...... without throwing an error !
If a decision process runs and does not complete correctly for whatever reason then an error should be thrown advising the user. The assumption is the user is dumb (that's me !) and everything you can do to stop them making stupid errors should be encouraged - hence a million different error checks throughout Zencart.
In this instance the filename was incorrect which caused the program to carry on and report that everything was OK when clearly it wasn't.... (the data was right - just the filename being wrong)
That cost me a day of running around based on information reported by the process that was clearly wrong. It said it worked, when clearly it had not. That isn't right.
I'm not trying to be negative - I'd just like to see the code improved to the benefit of all as it is an indispensable tool for Zencart.
Here's a patch to check the filenames and log an error - it may not be perfect but it is about there - also miles quicker than running through all the code for a simple failure :-)
You can see my comment line - sometimes it checks for the filename, others it does a anything else check with <>
Either way, if the name is checked at the start then it gives a fast response to the problem. If you have new sections / filenames then just add the name to the array. Using stristr would give you more flexibility as per my note, but I have left as is for now.
It's also dead simple.....
--- easypopulate_4_import-orig.php 2015-06-18 11:18:05.000000000 +0200
+++ easypopulate_4_import.php 2015-06-18 14:00:21.000000000 +0200
@@ -8,6 +8,37 @@
$file = array('name' => $_GET['import']);
$display_output .= sprintf(EASYPOPULATE_4_DISPLAY_LOCAL_FILE_SPEC, $file['name']);
+
+
+
+/*
+ * These are the filenames that we look for
+ *
+strtolower(substr($file['name'],0,11)) == "featured-ep")
+strtolower(substr($file['name'],0,15)) == "attrib-basic-ep"
+strtolower(substr($file['name'],0,18)) == "attrib-detailed-ep")
+strtolower(substr($file['name'],0,15)) == "sba-detailed-ep")
+strtolower(substr($file['name'],0,12)) == "sba-stock-ep")
+strtolower(substr($file['name'],0,15)) <> "categorymeta-ep")
+strtolower(substr($file['name'],0,7)) <> "attrib-")
+strtolower(substr($file['name'],0,4)) <> "sba-")
+strtolower(substr($file['name'],0,14)) == "pricebreaks-ep")
+*/
+
+
+$fileNameArray = array ("featured-ep", "attrib-basic-ep", "attrib-detailed-ep", "sba-detailed-ep", "categorymeta-ep", "attrib-", "sba-", "pricebreaks-ep");
+$discoveredFile = false;
+
+foreach ($fileNameArray as $key) {
+
+ $length = strlen ($key);
+ // probably better to do stristr but all the lines then need changing further down
+ if (strtolower(substr($file['name'],0,$length)) == $key) {
+ $discoveredFile = true;
+ }
+}
+
+if ($discoveredFile == true) { // we'll proceed
$ep_update_count = 0; // product records updated
$ep_import_count = 0; // new products records imported
@@ -1637,5 +1668,17 @@
} else {
$messageStack->add("File Import Completed.", 'success');
}
+}
+else {
+ $display_output .= '<h3>Finished Processing Import File</h3>';
+ $display_output .= '<br /><h3 style="color:red">Filename is wrong</h3> ';
+ $display_output .= '<br />Please check that the filename <b>starts</b> with the correct term';
+ $display_output .= '<br />The following are the permissible names :';
+ foreach ($fileNameArray as $key) {
+ $display_output .= "<br />" . $key;
+ }
+ $messageStack->add("File Import Failed.", 'error');
+
+} // End file check loop
} // END FILE UPLOADS
-?>
\ No newline at end of file
+?>
And a small patch to easypopulate.php itself to clear a small warning that was annoying me :-)
--- easypopulate_4-orig.php 2015-06-17 19:03:42.000000000 +0200
+++ easypopulate_4.php 2015-06-18 14:47:28.000000000 +0200
@@ -28,9 +28,9 @@
$ep_music = (int)EASYPOPULATE_4_CONFIG_MUSIC_DATA; // 0-Disable, 1-Enable
$ep_uses_mysqli = (PROJECT_VERSION_MAJOR > '1' || PROJECT_VERSION_MINOR >= '5.3' ? true : false--- easypopulate_4-orig.php 2015-06-17 19:03:42.000000000 +0200
+++ easypopulate_4.php 2015-06-18 14:14:01.000000000 +0200
@@ -30,7 +30,7 @@
@set_time_limit($ep_execution); // executin limit in seconds. 300 = 5 minutes before timeout, 0 means no timelimit
-if (!$error) {
+if (!isset($error)) {
$upload_max_filesize=ini_get("upload_max_filesize");
if (preg_match("/([0-9]+)K/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024;
if (preg_match("/([0-9]+)M/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024;);
-@set_time_limit($ep_execution); // executin limit in seconds. 300 = 5 minutes before timeout, 0 means no timelimit
+@set_time_limit($ep_execution); // execution limit in seconds. 300 = 5 minutes before timeout, 0 means no timelimit
-if (!$error) {
+if (!isset($error)) {
$upload_max_filesize=ini_get("upload_max_filesize");
if (preg_match("/([0-9]+)K/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024;
if (preg_match("/([0-9]+)M/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024;
I'd have a go on github but not very experienced with it.... and I am not sure which repo to follow - is chaddro still working on this ?
B. Rgds
John
Bookmarks