10 namespace Fossology\Lib\Dao;
23 public function __construct(
DbManager $dbManager)
26 $this->logger =
new Logger(self::class);
29 public function getFullPath($itemId, $tableName, $parentId=0, $dropArtifactPrefix=
false)
31 $statementName = __METHOD__.
".".$tableName;
33 if ($parentId==$itemId) {
34 return $this->getFullPath($itemId, $tableName);
35 }
else if ($parentId > 0) {
36 $params = array($itemId, $parentId);
37 $parentClause =
" = $2";
38 $parentLoopCondition =
"AND (ut.parent != $2)";
39 $statementName .=
".parent";
41 $params = array($itemId);
42 $parentClause =
" IS NULL";
43 $parentLoopCondition =
"";
48 WITH RECURSIVE file_tree(uploadtree_pk, parent, ufile_name, path, prev_ufile_mode, artifact_path_prefix, file_path, cycle) AS (
49 SELECT ut.uploadtree_pk, ut.parent, ut.ufile_name,
50 ARRAY[ut.uploadtree_pk],
53 CASE WHEN ut.ufile_mode & (1<<28) = 0 THEN ut.ufile_name ELSE '' END,
56 WHERE ut.uploadtree_pk = $1
58 SELECT ut.uploadtree_pk, ut.parent, ut.ufile_name,
59 path || ut.uploadtree_pk,
61 CASE WHEN prev_ufile_mode & (1<<28) = 0
63 CASE WHEN ut.ufile_mode & (1<<28) = 0
65 ELSE artifact_path_prefix
68 CASE WHEN ut.ufile_mode & (1<<28) = 0
69 THEN ut.ufile_name || '/' || artifact_path_prefix
70 ELSE artifact_path_prefix
73 CASE WHEN (prev_ufile_mode & (1<<28) = 0 and ut.ufile_mode & (1<<28) = 0)
74 THEN ut.ufile_name || '/' || artifact_path_prefix || file_path
77 (ut.uploadtree_pk = ANY(path)) $parentLoopCondition
78 FROM $tableName ut, file_tree ft
79 WHERE ut.uploadtree_pk = ft.parent AND NOT cycle
81 SELECT artifact_path_prefix, file_path from file_tree WHERE parent $parentClause",
82 $params, $statementName);
85 throw new \Exception(
"could not find path of $itemId:\n$sql--".print_r($params,
true));
88 if (! $dropArtifactPrefix) {
89 return $row[
'artifact_path_prefix'].$row[
'file_path'];
91 return $row[
'file_path'];
95 public function getMinimalCoveringItem($uploadId, $tableName)
97 $statementName = __METHOD__.
".".$tableName;
100 "SELECT uploadtree_pk FROM $tableName ut WHERE ut.upload_fk = $1
102 SELECT 1 FROM $tableName ut2 WHERE ut2.upload_fk = $1
103 AND NOT (ut2.lft BETWEEN ut.lft AND ut.rgt)
104 AND (ut2.ufile_mode & (3<<28) = 0)
106 ORDER BY ut.lft DESC LIMIT 1",
111 return $row ? $row[
'uploadtree_pk'] : 0;
118 public function getItemHashes($uploadtreeId, $uploadtreeTablename=
'uploadtree')
120 $pfile = $this->
dbManager->getSingleRow(
"SELECT pfile.* FROM $uploadtreeTablename, pfile WHERE uploadtree_pk=$1 AND pfile_fk=pfile_pk",
121 array($uploadtreeId), __METHOD__);
122 return array(
'sha1'=>$pfile[
'pfile_sha1'],
'md5'=>$pfile[
'pfile_md5'],
'sha256'=>$pfile[
'pfile_sha256']);
125 public function getRepoPathOfPfile($pfileId, $repo=
"files")
127 $pfileRow = $this->
dbManager->getSingleRow(
'SELECT * FROM pfile WHERE pfile_pk=$1',array($pfileId));
129 if (empty($pfileRow[
'pfile_sha1'])) {
132 $hash = $pfileRow[
'pfile_sha1'] .
"." . $pfileRow[
'pfile_md5'] .
"." . $pfileRow[
'pfile_size'];
134 exec(
"$LIBEXECDIR/reppath $repo $hash", $path);
145 $item = $itemTreeBounds->getItemId();
146 $tableName = $itemTreeBounds->getUploadTreeTableName();
147 $sql =
"SELECT realparent FROM $tableName WHERE uploadtree_pk = $1;";
148 $statement = __METHOD__ .
".$tableName";
149 $row = $this->
dbManager->getSingleRow($sql, [$item], $statement);
150 return $row[
'realparent'];
getItemHashes($uploadtreeId, $uploadtreeTablename='uploadtree')
getParentOfItem($itemTreeBounds)
fo_dbManager * dbManager
fo_dbManager object