Skip to content

Commit d1aa89b

Browse files
committed
#1159 Improve readability
1 parent e0b167f commit d1aa89b

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

library/Application/Console/Document/DiffCommand.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,20 @@ protected function configure()
5454
parent::configure();
5555

5656
$help = <<<EOT
57+
Shows the differences between two or more documents.
5758
59+
Multiple document IDs can be provided as argument. The fields of the documents
60+
are then compared and differences reported.
61+
62+
If a DOI is provided, using the <fg=green>--doi</> Option, the database is
63+
searched for matching documents. If more than one is found, the differences
64+
between the documents are reported.
65+
66+
<fg=red>NOTES:
67+
- Complex values like persons and patents are not shown with all their metadata.
68+
- For text values, like titles and abstracts, the exact differences are not
69+
highlighted. The report just shows that the values are different.
70+
</>
5871
EOT;
5972

6073
$this->setName('document:diff')

library/Application/Document/DocumentDiff.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,16 @@ public function diff($docIds)
9696
$output = $this->getOutput();
9797

9898
foreach ($diffKeys as $key) {
99-
$output->writeln("<fg=yellow>$key</>");
99+
$output->writeln("Field: <fg=yellow;options=bold>$key</>");
100100
$values = $differences[$key];
101101
$field = $doc->getField($key);
102102
$valueModelClass = $field->getValueModelClass();
103103
$linkModelClass = $field->getLinkModelClass();
104104

105105
foreach ($values as $docId => $value) {
106+
$output->writeln('------------------------------------------------------------');
106107
if (! is_array($value)) {
107-
$line = sprintf(" %{$maxDigits}d: %s", $docId, $value);
108+
$line = sprintf(" <fg=green>%{$maxDigits}d</>: %s", $docId, $value);
108109
$output->writeln($line);
109110
} else {
110111
if (count($value) > 0) {
@@ -118,11 +119,12 @@ public function diff($docIds)
118119
}
119120
}
120121
} else {
121-
$line = sprintf(" %{$maxDigits}d: %s", $docId, '-');
122+
$line = sprintf(" <fg=green>%{$maxDigits}d</>: %s", $docId, '-');
122123
$output->writeln($line);
123124
}
124125
}
125126
}
127+
$output->writeln('------------------------------------------------------------');
126128
$output->writeln('');
127129
}
128130
}
@@ -138,7 +140,11 @@ public function diff($docIds)
138140
protected function renderModel($key, $valueModelClass, $linkModelClass, $value, $docId, $maxDigits)
139141
{
140142
if (strpos($key, 'Person') === 0) {
141-
unset($value['DateOfBirth']); // TODO field causes problems with fromArray
143+
unset($value['DateOfBirth']); // TODO date field causes problems with fromArray
144+
}
145+
146+
if ($key === 'File') {
147+
unset($value['ServerDateSubmitted']); // TODO date field causes problems with fromArray
142148
}
143149

144150
if ($linkModelClass !== null) {
@@ -163,19 +169,19 @@ protected function renderModel($key, $valueModelClass, $linkModelClass, $value,
163169
break;
164170

165171
case 'Enrichment':
166-
$displayName = $model->getKeyName() . ' => ' . $model->getValue();
172+
$displayName = '<fg=magenta>' . $model->getKeyName() . '</>: ' . $model->getValue();
167173
break;
168174

169175
case 'Identifier':
170-
$displayName = $model->getType() . ' => ' . $model->getValue();
176+
$displayName = '<fg=magenta>' . $model->getType() . '</>: ' . $model->getValue();
171177
break;
172178

173179
case 'TitleMain':
174180
case 'TitleAbstract':
175181
case 'TitleAdditional':
176182
case 'TitleParent':
177183
case 'TitleSub':
178-
$displayName = '(' . $model->getLanguage() . ') ' . $model->getValue();
184+
$displayName = '(<fg=magenta>' . $model->getLanguage() . '</>) ' . $model->getValue();
179185
break;
180186

181187
case 'Note':
@@ -187,18 +193,22 @@ protected function renderModel($key, $valueModelClass, $linkModelClass, $value,
187193
break;
188194

189195
case 'Subject':
190-
$displayName = $model->getValue() . ' (' . $model->getType() . ')';
196+
$displayName = $model->getValue() . ' (<fg=magenta>' . $model->getType() . '</>)';
191197
break;
192198

193199
case 'Person':
194-
$displayName = $model->getDisplayName() . ' (' . $model->getRole() . ')';
200+
$displayName = $model->getDisplayName() . ' (<fg=magenta>' . $model->getRole() . '</>)';
201+
break;
202+
203+
case 'File':
204+
$displayName = $model->getLabel() . ' (<fg=magenta>' . $model->getMimeType() . '</>)';
195205
break;
196206

197207
default:
198208
$displayName = $model->getDisplayName();
199209
}
200210

201-
$line = sprintf(" %{$maxDigits}d: %s", $docId, $displayName);
211+
$line = sprintf(" <fg=green>%{$maxDigits}d</>: %s", $docId, $displayName);
202212
$this->getOutput()->writeln($line);
203213
}
204214

0 commit comments

Comments
 (0)