dbXapp
2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Toggle main menu visibility
Loading...
Searching...
No Matches
dbxKiCmsHelpProvision.class.php
Go to the documentation of this file.
1
<?php
2
namespace
dbx\dbxKi;
3
4
use dbx\dbxContent\dbxContentLng;
5
use dbx\dbxContent\dbxContentLngSync;
6
use dbx\dbxContent\dbxContentPageCache;
7
use dbx\dbxContent\dbxContentPermalinkIndex;
8
9
require_once dirname(__DIR__, 2) .
'/dbxContent/include/dbxContent_bootstrap_sync.php'
;
10
11
class
dbxKiCmsHelpProvision
{
12
13
public
const
PERMALINK
=
'dbxki-anleitung-content-seite-mit-ki'
;
14
public
const
TITLE
=
'Content-Seite mit ChatGPT oder DeepSeek erstellen'
;
15
public
const
TPL
=
'cms-anleitung-ki-content-seite'
;
16
public
const
CONFIG_KEY
=
'cms_anleitung_provision_version'
;
17
public
const
PROVISION_VERSION
= 2;
18
19
public
static
function
run
(): void {
20
$version = (int)
dbx
()->get_config(
'dbxKi'
, self::
CONFIG_KEY
, 0);
21
if
($version >= self::PROVISION_VERSION) {
22
return
;
23
}
24
$result
=
self::provision
();
25
if
(empty(
$result
[
'errors'
])) {
26
self::markProvisioned();
27
}
28
}
29
30
public
static
function
provision
(): array {
31
$result
= array(
'created'
=> 0,
'updated'
=> 0,
'folder_id'
=> 0,
'page_id'
=> 0,
'permalink'
=> self::
PERMALINK
,
'errors'
=> array());
32
33
$db
=
dbx
()->get_system_obj(
'dbxDB'
);
34
if
(!is_object(
$db
) || !
$db
->connect_db_server(
'dbx|dbxContent.db3'
)) {
35
$result
[
'errors'
][] =
'CMS-Datenbank nicht erreichbar.'
;
36
return
$result
;
37
}
38
39
dbxContentLngSync::ensureSchema(
$db
);
40
41
$folderId = self::ensureHelpFolder(
$db
,
$result
);
42
if
($folderId <= 0) {
43
return
$result
;
44
}
45
$result
[
'folder_id'
] = $folderId;
46
47
$content = self::loadTemplateHtml();
48
if
($content ===
''
) {
49
$result
[
'errors'
][] =
'Anleitungs-Template fehlt: '
. self::TPL .
'.htm'
;
50
return
$result
;
51
}
52
53
$cms
=
dbx
()->get_include_obj(
'dbxKiCmsService'
,
'dbxKi'
);
54
$lng = dbxContentLng::current();
55
$dd = dbxContentLng::ddContent($lng);
56
$existing =
$db
->select1($dd, array(
'permalink'
=> self::PERMALINK),
'id'
, 0);
57
$existingId = is_array($existing) ? (int) ($existing[
'id'
] ?? 0) : 0;
58
59
try
{
60
if
($existingId > 0) {
61
$params = array(
62
'lng'
=> $lng,
63
'id'
=> $existingId,
64
'content'
=> $content,
65
'title'
=> self::TITLE,
66
'group_read'
=>
'admin'
,
67
);
68
$plan =
$cms
->bundleBuildPlan(
'page.update'
, $params);
69
$exec =
$cms
->bundleExecutePlan(
'page.update'
, $params, $plan);
70
$result
[
'updated'
] = 1;
71
$result
[
'page_id'
] = (int) ($exec[
'id'
] ?? $existingId);
72
}
else
{
73
$params = array(
74
'lng'
=> $lng,
75
'folder_id'
=> $folderId,
76
'title'
=> self::TITLE,
77
'permalink'
=> self::PERMALINK,
78
'template'
=>
'parent'
,
79
'activ'
=> 1,
80
'group_read'
=>
'admin'
,
81
'description'
=>
'Schritt-fuer-Schritt-Anleitung: Neue CMS-Content-Seite mit ChatGPT, DeepSeek und dbxKi-Bundle erstellen.'
,
82
'keywords'
=>
'dbxKi, ChatGPT, DeepSeek, CMS, Bundle, KI'
,
83
'content'
=> $content,
84
);
85
$plan =
$cms
->bundleBuildPlan(
'page.create'
, $params);
86
$exec =
$cms
->bundleExecutePlan(
'page.create'
, $params, $plan);
87
$result
[
'created'
] = 1;
88
$result
[
'page_id'
] = (int) ($exec[
'id'
] ?? 0);
89
}
90
}
catch
(\Throwable $e) {
91
$result
[
'errors'
][] = $e->getMessage();
92
return
$result
;
93
}
94
95
if
(
$result
[
'page_id'
] > 0) {
96
dbxContentPermalinkIndex::upsertPage(
$result
[
'page_id'
], self::PERMALINK,
'admin'
, 1, $lng);
97
}
98
99
if
(dbxContentPageCache::isEnabled()) {
100
dbxContentPageCache::invalidateAll();
101
}
102
103
return
$result
;
104
}
105
106
public
static
function
pageUrl
(): string {
107
return self::
PERMALINK
;
108
}
109
110
private
static
function
markProvisioned(): void {
111
$config
=
dbx
()->get_config(
'dbxKi'
);
112
if
(!is_array(
$config
)) {
113
$config
= array();
114
}
115
$config
[self::CONFIG_KEY] = self::PROVISION_VERSION;
116
dbx
()->set_config(
'dbxKi'
,
$config
);
117
}
118
119
private
static
function
loadTemplateHtml(): string {
120
$path = dirname(__DIR__) .
'/tpl/htm/'
. self::TPL .
'.htm'
;
121
if
(!is_file($path) || !is_readable($path)) {
122
return
''
;
123
}
124
$html = file_get_contents($path);
125
return
is_string($html) ? trim($html) :
''
;
126
}
127
128
private
static
function
ensureHelpFolder(
$db
, array &
$result
): int {
129
$outsideId = self::findFolderByName(
$db
,
'outside'
, 0);
130
if
($outsideId <= 0) {
131
$outsideId = self::insertFolder(
$db
,
'outside'
, 0,
'admin'
);
132
}
133
if
($outsideId <= 0) {
134
$result
[
'errors'
][] =
'Ordner outside konnte nicht angelegt werden.'
;
135
return
0;
136
}
137
138
$helpId = self::findFolderByName(
$db
,
'help'
, $outsideId);
139
if
($helpId <= 0) {
140
$helpId = self::insertFolder(
$db
,
'help'
, $outsideId,
'admin'
);
141
}
142
if
($helpId <= 0) {
143
$result
[
'errors'
][] =
'Ordner help konnte nicht angelegt werden.'
;
144
return
0;
145
}
146
147
return
$helpId;
148
}
149
150
private
static
function
findFolderByName(
$db
,
string
$name,
int
$parentId): int {
151
$dd = dbxContentLng::ddFolder();
152
$where =
"name = '"
. str_replace(
"'"
,
"''"
, trim($name)) .
"' AND parent_id = "
. (int) $parentId;
153
$rows =
$db
->select($dd, $where,
'id'
,
'id'
,
'ASC'
,
''
, 1, 0, 0);
154
if
(!is_array($rows) || !isset($rows[0][
'id'
])) {
155
return
0;
156
}
157
return
(
int
) $rows[0][
'id'
];
158
}
159
160
private
static
function
insertFolder(
$db
,
string
$name,
int
$parentId,
string
$groupRead): int {
161
$cms
=
dbx
()->get_include_obj(
'dbxKiCmsService'
,
'dbxKi'
);
162
$params = array(
163
'lng'
=> dbxContentLng::current(),
164
'name'
=> $name,
165
'parent_id'
=> $parentId,
166
'group_read'
=> $groupRead,
167
'template'
=> $parentId > 0 ?
'parent'
:
'c-content'
,
168
);
169
$plan =
$cms
->bundleBuildPlan(
'folder.create'
, $params);
170
$exec =
$cms
->bundleExecutePlan(
'folder.create'
, $params, $plan);
171
return
(
int
) ($exec[
'id'
] ?? 0);
172
}
173
}
dbx\dbxKi\dbxKiCmsHelpProvision
Definition
dbxKiCmsHelpProvision.class.php:11
dbx\dbxKi\dbxKiCmsHelpProvision\pageUrl
static pageUrl()
Definition
dbxKiCmsHelpProvision.class.php:106
dbx\dbxKi\dbxKiCmsHelpProvision\provision
static provision()
Definition
dbxKiCmsHelpProvision.class.php:30
dbx\dbxKi\dbxKiCmsHelpProvision\PERMALINK
const PERMALINK
Definition
dbxKiCmsHelpProvision.class.php:13
dbx\dbxKi\dbxKiCmsHelpProvision\TITLE
const TITLE
Definition
dbxKiCmsHelpProvision.class.php:14
dbx\dbxKi\dbxKiCmsHelpProvision\PROVISION_VERSION
const PROVISION_VERSION
Definition
dbxKiCmsHelpProvision.class.php:17
dbx\dbxKi\dbxKiCmsHelpProvision\TPL
const TPL
Definition
dbxKiCmsHelpProvision.class.php:15
dbx\dbxKi\dbxKiCmsHelpProvision\run
static run()
Definition
dbxKiCmsHelpProvision.class.php:19
dbx\dbxKi\dbxKiCmsHelpProvision\CONFIG_KEY
const CONFIG_KEY
Definition
dbxKiCmsHelpProvision.class.php:16
$config
$config['version']
Definition
config.php:2
dbx
DBX schema administration.
$db
$db
Definition
run_context_help_provision.php:38
$result
if(! $db->connect_db_server($server)) $result
Definition
run_context_help_provision.php:45
$cms
$cms
Definition
run_job.php:206
dbx
modules
dbxKi
include
dbxKiCmsHelpProvision.class.php
Generated by
1.17.0