@@ -213,6 +213,11 @@ public static function installBaseData(Migration $migration, $version)
213213 self ::generateTemplate ($ container );
214214 foreach (json_decode ((string ) $ container ['itemtypes ' ]) as $ itemtype ) {
215215 $ classname = self ::getClassname ($ itemtype , $ container ["name " ]);
216+ // prevent usage of plugin class if not loaded
217+ if (!class_exists ($ classname )) {
218+ continue ;
219+ }
220+
216221 $ old_table = $ classname ::getTable ();
217222 // Rename genericobject container table
218223 if (
@@ -741,8 +746,10 @@ public static function create($fields)
741746
742747 foreach (PluginFieldsToolbox::decodeJSONItemtypes ($ fields ['itemtypes ' ]) as $ itemtype ) {
743748 //install table for receive field
744- $ classname = self ::getClassname ($ itemtype , $ fields ['name ' ]);
745- $ classname ::install ();
749+ if (class_exists ($ itemtype )) {
750+ $ classname = self ::getClassname ($ itemtype , $ fields ['name ' ]);
751+ $ classname ::install ();
752+ }
746753 }
747754
748755 return null ;
@@ -754,20 +761,31 @@ public static function generateTemplate($fields)
754761 ? PluginFieldsToolbox::decodeJSONItemtypes ($ fields ['itemtypes ' ], true )
755762 : [];
756763 foreach ($ itemtypes as $ itemtype ) {
764+
765+ $ sysname = self ::getSystemName ($ itemtype , $ fields ['name ' ]);
766+ $ classname = self ::getClassname ($ itemtype , $ fields ['name ' ]);
767+ $ class_filename = $ sysname . '.class.php ' ;
768+ $ injection_filename = $ sysname . 'injection.class.php ' ;
769+
757770 // prevent usage of plugin class if not loaded
758771 if (!class_exists ($ itemtype )) {
772+ //remove file
773+ if (file_exists (PLUGINFIELDS_CLASS_PATH . ('/ ' . $ class_filename ))) {
774+ unlink (PLUGINFIELDS_CLASS_PATH . ('/ ' . $ class_filename ));
775+ }
776+
777+ if (file_exists (PLUGINFIELDS_CLASS_PATH . ('/ ' . $ injection_filename ))) {
778+ unlink (PLUGINFIELDS_CLASS_PATH . ('/ ' . $ injection_filename ));
779+ }
780+
759781 continue ;
760782 }
761783
762- $ sysname = self ::getSystemName ($ itemtype , $ fields ['name ' ]);
763- $ classname = self ::getClassname ($ itemtype , $ fields ['name ' ]);
764-
765784 $ template_class = file_get_contents (PLUGINFIELDS_DIR . '/templates/container.class.tpl ' );
766785 $ template_class = str_replace ('%%CLASSNAME%% ' , $ classname , $ template_class );
767786 $ template_class = str_replace ('%%ITEMTYPE%% ' , $ itemtype , $ template_class );
768787 $ template_class = str_replace ('%%CONTAINER%% ' , $ fields ['id ' ], $ template_class );
769788 $ template_class = str_replace ('%%ITEMTYPE_RIGHT%% ' , $ itemtype ::$ rightname , $ template_class );
770- $ class_filename = $ sysname . '.class.php ' ;
771789 if (file_put_contents (PLUGINFIELDS_CLASS_PATH . ('/ ' . $ class_filename ), $ template_class ) === false ) {
772790 Toolbox::logDebug ('Error : class file creation - ' . $ class_filename );
773791
@@ -780,9 +798,8 @@ public static function generateTemplate($fields)
780798 $ template_class = str_replace ('%%ITEMTYPE%% ' , $ itemtype , $ template_class );
781799 $ template_class = str_replace ('%%CONTAINER_ID%% ' , $ fields ['id ' ], $ template_class );
782800 $ template_class = str_replace ('%%CONTAINER_NAME%% ' , $ fields ['label ' ], $ template_class );
783- $ class_filename = $ sysname . 'injection.class.php ' ;
784- if (file_put_contents (PLUGINFIELDS_CLASS_PATH . ('/ ' . $ class_filename ), $ template_class ) === false ) {
785- Toolbox::logDebug ('Error : datainjection class file creation - ' . $ class_filename );
801+ if (file_put_contents (PLUGINFIELDS_CLASS_PATH . ('/ ' . $ injection_filename ), $ template_class ) === false ) {
802+ Toolbox::logDebug ('Error : datainjection class file creation - ' . $ injection_filename );
786803
787804 return false ;
788805 }
0 commit comments