source: extensions/fstats/maintain.inc.php @ 31936

Last change on this file since 31936 was 3324, checked in by rub, 15 years ago

extension added: fstats

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Files statistics - a PWG Plugin                                       |
4// | Copyright (C) 2007 Ruben ARNAUD - rub@phpwebgallery.net               |
5// +-----------------------------------------------------------------------+
6// | This program is free software; you can redistribute it and/or modify  |
7// | it under the terms of the GNU General Public License as published by  |
8// | the Free Software Foundation                                          |
9// |                                                                       |
10// | This program is distributed in the hope that it will be useful, but   |
11// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13// | General Public License for more details.                              |
14// |                                                                       |
15// | You should have received a copy of the GNU General Public License     |
16// | along with this program; if not, write to the Free Software           |
17// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18// | USA.                                                                  |
19// +-----------------------------------------------------------------------+
20
21if (!defined('PHPWG_ROOT_PATH'))
22{
23  die('Hacking attempt!');
24}
25
26function plugin_install()
27{
28  include_once(dirname(__FILE__).'/constants.php');
29
30  @mkdir(FSTATS_DATA_DIR);
31  @mkdir(FSTATS_RAW_DIR);
32  @mkdir(FSTATS_SUMMARY_DIR);
33  $filename = FSTATS_DATA_DIR.'/.htaccess';
34  $hfile = fopen($filename, 'w+');
35  if ($hfile !== FALSE)
36  {
37    fwrite($hfile, 'deny from all');
38    fclose($hfile);
39  }
40}
41
42function plugin_activate()
43{
44  global $conf;
45
46  if (!empty($conf['fstat_plugin_activate_migrate']) and $conf['fstat_plugin_activate_migrate'])
47  {
48    include_once(dirname(__FILE__).'/constants.php');
49    include_once(FSTATS_PLUGIN_DIR.'/functions.inc.php');
50
51    @set_time_limit(0);
52
53    // HISTORY_TABLE
54    $query = 'select * from '.HISTORY_TABLE.' order by date, time, user_id';
55
56    $result = pwg_query($query);
57
58    $year = null;
59    $month = null;
60    $day = null;
61    $hour = null;
62    $user_id = null;
63    $filename = null;
64    $hfile = FALSE;
65
66    while ($row = mysql_fetch_array($result))
67    {
68      if ($year.'_'.$month.'_'.$day.'_'.$hour.'_'.$user_id != $row['year'].'_'.$row['month'].'_'.$row['day'].'_'.$row['hour'].'_'.$row['user_id'])
69      {
70        if ($hfile !== FALSE)
71        {
72          fclose($hfile);
73        }
74
75        $year = $row['year'];
76        $month = $row['month'];
77        $day = $row['day'];
78        $hour = $row['hour'];
79        $user_id = $row['user_id'];
80
81        $dirname = sprintf(FSTATS_FMT_RAW_DIR_H, $year, $month, $day, $hour);
82
83        fstats_Rmkdir($dirname);
84
85        $filename = $dirname.'/'.sprintf(FSTATS_FMT_RAW_FILE, $year, $month, $day, $hour, $user_id);
86        $hfile = fopen($filename, 'w+');
87      }
88
89      $row['version'] = '0';
90      if ($hfile !== FALSE)
91      {
92        fwrite($hfile, serialize ($row)."\n");
93      }
94    }
95
96    if ($hfile !== FALSE)
97    {
98      fclose($hfile);
99    }
100    // HISTORY_SUMMARY_TABLE
101    $query = 'select * from '.HISTORY_SUMMARY_TABLE.' order by year, month, day, hour';
102
103    $result = pwg_query($query);
104
105    $year = null;
106    $month = null;
107    $day = null;
108    $hour = null;
109    $filename = null;
110    $hfile = FALSE;
111
112    while ($row = mysql_fetch_array($result))
113    {
114      if ($year.'_'.$month.'_'.$day.'_'.$hour != $row['year'].'_'.$row['month'].'_'.$row['day'].'_'.$row['hour'])
115      {
116        if ($hfile !== FALSE)
117        {
118          fclose($hfile);
119        }
120
121        $year = $row['year'];
122        $month = $row['month'];
123        $day = $row['day'];
124        $hour = $row['hour'];
125
126        $dirname = sprintf(FSTATS_FMT_SUMMARY_DIR, $year, $month, $day, $hour);
127
128        fstats_Rmkdir($dirname);
129
130        $filename = $dirname.'/'.sprintf(FSTATS_FMT_SUMMARY_FILE, $year, $month, $day, $hour);
131        $hfile = fopen($filename, 'w+');
132      }
133
134      $row['version'] = '0';
135      if ($hfile !== FALSE)
136      {
137        fwrite($hfile, serialize ($row)."\n");
138      }
139    }
140
141    if ($hfile !== FALSE)
142    {
143      fclose($hfile);
144    }
145  }
146}
147
148?>
Note: See TracBrowser for help on using the repository browser.