30 use \Symfony\Component\HttpFoundation\Request;
35 const NAME =
"ajax_sh_browser";
37 private $uploadtree_tablename =
"";
55 protected $agentNames = array(
'softwareHeritage' =>
'SH');
57 public function __construct()
59 parent::__construct(self::NAME, array(
60 self::TITLE => _(
"Ajax: File Browser"),
61 self::DEPENDENCIES => array(
"fileBrowse"),
63 self::REQUIRES_LOGIN =>
false 66 $this->uploadDao = $this->
getObject(
'dao.upload');
67 $this->licenseDao = $this->
getObject(
'dao.license');
68 $this->agentDao = $this->
getObject(
'dao.agent');
69 $this->shDao = $this->container->get(
'dao.softwareHeritage');
70 $this->configuration = parse_ini_file(__DIR__ .
'/../agent/softwareHeritage.conf');
77 public function handle(Request $request)
79 $upload = intval($request->get(
"upload"));
80 $groupId = Auth::getGroupId();
81 if (!$this->uploadDao->isAccessible($upload, $groupId)) {
82 throw new \Exception(
"Permission Denied");
85 $item = intval($request->get(
"item"));
87 $itemTreeBounds = $this->uploadDao->getItemTreeBounds($item, $this->uploadtree_tablename);
88 $left = $itemTreeBounds->getLeft();
90 throw new \Exception(
"Job unpack/adj2nest hasn't completed.");
93 $scannerAgents = array_keys($this->agentNames);
94 $scanJobProxy =
new ScanJobProxy($this->agentDao, $upload);
95 $scanJobProxy->createAgentStatus($scannerAgents);
96 $selectedAgentId = intval($request->get(
'agentId'));
97 $tag_pk = intval($request->get(
'tag'));
99 $UniqueTagArray = array();
100 $this->licenseProjector =
new LicenseMap($this->
getObject(
'db.manager'),$groupId,LicenseMap::CONCLUSION,
true);
101 $vars = $this->
createFileListing($tag_pk, $itemTreeBounds, $UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy);
103 return new JsonResponse(array(
104 'sEcho' => intval($request->get(
'sEcho')),
105 'aaData' => $vars[
'fileData'],
106 'iTotalRecords' => $vars[
'iTotalDisplayRecords'],
107 'iTotalDisplayRecords' => $vars[
'iTotalDisplayRecords']
122 if (!empty($selectedAgentId)) {
123 $agentName = $this->agentDao->getAgentName($selectedAgentId);
124 $selectedScanners = array($agentName=>$selectedAgentId);
126 $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
131 $isFlat = isset($_GET[
'flatten']);
134 $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds);
136 $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->
getItemId());
141 $vars[
'iTotalDisplayRecords'] = $descendantView->
count();
143 $columnNamesInDatabase = array($isFlat?
'ufile_name':
'lft');
144 $defaultOrder = array(array(0,
"asc"));
145 $orderString = $this->
getObject(
'utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder);
150 $orderString .=
" OFFSET $offset";
153 $orderString .=
" LIMIT $limit";
157 $sql = $descendantView->getDbViewQuery().
" $orderString";
158 $dbManager = $this->
getObject(
'db.manager');
160 $dbManager->prepare($stmt=__METHOD__.$orderString,$sql);
161 $res = $dbManager->execute($stmt,$descendantView->getParams());
162 $descendants = $dbManager->fetchAll($res);
163 $dbManager->freeResult($res);
166 if (!empty($tagId)) {
169 if (empty($descendants)) {
170 $vars[
'fileData'] = array();
175 $firstChild = reset($descendants);
176 $lastChild = end($descendants);
177 $nameRange = array($firstChild[
'ufile_name'],$lastChild[
'ufile_name']);
179 $nameRange = array();
183 $pfileLicenses = array();
184 foreach ($selectedScanners as $agentName=>$agentId) {
185 $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId($itemTreeBounds, $agentId, $isFlat, $nameRange);
186 foreach ($licensePerPfile as $pfile => $licenseRow) {
187 foreach ($licenseRow as $licId => $row) {
188 $lic = $this->licenseProjector->getProjectedShortname($licId);
189 $pfileLicenses[$pfile][$lic][$agentName] = $row;
196 $tableData = array();
197 $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
198 foreach ($descendants as $child) {
203 $baseUri, $UniqueTagArray, $isFlat);
206 $vars[
'fileData'] = $tableData;
219 private function createFileDataRow($child, $uploadId, $selectedAgentId, $uri, &$UniqueTagArray, $isFlat)
221 $fileId = $child[
'pfile_fk'];
222 $childUploadTreeId = $child[
'uploadtree_pk'];
224 if (!empty($fileId)) {
226 $linkUri .=
"?mod=view-license&upload=$uploadId&item=$childUploadTreeId";
227 if ($selectedAgentId) {
228 $linkUri .=
"&agentId=$selectedAgentId";
234 if ($isContainer && !$isFlat) {
235 $uploadtree_pk = $child[
'uploadtree_pk'];
236 $linkUri =
"$uri&item=" . $uploadtree_pk;
237 if ($selectedAgentId) {
238 $linkUri .=
"&agentId=$selectedAgentId";
240 }
else if ($isContainer) {
242 $linkUri =
"$uri&item=" . $uploadtree_pk;
243 if ($selectedAgentId) {
244 $linkUri .=
"&agentId=$selectedAgentId";
250 $fileName = htmlspecialchars($child[
'ufile_name']);
252 $fileName =
"<a href='$linkUri'><span style='color: darkblue'> <b>$fileName</b> </span></a>";
253 }
else if (!empty($linkUri)) {
254 $fileName =
"<a href='$linkUri'>$fileName</a>";
257 $pfileHash = $this->uploadDao->getUploadHashesFromPfileId($fileId);
258 $shRecord = $this->shDao->getSoftwareHetiageRecord($fileId);
261 if (! $isContainer) {
262 $text = _(
"Software Heritage");
263 $shLink = $this->configuration[
'api'][
'url'].$this->configuration[
'api'][
'uri'].$pfileHash[
"sha256"].$this->configuration[
'api'][
'content'];
264 $fileListLinks .=
"[<a href='".$shLink.
"' target=\"_blank\">$text</a>]";
267 if (! $isContainer) {
268 $img = $shRecord[
"img"];
271 return [$fileName, $pfileHash[
"sha256"], $shRecord[
"license"], $img, $fileListLinks];
Traceback_uri()
Get the URI without query to this location.
createFileDataRow($child, $uploadId, $selectedAgentId, $uri, &$UniqueTagArray, $isFlat)
FileListLinks($upload_fk, $uploadtree_pk, $napk, $pfile_pk, $Recurse=True, &$UniqueTagArray=array(), $uploadtree_tablename="uploadtree", $wantTags=true)
Get list of links: [View][Info][Download]
Wrapper class for license map.
DirGetNonArtifact($UploadtreePk, $uploadtree_tablename='uploadtree')
Given an artifact directory (uploadtree_pk), return the first non-artifact directory (uploadtree_pk)...
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy)
char * uploadtree_tablename
upload.uploadtree_tablename
#define PERM_READ
Read-only permission.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.