xPapers/xPapers — Issue #2: deleting a category causes "Can't call method "eun" without a package or object reference at /home/xpapers/assets/mason/menu/user.html line 17."
Author: fws-hub
Created: 2011-10-13 14:09:57+00:00
State: open

If one user deletes a category and another user has set that category as on of there areas they will receive the following error upon logging in:

System error
error:	Can't call method "eun" without a package or object reference at /home/xpapers/assets/mason/menu/user.html line 17.
context:
...
13:	}
14:	my @areas = $user->areas_o;
15:	if ($#areas > -1) {
16:	print "
{id}/areas.html\">My areas

";
17:	print join("",
18:	map { sprintf "
%s
", $_->eun,$_->name } @areas
19:	);
20:	print "

";
21:	}
...
code stack:	/home/xpapers/assets/mason/menu/user.html:17
/home/xpapers/assets/mason/menu/menu.html:29
/home/xpapers/sites/fwshub/mason/header.html:14
/home/xpapers/assets/mason/bbs/newmsg.pl:182
/home/xpapers/assets/mason/autohandler:481

This is caused because there is no foreign key constraint between the cats and areas_m table in the database. So when the category is deleted no cascade delete can take place to remove that category from the areas_m table (the link table between the user and category).

A simple workaround is to manually edit the areas_m table and remove any entry who's aid field refers to a non-existent category. Once this is done the database cache must be flushed by running $XPAPERS/bin/dev/flush_cache.pl.

Ideally there should be a foreign key constraint added between the cats and areas_m table. There are also many many other foreign key relations missing in the database which have the potential to cause similar problems with other tables.