#!/usr/bin/perl -w

# Remove the profile from user files.

use lib "../src";
use strict;
use Siikir;

my $cms = Siikir->new(
	debug => $ENV{X_SIIKIR_DEBUG} || 0,
	root  => "..",
);
$cms->loadPlugin("JsonDB");
$cms->loadPlugin("User");

print "Searching user accounts for the erroneous 'profile' key...\n\n";

my $users = $cms->User->listUsers();
foreach my $id (@{$users}) {
	print "Scan user: $id\n";
	my $acct = $cms->User->getAccount($id);

	if (exists $acct->{profile}) {
		print "\tHas profile: deleting it!\n";
		delete $acct->{profile};
		$cms->User->setAccount($id, $acct);
	}
}
