Skip to content

Commit

Permalink
Add task to unprotect all terms
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-dna committed Nov 21, 2023
1 parent 6ed0d6f commit 331c043
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Tasks/UnprotectTaxonomyTerms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace DNADesign\Tagurit\Tasks;

use DNADesign\Tagurit\Model\TaxonomyTerm;
use SilverStripe\Dev\BuildTask;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Queries\SQLUpdate;

/**
* BuildTask to create the set of protected Types and Terms from config.
* The protected taxonomy is created on build, and missing records are recreated.
*/
class UnprotectTaxonomyTerms extends BuildTask
{
protected $title = '[Taxonomy] Un-protect Taxonomy Terms';

protected $description = "Set every Taxonomy Term as un-protected";

private static $segment = "unprotect-taxonomy-terms";

protected $enabled = true;

public function run($request)
{
$table = DataObject::getSchema()->tableForField(TaxonomyTerm::class, 'Protected');
if (!$table) {
exit('Could not locate DB table to update!');
}

$query = SQLUpdate::create($table, ['Protected' => false]);
$query->execute();

echo 'Done.';
}
}

0 comments on commit 331c043

Please sign in to comment.