ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilWOPICrawler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 use ILIAS\Data\URI;
30 
34 class ilWOPICrawler extends CronJob
35 {
38  private Crawler $crawler;
41 
42  public function __construct()
43  {
44  global $DIC;
45  $this->language = $DIC->language();
46  $this->language->loadLanguageModule('wopi');
47  $this->settings = $DIC->settings();
48  $this->crawler = new Crawler();
49 
50  $this->app_repository = new AppDBRepository($DIC->database());
51  $this->action_repository = new ActionDBRepository($DIC->database());
52  }
53 
54  public function getId(): string
55  {
56  return 'wopi_crawler';
57  }
58 
59  public function getTitle(): string
60  {
61  return $this->language->txt('wopi_crawler_cronjob_title');
62  }
63 
64  public function getDescription(): string
65  {
66  return $this->language->txt('wopi_crawler_cronjob_description');
67  }
68 
69  public function hasAutoActivation(): bool
70  {
71  return true;
72  }
73 
74  public function hasFlexibleSchedule(): bool
75  {
76  return true;
77  }
78 
80  {
81  return JobScheduleType::WEEKLY;
82  }
83 
84  public function getDefaultScheduleValue(): ?int
85  {
86  return 1;
87  }
88 
89  public function run(): JobResult
90  {
91  $result = new JobResult();
92  if (!(bool) $this->settings->get('wopi_activated', '0')) {
93  $result->setMessage($this->language->txt('wopi_crawler_cronjob_not_activated'));
94  return $result;
95  }
96  $discovery_url = $this->settings->get('wopi_discovery_url');
97 
98  if (!$this->crawler->validate(new URI($discovery_url))) {
99  $result->setStatus(JobResult::STATUS_FAIL);
100  $result->setMessage($this->language->txt('msg_error_wopi_invalid_discorvery_url'));
101  return $result;
102  }
103 
104  $apps = $this->crawler->crawl(new URI($discovery_url));
105  if ($apps === null) {
106  $result->setStatus(JobResult::STATUS_FAIL);
107  $result->setMessage($this->language->txt('wopi_crawler_cronjob_no_apps'));
108  return $result;
109  }
110  $result->setMessage($this->language->txt('wopi_crawler_cronjob_success'));
111  $this->app_repository->storeCollection($apps, $this->action_repository);
112 
113  return $result;
114  }
115 
116 }
AppRepository $app_repository
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ActionRepository $action_repository
global $DIC
Definition: shib_login.php:22
language()
description: > Example for rendring a language glyph.
Definition: language.php:41