Code Improve : Extension , Fix : php8.1

This commit is contained in:
sparkyx 2024-02-22 23:25:02 +01:00
parent 4496e09703
commit ea2b77465c
5 changed files with 273 additions and 11 deletions

View file

@ -335,7 +335,7 @@ class Acc_Bilan
} }
catch(Exception $Ex) catch(Exception $Ex)
{ {
record_log($e); record_log($Ex);
echo $Ex->getMessage(); echo $Ex->getMessage();
throw $Ex; throw $Ex;
} }
@ -437,7 +437,7 @@ class Acc_Bilan
$zip->close(); $zip->close();
} else } else
{ {
echo __FILE__.":".__LINE__."cannot unzip model ".$filename; echo __FILE__.":".__LINE__."cannot unzip model ".$file_base;
} }
ob_end_clean(); ob_end_clean();
@ -738,7 +738,7 @@ class Acc_Bilan
} }
else else
{ {
echo __FILE__.":".__LINE__."cannot unzip model ".$filename; echo __FILE__.":".__LINE__."cannot unzip model ".$file_base;
} }
// Remove the file we do not need anymore // Remove the file we do not need anymore

View file

@ -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 * @param Database $p_cn
*/ */
static function clean(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 * @todo add a mechanism to check once a day
* @global User $g_user * @global User $g_user
* @global number $version_plugin * @global number $version_plugin
@ -327,6 +327,9 @@ class Extension extends Menu_Ref_sql
throw new Exception(_('Manque répertoire racine'), 1); throw new Exception(_('Manque répertoire racine'), 1);
if (!isset($xml->plugin[$i]->file)) if (!isset($xml->plugin[$i]->file))
throw new Exception(_('Manque fichier à inclure'), 1); 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)) if (!isset($xml->plugin[$i]->depend))
$xml->plugin[$i]->depend="EXT"; $xml->plugin[$i]->depend="EXT";
if (!isset($xml->plugin[$i]->order)) 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 Parse a XML file to complete an array of extension objects, in the plugin.xml file , you can find
* @brief Create extension from XML. * several plugins sharing some parts.
*
* @param string $p_file filename * @param string $p_file filename
* @return array array of Extension * @return array array of Extension
*/ */
@ -363,7 +367,7 @@ class Extension extends Menu_Ref_sql
} }
catch (Exception $ex) catch (Exception $ex)
{ {
echo_warning($e->getMessage()); echo_warning($ex->getMessage());
if ($ex->getCode()==1) if ($ex->getCode()==1)
{ {
continue; continue;
@ -378,14 +382,46 @@ class Extension extends Menu_Ref_sql
$extension->me_parameter='plugin_code='.trim($xml->plugin[$i]->code); $extension->me_parameter='plugin_code='.trim($xml->plugin[$i]->code);
$extension->depend=(isset($xml->plugin[$i]->depend))?trim($xml->plugin[$i]->depend):"EXT"; $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->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; $a_extension[]=clone $extension;
} }
return $a_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 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";
} }

View file

@ -175,9 +175,10 @@ having count(*) > 1
</li> </li>
<ul> <ul>
<?php $all_dep=Database::fetch_all($poste); <?php
$all_dep=Database::fetch_all($poste);
$nb_dep = ($all_dep == FALSE ) ? 0 :count($all_dep); $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> <li>
<?php echo HtmlInput::history_account($all_dep[$e]['j_poste'],$all_dep[$e]['j_poste'],' display:inline ')?> <?php echo HtmlInput::history_account($all_dep[$e]['j_poste'],$all_dep[$e]['j_poste'],' display:inline ')?>

View file

@ -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>

View file

@ -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");
}
}