/** * Used to export package * */ function exportPackage($packages_id) { $this->getFromDB($packages_id); if (empty($this->fields['uuid'])) { $input = array('id' => $this->fields['id'], 'uuid' => Rule::getUuid()); $this->update($input); } $pfDeployOrder = new PluginFusioninventoryDeployOrder(); $pfDeployFile = new PluginFusioninventoryDeployFile(); // Generate JSON $a_xml = array(); $input = $this->fields; unset($input['id']); $a_xml['package'] = $input; $a_xml['orders'] = array(); $a_xml['files'] = array(); $a_xml['manifests'] = array(); $a_xml['repository'] = array(); $a_files = array(); $a_data = $pfDeployOrder->find("`plugin_fusioninventory_deploypackages_id`='" . $this->fields['id'] . "'"); foreach ($a_data as $data) { unset($data['id']); unset($data['plugin_fusioninventory_deploypackages_id']); $a_xml['orders'][] = $data; $json = json_decode($data['json'], true); $a_files = array_merge($a_files, $json['associatedFiles']); } // Add files foreach ($a_files as $files_id => $data) { $a_pkgfiles = current($pfDeployFile->find("`sha512`='" . $files_id . "'", '', 1)); if (count($a_pkgfiles) > 0) { unset($a_pkgfiles['id']); $a_xml['files'][] = $a_pkgfiles; } } // Create zip with JSON and files $name = preg_replace("/[^a-zA-Z0-9]/", '', $this->fields['name']); $filename = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/export/" . $this->fields['uuid'] . "." . $name . ".zip"; if (file_exists($filename)) { unlink($filename); } $zip = new ZipArchive(); if ($zip->open($filename) == TRUE) { if ($zip->open($filename, ZipArchive::CREATE) == TRUE) { $zip->addEmptyDir('files'); $zip->addEmptyDir('files/manifests'); $zip->addEmptyDir('files/repository'); foreach ($a_files as $hash => $data) { $sha512 = file_get_contents(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/manifests/" . $hash); $sha512 = trim($sha512); $zip->addFile(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/manifests/" . $hash, "files/manifests/" . $hash); $a_xml['manifests'][] = $hash; $file = PluginFusioninventoryDeployFile::getDirBySha512($sha512) . "/" . $sha512; $zip->addFile(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/repository/" . $file, "files/repository/" . $file); $a_xml['repository'][] = $file; } $json_string = json_encode($a_xml); $zip->addFromString('information.json', $json_string); } $zip->close(); Session::addMessageAfterRedirect(__("Package exported in", "fusioninventory") . " " . GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/export/" . $this->fields['uuid'] . "." . $name . ".zip"); } }
/** * Unregister the invalid manifests from database. */ function unregisterInvalidManifests($logger, $dryrun, $invalid_manifests) { global $DB; $logger->info("Unregistering " . count($invalid_manifests) . " manifests from database."); $pfDeployFile = new PluginFusioninventoryDeployFile(); foreach ($invalid_manifests as $manifest) { $short_sha512 = substr($manifest, 0, 6); $data = $pfDeployFile->find("shortsha512 = '" . $short_sha512 . "'"); foreach ($data as $config) { $pfDeployFile->getFromDB($config['id']); $logger->info("Unregister file " . $pfDeployFile->fields['name']); if (!$dryrun) { $pfDeployFile->deleteFromDB(); } } } }