Skip to content

Commit 2e02c0a

Browse files
committed
Updated APM, and page, and misc errors
1 parent d01eaf2 commit 2e02c0a

File tree

7 files changed

+89
-12
lines changed

7 files changed

+89
-12
lines changed

app/controllers/DocsController.php

+10
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ public function pluginGet(string $language, string $version, string $plugin_name
156156
public function singlePageGet(string $language, string $version) {
157157
$app = $this->app;
158158

159+
// Check if the language is valid
160+
if ($this->DocsLogic->checkValidLanguage($language) === false) {
161+
$language = 'en';
162+
}
163+
164+
// Check if the version is valid
165+
if ($this->DocsLogic->checkValidVersion($version) === false) {
166+
$version = 'v3';
167+
}
168+
159169
// recursively look through all the content files, and pull out each section and render it
160170
$sections = [];
161171
$language_directory = self::CONTENT_DIR . '/' . $version . '/' . $language . '/';

app/utils/DocsLogic.php

+55-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,24 @@
55
use app\middleware\HeaderSecurityMiddleware;
66
use DOMDocument;
77
use DOMXPath;
8-
use flight\core\EventDispatcher;
98

109
class DocsLogic {
1110

11+
const AVAILABLE_LANGUAGES = [
12+
'en',
13+
'es',
14+
'fr',
15+
'lv',
16+
'pt',
17+
'de',
18+
'ru',
19+
'zh',
20+
'ja',
21+
'ko',
22+
'uk',
23+
'id'
24+
];
25+
1226
/**
1327
* DocsLogic constructor.
1428
*
@@ -64,6 +78,16 @@ public function setupTranslatorService(string $language, string $version): Trans
6478
public function compileSinglePage(string $language, string $version, string $section) {
6579
$app = $this->app;
6680

81+
// Check if the language is valid
82+
if ($this->checkValidLanguage($language) === false) {
83+
$language = 'en';
84+
}
85+
86+
// Check if the version is valid
87+
if ($this->checkValidVersion($version) === false) {
88+
$version = 'v3';
89+
}
90+
6791
$Translator = $this->setupTranslatorService($language, $version);
6892

6993
$cacheStartTime = microtime(true);
@@ -99,6 +123,16 @@ public function compileSinglePage(string $language, string $version, string $sec
99123
public function compileScrollspyPage(string $language, string $version, string $section, string $sub_section) {
100124
$app = $this->app;
101125

126+
// Check if the language is valid
127+
if ($this->checkValidLanguage($language) === false) {
128+
$language = 'en';
129+
}
130+
131+
// Check if the version is valid
132+
if ($this->checkValidVersion($version) === false) {
133+
$version = 'v3';
134+
}
135+
102136
$Translator = $this->setupTranslatorService($language, $version);
103137

104138
$section_file_path = str_replace('_', '-', $section);
@@ -213,4 +247,24 @@ protected function wrapContentInDiv(string $html): string {
213247

214248
return $d;
215249
}
250+
251+
/**
252+
* Checks if the provided language is valid.
253+
*
254+
* @param string $language The language code to check.
255+
* @return bool True if the language is valid, false otherwise.
256+
*/
257+
public function checkValidLanguage(string $language): bool {
258+
return in_array($language, self::AVAILABLE_LANGUAGES, true) === true;
259+
}
260+
261+
/**
262+
* Checks if the provided version is valid.
263+
*
264+
* @param string $version The version code to check.
265+
* @return bool True if the version is valid, false otherwise.
266+
*/
267+
public function checkValidVersion(string $version): bool {
268+
return in_array($version, ['v3', 'v2'], true) === true;
269+
}
216270
}

app/views/links.latte

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<link
1616
rel="stylesheet"
1717
href="https://cdn.jsdelivr.net/npm/@tarekraafat/[email protected]/dist/css/autoComplete.min.css" />
18-
<link rel="stylesheet" href="./css/style.css?version=7" />
18+
<link rel="stylesheet" href="/css/style.css?version=7" />
1919

2020
{foreach ['en', 'fr', 'es', 'pt', 'lv', 'de', 'ru', 'zh', 'ja', 'ko', 'uk', 'id'] as $lang}
2121
<link rel="alternate" hreflang="{$lang}" href="./?lang={$lang}" />
@@ -26,4 +26,4 @@
2626
<!-- to prevent page flash -->
2727
<script
2828
nonce="{$nonce}"
29-
src="./js/color-mode-toggler.js"></script>
29+
src="/js/color-mode-toggler.js"></script>

app/views/scripts.latte

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script
22
nonce="{$nonce}"
3-
src="./js/color-mode-toggler.js"></script>
3+
src="/js/color-mode-toggler.js"></script>
44
<script async defer src="https://buttons.github.io/buttons.js"></script>
55
<script
66
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
@@ -10,7 +10,7 @@
1010

1111
<!-- Google tag (gtag.js) -->
1212
<script async src="https://www.googletagmanager.com/gtag/js?id=G-3C36SDZ8FE"></script>
13-
<script nonce="{$nonce}" src="./js/gtag.js"></script>
13+
<script nonce="{$nonce}" src="/js/gtag.js"></script>
1414

1515
<script
1616
src="https://cdn.jsdelivr.net/npm/@tarekraafat/[email protected]/dist/autoComplete.min.js"></script>

composer.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

content/v3/en/awesome-plugins/apm.md

+13
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ php vendor/bin/runway apm:init
7272
}
7373
```
7474

75+
> This process will also ask if you want to run the migrations for this setup. If you're setting this up for your first time, the answer is yes.
76+
7577
**Why two locations?**
7678
Raw metrics pile up fast (think unfiltered logs). The worker processes them into a structured destination for the dashboard. Keeps things tidy!
7779

@@ -255,6 +257,17 @@ php vendor/bin/runway apm:worker --daemon --batch_size 100 --timeout 3600
255257
```
256258
Runs for an hour, processing 100 metrics at a time.
257259

260+
## Upgrading
261+
262+
If you are upgrading to a newer version of the APM, there is a chance that there are database migrations that need to be run. You can do this by running the following command:
263+
264+
```bash
265+
php vendor/bin/runway apm:migrate
266+
```
267+
This will run any migrations that are needed to update the database schema to the latest version.
268+
269+
**Note:** If you're APM database is large in size, these migrations may take some time to run. You may want to run this command during off-peak hours.
270+
258271
## Troubleshooting
259272

260273
Stuck? Try these:

translate_content.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
$messages = [
6464
[
6565
"role" => "system",
66-
"content" => "You are a gifted translator focusing on the tech space. Today you are translating documentation for a PHP Framework called Flight (so please never translate the word 'Flight' as it's the name of the framework). You are going to receive content that is like a markdown file. When you receive the content you'll translate it from english to the two letter language code that is specified. When you generate a response, you are going to ONLY send back the translated markdown content, no other replies or 'here is your translated markdown' type statements back, only the translated markdown content in markdown format. If you get a follow up response, you need to continue to markdown translation from the very character you left off at and complete the translation until the full page is done. THIS NEXT ITEM IS VERY IMPORTANT! Make sure that when you are translating any code in the markdown file that you ONLY translate the comments of the code and not the classes/methods/variables/links/urls/etc. Please don't translate any URLs or you will break my app and I will lose my job if this is not done correctly!"
66+
"content" => "You are a gifted translator focusing on the tech space. Today you are translating documentation for a PHP Framework called Flight (so please never translate the word 'Flight' as it's the name of the framework). You are going to receive content that is a markdown file. When you receive the content you'll translate it from english to the two letter language code that is specified. When you generate a response, you are going to ONLY send back the translated markdown content, no other replies or 'here is your translated markdown' type statements back, only the translated markdown content in markdown format. If you get a follow up response, you need to continue to markdown translation from the very character you left off at and complete the translation until the full page is done. THIS NEXT ITEM IS VERY IMPORTANT! Make sure that when you are translating any code in the markdown file that you ONLY translate the comments of the code and not the classes/methods/variables/links/urls/etc. This next part is also incredibly important or it will break the entire page!!!! Please don't translate any URLs or you will break my app and I will lose my job if this is not done correctly!!!!"
6767
],
6868
[
6969
"role" => "user",

0 commit comments

Comments
 (0)