Exemplo n.º 1
0
 public function registerSchedule($schedule)
 {
     $settings = Settings::instance();
     $schedule->call(function () {
         BrokenLink::processLinks();
     })->cron($settings->time);
 }
Exemplo n.º 2
0
 public function onRefreshLinkList()
 {
     $brokenLinks = BrokenLink::processLinks();
     Flash::success(Lang::get('bombozama.linkcheck::lang.strings.total_links', ['number' => $brokenLinks]));
     return $this->listRefresh();
 }
Exemplo n.º 3
0
 /**
  * Checks for broken links in selected database fields and/or all CMS files
  * @return void
  */
 public static function processLinks()
 {
     # Let's start by truncating the BrokenLinks table
     BrokenLink::truncate();
     $brokenLinks = [];
     $settings = Settings::instance();
     foreach ($settings->modelators as $el) {
         list($modelName, $field) = explode('::', $el['modelator']);
         $models = $modelName::whereNotNull($field)->get();
         foreach ($models as $model) {
             $urls = Helper::scanForUrls($model->{$field});
             $modelParts = explode('\\', $modelName);
             foreach ($urls as $url) {
                 $status = BrokenLink::isBrokenLink($url);
                 if ($status) {
                     $brokenLinks[] = ['status' => $status, 'plugin' => $modelParts[1] . '.' . $modelParts[2], 'model' => array_pop($modelParts), 'model_id' => $model->id, 'field' => $field, 'url' => $model->{$field}];
                 }
             }
         }
     }
     /**
      * Go process the current theme
      */
     $theme = Theme::getActiveTheme();
     $theme->getPath();
     /**
      * Should we process theme pages?
      */
     if ($settings['checkCMS'] == '1') {
         foreach (File::directories($theme->getPath()) as $themeSubDir) {
             # Skip the assets folder
             if (basename($themeSubDir) == 'assets') {
                 continue;
             }
             foreach (File::allFiles($themeSubDir) as $filePath) {
                 $urls = Helper::scanForUrls(file_get_contents($filePath));
                 foreach ($urls as $url) {
                     $status = BrokenLink::isBrokenLink($url);
                     if ($status) {
                         $brokenLinks[] = ['status' => $status, 'plugin' => 'CMS', 'model' => str_replace($theme->getPath() . DIRECTORY_SEPARATOR, '', $filePath), 'url' => $url];
                     }
                 }
             }
         }
     }
     /**
      * Lets seed the BrokenLink table with any and all found links.
      */
     foreach ($brokenLinks as $brokenLink) {
         BrokenLink::create($brokenLink);
     }
     return count($brokenLinks);
 }