✏️ 正在编辑: FtpBonSucesso.php
路径:
/srv/systems_dir/yuppiecred/library/Core/Banco/Service/FtpBonSucesso.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_Banco_Service_FtpBonSucesso extends Core_Banco_Service_Ftp { public $arquivosBaixados = []; protected $_timeInicial; protected $_ultimoImportado; public function getFile($remoteFile, $localFile) { $pathInfo = pathinfo($remoteFile); if( strtolower(isset($pathInfo['extension']) ? $pathInfo['extension'] : null) == 'gz' ){ if( !file_exists($localFile) ){ return parent::getFile($remoteFile, $localFile); } } return null; } public function baixarArquivos($diretorio = '.', $bancoId, $closeConnection = true, $dataImportacao = null) { /* Apenas para LOG */ $urlSistema = Yuppie_Auth::getSiteKey(); $writer = new Zend_Log_Writer_Stream("/var/log/sistemayuppie/zf_log_ftp_{$urlSistema}_" . date('dmY') . ".txt"); $classeChamada = get_class($this); $log = new Zend_Log($writer); $log->log('#######################', Zend_Log::INFO); $log->log("IMPORTAÇÃO: " . $classeChamada, Zend_Log::INFO); $log->log("Usuário logado: " . Yuppie_Auth::getIdentity()->login, Zend_Log::INFO); $qtdArquivosBaixados = 0; $dbtableArquivo = null; if( $this->getIsConnected() ){ $this->changeDirectory($diretorio); $this->setModPasv(true); // if(!strstr($this->getHost(), "dataprocessing.sistemayuppie.com.br") // && strstr($this->getHost(), "sistemayuppie.com.br")){ // $this->setModPasv(true); // } $files = $this->listFilesInDirectory(); //localiza a última importação $dbtableArquivo = new Model_DbTable_ArquivoImportado(); $this->_ultimoImportado = $dbtableArquivo->getLastFileImported($bancoId); if ($dataImportacao != null) { $this->_ultimoImportado['data_importacao'] = (new Zend_Date($dataImportacao)) ->toString('yyyy-MM-dd 00:00:00'); } $log->log("Banco: " . $bancoId, Zend_Log::INFO); if( !$this->_ultimoImportado ){ $log->log("Último setado como data atual", Zend_Log::INFO); $this->_ultimoImportado['data_importacao'] = date('Y-m-d 00:00:00'); } $log->log("Último importado: " . $this->_ultimoImportado['id'], Zend_Log::INFO); $dt = DateTime::createFromFormat('Y-m-d H:i:s', $this->_ultimoImportado['data_importacao']); $this->_timeInicial = $dt->sub(new DateInterval('P15D'))->getTimestamp(); $diretorioDestino = $this->verificaDiretorioDestino($bancoId); $dateUltimoArquivo = clone $dt; $log->log("dateUltimoArquivo: " . $dateUltimoArquivo->format('d/m/Y'), Zend_Log::INFO); $log->log("Quantidade de arquivos no FTP: " . count($files), Zend_Log::INFO); if( $files != false && count($files) > 0 ){ try { foreach ( $files as $key => $file ) { $quebrarArquivo = explode("_", $file); $dataArquivo = $quebrarArquivo[0]; $dtArquivo = DateTime::createFromFormat('Ymd', $dataArquivo); $log->log("Nome Arquivo: " . $file, Zend_Log::INFO); $log->log("dateArquivoAtual: " . print_r($dtArquivo, true), Zend_Log::INFO); if( $dateUltimoArquivo < $dtArquivo ){ //baixa o arquivo if( $this->getFile($file, $diretorioDestino . '/' . $file) ){ array_push($this->arquivosBaixados, $file); $qtdArquivosBaixados++; $log->log("Arquivo {$file} foi baixado ", Zend_Log::INFO); } else { $log->log("Arquivo {$file} NÃO foi baixado ", Zend_Log::INFO); } } else { $log->log("Arquivo {$file} anterior a última importação. ", Zend_Log::INFO); } } } catch ( Exception $exc ) { throw new Exception( $exc->getMessage()); } } if( $closeConnection ){ $this->closeConnection(); } } return $qtdArquivosBaixados; } /** * Retorna o nome dos arquivos baixados * @return array */ public function getArquivosBaixados() : Array { return $this->arquivosBaixados; } }
💾 保存文件
← 返回文件管理器