public function run()
 {
     $connect = false;
     $this->addValidator(new V\ValidatorExtension('xml'));
     #если нет соединения то его надо установить.
     if (false === $connect) {
         $this->initFtpConnection();
         $connect = true;
     }
     foreach ($this->listFiles() as $file) {
         #если нет соединения то его надо установить.
         if (false === $connect) {
             $this->initFtpConnection();
             $connect = true;
         }
         $validate = $this->runValidators($file);
         if (true === $validate['success'] && $this->checkFileSize($file, 64000000) === true) {
             #копируем файл на локольный сервер и удаляем с FTP-сервера
             $filename = $this->getFile($file);
             if (false === $this->deleteFtpFile($file)) {
                 throw new \Exception("Can't delete {$file} from FTP server");
             }
             $process = null;
             if (false === $this->container->get('sportmaster_utility')->isFileUploaded($filename)) {
                 switch ($this->type) {
                     case 'ACKN':
                         $process = new SI\ImportAcknEvent($filename, $this->container);
                         #передаем файл сразу в SCA
                         $result = $this->putFtp($this->config['distinationPath'] . '/' . $file, $filename);
                         if ($result === false) {
                             throw new \Exception("Can't upload file {$file} to FTP-server");
                         }
                         break;
                     case 'EEM_SHIPMENT':
                         $process = new SI\ImportShipmentEventEem($filename, $this->container);
                         $process->setDistinationPath($this->config['distinationPath']);
                         #в этом случае на каждый файл будет открываться новое соединение
                         $connect = false;
                         $this->ftpClose();
                         break;
                     case 'PO':
                         $process = new SI\ImportShipmentPoEem($filename, $this->container);
                         $process->setDistinationPath($this->config['distinationPath']);
                         break;
                     case 'SCA_SHIPMENT':
                         $process = new SI\ImportShipmentEventSca($filename, $this->container);
                         $process->setDistinationPath($this->config['distinationPath']);
                         break;
                     case 'SPM_BOOKING':
                         $process = new SI\ImportShipmentBooking($filename, $this->container);
                         $process->setDistinationPath($this->config['distinationPath']);
                         break;
                 }
                 $process->parse();
             }
         } else {
             $message = "File {$file} in folder {$this->config['dir']} has wrong extension or too big";
             $logger = $this->container->get('logger');
             $logger->error($message);
             @mail('ivan.popov@panalpina.com,stanislav.biryukov@panalpina.com', 'Exception occured', $message);
             continue;
         }
     }
     if (true === $connect) {
         $this->ftpClose();
     }
 }
Пример #2
0
 protected function importPO($file)
 {
     $zip = new U\Zip();
     $remove = false;
     if (is_file($file)) {
         if ($zip->isZipArchive($file)) {
             $pathToFile = $zip->extract($file);
             $remove = true;
         } else {
             $pathToFile = $file;
         }
         $process = new SI\ImportShipmentPoEem($pathToFile, $this->_container);
         $process->setDistinationPath($this->_distinationPath);
         $process->importPO();
         if (true == $remove) {
             unlink($pathToFile);
         }
         return "File {$file} succesufully parsed. \n\r";
     } else {
         return "File {$file} not found at server";
     }
 }