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 $firstLicenseId = $firstLicense->getId();
118 $normalizedRow[
"firstname"] = $firstLicenseId;
120 if ($normalizedRow[
"secondname"] !=
null) {
121 $secondLicense = $this->licenseDao->getLicenseByShortName(
122 $normalizedRow[
"secondname"],
null);
123 $secondLicenseId = $secondLicense->getId();
124 $normalizedRow[
"secondname"] = $secondLicenseId;
138 $oldRule = $this->
dbManager->getSingleRow(
"SELECT
139 compatibility, comment FROM license_rules WHERE lr_pk = $1",
140 [$lrPk], __METHOD__ .
'.getOldRule');
142 $old_comp= $this->
dbManager->booleanFromDb($oldRule[
"compatibility"]);
143 $new_comp= filter_var($row[
"compatibility"], FILTER_VALIDATE_BOOLEAN);
146 if ($old_comp != $new_comp) {
147 $rule[
"compatibility"] = $this->
dbManager->booleanToDb($new_comp);
148 $log[] =
"updated compatibility";
150 if (!empty($row[
'comment']) && $row[
'comment'] != $oldRule[
'comment']) {
151 $rule[
"comment"] = $row[
"comment"];
152 $log[] =
"updated comment";
154 if (count($rule) > 1) {
156 $this->compatibilityDao->updateRuleFromArray([$lrPk => $rule]);
157 }
catch (\UnexpectedValueException $e) {
158 $log[] = $e->getMessage();
161 return join(
", ", $log);
174 $stmt = __METHOD__ .
'.LicRules';
175 $sql =
"SELECT lr_pk FROM license_rules WHERE ";
179 if (!empty($row[
'firstname'])) {
180 $param[] = $row[
'firstname'];
182 $extraParams[] =
"first_rf_fk=$" . count($param);
184 if (!empty($row[
'secondname'])) {
185 $param[] = $row[
'secondname'];
187 $extraParams[] =
"second_rf_fk=$" . count($param);
189 if (!empty($row[
'firsttype'])) {
190 $param[] = $row[
'firsttype'];
192 $extraParams[] =
"first_type=$" . count($param);
194 if (!empty($row[
'secondtype'])) {
195 $param[] = $row[
'secondtype'];
197 $extraParams[] =
"second_type=$" . count($param);
199 if (count($param) == 2) {
200 $sql .= join(
" AND ", $extraParams);
201 $res = $this->
dbManager->getSingleRow($sql, $param, $stmt);
203 $lr_pk = $res[
"lr_pk"];
206 if (!empty($lr_pk)) {
221 return $this->compatibilityDao->insertRule($row[
"firstname"],
222 $row[
"secondname"], $row[
"firsttype"], $row[
"secondtype"],
223 $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.