save_plugin();
+
+ } catch (\Exception $e) {
+ echo_warning($e->getMessage());
+ }
+
}
}
@@ -56,47 +63,7 @@ $nb_plugin=count($a_plugin);
*/
$a_profile=$cn->get_array('select p_id,p_name from profile where p_id > 0 order by p_name');
$nb_profile=count($a_profile);
-/******************************************************************************
- * save
- ******************************************************************************/
-if ( isset ($_POST['save_plugin'])){
- // retrieve array of plugin
- $plugin=$http->post('plugin', "string",array());
- // for each extension
- for ($i=0;$i<$nb_plugin;$i++) {
-
- $code=$a_plugin[$i]->me_code;
- // for each profile
- for ($e=0;$e<$nb_profile;$e++)
- {
- $profile=$a_profile[$e]['p_id'];
- if ( isset ($plugin[$code][$profile])) {
- // insert or update into db
- $count = $cn->get_value("select count(*) from menu_ref where me_code=$1", array($code));
- if ( $count == 0 ) {
- $a_plugin[$i]->insert();
- }
- try
- {
- $a_plugin[$i]->insert_profile_menu($profile);
- }
- catch (Exception $exc)
- {
- record_log($exc->getMessage()." trace:".$exc->getTraceAsString());
- $profile_name=$cn->get_value('select profile.p_name from profile where p_id=$1'
- ,array($profile));
- echo '';
- echo "code $code"," profile $profile_name ",$exc->getMessage();
- echo '
';
- }
- } else {
- // delete
- $a_plugin[$i]->remove_from_profile_menu ($profile);
- }
- }
- }
-}
/******************************************************************************
* Display the Plugin and for each profile were it is installed or not
******************************************************************************/
@@ -105,7 +72,7 @@ if ( isset ($_POST['save_plugin'])){
?>
diff --git a/include/class/extension.class.php b/include/class/extension.class.php
index 12d4871f5..58253f276 100644
--- a/include/class/extension.class.php
+++ b/include/class/extension.class.php
@@ -162,7 +162,9 @@ class Extension extends Menu_Ref_sql
// throw an exception if there is no dependency
if (empty($dep_id))
{
- throw new Exception(_('Pas de menu ').$p_module, 30);
+ $msg = sprintf(_("Le menu %s dont dépend %s doit être crée ou %s doit être ajouté depuis le menu CFGPRO"),
+ $p_module,$this->me_code,$this->me_code);
+ throw new Exception($msg, 30);
}
$nb_dep=count($dep_id);
@@ -196,7 +198,20 @@ class Extension extends Menu_Ref_sql
}
/**
- * Insert a plugin into the given profile, by default always insert into EXT
+ * @brief save a plugin into MENU_REF , calls insert_plugin or update_plugin if it already exists
+ * @return void
+ */
+ function save_plugin()
+ {
+ if ( $this->cn->get_value("select count(*) from menu_ref where me_code=$1",[$this->me_code]) > 0) {
+ $this->update_plugin();
+ } else {
+ $this->insert_plugin();
+
+ }
+ }
+ /**
+ * @brief Insert a plugin into the given profile, by default always insert into EXT
*
* @param type $p_id profile.p_id
* @throws Exception if duplicate or error db