Hello.
I have a composer package. It's like small cms (with db tables).
My target is to start migrations after package install/update from composer. In this case I use composer scripts. But there are no any autoloaded classes exist inside it.
composer.json:
Code:
{
"name": "nwnpc/ci4-cms",
"description": "Small seo friendly ci4 cms",
"license": "MIT",
"minimum-stability": "dev",
"require": {
"php": "^7.3 || ^8.0"
},
"autoload": {
"psr-4": {
"Velldoris\\": "src/"
}
},
"scripts": "Velldoris\\Database\\Migration::install"
}
Velldoris\Database\Migration::install:
Code:
try {
$velldoris_app_config = config('Velldoris\\Config\\VelldorisApp');
$db = \Config\Database::connect($velldoris_app_config->DBGroup);
$db->getVersion();
} catch (\Throwable $e) {
print_r('Velldoris package installation error: ' . $e->getMessage());
exit;
}
$migrations = service('Migrations', config('Config\Migrations'), $db);
$migrations->setNamespace('Velldoris');
try {
$migrations->latest();
} catch (\Throwable $e) {
print_r('Velldoris package installation error: ' . $e->getMessage());
exit;
}
There is an error like "Codeigniter class not defined" while i try to init my method strict ("composer run-script post-install-cmd"). And it's not surprising.
Here are the solutions I see:
1) Load all project classes throught composer autoload.php
2) Use mysql dump instead of migrations (really?)