Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review Bank Page Issue on Analyse (again) button #190

Open
ShreeKrishnaLabs opened this issue Mar 4, 2018 · 1 comment
Open

Review Bank Page Issue on Analyse (again) button #190

ShreeKrishnaLabs opened this issue Mar 4, 2018 · 1 comment

Comments

@ShreeKrishnaLabs
Copy link

enter image description here
When I click Analyse (again) button on the review page i.e.(civicrm/banking/review?s_list=45)
I get 500 service unavailable error in console
enter image description here

 https://www.example.com/civicrm/ajax/rest 500 (Service unavailable (with message))
  send @ jquery.js:9664
  ajax @ jquery.js:9215
  (anonymous) @ crm.ajax.js?p52hox:143
  CRM.api @ crm.ajax.js?p52hox:152
  analysePayment @ review?s_list=45:752 
  onclick @ review?s_list=45:685

The code at analysePayment@review?s_list=45:752 is

  CRM.api('BankingTransaction', 'analyselist', query,
    {success: function(data) {
    console.log(data);
        if (!data['is_error']) {
          // remove 'execute' bit from URL before reload
          var newURL = window.location.href.replace(reload_regex, '');
          if (window.location.href == newURL) {
            window.location.reload(false);
          } else {
            window.location = newURL;
          }
        } else {
          cj('<div title="Fout"><span class="ui-icon ui-icon-alert" style="float:left;"></span>' + data['error_message'] + '</div>').dialog({
            modal: true,
            buttons: {
              Ok: function() {
                window.location = window.location.href.replace(reload_regex, '');
              }
            }
          });
        }
      }
    }
  );
@ShreeKrishnaLabs
Copy link
Author

While debugging the above issue, I have traced it back to the below function
which you can find it here in github
https://github.com/Project60/org.project60.banking/blob/9dc6bdcc486753f70948edfd4ea36df0eb9d2f86/extension/CRM/Banking/Matcher/Engine.php
and the exact code where I think the issue is $continue value turns out to be 1 and which results in return value to be false since it does not enter the if(!$continue) condition

 foreach ($matchers as $matcher) {
          try {
            // run matchers to generate suggestions
            $logger->setTimer('matcher');
            $continue = $this->matchPlugin( $matcher, $context );
            $logger->logTime("Matcher [{$matcher->getPluginID()}]", 'matcher');
            if (!$continue) {
              $lock->release();
              $logger->logTime("Matching of btx [{$btx_id}]", 'matcher');
              return true;
            }

Now I need to find out a way to make it true so I can see options to match contributions
The matcher I am using is
https://github.com/Project60/org.project60.banking/blob/9dc6bdcc486753f70948edfd4ea36df0eb9d2f86/configuration_database/matcher/default/EnglishDefaults.json
I think this is where I need to alter json so that $continue value turns out to be false,but unsure how I can alter it and what does each key value pair does specifically.



  /**
   * Run this BTX through the matchers
   *
   * @param CRM_Banking_BAO_BankTransaction $btx
   * @param bool $override_processed   Set this to TRUE if you want to re-match processed transactions.
   *                                    This will destroy all records of the execution!
   */
  public function match( $btx_id, $override_processed = FALSE ) {
    // TODO: timeout is 30s - do we need a setting here?
    $lock_timeout = 30.0;
    $lock = CRM_Utils_BankingSafeLock::acquireLock('org.project60.banking.tx'.'-'.$btx_id, $lock_timeout);
    if (empty($lock)) {
      error_log("org.project60.banking - couldn't acquire lock. Timeout is $lock_timeout.");
      return false;
    }

    // load btx
    $btx = new CRM_Banking_BAO_BankTransaction();
    $btx->get('id', $btx_id);

    if (!$override_processed) {
      // don't match already executed transactions...
      $processed_status_id = banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'Processed');
      $ignored_status_id = banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'Ignored');
      if ($btx->status_id == $processed_status_id || $btx->status_id == $ignored_status_id) {
        // will not match already executed transactions
        $lock->release();
        return true;
      }
    }

    // reset the BTX suggestion list
    $btx->resetSuggestions();

    // reset the cache / context object
    $context = new CRM_Banking_Matcher_Context( $btx );
    $logger = CRM_Banking_Helpers_Logger::getLogger();

    // run through the list of matchers
    $logger->setTimer('matching');
    // run through the list of matchers
    $all_matchers = $this->getMatchers();
    if (empty($all_matchers)) {
      CRM_Core_Session::setStatus(ts("No matcher plugins configured!"), ts('No processors'), 'alert');
    } else {
      foreach ($all_matchers as $weight => $matchers) {
        foreach ($matchers as $matcher) {
          try {
            // run matchers to generate suggestions
            $logger->setTimer('matcher');
            $continue = $this->matchPlugin( $matcher, $context );
            $logger->logTime("Matcher [{$matcher->getPluginID()}]", 'matcher');
            if (!$continue) {
              $lock->release();
              $logger->logTime("Matching of btx [{$btx_id}]", 'matcher');
              return true;
            }
            // check if we can execute the suggestion right aways
            $abort = $this->checkAutoExecute($matcher, $btx);
            if ($abort) {
              $logger->logDebug("Matcher [{$matcher->getPluginID()}] executed automatically.");
              $lock->release();
              $logger->logTime("Matching of btx [{$btx_id}]", 'matcher');
              return false;
            }
          } catch (Exception $e) {
            $matcher_id = $matcher->getPluginID();
            error_log("org.project60.banking - Exception during the execution of matcher [$matcher_id], error was: ".$e->getMessage());
            $lock->release();
            return false;
          }
        }
      }
    }

    $btx->saveSuggestisons();
    // set the status
    $newStatus = banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'Suggestions');

    $btx->status_id = $newStatus;
    $btx->setStatus($newStatus);

    $lock->release();
    $context->destroy();
    $logger->logTime("Matching of btx [{$btx_id}]", 'matcher');
    return false;
  }


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant