2016-04-26 13 views
1

Ich erhalte einen fatalen PHP-Fehler in einem Cron-Skript, das für Commission Junction verwendet wird. Es scheint in der error_log es hält mitMagento-Cron-Skript "Aufruf zu undefinierter Methode"

PHP Fatal error: Call to undefined method Mage_Core_Helper_Data::getEscapedCSVData() in /home/lovescen/public_html/app/code/core/Mage/Dataflow/Model/Convert/Parser/Csv.php on line 269 

Der Code auf der Leitung 269 wird $escapedValue = Mage::helper("core")->getEscapedCSVData(array($value));

Und hier ist der gesamte Code in Csv.php aktualisieren.

<?php 
 
    /** 
 
    * Magento 
 
    * 
 
    * NOTICE OF LICENSE 
 
    * 
 
    * This source file is subject to the Open Software License (OSL 3.0) 
 
    * that is bundled with this package in the file LICENSE.txt. 
 
    * It is also available through the world-wide-web at this URL: 
 
    * http://opensource.org/licenses/osl-3.0.php 
 
    * If you did not receive a copy of the license and are unable to 
 
    * obtain it through the world-wide-web, please send an email 
 
    * to [email protected] so we can send you a copy immediately. 
 
    * 
 
    * DISCLAIMER 
 
    * 
 
    * Do not edit or add to this file if you wish to upgrade Magento to newer 
 
    * versions in the future. If you wish to customize Magento for your 
 
    * needs please refer to http://www.magento.com for more information. 
 
    * 
 
    * @category Mage 
 
    * @package  Mage_Dataflow 
 
    * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com) 
 
    * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 
 
    */ 
 

 

 
    /** 
 
    * Convert csv parser 
 
    * 
 
    * @category Mage 
 
    * @package Mage_Dataflow 
 
    * @author  Magento Core Team <[email protected]> 
 
    */ 
 
    class Mage_Dataflow_Model_Convert_Parser_Csv extends Mage_Dataflow_Model_Convert_Parser_Abstract 
 
    { 
 
     protected $_fields; 
 

 
     protected $_mapfields = array(); 
 

 
     public function parse() 
 
     { 
 
      // fixed for multibyte characters 
 
      setlocale(LC_ALL, Mage::app()->getLocale()->getLocaleCode().'.UTF-8'); 
 

 
      $fDel = $this->getVar('delimiter', ','); 
 
      $fEnc = $this->getVar('enclose', '"'); 
 
      if ($fDel == '\t') { 
 
       $fDel = "\t"; 
 
      } 
 

 
      $adapterName = $this->getVar('adapter', null); 
 
      $adapterMethod = $this->getVar('method', 'saveRow'); 
 

 
      if (!$adapterName || !$adapterMethod) { 
 
       $message = Mage::helper('dataflow')->__('Please declare "adapter" and "method" nodes first.'); 
 
       $this->addException($message, Mage_Dataflow_Model_Convert_Exception::FATAL); 
 
       return $this; 
 
      } 
 

 
      try { 
 
       $adapter = Mage::getModel($adapterName); 
 
      } 
 
      catch (Exception $e) { 
 
       $message = Mage::helper('dataflow')->__('Declared adapter %s was not found.', $adapterName); 
 
       $this->addException($message, Mage_Dataflow_Model_Convert_Exception::FATAL); 
 
       return $this; 
 
      } 
 

 
      if (!method_exists($adapter, $adapterMethod)) { 
 
       $message = Mage::helper('dataflow')->__('Method "%s" not defined in adapter %s.', $adapterMethod, $adapterName); 
 
       $this->addException($message, Mage_Dataflow_Model_Convert_Exception::FATAL); 
 
       return $this; 
 
      } 
 

 
      $batchModel = $this->getBatchModel(); 
 
      $batchIoAdapter = $this->getBatchModel()->getIoAdapter(); 
 

 
      if (Mage::app()->getRequest()->getParam('files')) { 
 
       $file = Mage::app()->getConfig()->getTempVarDir().'/import/' 
 
        . urldecode(Mage::app()->getRequest()->getParam('files')); 
 
       $this->_copy($file); 
 
      } 
 

 
      $batchIoAdapter->open(false); 
 

 
      $isFieldNames = $this->getVar('fieldnames', '') == 'true' ? true : false; 
 
      if (!$isFieldNames && is_array($this->getVar('map'))) { 
 
       $fieldNames = $this->getVar('map'); 
 
      } 
 
      else { 
 
       $fieldNames = array(); 
 
       foreach ($batchIoAdapter->read(true, $fDel, $fEnc) as $v) { 
 
        $fieldNames[$v] = $v; 
 
       } 
 
      } 
 

 
      $countRows = 0; 
 
      while (($csvData = $batchIoAdapter->read(true, $fDel, $fEnc)) !== false) { 
 
       if (count($csvData) == 1 && $csvData[0] === null) { 
 
        continue; 
 
       } 
 

 
       $itemData = array(); 
 
       $countRows ++; $i = 0; 
 
       foreach ($fieldNames as $field) { 
 
        $itemData[$field] = isset($csvData[$i]) ? $csvData[$i] : null; 
 
        $i ++; 
 
       } 
 

 
       $batchImportModel = $this->getBatchImportModel() 
 
        ->setId(null) 
 
        ->setBatchId($this->getBatchModel()->getId()) 
 
        ->setBatchData($itemData) 
 
        ->setStatus(1) 
 
        ->save(); 
 
      } 
 

 
      $this->addException(Mage::helper('dataflow')->__('Found %d rows.', $countRows)); 
 
      $this->addException(Mage::helper('dataflow')->__('Starting %s :: %s', $adapterName, $adapterMethod)); 
 

 
      $batchModel->setParams($this->getVars()) 
 
       ->setAdapter($adapterName) 
 
       ->save(); 
 

 
      //$adapter->$adapterMethod(); 
 

 
      return $this; 
 

 
    //  // fix for field mapping 
 
    //  if ($mapfields = $this->getProfile()->getDataflowProfile()) { 
 
    //   $this->_mapfields = array_values($mapfields['gui_data']['map'][$mapfields['entity_type']]['db']); 
 
    //  } // end 
 
    // 
 
    //  if (!$this->getVar('fieldnames') && !$this->_mapfields) { 
 
    //   $this->addException('Please define field mapping', Mage_Dataflow_Model_Convert_Exception::FATAL); 
 
    //   return; 
 
    //  } 
 
    // 
 
    //  if ($this->getVar('adapter') && $this->getVar('method')) { 
 
    //   $adapter = Mage::getModel($this->getVar('adapter')); 
 
    //  } 
 
    // 
 
    //  $i = 0; 
 
    //  while (($line = fgetcsv($fh, null, $fDel, $fEnc)) !== FALSE) { 
 
    //   $row = $this->parseRow($i, $line); 
 
    // 
 
    //   if (!$this->getVar('fieldnames') && $i == 0 && $row) { 
 
    //    $i = 1; 
 
    //   } 
 
    // 
 
    //   if ($row) { 
 
    //    $loadMethod = $this->getVar('method'); 
 
    //    $adapter->$loadMethod(compact('i', 'row')); 
 
    //   } 
 
    //   $i++; 
 
    //  } 
 
    // 
 
    //  return $this; 
 
     } 
 

 
     public function parseRow($i, $line) 
 
     { 
 
      if (sizeof($line) == 1) return false; 
 

 
      if (0==$i) { 
 
       if ($this->getVar('fieldnames')) { 
 
        $this->_fields = $line; 
 
        return; 
 
       } else { 
 
        foreach ($line as $j=>$f) { 
 
         $this->_fields[$j] = $this->_mapfields[$j]; 
 
        } 
 
       } 
 
      } 
 

 
      $resultRow = array(); 
 

 
      foreach ($this->_fields as $j=>$f) { 
 
       $resultRow[$f] = isset($line[$j]) ? $line[$j] : ''; 
 
      } 
 
      return $resultRow; 
 
     } 
 

 
     /** 
 
     * Read data collection and write to temporary file 
 
     * 
 
     * @return Mage_Dataflow_Model_Convert_Parser_Csv 
 
     */ 
 
     public function unparse() 
 
     { 
 
      $batchExport = $this->getBatchExportModel() 
 
       ->setBatchId($this->getBatchModel()->getId()); 
 
      $fieldList = $this->getBatchModel()->getFieldList(); 
 
      $batchExportIds = $batchExport->getIdCollection(); 
 

 
      $io = $this->getBatchModel()->getIoAdapter(); 
 
      $io->open(); 
 

 
      if (!$batchExportIds) { 
 
       $io->write(""); 
 
       $io->close(); 
 
       return $this; 
 
      } 
 

 
      if ($this->getVar('fieldnames')) { 
 
       $csvData = $this->getCsvString($fieldList); 
 
       $io->write($csvData); 
 
      } 
 

 
      foreach ($batchExportIds as $batchExportId) { 
 
       $csvData = array(); 
 
       $batchExport->load($batchExportId); 
 
       $row = $batchExport->getBatchData(); 
 

 
       foreach ($fieldList as $field) { 
 
        $csvData[] = isset($row[$field]) ? $row[$field] : ''; 
 
       } 
 
       $csvData = $this->getCsvString($csvData); 
 
       $io->write($csvData); 
 
      } 
 

 
      $io->close(); 
 

 
      return $this; 
 
     } 
 

 
     public function unparseRow($args) 
 
     { 
 
      $i = $args['i']; 
 
      $row = $args['row']; 
 

 
      $fDel = $this->getVar('delimiter', ','); 
 
      $fEnc = $this->getVar('enclose', '"'); 
 
      $fEsc = $this->getVar('escape', '\\'); 
 
      $lDel = "\r\n"; 
 

 
      if ($fDel == '\t') { 
 
       $fDel = "\t"; 
 
      } 
 

 
      $line = array(); 
 
      foreach ($this->_fields as $f) { 
 
       $v = isset($row[$f]) ? str_replace(array('"', '\\'), array($fEnc.'"', $fEsc.'\\'), $row[$f]) : ''; 
 
       $line[] = $fEnc.$v.$fEnc; 
 
      } 
 

 
      return join($fDel, $line); 
 
     } 
 

 
     /** 
 
     * Retrieve csv string from array 
 
     * 
 
     * @param array $fields 
 
     * @return string 
 
     */ 
 
     public function getCsvString($fields = array()) { 
 
      $delimiter = $this->getVar('delimiter', ','); 
 
      $enclosure = $this->getVar('enclose', ''); 
 
      $escapeChar = $this->getVar('escape', '\\'); 
 

 
      if ($delimiter == '\t') { 
 
       $delimiter = "\t"; 
 
      } 
 

 
      $str = ''; 
 
      foreach ($fields as $value) { 
 

 
       $escapedValue = Mage::helper("core")->getEscapedCSVData(array($value)); 
 
       $value = $escapedValue[0]; 
 

 
       if (strpos($value, $delimiter) !== false || 
 
        empty($enclosure) || 
 
        strpos($value, $enclosure) !== false || 
 
        strpos($value, "\n") !== false || 
 
        strpos($value, "\r") !== false || 
 
        strpos($value, "\t") !== false || 
 
        strpos($value, ' ') !== false) { 
 
        $str2 = $enclosure; 
 
        $escaped = 0; 
 
        $len = strlen($value); 
 
        for ($i=0;$i<$len;$i++) { 
 
         if ($value[$i] == $escapeChar) { 
 
          $escaped = 1; 
 
         } else if (!$escaped && $value[$i] == $enclosure) { 
 
          $str2 .= $enclosure; 
 
         } else { 
 
          $escaped = 0; 
 
         } 
 
          $str2 .= $value[$i]; 
 
        } 
 
        $str2 .= $enclosure; 
 
        $str .= $str2.$delimiter; 
 
       } else { 
 
        $str .= $enclosure.$value.$enclosure.$delimiter; 
 
       } 
 
      } 
 
      return substr($str, 0, -1) . "\n"; 
 
     } 
 
    }

