50 'type'=>array(
'type',
'Type'),
51 'topic'=>array(
'topic',
'Obligation or Risk topic'),
52 'text'=>array(
'text',
'Full Text'),
53 'classification'=>array(
'classification',
'Classification'),
54 'modifications'=>array(
'modifications',
'Apply on modified source code'),
55 'comment'=>array(
'comment',
'Comment'),
56 'licnames'=>array(
'licnames',
'Associated Licenses'),
57 'candidatenames'=>array(
'candidatenames',
'Associated candidate Licenses')
67 $this->obligationMap = $GLOBALS[
'container']->get(
'businessrules.obligationmap');
96 if (!is_file($filename) || ($handle = fopen($filename,
'r')) ===
false) {
97 return _(
'Internal error');
102 while (($row = fgetcsv($handle,0,$this->delimiter,$this->enclosure)) !==
false) {
109 $msg .= _(
'Read csv').(
": $cnt ")._(
'obligations');
112 return $msg .= _(
'Error while parsing file').
': '.$e->getMessage();
126 if ($this->headrow===null) {
132 foreach (array(
'type',
'topic',
'text',
'classification',
'modifications',
'comment',
'licnames',
'candidatenames') as $needle) {
133 $mRow[$needle] = $row[$this->headrow[$needle]];
148 foreach (array(
'type',
'topic',
'text',
'classification',
'modifications',
'comment',
'licnames',
'candidatenames') as $needle) {
149 $col = ArrayOperation::multiSearch($this->alias[$needle], $row);
150 if (
false === $col) {
151 throw new \Exception(
"Undetermined position of $needle");
165 $req = array($row[
'topic'], $row[
'text']);
166 $row = $this->
dbManager->getSingleRow(
'SELECT ob_pk FROM obligation_ref WHERE ob_topic=$1 AND ob_md5=md5($2)',$req);
167 return ($row ===
false) ?
false : $row[
'ob_pk'];
180 $getList = $this->obligationMap->getLicenseList($exists, $candidate);
183 $diff = strcmp($listFromDb, $listFromCsv);
195 $string = explode(
";", $string);
197 $string = implode(
",", $string);
210 $this->obligationMap->unassociateLicenseFromObligation($exists, $licId, $candidate);
227 $associatedLicenses =
"";
228 $candidateLicenses =
"";
230 if ($exists !==
false) {
231 $msg =
"Obligation topic '$row[topic]' already exists in DB (id=".$exists.
"),";
232 if ( $this->
compareLicList($exists, $row[
'licnames'],
false, $row) === 0 ) {
233 $msg .=
" No Changes in AssociateLicense";
236 if (!empty($row[
'licnames'])) {
239 $msg .=
" Updated AssociatedLicense license";
241 if ($this->
compareLicList($exists, $row[
'candidatenames'],
true, $row) === 0) {
242 $msg .=
" No Changes in CandidateLicense";
245 if (!empty($row[
'candidatenames'])) {
248 $msg .=
" Updated CandidateLicense";
251 return $msg .
"\n" . $associatedLicenses .
"\n";
254 $stmtInsert = __METHOD__.
'.insert';
255 $dbManager->prepare($stmtInsert,
'INSERT INTO obligation_ref (ob_type,ob_topic,ob_text,ob_classification,ob_modifications,ob_comment,ob_md5)' 256 .
' VALUES ($1,$2,$3,$4,$5,$6,md5($3)) RETURNING ob_pk');
257 $resi =
$dbManager->execute($stmtInsert,array($row[
'type'],$row[
'topic'],$row[
'text'],$row[
'classification'],$row[
'modifications'],$row[
'comment']));
261 if (!empty($row[
'licnames'])) {
264 if (!empty($row[
'candidatenames'])) {
268 $message =
"License association results for obligation '$row[topic]':\n";
269 $message .=
"$associatedLicenses";
270 $message .=
"$candidateLicenses";
271 $message .=
"Obligation with id=$new[ob_pk] was added successfully.\n";
285 $associatedLicenses =
"";
288 $licenses = explode(
";",$licList);
289 foreach ($licenses as $license) {
290 $licIds = $this->obligationMap->getIdFromShortname($license, $candidate);
292 if (empty($licIds)) {
293 $message .=
"License $license could not be found in the DB.\n";
295 $updated = $this->obligationMap->associateLicenseFromLicenseList($obPk,
296 $licIds, $candidate);
299 if ($associatedLicenses ==
"") {
300 $associatedLicenses =
"$license";
302 $associatedLicenses .=
";$license";
307 if (!empty($associatedLicenses)) {
308 $message .=
"$associatedLicenses were associated.\n";
311 $message .= $candidate ?
"candidate":
"";
312 $message .=
"licenses were associated.\n";
329 $this->
dbManager->getSingleRow(
'UPDATE obligation_ref SET ob_classification=$2, ob_modifications=$3, ob_comment=$4 where ob_pk=$1',
330 array($exists, $row[
'classification'], $row[
'modifications'], $row[
'comment']),
331 __METHOD__ .
'.updateOtherOb');
handleFile($filename)
Read the CSV line by line and import it.
Helper class for Obligation CSV Import.
getKeyFromTopicAndText($row)
Get the Obligation key from obligation topic and obligation text.
setEnclosure($enclosure='"')
Update the enclosure.
clearListFromDb($exists, $candidate)
Clear all license maps for given obligation.
Utility functions for specific applications.
AssociateWithLicenses($licList, $obPk, $candidate=False)
Associate selected licenses to the obligation.
updateOtherFields($exists, $row)
Update other fields of the obligation.
__construct(DbManager $dbManager)
compareLicList($exists, $listFromCsv, $candidate, $row)
Compare licenses from Database and CSV.
fo_dbManager * dbManager
fo_dbManager object
handleCsvObligation($row)
Handle a single row from CSV.
handleHeadCsv($row)
Handle a row as head row.
setDelimiter($delimiter=',')
Update the delimiter.