collectiveaccess / providence

Cataloguing and data/media management application
GNU General Public License v3.0
290 stars 166 forks source link

purge-deleted Only Deletes Some Records and Not Others #1524

Open miqrogroove opened 6 months ago

miqrogroove commented 6 months ago

I'm getting this same output everytime I run caUtils purge-deleted:

CollectiveAccess 1.7.15 (158/RELEASE) Utilities
(c) 2013-2019 Whirl-i-Gig

Removing deleted representations from database               100.0% 52/52 ETC: < 1 sec. Elapsed: 2 secs 

Done!

Those 52 representations and their associated media files aren't going away.

kehh commented 6 months ago

We've seen this before where there are foreign keys preventing this deletion. Take a look in the database to see if there's anywhere those representations are being used (either a parent representation or maybe one of the ca_{tablename}_x_object_representations). Do a query to find out what the id's of the deleted representations are. (SELECT representation_id FROM ca_object_representations WHERE deleted).

miqrogroove commented 6 months ago

@kehh Does that imply my object representations can't be deleted unless the object is also deleted? That would be... highly inconvenient.

Foreign key constraints are a likely issue. I've traced the silent failure as far as

https://github.com/collectiveaccess/providence/blob/d06f5b1fb6ef3df64b480a2fb1344d44cccb0674/app/lib/BaseModel.php#L3493

And I was going to try to pull the codes next.

miqrogroove commented 6 months ago
     'opn_error_number' => 250,
     'ops_error_description' => 'Invalid relationship reference for representation_id',
     'ops_error_context' => 'Db->mysqli->execute()',
miqrogroove commented 6 months ago

Here's the same query sent straight to the mysql client:

mysql> DELETE FROM ca_object_representations WHERE representation_id = 5773;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`providence`.`ca_download_log`, CONSTRAINT `fk_ca_download_log_representation_id` FOREIGN KEY (`representation_id`) REFERENCES `ca_object_representations` (`representation_id`) ON DELETE RESTR)
miqrogroove commented 6 months ago

Good lord. So now I can't delete anything that has ever been downloaded? Is there no code to handle this?

collectiveaccess commented 6 months ago

Purge the download log and delete whatever you want. Please keep in mind this is software for archival usage. For most users permanently deleting things is not desirable, especially if those things been interacted with (eg. downloaded).

miqrogroove commented 6 months ago

Got it but gee whiz. I'm trying to replace some representations and occasionally things get uploaded in error. Is this not a bug where I have to truncate a table to get the caUtils purge command to work as expected?