41 'firstname' => [
'firstname',
'mainname',
'First Name'],
42 'secondname' => [
'secondname',
'subname',
'Second Name'],
43 'firsttype' => [
'firsttype',
'maintype',
'First Type'],
44 'secondtype' => [
'secondtype',
'subtype',
'Second Type'],
45 'compatibility' => [
'compatibility',
'Compatibility'],
46 'comment' => [
'comment',
'text',
'Comment']
74 if (!is_file($filename) || ($handle = fopen($filename,
'r')) ===
false) {
75 return _(
'Internal error');
79 $file_content = yaml_parse_file($filename);
81 foreach ($file_content[
"rules"] as $row) {
88 $msg .= _(
'Read yaml').(
": $cnt ")._(
'license rules');
91 return $msg . _(
'Error while parsing file') .
': ' . $e->getMessage();
105 foreach (array_keys($this->alias) as $key) {
106 $col = ArrayOperation::multiSearch($this->alias[$key], array_keys($row));
107 if ($col ===
false) {
108 throw new \UnexpectedValueException(
"Unable to find key for $key in " .
111 $col = array_keys($row)[$col];
112 $normalizedRow[$key] = $row[$col];
114 if ($normalizedRow[
"firstname"] !=
null) {
115 $firstLicense = $this->licenseDao->getLicenseByShortName(
116 $normalizedRow[
"firstname"],
null);
117 if ($firstLicense ===
null) {
118 throw new \UnexpectedValueException(
"Unable to find license " .
119 $normalizedRow[
"firstname"] .
" from YAML");
121 $normalizedRow[
"firstname"] = $firstLicense->getId();
123 if ($normalizedRow[
"secondname"] !=
null) {
124 $secondLicense = $this->licenseDao->getLicenseByShortName(
125 $normalizedRow[
"secondname"],
null);
126 if ($secondLicense ===
null) {
127 throw new \UnexpectedValueException(
"Unable to find license " .
128 $normalizedRow[
"secondname"] .
" from YAML");
130 $normalizedRow[
"secondname"] = $secondLicense->getId();
144 $oldRule = $this->
dbManager->getSingleRow(
"SELECT
145 compatibility, comment FROM license_rules WHERE lr_pk = $1",
146 [$lrPk], __METHOD__ .
'.getOldRule');
148 $old_comp= $this->
dbManager->booleanFromDb($oldRule[
"compatibility"]);
149 $new_comp= filter_var($row[
"compatibility"], FILTER_VALIDATE_BOOLEAN);
152 if ($old_comp != $new_comp) {
153 $rule[
"result"] = $new_comp;
154 $log[] =
"updated compatibility";
156 if (!empty($row[
'comment']) && $row[
'comment'] != $oldRule[
'comment']) {
157 $rule[
"comment"] = $row[
"comment"];
158 $log[] =
"updated comment";
162 $this->compatibilityDao->updateRuleFromArray([$lrPk => $rule]);
163 }
catch (\UnexpectedValueException $e) {
164 $log[] = $e->getMessage();
167 return join(
", ", $log);
180 $stmt = __METHOD__ .
'.LicRules';
181 $sql =
"SELECT lr_pk FROM license_rules WHERE ";
185 if (!empty($row[
'firstname'])) {
186 $param[] = $row[
'firstname'];
188 $extraParams[] =
"first_rf_fk=$" . count($param);
190 if (!empty($row[
'secondname'])) {
191 $param[] = $row[
'secondname'];
193 $extraParams[] =
"second_rf_fk=$" . count($param);
195 if (!empty($row[
'firsttype'])) {
196 $param[] = $row[
'firsttype'];
198 $extraParams[] =
"first_type=$" . count($param);
200 if (!empty($row[
'secondtype'])) {
201 $param[] = $row[
'secondtype'];
203 $extraParams[] =
"second_type=$" . count($param);
205 if (count($param) == 2) {
206 $sql .= join(
" AND ", $extraParams);
207 $res = $this->
dbManager->getSingleRow($sql, $param, $stmt);
209 $lr_pk = $res[
"lr_pk"];
212 if (!empty($lr_pk)) {
227 return $this->compatibilityDao->insertRule($row[
"firstname"],
228 $row[
"secondname"], $row[
"firsttype"], $row[
"secondtype"],
229 $row[
"comment"], $row[
"compatibility"]);
Import licenses from YAML.
handleYamlLicense($row)
Handle a single row from YAML.
updateLicense($row, $lrPk)
Update the license info in the DB.
__construct(DbManager $dbManager, UserDao $userDao, LicenseDao $licenseDao, CompatibilityDao $compatibilityDao)
insertNewLicense($row)
Insert a new license in DB.
handleFile($filename)
Read the YAML line by line and import it.
fo_dbManager * dbManager
fo_dbManager object
Utility functions for specific applications.