veda-consulting-company / uk.co.vedaconsulting.mailchimp

Other
22 stars 43 forks source link

Fatal Error: Mailchimp class is defined twice when using Drupal Mailchimp module #119

Closed hansrossel closed 9 years ago

hansrossel commented 9 years ago

When using this extension together with the Drupal Mailchimp module you get: "Fatal error: Cannot redeclare class Mailchimp_Folders in /home/xxx/public_html/sites/all/civiextensions/uk.co.vedaconsulting.mailchimp/vendor/mailchimp/Mailchimp/Folders.php on line 3"

So the Mailchimp classes are apparently loaded twice. I'm not sure where this happens as Drupal uses the libraries module to load the Mailchimp library and the extension is including it with require_once.

Temporary workaround in uk.co.vedaconsulting.mailchimp/vendor/mailchimp/Mailchimp/Folders.php:

if (class_exists('Mailchimp_Folders') != true) {
  class Mailchimp_Folders {
  }
}
veda-consulting commented 9 years ago

Thanks for the fix, we'll patch into the next version

hansrossel commented 9 years ago

Actually when you try to make Mailchimp Signup forms in Drupal there is an error for every Mailchimp class, Mailchimp_Folders is just the first one that gets included in vendor/mailchimp/mailchimp.php, so they should all be wrapped in a class_exists.

Maybe it is easier to work from vendor/mailchimp/mailchimp.php and wrap everything in a if (class_exists('Mailchimp') != true) {. I suppose if the main Mailchimp class exists this means Drupal has loaded the library allready and all other classes should not be loaded.

I don't understand why require_once does not prevent these classes from being loaded when they exist allready. There should be a cleaner solution to prevent this problem than checking class_exists.

veda-consulting commented 9 years ago

Yep - agreed, CiviCRM uses an autoloader to avoid such issues but as these classes are external I'm not sure we can use that. We'll have a look to see what other possible solutions there are to this and update accordingly.

veda-consulting commented 9 years ago

Patched - Closing

marianellam commented 9 years ago

I just installed the extension in CiviCRM and I already have the Drupal module installed for the sign up form on the site. As soon as I installed it and entered the API key, I am getting the same error: "Fatal error: Cannot redeclare class Mailchimp_Folders". In installed the extension from within CiviCRM.

wluisi commented 8 years ago

I'm getting the fatal error using mailchimp civi 1.8.7 w/ Drupal 7 mailchimp module.

require_once(): Cannot redeclare class mailchimp

Is this civi extension not compatible w/ the standard Drupal mailchimp module?

TWoofenden commented 7 years ago

@veda-consulting : Could you clarify what was patched? I don't see either file patched in the latest version, and I'm also seeing this same issue.