Skip to content

Instantly share code, notes, and snippets.

@sbreker
Last active November 2, 2018 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sbreker/373f0aa7a92e23d392d8c03b53d7a34d to your computer and use it in GitHub Desktop.
Save sbreker/373f0aa7a92e23d392d8c03b53d7a34d to your computer and use it in GitHub Desktop.
<?php
// VERSION: 0.11
// Delete actors that are not users or repos.
//
// This script can be used to DELETE authority records.
//
// There is a $dryRun variable - set this to 'True' if you want to test
// what the sript finds WITHOUT DELETING. It will output a list of slugs
// it would have deleted. 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
//
// Setting $dryRun to 'False' will cause the script to delete any Actors
// it finds.
//
// *WARNING - SCRIPT WILL DELETE DATA FROM ATOM* *MAKE BACKUPS FIRST!*
//
// Command: php symfony tools:run <full_path_to_this_file>
$dryRun = True;
$criteria = new Criteria;
$criteria->addJoin(QubitActor::ID, QubitObject::ID);
$criteria->addMultipleJoin(array(
array(QubitActorI18n::ID, QubitActor::ID),
array(QubitActor::SOURCE_CULTURE, QubitActorI18n::CULTURE)),
Criteria::LEFT_JOIN);
$criteria->addJoin(QubitSlug::OBJECT_ID, QubitObject::ID);
// Ensure the actors are not repos or users.
$criteria->add(QubitObject::CLASS_NAME, 'QubitActor');
// Ensure it is not the root object.
$criteria->add(QubitObject::ID, 1, Criteria::NOT_EQUAL);
$criteria->add(QubitObject::ID, QubitActor::ROOT_ID, Criteria::NOT_EQUAL);
// Add any additional criteria. If these are true, actor will be deleted.
// Field comparison will be done in the SOURCE_CULTURE language of the Actor.
// -- if the source_culture of an Actor is 'fr' then the French translation record will
// be used in the comparisons below.
// Delete Actors where authorized_form_of_name is NOT null (change ISNOTNULL to ISNULL
// if you want to re-run and catch actors that ALSO have a blank auth form of name).
$criteria->add(QubitActorI18n::AUTHORIZED_FORM_OF_NAME, null, Criteria::ISNOTNULL);
$criteria->add(QubitActorI18n::DATES_OF_EXISTENCE, null, Criteria::ISNULL);
$criteria->add(QubitActorI18n::HISTORY, null, Criteria::ISNULL);
// ...plus any more?
foreach (QubitObject::get($criteria) as $obj)
{
print("FOUND: " . $obj->slug . "\n");
if (!$dryRun)
{
print("DELETING: " . $obj->slug . "\n");
$obj->delete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment