/** * @param Request $request * @return Response */ protected function handle(Request $request) { $userId = Auth::getUserId(); $vars = array(); $folderContentId = intval($request->get('foldercontent')); $parentFolderId = intval($request->get('toFolder')); if ($folderContentId && $parentFolderId && $request->get('copy')) { try { $this->folderDao->copyContent($folderContentId, $parentFolderId); } catch (Exception $ex) { $vars['message'] = $ex->getMessage(); } } elseif ($folderContentId && $parentFolderId) { try { $this->folderDao->moveContent($folderContentId, $parentFolderId); } catch (Exception $ex) { $vars['message'] = $ex->getMessage(); } } $rootFolderId = $this->folderDao->getRootFolder($userId)->getId(); /* @var $uiFolderNav FolderNav */ $uiFolderNav = $this->getObject('ui.folder.nav'); $vars['folderTree'] = $uiFolderNav->showFolderTree($rootFolderId); $vars['folderStructure'] = $this->folderDao->getFolderStructure($rootFolderId); return $this->render('admin_content_move.html.twig', $this->mergeWithDefault($vars)); }
/** * @param int $parentFolder parent folder_pk * @return string HTML of the folder tree */ public function showFolderTree($parentFolder) { $uri = Traceback_uri(); $sql = $this->folderDao->getFolderTreeCte($parentFolder) . " SELECT folder_pk, folder_name, folder_desc, depth, name_path FROM folder_tree ORDER BY name_path"; $stmt = __METHOD__; $this->dbManager->prepare($stmt, $sql); $res = $this->dbManager->execute($stmt, array($parentFolder)); $out = ''; $lastDepth = -1; while ($row = $this->dbManager->fetchArray($res)) { for (; $row['depth'] < $lastDepth; $lastDepth--) { $out .= '</li></ul>'; } if ($row['depth'] == $lastDepth) { $out .= "</li>\n<li>"; } if ($row['depth'] == 0) { $out .= '<ul id="tree"><li>'; $lastDepth++; } for (; $row['depth'] > $lastDepth; $lastDepth++) { $out .= '<ul><li>'; } $out .= $this->getFormattedItem($row, $uri); } for (; -1 < $lastDepth; $lastDepth--) { $out .= '</li></ul>'; } return $out; }
public function check() { $this->checkDecisionScopes(); $this->checkUploadStatus(); $this->checkLicenseEventTypes(); $this->checkExistsTable('license_candidate'); $folderDao = new FolderDao($this->dbManager, $GLOBALS['container']->get('dao.user'), $GLOBALS['container']->get('dao.upload')); $folderDao->ensureTopLevelFolder(); return $this->errors; }
protected function setUp() { $this->folderDao = M::mock(FolderDao::classname()); $this->dbManager = M::mock(DbManager::classname()); $this->folderNav = new FolderNav($this->dbManager, $this->folderDao); $this->uri = Traceback_uri(); $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount(); }
public function testGetFolder() { $this->folderDao->ensureTopLevelFolder(); $goodFolder = $this->folderDao->getFolder(FolderDao::TOP_LEVEL); assertThat($goodFolder, is(anInstanceOf(\Fossology\Lib\Data\Folder\Folder::classname()))); assertThat($goodFolder->getId(), equalTo(FolderDao::TOP_LEVEL)); $badFolder = $this->folderDao->getFolder(987); assertThat($badFolder, is(nullValue())); }
/** * @param Request $request * @return Response */ protected function handle(Request $request) { $userId = Auth::getUserId(); $vars = array(); $folderContentId = intval($request->get('foldercontent')); if ($folderContentId) { try { $this->folderDao->removeContent($folderContentId); } catch (Exception $ex) { $vars['message'] = $ex->getMessage(); } } $rootFolderId = $this->folderDao->getRootFolder($userId)->getId(); /* @var $uiFolderNav FolderNav */ $uiFolderNav = $GLOBALS['container']->get('ui.folder.nav'); $vars['folderTree'] = $uiFolderNav->showFolderTree($rootFolderId); return $this->render('admin_content_delete.html.twig', $this->mergeWithDefault($vars)); }
protected function handle(Request $request) { // Handle request $this->folderDao->ensureTopLevelFolder(); $message = ""; $description = ""; if ($request->isMethod(Request::METHOD_POST)) { list($success, $message, $description) = $this->handleUpload($request); } $vars['message'] = $message; $vars['descriptionInputValue'] = $description ?: ""; $vars['descriptionInputName'] = self::DESCRIPTION_INPUT_NAME; $vars['folderParameterName'] = self::FOLDER_PARAMETER_NAME; $vars['upload_max_filesize'] = ini_get('upload_max_filesize'); $vars['agentCheckBoxMake'] = ''; $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId()); $folderStructure = $this->folderDao->getFolderStructure($rootFolder->getId()); $vars['folderStructure'] = $folderStructure; $vars['baseUrl'] = $request->getBaseUrl(); $vars['moduleName'] = $this->getName(); $vars[self::FOLDER_PARAMETER_NAME] = $request->get(self::FOLDER_PARAMETER_NAME); $parmAgentList = MenuHook::getAgentPluginNames("ParmAgents"); $vars['parmAgentContents'] = array(); $vars['parmAgentFoots'] = array(); foreach ($parmAgentList as $parmAgent) { $agent = plugin_find($parmAgent); $vars['parmAgentContents'][] = $agent->renderContent($vars); $vars['parmAgentFoots'][] = $agent->renderFoot($vars); } $session = $request->getSession(); $session->set(self::UPLOAD_FORM_BUILD_PARAMETER_NAME, time() . ':' . $_SERVER['REMOTE_ADDR']); $vars['uploadFormBuild'] = $session->get(self::UPLOAD_FORM_BUILD_PARAMETER_NAME); $vars['uploadFormBuildParameterName'] = self::UPLOAD_FORM_BUILD_PARAMETER_NAME; if (@$_SESSION[Auth::USER_LEVEL] >= PLUGIN_DB_WRITE) { $skip = array("agent_unpack", "agent_adj2nest", "wget_agent"); $vars['agentCheckBoxMake'] = AgentCheckBoxMake(-1, $skip); } return $this->handleView($request, $vars); }
/** * @param int $folderId * @param int $trustGroupId * @return UploadProgress[] */ protected function prepareFolderUploads($folderId, $trustGroupId = null) { if (empty($trustGroupId)) { $trustGroupId = Auth::getGroupId(); } $folderUploads = $this->folderDao->getFolderUploads($folderId, $trustGroupId); $uploadsById = array(); foreach ($folderUploads as $uploadProgress) { $key = $uploadProgress->getId() . ',' . $uploadProgress->getGroupId(); $display = $uploadProgress->getFilename() . _(" from ") . date("Y-m-d H:i", $uploadProgress->getTimestamp()) . ' (' . $uploadProgress->getStatusString() . ')'; $uploadsById[$key] = $display; } return $uploadsById; }
/** * @brief kludge for plugins not supplying a folder parameter. * Find what folder this upload is in. */ private function getFolderId($uploadId) { $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId()); if (empty($uploadId)) { return $rootFolder->getId(); } global $container; /* @var $dbManager DbManager */ $dbManager = $container->get('db.manager'); $uploadExists = $dbManager->getSingleRow("SELECT count(*) cnt FROM upload WHERE upload_pk=\$1", array($uploadId)); if ($uploadExists['cnt'] < 1) { throw new Exception("This upload no longer exists on this system."); } $folderTreeCte = $this->folderDao->getFolderTreeCte($rootFolder); $parent = $dbManager->getSingleRow($folderTreeCte . " SELECT ft.folder_pk FROM foldercontents fc LEFT JOIN folder_tree ft ON fc.parent_fk=ft.folder_pk " . "WHERE child_id=\$2 AND foldercontents_mode=\$3 ORDER BY depth LIMIT 1", array($rootFolder->getId(), $uploadId, FolderDao::MODE_UPLOAD), __METHOD__ . '.parent'); if (!$parent) { throw new Exception("Upload {$uploadId} missing from foldercontents in your foldertree."); } return $parent['folder_pk']; }
public function Output() { $groupId = Auth::getGroupId(); $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId()); $folderStructure = $this->folderDao->getFolderStructure($rootFolder->getId()); $V = ""; $folder_pk = GetParm('folder', PARM_INTEGER); if (empty($folder_pk)) { $folder_pk = $rootFolder->getId(); } $NewName = GetArrayVal("newname", $_POST); $NewDesc = GetArrayVal("newdesc", $_POST); $upload_pk = GetArrayVal("upload_pk", $_POST); if (empty($upload_pk)) { $upload_pk = GetParm('upload', PARM_INTEGER); } /* Check Upload permission */ if (!empty($upload_pk) && !$this->uploadDao->isEditable($upload_pk, $groupId)) { $text = _("Permission Denied"); return "<h2>{$text}</h2>"; } $rc = $this->UpdateUploadProperties($upload_pk, $NewName, $NewDesc); if ($rc == 0) { $text = _("Nothing to Change"); $this->vars['message'] = $text; } else { if ($rc == 1) { $text = _("Upload Properties successfully changed"); $this->vars['message'] = $text; } } $this->vars['folderStructure'] = $folderStructure; $this->vars['folderId'] = $folder_pk; $this->vars['baseUri'] = $Uri = Traceback_uri() . "?mod=" . $this->Name . "&folder="; $folderUploads = $this->folderDao->getFolderUploads($folder_pk, $groupId); $uploadsById = array(); /* @var $uploadProgress UploadProgress */ foreach ($folderUploads as $uploadProgress) { if ($uploadProgress->getGroupId() != $groupId) { continue; } if (!$this->uploadDao->isEditable($uploadProgress->getId(), $groupId)) { continue; } $display = $uploadProgress->getFilename() . _(" from ") . date("Y-m-d H:i", $uploadProgress->getTimestamp()); $uploadsById[$uploadProgress->getId()] = $display; } $this->vars['uploadList'] = $uploadsById; if (empty($upload_pk)) { reset($uploadsById); $upload_pk = key($uploadsById); } $this->vars['uploadId'] = $upload_pk; if ($upload_pk) { $upload = $this->uploadDao->getUpload($upload_pk); if (empty($upload)) { $this->vars['message'] = _("Missing upload."); return 0; } } else { $upload = null; } $baseFolderUri = $this->vars['baseUri'] . "{$folder_pk}&upload="; $this->vars['uploadAction'] = "onchange=\"js_url(this.value, '{$baseFolderUri}')\""; $this->vars['uploadFilename'] = $upload ? $upload->getFilename() : ''; $this->vars['uploadDesc'] = $upload ? $upload->getDescription() : ''; $this->vars['content'] = $V; return $this->render('admin_upload_edit.html.twig'); }