Skip to content

Commit 577a940

Browse files
committed
47525: Style images still missing after (amended) style.ilStyleIRSSMigration
1 parent e196aad commit 577a940

8 files changed

Lines changed: 157 additions & 207 deletions

File tree

components/ILIAS/Style/Content/Characteristic/class.ilStyleCharacteristicGUI.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function executeCommand(): void
109109

110110
$next_class = $ctrl->getNextClass($this);
111111
$cmd = $ctrl->getCmd();
112+
$this->showMigrationState();
112113
switch ($next_class) {
113114
default:
114115
if (in_array($cmd, [
@@ -118,12 +119,38 @@ public function executeCommand(): void
118119
"pasteCharacteristicsWithinStyle", "pasteCharacteristicsFromOtherStyle",
119120
"saveStatus", "setOutdated", "removeOutdated",
120121
"editTagStyle", "refreshTagStyle", "updateTagStyle",
121-
"editTagTitles", "saveTagTitles", "switchMQuery"])) {
122+
"editTagTitles", "saveTagTitles", "switchMQuery", "migrateImages"])) {
122123
$this->$cmd();
123124
}
124125
}
125126
}
126127

128+
public function showMigrationState(): void
129+
{
130+
$mt = $this->gui_service->mainTemplate();
131+
$lng = $this->domain_service->lng();
132+
$style_id = $this->object->getId();
133+
$f = $this->gui_service->ui()->factory();
134+
$toolbar = $this->gui_service->toolbar();
135+
$ctrl = $this->gui_service->ctrl();
136+
if (!$this->domain_service->style($style_id)->isMigrated()) {
137+
$mt->setOnScreenMessage('info', $lng->txt('sty_style_not_migrated'));
138+
} else {
139+
if ($this->domain_service->image(
140+
$style_id,
141+
$this->access_manager
142+
)->hasLegacyDirAndNoImages()) {
143+
$mt->setOnScreenMessage('info', $lng->txt('sty_legacy_image_directory_found'));
144+
$toolbar->addComponent(
145+
$f->button()->standard(
146+
$lng->txt('sty_migrate_images'),
147+
$ctrl->getLinkTarget($this, "migrateImages")
148+
)
149+
);
150+
}
151+
}
152+
}
153+
127154
public function listCharacteristics(): void
128155
{
129156
$lng = $this->domain_service->lng();
@@ -1338,4 +1365,11 @@ public function switchMQuery(): void
13381365
$ctrl->redirectByClass("ilstylecharacteristicgui", "editTagStyle");
13391366
}
13401367

1368+
protected function migrateImages(): void
1369+
{
1370+
$this->domain_service->style($this->object->getId())->migrateImages();
1371+
$ctrl = $this->gui_service->ctrl();
1372+
$ctrl->redirectByClass(self::class, "listCharacteristics");
1373+
}
1374+
13411375
}

