static function addFileInRepo($params) { $deployFile = new self(); $filename = addslashes($params['filename']); $file_tmp_name = $params['file_tmp_name']; $maxPartSize = 1024 * 1024; $repoPath = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/repository/"; $tmpFilepart = tempnam(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/", "filestore"); $sha512 = hash_file('sha512', $file_tmp_name); $short_sha512 = substr($sha512, 0, 6); $file_present_in_repo = FALSE; if ($deployFile->checkPresenceFile($sha512)) { $file_present_in_repo = TRUE; } $file_present_in_db = $deployFile->getFromDBByQuery("WHERE shortsha512 = '" . $short_sha512 . "'"); //Manifest files contains the multiparts list attached to the file $manifest_path = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/manifests/"; $manifest_filename = $manifest_path . $sha512; $new_entry = array('name' => $filename, 'p2p' => $params['p2p'], 'p2p-retention-duration' => $params['p2p-retention-duration'], 'uncompress' => $params['uncompress']); $fdIn = fopen($file_tmp_name, 'rb'); if (!$fdIn) { return FALSE; } $fdPart = NULL; $multiparts = array(); do { clearstatcache(); if (file_exists($tmpFilepart)) { if (feof($fdIn) || filesize($tmpFilepart) >= $maxPartSize) { $part_sha512 = $deployFile->registerFilepart($repoPath, $tmpFilepart, $file_present_in_repo); unlink($tmpFilepart); $multiparts[] = $part_sha512; } } if (feof($fdIn)) { break; } $data = fread($fdIn, 1024 * 1024); $fdPart = gzopen($tmpFilepart, 'a'); gzwrite($fdPart, $data, strlen($data)); gzclose($fdPart); } while (1); // $new_entry['multiparts'] = $multiparts; //create manifest file if (!$file_present_in_repo) { $handle = fopen($manifest_filename, "w+"); if ($handle) { foreach ($multiparts as $sha) { fwrite($handle, $sha . "\n"); } fclose($handle); } } //TODO: Add a new files interface to list, create, manage entities and visibility // entity on a file is just anticipated and will be fully used later if (!$file_present_in_db) { $entry = array("name" => $filename, "filesize" => $params['filesize'], "mimetype" => $params['mime_type'], "sha512" => $sha512, "shortsha512" => $short_sha512, "comments" => "", "date_mod" => date('Y-m-d H:i:s'), "entities_id" => 0, "is_recursive" => 1); $deployFile->add($entry); } //get current order json $datas = json_decode(PluginFusioninventoryDeployOrder::getJson($params['orders_id']), TRUE); //add new entry $datas['associatedFiles'][$sha512] = $new_entry; if (!in_array($sha512, $datas['jobs']['associatedFiles'])) { $datas['jobs']['associatedFiles'][] = $sha512; } //update order PluginFusioninventoryDeployOrder::updateOrderJson($params['orders_id'], $datas); return TRUE; }