| 1 |
#!/usr/bin/php -q |
|---|
| 2 |
<?php |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
set_time_limit(0); |
|---|
| 25 |
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING)); |
|---|
| 26 |
|
|---|
| 27 |
include_once (dirname(__FILE__)."/lib/Class.Table.php"); |
|---|
| 28 |
include (dirname(__FILE__)."/lib/Class.A2Billing.php"); |
|---|
| 29 |
include (dirname(__FILE__)."/lib/Misc.php"); |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
$A2B = new A2Billing(); |
|---|
| 33 |
$A2B -> load_conf($agi, NULL, 0, $idconfig); |
|---|
| 34 |
|
|---|
| 35 |
write_log(LOGFILE_CRONT_ARCHIVE_DATA, basename(__FILE__).' line:'.__LINE__."[#### ARCHIVING DATA BEGIN ####]"); |
|---|
| 36 |
|
|---|
| 37 |
if (!$A2B -> DbConnect()){ |
|---|
| 38 |
echo "[Cannot connect to the database]\n"; |
|---|
| 39 |
write_log(LOGFILE_CRONT_ARCHIVE_DATA, basename(__FILE__).' line:'.__LINE__."[Cannot connect to the database]"); |
|---|
| 40 |
exit; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
$A2B = new A2Billing(); |
|---|
| 44 |
$A2B -> load_conf($agi, NULL, 0, $idconfig); |
|---|
| 45 |
|
|---|
| 46 |
$instance_table = new Table(); |
|---|
| 47 |
|
|---|
| 48 |
$from_month = $A2B->config["backup"]['archive_data_x_month']; |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
if($A2B->config["database"]['dbtype'] == "postgres"){ |
|---|
| 52 |
$condition = "CURRENT_TIMESTAMP - interval '$from_month months' > starttime"; |
|---|
| 53 |
}else{ |
|---|
| 54 |
$condition = "DATE_SUB(NOW(),INTERVAL $from_month MONTH) > starttime"; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
$value = "SELECT sessionid,uniqueid,username,nasipaddress,starttime,stoptime,sessiontime,calledstation,startdelay,stopdelay,terminatecause,usertariff,calledprovider,calledcountry,calledsub,calledrate,sessionbill,destination,id_tariffgroup,id_tariffplan,id_ratecard,id_trunk,sipiax,src,id_did,buyrate,buycost,id_card_package_offer,real_sessiontime FROM cc_call where $condition"; |
|---|
| 58 |
$func_fields = "sessionid,uniqueid,username,nasipaddress,starttime,stoptime,sessiontime,calledstation,startdelay,stopdelay,terminatecause,usertariff,calledprovider,calledcountry,calledsub,calledrate,sessionbill,destination,id_tariffgroup,id_tariffplan,id_ratecard,id_trunk,sipiax,src,id_did,buyrate,buycost,id_card_package_offer,real_sessiontime"; |
|---|
| 59 |
$func_table = 'cc_call_archive'; |
|---|
| 60 |
$id_name = ""; |
|---|
| 61 |
$subquery = true; |
|---|
| 62 |
$result = $instance_table -> Add_table ($A2B -> DBHandle, $value, $func_fields, $func_table, $id_name,$subquery); |
|---|
| 63 |
|
|---|
| 64 |
$fun_table = "cc_call"; |
|---|
| 65 |
$result = $instance_table -> Delete_table ($A2B -> DBHandle, $condition, $fun_table); |
|---|
| 66 |
write_log(LOGFILE_CRONT_ARCHIVE_DATA, basename(__FILE__).' line:'.__LINE__."[#### ARCHIVING DATA END ####]"); |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
?> |
|---|
| 70 |
|
|---|