FOSSology  4.4.0
Open Source License Compliance by Open Source Software
PackageDao.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\Dao;
9 
10 
14 use Monolog\Logger;
15 
17 {
18 
20  private $dbManager;
21 
26  public function __construct(DbManager $dbManager, Logger $logger)
27  {
28  $this->dbManager = $dbManager;
29  $this->logger = $logger;
30  }
31 
36  public function findPackageForUpload($uploadId)
37  {
38  $statementName = __METHOD__;
39 
40  $this->dbManager->prepare($statementName, "
41 SELECT p.*, u.*
42 FROM package p
43  INNER JOIN upload_packages up ON p.package_pk = up.package_fk
44  INNER JOIN upload_packages up2 ON p.package_pk = up2.package_fk
45  INNER JOIN upload u ON up2.upload_fk = u.upload_pk
46 WHERE up.upload_fk = $1
47 ORDER BY up2.upload_fk ASC");
48  $res = $this->dbManager->execute($statementName, array($uploadId));
49  $packageId = 0;
50  $packageName = "";
51  $uploads = array();
52  while ($row = $this->dbManager->fetchArray($res)) {
53  $packageId = intval($row['package_pk']);
54  $packageName = $row['package_name'];
55  $uploads[] = Upload::createFromTable($row);
56  }
57  $this->dbManager->freeResult($res);
58  return $packageId > 0 ? new Package($packageId, $packageName, $uploads) : null;
59  }
60 
64  public function createPackage($packageName)
65  {
66  $statementName = __METHOD__;
67 
68  $row = $this->dbManager->getSingleRow(
69  "INSERT INTO package (package_name) VALUES($1) RETURNING package_pk",
70  array($packageName), $statementName);
71  return new Package(intval($row['package_pk']), $packageName, array());
72  }
73 
78  public function addUploadToPackage($uploadId, Package $package)
79  {
80  $statementName = __METHOD__;
81 
82  $this->dbManager->prepare($statementName,
83  "INSERT INTO upload_packages (package_fk, upload_fk) VALUES($1, $2)");
84  $res = $this->dbManager->execute($statementName, array($package->getId(), $uploadId));
85  $this->dbManager->freeResult($res);
86  }
87 }
__construct(DbManager $dbManager, Logger $logger)
Definition: PackageDao.php:26
addUploadToPackage($uploadId, Package $package)
Definition: PackageDao.php:78
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16