Changeset 10144
- Timestamp:
- 07/14/10 16:44:59 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
freepbx/trunk/amp_conf/htdocs/admin/common/php-asmanager.php
r10143 r10144 113 113 */ 114 114 var $event_handlers; 115 116 var $useCaching = false; 117 var $memAstDB = null; 115 118 116 119 /** … … 137 140 if(!isset($this->config['asmanager']['username'])) $this->config['asmanager']['username'] = 'phpagi'; 138 141 if(!isset($this->config['asmanager']['secret'])) $this->config['asmanager']['secret'] = 'phpagi'; 139 } 140 142 143 if(isset($this->config['asmanager']['cachemode'])) $this->useCaching = $this->config['asmanager']['cachemode']; 144 } 145 146 function LoadAstDB(){ 147 if ($this->memAstDB != null) unset($this->memAstDB); 148 $this->memAstDB = $this->database_show(); 149 } 150 141 151 /** 142 152 * Send a request … … 735 745 */ 736 746 function database_show($family='') { 747 if ($this->useCaching && $this->memAstDB != null) { 748 if ($family == '') { 749 return $this->memAstDB; 750 } else { 751 $key = '/'.$family; 752 if (isset($this->memAstDB[$key])) { 753 return array($key => $this->memAstDB[$key]); 754 } else { 755 $key .= '/'; 756 $len = strlen($key); 757 $fam_arr = array(); 758 foreach ($this->memAstDB as $this_key => $value) { 759 if (substr($this_key,0,$len) == $key) { 760 $fam_arr[$this_key] = $value; 761 } 762 } 763 return $fam_arr; 764 } 765 } 766 } 737 767 $r = $this->command("database show $family"); 738 768 … … 762 792 $value = (trim($value) == '')?'"'.$value.'"':$value; 763 793 $r = $this->command("database put ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)." ".$value); 794 if (!empty($this->memAstDB)){ 795 $keyUsed="/".str_replace(" ","/",$family)."/".str_replace(" ","/",$key); 796 $this->memAstDB[$keyUsed] = $value; 797 } 764 798 return (bool)strstr($r["data"], "success"); 765 799 } … … 770 804 * @return mixed Value of the key, or false if error 771 805 */ 806 /* 772 807 function database_get($family, $key) { 773 808 $r = $this->command("database get ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); … … 779 814 } 780 815 } 816 */ 817 function database_get($family, $key) { 818 if ($this->useCaching) { 819 if ($this->memAstDB == null) { 820 $this->LoadAstDB(); 821 } 822 $keyUsed="/".str_replace(" ","/",$family)."/".str_replace(" ","/",$key); 823 if (array_key_exists($keyUsed,$this->memAstDB)){ 824 return $this->memAstDB[$keyUsed]; 825 } 826 } else { 827 $r = $this->command("database get ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); 828 $data = strpos($r["data"],"Value:"); 829 if ($data !== false) { 830 return trim(substr($r["data"],6+$data)); 831 } 832 } 833 return false; 834 } 835 781 836 782 837 /** Delete an entry from the asterisk database … … 786 841 */ 787 842 function database_del($family, $key) { 843 if (!empty($this->memAstDB)){ 844 $keyUsed="/".str_replace(" ","/",$family)."/".str_replace(" ","/",$key); 845 unset($this->memAstDB[$keyUsed]); 846 } 788 847 $r = $this->command("database del ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); 789 848 return (bool)strstr($r["data"], "removed"); … … 795 854 */ 796 855 function database_deltree($family) { 856 if (!empty($this->memAstDB)){ 857 $keyUsed="/".str_replace(" ","/",$family); 858 unset($this->memAstDB[$keyUsed]); 859 } 797 860 $r = $this->command("database deltree ".str_replace(" ","/",$family)); 798 861 return (bool)strstr($r["data"], "removed");
