• Resolved wpyourname

    (@wpyourname)


    Unfortunately the plugin disconnect sometimes and will stays disconnected if you don’t hit connect again in Connection tab.
    And that is why i changed the Plugin class and connected function like this:

    public function connected() {
     $cacheConnected = isset( $this->options ) && isset( $this->options["connected"] ) && $this->options["connected"] == true;
     if ( $cacheConnected !== true ) {
      return $this->retryConnect();
     }
    
     return true;
    }
    
    private function retryConnect() {
     /* Delete cache section */
     ACRM()->purgeCache();
     Connection::setConnectionStatus( false );
     $options = get_option( Plugin::PREFIX . 'options' );
    
     if ( ! isset( $options["serverUrl"] ) ||
          ! isset( $options["username"] ) ||
          ! isset( $options["password"] ) ||
          ! $options["serverUrl"] ||
          ! $options["username"] ||
          ! $options["password"]
     ) {
      return false;
     }
    
     try {
      $clientSettings = new Settings( $options );
    
      ACRM()->getLogger()->notice( 'Connecting to a new instance', [
       'settings' => [
        'authMode'        => $clientSettings->authMode,
        'crmUrl'          => $clientSettings->serverUrl,
        'username'        => $clientSettings->username,
        'ignoreSslErrors' => $clientSettings->ignoreSslErrors,
       ]
      ] );
    
      $client = new Client( $clientSettings, ACRM()->getCache(), ACRM()->getLogger()->withName( 'crmtoolkit' ) );
    
      // next settings are retrieved during Client instantiation
      $options['organizationName']       = $clientSettings->organizationName;
      $options['organizationUniqueName'] = $clientSettings->organizationUniqueName;
      $options['organizationVersion']    = $clientSettings->organizationVersion;
      $options['organizationId']         = $clientSettings->organizationId;
    
      if ( isset( $client ) && $whoAmI = $client->executeAction( "WhoAmI" ) ) {
       update_option( Plugin::PREFIX . 'options', $options );
       $this->options = ACRM()->options = $options;
       Connection::setConnectionStatus( true );
      }
     } catch ( Exception $e ) {
      return false;
     }
    
     return true;
    }

    Do you approve it?

Viewing 1 replies (of 1 total)
  • Plugin Author alexacrm

    (@alexacrm)

    Hi @wpyourname,

    we need to be very careful with the retry logic because there could be various reasons for the failed connection, some of them transient and some not. For example, invalid password would result in a failed connection that does not make sense to retry at all. Imagine retrying it on every page request (that’s what will effectively happen). That’s why, under certain circumstances, we leave plugin disconnected.

    If your retry logic works for you, great. If you’d like to submit it as a pull request, by all means, we’ll review it and incorporate if applicable.

    Cheers
    AlexaCRM Team

Viewing 1 replies (of 1 total)
  • The topic ‘Auto Disconnection from CRM’ is closed to new replies.