8 namespace Fossology\Lib\Proxy;
12 const ARS_SUFFIX =
'_ars';
16 private $columns =
'agent_pk, agent_name';
26 public function __construct($uploadId, $agentNames=array(
'nomos',
'monk'), $dbViewName=
'latest_scanner', $andEnabled =
"AND agent_enabled")
28 if (empty($agentNames)) {
29 throw new \Exception(
'empty set of scanners');
31 $this->uploadId = $uploadId;
32 $subqueries = array();
33 foreach ($agentNames as $name) {
35 $subqueries[] =
"SELECT * FROM (SELECT $this->columns FROM $name".self::ARS_SUFFIX.
", agent
36 WHERE agent_fk=agent_pk AND upload_fk=$uploadId $andEnabled ORDER BY agent_fk DESC limit 1) latest_$name";
38 $dbViewQuery = implode(
' UNION ',$subqueries);
39 parent::__construct($dbViewQuery, $dbViewName.
"_".implode(
"_",$agentNames));
44 if (!is_int($this->uploadId)) {
45 throw new \Exception(
'cannot materialize LatestScannerProxy because upload Id is no number');
47 parent::materialize();
55 if (!is_int($this->uploadId)) {
56 throw new \Exception(
'cannot map LatestScannerProxy because upload Id is no number');
59 $dbManager = $container->get(
'db.manager');
60 $stmt = __METHOD__.
".$this->dbViewName";
61 if ($this->materialized) {
63 $sql =
"SELECT * FROM $this->dbViewName";
65 $sql = $this->dbViewQuery;
70 $dbManager->prepare($stmt, $sql);
71 $res = $dbManager->execute($stmt, array());
72 while ($row = $dbManager->fetchArray($res)) {
73 $map[$row[
'agent_name']] = $row[
'agent_pk'];
75 $dbManager->freeResult($res);
materialize()
create temp table
__construct($uploadId, $agentNames=array('nomos', 'monk'), $dbViewName='latest_scanner', $andEnabled="AND agent_enabled")
getNameToIdMap()
create temp table