- Some bugfixes were made and annotations were converted into attributes

This commit is contained in:
mcndave committed 2023-01-21 20:27:08 +00:00
1 parent 9c8f9903fc
commit 6ff29a576c
14 files changed
+247 -113

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
<?php
namespace Lean\Console\Form\Storage;
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 DatabaseImport implements FormInterface
{
protected ? Lib\DatabaseMigrations $migration;
protected array $connections;
public function __construct(Lib\DatabaseMigrations $migration, array $connections)
{
$this->migration = $migration;
$this->connections = $connections;
}
public function initialize(FormContextInterface $context) : void
{
$context->sourceTables ??= new EntityCollection();
$context->destinationTables ??= new EntityCollection();
}
public function validate(FormContextInterface $context) : bool
{
if ($context->source) {
$filtered = array_filter($this->migration->entities, fn($e, $key) => $key::repository()->adapter->name === $context->source, ARRAY_FILTER_USE_BOTH);
$context->sourceTables->replaceWith($filtered);
}
return $context->valid();
}
public function execute(FormContextInterface $context) : void
{
if ($context->copy) {
foreach (array_filter($context->copy) as $dest => $source) {
foreach($source::repository()->yield() as $src) {
$dest::repository()->save( $src->toArray(), null, true );
}
}
}
}
public static function getContext(ServerRequestInterface $request, ? string $formName = null) : FormContextInterface
{
return new class($request, $formName) extends FormContext {
public EntityCollection $sourceTables;
public EntityCollection $destinationTables;
};
}
}
@@ -1,6 +1,6 @@
<?php
namespace Lean\Console\Form;
namespace Lean\Console\Form\Storage;
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
@@ -11,7 +11,7 @@ use Psr\Http\Message\ServerRequestInterface;
use Ulmus\Common\EntityResolver;
use \Ulmus\Entity\InformationSchema\Table;
class Database implements FormInterface
class DatabaseMigration implements FormInterface
{
protected ? Lib\DatabaseMigrations $migration;
@@ -95,9 +95,9 @@ class Database implements FormInterface
$this->initialize($context);
}
public function getContext(ServerRequestInterface $request) : FormContextInterface
public static function getContext(ServerRequestInterface $request, ? string $formName = null) : FormContextInterface
{
return new class($request) extends FormContext {
return new class($request, $formName) extends FormContext {
public array $status = [];