Last active
November 2, 2018 19:28
-
-
Save sbreker/54df1500d93a52de04a4513e9a5cdde5 to your computer and use it in GitHub Desktop.
Delete Authority records not referenced by an Information Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// VERSION: 0.10 | |
// Delete actors that are not users or repos and: | |
// - are not a name access point for any descriptons | |
// - are not linked via the events table - e.g. not a creator | |
// | |
// This script can be used to DELETE authority records. | |
// | |
// It will output a list of slugs that the script | |
// will delete. This is great for testing! The slug can be | |
// appended to your base URL to look at the Actor in question. e.g. | |
// http://10.10.10.10/rjpx-mzwk-pwls where the slug is rjpx-mzwk-pwls | |
// | |
// *WARNING - SCRIPT WILL DELETE DATA FROM ATOM* *MAKE BACKUPS FIRST!* | |
// | |
// Command: php symfony tools:run <full_path_to_this_file> | |
$verbose = True; | |
$actors = QubitActor::getOnlyActors(); | |
foreach ($actors as $actor) | |
{ | |
if ($actor->id == QubitActor::ROOT_ID) | |
{ | |
continue; | |
} | |
$eventRelations = $actor->getResourceRelations(); | |
$relations = getActorRelations($actor->id); | |
if (count($eventRelations) == 0 && count($relations) == 0) | |
{ | |
print("--------------\n"); | |
print("CAN DELETE: " . $actor->slug."\n"); | |
print("Events linked: " . count($eventRelations)."\n"); | |
print("Name acess points: " . count($relations)."\n"); | |
//$actor->delete(); | |
} | |
if ((count($eventRelations) > 0 || count($relations) > 0) && $verbose) | |
{ | |
print("--------------\n"); | |
print("KEEP: " . $actor->slug."\n"); | |
print("Events linked: " . count($eventRelations)."\n"); | |
print("Name acess points: " . count($relations)."\n"); | |
} | |
} | |
function getActorRelations($actorId) | |
{ | |
$criteria = new Criteria; | |
$criteria->addJoin(QubitRelation::TYPE_ID, QubitTerm::ID); | |
$criteria->add($criteria->getNewCriterion(QubitRelation::OBJECT_ID, $actorId) | |
->addAnd($criteria->getNewCriterion(QubitTerm::TAXONOMY_ID, QubitTaxonomy::RELATION_TYPE_ID)) | |
->addAnd($criteria->getNewCriterion(QubitTerm::ID, QubitTerm::NAME_ACCESS_POINT_ID))); | |
$criteria->addAscendingOrderByColumn(QubitRelation::TYPE_ID); | |
$criteria->addDescendingOrderByColumn(QubitRelation::START_DATE); | |
return QubitRelation::get($criteria); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment