You are here

function security_review_store_results in Security Review 7

Same name and namespace in other branches
  1. 6 security_review.module \security_review_store_results()

Store checklist results.

3 calls to security_review_store_results()
security_review_drush in ./security_review.drush.inc
Run checklist and display results command.
security_review_run_store in ./security_review.module
Run the security review checklist and store the results.
_security_review_batch_finished in ./security_review.module
Finished callback for Batch processing the checklist.

File

./security_review.module, line 160
Site security review and reporting Drupal module.

Code

function security_review_store_results($results) {
  $log = variable_get('security_review_log', TRUE);
  $saved = $to_save = 0;
  foreach ($results as $module => $checks) {
    foreach ($checks as $check_name => $check) {
      $num_deleted = db_delete('security_review')
        ->condition('namespace', $module)
        ->condition('reviewcheck', $check_name)
        ->execute();
      if ($num_deleted == 1 && is_null($check['result']) && $log) {

        // Last check was deleted and current check returns null so check is
        // no longer applicable.
        $message = '!name no longer applicable for checking';
        _security_review_log($module, $check_name, $message, array(
          '!name' => $check['title'],
        ), WATCHDOG_INFO);
      }
      elseif (!is_null($check['result'])) {
        $to_save++;
        $record = array(
          'namespace' => $module,
          'reviewcheck' => $check_name,
          'result' => $check['result'],
          'lastrun' => $check['lastrun'] ? $check['lastrun'] : REQUEST_TIME,
        );
        if (drupal_write_record('security_review', $record) == SAVED_NEW) {
          $saved++;
        }
        elseif ($log) {
          _security_review_log($module, $check_name, 'Unable to store check !reviewcheck for !namespace', array(
            '!reviewcheck' => $check_name,
            '!namespace' => $module,
          ), WATCHDOG_ERROR);
        }
      }
    }
  }
  return $to_save == $saved ? TRUE : FALSE;
}