Hi Matt,
Thanks for this. I’ve tried this but had to make some changes for it to work in a virtualised container / docker. Since the $this->appRoot tries to get the actual directory on my local Mac, rather than the virtual directory inside docker (ubuntu, so /var/www etc. rather than /users/username/project-dir etc.).
In order to get around this, can you add an appPath variable to the env/config? This worked when I replaced $this->appRoot with “./”, so if I can interface with that rather than hard coding inside the vendor package that will work.
ClassFinder.php:
private function getNamespaceDirectory(string $namespace): string
{
$composerNamespaces = $this->getDefinedNamespaces();
$namespaceFragments = explode('\\', $namespace);
$undefinedNamespaceFragments = [];
$appPath = "./";
while($namespaceFragments) {
$possibleNamespace = implode('\\', $namespaceFragments) . '\\';
if(array_key_exists($possibleNamespace, $composerNamespaces)) {
return realpath($appPath . '/' . $composerNamespaces[$possibleNamespace] . implode('/', $undefinedNamespaceFragments));
}
}
}
private function fetchFiles(string $directory): array
{
if (empty($directory))
{
$directory = "./";
}
SchemaEmmitter.php
public static function getSerializedSchema(Datasource $datasource)
{
if (config('isProduction')) {
if (config('schemaPath') && file_exists(config('schemaPath'))) {
$schema = json_decode(file_get_contents(config('schemaPath')), true, 512, JSON_THROW_ON_ERROR);
} else {
Logger::log('Warn', 'The .forestadmin-schema.json file doesn\'t exist');
$schema = [
'meta' => self::meta(sha1(json_encode([], JSON_THROW_ON_ERROR))),
'collections' => [],
];
}
} else {
$schema = self::generate($datasource);
$hash = sha1(json_encode($schema, JSON_THROW_ON_ERROR));
$schema = [
'meta' => self::meta($hash),
'collections' => $schema,
];
$pretty = json_encode($schema, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
file_put_contents("./.forestadmin-schema.json", $pretty);
}
return self::serialize($schema);
}
Lastly, had to override the schemaPath in the forest.php config from
'schemaPath' => base_path() . '/.forestadmin-schema.json',
to
'schemaPath' => base_path() . './.forestadmin-schema.json',
Finally this gets to update the forestschema but returns to the original error of not being able to serialize it:
[2024-02-08T10:04:51.441323+00:00] forestadmin.INFO: schema was updated, sending new version
Configuration cache cleared!
[2024-02-08T10:04:56.299992+00:00] forestadmin.INFO: Schema was not updated since last run