Skip to content

Commit a47ea57

Browse files
grandeljayJayJay
authored
Add option to define shop root (#73)
Co-authored-by: Jay <j.trees@hybridsupply.de> Co-authored-by: Jay <grandel@posteo.de>
1 parent 738bd92 commit a47ea57

6 files changed

Lines changed: 55 additions & 6 deletions

File tree

config/_config.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,16 @@
2424
* @param string selfUpdate stable, latest
2525
*/
2626
'installMode' => 'copy',
27-
'selfUpdate' => 'stable'
27+
'selfUpdate' => 'stable',
28+
29+
/**
30+
* Settings revolving around your modified-shop
31+
*
32+
* Overwrite the default shop path. If your MMLC installation is not inside
33+
* of your modified-shop root and exists as a symbolic link, you may need to
34+
* define your shop root here.
35+
*
36+
* Leave empty for default.
37+
*/
38+
'shopRoot' => '',
2839
];

src/Classes/Api/V1/HttpRequest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ public function sendPostRequest(string $url, $data)
4646

4747
// Logging
4848
if ($this->logging) {
49-
file_put_contents(App::getLogsRoot() . '/log.txt', $result);
49+
$logFilepath = App::getLogsRoot() . '/log.txt';
50+
$logDirectory = dirname($logFilepath);
51+
52+
if (!file_exists($logDirectory)) {
53+
mkdir($logDirectory);
54+
}
55+
56+
file_put_contents($logFilepath, $result);
5057
}
5158

5259
return $result;

src/Classes/App.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function getRoot(): string
4040

4141
public static function getShopRoot(): string
4242
{
43-
return realPath(__DIR__ . '/../../../');
43+
return Config::getShopRoot();
4444
}
4545

4646
public static function getSrcRoot(): string

src/Classes/Config.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,26 @@ public static function setAdminDir(string $newAdminDir): void
225225
self::writeConfiguration(['adminDir' => $newAdminDir]);
226226
}
227227

228+
/**
229+
* Get the modified-shop root directory.
230+
*
231+
* @return string
232+
*/
233+
public static function getShopRoot(): string
234+
{
235+
$shopRootOption = self::getOption('shopRoot');
236+
$shopRootDirectory = empty($shopRootOption)
237+
? realpath(__DIR__ . '/../../../')
238+
: rtrim($shopRootOption, '/\\');
239+
240+
return $shopRootDirectory;
241+
}
242+
243+
public static function setShopRoot(string $newShopRoot): void
244+
{
245+
self::writeConfiguration(['shopRoot' => $newShopRoot]);
246+
}
247+
228248
/**
229249
* Get modulesLocalDir from config.
230250
*

src/Classes/IndexController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,10 @@ public function invokeSettings()
602602
Config::setAccessToken($parsedBody['accessToken']);
603603
}
604604

605+
if (isset($parsedBody['shopRoot'])) {
606+
Config::setShopRoot($parsedBody['shopRoot']);
607+
}
608+
605609
if (isset($parsedBody['modulesLocalDir'])) {
606610
Config::setModulesLocalDir($parsedBody['modulesLocalDir']);
607611
}

src/Templates/Settings.tmpl.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function viewIsSelected(bool $value): string
7373
<input type="text" name="username" class="form-control" id="inputUsername" value="<?= Config::getUsername(); ?>">
7474
<p>Mit diesem Namen meldest du dich im MMLC an.</p>
7575
</div>
76-
76+
7777
<div class="form-group">
7878
<label for="inputPassword">Password</label>
7979
<input type="password" name="password" class="form-control" id="inputPassword">
@@ -90,6 +90,13 @@ function viewIsSelected(bool $value): string
9090
<div class="tab-pane fade show" id="v-pills-advanced" role="tabpanel" aria-labelledby="v-pills-advanced-tab">
9191
<h2>Erweitert</h2>
9292
<form action="?action=settings&section=advanced" method="post">
93+
<!-- shopRoot -->
94+
<div class="form-group">
95+
<label for="inputShopRoot">Shop Root</label>
96+
<input type="text" name="shopRoot" class="form-control" id="inputShopRoot" value="<?= Config::getShopRoot(); ?>">
97+
<p>Verzeichnis vom modified-shop. Lasse dieses Feld leer für die Standard Einstellung.</p>
98+
</div>
99+
93100
<!-- modulesLocalDir -->
94101
<div class="form-group">
95102
<label for="inputModulesLocalDir">Module Pfad</label>
@@ -104,7 +111,7 @@ function viewIsSelected(bool $value): string
104111
<option <?= viewIsSelected(Config::getInstallMode() == 'copy') ?> value="copy">copy</option>
105112
<option <?= viewIsSelected(Config::getInstallMode() == 'link') ?> value="link">link</option>
106113
</select>
107-
114+
108115
<p>Du kannst zwischen <code>copy</code> und <code>link</code> wählen. Hast du den MMLC in einem Live-Shop im Einsatz, wähle <code>copy</code>. Wenn du mit dem MMLC Module entwickelst, wähle <code>link</code>.</p>
109116
</div>
110117

@@ -126,7 +133,7 @@ function viewIsSelected(bool $value): string
126133
$(tabId).tab('show')
127134
})
128135
</script>
129-
136+
130137
<?php include 'Footer.tmpl.php' ?>
131138
</body>
132139
</html>

0 commit comments

Comments
 (0)