From 0a0bd336d98ade062822c1a288e3fea26618aac1 Mon Sep 17 00:00:00 2001 From: Mark Jordan Date: Mon, 7 Jan 2019 14:31:26 -0800 Subject: [PATCH] WIP on #26. --- src/Command/CheckFixityCommand.php | 56 +++++++++++++--------- src/Command/PluginFetchDigestFromShell.php | 15 +++--- src/Command/PluginPersistToCsv.php | 4 +- src/Service/FixityEventDetailManager.php | 11 ++++- 4 files changed, 55 insertions(+), 31 deletions(-) diff --git a/src/Command/CheckFixityCommand.php b/src/Command/CheckFixityCommand.php index 50faad2..042b5e6 100644 --- a/src/Command/CheckFixityCommand.php +++ b/src/Command/CheckFixityCommand.php @@ -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; @@ -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(); } @@ -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']; @@ -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 @@ -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, @@ -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( @@ -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(); diff --git a/src/Command/PluginFetchDigestFromShell.php b/src/Command/PluginFetchDigestFromShell.php index 731ac0e..f040d19 100644 --- a/src/Command/PluginFetchDigestFromShell.php +++ b/src/Command/PluginFetchDigestFromShell.php @@ -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); @@ -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, )); diff --git a/src/Command/PluginPersistToCsv.php b/src/Command/PluginPersistToCsv.php index 7592586..85ee57b 100644 --- a/src/Command/PluginPersistToCsv.php +++ b/src/Command/PluginPersistToCsv.php @@ -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(); } @@ -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); @@ -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, diff --git a/src/Service/FixityEventDetailManager.php b/src/Service/FixityEventDetailManager.php index 01dbce9..6518669 100644 --- a/src/Service/FixityEventDetailManager.php +++ b/src/Service/FixityEventDetailManager.php @@ -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 = ';'; + } } /** @@ -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'])) {