- Update on database migration
This commit is contained in:
		
							parent
							
								
									5035a65672
								
							
						
					
					
						commit
						d133ac662e
					
				
							
								
								
									
										7
									
								
								meta/i18n/fr/lean.debugging.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								meta/i18n/fr/lean.debugging.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
{
 | 
			
		||||
    "title" : "Debugging -- LEAN",
 | 
			
		||||
    "page-title": "Déboguage",
 | 
			
		||||
    "breadcrumb" : {
 | 
			
		||||
        "index" : "Negundo"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -20,6 +20,11 @@
 | 
			
		||||
      "label": "Caching"
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    "debugging": {
 | 
			
		||||
      "label": "Déboguage",
 | 
			
		||||
      "logs": "Logs"
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    "request": {
 | 
			
		||||
      "label": "Request",
 | 
			
		||||
      "routes": "Routes"
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,6 @@ use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
 | 
			
		||||
use Lean\Console\{ Form, Lib };
 | 
			
		||||
use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
 | 
			
		||||
 | 
			
		||||
#[Language("lean.caching")]
 | 
			
		||||
class Caching extends Console {
 | 
			
		||||
    use Lib\ConsoleControllerTrait;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -9,7 +9,6 @@ use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
 | 
			
		||||
 | 
			
		||||
use \Lean\Console\{ Lib, Form };
 | 
			
		||||
 | 
			
		||||
#[Language("lean.console")]
 | 
			
		||||
class Console {
 | 
			
		||||
    use Lib\ConsoleControllerTrait;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										34
									
								
								src/Controller/Debugging.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/Controller/Debugging.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Lean\Console\Controller;
 | 
			
		||||
 | 
			
		||||
use League\Route\Router;
 | 
			
		||||
use Picea\{FileFetcher, Picea, Caching\Opcache, Extension\UrlExtension, Ui\Method\FormHandler};
 | 
			
		||||
use Lean\File;
 | 
			
		||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
 | 
			
		||||
use Lean\Console\{ Form, Lib };
 | 
			
		||||
use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
 | 
			
		||||
 | 
			
		||||
class Debugging extends Console {
 | 
			
		||||
    use Lib\ConsoleControllerTrait;
 | 
			
		||||
 | 
			
		||||
    #[Route(route: "/debugging/logs", name: "lean.console:debugging-logs")]
 | 
			
		||||
    public function logs(ServerRequestInterface $request, array $arguments) : ResponseInterface
 | 
			
		||||
    {
 | 
			
		||||
        $list = [];
 | 
			
		||||
 | 
			
		||||
        new FormHandler($request, new Form\Debugging\Logs(), $this->pushContext(new Lib\FormContext($request, "debugging.logs")));
 | 
			
		||||
 | 
			
		||||
        $path = getenv('LOGS_PATH');
 | 
			
		||||
 | 
			
		||||
        $files = array_map(fn($e) => basename($e), glob("$path/*"));
 | 
			
		||||
 | 
			
		||||
        $default = basename(ini_get('error_log'));
 | 
			
		||||
 | 
			
		||||
        $open = end($files);
 | 
			
		||||
 | 
			
		||||
        $content = File::tail($path . DIRECTORY_SEPARATOR . $open, 100);
 | 
			
		||||
 | 
			
		||||
        return $this->renderView("lean-console/page/debugging/logs", get_defined_vars());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -8,7 +8,6 @@ use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
 | 
			
		||||
 | 
			
		||||
use \Lean\Console\Lib;
 | 
			
		||||
 | 
			
		||||
#[Language("lean.dev")]
 | 
			
		||||
class Dev {
 | 
			
		||||
    use Lib\ConsoleControllerTrait;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,6 @@ use \Lean\Console\Lib;
 | 
			
		||||
 | 
			
		||||
use Picea\Extension\UrlExtension;
 | 
			
		||||
 | 
			
		||||
#[Language("lean.request")]
 | 
			
		||||
class Request extends Console {
 | 
			
		||||
    use Lib\ConsoleControllerTrait;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -17,8 +17,6 @@ use Picea\Extension\UrlExtension;
 | 
			
		||||
use Ulmus\Annotation\Classes\Table,
 | 
			
		||||
    Ulmus\Container\AdapterProxy;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#[Language("lean.storage")]
 | 
			
		||||
class Storage extends Console {
 | 
			
		||||
    use Lib\ConsoleControllerTrait;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,6 @@ use \Lean\Console\Lib;
 | 
			
		||||
 | 
			
		||||
use Picea\Extension\UrlExtension;
 | 
			
		||||
 | 
			
		||||
#[Language("lean.templating")] # migrated from: "lean.templating"
 | 
			
		||||
class Templating extends Console {
 | 
			
		||||
    use Lib\ConsoleControllerTrait;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										34
									
								
								src/Form/Debugging/Logs.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/Form/Debugging/Logs.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Lean\Console\Form\Debugging;
 | 
			
		||||
 | 
			
		||||
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
 | 
			
		||||
 | 
			
		||||
use \Lean\Console\Lib;
 | 
			
		||||
 | 
			
		||||
use Picea\{Caching\Opcache, Compiler\Context };
 | 
			
		||||
use Psr\Http\Message\ServerRequestInterface;
 | 
			
		||||
use Ulmus\Common\EntityResolver;
 | 
			
		||||
use \Ulmus\Entity\InformationSchema\Table;
 | 
			
		||||
 | 
			
		||||
use RecursiveIteratorIterator, RecursiveDirectoryIterator;
 | 
			
		||||
 | 
			
		||||
class Logs 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
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -71,11 +71,20 @@ class DatabaseMigration implements FormInterface
 | 
			
		||||
                $alter = $this->definition[$entity]['columns']->filterAlter();
 | 
			
		||||
 | 
			
		||||
                if ( $alter->count() ) {
 | 
			
		||||
                    if ( $adapter->splitAlterQuery() ) {
 | 
			
		||||
                        $query = $alter->map(fn(Lib\Database\Definition $map) => $entity::repository()
 | 
			
		||||
                            ->alterSqlQuery([$map->toArray()])
 | 
			
		||||
                            ->getSqlQuery(true));
 | 
			
		||||
                    }
 | 
			
		||||
                    else {
 | 
			
		||||
                        $query = $entity::repository()
 | 
			
		||||
                            ->alterSqlQuery($alter->map(fn(Lib\Database\Definition $map) => $map->toArray()))
 | 
			
		||||
                            ->getSqlQuery(true);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    $tableDefinition->modifier = new Lib\Database\Modifier(
 | 
			
		||||
                        type: Lib\Database\ModifierTypeEnum::Alter,
 | 
			
		||||
                        query: $entity::repository()
 | 
			
		||||
                            ->alterSqlQuery($alter->map(fn(Lib\Database\Definition $e) => $e->toArray()))
 | 
			
		||||
                            ->getSqlQuery(true),
 | 
			
		||||
                        query: $query,
 | 
			
		||||
                    );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@ -110,10 +119,19 @@ class DatabaseMigration implements FormInterface
 | 
			
		||||
        $alter = $context->alterAll ? explode(',', $context->alterAll) : [ $context->alter ];
 | 
			
		||||
 | 
			
		||||
        foreach(array_filter($alter) as $entity) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            if ($this->definition[$entity]['table']->modifier->type === Lib\Database\ModifierTypeEnum::Alter) {
 | 
			
		||||
                $entity::repository()->alterTable($this->definition[$entity]['columns']->filterAlter  ()->map( fn($e) => $e->toArray() ));
 | 
			
		||||
                $adapter = $entity::resolveEntity()->sqlAdapter()->adapter();
 | 
			
		||||
 | 
			
		||||
                $def = $this->definition[$entity]['columns']->filterAlter();
 | 
			
		||||
 | 
			
		||||
                if ( $adapter->splitAlterQuery() ) {
 | 
			
		||||
                    $def->walk(fn(Lib\Database\Definition $definition) =>
 | 
			
		||||
                        $entity::repository()->alterTable([ $definition->toArray() ])
 | 
			
		||||
                    );
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    $entity::repository()->alterTable($def->map( fn(Lib\Database\Definition $e) => $e->toArray() ));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,7 @@ class Definition
 | 
			
		||||
        public string               $entity,
 | 
			
		||||
        public string|null          $field = null,
 | 
			
		||||
        public array|null           $definition = null,
 | 
			
		||||
        public null|Modifier   $modifier = null,
 | 
			
		||||
        public null|Modifier|array  $modifier = null,
 | 
			
		||||
        public null|Definition      $previous = null,
 | 
			
		||||
        public null|string          $action = null,
 | 
			
		||||
    ) {}
 | 
			
		||||
 | 
			
		||||
@ -26,4 +26,10 @@
 | 
			
		||||
    <ul>
 | 
			
		||||
        <li><a href="{% route 'lean.console:caching' %}">{% lang "lean.nav.templating.picea" %}</a></li>
 | 
			
		||||
    </ul>
 | 
			
		||||
 | 
			
		||||
    <label>{% lang "lean.nav.debugging.label" %}</label>
 | 
			
		||||
    <ul>
 | 
			
		||||
        <li><a href="{% route 'lean.console:debugging-logs' %}">{% lang "lean.nav.debugging.logs" %}</a></li>
 | 
			
		||||
    </ul>
 | 
			
		||||
 | 
			
		||||
</nav>
 | 
			
		||||
@ -13,16 +13,24 @@
 | 
			
		||||
        <section>
 | 
			
		||||
            <header>
 | 
			
		||||
                <h1>{{ $path }}</h1>
 | 
			
		||||
                {% ui.form.post "caching.picea" %}
 | 
			
		||||
                {% ui:form.post "caching.picea" %}
 | 
			
		||||
                <button class="btn-red" type="submit">{% _ 'clear' %}</button>
 | 
			
		||||
                {% ui.endform %}
 | 
			
		||||
                {% ui:endform %}
 | 
			
		||||
            </header>
 | 
			
		||||
 | 
			
		||||
            <article class="picea">
 | 
			
		||||
                {% foreach $folder as $file %}
 | 
			
		||||
                    {% php $import = include($file) %}
 | 
			
		||||
 | 
			
		||||
                    <div class="grid">
 | 
			
		||||
                        <strong class="col route-name">{{ substr($file, strlen($path)) }}</strong>
 | 
			
		||||
                        <div>
 | 
			
		||||
 | 
			
		||||
                        <div class="col">
 | 
			
		||||
                            {{ $import['namespace'] }}
 | 
			
		||||
                        </div>
 | 
			
		||||
 | 
			
		||||
                        <div class="col">
 | 
			
		||||
                            {{ $import['view'] }}
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                {% endforeach %}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										36
									
								
								view/lean-console/page/debugging/logs.phtml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								view/lean-console/page/debugging/logs.phtml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
{% extends "lean-console/base/layout" %}
 | 
			
		||||
 | 
			
		||||
{% language.set "lean.caching" %}
 | 
			
		||||
 | 
			
		||||
{% title _("title") %}
 | 
			
		||||
 | 
			
		||||
{% section "header" %}
 | 
			
		||||
    <div class="page-title">{% _ "page-title" %}</div>
 | 
			
		||||
{% endsection %}
 | 
			
		||||
 | 
			
		||||
{% section "content" %}
 | 
			
		||||
        <section>
 | 
			
		||||
            <header>
 | 
			
		||||
                <h1>{{ $path }}</h1>
 | 
			
		||||
 | 
			
		||||
                {% ui:form.get current_url() %}
 | 
			
		||||
                    {% ui:select 'logfile', array_combine($files, $files), get('file') ?? $open %}
 | 
			
		||||
                {% ui:endform %}
 | 
			
		||||
            </header>
 | 
			
		||||
 | 
			
		||||
            <article class="logs">
 | 
			
		||||
                <div class="log-item">
 | 
			
		||||
                    {% foreach array_reverse($content) as $line %}
 | 
			
		||||
                        <div class="line">{{ $line }}</div>
 | 
			
		||||
                    {% endforeach %}
 | 
			
		||||
                </div>
 | 
			
		||||
            </article>
 | 
			
		||||
        </section>
 | 
			
		||||
    <style>
 | 
			
		||||
        section > header {display:flex;justify-content: space-between}
 | 
			
		||||
        .log-item {max-height: 60vh; overflow-y:auto}
 | 
			
		||||
        .log-item .line {padding:0.5rem}
 | 
			
		||||
        .log-item .line {background: #efefef}
 | 
			
		||||
        .log-item .line:nth-child(even) {background: #ccc}
 | 
			
		||||
    </style>
 | 
			
		||||
{% endsection %}
 | 
			
		||||
@ -40,14 +40,14 @@
 | 
			
		||||
                            <div class="col text-right">{% _ 'database.table.actions' %}</div>
 | 
			
		||||
                        </strong>
 | 
			
		||||
 | 
			
		||||
                        {% ui.form.post "database" %}
 | 
			
		||||
                        {% ui:form.post "database" %}
 | 
			
		||||
                            {% foreach array_filter($migrations->entities, fn($e) => $e->databaseAdapter() === $connection) as $entity => $item %}
 | 
			
		||||
                                <div class="grid table-item align-items-center">
 | 
			
		||||
                                    <div class="col"><span>📄</span> <span>{{ $item->tableName() }}</span></div>
 | 
			
		||||
                                    <div class="col">{% _ "database.table.fields", [ 'count' => count( $item->fieldList() ) ] %}</div>
 | 
			
		||||
                                    <div class="col col-grow-2">
 | 
			
		||||
                                        {% if $context->definition[$entity]['table']->modifier->query %}
 | 
			
		||||
                                            <code>{{ $context->definition[$entity]['table']->modifier->query }}</code>
 | 
			
		||||
                                            <code>{{= implode('<br><br>',(array) $context->definition[$entity]['table']->modifier->query) }}</code>
 | 
			
		||||
                                        {% else %}
 | 
			
		||||
                                            <div>🗸 This table is up-to-date</div>
 | 
			
		||||
                                        {% endif %}
 | 
			
		||||
@ -86,7 +86,7 @@
 | 
			
		||||
                                    <button name="alterAll" value="{{ implode(',', $alterAll) }}" class="btn-red">🗸 {% _ 'database.table.alterAll' %}</button>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            {% endif %}
 | 
			
		||||
                        {% ui.endform %}
 | 
			
		||||
                        {% ui:endform %}
 | 
			
		||||
                    </div>
 | 
			
		||||
                </article>
 | 
			
		||||
            </section>
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,7 @@
 | 
			
		||||
 | 
			
		||||
{% section "content" %}
 | 
			
		||||
    {% if $connections %}
 | 
			
		||||
        {% ui.form.post "database.import" %}
 | 
			
		||||
        {% ui:form.post "database.import" %}
 | 
			
		||||
            <section>
 | 
			
		||||
                <header>Import data from a connection into another</header>
 | 
			
		||||
 | 
			
		||||
@ -19,15 +19,15 @@
 | 
			
		||||
                        {% php $select = array_combine(array_column($connections, 'name'), array_column($connections, 'name')) %}
 | 
			
		||||
 | 
			
		||||
                        <div class="db-grid">
 | 
			
		||||
                            Source connection: {% ui.select "source", $select %}
 | 
			
		||||
                            Source connection: {% ui:select "source", $select %}
 | 
			
		||||
                        </div>
 | 
			
		||||
 | 
			
		||||
                        <div class="db-grid">
 | 
			
		||||
                            Destination connection: {% ui.select "destination", $select %}
 | 
			
		||||
                            Destination connection: {% ui:select "destination", $select %}
 | 
			
		||||
                        </div>
 | 
			
		||||
                    {% else %}
 | 
			
		||||
                        {% ui.hidden 'source', $context->source %}
 | 
			
		||||
                        {% ui.hidden 'destination', $context->destination %}
 | 
			
		||||
                        {% ui:hidden 'source', $context->source %}
 | 
			
		||||
                        {% ui:hidden 'destination', $context->destination %}
 | 
			
		||||
 | 
			
		||||
                        <div class="db-grid">
 | 
			
		||||
                            COPY DATA FROM → TO:
 | 
			
		||||
@ -35,7 +35,7 @@
 | 
			
		||||
 | 
			
		||||
                            {% foreach $dest as $key => $value %}
 | 
			
		||||
                                <div class="db-grid">
 | 
			
		||||
                                    <span>{% ui.select "copy[$key]", [ null => '' ] + $context->sourceTables->buildArray('entityClass', 'entityClass') %}</span>
 | 
			
		||||
                                    <span>{% ui:select "copy[$key]", [ null => '' ] + $context->sourceTables->buildArray('entityClass', 'entityClass') %}</span>
 | 
			
		||||
                                    <span>→</span>
 | 
			
		||||
                                    <span>{{ sprintf('%s (%s)', $key, $value->tableName()) }}</span>
 | 
			
		||||
                                </div>
 | 
			
		||||
@ -49,7 +49,7 @@
 | 
			
		||||
                    <a href="{% route 'lean.console:storage.database' %}" class="btn-red">Cancel</a>
 | 
			
		||||
                </footer>
 | 
			
		||||
            </section>
 | 
			
		||||
        {% ui.endform %}
 | 
			
		||||
        {% ui:endform %}
 | 
			
		||||
    {% else %}
 | 
			
		||||
        No connection found
 | 
			
		||||
    {% endif %}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user