Skip to content

Commit

Permalink
WIP on #26.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Jan 7, 2019
1 parent 0c4a28b commit 0a0bd33
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
56 changes: 33 additions & 23 deletions src/Command/CheckFixityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class CheckFixityCommand extends ContainerAwareCommand

public function __construct(
ParameterBagInterface $params = null,
LoggerInterface $logger = null,
FixityEventDetailManager $event_detail = null
LoggerInterface $logger = null
) {
// Set in the parameters section of config/services.yaml.
$this->params = $params;
Expand All @@ -37,7 +36,6 @@ public function __construct(

// Set log output path in config/packages/{environment}/monolog.yaml
$this->logger = $logger;
$this->event_detail = $event_detail;

parent::__construct();
}
Expand Down Expand Up @@ -109,17 +107,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!strlen($resource_id)) {
continue;
}
print "\n";
$uuid4 = Uuid::uuid4();
$event_uuid = $uuid4->toString();
$now_iso8601 = date(\DateTime::ISO8601);

$event_detail = '';

// Execute plugins that persist event data. We execute them twice and pass in an 'operation' option,
// once to get the last digest for the resource and again to persist the event resulting from comparing
// that digest with a new one.
if (count($this->persistPlugins) > 0) {
foreach ($this->persistPlugins as $persist_plugin_name) {

$this->event_detail = new FixityEventDetailManager($this->params);
$this->event_detail->add('event_detail', 'wassup.');
// var_dump($this->event_detail->getDetails());

$json_object_array = json_decode($resource_id, true);
$resource_id = $json_object_array['resource_id'];
$last_modified_timestamp = $json_object_array['last_modified_timestamp'];
Expand All @@ -144,8 +146,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$reference_event_plugin_output
);
$reference_event = json_decode($reference_event_plugin_output->fetch(), true);
var_dump($resource_id);
var_dump($reference_event);
// var_dump("From command");
// var_dump($resource_id);
// var_dump($reference_event);
// $reference_event contains to members, 1) the digest recorded in the last fixity
// event check for this resource, which we compare this value with the digest retrieved
// during the current fixity check, and 2) the timestamp from the last event, so we can
Expand All @@ -161,7 +164,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// using a postcheck plugin instead of multiple persist plugins?
$reference_event_digest_value = $reference_event['digest_value'];
$reference_event_last_modified_timestamp = $reference_event['last_modified_timestamp'];
$reference_event_timestamp = $reference_event['timestamp'];

$this->logger->info("Persist plugin ran.", array(
'plugin_name' => $persist_plugin_name,
Expand Down Expand Up @@ -209,32 +212,38 @@ protected function execute(InputInterface $input, OutputInterface $output)
// var_dump($reference_event_digest_value);
// var_dump("current_digest_value");
// var_dump($current_digest_value);
print "\n";

// Riprap has no entries in its db for this resource; this is OK, since this will
// be the case for new resources detected by the fetchresourcelist plugins.
if (strlen($reference_event_digest_value) == 0) {
$outcome = 'success';
$num_successful_events++;
if ($this->event_detail) {
// if ($this->event_detail) {
$this->event_detail->add('event_detail', 'Initial fixity check.');
}
// The resource's current last modified date is later than the timestamp in the
// last fixity check event for this resource.
} elseif ($current_digest_plugin_output['last_modified_timestamp'] > $reference_event_last_modified_timestamp) {
// }
} elseif ($reference_event_digest_value == $current_digest_value) {
$outcome = 'success';
$num_successful_events++;
if ($this->event_detail) {
$this->event_detail->add('event_detail', "Resource modified since last fixity check.");
}
} elseif ($reference_event_digest_value == $current_digest_value) {
// The resource's current last modified date is later than the timestamp in the
// reference fixity check event for this resource.
} elseif ($current_digest_plugin_output['last_modified_timestamp'] > $reference_event_timestamp) {
print "From within true loop for $resource_id:\n";
print "Current digest plugin last modified timestamp: " . $current_digest_plugin_output['last_modified_timestamp'] . "\n";
print "Reference event timestamp:" . $reference_event_timestamp . "\n";
$outcome = 'success';
$num_successful_events++;
$num_successful_events++;
// if ($this->event_detail) {
$this->event_detail->add(
'event_detail', 'Resource modified since last fixity check.'
);
// }
} else {
$num_failed_events++;
if ($this->event_detail) {
$this->event_detail->add('event_outcome_detail_note', 'Insufficient conditions for fixity check event.');
}
// if ($this->event_detail) {
$this->event_detail->add(
'event_outcome_detail_note', 'Insufficient conditions for fixity check event.'
);
// }
}
} else {
$this->logger->error("Fetchdigest plugin ran.", array(
Expand All @@ -260,7 +269,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$persist_fix_event_plugin_output = new BufferedOutput();
$persist_fix_event_plugin_return_code = $persist_fix_event_plugin_command->run(
$persist_fix_event_plugin_input,
$persist_fix_event_plugin_output
$persist_fix_event_plugin_output,
$this->event_detail
);
// Currently not used.
// $persist_fix_event_plugin_output_string = $persist_fix_event_plugin_output->fetch();
Expand Down
15 changes: 9 additions & 6 deletions src/Command/PluginFetchDigestFromShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$file_path = $input->getOption('resource_id');
var_dump("From plugin");
var_dump($file_path);
$external_digest_program_command = $this->external_program . ' ' . $file_path;
$external_digest_program_command = escapeshellcmd($external_digest_program_command);
$external_digest_command_output = exec($external_digest_program_command, $external_digest_program_command_output, $return);
Expand All @@ -56,16 +58,17 @@ protected function execute(InputInterface $input, OutputInterface $output)

$mtime = exec('stat -c %Y '. escapeshellarg($file_path));
$mtime_iso8601 = date(\DateTime::ISO8601, $mtime);
var_dump($mtime_iso8601);
// var_dump("Mtime: " . $mtime_iso8601);

$event_digest_value_and_timestamp_array = array(
$digest_value_and_timestamp_array = array(
'digest_value' => trim($digest),
'last_modified_timestamp' => $mtime_iso8601
);
$event_digest_value_and_timestamp = json_encode($event_digest_value_and_timestamp_array);
$output->writeln(trim($event_digest_value_and_timestamp));
);
var_dump($digest_value_and_timestamp_array);
$digest_value_and_timestamp = json_encode($digest_value_and_timestamp_array);
$output->writeln(trim($digest_value_and_timestamp));
} else {
$this->logger->warning("check_fixity cannot retrieve digest from repository.", array(
$this->logger->warning("check_fixity cannot retrieve digest from file system.", array(
'resource_id' => $file_path,
'status_code' => $return,
));
Expand Down
4 changes: 3 additions & 1 deletion src/Command/PluginPersistToCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct(
// Set log output path in config/packages/{environment}/monolog.yaml
$this->logger = $logger;
$this->event_detail = $event_detail;
var_dump($this->event_detail->getDetails());

parent::__construct();
}
Expand Down Expand Up @@ -96,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$event_digest_value_and_timestamp_array = array(
'digest_value' => $last_record[5],
'last_modified_timestamp' => $last_record[3]
'timestamp' => $last_record[3]
);
$event_digest_value_and_timestamp = json_encode($event_digest_value_and_timestamp_array);
$output->write($event_digest_value_and_timestamp);
Expand Down Expand Up @@ -131,6 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($input->getOption('operation') == 'persist_fix_event') {
$details = $this->event_detail->getDetails();
$event_details = $this->event_detail->serialize($details);
// var_dump($event_details);
$record = array(
$input->getOption('event_uuid'),
$this->event_type,
Expand Down
11 changes: 10 additions & 1 deletion src/Service/FixityEventDetailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ class FixityEventDetailManager
public function __construct(ParameterBagInterface $params = null)
{
$this->event_details = array('event_detail' => array(), 'event_outcome_detail_note' => array());
$this->serialize_delimiter = $params->get('app.service.detailmanager.delimiter');

$this->params = $params;
if ($this->params->has('app.service.detailmanager.delimiter')) {
$this->serialize_delimiter = $this->params->get('app.service.detailmanager.delimiter');
} else {
$this->serialize_delimiter = ';';
}
}

/**
Expand All @@ -31,6 +37,9 @@ public function __construct(ParameterBagInterface $params = null)
*/
public function add($key, $value)
{
if (!strlen($value)) {
return $this->event_details;
}
if ($key == 'event_detail') {
// Do no duplicate values that already exist.
if (!in_array($value, $this->event_details['event_detail'])) {
Expand Down

0 comments on commit 0a0bd33

Please sign in to comment.