From 68a922085dc15a54bc7dd66b0a93d2da54c08477 Mon Sep 17 00:00:00 2001 From: Michael Mussulis Date: Fri, 25 Aug 2023 13:52:50 -0400 Subject: [PATCH 1/5] Fixes for M2 --- magmi/engines/magmi_productimportengine.php | 7 ++- magmi/inc/fshelper.php | 2 + magmi/inc/magmi_config.php | 2 +- magmi/inc/remotefilegetter.php | 15 ++++++ .../base/general/reindex/options_panel.php | 4 +- .../imageitattributeemprocessor.php | 29 ++++++++++- magmi/plugins/inc/magmi_plugin.php | 2 +- .../clearcustomers/clearcustomers.php | 4 +- .../utilities/clearproducts/clearproduct.php | 49 +++++++++++++------ magmi/web/magmi_web_utils.php | 4 +- magmi/web/progress_parser.php | 4 +- 11 files changed, 95 insertions(+), 27 deletions(-) diff --git a/magmi/engines/magmi_productimportengine.php b/magmi/engines/magmi_productimportengine.php index 510912bf..e9b3221f 100755 --- a/magmi/engines/magmi_productimportengine.php +++ b/magmi/engines/magmi_productimportengine.php @@ -419,8 +419,11 @@ public function getMode() */ public function addExtraAttribute($attr) { - $attinfo = $this->attrinfo[$attr]; - $this->_extra_attrs[$attinfo["backend_type"]]["data"][] = $attinfo; + if(isset($this->attrinfo[$attr])) + { + $attinfo = $this->attrinfo[$attr]; + $this->_extra_attrs[$attinfo["backend_type"]]["data"][] = $attinfo; + } } /** diff --git a/magmi/inc/fshelper.php b/magmi/inc/fshelper.php index 5a487a29..7e8ff908 100755 --- a/magmi/inc/fshelper.php +++ b/magmi/inc/fshelper.php @@ -371,6 +371,7 @@ public function unlink($path) */ public function copyFromRemote($remoteurl, $destpath) { + error_log("copyFromRemote()" . __LINE__); $rfg = RemoteFileGetterFactory::getFGInstance($this->_rfgid); $mp = str_replace("//", "/", $this->_magdir . "/" . str_replace($this->_magdir, '', $destpath)); $ok = $rfg->copyRemoteFile($remoteurl, $mp); @@ -387,6 +388,7 @@ public function copyFromRemote($remoteurl, $destpath) */ public function copy($srcpath, $destpath) { + error_log("copy() " . __LINE__); $result = false; $destpath = str_replace("//", "/", $this->_magdir . "/" . str_replace($this->_magdir, '', $destpath)); if (preg_match('|^.*?://.*$|', $srcpath)) { diff --git a/magmi/inc/magmi_config.php b/magmi/inc/magmi_config.php index 844a19e8..b2672942 100755 --- a/magmi/inc/magmi_config.php +++ b/magmi/inc/magmi_config.php @@ -63,7 +63,7 @@ public function getLastSaved($fmt = "r") public function load($name = null) { - if (!isset($this->_props)) { + if (!isset($this->_props) || empty($this->_props)) { if ($name == null) { $name = $this->inifile; } diff --git a/magmi/inc/remotefilegetter.php b/magmi/inc/remotefilegetter.php index 066674b0..a463d090 100644 --- a/magmi/inc/remotefilegetter.php +++ b/magmi/inc/remotefilegetter.php @@ -239,6 +239,7 @@ public function setCookie($cookie = null) public function copyRemoteFile($url, $dest) { + error_log("copyRemoteFile()" . __LINE__); $result = false; $this->_errors = array(); try { @@ -259,9 +260,12 @@ public function setURLOptions($url, &$optab) public function getRemoteFile($url, $dest, $authmode = null, $cookies = null) { + error_log("getRemoteFile()" . __LINE__); $context = $this->createContext($url); $ch = $context['curlhandle']; $dl_opts = $context['opts']['dl']; + + $dest = str_replace("pub/pub", "pub", $dest); $outname = $dest; if ($cookies) { @@ -270,20 +274,25 @@ public function getRemoteFile($url, $dest, $authmode = null, $cookies = null) } } + error_log("getRemoteFile()" . $outname); + $fp = fopen($outname, "w"); if ($fp == false) { $this->destroyContext($context); + error_log("Cannot write file:$outname"); throw new Exception("Cannot write file:$outname"); } $dl_opts[CURLOPT_FILE] = $fp; $this->setURLOptions($url, $dl_opts); $this->setAuthOptions($context, $dl_opts); + error_log("getRemoteFile()" . __LINE__); // Download the file , force expect to nothing to avoid buffer save problem curl_setopt_array($ch, $dl_opts); $inf = curl_getinfo($ch); if (!curl_exec($ch)) { + error_log("getRemoteFile()" . __LINE__); if (curl_error($ch) != "") { $err = "Cannot fetch $url :" . curl_error($ch); } else { @@ -292,19 +301,25 @@ public function getRemoteFile($url, $dest, $authmode = null, $cookies = null) $this->destroyContext($context); fclose($fp); unlink($dest); + error_log($err); throw new Exception($err); } else { + error_log("getRemoteFile()" . __LINE__); $proto = $context['scheme']; if ($proto == 'http' || $proto == 'https') { + error_log("getRemoteFile()" . __LINE__); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $ok = ($httpCode < 400); if (!$ok) { fclose($fp); @unlink($outname); + error_log('Cannot fetch URL :'.$url); throw new Exception('Cannot fetch URL :'.$url); } + error_log("getRemoteFile() httpCode " . $httpCode); } } + error_log("getRemoteFile()" . __LINE__); fclose($fp); $this->destroyContext($context); diff --git a/magmi/plugins/base/general/reindex/options_panel.php b/magmi/plugins/base/general/reindex/options_panel.php index c424c0fd..5138db85 100644 --- a/magmi/plugins/base/general/reindex/options_panel.php +++ b/magmi/plugins/base/general/reindex/options_panel.php @@ -17,8 +17,8 @@ href="#REINDEX:config" onclick="fcheck(0)">None \ No newline at end of file + diff --git a/magmi/plugins/extra/itemprocessors/imageprocessor/imageitattributeemprocessor.php b/magmi/plugins/extra/itemprocessors/imageprocessor/imageitattributeemprocessor.php index 433e9daa..09d7e664 100644 --- a/magmi/plugins/extra/itemprocessors/imageprocessor/imageitattributeemprocessor.php +++ b/magmi/plugins/extra/itemprocessors/imageprocessor/imageitattributeemprocessor.php @@ -23,6 +23,7 @@ public function initialize($params) $this->magdir = Magmi_Config::getInstance()->getMagentoDir(); $this->_mdh = MagentoDirHandlerFactory::getInstance()->getHandler($this->magdir); $this->_mdh->setRemoteGetterId("image"); + error_log("mdh: " . get_class($this->_mdh)); // remote root if ($this->getParam("IMG:remoteroot", "")) { @@ -439,12 +440,15 @@ public function saveImage($imgfile, $target) */ public function copyImageFile($imgfile, &$item, $extra) { + error_log("in copyImageFile"); if ($imgfile == "__NULL__" || $imgfile == null) { + error_log("$imgfile is null"); return false; } // check for source image in error if ($this->isErrorImage($imgfile)) { + error_log("Error $imgfile"); if ($this->_newitem) { $this->fillErrorAttributes($item); }; @@ -453,12 +457,14 @@ public function copyImageFile($imgfile, &$item, $extra) //handle remote root per image if (!is_remote_path($imgfile)) { + error_log("! is_remote_path $imgfile"); if ($this->_remoteroot != "") { $imgfile = $this->_remoteroot . str_replace("//", "/", "/$imgfile"); } } //handle amazon specific if (is_remote_path($imgfile)) { + error_log("is_remote_path $imgfile"); // Amazon images patch , remove SLXXXX part if (preg_match('|amazon\..*?/images/I|', $imgfile)) { $pattern = '/\bSL[0-9]+\./i'; @@ -468,6 +474,7 @@ public function copyImageFile($imgfile, &$item, $extra) $source = $this->findImageFile($imgfile); if ($source == false) { + error_log("$imgfile not found"); $this->log("$imgfile cannot be found in images path", "warning"); // last image in error,add it to error cache $this->setErrorImg($imgfile); @@ -484,30 +491,36 @@ public function copyImageFile($imgfile, &$item, $extra) $impath = "/$i1/$i2/$bimgfile"; // target directory; - if(!strstr(getcwd(), "pub")) { + error_log("current cwd: " . getcwd()); + if(!strstr(getcwd(), "pub")) $l2d = "pub/media/catalog/product/$i1/$i2"; - } - else { + else $l2d = "media/catalog/product/$i1/$i2"; - } - // test for existence $targetpath = "$l2d/$bimgfile"; + error_log("l2d " . $l2d); + error_log("targetpath " . $targetpath); /* test for same image (without problem) */ if ($impath == $this->_lastimage) { return $impath; } + error_log("mdh->file_exists() " . $this->_mdh->file_exists($targetpath)); + error_log("writemode " . $this->getParam("IMG:writemode")); + /* test if imagefile comes from export */ if (!$this->_mdh->file_exists($targetpath) || $this->getParam("IMG:writemode") == "override") { + error_log("file not exists || writemode is override"); // if we already had problems with this target,assume we'll get others. if ($this->isErrorImage($impath)) { + error_log("isError"); return false; } /* try to recursively create target dir */ if (!$this->_mdh->file_exists($l2d)) { + error_log("creating target dir"); $tst = $this->_mdh->mkdir($l2d, Magmi_Config::getInstance()->getDirMask(), true); if (!$tst) { // if we had problem creating target directory,add target to error cache @@ -520,6 +533,7 @@ public function copyImageFile($imgfile, &$item, $extra) } if (!$this->saveImage($imgfile, $targetpath)) { + error_log("saving image"); $errors = $this->_mdh->getLastError(); $this->fillErrorAttributes($item); $this->log("error copying $l2d/$bimgfile : {$errors["type"]},{$errors["message"]}", "warning"); @@ -527,9 +541,11 @@ public function copyImageFile($imgfile, &$item, $extra) $this->setErrorImg($impath); return false; } else { + error_log("save image failed"); @$this->_mdh->chmod("$l2d/$bimgfile", Magmi_Config::getInstance()->getFileMask()); if ($this->getParam("IMG:storeindb", "no") == "yes") { + error_log("store in DB"); /* create target dirs if they don't exist */ $dir_table = $this->tablename('core_directory_storage'); // get "catalog/product" path ID @@ -575,6 +591,7 @@ public function copyImageFile($imgfile, &$item, $extra) } $this->_lastimage = $impath; /* return image file name relative to media dir (with leading / ) */ + error_log("returning " . $impath); return $impath; } diff --git a/magmi/plugins/extra/itemprocessors/itemindexer/options_panel.php b/magmi/plugins/extra/itemprocessors/itemindexer/options_panel.php index 7adad2ff..62ab63df 100644 --- a/magmi/plugins/extra/itemprocessors/itemindexer/options_panel.php +++ b/magmi/plugins/extra/itemprocessors/itemindexer/options_panel.php @@ -27,4 +27,4 @@ - \ No newline at end of file + diff --git a/magmi/plugins/utilities/clearproducts/clearproduct.php b/magmi/plugins/utilities/clearproducts/clearproduct.php index a04a322a..428707b5 100644 --- a/magmi/plugins/utilities/clearproducts/clearproduct.php +++ b/magmi/plugins/utilities/clearproducts/clearproduct.php @@ -58,6 +58,7 @@ public function runUtility() } //clean url rewrites for products + //$sql = "DELETE FROM ".$this->tablename("core_url_rewrite")." WHERE product_id IS NOT NULL AND is_system=1"; $sql = "DELETE FROM ".$this->tablename("url_rewrite")." WHERE entity_id IS NOT NULL AND is_autogenerated=1"; $this->delete($sql); diff --git a/magmi/plugins/utilities/massopt_translate/csvds_filelist.php b/magmi/plugins/utilities/massopt_translate/csvds_filelist.php index f6638167..779cf06c 100755 --- a/magmi/plugins/utilities/massopt_translate/csvds_filelist.php +++ b/magmi/plugins/utilities/massopt_translate/csvds_filelist.php @@ -18,4 +18,4 @@ ?> No csv files found in getScanDir(false)?> \ No newline at end of file + }?> diff --git a/magmi/web/magmi_progress.php b/magmi/web/magmi_progress.php index 716e7880..7f6affd5 100755 --- a/magmi/web/magmi_progress.php +++ b/magmi/web/magmi_progress.php @@ -184,4 +184,4 @@ class='log_end getData("error")) > 0) { - \ No newline at end of file + diff --git a/magmi/web/progress_details.php b/magmi/web/progress_details.php index ee3d7138..4a46c72c 100644 --- a/magmi/web/progress_details.php +++ b/magmi/web/progress_details.php @@ -51,4 +51,4 @@ } } ?> - \ No newline at end of file + From 8056e447191b6519649846e6c552cd5e57c94ec2 Mon Sep 17 00:00:00 2001 From: Michael Mussulis Date: Fri, 8 Sep 2023 08:36:08 -0400 Subject: [PATCH 5/5] Removed more error_log() debug statements --- magmi/inc/fshelper.php | 2 -- .../attributesetimport/name2id_decoding.php | 1 - .../imageitattributeemprocessor.php | 22 +------------------ 3 files changed, 1 insertion(+), 24 deletions(-) diff --git a/magmi/inc/fshelper.php b/magmi/inc/fshelper.php index 7e8ff908..5a487a29 100755 --- a/magmi/inc/fshelper.php +++ b/magmi/inc/fshelper.php @@ -371,7 +371,6 @@ public function unlink($path) */ public function copyFromRemote($remoteurl, $destpath) { - error_log("copyFromRemote()" . __LINE__); $rfg = RemoteFileGetterFactory::getFGInstance($this->_rfgid); $mp = str_replace("//", "/", $this->_magdir . "/" . str_replace($this->_magdir, '', $destpath)); $ok = $rfg->copyRemoteFile($remoteurl, $mp); @@ -388,7 +387,6 @@ public function copyFromRemote($remoteurl, $destpath) */ public function copy($srcpath, $destpath) { - error_log("copy() " . __LINE__); $result = false; $destpath = str_replace("//", "/", $this->_magdir . "/" . str_replace($this->_magdir, '', $destpath)); if (preg_match('|^.*?://.*$|', $srcpath)) { diff --git a/magmi/plugins/5b5/general/attributesetimport/name2id_decoding.php b/magmi/plugins/5b5/general/attributesetimport/name2id_decoding.php index 382829b2..a474ce4c 100644 --- a/magmi/plugins/5b5/general/attributesetimport/name2id_decoding.php +++ b/magmi/plugins/5b5/general/attributesetimport/name2id_decoding.php @@ -83,7 +83,6 @@ public function decode($record) $indexedResult[] = $mappingTable[$values]; } else { $indexedResult[] = $record[$columnName]; - error_log("Mapped value not found for column $columnName for name(s): ".print_r($values, true)); } } } diff --git a/magmi/plugins/extra/itemprocessors/imageprocessor/imageitattributeemprocessor.php b/magmi/plugins/extra/itemprocessors/imageprocessor/imageitattributeemprocessor.php index 09d7e664..45ce0272 100644 --- a/magmi/plugins/extra/itemprocessors/imageprocessor/imageitattributeemprocessor.php +++ b/magmi/plugins/extra/itemprocessors/imageprocessor/imageitattributeemprocessor.php @@ -23,7 +23,6 @@ public function initialize($params) $this->magdir = Magmi_Config::getInstance()->getMagentoDir(); $this->_mdh = MagentoDirHandlerFactory::getInstance()->getHandler($this->magdir); $this->_mdh->setRemoteGetterId("image"); - error_log("mdh: " . get_class($this->_mdh)); // remote root if ($this->getParam("IMG:remoteroot", "")) { @@ -440,15 +439,12 @@ public function saveImage($imgfile, $target) */ public function copyImageFile($imgfile, &$item, $extra) { - error_log("in copyImageFile"); if ($imgfile == "__NULL__" || $imgfile == null) { - error_log("$imgfile is null"); return false; } // check for source image in error if ($this->isErrorImage($imgfile)) { - error_log("Error $imgfile"); if ($this->_newitem) { $this->fillErrorAttributes($item); }; @@ -457,14 +453,12 @@ public function copyImageFile($imgfile, &$item, $extra) //handle remote root per image if (!is_remote_path($imgfile)) { - error_log("! is_remote_path $imgfile"); if ($this->_remoteroot != "") { $imgfile = $this->_remoteroot . str_replace("//", "/", "/$imgfile"); } } //handle amazon specific if (is_remote_path($imgfile)) { - error_log("is_remote_path $imgfile"); // Amazon images patch , remove SLXXXX part if (preg_match('|amazon\..*?/images/I|', $imgfile)) { $pattern = '/\bSL[0-9]+\./i'; @@ -474,7 +468,6 @@ public function copyImageFile($imgfile, &$item, $extra) $source = $this->findImageFile($imgfile); if ($source == false) { - error_log("$imgfile not found"); $this->log("$imgfile cannot be found in images path", "warning"); // last image in error,add it to error cache $this->setErrorImg($imgfile); @@ -491,36 +484,27 @@ public function copyImageFile($imgfile, &$item, $extra) $impath = "/$i1/$i2/$bimgfile"; // target directory; - error_log("current cwd: " . getcwd()); if(!strstr(getcwd(), "pub")) $l2d = "pub/media/catalog/product/$i1/$i2"; else $l2d = "media/catalog/product/$i1/$i2"; // test for existence $targetpath = "$l2d/$bimgfile"; - error_log("l2d " . $l2d); - error_log("targetpath " . $targetpath); /* test for same image (without problem) */ if ($impath == $this->_lastimage) { return $impath; } - - error_log("mdh->file_exists() " . $this->_mdh->file_exists($targetpath)); - error_log("writemode " . $this->getParam("IMG:writemode")); - + /* test if imagefile comes from export */ if (!$this->_mdh->file_exists($targetpath) || $this->getParam("IMG:writemode") == "override") { - error_log("file not exists || writemode is override"); // if we already had problems with this target,assume we'll get others. if ($this->isErrorImage($impath)) { - error_log("isError"); return false; } /* try to recursively create target dir */ if (!$this->_mdh->file_exists($l2d)) { - error_log("creating target dir"); $tst = $this->_mdh->mkdir($l2d, Magmi_Config::getInstance()->getDirMask(), true); if (!$tst) { // if we had problem creating target directory,add target to error cache @@ -533,7 +517,6 @@ public function copyImageFile($imgfile, &$item, $extra) } if (!$this->saveImage($imgfile, $targetpath)) { - error_log("saving image"); $errors = $this->_mdh->getLastError(); $this->fillErrorAttributes($item); $this->log("error copying $l2d/$bimgfile : {$errors["type"]},{$errors["message"]}", "warning"); @@ -541,11 +524,9 @@ public function copyImageFile($imgfile, &$item, $extra) $this->setErrorImg($impath); return false; } else { - error_log("save image failed"); @$this->_mdh->chmod("$l2d/$bimgfile", Magmi_Config::getInstance()->getFileMask()); if ($this->getParam("IMG:storeindb", "no") == "yes") { - error_log("store in DB"); /* create target dirs if they don't exist */ $dir_table = $this->tablename('core_directory_storage'); // get "catalog/product" path ID @@ -591,7 +572,6 @@ public function copyImageFile($imgfile, &$item, $extra) } $this->_lastimage = $impath; /* return image file name relative to media dir (with leading / ) */ - error_log("returning " . $impath); return $impath; }