Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezstats/admin/cron.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: cron.php 9901 2004-07-08 16:15:25Z br $
5 //
6 // Created on: <23-Oct-2000 17:53:46 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27
28 // include_once( "classes/ezdb.php" );
29 // include_once( "classes/ezdatetime.php" );
30
31 $db =& eZDB::globalDatabase();
32
33 $db->begin();
34
35 $timestamp = (new eZDateTime())->timeStamp( true );
36 $debug = false;
37 $limit = 10000;
38
39 set_time_limit( 86400 );
40
41 // BrowserType archive
42
43 $newelements = array();
44 $oldelements = array();
45 $res = array();
46 if ( $debug == true )
47 print( "\nStarting query eZStats_PageView (BrowserType archive):" );
48
49 unset( $newelements );
50 flush();
51 $offset = 0;
52 $newelements = array( "dummy" );
53 while ( count( $newelements ) > 0 )
54 {
55 $db->array_query( $newelements, "SELECT COUNT(*), BrowserTypeID FROM eZStats_PageView WHERE Date < " . $timestamp . " GROUP BY BrowserTypeID", array( "Limit" => $limit, "Offset" => $offset ) );
56 $offset += $limit;
57 if ( $debug == true )
58 print( "." );
59
60 foreach ( $newelements as $element )
61 {
62 $browser = array();
63 $db->array_query( $browser, "SELECT BrowserType FROM eZStats_BrowserType WHERE ID='" . $element[$db->fieldName("BrowserTypeID")] . "'" );
64 $browsername = $db->escapeString( $browser[0][$db->fieldName("BrowserType")] );
65 $db->array_query( $oldelements, "SELECT * FROM eZStats_Archive_BrowserType WHERE Browser='" . $browsername . "'");
66
67 if ( count( $oldelements ) == 0 )
68 {
69 $db->lock( "eZStats_Archive_BrowserType" );
70 $nextid = $db->nextID( "eZStats_Archive_BrowserType", "ID" );
71 $res[] = $db->query( "INSERT INTO eZStats_Archive_BrowserType (ID, Browser, Count) VALUES ('$nextid', '$browsername', '$element[0]')" );
72 $db->unlock();
73 }
74 else
75 {
76 $count = $oldelements[0][$db->fieldName("Count")] + $element[0];
77 $res[] = $db->query( "UPDATE eZStats_Archive_BrowserType SET Count='$count' WHERE Browser='$browsername'" );
78 }
79 }
80 }
81 // RequestPage archive
82
83 if ( $debug == true )
84 print( "\nStarting query eZStats_PageView (RequestPage archive):" );
85 unset( $newelements );
86 flush();
87 $offset = 0;
88 $newelements = array( "dummy" );
89 while ( count( $newelements ) > 0 )
90 {
91 $db->array_query( $newelements, "SELECT Date, RequestPageID FROM eZStats_PageView WHERE Date < " . $timestamp . " ORDER BY Date", array( "Limit" => $limit, "Offset" => $offset ) );
92 $offset += $limit;
93
94 if ( $debug == true )
95 print( "." );
96 foreach ( $newelements as $element )
97 {
98 $request = array();
99 $db->array_query( $request, "SELECT URI FROM eZStats_RequestPage WHERE ID=" . $element[$db->fieldName("RequestPageID")] );
100 $requestname = $db->escapeString( $request[0][$db->fieldName("URI")] );
101 $date = new eZDateTime();
102 $date->setTimeStamp( $element[$db->fieldName("Date")] );
103 $month = new eZDateTime( $date->year(), $date->month(), 1, 0, 0, 0 );
104 $db->array_query( $oldelements, "SELECT * FROM eZStats_Archive_RequestedPage WHERE URI='$requestname' AND Month='" . $month->timeStamp() . "'" );
105 if ( count( $oldelements ) == 0 )
106 {
107 $db->lock( "eZStats_Archive_RequestedPage" );
108 $nextid = $db->nextID( "eZStats_Archive_RequestedPage", "ID" );
109 $res[] = $db->query( "INSERT INTO eZStats_Archive_RequestedPage (ID, URI, Month, Count) VALUES ('$nextid', '$requestname', '" . $month->timeStamp() . "', '1')" );
110 $db->unlock();
111 }
112 else
113 {
114 $count = $oldelements[0][$db->fieldName("Count")] + 1;
115 $res[] = $db->query( "UPDATE eZStats_Archive_RequestedPage SET Count='$count' WHERE URI='$requestname' AND Month='" . $month->timeStamp() . "'" );
116 }
117 }
118 }
119 // ReferURL archive
120 if ( $debug == true )
121 print( "\nStart query eZStats_PageView (ReferURL archive):" );
122
123 unset( $newelements );
124 flush();
125 $offset = 0;
126 $newelements = array( "dummy" );
127 while ( count( $newelements ) > 0 )
128 {
129
130 $db->array_query( $newelements, "SELECT Date, RefererURLID FROM eZStats_PageView WHERE Date < " . $timestamp . " ORDER BY Date", array( "Limit" => $limit, "Offset" => $offset ) );
131 $offset += $limit;
132 if ( $debug == true )
133 print( "." );
134
135 foreach ( $newelements as $element )
136 {
137 $refer = array();
138 $db->array_query( $refer, "SELECT URI, Domain FROM eZStats_RefererURL WHERE ID=" . $element[$db->fieldName("RefererURLID")] );
139
140 $refername = $db->escapeString( $refer[0][$db->fieldName("URI")] );
141 $domain = $db->escapeString( $refer[0][$db->fieldName("Domain")] );
142
143 $date = new eZDateTime();
144 $date->setTimeStamp( $element[$db->fieldName("Date")] );
145 $month = new eZDateTime( $date->year(), $date->month(), 1, 0, 0, 0 );
146 $db->array_query( $oldelements, "SELECT * FROM eZStats_Archive_RefererURL WHERE URI='$refername' AND Domain='$domain' AND Month='". $month->timeStamp() . "'" );
147
148 if ( count( $oldelements ) == 0 )
149 {
150 $db->lock( "eZStats_Archive_RefererURL" );
151 $nextid = $db->nextID( "eZStats_Archive_RefererURL", "ID" );
152 $res[] = $db->query( "INSERT INTO eZStats_Archive_RefererURL (ID, URI, Domain, Month, Count, Language ) VALUES " .
153 "('$nextid', '$refername', '$domain', '" . $month->timeStamp() . "', '1', '' )" );
154 $db->unlock();
155 }
156 else
157 {
158 $count = $oldelements[0][$db->fieldName("Count")] + 1;
159 $res[] = $db->query( "UPDATE eZStats_Archive_RefererURL SET Count='$count' WHERE URI='$refername' AND Domain='$domain' AND Month='" . $month->timeStamp() . "'" );
160 }
161 }
162 }
163 // RemoteHost archive
164 if ( $debug == true )
165 print( "\nStart query eZStats_PageView (RemoteHost archive):" );
166
167 unset( $newelements );
168 flush();
169 $offset = 0;
170
171 $newelements = array( "dummy" );
172 while ( count( $newelements ) > 0 )
173 {
174
175 $db->array_query( $newelements, "SELECT RemoteHostID FROM eZStats_PageView WHERE Date < " . $timestamp, array( "Limit" => $limit, "Offset" => $offset ) );
176 $offset += $limit;
177 if ( $debug == true )
178 print( "." );
179
180 foreach ( $newelements as $element )
181 {
182 $remote = array();
183 $db->array_query( $remote, "SELECT IP, HostName FROM eZStats_RemoteHost WHERE ID=" . $element[$db->fieldName("RemoteHostID")] );
184
185 $remotename = $db->escapeString( $remote[0][$db->fieldName("IP")] );
186 $hostname = $db->escapeString( $remote[0][$db->fieldName("HostName")] );
187
188 $db->array_query( $oldelements, "SELECT * FROM eZStats_Archive_RemoteHost WHERE IP='$remotename' AND HostName='$hostname'" );
189
190 if ( count( $oldelements ) == 0 )
191 {
192 $remote_host_id = $element[$db->fieldName( "RemoteHostID" )];
193 $db->array_query( $remote_host, "SELECT * FROM eZStats_RemoteHost WHERE ID='$remote_host_id'" );
194
195 $remoteHostIP = $db->escapeString( $remote_host[0][$db->fieldName( "IP" )] );
196 $remoteHostName = $db->escapeString( $remote_host[0][$db->fieldName( "HostName" )] );
197
198 $db->lock( "eZStats_Archive_RemoteHost" );
199 $nextid = $db->nextID( "eZStats_Archive_RemoteHost", "ID" );
200
201 $res[] = $db->query( "INSERT INTO eZStats_Archive_RemoteHost (ID, IP, HostName, Count) VALUES ('$nextid', '" .
202 $remoteHostIP . "', '" .
203 $remoteHostName . "', '1')" );
204 $db->unlock();
205 }
206 else
207 {
208 $count = $oldelements[0][$db->fieldName("Count")] + 1;
209 $res[] = $db->query( "UPDATE eZStats_Archive_RemoteHost SET Count='$count' WHERE IP='$remotename' AND HostName='$hostname'" );
210 }
211 }
212 }
213 // Users archive
214 if ( $debug == true )
215 print( "\nStart query eZStats_PageView (Users archive):" );
216
217 unset( $newelements );
218 flush();
219 $offset = 0;
220
221 $newelements = array( "dummy" );
222 while ( count( $newelements ) > 0 )
223 {
224 $db->array_query( $newelements, "SELECT Date, UserID FROM eZStats_PageView WHERE Date < " . $timestamp . " ORDER BY Date", array( "Limit" => $limit, "Offset" => $offset ) );
225 $offset += $limit;
226
227 if ( $debug == true )
228 print( "." );
229 foreach ( $newelements as $element )
230 {
231 $userID = $element[$db->fieldName("UserID")];
232 $date = new eZDateTime();
233 $date->setTimeStamp( $element[$db->fieldName("Date")] );
234 $month = new eZDateTime( $date->year(), $date->month(), 1, 0, 0, 0 );
235 $db->array_query( $oldelements, "SELECT * FROM eZStats_Archive_Users WHERE UserID='$userID' AND Month='". $month->timeStamp() . "'" );
236
237 if ( count( $oldelements ) == 0 )
238 {
239 $db->lock( "eZStats_Archive_Users" );
240 $nextid = $db->nextID( "eZStats_Archive_Users", "ID" );
241 $res[] = $db->query( "INSERT INTO eZStats_Archive_Users (ID, UserID, Month, Count) VALUES ('$nextid', '$userID', '" . $month->timeStamp() . "', '1')" );
242 $db->unlock();
243 }
244 else
245 {
246 $count = $oldelements[0][$db->fieldName("Count")] + 1;
247 $res[] = $db->query( "UPDATE eZStats_Archive_Users SET Count='$count' WHERE UserID='$userID' AND Month='" . $month->timeStamp() . "'" );
248 }
249 }
250 }
251 /* UniqueVisits archive
252
253 $db->query( $newelements, "SELECT Date, RemoteHostID FROM eZStats_PageView WHERE Date < " . $timestamp . " ORDER BY Date" );
254
255
256 foreach ( $newelements as $element )
257 {
258 $date = new eZDateTime();
259 $date->setTimeStamp( $element[$db->fieldName("Date")] );
260 $day = new eZDateTime( $date->year(), $date->month(), $date->day() );
261 $db->query( $oldelements, "SELECT * FROM eZStats_Archive_UniqueVisits WHERE Day='" . $day->timeStamp() . "'" );
262
263 if ( count( $oldelements ) == 0 )
264 {
265 $db->lock( "eZStats_Archive_UniqueVisits" );
266 $nextid = $db->nextID( "eZStats_Archive_UniqueVisits", "ID" );
267 $res[] = $db->query( "INSERT INTO eZStats_Archive_UniqueVisits (ID, Day, Count) VALUES ('$nextid', '$day->timeStamp()', '1')" );
268 $db->unlock();
269 }
270 else
271 {
272 $count = $oldelements[0][$db->fieldName("Count")] + 1;
273 $res[] = $db->query( "UPDATE eZStats_Archive_UniqueVisits SET Count='$count' WHERE Day='" . $day->timeStamp() . "'" );
274 }
275 }
276 */
277
278 // PageView archive
279 if ( $debug == true )
280 print( "\nStart query eZStats_PageView (PageView archive):" );
281 unset( $newelements );
282 flush();
283 $offset = 0;
284
285 $newelements = array( "dummy" );
286 while ( count( $newelements ) > 0 )
287 {
288
289 $db->array_query( $newelements, "SELECT Date FROM eZStats_PageView WHERE Date < " . $timestamp . " ORDER BY Date", array( "Limit" => $limit, "Offset" => $offset ) );
290 $offset += $limit;
291 if ( $debug == true )
292 print( "." );
293
294 foreach ( $newelements as $element )
295 {
296 $date = new eZDateTime();
297 $date->setTimeStamp( $element[$db->fieldName("Date")] );
298 $hour = new eZDateTime( $date->year(), $date->month(), $date->day(), $date->hour(), 0, 0 );
299 $db->array_query( $oldelements, "SELECT * FROM eZStats_Archive_PageView WHERE Hour='" . $hour->timeStamp() . "'" );
300
301 if ( count( $oldelements ) == 0 )
302 {
303 $db->lock( "eZStats_Archive_PageView" );
304 $nextid = $db->nextID( "eZStats_Archive_PageView", "ID" );
305 $res[] = $db->query( "INSERT INTO eZStats_Archive_PageView (ID, Hour, Count) VALUES ('$nextid', '" . $hour->timeStamp() . "', '1')" );
306 $db->unlock();
307 }
308 else
309 {
310 $count = $oldelements[0][$db->fieldName("Count")] + 1;
311 $res[] = $db->query( "UPDATE eZStats_Archive_PageView SET Count='$count' WHERE Hour='" . $hour->timeStamp() . "'" );
312 }
313 }
314 }
315 $res[] = $db->query( "DELETE FROM eZStats_PageView WHERE Date < " . $timestamp );
316
317 if ( in_array( false, $res ) )
318 $db->rollback();
319 else
320 $db->commit();
321
322 ?>
$userID
else $userID
Definition: appointmentedit.php:121
$month
else $month
Definition: appointmentedit.php:660
$date
$date
Definition: bugpreview.php:66
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
$hour
$hour
Definition: export_froogle.php:310
$db
$db
Definition: ezstats/admin/cron.php:31
$timestamp
$timestamp
Definition: ezstats/admin/cron.php:35
$res
$res
Definition: ezstats/admin/cron.php:45
$debug
$debug
Definition: ezstats/admin/cron.php:36
$limit
$limit
Definition: ezstats/admin/cron.php:37
$newelements
$newelements
Definition: ezstats/admin/cron.php:43
$offset
$offset
Definition: ezstats/admin/cron.php:51
$oldelements
$oldelements
Definition: ezstats/admin/cron.php:44
$element
if(! $parent) $element
Definition: folder.php:64
$count
$count
Definition: onlinetypelist.php:108
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.