8 namespace Fossology\Lib\Dao;
32 private $defaultCompatibility;
39 $this->logger = $logger;
40 $this->licenseDao = $licenseDao;
41 $this->agentDao = $agentDao;
42 $this->agentName =
"compatibility";
43 $sql =
"SELECT compatibility FROM license_rules
44 WHERE first_rf_fk IS NULL AND second_rf_fk IS NULL
45 AND first_type IS NULL AND second_type IS NULL;";
46 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
48 if (!empty($result) && array_key_exists(
"compatibility", $result)) {
49 $this->defaultCompatibility = $result[
"compatibility"];
51 $this->defaultCompatibility =
false;
63 public function getCompatibilityForFile($itemTreeBounds, $shortname)
65 $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
66 $uploadTreePk = $itemTreeBounds->getItemId();
67 $stmt = __METHOD__.$uploadTreeTableName;
68 $sql =
"SELECT pfile_fk FROM $uploadTreeTableName UT
69 WHERE UT.uploadtree_pk = $1";
70 $result = $this->
dbManager->getSingleRow($sql, [$uploadTreePk], $stmt);
71 $pfileId = $result[
"pfile_fk"];
72 $uploadId = $itemTreeBounds->getUploadId();
74 $scanJobProxy =
new ScanJobProxy($this->agentDao, $uploadId);
75 $scanJobProxy->createAgentStatus([$this->agentName]);
76 $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
77 if (!array_key_exists($this->agentName, $selectedScanners)) {
79 " has not been scheduled/completed on the upload.");
81 $latestAgentId = $selectedScanners[$this->agentName];
82 $license = $this->licenseDao->getLicenseByShortName($shortname, $groupId=
null);
83 if ($license ===
null) {
86 $licenseId = $license->getId();
87 $stmt = __METHOD__ .
"getCompResult";
88 $sql =
"SELECT result FROM comp_result
89 WHERE pfile_fk = $1 AND agent_fk= $2 AND result = FALSE AND
90 (first_rf_fk = $3 OR second_rf_fk = $3);";
91 $res = $this->
dbManager->getSingleRow($sql,
92 [$pfileId, $latestAgentId, $licenseId], $stmt);
102 $sql =
"SELECT lr_pk, first_rf_fk, second_rf_fk, first_type, second_type,
103 comment, compatibility
104 FROM license_rules ORDER BY lr_pk;";
118 function insertRule($firstName, $secondName, $firstType, $secondType, $comment,
125 $comment =
trim($comment);
126 if (empty($comment)) {
131 'first_rf_fk' => $firstName,
132 'second_rf_fk' => $secondName,
133 'first_type' => $firstType,
134 'second_type' => $secondType,
135 'comment' => $comment,
136 'compatibility' => $result
138 $statement = __METHOD__ .
".insertNewLicCompatibilityRule";
139 $returning =
"lr_pk";
142 $returnVal = $this->
dbManager->insertTableRow(
"license_rules",
143 $params, $statement, $returning);
163 foreach ($ruleArray as $rulePk => $rule) {
164 if (count($rule) < 1) {
165 throw new \UnexpectedValueException(
"Rule has no values");
168 $statement = __METHOD__;
170 $updateStatement = [];
171 if (array_key_exists(
"firstLic", $rule)) {
172 $params[] = $rule[
"firstLic"];
173 $updateStatement[] =
"first_rf_fk = $" . count($params);
174 $statement .=
".first_rf_fk";
176 if (array_key_exists(
"secondLic", $rule)) {
177 $params[] = $rule[
"secondLic"];
178 $updateStatement[] =
"second_rf_fk = $" . count($params);
179 $statement .=
".second_rf_fk";
181 if (array_key_exists(
"firstType", $rule)) {
182 $params[] = $rule[
"firstType"];
183 $updateStatement[] =
"first_type = $" . count($params);
184 $statement .=
".first_type";
186 if (array_key_exists(
"secondType", $rule)) {
187 $params[] = $rule[
"secondType"];
188 $updateStatement[] =
"second_type = $" . count($params);
189 $statement .=
".second_type";
191 if (array_key_exists(
"comment", $rule)) {
192 $params[] = $rule[
"comment"];
193 $updateStatement[] =
"comment = $" . count($params);
194 $statement .=
".comment";
196 if (array_key_exists(
"result", $rule)) {
197 $params[] = $rule[
"result"];
198 $updateStatement[] =
"compatibility = $" . count($params);
199 $statement .=
".compatibility";
201 $sql =
"UPDATE license_rules " .
202 "SET " . join(
",", $updateStatement) .
203 " WHERE lr_pk = $1 " .
204 "RETURNING 1 AS updated;";
205 $retVal = $this->
dbManager->getSingleRow($sql, $params, $statement);
206 $updated += intval($retVal[
"updated"]);
218 if (! is_int($rulePk)) {
219 throw new \UnexpectedValueException(
"Invalid rule id $rulePk");
221 $sql =
"SELECT count(*) AS cnt FROM license_rules " .
224 $ruleCount = $this->
dbManager->getSingleRow($sql, [$rulePk]);
225 if ($ruleCount[
'cnt'] < 1) {
227 throw new \UnexpectedValueException(
"Invalid rule id $rulePk");
243 $stmt = __METHOD__ .
"DeletionOfRule";
244 $sql =
"DELETE FROM license_rules " .
245 "WHERE lr_pk = $1 " .
248 $retVal = $this->
dbManager->getSingleRow($sql, [$rulePk], $stmt);
249 if ($retVal[
"lr_pk"] == $rulePk) {
262 return $this->defaultCompatibility;
Contains the constants and helpers for authentication of user.
static isAdmin()
Check if user is admin.
deleteRule($rulePk)
Delete a license compatibility rule.
getDefaultCompatibility()
updateRuleFromArray($ruleArray)
Update the existing rules.
insertRule($firstName, $secondName, $firstType, $secondType, $comment, $result)
Insert new rule in the database.
isRuleIdValid($rulePk)
Check if rule ID exists in DB.
getAllRules()
Get all the existing rules present in the database.
Exception when an agent's stage is invalid.
char * trim(char *ptext)
Trimming whitespace.
fo_dbManager * dbManager
fo_dbManager object