ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilStyleReplaceResponsiveLogoObjective.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/* Copyright (c) 2022 Thibeau Fuhrer <thibeau@sr.solutions> Extended GPL, see docs/LICENSE */
4
7
13{
14 protected const RESPONSIVE_LOGO_PATH = '/images/HeaderIconResponsive.svg';
15 protected const COMMON_LOGO_PATH = '/images/HeaderIcon.svg';
16
28 protected $delos_path;
32 protected $ilias_path;
36 protected $skins_path;
37
38 public function __construct()
39 {
40 // determine ilias and delos-skin paths.
41 $this->ilias_path = dirname(__FILE__, 5);
42 $this->delos_path = "$this->ilias_path/templates/default/";
43 $this->skins_path = "$this->ilias_path/Customizing/global/skin/";
44
45 // calculate original logo hashes.
46 $this->delos_responsive_logo_hash = $this->getFileHash($this->delos_path . self::RESPONSIVE_LOGO_PATH);
47 $this->delos_common_logo_hash = $this->getFileHash($this->delos_path . self::COMMON_LOGO_PATH);
48 }
49
53 public function getHash() : string
54 {
55 return hash("sha256", self::class);
56 }
57
61 public function getLabel() : string
62 {
63 return 'Replacing responsive logos where necessary.';
64 }
65
69 public function isNotable() : bool
70 {
71 return true;
72 }
73
77 public function isApplicable(Environment $environment) : bool
78 {
79 // nothing to do if no custom skins were installed/created.
80 return (file_exists($this->skins_path) && is_dir($this->skins_path));
81 }
82
86 public function getPreconditions(Environment $environment) : array
87 {
88 return [];
89 }
90
94 public function achieve(Environment $environment) : Environment
95 {
96 // abort if the header-icons of the delos skin could not be located.
97 if (null === $this->delos_common_logo_hash || null === $this->delos_responsive_logo_hash) {
98 return $environment;
99 }
100
101 foreach (new DirectoryIterator($this->skins_path) as $skin_name) {
102 if ('.' === $skin_name || '..' === $skin_name) {
103 continue;
104 }
105
106 $this->maybeReplaceResponsiveIcon($this->skins_path . $skin_name);
107 }
108
109 return $environment;
110 }
111
116 protected function maybeReplaceResponsiveIcon(string $skin_path) : void
117 {
118 $responsive_logo = $skin_path . self::RESPONSIVE_LOGO_PATH;
119 $common_logo = $skin_path . self::COMMON_LOGO_PATH;
120
121 if ($this->getFileHash($common_logo) !== $this->delos_common_logo_hash &&
122 $this->getFileHash($responsive_logo) === $this->delos_responsive_logo_hash
123 ) {
124 copy($common_logo, $responsive_logo);
125 }
126 }
127
131 protected function getFileHash(string $absolute_file_path) : ?string
132 {
133 if (!file_exists($absolute_file_path)) {
134 return null;
135 }
136
137 if (false !== ($hash = sha1_file($absolute_file_path))) {
138 return $hash;
139 }
140
141 return null;
142 }
143}
An exception for terminatinating execution or to throw for unit testing.
isApplicable(Environment $environment)
Get to know whether the objective is applicable.Don't change the environment or cause changes on serv...
getFileHash(string $absolute_file_path)
Returns the sha1-sum of the given file if it exists.
maybeReplaceResponsiveIcon(string $skin_path)
Replaces the responsive header-icon with the common header-icon, if the common icon is different from...
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:15