16 require(dirname(__FILE__) .
'/bootstrap.inc.php');
25 parent::__construct(
$argv);
27 if (!
sizeof($this->argv)) {
39 echo
"Permanently removes user interests that are not referenced by any user accounts. USE WITH CARE.\n"
41 .
"\t{$this->scriptName} --show : Display user interests not referenced\n"
42 .
"\t{$this->scriptName} --remove : Permanently delete user interests not referenced\n";
51 if (!count($orphans)) {
52 echo
"No user interests to remove.\n";
56 $command = $this->parameters[0];
59 $interests = array_map(
function($entry) {
return $entry->getData(CONTROLLED_VOCAB_INTEREST); }, $orphans);
60 echo
"Below are the user interests that are not referenced by any user account.\n";
61 echo
"\t" . join($interests,
"\n\t") .
"\n";
66 foreach ($orphans as $orphanVocab) {
67 $vocabEntryDao->deleteObject($orphanVocab);
69 echo count($orphans) .
" entries deleted\n";
73 echo
"Invalid command.\n";
89 $interestVocab = $vocabDao->getBySymbolic(CONTROLLED_VOCAB_INTEREST);
90 $vocabEntryIterator = $vocabEntryDao->getByControlledVocabId($interestVocab->getId());
91 $vocabEntryList = $vocabEntryIterator->toArray();
94 $allInterestVocabIds = array_map(
96 return $entry->getId();
102 $interests = $interestDao->getAllInterests();
103 $userInterestVocabIds = array_map(
104 function($interest) {
105 return $interest->getId();
107 $interests->toArray()
111 $diff = array_diff($allInterestVocabIds, $userInterestVocabIds);
113 $orphans = array_filter(
115 function($entry) use($diff) {
116 return in_array($entry->getId(), $diff);