/** * Used to import package * */ function importPackage($zipfile) { $zip = new ZipArchive(); $pfDeployOrder = new PluginFusioninventoryDeployOrder(); $pfDeployFile = new PluginFusioninventoryDeployFile(); $filename = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/import/" . $zipfile; $extract_folder = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/import/" . $zipfile . ".extract"; if ($zip->open($filename, ZipArchive::CREATE) == TRUE) { $zip->extractTo($extract_folder); $zip->close(); } $json_string = file_get_contents($extract_folder . "/information.json"); $a_info = json_decode($json_string, true); // Find package with this uuid $a_packages = $this->find("`uuid`='" . $a_info['package']['uuid'] . "'"); if (count($a_packages) == 0) { // Create it $_SESSION['tmp_clone_package'] = true; $packages_id = $this->add($a_info['package']); unset($_SESSION['tmp_clone_package']); foreach ($a_info['orders'] as $input) { $input['plugin_fusioninventory_deploypackages_id'] = $packages_id; $pfDeployOrder->add($input); echo "|"; } foreach ($a_info['files'] as $input) { $pfDeployFile->add($input); } } else { // Update current } // Copy files foreach ($a_info['manifests'] as $manifest) { rename($extract_folder . "/files/manifests/" . $manifest, GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/manifests/" . $manifest); } foreach ($a_info['repository'] as $repository) { $split = explode('/', $repository); array_pop($split); $folder = ''; foreach ($split as $dir) { $folder .= '/' . $dir; if (!file_exists(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/repository" . $folder)) { mkdir(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/repository" . $folder); } } rename($extract_folder . "/files/repository/" . $repository, GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/repository/" . $repository); } }
/** * Create installation & uninstallation orders * @param packages_id the package ID * @return nothing */ static function createOrders($packages_id) { $order = new PluginFusioninventoryDeployOrder(); $tmp['create_date'] = date("Y-m-d H:i:s"); $tmp['plugin_fusioninventory_deploypackages_id'] = $packages_id; foreach (array(PluginFusioninventoryDeployOrder::INSTALLATION_ORDER, PluginFusioninventoryDeployOrder::UNINSTALLATION_ORDER) as $type) { $tmp['type'] = $type; $tmp['json'] = json_encode(array('jobs' => array('checks' => array(), 'associatedFiles' => array(), 'actions' => array()), 'associatedFiles' => array())); $order->add($tmp); } }