From 24e5490c71ec425b0b310b72370e95f931ff0085 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 29 Nov 2022 19:29:15 +0000 Subject: [PATCH] - Work done on the console to have at least some working functionality from every parts --- meta/definitions/software.php | 4 +- meta/i18n/en/lean.caching.json | 3 + meta/i18n/fr/lean.storage.json | 4 ++ src/Controller/Caching.php | 41 ++++++++++++ src/Controller/Storage.php | 39 +++++++++-- src/Controller/Templating.php | 37 ++++++++++ src/Form/Caching/Picea.php | 67 +++++++++++++++++++ src/Form/Database.php | 3 +- src/Lib/ConsoleControllerTrait.php | 4 +- src/Lib/FormContext.php | 5 ++ src/Lib/Sqlite/Triggers.php | 9 +++ view/lean-console/base/asset/lean.css | 8 +-- view/lean-console/base/console/main-nav.phtml | 12 ++-- view/lean-console/page/caching/picea.phtml | 41 ++++++++++++ view/lean-console/page/request/route.phtml | 2 +- view/lean-console/page/storage/database.phtml | 16 ++--- view/lean-console/page/storage/session.phtml | 42 ++++++++++++ view/lean-console/page/templating/picea.phtml | 42 ++++++++++++ 18 files changed, 352 insertions(+), 27 deletions(-) create mode 100644 meta/i18n/en/lean.caching.json create mode 100644 src/Controller/Caching.php create mode 100644 src/Controller/Templating.php create mode 100644 src/Form/Caching/Picea.php create mode 100644 src/Lib/FormContext.php create mode 100644 src/Lib/Sqlite/Triggers.php create mode 100644 view/lean-console/page/caching/picea.phtml create mode 100644 view/lean-console/page/storage/session.phtml create mode 100644 view/lean-console/page/templating/picea.phtml diff --git a/meta/definitions/software.php b/meta/definitions/software.php index 6199ef0..34ba1ff 100644 --- a/meta/definitions/software.php +++ b/meta/definitions/software.php @@ -5,9 +5,11 @@ use Lean\Console\Lib\DatabaseMigrations; return [ 'lean.console' => [ 'picea' => [ + 'context' => "Lean\\Console\\View", + 'view' => [ [ - 'path' => getenv("PROJECT_PATH") . "/vendor/mcnd/lean-console/view/", + 'path' => getenv("PROJECT_PATH") . implode(DIRECTORY_SEPARATOR, [ "", "vendor", "mcnd" , "lean-console" , "view" ]), 'order' => 99, ], ], diff --git a/meta/i18n/en/lean.caching.json b/meta/i18n/en/lean.caching.json new file mode 100644 index 0000000..6ab8de2 --- /dev/null +++ b/meta/i18n/en/lean.caching.json @@ -0,0 +1,3 @@ +{ + "clear": "Clear" +} \ No newline at end of file diff --git a/meta/i18n/fr/lean.storage.json b/meta/i18n/fr/lean.storage.json index 3459fd2..a7f3ec7 100644 --- a/meta/i18n/fr/lean.storage.json +++ b/meta/i18n/fr/lean.storage.json @@ -20,6 +20,10 @@ "createAll": "Create all tables", "query": "SQL Query" } + }, + "session": { + "header": "List of sessions", + "count": "{$count} session(s)" } } \ No newline at end of file diff --git a/src/Controller/Caching.php b/src/Controller/Caching.php new file mode 100644 index 0000000..1c5ebbc --- /dev/null +++ b/src/Controller/Caching.php @@ -0,0 +1,41 @@ + "lean.console:caching") + */ + public function picea(ServerRequestInterface $request, array $arguments) : ResponseInterface + { + $list = []; + + if ( isset($this->picea) ) { + form(new Form\Caching\Picea($this->picea, $list), $this->pushContext(new Lib\FormContext($request, "caching.picea"))); + } + + return $this->renderView("lean-console/page/caching/picea", get_defined_vars()); + } +} \ No newline at end of file diff --git a/src/Controller/Storage.php b/src/Controller/Storage.php index ba9fc6d..aa319a8 100644 --- a/src/Controller/Storage.php +++ b/src/Controller/Storage.php @@ -28,10 +28,7 @@ class Storage extends Console { use Lib\ConsoleControllerTrait; /** - * @Route("/storage/database", "name" => "lean.console:request.route") - * @param ServerRequestInterface $request - * @param array $arguments - * @return ResponseInterface + * @Route("/storage/database", "name" => "lean.console:storage.database") */ public function database(ServerRequestInterface $request, array $arguments) : ResponseInterface { @@ -45,6 +42,40 @@ class Storage extends Console { return $this->renderView("lean-console/page/storage/database", get_defined_vars()); } + /** + * @Route("/storage/session", "name" => "lean.console:storage.session") + */ + public function session(ServerRequestInterface $request, array $arguments) : ResponseInterface + { + $path = ini_get("session.save_path"); + + $sessions = preg_grep("/^sess_/", scandir($path)); + + return $this->renderView("lean-console/page/storage/session", get_defined_vars()); + } + + /** + * #Taxus('admin') + * @Route("/storage/session/content/{hash}", "name" => "lean.console:storage.session_content") + */ + public function sessionContent(ServerRequestInterface $request, array $arguments) : ResponseInterface + { + $sess = session_encode(); + + session_decode(file_get_contents($this->sessionPath() . $arguments['hash'])); + + $data = array_combine(array_keys($_SESSION), array_values($_SESSION)); + + session_decode($sess); + + return $this->renderJson($data); + } + + protected function sessionPath() : string + { + return rtrim(ini_get("session.save_path"), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + } + public function createTable() : void { foreach($migrations->entities as $table) { diff --git a/src/Controller/Templating.php b/src/Controller/Templating.php new file mode 100644 index 0000000..237aa1c --- /dev/null +++ b/src/Controller/Templating.php @@ -0,0 +1,37 @@ + "lean.console:templating.picea") + */ + public function picea(ServerRequestInterface $request, array $arguments) : ResponseInterface + { + $picea = $this->container->has(Picea::class) ? $this->container->get(Picea::class) : false; + + $list = $picea->fileFetcher->getFileList(); + + return $this->renderView("lean-console/page/templating/picea", get_defined_vars()); + } + +} \ No newline at end of file diff --git a/src/Form/Caching/Picea.php b/src/Form/Caching/Picea.php new file mode 100644 index 0000000..94f4e39 --- /dev/null +++ b/src/Form/Caching/Picea.php @@ -0,0 +1,67 @@ +folders = &$folders; + $this->picea = $picea; + } + + public function initialize(FormContextInterface $context) : void + { + if ($this->picea->cache instanceof Opcache) { + $path = $this->picea->cache->cachePath() . "/"; + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD); + + foreach ($iterator as $file) { + if ($file->isFile() && in_array($file->getExtension(), [ 'php' ])) { + $this->folders[$path][] = $file; + } + } + } + } + + public function validate(FormContextInterface $context) : bool + { + return $context->valid(); + } + + public function execute(FormContextInterface $context) : void + { + $deleted = $failed = 0; + + foreach($this->folders as $path => $files) { + foreach($files as $file) + { + unlink($file->getPathname()) ? $deleted++ : $failed++; + } + } + + if ($deleted) { + # $context->pushMessage(); + } + + if ($failed) { + # $context->pushMessage(); + } + } +} diff --git a/src/Form/Database.php b/src/Form/Database.php index ff1ef14..92dfdd4 100644 --- a/src/Form/Database.php +++ b/src/Form/Database.php @@ -34,7 +34,6 @@ class Database implements FormInterface continue; } -#<<<<<<< HEAD $tableEntity = $adapter->schemaTable($databaseName, $tableName); if ( $tableEntity ) { @@ -59,6 +58,8 @@ class Database implements FormInterface # } #>>>>>>> 7194a33bec884d745e838c8ac2693b353e95a3ce } + + $alter =false; if ( $alter ) { $context->status[$entity] = [ diff --git a/src/Lib/ConsoleControllerTrait.php b/src/Lib/ConsoleControllerTrait.php index f94510a..bd748e5 100644 --- a/src/Lib/ConsoleControllerTrait.php +++ b/src/Lib/ConsoleControllerTrait.php @@ -11,8 +11,8 @@ use Picea; /** * @Language("lean.route") * @RouteParam("methods" => [ 'GET', 'POST', 'DELETE' ], "base" => "/~") - * @Security('locked' => true) - * @Taxus("admin") + * @Security('locked' => false) + * @Taxus("dev") */ trait ConsoleControllerTrait { diff --git a/src/Lib/FormContext.php b/src/Lib/FormContext.php new file mode 100644 index 0000000..066acef --- /dev/null +++ b/src/Lib/FormContext.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/view/lean-console/page/caching/picea.phtml b/view/lean-console/page/caching/picea.phtml new file mode 100644 index 0000000..dce5364 --- /dev/null +++ b/view/lean-console/page/caching/picea.phtml @@ -0,0 +1,41 @@ +{% extends "lean-console/base/layout" %} + +{% language.set "lean.caching" %} + +{% title _("title") %} + +{% section "header" %} +
{% _ "page-title" %}
+{% endsection %} + +{% section "content" %} + {% foreach $list as $path => $folder %} +
+
+

{{ $path }}

+ {% ui.form.post "caching.picea" %} + + {% ui.endform %} +
+ +
+ {% foreach $folder as $file %} +
+ {{ substr($file, strlen($path)) }} +
+
+
+ {% endforeach %} +
+
+ {% endforeach %} + + +{% endsection %} \ No newline at end of file diff --git a/view/lean-console/page/request/route.phtml b/view/lean-console/page/request/route.phtml index b051b10..8aebb0c 100644 --- a/view/lean-console/page/request/route.phtml +++ b/view/lean-console/page/request/route.phtml @@ -40,7 +40,7 @@ {% endsection %} \ No newline at end of file diff --git a/view/lean-console/page/storage/session.phtml b/view/lean-console/page/storage/session.phtml new file mode 100644 index 0000000..7069630 --- /dev/null +++ b/view/lean-console/page/storage/session.phtml @@ -0,0 +1,42 @@ +{% extends "lean-console/base/layout" %} + +{% language.set "lean.storage" %} + +{% title _("title") %} + +{% section "header" %} +
{% _ "page-title" %}
+{% endsection %} + +{% section "content" %} +
+
+

{% _ 'session.header' %}

+
+ +
+ +
{% _ 'session.count', [ 'count' => count($sessions) ] %}
+
+ + {% foreach $sessions as $session %} +
+ {{ $session }} +
{{ date('Y-m-d H:i:s', filemtime(realpath($path . DIRECTORY_SEPARATOR . $session))) }}
+ +
+ {% endforeach %} +
+
+ + +{% endsection %} \ No newline at end of file diff --git a/view/lean-console/page/templating/picea.phtml b/view/lean-console/page/templating/picea.phtml new file mode 100644 index 0000000..1873ab5 --- /dev/null +++ b/view/lean-console/page/templating/picea.phtml @@ -0,0 +1,42 @@ +{% extends "lean-console/base/layout" %} + +{% language.set "lean.templating" %} + +{% title _("title") %} + +{% section "header" %} +
{% _ "page-title" %}
+{% endsection %} + +{% section "content" %} + + {% foreach $list as $path => $folder %} +
+
+

{{ $path }}

+
+ +
+ {% foreach $folder as $file %} +
+ {{ substr($file, strlen($path)) }} +
+ {# + Voir + #} +
+
+ {% endforeach %} +
+
+ {% endforeach %} + + +{% endsection %} \ No newline at end of file