/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $runAll = array_reduce($this->option(), function ($runAll, $option) {
         if ($runAll) {
             return (bool) $option === true ? false : true;
         }
         return $runAll;
     }, true);
     if ($this->option('regular') || $runAll) {
         // Regular Pages
         $pagesCrawler = new PagesCrawler();
         $pagesCrawler->map(function ($pageInfo) {
             if ($pageInfo['pageType'] == 'regular') {
                 $this->cacheFileHandler->saveCacheFile($pageInfo['url'], $pageInfo['content']());
             }
         });
     }
     if ($this->option('dynamic') || $runAll) {
         // Dynamic Pages
         $mapUrlDynamic = function ($urlDynamic) {
             $length = count($urlDynamic->parameters_lists);
             if ($length > 0) {
                 $this->dynamicRecursiveProcess($urlDynamic->parameters_lists, 0, ['url' => $urlDynamic->url, 'use_internal_url' => $urlDynamic->use_internal_url, 'internal_url' => $urlDynamic->internal_url, 'length' => $length]);
             } else {
                 $this->generateCacheFile(['url' => $urlDynamic->url, 'use_internal_url' => $urlDynamic->use_internal_url, 'internal_url' => $urlDynamic->internal_url, 'length' => $length]);
             }
         };
         if (count($this->option('dynamic-item')) === 0) {
             UrlDynamic::all()->map($mapUrlDynamic);
         } else {
             foreach ($this->option('dynamic-item') as $dynamicId) {
                 $mapUrlDynamic(UrlDynamic::find($dynamicId));
             }
         }
     }
     if ($this->option('blacklist') || $runAll) {
         @mkdir($this->cacheFileHandler->getCachePath(), 0777, true);
         // Index Blacklist
         $indexBlacklist = join('', array_map(function ($url) {
             $url = str_replace('/', '\\/', trim($url, '/'));
             return "(?!\\/{$url})";
         }, UrlBlacklist::all()->lists('url')));
         file_put_contents($this->cacheFileHandler->getCachePath() . '/index-blacklist.config', $indexBlacklist);
         // Route Blacklist
         $routeBlacklist = join('', array_map(function ($url) {
             $url = str_replace('/', '\\/', trim($url, '/'));
             return "(?!{$url})";
         }, UrlBlacklist::all()->lists('url')));
         file_put_contents($this->cacheFileHandler->getCachePath() . '/route-blacklist.config', $routeBlacklist);
         // Param Blacklist
         $paramBlacklist = GetParamBlacklist::all();
         $paramBlacklist->push(['name' => 'nocache', 'values' => json_encode([['value' => '1']])]);
         file_put_contents($this->cacheFileHandler->getCachePath() . '/param-blacklist.config', $paramBlacklist->toJson());
         // Param Blacklist function
         copy(\App::pluginsPath() . '/ebussola/statefull/assets/param-blacklist-function.php', $this->cacheFileHandler->getCachePath() . '/param-blacklist-function.php');
     }
 }
 /**
  * Called when data is being imported.
  * The $results array should be in the format of:
  *
  *    [
  *        'db_name1' => 'Some value',
  *        'db_name2' => 'Another value'
  *    ],
  *    [...]
  *
  */
 public function importData($results, $sessionKey = null)
 {
     foreach ($results as $row => $data) {
         try {
             $data['parameters_lists'] = json_decode($data['parameters_lists']);
             UrlDynamic::create($data);
             $this->logCreated();
         } catch (\Exception $e) {
             $this->logError($row, $e->getMessage());
         }
     }
 }
Exemplo n.º 3
0
 public function onSearchDynamics()
 {
     $pageCrawler = new PagesCrawler();
     array_map(function ($pageInfo) {
         if (!UrlDynamic::query()->where('url', $pageInfo['url'])->first()) {
             UrlDynamic::create(['url' => $pageInfo['url'], 'parameters_lists' => array_map(function ($item) {
                 return ['name' => $item, 'code' => '<?php return [];'];
             }, $pageInfo['urlParameters'])]);
         }
     }, $pageCrawler->getPageInfos('dynamic'));
     return $this->listRefresh();
 }
 /**
  * Called when data is being exported.
  * The return value should be an array in the format of:
  *
  *   [
  *       'db_name1' => 'Some attribute value',
  *       'db_name2' => 'Another attribute value'
  *   ],
  *   [...]
  *
  */
 public function exportData($columns, $sessionKey = null)
 {
     return UrlDynamic::all($columns)->toArray();
 }