source: extensions/GMaps/gmaps_install.class.inc.php @ 20451

Last change on this file since 20451 was 10915, checked in by grum, 14 years ago

fix bug:2304

  • Property svn:executable set to *
File size: 7.9 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : GMaps
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  GMaps_Install : classe to manage plugin install
13
14  --------------------------------------------------------------------------- */
15
16   include_once('gmaps_version.inc.php'); // => Don't forget to update this file !!
17   include_once('gmaps_root.class.inc.php');
18   include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php');
19   include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php');
20
21  /* GMaps class for install process */
22  class GMaps_Install extends GMaps_root
23  {
24    private $tablef;
25
26    public function __construct($prefixeTable, $filelocation)
27    {
28      parent::__construct($prefixeTable, $filelocation);
29      $this->tablef= new GPCTables($this->tables);
30    }
31
32    public function __destruct()
33    {
34      unset($this->tablef);
35      parent::__destruct();
36    }
37
38    /*
39        function for installation process
40        return true if install process is ok, otherwise false
41    */
42    public function install()
43    {
44      if(!file_exists(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY))
45      {
46        mkdir(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY, 0755, true);
47      }
48
49      $this->initConfig();
50      $this->loadConfig();
51      $this->config['installed']=GMAPS_VERSION2;
52      $this->config['newInstall']='y';
53      $this->saveConfig();
54
55      $tables_def=array(
56"CREATE TABLE `".$this->tables['maps']."` (
57  `id` int(10) unsigned NOT NULL auto_increment,
58  `name` varchar(80) NOT NULL,
59  `displayType` char(2) NOT NULL,
60  `sizeMode` char(1) NOT NULL,
61  `width` int(10) unsigned NOT NULL default '470',
62  `height` int(10) unsigned NOT NULL default '210',
63  `zoomLevel` smallint(6) NOT NULL default '4',
64  `mapType` varchar(9) NOT NULL default 'hybrid',
65  `mapTypeControl` smallint(6) NOT NULL default '0',
66  `navigationControl` smallint(6) NOT NULL default '0',
67  `scaleControl` char(1) NOT NULL default 'y',
68  `streetViewControl` char(1) NOT NULL default 'n',
69  `style` varchar(512) NOT NULL,
70  `zoomLevelMaxActivated` char(1) NOT NULL default 'n',
71  PRIMARY KEY  (`id`)
72)",
73"CREATE TABLE `".$this->tables['category_maps']."` (
74  `id` int(10) unsigned NOT NULL auto_increment,
75  `categoryId` smallint(5) unsigned NOT NULL,
76  `mapId` int(11) NOT NULL,
77  `imgSort` smallint(5) unsigned NOT NULL default '0',
78  `applySubCat` char(1) NOT NULL default 'y',
79  `kmlFileId` int(10) unsigned NOT NULL default '0',
80  `kmlFileUrl` varchar(255) NOT NULL,
81  `icon` varchar(255) NOT NULL,
82  `marker` varchar(255) NOT NULL,
83  `title` varchar(200) NOT NULL,
84  `forceDisplay` char(1) NOT NULL default 'n',
85  PRIMARY KEY  (`id`),
86  KEY `byCategorie` (`categoryId`,`mapId`)
87)",
88"CREATE TABLE `".$this->tables['cache']."` (
89  `requestId` mediumint(8) UNSIGNED NOT NULL default '0',
90  `imageId` mediumint(8) NOT NULL,
91  `latitude` decimal(17,14) NOT NULL default '0',
92  `longitude` decimal(17,14) NOT NULL default '0',
93  PRIMARY KEY (`requestId`,`imageId`)
94)",
95"CREATE TABLE `".$this->tables['cache_id']."` (
96  `requestId` mediumint(8) UNSIGNED NOT NULL auto_increment,
97  `userId` smallint(5) NOT NULL,
98  `date` timestamp NOT NULL default '0000-00-00 00:00:00',
99  PRIMARY KEY (`requestId`)
100)",
101"CREATE TABLE `".$this->tables['kmlfiles']."` (
102  `id` int(10) unsigned NOT NULL auto_increment,
103  `file` varchar(255) NOT NULL,
104  `name` varchar(255) NOT NULL,
105  `fileDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
106  `fileSize` mediumint(8) unsigned NOT NULL,
107  PRIMARY KEY  (`id`)
108)"
109      );
110
111      $tables_def = create_table_add_character_set($tables_def);
112      $result=$this->tablef->create($tables_def);
113      unset($tables_def);
114
115      GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED);
116      return($result);
117    }
118
119
120    /*
121        function for uninstall process
122    */
123    public function uninstall()
124    {
125      GPCCore::rmDir(dirname(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY));
126      $this->deleteConfig();
127      $this->tablef->drop();
128      GPCCore::unregister($this->getPluginName());
129      return('');
130    }
131
132    public function activate()
133    {
134      $this->initConfig();
135      $this->loadConfig();
136
137      /*
138       * migration code
139       */
140      switch($this->config['installed'])
141      {
142        case '01.00.00':
143          $this->updateFrom_010000();
144        case '01.01.00':
145          $this->updateFrom_010100();
146        case '01.02.00':
147        case '01.02.01':
148        case '01.02.02':
149          $this->updateFrom_010202();
150        default:
151          // nothing to do...
152          break;
153      }
154
155      $this->config['installed']=GMAPS_VERSION2;
156      $this->saveConfig();
157
158      GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED);
159      GPCRequestBuilder::register($this->getPluginName(), dirname($this->getFileLocation()).'/gmaps_rb_callback.class.inc.php');
160      return('');
161    }
162
163    public function deactivate()
164    {
165      GPCRequestBuilder::unregister($this->getPluginName());
166    }
167
168
169    /**
170     * update from release 1.0.0
171     *
172     *  - create the /local/plugins/GMaps/kml directory
173     *  - move kml files from /plugins/GMaps/kml directory to the new directory
174     *  - remove the /plugins/GMaps/kml directory
175     */
176    private function updateFrom_010000()
177    {
178      if(!file_exists(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY))
179          mkdir(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY, 0755, true);
180
181      $directory=scandir(GMAPS_PATH.'kml/');
182      foreach($directory as $file)
183      {
184        $ext=(pathinfo($file, PATHINFO_EXTENSION));
185        if(preg_match('/.*(?:\.kml|\.kmz)$/i', $file))
186        {
187          rename(GMAPS_PATH.'kml/'.$file, GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::KML_DIRECTORY.$file);
188        }
189      }
190
191      GPCCore::rmDir(GMAPS_PATH.'kml');
192
193      $tablesUpdate=array(
194        $this->tables['maps'] => array(
195          'zoomLevelMaxActivated' => " ADD COLUMN `zoomLevelMaxActivated` CHAR(1)  NOT NULL DEFAULT 'n' AFTER `style` ",
196        )
197      );
198
199      $tablef=new GPCTables(array($this->tables['maps']));
200      $tablef->updateTablesFields($tablesUpdate);
201
202      unset($tablesUpdate);
203    }
204
205    /**
206     * update from release 1.1.0
207     *
208     */
209    private function updateFrom_010100()
210    {
211
212      $tablesUpdate=array(
213        $this->tables['category_maps'] => array(
214          'forceDisplay' => " ADD COLUMN `forceDisplay` CHAR(1)  NOT NULL DEFAULT 'n' AFTER `title` ",
215        )
216      );
217
218      $tablef=new GPCTables(array($this->tables['category_maps']));
219      $tablef->updateTablesFields($tablesUpdate);
220
221      unset($tablesUpdate);
222    }
223
224    /**
225     * update from release 1.2.2
226     *
227     */
228    private function updateFrom_010202()
229    {
230      $sql="DROP TABLE ".$this->tables['cache'];
231      pwg_query($sql);
232
233      $tablesCreate=array(
234"CREATE TABLE `".$this->tables['cache']."` (
235  `requestId` mediumint(8) UNSIGNED NOT NULL default '0',
236  `imageId` mediumint(8) NOT NULL,
237  `latitude` decimal(17,14) NOT NULL default '0',
238  `longitude` decimal(17,14) NOT NULL default '0',
239  PRIMARY KEY (`requestId`,`imageId`)
240)",
241"CREATE TABLE `".$this->tables['cache_id']."` (
242  `requestId` mediumint(8) UNSIGNED NOT NULL auto_increment,
243  `userId` smallint(5) NOT NULL,
244  `date` timestamp NOT NULL default '0000-00-00 00:00:00',
245  PRIMARY KEY (`requestId`)
246)"
247      );
248
249      $tablesDef = create_table_add_character_set($tablesCreate);
250
251      $tablef=new GPCTables(array($this->tables['cache'], $this->tables['cache_id']));
252      $tablef->create($tablesCreate);
253
254      unset($tablesCreate);
255    }
256
257
258  } //class
259
260?>
Note: See TracBrowser for help on using the repository browser.