ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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;
33 
34  public function __construct()
35  {
36  // determine ilias and delos-skin paths.
37  $this->ilias_path = dirname(__FILE__, 5);
38  $this->delos_path = "$this->ilias_path/templates/default/";
39 
40  // calculate original logo hashes.
41  $this->delos_responsive_logo_hash = $this->getFileHash($this->delos_path . self::RESPONSIVE_LOGO_PATH);
42  $this->delos_common_logo_hash = $this->getFileHash($this->delos_path . self::COMMON_LOGO_PATH);
43  }
44 
48  public function getHash() : string
49  {
50  return hash("sha256", self::class);
51  }
52 
56  public function getLabel() : string
57  {
58  return 'Replacing responsive logos where necessary.';
59  }
60 
64  public function isNotable() : bool
65  {
66  return true;
67  }
68 
72  public function getPreconditions(Environment $environment) : array
73  {
74  return [];
75  }
76 
80  public function achieve(Environment $environment) : Environment
81  {
82  // abort if the header-icons of the delos skin could not be located.
83  if (null === $this->delos_common_logo_hash || null === $this->delos_responsive_logo_hash) {
84  return $environment;
85  }
86 
87  $skin_directory = "$this->ilias_path/Customizing/global/skin/";
88 
89  // nothing to do if no custom skins were installed/created.
90  if (!file_exists($skin_directory) || !is_dir($skin_directory)) {
91  return $environment;
92  }
93 
94  foreach (new DirectoryIterator($skin_directory) as $skin_name) {
95  if ('.' === $skin_name || '..' === $skin_name) {
96  continue;
97  }
98 
99  $this->maybeReplaceResponsiveIcon($skin_directory . $skin_name);
100  }
101 
102  return $environment;
103  }
104 
109  protected function maybeReplaceResponsiveIcon(string $skin_path) : void
110  {
111  $responsive_logo = $skin_path . self::RESPONSIVE_LOGO_PATH;
112  $common_logo = $skin_path . self::COMMON_LOGO_PATH;
113 
114  if ($this->getFileHash($common_logo) !== $this->delos_common_logo_hash &&
115  $this->getFileHash($responsive_logo) === $this->delos_responsive_logo_hash
116  ) {
117  copy($common_logo, $responsive_logo);
118  }
119  }
120 
124  protected function getFileHash(string $absolute_file_path) : ?string
125  {
126  if (!file_exists($absolute_file_path)) {
127  return null;
128  }
129 
130  if (false !== ($hash = sha1_file($absolute_file_path))) {
131  return $hash;
132  }
133 
134  return null;
135  }
136 }
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:14
An environment holds resources to be used in the setup process.
Definition: Environment.php:11
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...