10 namespace Fossology\Reso;
17 include_once(__DIR__ .
"/version.php");
31 const REUSE_FILE_SUFFIX =
".license";
50 parent::__construct(RESO_AGENT_NAME, AGENT_VERSION, AGENT_REV);
51 $this->uploadDao = $this->container->get(
'dao.upload');
52 $this->agentDao = $this->container->get(
'dao.agent');
64 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
67 if (empty($reSoUploadFiles)) {
84 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
86 $stmt = __METHOD__ .
'reSo_files'.self::REUSE_FILE_SUFFIX;
87 $sql =
"SELECT * FROM $uploadTreeTableName
88 WHERE upload_fk=$1 AND pfile_fk != 0 AND ufile_name like '%" . self::REUSE_FILE_SUFFIX .
"' ";
91 $res = $this->
dbManager->execute($stmt,$param);
104 $mergedArray = array();
105 foreach ($reSoUploadFiles as $row) {
107 if (!empty($baseFileRow)) {
108 $row[
'assoc_file'] = $baseFileRow;
109 $mergedArray[] = $row;
123 $stmt = __METHOD__ .
'find_reso_base_file';
124 $sql =
"SELECT * FROM $uploadTreeTableName
125 WHERE upload_fk=$1 AND ufile_name =$2 AND pfile_fk != 0 AND realparent=$3";
126 $param[] = $row[
'upload_fk'];
127 $param[] = substr($row[
'ufile_name'],0,-1 * abs(strlen(self::REUSE_FILE_SUFFIX)));
128 $param[] = $row[
'realparent'];
130 $res = $this->
dbManager->execute($stmt,$param);
144 $latestOjoAgent=$this->agentDao->agentARSList(
"ojo_ars",$uploadId);
145 $resoAgentId=$this->agentDao->getCurrentAgentId(
"reso");
147 foreach ($linkedFiles as $file) {
150 $insertParam = array();
151 $stmt = __METHOD__ .
'readLicenseFindingsOjo';
152 $sql =
"SELECT * FROM license_file
153 WHERE pfile_fk =$1 AND agent_fk=$2 AND rf_fk IS NOT NULL";
154 $param[] = $file[
'pfile_fk'];
155 $param[] = $latestOjoAgent[0][
'agent_fk'];
158 $res = $this->
dbManager->execute($stmt,$param);
159 while ($row=$this->
dbManager->fetchArray($res)) {
160 $insertParam = array();
161 $Istmt = __METHOD__ .
'insertLicenseFindingsReso';
162 $Isql =
"INSERT INTO license_file(rf_fk, agent_fk, pfile_fk)
163 (SELECT $1, $2, $3 WHERE NOT EXISTS (SELECT fl_pk FROM license_file where rf_fk=$1 AND agent_fk=$2 AND pfile_fk=$3))
165 $insertParam[] = $row[
'rf_fk'];
166 $insertParam[] = $resoAgentId;
167 $insertParam[] = $file[
'assoc_file'][0][
'pfile_fk'];
169 $this->
dbManager->prepare($Istmt, $Isql);
170 $Ires = $this->
dbManager->execute($Istmt,$insertParam);
185 $latestCopyrightAgent = $this->agentDao->agentARSList(
"copyright_ars",$uploadId);
186 $resoAgentId = $this->agentDao->getCurrentAgentId(
"reso");
187 if (empty($latestCopyrightAgent)) {
191 foreach ($linkedFiles as $file) {
194 $insertParam = array();
195 $stmt = __METHOD__ .
'readCopyrightFindings';
196 $sql =
"SELECT * FROM copyright WHERE pfile_fk =$1 AND agent_fk=$2";
197 $param[] = $file[
'pfile_fk'];
198 $param[] = $latestCopyrightAgent[0][
'agent_fk'];
201 $res = $this->
dbManager->execute($stmt,$param);
202 while ($row=$this->
dbManager->fetchArray($res)) {
203 $copytightrec = $this->
dbManager->getSingleRow(
"SELECT * FROM copyright WHERE agent_fk=$1 AND pfile_fk=$2 AND hash=md5($3)", array($resoAgentId, $file[
'assoc_file'][0][
'pfile_fk'], $row[
'content']), __METHOD__.
'checkExistingCopyright');
204 if (empty($copytightrec)) {
205 $insertParam = array();
206 $Insertstmt = __METHOD__ .
'insertCopyrightFindingsReso';
207 $Insertsql =
"INSERT INTO copyright(agent_fk, pfile_fk, content, hash, type, copy_startbyte, copy_endbyte) VALUES ($1, $2, $3, md5($3), $4, $5, $6)";
208 $insertParam[] = $resoAgentId;
209 $insertParam[] = $file[
'assoc_file'][0][
'pfile_fk'];
210 $insertParam[] = $row[
'content'];
211 $insertParam[] = $row[
'type'];
214 $this->
dbManager->prepare($Insertstmt, $Insertsql);
215 $Insertresult = $this->
dbManager->execute($Insertstmt,$insertParam);
Structure of an Agent with all required parameters.
heartbeat($newProcessed)
Send hear beat to the scheduler.
copyCopyrightFindings($linkedFiles, $uploadId)
Copy copyright from .license file to base file.
processUploadId($uploadId)
Run reso for a package.
copyOjoFindings($linkedFiles, $uploadId)
Copy license from licene holder to base file.
associateBaseFile($reSoUploadFiles, $uploadTreeTableName)
Find and associate base file to files containting license info.
findAssociatedFile($row, $uploadTreeTableName)
Find associated base file.
findReSoUploadFiles($uploadId)
Find all files with specific suffix.
fo_dbManager * dbManager
fo_dbManager object