Skip to content

Commit 8365ef6

Browse files
committed
feat: add a seed script
1 parent 3bcb3d2 commit 8365ef6

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

_build/gpm.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ build:
199199
- acls.gpm.php
200200
scriptsAfter:
201201
- lit.gpm.php
202+
- seed.gpm.php
202203

203204
database:
204205
tables:

_build/scripts/seed.gpm.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
return new class() {
4+
/**
5+
* @var \MODX\Revolution\modX
6+
*/
7+
private $modx;
8+
9+
/**
10+
* @var int
11+
*/
12+
private $action;
13+
14+
/**
15+
* @param \MODX\Revolution\modX $modx
16+
* @param int $action
17+
* @return bool
18+
*/
19+
public function __invoke(&$modx, $action)
20+
{
21+
$this->modx =& $modx;
22+
$this->action = $action;
23+
24+
if ($this->action === \xPDO\Transport\xPDOTransport::ACTION_UNINSTALL) {
25+
return true;
26+
}
27+
28+
/** @var class-string<\modAI\Tools\ToolInterface>[] $tools */
29+
$tools = [
30+
\modAI\Tools\GetWeather::class,
31+
32+
\modAI\Tools\GetCategories::class,
33+
\modAI\Tools\CreateCategory::class,
34+
35+
\modAI\Tools\GetChunks::class,
36+
\modAI\Tools\CreateChunk::class,
37+
38+
\modAI\Tools\GetTemplates::class,
39+
\modAI\Tools\CreateTemplate::class,
40+
41+
\modAI\Tools\CreateResource::class,
42+
\modAI\Tools\GetResources::class,
43+
\modAI\Tools\GetResourceDetail::class,
44+
];
45+
46+
foreach ($tools as $tool) {
47+
$exists = $this->modx->getCount(\modAI\Model\Tool::class, ['name' => $tool::getSuggestedName()]);
48+
if ($exists > 0) {
49+
continue;
50+
}
51+
52+
$toolObjects = $this->modx->newObject(\modAI\Model\Tool::class, [
53+
'class' => $tool,
54+
'name' => $tool::getSuggestedName(),
55+
'description' => $tool::getDescription(),
56+
'prompt' => null,
57+
'config' => null,
58+
'default' => false,
59+
'enabled' => true,
60+
]);
61+
62+
$toolObjects->save();
63+
}
64+
65+
66+
return true;
67+
}
68+
};

0 commit comments

Comments
 (0)