partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

CacheWarmupSetupController.php (3557B)


      1 <?php
      2 
      3 namespace PartKeepr\SetupBundle\Controller;
      4 
      5 use Symfony\Bundle\FrameworkBundle\Console\Application;
      6 use Symfony\Component\Console\Input\ArrayInput;
      7 use Symfony\Component\Console\Output\NullOutput;
      8 use Symfony\Component\HttpFoundation\JsonResponse;
      9 use Symfony\Component\HttpFoundation\Request;
     10 use Symfony\Component\HttpFoundation\Response;
     11 use Symfony\Component\Routing\Annotation\Route;
     12 
     13 class CacheWarmupSetupController extends SetupBaseController
     14 {
     15     /**
     16      * @Route("/setup/_int_cache_warmup")
     17      */
     18     public function intCacheWarmupAction(Request $request)
     19     {
     20         if (!$this->ensureAuthKey($request)) {
     21             return $this->getAuthKeyErrorResponse();
     22         }
     23 
     24         $response = [
     25             'success' => true,
     26             'errors'  => [],
     27             'message' => 'Cache successfully warmed up',
     28         ];
     29 
     30         try {
     31             $kernel = $this->get('kernel');
     32             $application = new Application($kernel);
     33             $application->setAutoExit(false);
     34             $output = new NullOutput();
     35 
     36             $input = new ArrayInput([
     37                 'command' => 'cache:warmup',
     38             ]);
     39 
     40             $application->run($input, $output);
     41 
     42             $input = new ArrayInput([
     43                 'command' => 'nfq:sprite:generate',
     44             ]);
     45 
     46             $application->run($input, $output);
     47 
     48             $input = new ArrayInput([
     49                 'command' => 'assets:install',
     50             ]);
     51 
     52             $application->run($input, $output);
     53 
     54             $input = new ArrayInput([
     55                 'command' => 'generate:extjs:entities',
     56             ]);
     57 
     58             $application->run($input, $output);
     59 
     60             $input = new ArrayInput([
     61                 'command' => 'assetic:dump',
     62             ]);
     63 
     64             $application->run($input, $output);
     65 
     66             $input = new ArrayInput([
     67                 'command' => 'partkeepr:update-category-paths',
     68             ]);
     69 
     70             $application->run($input, $output);
     71 
     72             $input = new ArrayInput([
     73                 'command' => 'partkeepr:cron:clear',
     74             ]);
     75 
     76             $application->run($input, $output);
     77 
     78             $input = new ArrayInput([
     79                 'command' => 'partkeepr:cron:versioncheck',
     80             ]);
     81 
     82             $application->run($input, $output);
     83 
     84             $input = new ArrayInput([
     85                 'command' => 'partkeepr:cron:synctips',
     86             ]);
     87 
     88             $application->run($input, $output);
     89 
     90             $input = new ArrayInput([
     91                 'command' => 'partkeepr:cron:create-statistic-snapshot',
     92             ]);
     93 
     94             $application->run($input, $output);
     95 
     96             if (function_exists('apc_clear_cache')) {
     97                 apc_clear_cache();
     98             }
     99         } catch (\Exception $e) {
    100             $response['success'] = false;
    101             $response['message'] = 'Cache warm up error';
    102             $response['errors'] = [$e->getMessage(), $e->getTrace()];
    103         }
    104 
    105         return new JsonResponse($response);
    106     }
    107 
    108     /**
    109      * @Route("/setup/warmupCache")
    110      */
    111     public function cacheWarmupAction(Request $request)
    112     {
    113         // Clear old cache. We don't do that directly as it could happen that old files are loaded prior clearing the cache
    114         $cacheDir = $this->get('kernel')->getRootDir().'/cache/prod';
    115 
    116         $filesystem = $this->get('filesystem');
    117         $filesystem->remove($cacheDir);
    118 
    119         $response = $this->handleRequest($request, '/setup/_int_cache_warmup', [], 'prod');
    120 
    121         return new Response($response->getContent());
    122     }
    123 }