- Work done on DatabaseMigration part and separation from Lean main package too.
This commit is contained in:
parent
923b2be49e
commit
f6fadd715e
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Lean\Console\Lib\DatabaseMigrations;
|
||||
|
||||
return [
|
||||
'lean.console' => [
|
||||
'picea' => [
|
||||
'view' => [
|
||||
[
|
||||
'path' => getenv("PROJECT_PATH") . "/vendor/mcnd/lean-console/view/",
|
||||
'order' => 99,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'ulmus' => [],
|
||||
|
||||
'tell' => [
|
||||
'json' => [
|
||||
[
|
||||
'path' => getenv("PROJECT_PATH") . "/vendor/mcnd/lean-console/meta/i18n",
|
||||
'order' => 99,
|
||||
],
|
||||
]
|
||||
],
|
||||
|
||||
'routes' => [
|
||||
'Lean\\Console\\Controller' => getenv("PROJECT_PATH") . "/vendor/mcnd/lean-console/src/Controller/",
|
||||
],
|
||||
],
|
||||
|
||||
DatabaseMigrations::class => function($c) {
|
||||
return new DatabaseMigrations( $c->get(Lean\Lean::class)->getEntities() );
|
||||
},
|
||||
];
|
|
@ -15,7 +15,7 @@ use \Lean\Console\Lib;
|
|||
use Picea\Extension\UrlExtension;
|
||||
|
||||
/**
|
||||
* @Language("lean.route")
|
||||
* @Language("lean.request")
|
||||
*/
|
||||
class Request extends Console {
|
||||
use Lib\ConsoleControllerTrait;
|
||||
|
|
|
@ -62,28 +62,18 @@ class Database implements FormInterface
|
|||
|
||||
public function execute(FormContextInterface $context) : void
|
||||
{
|
||||
try {
|
||||
if ( $context->create ?? false ) {
|
||||
$context->create::repository()->createTable();
|
||||
}
|
||||
elseif ( $context->createAll ?? false ) {
|
||||
foreach(explode(',', $context->createAll) as $entity) {
|
||||
$entity::repository()->createTable();
|
||||
}
|
||||
}
|
||||
|
||||
$this->initialize($context);
|
||||
if ( $context->create ?? false ) {
|
||||
$context->create::repository()->createTable();
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
dump($ex);
|
||||
|
||||
$context->pushMessage(new Message(
|
||||
"Une erreur inattendue semble avoir été provoquée lors de la sauvegarde des données. Le programmeur en charge du logiciel en a été avisé par courriel."
|
||||
));
|
||||
|
||||
# @TODO ADD THEBUGS EMAIL SENDING HERE !!!
|
||||
elseif ( $context->createAll ?? false ) {
|
||||
foreach(explode(',', $context->createAll) as $entity) {
|
||||
$entity::repository()->createTable();
|
||||
}
|
||||
}
|
||||
|
||||
$this->initialize($context);
|
||||
}
|
||||
|
||||
public function getContext(ServerRequestInterface $request) : FormContextInterface
|
||||
{
|
||||
return new class($request) extends FormContext {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Lean\Console;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
abstract class Lean
|
||||
{
|
||||
public static function definitions() : array
|
||||
{
|
||||
return require(dirname(__DIR__) . "/meta/definitions/software.php");
|
||||
}
|
||||
}
|
|
@ -17,10 +17,11 @@ class DatabaseMigrations
|
|||
{
|
||||
$this->entities = [];
|
||||
|
||||
foreach($this->folderList as $folder => $namespace) {
|
||||
foreach($this->folderList as $namespace => $folder) {
|
||||
foreach(static::files($folder) as $file) {
|
||||
$name = $file->getBasename(".".$file->getExtension());
|
||||
$entity = rtrim($namespace, "\\") . "\\{$name}";
|
||||
$name = $file->getBasename("." . $file->getExtension());
|
||||
$subNs = substr($file->getPath(), strlen($folder));
|
||||
$entity = rtrim($namespace, "\\") . ( $subNs ? "\\$subNs" : "" ) . "\\{$name}";
|
||||
$this->entities[$entity] = $entity::resolveEntity();
|
||||
}
|
||||
}
|
||||
|
@ -33,11 +34,15 @@ class DatabaseMigrations
|
|||
|
||||
foreach ($iterator as $file) {
|
||||
if ( $file->isFile() || $file->isDir() ) {
|
||||
if ($fileExtension && ( $file->getExtension() === $fileExtension )) {
|
||||
yield $file;
|
||||
if ($fileExtension) {
|
||||
if ( $file->getExtension() === $fileExtension ) {
|
||||
yield $file;
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield $file;
|
||||
if ( $file->isFile() ) {
|
||||
yield $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue