Oara\Network\Publisher\TradeDoubler::checkReportError PHP Method

checkReportError() public method

public checkReportError ( $content, $request, $try )
    public function checkReportError($content, $request, $try = 0)
    {
        if (\preg_match('/\\/report\\/published\\/aAffiliateEventBreakdownReport/', $content, $matches)) {
            //report too big, we have to download it and read it
            if (\preg_match('/(\\/report\\/published\\/(aAffiliateEventBreakdownReport(.*))\\.zip)/', $content, $matches)) {
                $file = "http://publisher.tradedoubler.com" . $matches[0];
                $newfile = \realpath(\dirname(COOKIES_BASE_DIR)) . '/pdf/' . $matches[2] . '.zip';
                if (!\copy($file, $newfile)) {
                    throw new \Exception('Failing copying the zip file \\n\\n');
                }
                $zip = new \ZipArchive();
                if ($zip->open($newfile, \ZIPARCHIVE::CREATE) !== TRUE) {
                    throw new \Exception('Cannot open zip file \\n\\n');
                }
                $zip->extractTo(\realpath(\dirname(COOKIES_BASE_DIR)) . '/pdf/');
                $zip->close();
                $unzipFilePath = \realpath(\dirname(COOKIES_BASE_DIR)) . '/pdf/' . $matches[2];
                $fileContent = \file_get_contents($unzipFilePath);
                \unlink($newfile);
                \unlink($unzipFilePath);
                return $fileContent;
            }
            throw new \Exception('Report too big \\n\\n');
        } else {
            if (\preg_match("/ error/", $content, $matches)) {
                $urls = array();
                $urls[] = $request;
                $exportReport = $this->_client->get($urls);
                $try++;
                if ($try < 5) {
                    return self::checkReportError($exportReport[0], $request, $try);
                } else {
                    throw new \Exception('Problem checking report\\n\\n');
                }
            } else {
                return $content;
            }
        }
    }