@@ -971,14 +971,22 @@ public function pre_deleteItem()
971971
972972 public static function preItemPurge ($ item )
973973 {
974+ /** @var DBmysql $DB */
975+ global $ DB ;
976+
974977 $ itemtype = $ item ::class;
975978 $ containers = new self ();
976- $ founded_containers = $ containers ->find ([ ' is_active ' => 1 ] );
979+ $ founded_containers = $ containers ->find ();
977980 foreach ($ founded_containers as $ container ) {
978981 $ itemtypes = PluginFieldsToolbox ::decodeJSONItemtypes ($ container ['itemtypes ' ]);
979982 if (in_array ($ itemtype , $ itemtypes )) {
980983 $ classname = self ::getClassname ($ itemtype , $ container ['name ' ]);
981- $ fields = new $ classname ();
984+ if (!$ DB ->tableExists ($ classname ::getTable ())) {
985+ // Disabled oversized container: no table to purge from.
986+ continue ;
987+ }
988+
989+ $ fields = new $ classname ();
982990 $ fields ->deleteByCriteria (['items_id ' => $ item ->fields ['id ' ]], true );
983991 }
984992 }
@@ -1074,7 +1082,19 @@ public static function renameOversizedContainer(int $id, string $new_name): bool
10741082
10751083 $ migration = new Migration ((string ) ($ plugin ->fields ['version ' ] ?? '' ));
10761084
1077- $ old_name = $ container ->fields ['name ' ];
1085+ $ old_name = $ container ->fields ['name ' ];
1086+
1087+ foreach ($ itemtypes as $ itemtype ) {
1088+ $ new_table = getTableForItemType (self ::getClassname ($ itemtype , $ new_name ));
1089+ $ old_table = getTableForItemType (self ::getClassname ($ itemtype , $ old_name ));
1090+
1091+ if ($ new_table !== $ old_table && $ DB ->tableExists ($ new_table )) {
1092+ Session ::AddMessageAfterRedirect (sprintf (__ ('Table %s already exists. ' , 'fields ' ), $ new_table ), false , ERROR );
1093+
1094+ return false ;
1095+ }
1096+ }
1097+
10781098 $ claimed_orphans = [];
10791099 $ data_preserved = false ;
10801100 foreach ($ itemtypes as $ itemtype ) {
0 commit comments