Beispiel #1
0
function get_cache()
{
    try {
        $cache = new \Doctrine\Common\Cache\FilesystemCache(CACHE_DIR);
        $cache->save('test.it.ok_or_not', true);
        return $cache;
    } catch (\Exception $e) {
        return new \Doctrine\Common\Cache\ArrayCache();
    }
}
 public function robotsAction(Request $request)
 {
     $host = $request->headers->get('host');
     $cacheId = 'robots_txt';
     $env = $this->get('kernel')->getEnvironment();
     $cache = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/' . $env . '/sys/' . $host . '/etc/');
     //$cache = new \Doctrine\Common\Cache\ApcCache();
     if ($fooString = $cache->fetch($cacheId)) {
         $response = unserialize($fooString);
     } else {
         $site = $this->getSite();
         if (!$site) {
             $response = $this->render('CMFTemplateBundle:Status:404.html.twig');
             $response->setStatusCode(404);
             return $response;
         }
         $response = new Response();
         $response->headers->set('Content-Type', 'text/plain');
         $response->sendHeaders();
         $response->setContent($site['robots_txt']);
         $cache->save($cacheId, serialize($response));
     }
     return $response;
 }
 /**
  * Edits an existing Site entity.
  *
  */
 public function updateAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository('NovuscomCMFBundle:Site')->find($id);
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find Site entity.');
     }
     $originalAliases = new ArrayCollection();
     // Create an ArrayCollection of the current Tag objects in the database
     foreach ($entity->getAliases() as $tag) {
         $originalAliases->add($tag);
     }
     $deleteForm = $this->createDeleteForm($id);
     $editForm = $this->createEditForm($entity);
     $editForm->handleRequest($request);
     if ($editForm->isSubmitted()) {
         if ($editForm->isValid()) {
             foreach ($originalAliases as $alias) {
                 if (false === $entity->getAliases()->contains($alias)) {
                     // remove the Task from the Tag
                     $entity->getAliases()->removeElement($alias);
                     // if it was a many-to-one relationship, remove the relationship like this
                     // $tag->setTask(null);
                     $em->persist($entity);
                     // if you wanted to delete the Tag entirely, you can also do that
                     $em->remove($alias);
                 }
             }
             $host = $request->headers->get('host');
             $cacheElement = 'robots_txt';
             $cacheProd = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/prod/sys/' . $host . '/etc/');
             $cacheDev = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/dev/sys/' . $host . '/etc/');
             //$cacheProd = new \Doctrine\Common\Cache\ApcCache();
             //$cacheDev = new \Doctrine\Common\Cache\ApcCache();
             $cacheProd->delete($cacheElement);
             $cacheDev->delete($cacheElement);
             $em->flush();
             return $this->redirect($this->generateUrl('cmf_admin_site_edit', array('id' => $id)));
         } else {
         }
     } else {
     }
     return $this->render('NovuscomCMFBundle:Site:edit.html.twig', array('entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()));
 }
Beispiel #4
0
        $resqueStat = new ResqueBoard\Lib\ResqueStat();
        $app->view(new ResqueBoard\View\JsonView());
        $app->render('jobs_class_distribution.ctp', array('class' => $resqueStat->getJobsRepartionStats($limit)));
    } catch (\Exception $e) {
        $app->error($e);
    }
})->conditions(array('limit' => '\\d+'));
/**
 * Return a list of scheduled jobs count grouped by time
 * Used to populate the cal-heatmap
 */
$app->get('/api/scheduled-jobs/stats/:start/:end', function ($start, $end) use($app) {
    $app->response()->header("Content-Type", "application/json");
    try {
        $cacheId = $start . $end;
        $cacheDriver = new \Doctrine\Common\Cache\FilesystemCache(CACHE . DS . 'scheduled-jobs' . DS . 'stats', '.cache');
        if ($cacheDriver->contains($cacheId)) {
            $jobs = $cacheDriver->fetch($cacheId);
        } else {
            $resqueSchedulerStat = new ResqueBoard\Lib\ResqueSchedulerStat();
            $jobs = $resqueSchedulerStat->getScheduledJobsCount((int) $start, (int) $end + 60, true);
            $jobs = json_encode($jobs);
            if ($start < $end && $end < time()) {
                $cacheDriver->save($cacheId, $jobs);
            }
        }
        echo $jobs;
    } catch (\Exception $e) {
        $app->error($e);
    }
})->conditions(array('start' => '\\d+', 'end' => '\\d+'));