components/ILIAS/Style/Content/Images/class.ImageFileRepo.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ protected function dir(int $style_id): string
6565
public function getImages(
6666
int $style_id,
6767
string $rid,
68-
bool $include_size_info = false
68+
bool $include_size_info = false,
69+
bool $include_legacy_dir = true
6970
): Generator {
71+
$has_images = false;
7072
if ($rid !== "") {
7173
$unzip = $this->irss->getContainerZip($rid);
7274
$uri = $this->irss->stream($rid)->getMetadata("uri");
@@ -98,6 +100,7 @@ public function getImages(
98100
$width = 0;
99101
$height = 0;
100102
}
103+
$has_images = true;
101104
yield $this->factory->image(
102105
$this->irss->getContainerUri($rid, $path),
103106
new DataSize($att["size"], DataSize::KB),
@@ -107,6 +110,9 @@ public function getImages(
107110
}
108111
}
109112

113+
if ($has_images || !$include_legacy_dir) {
114+
return;
115+
}
110116

111117
$dir = $this->dir($style_id);
112118
if ($this->web_files->hasDir($dir)) {
@@ -130,6 +136,24 @@ public function getImages(
130136
}
131137
}
132138

139+
public function hasLegacyDir(
140+
int $style_id
141+
): bool {
142+
$dir = $this->dir($style_id);
143+
if ($this->web_files->hasDir($dir)) {
144+
return true;
145+
}
146+
return false;
147+
}
148+
149+
public function hasImages(
150+
int $style_id,
151+
string $rid
152+
): bool {
153+
$images = iterator_to_array($this->getImages($style_id, $rid, false, false));
154+
return count($images) > 0;
155+
}
156+
133157
public function getImageStream(
134158
string $rid,
135159
string $image

components/ILIAS/Style/Content/Images/class.ImageManager.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ public function getImages(bool $include_size_info = false): Generator
6969
return $this->repo->getImages($this->style_id, $rid, $include_size_info);
7070
}
7171

72+
public function hasLegacyDirAndNoImages(): bool
73+
{
74+
return $this->repo->hasLegacyDir($this->style_id) &&
75+
!$this->repo->hasImages(
76+
$this->style_id,
77+
$this->style_repo->readRid($this->style_id)
78+
);
79+
}
80+
7281
public function filenameExists(string $filename): bool
7382
{
7483
/** @var Image $i */
@@ -148,11 +157,13 @@ public function deleteByFilename(string $filename): void
148157
public function importFromUploadResult(
149158
UploadResult $result
150159
): void {
151-
$rid = $this->style_repo->getOrCreateRid($this->style_id, $this->stakeholder);
152-
$this->repo->importFromUploadResult(
153-
$rid,
154-
$result
155-
);
160+
$rid = $this->style_repo->readRid($this->style_id);
161+
if ($rid !== "") {
162+
$this->repo->importFromUploadResult(
163+
$rid,
164+
$result
165+
);
166+
}
156167
}
157168

158169
}

components/ILIAS/Style/Content/Style/StyleManager.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,35 @@ public function __construct(
4040
$this->repo = $repo->style();
4141
}
4242

43-
public function writeCss(): void
43+
public function createRid(): string
4444
{
45-
$builder = $this->domain->cssBuilder(
46-
new \ilObjStyleSheet($this->style_id)
47-
);
48-
$css = $builder->getCss();
49-
$this->repo->writeCss(
45+
return $this->repo->getOrCreateRid(
5046
$this->style_id,
51-
$css,
5247
$this->stakeholder
5348
);
5449
}
5550

51+
public function writeCss(): bool
52+
{
53+
if ($this->isMigrated()) {
54+
$builder = $this->domain->cssBuilder(
55+
new \ilObjStyleSheet($this->style_id)
56+
);
57+
$css = $builder->getCss();
58+
$this->repo->writeCss(
59+
$this->style_id,
60+
$css,
61+
$this->stakeholder
62+
);
63+
$this->repo->saveUpToDate(
64+
$this->style_id,
65+
true
66+
);
67+
return true;
68+
}
69+
return false;
70+
}
71+
5672
public function getPath(
5773
bool $add_random = true,
5874
bool $add_token = true
@@ -116,4 +132,15 @@ public function cloneResourceContainer(
116132
);
117133
}
118134

135+
public function isMigrated(): bool
136+
{
137+
return ((string) $this->repo->getResourceIdentification($this->style_id)
138+
!== "");
139+
}
140+
141+
public function migrateImages(
142+
): void {
143+
$this->repo->migrateImages($this->style_id);
144+
}
145+
119146
}

components/ILIAS/Style/Content/Style/StyleRepo.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ public function writeCss(
128128
string $css,
129129
ResourceStakeholder $stakeholder
130130
): void {
131-
$rid = $this->getOrCreateRid($style_id, $stakeholder);
132-
$this->irss->addStringToContainer($rid, $css, "style.css");
131+
$rid = $this->readRid($style_id);
132+
if ($rid !== "") {
133+
$this->irss->addStringToContainer($rid, $css, "style.css");
134+
}
133135
}
134136

135137
public function getPath(
@@ -191,4 +193,36 @@ public function cloneResourceContainer(
191193
}
192194
}
193195

196+
public function saveUpToDate(
197+
int $style_id,
198+
bool $up_to_date
199+
): void {
200+
$this->db->update(
201+
"style_data",
202+
[
203+
"uptodate" => ["integer", (int) $up_to_date]
204+
],
205+
[
206+
"id" => ["integer", $style_id]
207+
]
208+
);
209+
}
210+
211+
public function migrateImages(
212+
int $style_id
213+
): void {
214+
$source_dir = CLIENT_WEB_DIR . '/sty/sty_' . $style_id . "/images";
215+
$rid = $this->readRid($style_id);
216+
if (is_dir($source_dir) && $rid !== "") {
217+
$this->irss->addDirectoryToContainer(
218+
$rid,
219+
$source_dir,
220+
"images"
221+
);
222+
$style_dir = CLIENT_WEB_DIR . '/sty/sty_' . $style_id;
223+
\ilFileUtils::delDir($style_dir);
224+
}
225+
}
226+
227+
194228
}

0 commit comments

Comments
 (0)