Changeset 6158

Show
Ignore:
Timestamp:
07/23/08 19:12:17 (4 months ago)
Author:
p_lindheimer
Message:

#2065 Migrate recordings to recording ids

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.5/findmefollow/functions.inc.php

    r6026 r6158  
    4646                                        $postdest = $grp['postdest']; 
    4747                                        $grppre = (isset($grp['grppre'])?$grp['grppre']:''); 
    48                                         $annmsg = $grp['annmsg']; 
     48                                        $annmsg_id = $grp['annmsg_id']; 
    4949                                        $dring = $grp['dring']; 
    5050 
    5151                                        $needsconf = $grp['needsconf']; 
    52                                         $remotealert = $grp['remotealert']; 
    53                                         $toolate = $grp['toolate']; 
     52                                        $remotealert_id = $grp['remotealert_id']; 
     53                                        $toolate_id = $grp['toolate_id']; 
    5454                                        $ringing = $grp['ringing']; 
    5555                                        $pre_ring = $grp['pre_ring']; 
     
    129129                                        $ext->add($contextname, $grpnum, '', new ext_setvar('RingGroupMethod',$strategy)); 
    130130                                        $ext->add($contextname, $grpnum, '', new ext_setvar('_FMGRP',$grpnum)); 
    131                                         if ((isset($annmsg) ? $annmsg : '') != '') { 
     131                                        if ((isset($annmsg_id) ? $annmsg_id : '')) { 
     132                                                $annmsg = recordings_get_file($annmsg_id); 
    132133                                                // should always answer before playing anything, shouldn't we ? 
    133134                                                $ext->add($contextname, $grpnum, '', new ext_gotoif('$[$["${DIALSTATUS}" = "ANSWER"] | $["foo${RRNODEST}" != "foo"]]','DIALGRP'));                       
     
    139140                                        // Create the confirm target 
    140141                                        $len=strlen($grpnum)+4; 
     142                                        $remotealert = recordings_get_file($remotealert_id); 
     143                                        $toolate = recordings_get_file($toolate_id); 
    141144                                        $ext->add("fmgrps", "_RG-${grpnum}-.", '', new ext_macro('dial','${DB(AMPUSER/'."$grpnum/followme/grptime)},". 
    142145                                                "M(confirm^${remotealert}^${toolate}^${grpnum})$dialopts".',${EXTEN:'.$len.'}')); 
     
    184187} 
    185188 
    186 function findmefollow_add($grpnum,$strategy,$grptime,$grplist,$postdest,$grppre='',$annmsg='',$dring,$needsconf,$remotealert,$toolate,$ringing,$pre_ring,$ddial) { 
     189function findmefollow_add($grpnum,$strategy,$grptime,$grplist,$postdest,$grppre='',$annmsg_id='',$dring,$needsconf,$remotealert_id,$toolate_id,$ringing,$pre_ring,$ddial) { 
    187190        global $amp_conf; 
    188191        global $astman; 
    189192 
    190         $sql = "INSERT INTO findmefollow (grpnum, strategy, grptime, grppre, grplist, annmsg, postdest, dring, needsconf, remotealert, toolate, ringing, pre_ring) VALUES ('".str_replace("'", "''",$grpnum)."', '".str_replace("'", "''", $strategy)."', ".str_replace("'", "''", $grptime).", '".str_replace("'", "''", $grppre)."', '".str_replace("'", "''", $grplist)."', '".str_replace("'", "''", $annmsg)."', '".str_replace("'", "''", $postdest)."', '".str_replace("'", "''", $dring)."', '$needsconf', '$remotealert', '$toolate', '$ringing', '$pre_ring')"; 
     193        $sql = "INSERT INTO findmefollow (grpnum, strategy, grptime, grppre, grplist, annmsg_id, postdest, dring, needsconf, remotealert_id, toolate_id, ringing, pre_ring) VALUES ('".str_replace("'", "''",$grpnum)."', '".str_replace("'", "''", $strategy)."', ".str_replace("'", "''", $grptime).", '".str_replace("'", "''", $grppre)."', '".str_replace("'", "''", $grplist)."', '".str_replace("'", "''", $annmsg_id)."', '".str_replace("'", "''", $postdest)."', '".str_replace("'", "''", $dring)."', '$needsconf', '$remotealert_id', '$toolate_id', '$ringing', '$pre_ring')"; 
    191194        $results = sql($sql); 
    192195 
     
    293296        global $astman; 
    294297 
    295         $results = sql("SELECT grpnum, strategy, grptime, grppre, grplist, annmsg, postdest, dring, needsconf, remotealert, toolate, ringing, pre_ring FROM findmefollow WHERE grpnum = '".str_replace("'", "''", $grpnum)."'","getRow",DB_FETCHMODE_ASSOC); 
     298        $results = sql("SELECT grpnum, strategy, grptime, grppre, grplist, annmsg_id, postdest, dring, needsconf, remotealert_id, toolate_id, ringing, pre_ring FROM findmefollow WHERE grpnum = '".str_replace("'", "''", $grpnum)."'","getRow",DB_FETCHMODE_ASSOC); 
    296299 
    297300        if ($check_astdb) { 
     
    417420} 
    418421 
     422function findmefollow_recordings_usage($recording_id) { 
     423        global $active_modules; 
     424 
     425        $results = sql("SELECT `grpnum` FROM `findmefollow` WHERE `annmsg_id` = '$recording_id' OR `remotealert_id` = '$recording_id' OR `toolate_id` = '$recording_id'","getAll",DB_FETCHMODE_ASSOC); 
     426        if (empty($results)) { 
     427                return array(); 
     428        } else { 
     429                //$type = isset($active_modules['ivr']['type'])?$active_modules['ivr']['type']:'setup'; 
     430                foreach ($results as $result) { 
     431                        $usage_arr[] = array( 
     432                                'url_query' => 'config.php?display=findmefollow&extdisplay=GRP-'.urlencode($result['grpnum']), 
     433                                'description' => "Follow-Me User: ".$result['grpnum'], 
     434                        ); 
     435                } 
     436                return $usage_arr; 
     437        } 
     438} 
     439 
    419440function findmefollow_fmf_toggle($c) { 
    420441        global $ext; 
  • modules/branches/2.5/findmefollow/install.php

    r5864 r6158  
    22 
    33global $db; 
     4global $amp_conf; 
     5global $astman; 
     6 
     7if (! function_exists("out")) { 
     8        function out($text) { 
     9                echo $text."<br />"; 
     10        } 
     11} 
     12 
     13if (! function_exists("outn")) { 
     14        function outn($text) { 
     15                echo $text; 
     16        } 
     17} 
     18 
     19$sql = " 
     20CREATE TABLE IF NOT EXISTS `findmefollow`  
     21(  
     22        `grpnum` VARCHAR( 20 ) NOT NULL ,  
     23        `strategy` VARCHAR( 50 ) NOT NULL ,  
     24        `grptime` SMALLINT NOT NULL ,  
     25        `grppre` VARCHAR( 100 ) NULL ,  
     26        `grplist` VARCHAR( 255 ) NOT NULL ,  
     27        `annmsg_id` INTEGER, 
     28        `postdest` VARCHAR( 255 ) NULL ,  
     29        `dring` VARCHAR ( 255 ) NULL ,  
     30        `remotealert_id` INTEGER, 
     31        `needsconf` VARCHAR ( 10 ),  
     32        `toolate_id` INTEGER, 
     33        `pre_ring` SMALLINT NOT NULL DEFAULT 0,  
     34        PRIMARY KEY  (`grpnum`)  
     35) 
     36"; 
     37$check = $db->query($sql); 
     38if(DB::IsError($check)) { 
     39        die_freepbx("Can not create annoucment table"); 
     40} 
    441 
    542//TODO: Also need to create all the states if enabled 
     
    2057    if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } 
    2158} 
    22 // Version 2.0 upgrade. Yeah. 2.0 baby!  
    23 $sql = "SELECT remotealert FROM findmefollow"; 
     59// If there is no needsconf then this is a really old upgrade. We create the 2 old fields 
     60// here  and then the migration code below will change them as needed but will work properly 
     61// since it now has the fields it is expecting 
     62// 
     63$sql = "SELECT needsconf FROM findmefollow"; 
    2464$check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
    2565if(DB::IsError($check)) { 
     
    75115// is this global...? what if we include this files 
    76116// from a function...? 
    77 global $astman; 
    78 global $amp_conf; 
    79117 
    80118$sql = "SELECT * FROM findmefollow"; 
     
    107145} 
    108146 
     147// Version 2.5 migrate to recording ids 
     148// 
     149outn(_("Checking if recordings need migration..")); 
     150$sql = "SELECT annmsg_id FROM findmefollow"; 
     151$check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
     152if(DB::IsError($check)) { 
     153        //  Add recording_id field 
     154        // 
     155        out("migrating"); 
     156        outn(_("adding annmsg_id field..")); 
     157  $sql = "ALTER TABLE findmefollow ADD annmsg_id INTEGER"; 
     158  $result = $db->query($sql); 
     159  if(DB::IsError($result)) { 
     160                out(_("fatal error")); 
     161                die_freepbx($result->getDebugInfo());  
     162        } else { 
     163                out(_("ok")); 
     164        } 
     165        outn(_("adding remotealert_id field..")); 
     166  $sql = "ALTER TABLE findmefollow ADD remotealert_id INTEGER"; 
     167  $result = $db->query($sql); 
     168  if(DB::IsError($result)) { 
     169                out(_("fatal error")); 
     170                die_freepbx($result->getDebugInfo());  
     171        } else { 
     172                out(_("ok")); 
     173        } 
     174        outn(_("adding toolate_id field..")); 
     175  $sql = "ALTER TABLE findmefollow ADD toolate_id INTEGER"; 
     176  $result = $db->query($sql); 
     177  if(DB::IsError($result)) { 
     178                out(_("fatal error")); 
     179                die_freepbx($result->getDebugInfo());  
     180        } else { 
     181                out(_("ok")); 
     182        } 
     183 
     184        // Get all the valudes and replace them with recording_id 
     185        // 
     186        outn(_("migrate annmsg to ids..")); 
     187  $sql = "SELECT `grpnum`, `annmsg` FROM `findmefollow`"; 
     188        $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     189        if(DB::IsError($results)) { 
     190                out(_("fatal error")); 
     191                die_freepbx($results->getDebugInfo());   
     192        } 
     193        $migrate_arr = array(); 
     194        $count = 0; 
     195        foreach ($results as $row) { 
     196                if (trim($row['annmsg']) != '') { 
     197                        $rec_id = recordings_get_or_create_id($row['annmsg'], 'findmefollow'); 
     198                        $migrate_arr[] = array($rec_id, $row['grpnum']); 
     199                        $count++; 
     200                } 
     201        } 
     202        if ($count) { 
     203                $compiled = $db->prepare('UPDATE `findmefollow` SET `annmsg_id` = ? WHERE `grpnum` = ?'); 
     204                $result = $db->executeMultiple($compiled,$migrate_arr); 
     205                if(DB::IsError($result)) { 
     206                        out(_("fatal error")); 
     207                        die_freepbx($result->getDebugInfo());    
     208                } 
     209        } 
     210        out(sprintf(_("migrated %s entries"),$count)); 
     211 
     212        outn(_("migrate remotealert to ids..")); 
     213  $sql = "SELECT `grpnum`, `remotealert` FROM `findmefollow`"; 
     214        $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     215        if(DB::IsError($results)) { 
     216                out(_("fatal error")); 
     217                die_freepbx($results->getDebugInfo());   
     218        } 
     219        $migrate_arr = array(); 
     220        $count = 0; 
     221        foreach ($results as $row) { 
     222                if (trim($row['remotealert']) != '') { 
     223                        $rec_id = recordings_get_or_create_id($row['remotealert'], 'findmefollow'); 
     224                        $migrate_arr[] = array($rec_id, $row['grpnum']); 
     225                        $count++; 
     226                } 
     227        } 
     228        if ($count) { 
     229                $compiled = $db->prepare('UPDATE `findmefollow` SET `remotealert_id` = ? WHERE `grpnum` = ?'); 
     230                $result = $db->executeMultiple($compiled,$migrate_arr); 
     231                if(DB::IsError($result)) { 
     232                        out(_("fatal error")); 
     233                        die_freepbx($result->getDebugInfo());    
     234                } 
     235        } 
     236        out(sprintf(_("migrated %s entries"),$count)); 
     237 
     238        outn(_("migrate toolate to  ids..")); 
     239  $sql = "SELECT `grpnum`, `toolate` FROM `findmefollow`"; 
     240        $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     241        if(DB::IsError($results)) { 
     242                out(_("fatal error")); 
     243                die_freepbx($results->getDebugInfo());   
     244        } 
     245        $migrate_arr = array(); 
     246        $count = 0; 
     247        foreach ($results as $row) { 
     248                if (trim($row['toolate']) != '') { 
     249                        $rec_id = recordings_get_or_create_id($row['toolate'], 'findmefollow'); 
     250                        $migrate_arr[] = array($rec_id, $row['grpnum']); 
     251                        $count++; 
     252                } 
     253        } 
     254        if ($count) { 
     255                $compiled = $db->prepare('UPDATE `findmefollow` SET `toolate_id` = ? WHERE `grpnum` = ?'); 
     256                $result = $db->executeMultiple($compiled,$migrate_arr); 
     257                if(DB::IsError($result)) { 
     258                        out(_("fatal error")); 
     259                        die_freepbx($result->getDebugInfo());    
     260                } 
     261        } 
     262        out(sprintf(_("migrated %s entries"),$count)); 
     263 
     264        // Now remove the old recording field replaced by new id field 
     265        // 
     266        outn(_("dropping annmsg field..")); 
     267  $sql = "ALTER TABLE `findmefollow` DROP `annmsg`"; 
     268  $result = $db->query($sql); 
     269  if(DB::IsError($result)) {  
     270                out(_("no annmsg field???")); 
     271        } else { 
     272                out(_("ok")); 
     273        } 
     274        outn(_("dropping remotealert field..")); 
     275  $sql = "ALTER TABLE `findmefollow` DROP `remotealert`"; 
     276  $result = $db->query($sql); 
     277  if(DB::IsError($result)) {  
     278                out(_("no remotealert field???")); 
     279        } else { 
     280                out(_("ok")); 
     281        } 
     282        outn(_("dropping toolate field..")); 
     283  $sql = "ALTER TABLE `findmefollow` DROP `toolate`"; 
     284  $result = $db->query($sql); 
     285  if(DB::IsError($result)) {  
     286                out(_("no toolate field???")); 
     287        } else { 
     288                out(_("ok")); 
     289        } 
     290 
     291} else { 
     292        out("already migrated"); 
     293} 
     294 
    109295?> 
  • modules/branches/2.5/findmefollow/module.xml

    r6083 r6158  
    22        <rawname>findmefollow</rawname> 
    33        <name>Follow Me</name> 
    4         <version>2.5.0.1</version> 
     4        <version>2.5.1</version> 
    55        <changelog> 
     6                *2.5.1* #2065 Migrate recordings to recording ids 
    67                *2.5.0.1* #2391, #2908, #2845, #1791, added delete and add icons 
    78                *2.5.0* Add enable/disable featurecode with blf support, new confirmation sound file announces cid availability 
     
    4243        <depends> 
    4344                <version>2.5.0alpha1</version> 
     45                <module>recordings ge 3.3.8</module> 
    4446        </depends> 
    4547        <type>setup</type> 
  • modules/branches/2.5/findmefollow/page.findmefollow.php

    r5972 r6158  
    2323isset($_REQUEST['grppre'])?$grppre = $_REQUEST['grppre']:$grppre=''; 
    2424isset($_REQUEST['strategy'])?$strategy = $_REQUEST['strategy']:$strategy=''; 
    25 isset($_REQUEST['annmsg'])?$annmsg = $_REQUEST['annmsg']:$annmsg=''; 
     25isset($_REQUEST['annmsg_id'])?$annmsg_id = $_REQUEST['annmsg_id']:$annmsg_id=''; 
    2626isset($_REQUEST['dring'])?$dring = $_REQUEST['dring']:$dring=''; 
    2727isset($_REQUEST['needsconf'])?$needsconf = $_REQUEST['needsconf']:$needsconf=''; 
    28 isset($_REQUEST['remotealert'])?$remotealert = $_REQUEST['remotealert']:$remotealert=''; 
    29 isset($_REQUEST['toolate'])?$toolate = $_REQUEST['toolate']:$toolate=''; 
     28isset($_REQUEST['remotealert_id'])?$remotealert_id = $_REQUEST['remotealert_id']:$remotealert_id=''; 
     29isset($_REQUEST['toolate_id'])?$toolate_id = $_REQUEST['toolate_id']:$toolate_id=''; 
    3030isset($_REQUEST['ringing'])?$ringing = $_REQUEST['ringing']:$ringing=''; 
    3131isset($_REQUEST['pre_ring'])?$pre_ring = $_REQUEST['pre_ring']:$pre_ring='0'; 
     
    7373                //add group 
    7474                if ($action == 'addGRP') { 
    75                         findmefollow_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$grppre,$annmsg,$dring,$needsconf,$remotealert,$toolate,$ringing,$pre_ring,$ddial); 
     75                        findmefollow_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$grppre,$annmsg_id,$dring,$needsconf,$remotealert_id,$toolate_id,$ringing,$pre_ring,$ddial); 
    7676 
    7777                        needreload(); 
     
    8989                if ($action == 'edtGRP') { 
    9090                        findmefollow_del($account);      
    91                         findmefollow_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$grppre,$annmsg,$dring,$needsconf,$remotealert,$toolate,$ringing,$pre_ring,$ddial); 
     91                        findmefollow_add($account,$strategy,$grptime,implode("-",$grplist),$goto,$grppre,$annmsg_id,$dring,$needsconf,$remotealert_id,$toolate_id,$ringing,$pre_ring,$ddial); 
    9292 
    9393                        needreload(); 
     
    134134                $grptime     = isset($thisgrp['grptime'])     ? $thisgrp['grptime']     : ''; 
    135135                $goto        = isset($thisgrp['postdest'])    ? $thisgrp['postdest']    : ''; 
    136                 $annmsg      = isset($thisgrp['annmsg'])      ? $thisgrp['annmsg']      : ''; 
     136                $annmsg_id      = isset($thisgrp['annmsg_id'])      ? $thisgrp['annmsg_id']      : ''; 
    137137                $dring       = isset($thisgrp['dring'])       ? $thisgrp['dring']       : ''; 
    138                 $remotealert = isset($thisgrp['remotealert']) ? $thisgrp['remotealert'] : ''; 
     138                $remotealert_id = isset($thisgrp['remotealert_id']) ? $thisgrp['remotealert_id'] : ''; 
    139139                $needsconf   = isset($thisgrp['needsconf'])   ? $thisgrp['needsconf']   : ''; 
    140                 $toolate     = isset($thisgrp['toolate'])     ? $thisgrp['toolate']     : ''; 
     140                $toolate_id     = isset($thisgrp['toolate_id'])     ? $thisgrp['toolate_id']     : ''; 
    141141                $ringing     = isset($thisgrp['ringing'])     ? $thisgrp['ringing']     : ''; 
    142142                $pre_ring    = isset($thisgrp['pre_ring'])    ? $thisgrp['pre_ring']    : ''; 
     
    288288                                <td><a href="#" class="info"><?php echo _("Announcement:")?><span><?php echo _("Message to be played to the caller before dialing this group.<br><br>To add additional recordings please use the \"System Recordings\" MENU to the left")?></span></a></td> 
    289289                                <td> 
    290                                         <select name="annmsg" tabindex="<?php echo ++$tabindex;?>"> 
     290                                        <select name="annmsg_id" tabindex="<?php echo ++$tabindex;?>"> 
    291291                                        <?php 
    292292                                                $tresults = recordings_list(); 
    293                                                 $default = (isset($annmsg) ? $annmsg : ''); 
     293                                                $default = (isset($annmsg_id) ? $annmsg_id : ''); 
    294294                                                echo '<option value="">'._("None"); 
    295295                                                if (isset($tresults)) { 
    296296                                                        foreach ($tresults as $tresult) { 
    297                                                                 echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]
     297                                                                echo '<option value="'.$tresult['id'].'"'.($tresult['id'] == $default ? ' SELECTED' : '').'>'.$tresult['displayname']."</option>\n"
    298298                                                        } 
    299299                                                } 
     
    307307                                <td> 
    308308                                        <?php 
    309                                                 $default = (isset($annmsg) ? $annmsg : ''); 
     309                                                $default = (isset($annmsg_id) ? $annmsg_id : ''); 
    310310                                        ?> 
    311                                         <input type="hidden" name="annmsg" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?> 
     311                                        <input type="hidden" name="annmsg_id" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?> 
    312312                                </td> 
    313313                        </tr> 
     
    354354                                <td><a href="#" class="info"><?php echo _("Remote Announce:")?><span><?php echo _("Message to be played to the person RECEIVING the call, if 'Confirm Calls' is enabled.<br><br>To add additional recordings use the \"System Recordings\" MENU to the left")?></span></a></td> 
    355355                                <td> 
    356                                         <select name="remotealert" tabindex="<?php echo ++$tabindex;?>"> 
     356                                        <select name="remotealert_id" tabindex="<?php echo ++$tabindex;?>"> 
    357357                                        <?php 
    358358                                                $tresults = recordings_list(); 
    359                                                 $default = (isset($remotealert) ? $remotealert : ''); 
     359                                                $default = (isset($remotealert_id) ? $remotealert_id : ''); 
    360360                                                echo '<option value="">'._("Default")."</option>"; 
    361361                                                if (isset($tresults[0])) { 
    362362                                                        foreach ($tresults as $tresult) { 
    363                                                                 echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n"; 
     363                                                                echo '<option value="'.$tresult['id'].'"'.($tresult['id'] == $default ? ' SELECTED' : '').'>'.$tresult['displayname']."</option>\n"; 
    364364                                                        } 
    365365                                                } 
     
    371371                                <td><a href="#" class="info"><?php echo _("Too-Late Announce:")?><span><?php echo _("Message to be played to the person RECEIVING the call, if the call has already been accepted before they push 1.<br><br>To add additional recordings use the \"System Recordings\" MENU to the left")?></span></a></td> 
    372372                                <td> 
    373                                 <select name="toolate" tabindex="<?php echo ++$tabindex;?>"> 
     373                                <select name="toolate_id" tabindex="<?php echo ++$tabindex;?>"> 
    374374                                        <?php 
    375375                                                $tresults = recordings_list(); 
    376                                                 $default = (isset($toolate) ? $toolate : ''); 
     376                                                $default = (isset($toolate_id) ? $toolate_id : ''); 
    377377                                                echo '<option value="">'._("Default")."</option>"; 
    378378                                                if (isset($tresults[0])) { 
    379379                                                        foreach ($tresults as $tresult) { 
    380                                                                 echo '<option value="'.$tresult[2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n"; 
     380                                                                echo '<option value="'.$tresult['id'].'"'.($tresult['id'] == $default ? ' SELECTED' : '').'>'.$tresult['displayname']."</option>\n"; 
    381381                                                        } 
    382382                                                } 
  • modules/branches/2.5/findmefollow/uninstall.php

    r5864 r6158  
    3232} 
    3333 
     34sql('DROP TABLE IF EXISTS findmefollow'); 
     35 
    3436?> 
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads