ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilWOPICrawler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 use ILIAS\Data\URI;
28 
32 class ilWOPICrawler extends ilCronJob
33 {
36  private Crawler $crawler;
39 
40  public function __construct()
41  {
42  global $DIC;
43  $this->language = $DIC->language();
44  $this->language->loadLanguageModule('wopi');
45  $this->settings = $DIC->settings();
46  $this->crawler = new Crawler();
47 
48  $this->app_repository = new AppDBRepository($DIC->database());
49  $this->action_repository = new ActionDBRepository($DIC->database());
50  }
51 
52  public function getId(): string
53  {
54  return 'wopi_crawler';
55  }
56 
57  public function getTitle(): string
58  {
59  return $this->language->txt('wopi_crawler_cronjob_title');
60  }
61 
62  public function getDescription(): string
63  {
64  return $this->language->txt('wopi_crawler_cronjob_description');
65  }
66 
67  public function hasAutoActivation(): bool
68  {
69  return true;
70  }
71 
72  public function hasFlexibleSchedule(): bool
73  {
74  return true;
75  }
76 
78  {
79  return CronJobScheduleType::SCHEDULE_TYPE_WEEKLY;
80  }
81 
82  public function getDefaultScheduleValue(): ?int
83  {
84  return 1;
85  }
86 
87  public function run(): ilCronJobResult
88  {
89  $result = new ilCronJobResult();
90  if (!(bool) $this->settings->get('wopi_activated', '0')) {
91  $result->setMessage($this->language->txt('wopi_crawler_cronjob_not_activated'));
92  return $result;
93  }
94  $discovery_url = $this->settings->get('wopi_discovery_url');
95 
96  if (!$this->crawler->validate(new URI($discovery_url))) {
97  $result->setStatus(ilCronJobResult::STATUS_FAIL);
98  $result->setMessage($this->language->txt('msg_error_wopi_invalid_discorvery_url'));
99  return $result;
100  }
101 
102  $apps = $this->crawler->crawl(new URI($discovery_url));
103  if ($apps === null) {
104  $result->setStatus(ilCronJobResult::STATUS_FAIL);
105  $result->setMessage($this->language->txt('wopi_crawler_cronjob_no_apps'));
106  return $result;
107  }
108  $result->setMessage($this->language->txt('wopi_crawler_cronjob_success'));
109  $this->app_repository->storeCollection($apps, $this->action_repository);
110 
111  return $result;
112  }
113 
114 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
AppRepository $app_repository
ActionRepository $action_repository
global $DIC
Definition: shib_login.php:25
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:34
language()
description: > Example for rendring a language glyph.
Definition: language.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Crawler.php:21