public static function waitForUpload($sessionID, $response, $context, $allowError = false) { $xml = Sync::getXMLFromResponse($response); if (isset($xml->uploaded) || isset($xml->error) && $allowError) { return $xml; } $context->assertTrue(isset($xml->queued)); $max = 5; do { $wait = (int) $xml->queued['wait']; sleep($wait / 1000); $response = Sync::uploadStatus($sessionID, $allowError); $xml = Sync::getXMLFromResponse($response); $max--; } while (isset($xml->queued) && $max > 0); if (!$max) { $context->fail("Upload did not finish after {$max} attempts"); } if (!$allowError) { $context->assertTrue(isset($xml->uploaded)); } return $xml; }