Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8b208426a | ||
|
|
3a8e56a617 | ||
|
|
39b02507a3 | ||
|
|
ce2b9399c2 | ||
|
|
cd38800131 | ||
|
|
0b1286c05f | ||
|
|
73fca52013 |
No files matched your search
@@ -39,6 +39,10 @@ return [
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'cli' => [
|
||||||
|
'Lean\\Console\\Cli' => implode(DIRECTORY_SEPARATOR, [ $path, "src", "Cli", "" ]),
|
||||||
|
],
|
||||||
|
|
||||||
'routes' => ! getenv('DEBUG') ? [] : [
|
'routes' => ! getenv('DEBUG') ? [] : [
|
||||||
'Lean\\Console\\Controller' => implode(DIRECTORY_SEPARATOR, [ $path, "src", "Controller", "" ]),
|
'Lean\\Console\\Controller' => implode(DIRECTORY_SEPARATOR, [ $path, "src", "Controller", "" ]),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lean\Console\Cli;
|
||||||
|
|
||||||
|
use Notes\CLI\Attribute\{Option, Command};
|
||||||
|
use Psr\Http\Message\{ServerRequestInterface, ResponseInterface};
|
||||||
|
|
||||||
|
use Lean\Console\{Lib, };
|
||||||
|
|
||||||
|
# https://www.asciiart.eu/text-to-ascii-art
|
||||||
|
#[Command(description: PHP_EOL . <<<CLI
|
||||||
|
#[color:gray, bg: black]╔═════════════════════════╗[#]
|
||||||
|
#[color:gray, bg: black]║ _ ║[#]
|
||||||
|
#[color:gray, bg: black]║ | | ___ __ _ _ __ ║[#]
|
||||||
|
#[color:gray, bg: black]║ | | / _ \/ _` | '_ \ ║[#]
|
||||||
|
#[color:gray, bg: black]║ | |__| __/ (_| | | | | ║[#]
|
||||||
|
#[color:gray, bg: black]║ |_____\___|\__,_|_| |_| ║[#]
|
||||||
|
#[color:gray, bg: black]║ ║[#]
|
||||||
|
#[color:gray, bg: black]╚═════════════════════════╝[#]
|
||||||
|
|
||||||
|
Try #[color:gray, bg: black]'lean console --help'[#] for more information.
|
||||||
|
CLI
|
||||||
|
, command: 'console')]
|
||||||
|
#[Option(toggle: ['-h', '--help'], description: "Display help for the given command. When no command is given display help for the list command")]
|
||||||
|
#[Option(toggle: ['-q', '--quiet'], description: "Do not output any message")]
|
||||||
|
#[Option(toggle: ['-n', '--no-interaction'], description: "Run script without user interaction")]
|
||||||
|
#[Option(toggle: ['-v', '-vv', '-vvv', '--verbose'], description: "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug", argument: Option::ARGUMENT_OPTIONAL)]
|
||||||
|
class Console
|
||||||
|
{
|
||||||
|
use Lib\ConsoleControllerTrait;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lean\Console\Cli;
|
||||||
|
|
||||||
|
use Notes\CLI\Attribute\{Option, Command};
|
||||||
|
use Psr\Http\Message\{ServerRequestInterface, ResponseInterface};
|
||||||
|
|
||||||
|
use Lean\Console\{Lib, };
|
||||||
|
|
||||||
|
# https://www.asciiart.eu/text-to-ascii-art
|
||||||
|
#[Command(description: PHP_EOL . <<<CLI
|
||||||
|
#[color:gray, bg: black]╔═════════════════════════╗[#]
|
||||||
|
#[color:gray, bg: black]║ _ ║[#]
|
||||||
|
#[color:gray, bg: black]║ | | ___ __ _ _ __ ║[#]
|
||||||
|
#[color:gray, bg: black]║ | | / _ \/ _` | '_ \ ║[#]
|
||||||
|
#[color:gray, bg: black]║ | |__| __/ (_| | | | | ║[#]
|
||||||
|
#[color:gray, bg: black]║ |_____\___|\__,_|_| |_| ║[#]
|
||||||
|
#[color:gray, bg: black]║ ║[#]
|
||||||
|
#[color:gray, bg: black]║ STORAGE ║[#]
|
||||||
|
#[color:gray, bg: black]╚═════════════════════════╝[#]
|
||||||
|
|
||||||
|
Try #[color:gray, bg: black]'lean console storage --help'[#] for more information.
|
||||||
|
CLI
|
||||||
|
, command: 'console storage')]
|
||||||
|
#[Option(toggle: ['-h', '--help'], description: "Display help for the given command. When no command is given display help for the list command")]
|
||||||
|
#[Option(toggle: ['-q', '--quiet'], description: "Do not output any message")]
|
||||||
|
#[Option(toggle: ['-n', '--no-interaction'], description: "Run script without user interaction")]
|
||||||
|
#[Option(toggle: ['-v', '-vv', '-vvv', '--verbose'], description: "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug", argument: Option::ARGUMENT_OPTIONAL)]
|
||||||
|
class Storage
|
||||||
|
{
|
||||||
|
use Lib\ConsoleControllerTrait;
|
||||||
|
|
||||||
|
#[Command(description: "Generate entities based on an existing connection", command: "entity:generate")]
|
||||||
|
#[Option(toggle: ['-l', '--list'], description: "")]
|
||||||
|
public function generate_entity(ServerRequestInterface $request, array $arguments): ResponseInterface
|
||||||
|
{
|
||||||
|
dump($arguments);
|
||||||
|
|
||||||
|
return $this->renderCLI($request, ":)");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,7 +27,7 @@ class Storage extends Console {
|
|||||||
$migrations = $this->container->has(Lib\DatabaseMigrations::class) ? $this->container->get(Lib\DatabaseMigrations::class) : false;
|
$migrations = $this->container->has(Lib\DatabaseMigrations::class) ? $this->container->get(Lib\DatabaseMigrations::class) : false;
|
||||||
$migrations->getEntities();
|
$migrations->getEntities();
|
||||||
|
|
||||||
$context = (new FormHandler($request, new Form\Storage\DatabaseMigration($migrations)))->context;
|
$context = (new FormHandler($request, new Form\Storage\Database\Migrate($migrations)))->context;
|
||||||
|
|
||||||
return $this->renderView("lean-console/page/storage/database", get_defined_vars());
|
return $this->renderView("lean-console/page/storage/database", get_defined_vars());
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ class Storage extends Console {
|
|||||||
$migrations = $this->container->has(Lib\DatabaseMigrations::class) ? $this->container->get(Lib\DatabaseMigrations::class) : false;
|
$migrations = $this->container->has(Lib\DatabaseMigrations::class) ? $this->container->get(Lib\DatabaseMigrations::class) : false;
|
||||||
$migrations->getEntities();
|
$migrations->getEntities();
|
||||||
|
|
||||||
$form = new Form\Storage\DatabaseImport($migrations, $connections);
|
$form = new Form\Storage\Database\Import($migrations, $connections);
|
||||||
|
|
||||||
$context = (new FormHandler($request, $form, $this->pushContext(new Lib\FormContext($request, "database.import"))))->context;
|
$context = (new FormHandler($request, $form, $this->pushContext(new Lib\FormContext($request, "database.import"))))->context;
|
||||||
|
|
||||||
@@ -74,12 +74,4 @@ class Storage extends Console {
|
|||||||
{
|
{
|
||||||
return rtrim(ini_get("session.save_path"), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
return rtrim(ini_get("session.save_path"), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createTable() : void
|
|
||||||
{
|
|
||||||
foreach($migrations->entities as $table) {
|
|
||||||
// $repository = $table
|
|
||||||
// $entity::repository()->createTable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
<?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\Common\EntityResolver;
|
|
||||||
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) {
|
|
||||||
$adapter = $entity::resolveEntity()->sqlAdapter()->adapter();
|
|
||||||
|
|
||||||
$tableName = $table->tableName();
|
|
||||||
$databaseName = $table->databaseName();
|
|
||||||
|
|
||||||
if ( ! $tableName || ! $databaseName ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#<<<<<<< HEAD
|
|
||||||
$tableEntity = $adapter->schemaTable($databaseName, $tableName);
|
|
||||||
|
|
||||||
if ( $tableEntity ) {
|
|
||||||
#$fields = $entiy::resolveEntity()->fieldList();
|
|
||||||
|
|
||||||
foreach($tableEntity->columns as $col) {
|
|
||||||
//dump( $entity::field($col->name) );
|
|
||||||
#=======
|
|
||||||
# $table = Table::repository()
|
|
||||||
# ->where(Table::field('name'), $table->tableName())
|
|
||||||
# ->where(Table::field('schema'), $table->databaseName())
|
|
||||||
# ->loadOne();
|
|
||||||
|
|
||||||
# if ( $table ) {
|
|
||||||
# $fields = $entity::resolveEntity()->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
|
|
||||||
|
|
||||||
# $alter = [];
|
|
||||||
|
|
||||||
# foreach($fields as $field => $definition) {
|
|
||||||
# if ( $table->columns->filtersCollection(fn($e) => $e->name === $field)->count() === 0 ) {
|
|
||||||
# $alter[$field] = $definition;
|
|
||||||
# }
|
|
||||||
#>>>>>>> 7194a33bec884d745e838c8ac2693b353e95a3ce
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $alter ) {
|
|
||||||
$context->status[$entity] = [
|
|
||||||
'msg' => "alter",
|
|
||||||
"query" => $entity::repository()->alterSqlQuery($alter)->getSqlQuery(true),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# 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
|
|
||||||
{
|
|
||||||
if ( $context->create ?? false ) {
|
|
||||||
$context->create::repository()->createTable();
|
|
||||||
}
|
|
||||||
elseif ( $context->createAll ?? false ) {
|
|
||||||
foreach(explode(',', $context->createAll) as $entity) {
|
|
||||||
$entity::repository()->createTable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif ( $context->alter ?? false ) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->initialize($context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getContext(ServerRequestInterface $request) : FormContextInterface
|
|
||||||
{
|
|
||||||
return new class($request) extends FormContext {
|
|
||||||
|
|
||||||
public array $status = [];
|
|
||||||
|
|
||||||
public array $actions = [];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lean\Console\Form\Storage\Database;
|
||||||
|
|
||||||
|
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
|
||||||
|
|
||||||
|
use \Lean\Console\{ Lib, Entity };
|
||||||
|
|
||||||
|
use Picea\Compiler\Context;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Ulmus\{ EntityCollection };
|
||||||
|
|
||||||
|
class GenerateEntity implements FormInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initialize(FormContextInterface $context) : void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validate(FormContextInterface $context) : bool
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
return $context->valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(FormContextInterface $context) : void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Lean\Console\Form\Storage;
|
namespace Lean\Console\Form\Storage\Database;
|
||||||
|
|
||||||
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
|
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ use Picea\Compiler\Context;
|
|||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Ulmus\{ EntityCollection };
|
use Ulmus\{ EntityCollection };
|
||||||
|
|
||||||
class DatabaseImport implements FormInterface
|
class Import implements FormInterface
|
||||||
{
|
{
|
||||||
protected ? Lib\DatabaseMigrations $migration;
|
protected ? Lib\DatabaseMigrations $migration;
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Lean\Console\Form\Storage;
|
namespace Lean\Console\Form\Storage\Database;
|
||||||
|
|
||||||
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
|
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ use Psr\Http\Message\ServerRequestInterface;
|
|||||||
use Ulmus\Common\EntityResolver;
|
use Ulmus\Common\EntityResolver;
|
||||||
use \Ulmus\Entity\InformationSchema\Table;
|
use \Ulmus\Entity\InformationSchema\Table;
|
||||||
|
|
||||||
class DatabaseMigration implements FormInterface
|
class Migrate implements FormInterface
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected ? Lib\DatabaseMigrations $migration,
|
protected ? Lib\DatabaseMigrations $migration,
|
||||||
@@ -22,7 +22,7 @@ class DatabaseMigrations
|
|||||||
foreach($this->folderList as $namespace => $folder) {
|
foreach($this->folderList as $namespace => $folder) {
|
||||||
foreach(static::files($folder) as $file) {
|
foreach(static::files($folder) as $file) {
|
||||||
$name = $file->getBasename("." . $file->getExtension());
|
$name = $file->getBasename("." . $file->getExtension());
|
||||||
$subNs = substr($file->getPath(), strlen($folder));
|
$subNs = str_replace('/', '\\', substr($file->getPath(), strlen($folder)));
|
||||||
$entity = rtrim($namespace, "\\") . ( $subNs ? "\\$subNs" : "" ) . "\\{$name}";
|
$entity = rtrim($namespace, "\\") . ( $subNs ? "\\$subNs" : "" ) . "\\{$name}";
|
||||||
|
|
||||||
if ( ! method_exists($entity, 'resolveEntity') ) {
|
if ( ! method_exists($entity, 'resolveEntity') ) {
|
||||||
@@ -34,6 +34,8 @@ class DatabaseMigrations
|
|||||||
if ( $resolve->sqlAdapter()->adapter() instanceof SqlAdapterInterface) {
|
if ( $resolve->sqlAdapter()->adapter() instanceof SqlAdapterInterface) {
|
||||||
$this->entities[$entity] = $resolve;
|
$this->entities[$entity] = $resolve;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
<div class="col"><span>📄</span> <span>{{ $item->tableName() }}</span></div>
|
<div class="col"><span>📄</span> <span>{{ $item->tableName() }}</span></div>
|
||||||
<div class="col">{% _ "database.table.fields", [ 'count' => count( $item->fieldList() ) ] %}</div>
|
<div class="col">{% _ "database.table.fields", [ 'count' => count( $item->fieldList() ) ] %}</div>
|
||||||
<div class="col col-grow-2">
|
<div class="col col-grow-2">
|
||||||
{% if $context->definition[$entity]['table']->modifier->query %}
|
{% if $context->definition[$entity]['table']->modifier->query ?? false %}
|
||||||
<code>{{= implode('<br><br>',(array) $context->definition[$entity]['table']->modifier->query) }}</code>
|
<code>{{= implode('<br><br>',(array) $context->definition[$entity]['table']->modifier->query) }}</code>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div style="color:#abecab">✓ {% _ 'database.table.uptodate' %}</div>
|
<div style="color:#abecab">✓ {% _ 'database.table.uptodate' %}</div>
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{% switch $context->definition[$entity]['table']->modifier->type %}
|
{% switch $context->definition[$entity]['table']->modifier->type ?? false %}
|
||||||
{% case ModifierTypeEnum::Create %}
|
{% case ModifierTypeEnum::Create %}
|
||||||
{% php $createAll[] = $entity %}
|
{% php $createAll[] = $entity %}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user