nicht sicher, wie dieses Problem zu beheben. Wenn ich Hilfe bekommen könnte, würde ich es sehr schätzen.

Dank

UPDATE

Hier ist der Code aus meiner app/code/core/Mage/Core/Helper/Data.php Datei: http://pastie.org/10815259

Antwort

1

Ist die Datei app/code/core/Mage/Core/Helper/Data.php haben die getEscapedCSVData Funktion darin?

Es scheint, dass diese Funktion von SUPEE-7405 hinzugefügt wird. Haben Sie Ihren Laden mit dieser SUPEE geflickt?

+0

Hmmm nein, es scheint nicht diese Funktion zu haben. Sollte es oder sollte es nicht diese Funktion haben? Sollte ich es irgendwo hinzufügen? Hier ist der Code von meiner Data.php: http://pastie.org/10815259 Und ja, ich habe versucht, die Website mit SUPEE-7405 vor nicht allzu langer Zeit zu patchen. Die Seite wurde auch von 1.9.2 auf 1.9.4 aktualisiert. – Keo777

+1

Also ging ich voran und lud eine Kopie von Magento 1.9.2.4 herunter und fand die Datei Data.php, dann kopierte ich die Funktionen, die am Ende meiner Data.php hinzugefügt wurden Datei. Es scheint, dass Sie Recht hatten, die Cron-Jobs werden nun endlich ohne Fehler aktualisiert. Danke vielmals! – Keo777

0

In meinem Fall einige vorherige programer haben die Datei kopieren

von Kern

\ app \ code \ core \ Mage \ Core \ Helper \ data.php

zu lokalen

app \ code \ local \ Mage \ Core \ Helper \ data.php

ein nd dann SUPE PATCH 7405 anwenden ... es verursacht, dass alle Änderungen, die von SUPE in data.php gemacht werden, wo durch die alten in lokalem Ordner neu geschrieben werden ... Lösung: kopieren Sie die neue data.php zum lokalen oder bildete eine Verlängerung von Klasse (bessere Lösung)

Verwandte Themen