#!/bin/bash
# Copyright (c) 1997-2009, NeoNova BV, The Netherlands. All rights Reserved.
#
# This software is the copyrighted work of NeoNova BV.
# Use of the software is subject to the general business terms and conditions of NeoNova BV
# and its related transaction documents like license sheets or other written notices.
#
# Any reproduction or redistribution of the software not in accordance with the license terms
# is expressly prohibited by law, and may result in severe civil and criminally penalties.
# Violators will be prosecuted to the maximum extent possible.
#
# remove conferences that are too old

# remove old records from the conference table
echo "update conference set status='deleted' where id > 1 and enddate < NOW()" | \
 psql -q -U astium

# set status of associated phonelines to 'deleted'
echo "update phoneline set status='deleted' from conference \
       where phoneline.function='conference' and phoneline.id=conference.phoneline and conference.status = 'deleted'" | \
 psql -q -U astium

# recreate all conference (meetme.conf) files, so expired conferences will really become unavailable
SOON=`echo "select NOW() + interval '2 minutes'" |  psql -t -U astium`
for company in `echo "select id from company where id > 2 and status <> 'deleted'" | psql -t -U astium`
do
  echo "insert into activate(action, type, which, status, created, process) values ('modify', 'company', '$company', 'QUEUED', NOW(), '$SOON')" | psql -q -U astium
done
