function publish_chart($user, $chart, $fromCli = false, $justLocal = false) { $files = array(); if (!$fromCli) { _setPublishStatus($chart, 0.01); } else { print "Publishing chart " . $chart->getID() . ".\n"; } $files = array_merge($files, publish_html($user, $chart)); if (!$fromCli) { _setPublishStatus($chart, 0.05); } $files = array_merge($files, publish_css($user, $chart)); if (!$fromCli) { _setPublishStatus($chart, 0.1); } $files = array_merge($files, publish_data($user, $chart)); if (!$fromCli) { _setPublishStatus($chart, 0.2); } $files = array_merge($files, publish_js($user, $chart)); if (!$fromCli) { _setPublishStatus($chart, 0.3); } else { print "Files stored to static folder (html, css, data, js)\n"; } $totalSize = 0; // total file size foreach ($files as $i => $file) { $totalSize += filesize($file[0]); } $done = 0; foreach ($files as $file) { if (!$justLocal) { publish_push_to_cdn(array($file), $chart); } $done += filesize($file[0]); _setPublishStatus($chart, 0.3 + $done / $totalSize * 0.7); } if (!$fromCli) { _setPublishStatus($chart, 1); _clearPublishStatus($chart); } else { print "Files pushed to CDN.\n"; } $chart->redirectPreviousVersions(); DatawrapperHooks::execute(DatawrapperHooks::POST_CHART_PUBLISH, $chart, $user); }
if (isset($_GLOBALS['dw-config']['memcache'])) { global $memcache; $memcache->delete('publish-status-' . $chart->getID()); } else { unlink('../../charts/tmp/publish-status-' . $chart->getID()); } } $app->post('/charts/:id/publish', function ($chart_id) use($app) { disable_cache($app); if_chart_is_writable($chart_id, function ($user, $chart) use($app) { $files = array(); _setPublishStatus($chart, 0); $files = array_merge($files, publish_html($user, $chart)); $files = array_merge($files, publish_css($user, $chart)); $files = array_merge($files, publish_data($user, $chart)); $files = array_merge($files, publish_js($user, $chart)); _setPublishStatus($chart, 0.3); $totalSize = 0; // total file size foreach ($files as $i => $file) { $totalSize += filesize($file[0]); } $done = 0; foreach ($files as $file) { publish_push_to_cdn(array($file), $chart); $done += filesize($file[0]); _setPublishStatus($chart, 0.3 + $done / $totalSize * 0.7); } _setPublishStatus($chart, 1); _clearPublishStatus($chart); DatawrapperHooks::execute(DatawrapperHooks::POST_CHART_PUBLISH, $chart, $user);