33 public function __construct(
DbManager $dbManager)
36 $this->logger =
new Logger(self::class);
39 public function getFullPath($itemId, $tableName, $parentId=0, $dropArtifactPrefix=
false)
41 $statementName = __METHOD__.
".".$tableName;
43 if ($parentId==$itemId) {
44 return $this->getFullPath($itemId, $tableName);
45 }
else if ($parentId > 0) {
46 $params = array($itemId, $parentId);
47 $parentClause =
" = $2";
48 $parentLoopCondition =
"AND (ut.parent != $2)";
49 $statementName .=
".parent";
51 $params = array($itemId);
52 $parentClause =
" IS NULL";
53 $parentLoopCondition =
"";
58 WITH RECURSIVE file_tree(uploadtree_pk, parent, ufile_name, path, prev_ufile_mode, artifact_path_prefix, file_path, cycle) AS ( 59 SELECT ut.uploadtree_pk, ut.parent, ut.ufile_name, 60 ARRAY[ut.uploadtree_pk], 63 CASE WHEN ut.ufile_mode & (1<<28) = 0 THEN ut.ufile_name ELSE '' END, 66 WHERE ut.uploadtree_pk = $1 68 SELECT ut.uploadtree_pk, ut.parent, ut.ufile_name, 69 path || ut.uploadtree_pk, 71 CASE WHEN prev_ufile_mode & (1<<28) = 0 73 CASE WHEN ut.ufile_mode & (1<<28) = 0 75 ELSE artifact_path_prefix 78 CASE WHEN ut.ufile_mode & (1<<28) = 0 79 THEN ut.ufile_name || '/' || artifact_path_prefix 80 ELSE artifact_path_prefix 83 CASE WHEN (prev_ufile_mode & (1<<28) = 0 and ut.ufile_mode & (1<<28) = 0) 84 THEN ut.ufile_name || '/' || artifact_path_prefix || file_path 87 (ut.uploadtree_pk = ANY(path)) $parentLoopCondition 88 FROM $tableName ut, file_tree ft 89 WHERE ut.uploadtree_pk = ft.parent AND NOT cycle 91 SELECT artifact_path_prefix, file_path from file_tree WHERE parent $parentClause",
92 $params, $statementName);
95 throw new \Exception(
"could not find path of $itemId:\n$sql--".print_r($params,
true));
98 if (! $dropArtifactPrefix) {
99 return $row[
'artifact_path_prefix'].$row[
'file_path'];
101 return $row[
'file_path'];
105 public function getMinimalCoveringItem($uploadId, $tableName)
107 $statementName = __METHOD__.
".".$tableName;
110 "SELECT uploadtree_pk FROM $tableName ut WHERE ut.upload_fk = $1 112 SELECT 1 FROM $tableName ut2 WHERE ut2.upload_fk = $1 113 AND NOT (ut2.lft BETWEEN ut.lft AND ut.rgt) 114 AND (ut2.ufile_mode & (3<<28) = 0) 116 ORDER BY ut.lft DESC LIMIT 1",
121 return $row ? $row[
'uploadtree_pk'] : 0;
128 public function getItemHashes($uploadtreeId, $uploadtreeTablename=
'uploadtree')
130 $pfile = $this->
dbManager->getSingleRow(
"SELECT pfile.* FROM $uploadtreeTablename, pfile WHERE uploadtree_pk=$1 AND pfile_fk=pfile_pk",
131 array($uploadtreeId), __METHOD__);
132 return array(
'sha1'=>$pfile[
'pfile_sha1'],
'md5'=>$pfile[
'pfile_md5'],
'sha256'=>$pfile[
'pfile_sha256']);
135 public function getRepoPathOfPfile($pfileId, $repo=
"files")
137 $pfileRow = $this->
dbManager->getSingleRow(
'SELECT * FROM pfile WHERE pfile_pk=$1',array($pfileId));
139 if (empty($pfileRow[
'pfile_sha1'])) {
142 $hash = $pfileRow[
'pfile_sha1'] .
"." . $pfileRow[
'pfile_md5'] .
"." . $pfileRow[
'pfile_size'];
144 exec(
"$LIBEXECDIR/reppath $repo $hash", $path);
fo_dbManager * dbManager
fo_dbManager object
getItemHashes($uploadtreeId, $uploadtreeTablename='uploadtree')