/** * Deletes the image trought FTP */ private function deleteFtp() { $size = 0; $count = 0; $deleted = false; do { $ftp = $this->mastroProduct->getProductFromCsv()->getFtp(); if ( $this->magentoUrl != '' && is_resource($ftp) && $this->mastroProduct->getProductFromCsv()->getConfig(self::$mainImageConvert) !== false && is_file($this->magentoFileName . $this->magentoPath) ) { ftp_chdir($ftp, $this->mastroProduct->getProductFromCsv()->getConfig('FTP_BASE_DIR')); foreach ($this->imagesSubDirs as $dir) { $fileList = ftp_nlist($ftp,'.'); if (!in_array($dir, $fileList)) { ftp_mkdir($ftp,$dir); } ftp_chdir($ftp,$dir); } $fileList = ftp_nlist($ftp,'.'); if ( !in_array($this->fileName['parsedFilename'] .$this->suffix . '.jpeg', $fileList) ) { echo 'Deleted image '.$this->fileName['filename'].PHP_EOL; $deleted = ftp_delete($ftp, $this->fileName['parsedFilename'] . $this->suffix. '.jpeg', $this->magentoFileName . $this->magentoPath, FTP_BINARY); } ftp_chdir($ftp, $this->mastroProduct->getProductFromCsv()->getConfig('FTP_BASE_DIR')); foreach ($this->imagesSubDirs as $dir) { $fileList = ftp_nlist($ftp,'.'); if (!in_array($dir, $fileList)) { ftp_mkdir($ftp,$dir); } ftp_chdir($ftp,$dir); } $fileList = ftp_nlist($ftp,'.'); if ( in_array($this->fileName['parsedFilename'] .$this->suffix . '.jpeg', $fileList) ) { $size = ftp_size ($ftp,$this->fileName['parsedFilename'] . $this->suffix . '.jpeg') != filesize($this->magentoFileName . $this->magentoPath); } ftp_chdir($ftp, $this->mastroProduct->getProductFromCsv()->getConfig('FTP_BASE_DIR')); } $count++; } while ($deleted == true && $count < 10); $updated = true; if ($count >=10) { $this->mastroProduct->getProductFromCsv()->appendToLog('Error on image delete :'.$this->mastroFile); $updated = false; } return $updated; }
/** * Creates reference to PrductFromCsv * @param MastroProduct $mastroProduct */ public function __construct(MastroProduct $mastroProduct) { foreach($mastroProduct->getHeaders() as $header) self::$headers['MASTRO_'.$header]=null; $this->productFromCsv = $mastroProduct->getProductFromCsv(); }