Changeset 6151

Show
Ignore:
Timestamp:
07/23/08 19:07:41 (4 years ago)
Author:
p_lindheimer
Message:

#2066, #2943 Migrate recordings to recording ids, fix sqlite3 syntax

Files:

Legend:

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

    r5824 r6151  
    129129      return array(); 
    130130    } else { 
    131       //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup'; 
     131      //$type = isset($active_modules['ivr']['type'])?$active_modules['ivr']['type']:'setup'; 
    132132      return array('description' => 'IVR : '.$thisexten['displayname'], 
    133133                   'edit_url' => 'config.php?display=ivr&action=edit&id='.urlencode($exten), 
     
    136136  } else { 
    137137    return false; 
     138  } 
     139} 
     140 
     141function ivr_recordings_usage($recording_id) { 
     142  global $active_modules; 
     143 
     144  $results = sql("SELECT `ivr_id`, `displayname` FROM `ivr` WHERE `announcement_id` = '$recording_id'","getAll",DB_FETCHMODE_ASSOC); 
     145  if (empty($results)) { 
     146    return array(); 
     147  } else { 
     148    //$type = isset($active_modules['ivr']['type'])?$active_modules['ivr']['type']:'setup'; 
     149    foreach ($results as $result) { 
     150      $usage_arr[] = array( 
     151        'url_query' => 'config.php?display=ivr&action=edit&id='.urlencode($result['ivr_id']), 
     152        'description' => "IVR: ".$result['displayname'], 
     153      ); 
     154    } 
     155    return $usage_arr; 
    138156  } 
    139157} 
     
    151169          $details = ivr_get_details($item['ivr_id']); 
    152170 
    153           $announcement = (isset($details['announcement']) ? $details['announcement'] : ''); 
     171          $announcement_id = (isset($details['announcement_id']) ? $details['announcement_id'] : ''); 
    154172          $loops = (isset($details['loops']) ? $details['loops'] : '2'); 
    155173 
     
    183201          $ext->add($id, 's', 'begin', new ext_digittimeout(3)); 
    184202          $ext->add($id, 's', '', new ext_responsetimeout($details['timeout'])); 
    185           if ($announcement != '') { 
    186             $ext->add($id, 's', '', new ext_background($announcement)); 
     203          if ($announcement_id != '') { 
     204            $announcement_msg = recordings_get_file($announcement_id); 
     205            $ext->add($id, 's', '', new ext_background($announcement_msg)); 
    187206          } 
    188207          $ext->add($id, 's', '', new ext_waitexten()); 
     
    296315  $ena_directory = isset($post['ena_directory'])?$post['ena_directory']:''; 
    297316  $ena_directdial = isset($post['ena_directdial'])?$post['ena_directdial']:''; 
    298   $annmsg = isset($post['annmsg'])?$post['annmsg']:''; 
     317  $annmsg_id = isset($post['annmsg_id'])?$post['annmsg_id']:''; 
    299318  $dircontext = isset($post['dircontext'])?$post['dircontext']:''; 
    300319 
     
    316335  } 
    317336   
    318   sql("UPDATE ivr SET displayname='$displayname', enable_directory='$ena_directory', enable_directdial='$ena_directdial', timeout='$timeout', announcement='$annmsg', dircontext='$dircontext', alt_timeout='$alt_timeout', alt_invalid='$alt_invalid', `loops`='$loops' WHERE ivr_id='$id'"); 
     337  sql("UPDATE ivr SET displayname='$displayname', enable_directory='$ena_directory', enable_directdial='$ena_directdial', timeout='$timeout', announcement_id='$annmsg_id', dircontext='$dircontext', alt_timeout='$alt_timeout', alt_invalid='$alt_invalid', `loops`='$loops' WHERE ivr_id='$id'"); 
    319338 
    320339  // Delete all the old dests 
  • modules/branches/2.5/ivr/install.php

    r5824 r6151  
    11<?php 
    2 sql('CREATE TABLE IF NOT EXISTS ivr ( ivr_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, displayname VARCHAR(50), deptname VARCHAR(50), enable_directory VARCHAR(8), enable_directdial VARCHAR(8), timeout INT, announcement VARCHAR(255), dircontext VARCHAR ( 50 ) DEFAULT "default", alt_timeout VARCHAR(8), alt_invalid VARCHAR(8), `loops` TINYINT(1) NOT NULL DEFAULT 2 )'); 
    3 sql('CREATE TABLE IF NOT EXISTS ivr_dests ( ivr_id INT NOT NULL, selection VARCHAR(10), dest VARCHAR(50), ivr_ret TINYINT(1) NOT NULL DEFAULT 0)'); 
     2 
     3if (! function_exists("out")) { 
     4  function out($text) { 
     5    echo $text."<br />"; 
     6  } 
     7
     8 
     9if (! function_exists("outn")) { 
     10  function outn($text) { 
     11    echo $text; 
     12  } 
     13
    414 
    515global $db; 
     16global $amp_conf; 
     17 
     18$autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT":"AUTO_INCREMENT"; 
     19$sql = " 
     20CREATE TABLE IF NOT EXISTS ivr  
     21(  
     22  `ivr_id` INT NOT NULL $autoincrement PRIMARY KEY,  
     23  `displayname` VARCHAR(50),  
     24  `deptname` VARCHAR(50),  
     25  `enable_directory` VARCHAR(8),  
     26  `enable_directdial` VARCHAR(8),  
     27  `timeout` INT,  
     28  `announcement` VARCHAR(255),  
     29  `dircontext` VARCHAR ( 50 ) DEFAULT 'default',  
     30  `alt_timeout` VARCHAR(8),  
     31  `alt_invalid` VARCHAR(8),  
     32  `loops` TINYINT(1) NOT NULL DEFAULT 2  
     33) 
     34"; 
     35sql($sql); 
     36 
     37$sql = " 
     38CREATE TABLE IF NOT EXISTS ivr_dests  
     39(  
     40  `ivr_id` INT NOT NULL,  
     41  `selection` VARCHAR(10),  
     42  `dest` VARCHAR(50),  
     43  `ivr_ret` TINYINT(1) NOT NULL DEFAULT 0 
     44) 
     45"; 
     46sql($sql); 
    647 
    748// Now, we need to check for upgrades.  
     
    110151    if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } 
    111152} 
     153 
     154 
     155 
     156// Version 2.5 migrate to recording ids 
     157// 
     158outn(_("Checking if announcements need migration..")); 
     159$sql = "SELECT announcement_id FROM ivr"; 
     160$check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
     161if(DB::IsError($check)) { 
     162  //  Add announcement_id field 
     163  // 
     164  out("migrating"); 
     165  outn(_("adding announcement_id field..")); 
     166  $sql = "ALTER TABLE ivr ADD announcement_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 
     175  // Get all the valudes and replace them with announcement_id 
     176  // 
     177  outn(_("migrate to recording ids..")); 
     178  $sql = "SELECT `ivr_id`, `announcement` FROM `ivr`"; 
     179  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     180  if(DB::IsError($results)) { 
     181    out(_("fatal error")); 
     182    die_freepbx($results->getDebugInfo());   
     183  } 
     184  $migrate_arr = array(); 
     185  $count = 0; 
     186  foreach ($results as $row) { 
     187    if (trim($row['announcement']) != '') { 
     188      $rec_id = recordings_get_or_create_id($row['announcement'], 'ivr'); 
     189      $migrate_arr[] = array($rec_id, $row['ivr_id']); 
     190      $count++; 
     191    } 
     192  } 
     193  if ($count) { 
     194    $compiled = $db->prepare('UPDATE `ivr` SET `announcement_id` = ? WHERE `ivr_id` = ?'); 
     195    $result = $db->executeMultiple($compiled,$migrate_arr); 
     196    if(DB::IsError($result)) { 
     197      out(_("fatal error")); 
     198      die_freepbx($result->getDebugInfo());  
     199    } 
     200  } 
     201  out(sprintf(_("migrated %s entries"),$count)); 
     202 
     203  // Now remove the old recording field replaced by new id field 
     204  // 
     205  outn(_("dropping announcement field..")); 
     206  $sql = "ALTER TABLE `ivr` DROP `announcement`"; 
     207  $result = $db->query($sql); 
     208  if(DB::IsError($result)) {  
     209    out(_("no announcement field???")); 
     210  } else { 
     211    out(_("ok")); 
     212  } 
     213 
     214} else { 
     215  out("already migrated"); 
     216} 
     217 
    112218?> 
  • modules/branches/2.5/ivr/module.xml

    r6085 r6151  
    22  <rawname>ivr</rawname> 
    33  <name>IVR</name> 
    4   <version>2.5.17.1</version> 
     4  <version>2.5.18</version> 
    55  <type>setup</type> 
    66  <category>Inbound Call Control</category> 
     
    99  </description> 
    1010  <changelog> 
     11    *2.5.18* #2066 Migrate recordings to recording ids 
    1112    *2.5.17.1* #2845 tabindex 
    1213    *2.5.17* #2858 Better handing of i and t options, added loop count and ability to loop before going to user defined i, t options 
     
    3738  </changelog> 
    3839  <depends> 
    39     <version>2.4.0</version> 
     40    <version>2.5.0alpha1</version> 
     41    <module>recordings ge 3.3.8</module> 
    4042  </depends> 
    4143  <menuitems> 
  • modules/branches/2.5/ivr/page.ivr.php

    r5970 r6151  
    190190    </tr> 
    191191<?php 
    192       $annmsg = isset($ivr_details['announcement'])?$ivr_details['announcement']:''; 
     192      $annmsg_id = isset($ivr_details['announcement_id'])?$ivr_details['announcement_id']:''; 
    193193      if(function_exists('recordings_list')) { //only include if recordings is enabled ?> 
    194194    <tr> 
    195195      <td><a href="#" class="info"><?php echo _("Announcement")?><span><?php echo _("Message to be played to the caller. To add additional recordings please use the \"System Recordings\" MENU to the left")?></span></a></td> 
    196196      <td> 
    197         <select name="annmsg" tabindex="<?php echo ++$tabindex;?>"> 
     197        <select name="annmsg_id" tabindex="<?php echo ++$tabindex;?>"> 
    198198        <?php 
    199199          $tresults = recordings_list(); 
     
    201201          if (isset($tresults[0])) { 
    202202            foreach ($tresults as $tresult) { 
    203               echo '<option value="'.$tresult[2].'"'.($tresult[2] == $annmsg ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n"; 
     203              echo '<option value="'.$tresult['id'].'"'.($tresult['id'] == $annmsg_id ? ' SELECTED' : '').'>'.$tresult['displayname']."</option>\n"; 
    204204            } 
    205205          } 
     
    216216      <td> 
    217217      <?php 
    218         $default = (isset($annmsg) ? $annmsg : ''); 
     218        $default = (isset($annmsg_id) ? $annmsg_id : ''); 
    219219      ?> 
    220         <input type="hidden" name="annmsg" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?> 
     220        <input type="hidden" name="annmsg_id" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?> 
    221221      </td> 
    222222    </tr>