34 private $fileNameCache = array();
41 public function __construct($groupBy =
"content")
45 $this->uploadDao = $container->get(
'dao.upload');
46 $this->treeDao = $container->get(
'dao.tree');
48 $this->groupBy = $groupBy;
51 public function getCliArgs()
53 $args = getopt(
"u:", array(
"uId:",
"gId:"));
55 if (!array_key_exists(
'u',$args)) {
56 throw new Exception(
"missing required parameter -u {uploadId}\n",2);
59 $this->uploadId = intval($args[
'u']);
60 $this->userId = intval(@$args[
'uId']);
61 $this->groupId = intval(@$args[
'gId']);
64 public function getUploadId()
66 $uploadId = $this->uploadId;
69 print
"invalid uploadId ".$uploadId;
75 public function getUserId()
77 $userId = $this->userId;
80 print
"invalid user ".$userId;
86 public function getGroupId()
88 $groupId = $this->groupId;
91 print
"invalid group ".$groupId;
97 protected function changeTreeIdsToPaths(&$ungrupedStatements, $uploadTreeTableName, $uploadId)
99 $parentId = $this->treeDao->getMinimalCoveringItem($uploadId, $uploadTreeTableName);
101 foreach ($ungrupedStatements as &$statement) {
102 $uploadTreeId = $statement[
'uploadtree_pk'];
103 unset($statement[
'uploadtree_pk']);
105 if (!array_key_exists($uploadTreeId, $this->fileNameCache)) {
106 $this->fileNameCache[$uploadTreeId] = $this->treeDao->getFullPath($uploadTreeId, $uploadTreeTableName, $parentId);
109 $statement[
'fileName'] = $this->fileNameCache[$uploadTreeId];
114 protected function groupStatements($ungrupedStatements, $extended, $agentCall, $isUnifiedReport, $objectAgent)
116 $statements = array();
119 foreach ($ungrupedStatements as $statement) {
120 $licenseId = $statement[
'licenseId'];
122 $content = htmlspecialchars($content, ENT_DISALLOWED);
124 $fileName = $statement[
'fileName'];
126 if (!array_key_exists(
'text', $statement)) {
127 $description = $statement[
'description'];
128 $textfinding = $statement[
'textfinding'];
130 if ($description === null) {
133 if (!empty($textfinding) && empty($agentCall)) {
134 $content = $textfinding;
136 $text = $description;
139 $text = $statement[
'text'];
142 if ($agentCall ==
"license") {
143 $this->groupBy =
"text";
145 $this->groupBy =
"content";
147 $groupBy = $statement[$this->groupBy];
149 if (empty($comments) && array_key_exists($groupBy, $statements)) {
150 $currentFiles = &$statements[$groupBy][
'files'];
151 if (!in_array($fileName, $currentFiles)) {
152 $currentFiles[] = $fileName;
155 $singleStatement = array(
156 "licenseId" => $licenseId,
159 "files" => array($fileName)
162 $singleStatement[
"comments"] =
convertToUTF8($comments,
false);
163 $singleStatement[
"risk"] = $statement[
'risk'];
166 if (empty($comments)) {
167 $statements[$groupBy] = $singleStatement;
169 $statements[] = $singleStatement;
172 if (!empty($statement[
'textfinding']) && !empty($agentCall) && $agentCall !=
"license") {
174 "licenseId" => $licenseId,
175 "content" =>
convertToUTF8($statement[
'textfinding'],
false),
177 "files" => array($fileName)
180 $key = array_search($statement[
'textfinding'], array_column($findings,
'content'));
181 $findings[$key][
"comments"] =
convertToUTF8($comments,
false);
186 if ($countLoop % 500 == 0) {
187 $objectAgent->heartbeat(0);
191 if ($isUnifiedReport) {
193 if (!empty($objectAgent)) {
194 $actualHeartbeat = (count($statements) + count($findings));
195 $objectAgent->heartbeat($actualHeartbeat);
197 return array(
"userFindings" => $findings,
"scannerFindings" => $statements);
199 $statements = array_merge($findings, $statements);
200 if (!empty($objectAgent)) {
201 $objectAgent->heartbeat(count($statements));
203 return array(
"statements" => array_values($statements));
213 abstract protected function getStatements($uploadId, $uploadTreeTableName, $groupId=null);
215 public function getCleared($uploadId, $groupId=null, $extended=
true, $agentcall=null, $isUnifiedReport=
false, $objectAgent)
217 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
218 $ungrupedStatements = $this->
getStatements($uploadId, $uploadTreeTableName, $groupId);
219 $this->changeTreeIdsToPaths($ungrupedStatements, $uploadTreeTableName, $uploadId);
220 $statements = $this->groupStatements($ungrupedStatements, $extended, $agentcall, $isUnifiedReport, $objectAgent);
224 public function getLicenseHistogramForReport($uploadId, $groupId)
226 $histogramStatements = $this->getHistogram($uploadId, $groupId);
227 return array(
"statements" => $histogramStatements);
230 public function cJson($uploadId, $groupId=null)
232 $escapeChars = array(
'\\f',
"\\",
"/",
"\"");
233 $withThisValue = array(
"",
"\\\\",
"\\/",
"\\\"");
234 $clearedString = str_replace($escapeChars, $withThisValue, $this->getCleared($uploadId, $groupId,
false, null,
false, null));
235 $json = json_encode($clearedString);
236 return str_replace(
'\u001b',
'',$json);
239 public function cJsonHist($uploadId, $groupId=null)
241 $jsonHist = json_encode($this->getLicenseHistogramForReport($uploadId, $groupId));
242 return str_replace(
'\u001b',
'',str_replace(
'\\f',
'',$jsonHist));
if(!defined('ENT_SUBSTITUTE')) convertToUTF8($content, $toHTML=true)
getStatements($uploadId, $uploadTreeTableName, $groupId=null)