source: extensions/EStat/estat_install.class.inc.php @ 17862

Last change on this file since 17862 was 17758, checked in by grum, 12 years ago

version 0.1.0b

. Fix install bugs
. Manage anonymous directories
. Manage CSV export options settings
. Fix IPadress<=>country association bug & improve join performances
. Fix bug on IP filter
. Improve performances for history consult

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : EStat
4  Author     : Grum
5    email    : grum@piwigo.org
6    website  : http://photos.grum.fr
7
8    << May the Little SpaceFrog be with you ! >>
9  ------------------------------------------------------------------------------
10  See main.inc.php for release information
11
12  EStat_Install : classe to manage plugin install
13
14  --------------------------------------------------------------------------- */
15
16   include_once('estat_version.inc.php'); // => Don't forget to update this file !!
17   include_once('estat_root.class.inc.php');
18
19  /* EStat class for install process */
20  class EStat_Install extends EStat_root
21  {
22    /*
23        function for installation process
24        return true if install process is ok, otherwise false
25    */
26    public function install()
27    {
28      $this->checkDirectories();
29      $this->initConfig();
30      $this->loadConfig();
31
32      // create Global Stat File
33      $gStatFile=new StatDBGlobal($this->fileStatDir, self::FILE_GLOBAL);
34      $gStatFile->open(ASDF_OPEN_WRITE);
35      $gStatFile->close();
36
37      $this->config['installed']=ESTAT_VERSION2;
38      $this->config['plugin.newInstall']='y';
39      $this->saveConfig();
40
41      GPCCore::register($this->getPluginName(), ESTAT_VERSION, ESTAT_GPC_NEEDED);
42      return(true);
43    }
44
45
46    /*
47        function for uninstall process
48    */
49    public function uninstall()
50    {
51      //GPCCore::rmDir(dirname($this->fileStatDir));
52      $this->deleteConfig();
53      GPCCore::unregister($this->getPluginName());
54      return('');
55    }
56
57    public function activate()
58    {
59      $this->checkDirectories();
60      $this->initConfig();
61      $this->loadConfig();
62
63      // check if ip database need to be updated
64      $this->checkIpCountryFile();
65
66      /*
67       * migration code
68       */
69      switch($this->config['installed'])
70      {
71        case '00.01.00b':
72          //$this->updateFrom_000100b();
73        default:
74          // nothing to do...
75          break;
76      }
77
78      $this->config['installed']=ESTAT_VERSION2;
79      $this->saveConfig();
80
81      GPCCore::register($this->getPluginName(), ESTAT_VERSION, ESTAT_GPC_NEEDED);
82      return('');
83    }
84
85    public function deactivate()
86    {
87    }
88
89
90    /**
91     * update from release 0.1.0b
92     *
93     *  -- dummy --
94     *
95     */
96    private function updateFrom_000100b()
97    {
98      return(false);
99    }
100
101
102    /**
103     * check version of the ipCountry.bin file
104     *
105     * if database need an update, the config value 'plugin.newInstall' is set to "u"
106     */
107    private function checkIpCountryFile()
108    {
109      if($this->config['plugin.newInstall']=='y') return(false);
110
111      $dbCountry=new StatDBCountry($this->fileStatDir, self::FILE_COUNTRY);
112      $ipFileInfo=$dbCountry->getIpFileInfo(ESTAT_PATH.'data/ipCountry.bin');
113      $ipDBVersion=$dbCountry->getInfoProperty('nfo', 'ipFileVersion');
114
115      if($ipFileInfo['fileVersion']>$ipDBVersion)
116      {
117        $this->config['plugin.newInstall']=='u';
118        return(true);
119      }
120
121      return(false);
122    }
123
124    /**
125     * create the local directories & copy index.php files
126     *
127     */
128    private function checkDirectories()
129    {
130      if(!file_exists($this->fileStatDir))
131          mkdir($this->fileStatDir, 0755, true);
132
133      if(!file_exists($this->fileExportDir))
134          mkdir($this->fileExportDir, 0755, true);
135
136
137      if(!file_exists($this->fileStatDir.'/index.php'))
138        copy(ESTAT_PATH.'index.php', $this->fileStatDir.'/index.php');
139
140      if(!file_exists(dirname($this->fileStatDir).'/index.php'))
141        copy(ESTAT_PATH.'index.php', dirname($this->fileStatDir).'/index.php');
142
143      if(!file_exists($this->fileExportDir.'/index.php'))
144        copy(ESTAT_PATH.'index.php', $this->fileExportDir.'/index.php');
145
146      if(!file_exists(dirname($this->fileExportDir).'/index.php'))
147        copy(ESTAT_PATH.'index.php', dirname($this->fileExportDir).'/index.php');
148    }
149
150  } //class
151
152?>
Note: See TracBrowser for help on using the repository browser.