- First commit, routes and database builder are usable
This commit is contained in:
commit
5f6ce82fd2
23 files changed
+787
No files matched your search
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Console\Form;
|
||||
|
||||
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
|
||||
|
||||
use \Lean\Console\Lib;
|
||||
|
||||
use Picea\Compiler\Context;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use \Ulmus\Entity\InformationSchema\Table;
|
||||
|
||||
class Database implements FormInterface
|
||||
{
|
||||
protected ? Lib\DatabaseMigrations $migration;
|
||||
|
||||
public function __construct(Lib\DatabaseMigrations $migration)
|
||||
{
|
||||
$this->migration = $migration;
|
||||
}
|
||||
|
||||
public function initialize(FormContextInterface $context) : void
|
||||
{
|
||||
$context->tableExist = [];
|
||||
|
||||
foreach($this->migration->entities as $entity => $table) {
|
||||
|
||||
$table = Table::repository()->where(Table::field('name'), $table->tableName())
|
||||
->where(Table::field('schema'), $table->databaseName())
|
||||
->loadOne();
|
||||
|
||||
if ( $table ) {
|
||||
#$fields = $entiy::resolveEntity()->fieldList();
|
||||
|
||||
foreach($table->columns as $col) {
|
||||
dump( $entity::field($col->name) );
|
||||
}
|
||||
|
||||
# if columns are different
|
||||
$context->status[$entity] = [
|
||||
'msg' => "up-to-date",
|
||||
'query' => "",
|
||||
];
|
||||
}
|
||||
else {
|
||||
$context->status[$entity] = [
|
||||
'msg' => "unexisting",
|
||||
'query' => $entity::repository()->createSqlQuery()->getSqlQuery(true),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ( $context->formSent() ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(FormContextInterface $context) : bool
|
||||
{
|
||||
return $context->valid();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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 !!!
|
||||
}
|
||||
}
|
||||
public function getContext(ServerRequestInterface $request) : FormContextInterface
|
||||
{
|
||||
return new class($request) extends FormContext {
|
||||
|
||||
public array $status = [];
|
||||
|
||||
public array $actions = [];
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user