public function removeItemFromAllGroups($key)
{
// get our table name from the constructor
$tableName = $this->args[0];
// what are we doing?
$log = usingLog()->startAction("remove entry '{$key}' from all groups in {$tableName} table");
// get the table config
$tables = $this->getAllTables();
// make sure it exists
if (!isset($tables->{$tableName})) {
$msg = "table is empty / does not exist. '{$key}' not removed";
$log->endAction($msg);
return;
}
$groups = get_object_vars($tables->{$tableName});
if (!count($groups)) {
$msg = "table has no groups. '{$key}' not removed";
$log->endAction($msg);
return;
}
foreach ($tables->{$tableName} as $group => $contents) {
if (isset($tables->{$tableName}->{$group}->{$key})) {
// remove the entry
unset($tables->{$tableName}->{$group}->{$key});
// remove the table if it's empty
if (!count(get_object_vars($tables->{$tableName}->{$group}))) {
$log->addStep("table group '{$tableName}->{$group}' is empty, removing from runtime config", function () use($tables, $tableName, $group) {
unset($tables->{$tableName}->{$group});
});
}
}
}
// save the changes
$this->st->saveRuntimeConfig();
// all done
$log->endAction();
}