55 include_once(__DIR__ .
"/version.php");
91 function __construct()
97 parent::__construct(README_AGENT_NAME, AGENT_VERSION, AGENT_REV);
99 $this->uploadDao = $this->container->get(
'dao.upload');
101 $this->agentSpecifLongOptions[] = self::UPLOAD_ADDS.
':';
114 $this->additionalUploadIds = array_key_exists(self::UPLOAD_ADDS,
$args) ? explode(
',',
$args[self::UPLOAD_ADDS]) : array();
116 array_unshift($uploadIds, $uploadId);
119 $licenseStmts = array();
120 $copyrightStmts = array();
121 $licenseStmtsMain = array();
122 $licenseAcknowledgements = array();
124 foreach ($uploadIds as $addUploadId) {
125 if (!$this->uploadDao->isAccessible($addUploadId,
$groupId)) {
128 $moreLicenses = $this->licenseClearedGetter->getCleared($addUploadId,
$groupId,
true, null,
false, $this);
129 $licenseStmts = array_merge($licenseStmts, $moreLicenses[
'statements']);
130 $this->
heartbeat(count($moreLicenses[
'statements']));
131 $this->licenseClearedGetter->setOnlyAcknowledgements(
true);
132 $moreAcknowledgements = $this->licenseClearedGetter->getCleared($addUploadId,
$groupId,
true, null,
false, $this);
133 $licenseAcknowledgements = array_merge($licenseAcknowledgements, $moreAcknowledgements[
'statements']);
134 $this->
heartbeat(count($moreAcknowledgements[
'statements']));
135 $moreCopyrights = $this->cpClearedGetter->getCleared($addUploadId,
$groupId,
true,
"copyright",
false, $this);
136 $copyrightStmts = array_merge($copyrightStmts, $moreCopyrights[
'statements']);
137 $this->
heartbeat(count($moreCopyrights[
'statements']));
138 $moreMainLicenses = $this->licenseMainGetter->getCleared($addUploadId,
$groupId,
true, null,
false, $this);
139 $licenseStmtsMain = array_merge($licenseStmtsMain, $moreMainLicenses[
'statements']);
140 $this->
heartbeat(count($moreMainLicenses[
'statements']));
142 list($licenseStmtsMain, $licenseStmts) = $this->licenseClearedGetter->updateIdentifiedGlobalLicenses($licenseStmtsMain, $licenseStmts);
143 $contents = array(
'licensesMain'=>$licenseStmtsMain,
'licenses'=>$licenseStmts,
'copyrights'=>$copyrightStmts,
'licenseAcknowledgements' => $licenseAcknowledgements);
158 $packageName = $this->uploadDao->getUpload($uploadId)->getFilename();
160 $fileBase = $SysConf[
'FOSSOLOGY'][
'path'].
"/report/";
161 $fileName = $fileBase.
"ReadMe_OSS_".$packageName.
'_'.time().
".txt" ;
163 foreach ($this->additionalUploadIds as $addUploadId) {
164 $packageName .=
', ' . $this->uploadDao->getUpload($addUploadId)->getFilename();
167 if (!is_dir($fileBase)) {
168 mkdir($fileBase, 0777,
true);
173 file_put_contents($fileName, $message);
186 $this->
dbManager->insertTableRow(
'reportgen', array(
'upload_fk'=>$uploadId,
'job_fk'=>
$jobId,
'filepath'=>$filename), __METHOD__);
200 foreach ($dataForReadME as $statements) {
201 if ($extract ==
'text') {
202 $outData .= $statements[
"content"] . $break;
204 $outData .= str_replace(
"\n",
"\r\n", $statements[$extract]) . $break;
205 if (!empty($addSeparator)) {
206 $outData .= $addSeparator . $break;
221 $separator1 = str_repeat(
"=", 120);
222 $separator2 = str_repeat(
"-", 120);
223 $break = str_repeat(
"\r\n", 2);
224 $output = $separator1 . $break . $packageName . $break . $separator2 . $break;
225 if (!empty($contents[
'licensesMain'])) {
226 $output .= $separator1 . $break .
" MAIN LICENSES " . $break . $separator2 . $break;
229 if (!empty($contents[
'licenses'])) {
230 $output .= $separator1 . $break .
" OTHER LICENSES " . $break . $separator2 . $break;
233 if (!empty($contents[
'licenseAcknowledgements'])) {
234 $output .= $separator1 . $break .
" ACKNOWLEDGEMENTS " . $break . $separator2 . $break;
235 $output .= $this->
createReadMeOSSFormat($separator2, $contents[
'licenseAcknowledgements'],
'text', $break);
238 if (empty($copyrights)) {
239 $output .=
"<Copyright notices>";
241 $output .=
"<notices>";
243 $output .=
"Copyright notices";
245 $output .= $copyrights;
252 $agent->scheduler_connect();
253 $agent->run_scheduler_event_loop();
254 $agent->scheduler_disconnect(0);
heartbeat($newProcessed)
Send hear beat to the scheduler.
writeReport($contents, $uploadId)
Write data to text file.
createReadMeOSSFormat($addSeparator, $dataForReadME, $extract='text', $break)
This function lists elements of array.
Structure of an Agent with all required parameters.
Readme_OSS agent generates list of licenses and copyrights found in an upload.
int jobId
The id of the job.
processUploadId($uploadId)
Given an upload ID, process the items in it.
generateReport($contents, $packageName)
Gather all the data.
fo_dbManager * dbManager
fo_dbManager object
const UPLOAD_ADDS
The HTTP GET parameter name.
updateReportTable($uploadId, $jobId, $filename)
Update the report path.