public function jobsAdmin($app, $page) { $jobs = JobQuery::create()->filterByStatus('failed')->orderById('desc')->find(); $page = array_merge($page, array('title' => 'Background Jobs', 'jobs' => count($jobs) > 0 ? $jobs : false, 'queued' => JobQuery::create()->filterByStatus('queued')->count(), 'failed' => JobQuery::create()->filterByStatus('failed')->count(), 'done' => JobQuery::create()->filterByStatus('done')->count())); $page['est_time'] = ceil($page['queued'] * 2 / 60); $app->render('plugins/admin-jobs/admin-jobs.twig', $page); }
function add_adminpage_vars(&$page, $active) { $page['adminmenu'] = array('/admin' => 'Dashboard', '/admin/users' => 'Users', '/admin/themes' => 'Themes', '/admin/jobs' => 'Jobs'); $q = JobQuery::create()->filterByStatus('queued')->count(); if ($q > 0) { $page['adminmenu']['/admin/jobs'] .= ' <span class="badge badge-info">' . $q . '</span>'; } $f = JobQuery::create()->filterByStatus('failed')->count(); if ($f > 0) { $page['adminmenu']['/admin/jobs'] .= ' <span class="badge badge-important">' . $f . '</span>'; } $page['adminactive'] = $active; }
<?php require_once ROOT_PATH . 'lib/utils/themes.php'; require_once ROOT_PATH . 'vendor/jsmin/jsmin.php'; /* * PUBLISH STEP - shows progress of publishing action and thumbnail generation * forwards to /chart/:id/finish */ $app->get('/chart/:id/publish', function ($id) use($app) { disable_cache($app); check_chart_writable($id, function ($user, $chart) use($app) { $cfg = $GLOBALS['dw_config']; $page = array('title' => $chart->getID() . ' :: ' . __('Publish'), 'chartData' => $chart->loadData(), 'chart' => $chart, 'visualizations' => DatawrapperVisualization::all(), 'vis' => DatawrapperVisualization::get($chart->getType()), 'chartUrl' => $chart->getPublicUrl(), 'chartUrlLocal' => '/chart/' . $chart->getID() . '/preview', 'themes' => DatawrapperTheme::all(), 'exportStaticImage' => !empty($cfg['phantomjs']), 'chartActions' => DatawrapperHooks::execute(DatawrapperHooks::GET_CHART_ACTIONS, $chart), 'estExportTime' => ceil(JobQuery::create()->estimatedTime('export_image') / 60)); add_header_vars($page, 'chart', 'chart-editor/publish.css'); add_editor_nav($page, 4); if ($user->isAbleToPublish() && ($chart->getLastEditStep() == 3 || $app->request()->get('republish') == 1)) { // actual publish process $chart->publish(); $page['chartUrl'] = $chart->getPublicUrl(); // generate thumbnails $page['publish'] = true; $page['republish'] = $app->request()->get('republish') == 1; } $app->render('chart/publish.twig', $page); }); });
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Chart is new, it will return * an empty collection; or if this Chart has previously * been saved, it will retrieve related Jobs from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Chart. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelObjectCollection|Job[] List of Job objects */ public function getJobsJoinUser($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = JobQuery::create(null, $criteria); $query->joinWith('User', $join_behavior); return $this->getJobs($query, $con); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(JobPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = JobQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
if_chart_is_writable($chart_id, function ($user, $chart) use($app, $type) { try { // create a new export job for this chart $params = json_decode($app->request()->getBody(), true); $job = JobQuery::create()->createJob($type, $chart, $user, $params); ok(ceil(JobQuery::create()->estimatedTime($type) / 60)); } catch (Exception $e) { error('io-error', $e->getMessage()); } }); }); /* * returns the estimated time to complete a new print job * in minutes */ $app->get('/jobs/:type/estimate', function ($type) use($app) { disable_cache($app); ok(ceil(JobQuery::create()->estimatedTime($type) / 60)); }); /* * change status of a job, need admin access */ $app->put('/jobs/:id', function ($job_id) use($app) { if_is_admin(function () use($app, $job_id) { $job = JobQuery::create()->findOneById($job_id); $params = json_decode($app->request()->getBody(), true); $job->setStatus($params['status']); $job->save(); ok(); }); });
public function triggerExportJob($chart, $user) { // queue a job for thumbnail generation $params = array('width' => $chart->getMetadata('publish.embed-width'), 'height' => $chart->getMetadata('publish.embed-height')); $job = JobQuery::create()->createJob("export_static_chart", $chart, $user, $params); }
<?php /* * PUBLISH STEP - shows progress of publishing action and thumbnail generation */ $app->get('/chart/:id/publish', function ($id) use($app) { disable_cache($app); check_chart_writable($id, function ($user, $chart) use($app) { $cfg = $GLOBALS['dw_config']; $chartActions = DatawrapperHooks::execute(DatawrapperHooks::GET_CHART_ACTIONS, $chart); // add duplicate action $chartActions[] = array('id' => 'duplicate', 'icon' => 'code-fork', 'title' => __('Duplicate this chart'), 'order' => 500); // sort actions usort($chartActions, function ($a, $b) { return (isset($a['order']) ? $a['order'] : 999) - (isset($b['order']) ? $b['order'] : 999); }); $chartW = $chart->getMetadata('publish.embed-width'); $chartH = $chart->getMetadata('publish.embed-height'); if (substr($chartW, -1) != '%') { $chartW .= 'px'; } if (substr($chartH, -1) != '%') { $chartH .= 'px'; } $page = array('title' => $chart->getID() . ' :: ' . __('Publish'), 'chartData' => $chart->loadData(), 'chart' => $chart, 'visualizations' => DatawrapperVisualization::all(), 'vis' => DatawrapperVisualization::get($chart->getType()), 'chartUrl' => $chart->getPublicUrl(), 'chartUrlLocal' => '/chart/' . $chart->getID() . '/preview', 'embedWidth' => $chartW, 'embedHeight' => $chartH, 'themes' => DatawrapperTheme::all(), 'exportStaticImage' => !empty($cfg['phantomjs']), 'chartActions' => $chartActions, 'estExportTime' => ceil(JobQuery::create()->estimatedTime('export') / 60)); add_header_vars($page, 'chart', 'chart-editor/publish.css'); add_editor_nav($page, 4); $app->render('chart/publish.twig', $page); }); });
public function unpublish() { $path = $this->getStaticPath(); if (file_exists($path)) { $dirIterator = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS); $itIterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST); foreach ($itIterator as $entry) { $file = realpath((string) $entry); if (is_dir($file)) { rmdir($file); } else { unlink($file); } } rmdir($path); } // Load CDN publishing class $config = $GLOBALS['dw_config']; if (!empty($config['publish'])) { // remove files from CDN $pub = get_module('publish', dirname(__FILE__) . '/../../../../'); $id = $this->getID(); $chart_files = array(); $chart_files[] = "{$id}/index.html"; $chart_files[] = "{$id}/data"; $chart_files[] = "{$id}/{$id}.min.js"; $pub->unpublish($chart_files); } // remove all jobs related to this chart JobQuery::create()->filterByChart($this)->delete(); }
public function unpublish() { $path = $this->getStaticPath(); if (file_exists($path)) { array_map('unlink', glob($path . "/*")); rmdir($path); } // Load CDN publishing class $config = $GLOBALS['dw_config']; if (!empty($config['publish'])) { // remove files from CDN $pub = get_module('publish', dirname(__FILE__) . '/../../../../'); $id = $this->getID(); $chart_files = array(); $chart_files[] = "{$id}/index.html"; $chart_files[] = "{$id}/data"; $chart_files[] = "{$id}/{$id}.min.js"; $pub->unpublish($chart_files); } // remove all jobs related to this chart JobQuery::create()->filterByChart($this)->delete(); }