Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7312231
normalize.php
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
normalize.php
View Options
#!/usr/bin/php
<?
set_time_limit
(
0
)
;
$path
=
dirname
(
realpath
(
$_SERVER
[
'PHP_SELF'
]
)
)
;
include
(
$path
.
"/../global.inc"
)
;
include
(
$path
.
"/../cdrlib.phtml"
)
;
define_syslog_variables
(
)
;
openlog
(
"CDRTool"
,
LOG_PID
,
LOG_LOCAL0
)
;
$lockFile
=
"/var/lock/CDRTool_normalize.lock"
;
$f
=
fopen
(
$lockFile
,
"w"
)
;
if
(
flock
(
$f
,
LOCK_EX
+
LOCK_NB
,
$w
)
)
{
if
(
$w
)
{
print
"Another CDRTool normalization is in progress. Aborting.\n"
;
syslog
(
LOG_NOTICE
,
"Another CDRTool normalization is in progress. Aborting."
)
;
exit
(
2
)
;
}
}
else
{
print
"Another CDRTool normalization is in progress. Aborting.\n"
;
syslog
(
LOG_NOTICE
,
"Another CDRTool normalization is in progress. Aborting."
)
;
exit
(
1
)
;
}
while
(
list
(
$k
,
$v
)
=
each
(
$DATASOURCES
)
)
{
if
(
strlen
(
$v
[
"normalizedField"
]
)
)
{
$b
=
time
(
)
;
$class_name
=
$v
[
"class"
]
;
unset
(
$CDRS
)
;
$CDRS
=
new
$class_name
(
$k
)
;
$log
=
sprintf
(
"Normalize datasource %s, database %s, table %s\n"
,
$k
,
$v
[
'db_class'
]
,
$CDRS
->
table
)
;
print
$log
;
syslog
(
LOG_NOTICE
,
$log
)
;
$CDRS
->
NormalizeCDRS
(
)
;
$e
=
time
(
)
;
$d
=
$e
-
$b
;
if
(
$CDRS
->
status
[
'cdr_to_normalize'
]
)
{
$speed
=
0
;
if
(
$d
)
$speed
=
number_format
(
$CDRS
->
status
[
'cdr_to_normalize'
]
/
$d
,
0
,
""
,
""
)
;
$log
=
sprintf
(
"%d CDRs, %d normalized in %s s @ %s cps\n"
,
$CDRS
->
status
[
'cdr_to_normalize'
]
,
$CDRS
->
status
[
'normalized'
]
,
$d
,
$speed
)
;
print
$log
;
syslog
(
LOG_NOTICE
,
$log
)
;
}
if
(
preg_match
(
"/^(\w+)\d{6}$/"
,
$CDRS
->
table
,
$m
)
)
{
$lastMonthTable
=
$m
[
1
]
.
date
(
'Ym'
,
mktime
(
0
,
0
,
0
,
date
(
"m"
)
-
1
,
"01"
,
date
(
"Y"
)
)
)
;
$log
=
sprintf
(
"Normalize datasource %s, database %s, table %s\n"
,
$k
,
$v
[
'db_class'
]
,
$lastMonthTable
)
;
print
$log
;
syslog
(
LOG_NOTICE
,
$log
)
;
$b
=
time
(
)
;
$CDRS
->
table
=
$lastMonthTable
;
$CDRS
->
NormalizeCDRS
(
)
;
if
(
$CDRS
->
status
[
'cdr_to_normalize'
]
)
{
$e
=
time
(
)
;
$d
=
$e
-
$b
;
$speed
=
0
;
if
(
$d
)
$speed
=
number_format
(
$CDRS
->
status
[
'cdr_to_normalize'
]
/
$d
,
0
,
""
,
""
)
;
$log
=
sprintf
(
"%d CDRs, %d normalized in %s s @ %s cps\n"
,
$CDRS
->
status
[
'cdr_to_normalize'
]
,
$CDRS
->
status
[
'normalized'
]
,
$d
,
$speed
)
;
print
$log
;
syslog
(
LOG_NOTICE
,
$log
)
;
}
}
}
}
?>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 1, 5:29 AM (19 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3488753
Default Alt Text
normalize.php (2 KB)
Attached To
Mode
rCDRT CDRTool
Attached
Detach File
Event Timeline
Log In to Comment