Only save recordings for sale dispositions.

Discussions about new features or changes in existing features

Moderators: gerski, enjay, williamconley, Op3r, Staydog, gardo, mflorell, MJCoate, mcargile, Kumba, Michael_N

Only save recordings for sale dispositions.

Postby iratik » Thu May 13, 2010 2:02 pm

This script will kill all recordings made over 1.5 hours ago that are not in sale disposition categories. It uses our in-house DB library. The script will not work on a normal install unless you reimplement the DB connectivity to use vicidial's native dbconnect. It would not be difficult to modify to use vicidial's dbconnect style of connecting to the database. I run this script on a cron job every hour. I have set our mp3/mixing cron scripts to run between shift and at the end of the night. The only files they process end up being sales because this script has removed non-sale recordings before the mixing scripts get to the monitor directories. This script is also dependent on the default naming convention for recordings.


Code: Select all
<?php
/*
     Find all calls made today more than 1.5 hours ago which are
     not in the sale category. Remove them from recording_log and delete the files *all,*in and *out.
*/
require "/srv/www/htdocs/ctallc/shared/dbutil/dbutil.php";
$db=new DB();
$ql="SELECT l.phone_number FROM ";
$ql.=" vicidial_log l join vicidial_campaign_statuses vcs  ";
$ql.="   on vcs.status=l.status and vcs.campaign_id=l.campaign_id ";
$ql.=" WHERE l.call_date<(now()-interval 1.5 hour) ";
$ql.=" and to_days(l.call_date)=to_days(now()) ";
$ql.=" and vcs.sale='N' ";
$records=$db->Query($ql);
$disposable_numbers=array();
foreach ($records as $record) {
        $disposable_numbers[]=$record['phone_number'];
}
$cutoff=strftime('%Y%m%d%H%M%S',strtotime('-1.5 hour'));
foreach (glob("/var/spool/asterisk/monitor/*in.wav") as $filename) {
        $basename=basename($filename);
        list($date,$phone_ext)=explode("_",$basename); 
        $phone=str_replace("-in.wav","",$phone_ext);
        $db_filename=$date."_".$phone;
        $date=preg_replace("/[^0-9]/","",$date);
        if ($date<$cutoff) {
                if (array_search($phone,$disposable_numbers)!==false) {
                        $ql="DELETE FROM recording_log ";
                        $ql.=" WHERE filename='#filename' ";
                        $db->Command($ql,array(
                                '#filename'=>$db->filename
                        ));
                        unlink($filename);
                        unlink(str_replace("in","out",$filename));
                        unlink(str_replace("in","all",$filename));
                }
        }       
}
?>
iratik
 
Posts: 26
Joined: Tue Dec 09, 2008 4:43 pm

Postby mflorell » Thu May 13, 2010 5:46 pm

Please post this to the issue tracker.
mflorell
Site Admin
 
Posts: 18335
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida


Return to Features

Who is online

Users browsing this forum: No registered users and 33 guests

cron