Skip to content

Commit

Permalink
- [X] Fix initialization error on reinstall the package
Browse files Browse the repository at this point in the history
- [X] Prevent initialization from repeated if already done once
  • Loading branch information
aemaddin committed Mar 20, 2024
1 parent 02e18ae commit fae65d2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Zoho.php
Expand Up @@ -74,6 +74,10 @@ public static function useEnvironment(Environment $environment): static
*/
public static function initialize($code = null): void
{
if (self::isInitialized()) {
return;
}

$environment = self::$environment ?: self::getDataCenterEnvironment();
$resourcePath = config('zoho.resourcePath');
$token_store = new FileStore(config('zoho.token_persistence_path'));
Expand Down Expand Up @@ -129,6 +133,11 @@ public static function initialize($code = null): void
->initialize();
}

public static function isInitialized(): bool
{
return \com\zoho\crm\api\Initializer::getInitializer() !== null;
}

public static function getDataCenterEnvironment(): ?Environment
{
if (!empty(static::$environment)) {
Expand Down
2 changes: 1 addition & 1 deletion src/ZohoManager.php
Expand Up @@ -27,7 +27,7 @@ public function __construct($module_api_name = 'Leads')
$this->module_api_name = $module_api_name;
Zoho::initialize();
} catch (SDKException $e) {
//
logger()->error($e->getMessage());
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/ZohoModuleTest.php
Expand Up @@ -5,8 +5,8 @@
use Asciisd\Zoho\ZohoManager;
use com\zoho\crm\api\record\Leads;
use com\zoho\crm\api\record\Record;
use com\zoho\crm\api\modules\Module;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\webforms\Module;

class ZohoModuleTest extends IntegrationTestCase
{
Expand Down

0 comments on commit fae65d2

Please sign in to comment.