Example #1
0
 /**
  * Export all clients
  */
 public function exportAction()
 {
     $request = $this->getRequest();
     $directory = $request->getParam('directory');
     $validate = $request->getParam('validate') || $request->getParam('v');
     if (!is_dir($directory) or !is_writable($directory)) {
         $model = new \Zend\Mvc\Console\View\ViewModel();
         $model->setErrorLevel(10);
         $model->setResult("Directory '{$directory}' does not exist or is not writable.\n");
         return $model;
     }
     $clients = $this->_clientManager->getClients(null, 'IdString');
     foreach ($clients as $client) {
         $id = $client['IdString'];
         $this->console->writeLine("Exporting {$id}");
         $document = $client->toDomDocument();
         $document->save($directory . '/' . $document->getFilename());
         if ($validate and !$document->isValid()) {
             $model = new \Zend\Mvc\Console\View\ViewModel();
             $model->setErrorLevel(11);
             $model->setResult("Validation failed for {$id}.\n");
             return $model;
         }
     }
 }
Example #2
0
 /**
  * Decode a compressed inventory file
  */
 public function decodeInventoryAction()
 {
     $input = $this->getRequest()->getParam('input_file');
     if (!is_file($input) or !is_readable($input)) {
         $model = new \Zend\Mvc\Console\View\ViewModel();
         $model->setErrorLevel(10);
         $model->setResult("Input file does not exist or is not readable.\n");
         return $model;
     }
     try {
         return $this->_inventoryDecode->filter(\Library\FileObject::fileGetContents($input));
     } catch (\InvalidArgumentException $e) {
         $model = new \Zend\Mvc\Console\View\ViewModel();
         $model->setErrorLevel(11);
         $model->setResult($e->getMessage() . "\n");
         return $model;
     }
 }