Example #1
0
 /**
  * Import configuration data.
  *
  * $params structure:
  * array(
  * 	'format' => 'json'|'xml'
  * 	'source' => configuration data in specified format,
  * 	'rules' => array(
  * 		'hosts' => array('createMissing' => true, 'updateExisting' => false),
  * 		'templates' => array('createMissing' => true, 'updateExisting' => true),
  * 		...
  * 	)
  * )
  *
  * @param $params
  *
  * @return bool
  */
 public function import($params)
 {
     $importReader = CImportReaderFactory::getReader($params['format']);
     $configurationImport = new CConfigurationImport($params['source'], $params['rules']);
     $configurationImport->setReader($importReader);
     return $configurationImport->import();
 }
Example #2
0
 /**
  * Import configuration data.
  *
  * $params structure:
  * array(
  * 	'format' => 'json'|'xml'
  * 	'source' => configuration data in specified format,
  * 	'rules' => array(
  * 		'hosts' => array('createMissing' => true, 'updateExisting' => false),
  * 		'templates' => array('createMissing' => true, 'updateExisting' => true),
  * 		...
  * 	)
  * )
  *
  * @param $params
  *
  * @return bool
  */
 public function import($params)
 {
     $importReader = CImportReaderFactory::getReader($params['format']);
     $configurationImport = new CConfigurationImport($params['source'], $params['rules'], new CImportReferencer(), new CImportedObjectContainer(), new CTriggerExpression());
     $configurationImport->setReader($importReader);
     return $configurationImport->import();
 }
                $requestRules[$ruleName]['updateExisting'] = false;
            }
            if (isset($rule['createMissing'])) {
                $requestRules[$ruleName]['createMissing'] = false;
            }
        } elseif (!isset($requestRules[$ruleName]['updateExisting']) && isset($rule['updateExisting'])) {
            $requestRules[$ruleName]['updateExisting'] = false;
        } elseif (!isset($requestRules[$ruleName]['createMissing']) && isset($rule['createMissing'])) {
            $requestRules[$ruleName]['createMissing'] = false;
        }
    }
    $data['rules'] = $requestRules;
}
if (isset($_FILES['import_file'])) {
    try {
        $file = new CUploadFile($_FILES['import_file']);
        $importFormat = CImportReaderFactory::fileExt2ImportFormat($file->getExtension());
        $importReader = CImportReaderFactory::getReader($importFormat);
        $configurationImport = new CConfigurationImport($file->getContent(), $data['rules']);
        $configurationImport->setReader($importReader);
        $configurationImport->import();
        show_messages(true, _('Imported successfully'));
    } catch (Exception $e) {
        error($e->getMessage());
        show_messages(false, null, _('Import failed'));
    }
}
$view = new CView('conf.import', $data);
$view->render();
$view->show();
require_once 'include/page_footer.php';