23 const ARS_SUFFIX =
'_ars';
27 private $columns =
'agent_pk, agent_name';
37 public function __construct($uploadId, $agentNames=array(
'nomos',
'monk'), $dbViewName=
'latest_scanner', $andEnabled =
"AND agent_enabled")
39 if (empty($agentNames)) {
40 throw new \Exception(
'empty set of scanners');
42 $this->uploadId = $uploadId;
43 $subqueries = array();
44 foreach ($agentNames as $name) {
46 $subqueries[] =
"SELECT * FROM (SELECT $this->columns FROM $name".self::ARS_SUFFIX.
", agent 47 WHERE agent_fk=agent_pk AND upload_fk=$uploadId $andEnabled ORDER BY agent_fk DESC limit 1) latest_$name";
49 $dbViewQuery = implode(
' UNION ',$subqueries);
50 parent::__construct($dbViewQuery, $dbViewName.
"_".implode(
"_",$agentNames));
53 public function materialize()
55 if (!is_int($this->uploadId)) {
56 throw new \Exception(
'cannot materialize LatestScannerProxy because upload Id is no number');
58 parent::materialize();
66 if (!is_int($this->uploadId)) {
67 throw new \Exception(
'cannot map LatestScannerProxy because upload Id is no number');
70 $dbManager = $container->get(
'db.manager');
71 $stmt = __METHOD__.
".$this->dbViewName";
72 if ($this->materialized) {
74 $sql =
"SELECT * FROM $this->dbViewName";
76 $sql = $this->dbViewQuery;
81 $dbManager->prepare($stmt, $sql);
82 $res = $dbManager->execute($stmt, array());
83 while ($row = $dbManager->fetchArray($res)) {
84 $map[$row[
'agent_name']] = $row[
'agent_pk'];
86 $dbManager->freeResult($res);
__construct($uploadId, $agentNames=array('nomos','monk'), $dbViewName='latest_scanner', $andEnabled="AND agent_enabled")
getNameToIdMap()
create temp table