#!/usr/bin/perl
#use Mooix::Thing;
run sub {
	my $this=shift;
	%_=@_;
	my $oldversion=$_{oldversion} || $this->croak("missing oldversion");
	
	if (33 > $oldversion) {
		# Everything moved into one list file; it should take
		# perms with the watermark file. The directory should not
		# be 775 anymore.
		open(LIST, ">>list") || die "open list: $!";
		foreach my $file (glob("item*")) {
			next unless -l $file;
			print LIST "mooix:".readlink($file)."\n";
			unlink $file;
		}
		close LIST;
		if (-e "watermark") {
			$mode = (stat("watermark"))[2] & 07777;
			chmod($mode, "list") || die "chmod list: $!";
		}
		# Set sticky bit.
		$mode = (stat("list"))[2] & 07777;
		chmod($mode | 01000, "list") || die "chmod list: $!";
		unlink("watermark");
		unlink("dir_ok");
		chmod(0755, $this->id);
	}

	if (35 > $oldverson && $this->defines("updatelisten")) {
		# There used to be an updatelisten field that made the
		# owners calclistening method be run. calclistening became
		# calcaware, and updatelisten is replaced with onchange.
		if ($this->updatelisten) {
			$this->onchange("calcaware");
		}
		unlink $this->fieldfile("updatelisten")
			|| die "unlink updatelisten: $!";
	}
	
	return $this->super(@_);
}
