[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 08/10: Code Improve : Extension , Fix : php8.
From: |
dwm |
Subject: |
[Noalyss-commit] [noalyss] 08/10: Code Improve : Extension , Fix : php8.1 |
Date: |
Sun, 25 Feb 2024 13:17:51 -0500 (EST) |
sparkyx pushed a commit to branch devel
in repository noalyss.
commit ea2b77465c9ace469762f159d924269502dfcdd9
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Thu Feb 22 23:25:02 2024 +0100
Code Improve : Extension , Fix : php8.1
---
include/class/acc_bilan.class.php | 6 +-
include/class/extension.class.php | 48 +++++++++--
include/verif_bilan.inc.php | 5 +-
unit-test/include/class/data/plugin.xml | 86 ++++++++++++++++++
unit-test/include/class/extensiontest.php | 139 ++++++++++++++++++++++++++++++
5 files changed, 273 insertions(+), 11 deletions(-)
diff --git a/include/class/acc_bilan.class.php
b/include/class/acc_bilan.class.php
index d39780f54..4993b1453 100644
--- a/include/class/acc_bilan.class.php
+++ b/include/class/acc_bilan.class.php
@@ -335,7 +335,7 @@ class Acc_Bilan
}
catch(Exception $Ex)
{
- record_log($e);
+ record_log($Ex);
echo $Ex->getMessage();
throw $Ex;
}
@@ -437,7 +437,7 @@ class Acc_Bilan
$zip->close();
} else
{
- echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
+ echo __FILE__.":".__LINE__."cannot unzip model ".$file_base;
}
ob_end_clean();
@@ -738,7 +738,7 @@ class Acc_Bilan
}
else
{
- echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
+ echo __FILE__.":".__LINE__."cannot unzip model ".$file_base;
}
// Remove the file we do not need anymore
diff --git a/include/class/extension.class.php
b/include/class/extension.class.php
index bf60cbdad..6f1cdacf5 100644
--- a/include/class/extension.class.php
+++ b/include/class/extension.class.php
@@ -253,7 +253,7 @@ class Extension extends Menu_Ref_sql
}
/**
- * remove all the schema from the plugins
+ * @brief remove all the standard plugins schema
* @param Database $p_cn
*/
static function clean(Database $p_cn)
@@ -269,7 +269,7 @@ class Extension extends Menu_Ref_sql
}
/**
- * compare the version of the plugin and the last version , propose to
update it if a new version exists
+ * @brief compare the version of the plugin and the last version , propose
to update it if a new version exists
* @todo add a mechanism to check once a day
* @global User $g_user
* @global number $version_plugin
@@ -327,6 +327,9 @@ class Extension extends Menu_Ref_sql
throw new Exception(_('Manque répertoire racine'), 1);
if (!isset($xml->plugin[$i]->file))
throw new Exception(_('Manque fichier à inclure'), 1);
+ if (!isset($xml->plugin[$i]->version))
+ throw new Exception(_("Manque version de l'extension"), 1);
+
if (!isset($xml->plugin[$i]->depend))
$xml->plugin[$i]->depend="EXT";
if (!isset($xml->plugin[$i]->order))
@@ -340,8 +343,9 @@ class Extension extends Menu_Ref_sql
}
/**
- * Parse a XML file to complete an array of extension objects
- * @brief Create extension from XML.
+ * @brief Parse a XML file to complete an array of extension objects, in
the plugin.xml file , you can find
+ * several plugins sharing some parts.
+ *
* @param string $p_file filename
* @return array array of Extension
*/
@@ -363,7 +367,7 @@ class Extension extends Menu_Ref_sql
}
catch (Exception $ex)
{
- echo_warning($e->getMessage());
+ echo_warning($ex->getMessage());
if ($ex->getCode()==1)
{
continue;
@@ -378,14 +382,46 @@ class Extension extends Menu_Ref_sql
$extension->me_parameter='plugin_code='.trim($xml->plugin[$i]->code);
$extension->depend=(isset($xml->plugin[$i]->depend))?trim($xml->plugin[$i]->depend):"EXT";
$extension->order=(isset($xml->plugin[$i]->order))?trim($xml->plugin[$i]->order):9000;
+ $extension->version=trim($xml->plugin[$i]->version);
+
$extension->noalyss_version=(isset($xml->plugin[$i]->noalyss_version))?trim($xml->plugin[$i]->noalyss_version):8000;
$a_extension[]=clone $extension;
}
return $a_extension;
}
+ /**
+ * @brief find the extension with the me_code = last part of access_code
+ * @param $a_extension
+ * @param $access_code find the ME_CODE (normally last part )
+ * @return the extension or null
+ */
+ public static function
find_extension_code($a_extension,$access_code):Extension|null
+ {
+ $a_me_code=explode("/", $access_code);
+ if (empty($a_me_code ) ) return null;
+ $nb_me_code=count($a_me_code);
+ $me_code=$a_me_code[$nb_me_code-1];
+ foreach ($a_extension as $extension) {
+ if ($extension->me_code==$me_code) return $extension;
+ }
+ return null;
+ }
+
public function __toString(): string
{
- return "Extension";
+ $r = "";
+ $r .= " me_code " . $this->me_code.PHP_EOL;
+ $r .= " me_menu.".$this->me_menu.PHP_EOL;
+ $r .= " version".$this->version.PHP_EOL;
+ $r .= " noalyss_version".$this->noalyss_version.PHP_EOL;
+ $r .= " me_file" . $this->me_file.PHP_EOL;
+ $r .= " me_url" . $this->me_url.PHP_EOL;
+ $r .= " me_description" . $this->me_description.PHP_EOL;
+ $r .= " me_parameter" . $this->me_parameter.PHP_EOL;
+ $r .= " me_javascript" . $this->me_javascript.PHP_EOL;
+ $r .= " me_type" . $this->me_type.PHP_EOL;
+ $r .= " me_descrition_etendue" .
$this->me_description_etendue.PHP_EOL;
+ return "Extension $r";
}
diff --git a/include/verif_bilan.inc.php b/include/verif_bilan.inc.php
index 05e90e595..bff0737ec 100644
--- a/include/verif_bilan.inc.php
+++ b/include/verif_bilan.inc.php
@@ -175,9 +175,10 @@ having count(*) > 1
</li>
<ul>
- <?php $all_dep=Database::fetch_all($poste);
+ <?php
+ $all_dep=Database::fetch_all($poste);
$nb_dep = ($all_dep == FALSE ) ? 0 :count($all_dep);
- for ($e=0;$e<count($nb_dep);$e++):
+ for ($e=0;$e<$nb_dep;$e++):
?>
<li>
<?php echo
HtmlInput::history_account($all_dep[$e]['j_poste'],$all_dep[$e]['j_poste'],'
display:inline ')?>
diff --git a/unit-test/include/class/data/plugin.xml
b/unit-test/include/class/data/plugin.xml
new file mode 100644
index 000000000..669eb6fc9
--- /dev/null
+++ b/unit-test/include/class/data/plugin.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?><!--
+/*
+ * This file is part of NOALYSS.
+ *
+ * NOALYSS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * NOALYSS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NOALYSS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+// Copyright (c) 2002-2014 Author Dany De Bontridder danydb@aevalys.eu
+-->
+<plugins>
+ <plugin>
+ <name>
+ Skeleton for plugin
+ </name>
+ <description>
+ Example of an XML File for developing a plugin.
+
+ </description>
+ <code>
+ SKEL
+ </code>
+ <root>
+ skel
+ </root>
+ <file>
+ index.php
+ </file>
+ <author>
+ Dany De Bontridder
+ </author>
+ <noalyss_version>9000</noalyss_version>
+ <order>
+ 9000
+ </order>
+ <depend>
+ EXT
+ </depend>
+ <schema>
+ skeleton
+ </schema>
+ <version>2000</version>
+ </plugin>
+ <plugin>
+ <name>
+ Second Skeleton for plugin
+ </name>
+ <description>
+ Example of an XML File for developing a plugin.
+ Second plugin inside
+ </description>
+ <code>
+ PLUGIN_TEST
+ </code>
+ <root>
+ skel
+ </root>
+ <file>
+ index-plugin_test.php
+ </file>
+ <author>
+ Dany De Bontridder
+ </author>
+ <noalyss_version>8111</noalyss_version>
+ <order>
+ 9000
+ </order>
+ <depend>
+ EXT
+ </depend>
+ <schema>
+ skeleton
+ </schema>
+ <version>9019</version>
+ </plugin>
+</plugins>
\ No newline at end of file
diff --git a/unit-test/include/class/extensiontest.php
b/unit-test/include/class/extensiontest.php
new file mode 100644
index 000000000..e4dbb73f6
--- /dev/null
+++ b/unit-test/include/class/extensiontest.php
@@ -0,0 +1,139 @@
+<?php
+
+/*
+ * * Copyright (C) 2022 Dany De Bontridder <dany@alchimerys.be>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Author : Dany De Bontridder danydb@noalyss.eu $(DATE)
+ */
+
+/**
+ * @file
+ * @brief noalyss
+ */
+
+use PHPUnit\Framework\TestCase;
+
+require DIRTEST . '/global.php';
+
+/**
+ * @testdox Class ExtensionTest : used for ...
+ * @backupGlobals enabled
+ * @coversDefaultClass
+ */
+class ExtensionTest extends TestCase
+{
+
+ /**
+ * @var Fiche
+ */
+ protected $object;
+ protected $connection;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test method is executed.
+ */
+ protected function setUp(): void
+ {
+
+
+ }
+
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test method is executed.
+ */
+ protected function tearDown(): void
+ {
+ /**
+ * example
+ * if ( ! is_object($this->object->fiche_def)) return;
+ * include_once DIRTEST.'/global.php';
+ * $g_connection=Dossier::connect();
+ * $sql=new ArrayObject();
+ * $sql->append("delete from fiche_detail where f_id in (select f_id
from fiche where fd_id =\$1 )");
+ * $sql->append("delete from fiche where f_id not in (select f_id from
fiche_detail where \$1=\$1)");
+ * $sql->append("delete from jnt_fic_attr where fd_id = \$1 ");
+ * $sql->append("delete from fiche_def where fd_id = \$1");
+ * foreach ($sql as $s) {
+ * $g_connection->exec_sql($s,[$this->object->fiche_def->id]);
+ * }
+ */
+ }
+
+ /**
+ * the setUpBeforeClass() template methods is called before the first test
of the test case
+ * class is run
+ */
+ public static function setUpBeforeClass(): void
+ {
+ // include 'global.php';
+ }
+
+ /**
+ * tearDownAfterClass() template methods is calleafter the last test of
the test case class is run,
+ *
+ */
+ static function tearDownAfterClass(): void
+ {
+ // include 'global.php';
+ }
+//
+// public function dataExample()
+// {
+// return array([1], [2], [3]);
+// }
+
+ /**
+ * @testdox check the load of plugin and find the plugin from an
access_code
+ * @covers \Extension::find_extension_code \Extension:read_definition ,
\Extension::verify
+ * @backupGlobals on
+ */
+ function testFind_extension_file()
+ {
+ global $cn;
+ require DIRTEST . '/global.php';
+ $cn=$g_connection;
+ $a_extension=\Extension::read_definition(__DIR__."/data/plugin.xml");
+ $access_code="EXT/TOOLS/PLUGIN_TEST";
+ $extension=\Extension::find_extension_code($a_extension, $access_code);
+
+ $this->assertTrue($extension->me_file=="skel/index-plugin_test.php");
+ $this->assertTrue($extension->version==9019, " ne peut retrouver la
version");
+ $this->assertTrue($extension->noalyss_version==8111," ne peut pas
retrouver la version de noalyss");
+ }
+
+ /**
+ * @testdox check the load of plugin and find the plugin from an
access_code
+ * @covers \Extension::find_extension_code
\Extension:read_definition\Extension::verify
+ * @backupGlobals on
+ */
+ function testFind_extension_version()
+ {
+ global $cn;
+ require DIRTEST . '/global.php';
+ $cn=$g_connection;
+ $a_extension=\Extension::read_definition(__DIR__."/data/plugin.xml");
+ $access_code="EXT/TOOLS/SKEL";
+ $extension=\Extension::find_extension_code($a_extension, $access_code);
+
+ $this->assertTrue($extension->version==2000, " ne peut retrouver la
version");
+ $this->assertTrue($extension->noalyss_version==9000," ne peut pas
retrouver la version de noalyss");
+
+ }
+}
\ No newline at end of file
- [Noalyss-commit] [noalyss] branch devel updated (910ae8b9f -> 39eb388b0), dwm, 2024/02/25
- [Noalyss-commit] [noalyss] 02/10: If card already used in accountancy, cannot changed the quickcode, dwm, 2024/02/25
- [Noalyss-commit] [noalyss] 06/10: Bug : verification ne fonctionne pas avec MY_REPORT=N, dwm, 2024/02/25
- [Noalyss-commit] [noalyss] 05/10: FOLLOWUP : change destinataire et concerne, supprime filtre sur "concerne", dwm, 2024/02/25
- [Noalyss-commit] [noalyss] 08/10: Code Improve : Extension , Fix : php8.1,
dwm <=
- [Noalyss-commit] [noalyss] 07/10: Saved search for accountancy replace filter by "Saved search", dwm, 2024/02/25
- [Noalyss-commit] [noalyss] 01/10: PHP8.1 compatibility, dwm, 2024/02/25
- [Noalyss-commit] [noalyss] 09/10: Merge, dwm, 2024/02/25
- [Noalyss-commit] [noalyss] 10/10: Follow-Up : list with a filter, dwm, 2024/02/25
- [Noalyss-commit] [noalyss] 03/10: QCODE : remove trigger update on jrnx, dwm, 2024/02/25
- [Noalyss-commit] [noalyss] 04/10: PHP8.1 compatibility, dwm, 2024/02/25