Exemplo n.º 1
0
 /**
  * Handle the event.
  *
  * @param  ProjectWatcher  $event []
  * @return void
  */
 public function handle(ProjectWatcher $event)
 {
     $urlsFromDatabase = $event->project->urls->pluck('url');
     if (is_string($urlsFromDatabase)) {
         $urlsFromDatabase = (array) $urlsFromDatabase;
     } else {
         $urlsFromDatabase = $urlsFromDatabase->toArray();
     }
     $this->crawler->setBaseUrl($event->project->main_url);
     $this->crawler->start();
     $urlsFromWeb = array_merge($this->crawler->getSiteUrl(), $this->crawler->getSiteCss(), $this->crawler->getSiteJs());
     if (empty($urlsFromDatabase)) {
         foreach ($urlsFromWeb as $url) {
             $this->addNewUrl($event, $url);
         }
     } else {
         foreach ($urlsFromWeb as $url) {
             if (!in_array($url['url'], $urlsFromDatabase)) {
                 $this->addNewUrl($event, $url);
             }
         }
         foreach ($urlsFromDatabase as $url) {
             $objectUrl = Url::ByUrl($url)->first();
             if (!in_array($url, array_pluck($urlsFromWeb, 'url'))) {
                 $objectUrl->update(['is_active' => false]);
             } else {
                 $objectUrl->update(['is_active' => true]);
             }
         }
     }
     $event->project->update(['is_crawlable' => false]);
 }
Exemplo n.º 2
0
 /**
  * Test get query scope of byType method
  *
  * @return void
  */
 public function testScopeByType()
 {
     $url = new Url();
     $this->assertEquals(new Collection(), $url->byType('url')->get());
 }