Exemple #1
0
 /**
  * Save package file to var/connect.
  *
  * @return boolean
  */
 public function savePackage()
 {
     if ($this->getData('file_name') != '') {
         $fileName = $this->getData('file_name');
         $this->unsetData('file_name');
     } else {
         $fileName = $this->getName();
     }
     if (!preg_match('/^[a-z0-9]+[a-z0-9\\-\\_\\.]*([\\/\\\\]{1}[a-z0-9]+[a-z0-9\\-\\_\\.]*)*$/i', $fileName)) {
         return false;
     }
     if (!$this->getPackageXml()) {
         $this->generatePackageXml();
     }
     if (!$this->getPackageXml()) {
         return false;
     }
     try {
         //            $path = $this->writeDirectory->getAbsolutePath();
         $this->writeDirectory->writeFile(sprintf('connect/%s', 'package.xml'), $this->getPackageXml());
         $this->unsPackageXml();
         $this->unsTargets();
         $xml = $this->_convertArray->assocToXml($this->getData());
         $xml = new \Magento\Framework\Simplexml\Element($xml->asXML());
         // prepare dir to save
         $parts = explode('/', $fileName);
         array_pop($parts);
         $directoryPath = implode('/', $parts);
         if (!empty($directoryPath)) {
             $this->writeDirectory->create(sprintf('connect/%s', $directoryPath));
         }
         $this->writeDirectory->writeFile(sprintf('connect/%s.xml', $fileName), $xml->asNiceXml());
     } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
         $this->logger->addStreamLog(\Magento\Framework\Logger::LOGGER_EXCEPTION);
         $this->logger->log($e->getMessage());
         return false;
     }
     return true;
 }
 /**
  * @param array $array
  * @param string $rootName
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @dataProvider assocToXmlExceptionDataProvider
  */
 public function testAssocToXmlException($array, $rootName = '_')
 {
     $this->_model->assocToXml($array, $rootName);
 }