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

mailchimp script failing #870

Closed
kristanslack opened this issue Feb 20, 2023 · 2 comments
Closed

mailchimp script failing #870

kristanslack opened this issue Feb 20, 2023 · 2 comments

Comments

@kristanslack
Copy link

Hi,

The mail chimp script is failing with an exception:

Fatal error: Uncaught PharException: Extraction from phar "/tmp/jethro-mc-1676867940/response.tar" failed: Cannot extract ".", internal error in /home/aliceang/public_html/jethro/scripts/mailchimp_sync.php:271
Stack trace:
#0 /home/aliceang/public_html/jethro/scripts/mailchimp_sync.php(271): PharData->extractTo('/tmp/jethro-mc-...', NULL, true)
#1 /home/aliceang/public_html/jethro/scripts/mailchimp_sync.php(81): run_mc_sync(Object(DrewM\MailChimp\MailChimp), 2, '41f1a38d0e')
#2 {main}
thrown in /home/aliceang/public_html/jethro/scripts/mailchimp_sync.php on line 271

==
It worked a few days ago. I'm unaware of having changed any mail chimp related settings either on mail chimp or in Jethro.

thanks,
Kristan

@jefft
Copy link
Contributor

jefft commented Feb 20, 2023

The relevant bit of code only runs if Mailchimp returned an error ("errored_operations" > 0):

if (($DEBUG > 1) || ($batch_res_summary['errored_operations'] > 0)) {
// Fetch the results from mailchimp and unpack them
$fp = fopen($batch_res_summary['response_body_url'], 'r');
$batch_results = stream_get_contents($fp);
fclose($fp);
$dir = sys_get_temp_dir().'/jethro-mc-'.time();
$tgzfile = $dir.'/response.tgz';
@mkdir($dir);
file_put_contents($tgzfile, $batch_results);
$p = new PharData($tgzfile);
$p2 = $p->decompress();
$p2->extractTo($dir, NULL, TRUE);
foreach (glob($dir.'/*.json') as $jsonfile) {
$resps = json_decode(file_get_contents($jsonfile));
foreach ($resps as $resp) {
$resp->response = json_decode($resp->response);
// Special handling for 'member in compliance state' unavoidable error
// See https://github.com/tbar0970/jethro-pmm/issues/656
if (is_object($resp->response) && ($resp->response->status == 400) && ($resp->response->title == 'Member In Compliance State')) {
$pemail = substr($resp->operation_id, 4); // chop of 'add-'
$bpersons = $GLOBALS['system']->getDBObjectData('person', Array('email' => $pemail));
foreach ($bpersons as $pid => $pdetail) {
$n = new Person_Note();
$n->setValue('personid', $pid);
$n->setValue('subject', 'Mailchimp sync error');
$n->setValue('details', '[SYSTEM NOTE] Email address '.$pemail.' could not be synced to Mailchimp. Mailchimp said: '.$resp->response->detail);
$n->setValue('creator', $pid);
$n->createIfNew();
}
} else if ($resp->status_code != 200) {
// Unknown error - report it to the console
$all_failures[] = $resp;
}
}
}

This is not a common codepath, and it's quite possible Mailchimp now returning something the script doesn't expect.

Specifically, the script assumes the returned bytes are a tar.gz file containing JSON. There are people saying that it might be returning a tar.gz containing a . element.

Perhaps you could edit scripts/mailchimp_sync.php and just after line 266:

$tgzfile = $dir.'/response.tgz';

Copy the tar.gz somewhere for later inspection:

copy($tgzfile, "/tmp/mailchimp.tgz");

Then see what's in it:

tar tvf /tmp/mailchimp.tgz

@jefft
Copy link
Contributor

jefft commented Apr 3, 2023

Having experienced this for myself, I can confirm it happens when Mailchimp returns errors in a tar.gz file with an unnecessary . entry:

$ tar tf response.tar
.
./u4xj0hswis.json

See attached response.tar.gz for an example. The PHP code:

<?php
$tgzfile="response.tar.gz";
$p = new PharData($tgzfile);
$p2 = $p->decompress();
$p2->extractTo("subdir", NULL, TRUE);

results in the error:

PHP Fatal error:  Uncaught PharException: Extraction from phar "/tmp/mailchimp_pharbug/response.tar.gz" failed: Cannot extract ".", internal error in /tmp/mailchimp_pharbug/extract.php:6
Stack trace:
#0 /tmp/mailchimp_pharbug/extract.php(6): PharData->extractTo()
#1 {main}
  thrown in /tmp/mailchimp_pharbug/extract.php on line 6

jefft added a commit to jefft/jethro-pmm that referenced this issue Apr 3, 2023
tbar0970 added a commit that referenced this issue Apr 12, 2023
#870 - properly parse Mailchimp's broken tgz file with '.' entry
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

Successfully merging a pull request may close this issue.

3 participants