예제 #1
0
 /**
  * pushd and popd should always be called in pairs. even if pushd returns FALSE
  * @return boolean      Whether or not the directory was changed successfully
  */
 private function _popd()
 {
     $oldCwd = array_pop($this->_dirs);
     if (FALSE !== $oldCwd) {
         return $this->_oSftp->cd($oldCwd);
     }
     return FALSE;
 }
예제 #2
0
 /**
  * Goes to specified host/path and fetches reports from there.
  * Save reports to database.
  *
  * @param array $config SFTP credentials
  * @return int Number of report rows that were fetched and saved successfully
  */
 public function fetchAndSave($config)
 {
     $connection = new Varien_Io_Sftp();
     $connection->open(array('host' => $config['hostname'], 'username' => $config['username'], 'password' => $config['password']));
     $connection->cd($config['path']);
     $fetched = 0;
     $listing = $this->_filterReportsList($connection->rawls());
     foreach ($listing as $filename => $attributes) {
         $localCsv = tempnam(Mage::getConfig()->getOptions()->getTmpDir(), 'PayPal_STL');
         if ($connection->read($filename, $localCsv)) {
             if (!is_writable($localCsv)) {
                 Mage::throwException(Mage::helper('paypalmx')->__('Cannot create target file for reading reports.'));
             }
             $encoded = file_get_contents($localCsv);
             $csvFormat = 'new';
             if (self::FILES_OUT_CHARSET != mb_detect_encoding($encoded)) {
                 $decoded = @iconv(self::FILES_IN_CHARSET, self::FILES_OUT_CHARSET . '//IGNORE', $encoded);
                 file_put_contents($localCsv, $decoded);
                 $csvFormat = 'old';
             }
             // Set last modified date, this value will be overwritten during parsing
             if (isset($attributes['mtime'])) {
                 $lastModified = new Zend_Date($attributes['mtime']);
                 $this->setReportLastModified($lastModified->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
             }
             $this->setReportDate($this->_fileNameToDate($filename))->setFilename($filename)->parseCsv($localCsv, $csvFormat);
             if ($this->getAccountId()) {
                 $this->save();
             }
             if ($this->_dataSaveAllowed) {
                 $fetched += count($this->_rows);
             }
             // clean object and remove parsed file
             $this->unsetData();
             unlink($localCsv);
         }
     }
     return $fetched;
 }
예제 #3
0
 /**
  * Download Images (Step 6)
  *
  * @param Pimgento_Core_Model_Task $task
  *
  * @return bool
  */
 public function downloadImages($task)
 {
     $adapter = $this->getAdapter();
     $ftp = null;
     try {
         $connexion = Mage::getStoreConfig('pimdata/asset/connexion');
         if ($connexion == 'ftp') {
             /* @var $ftp Varien_Io_Ftp */
             $ftp = new Varien_Io_Ftp();
             $config = array('host' => Mage::getStoreConfig('pimdata/asset/host'), 'user' => Mage::getStoreConfig('pimdata/asset/user'), 'password' => Mage::getStoreConfig('pimdata/asset/password'));
             if (Mage::getStoreConfig('pimdata/asset/directory')) {
                 $config['path'] = Mage::getStoreConfig('pimdata/asset/directory');
             }
             if (Mage::getStoreConfig('pimdata/asset/passive')) {
                 $config['passive'] = true;
             }
             $ftp->open($config);
         } else {
             if ($connexion == 'sftp') {
                 /* @var $ftp Varien_Io_Sftp */
                 $ftp = new Varien_Io_Sftp();
                 $config = array('host' => Mage::getStoreConfig('pimdata/asset/host'), 'username' => Mage::getStoreConfig('pimdata/asset/user'), 'password' => Mage::getStoreConfig('pimdata/asset/password'));
                 $ftp->open($config);
                 if (Mage::getStoreConfig('pimdata/asset/directory')) {
                     $ftp->cd(Mage::getStoreConfig('pimdata/asset/directory'));
                 }
             } else {
                 $task->error(Mage::helper('pimgento_asset')->__('Connexion type %s is not authorised', $connexion));
             }
         }
         if ($ftp) {
             $select = $adapter->select()->from($adapter->getTableName('pimgento_asset'), array('file', 'image'));
             $query = $adapter->query($select);
             $directory = Mage::helper('pimgento_asset')->getBaseMediaPath();
             while ($row = $query->fetch()) {
                 $dir = dirname($directory . $row['image']);
                 if (!is_dir($dir)) {
                     mkdir($dir, 0777, true);
                 }
                 $ftp->read($row['file'], $directory . $row['image']);
             }
             $ftp->close();
         }
     } catch (Exception $e) {
         $task->error(Mage::helper('pimgento_asset')->__($e->getMessage()));
     }
     return true;
 }
예제 #4
0
 public function filteredLs()
 {
     $result = parent::ls();
     return Mage::getSingleton('udbatch/io')->filterLs($result, $this);
 }