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

Last change on this file since 7548 was 7548, checked in by grum, 10 years ago

fix bug on upgrade process 1.1.0 => 1.2.0

  • Property svn:executable set to *
File size: 6.8 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().self::KML_DIRECTORY))
45      {
46        mkdir(GPCCore::getPiwigoSystemPath().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  `userId` smallint(5) NOT NULL,
90  `requestId` timestamp NOT NULL default '0000-00-00 00:00:00',
91  `imageId` mediumint(8) NOT NULL,
92  `latitude` decimal(20,17) NOT NULL default '0.00000000000000000',
93  `longitude` decimal(20,17) NOT NULL default '0.00000000000000000',
94  `imageName` varchar(255) NOT NULL,
95  `imageTnFile` varchar(255) NOT NULL,
96  `imageCatsId` varchar(255) NOT NULL,
97  `imageCatsNames` varchar(255) NOT NULL,
98  `imageCatsPLink` varchar(255) NOT NULL,
99  PRIMARY KEY  USING BTREE (`userId`,`requestId`,`imageId`)
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().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        default:
147          // nothing to do...
148          break;
149      }
150
151      $this->config['installed']=GMAPS_VERSION2;
152      $this->saveConfig();
153
154      GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED);
155      GPCRequestBuilder::register($this->getPluginName(), dirname($this->getFileLocation()).'/gmaps_rb_callback.class.inc.php');
156      return('');
157    }
158
159    public function deactivate()
160    {
161      GPCRequestBuilder::unregister($this->getPluginName());
162    }
163
164
165    /**
166     * update from release 1.0.0
167     *
168     *  - create the /local/plugins/GMaps/kml directory
169     *  - move kml files from /plugins/GMaps/kml directory to the new directory
170     *  - remove the /plugins/GMaps/kml directory
171     */
172    private function updateFrom_010000()
173    {
174      if(!file_exists(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY))
175          mkdir(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY, 0755, true);
176
177      $directory=scandir(GMAPS_PATH.'kml/');
178      foreach($directory as $file)
179      {
180        $ext=(pathinfo($file, PATHINFO_EXTENSION));
181        if(preg_match('/.*(?:\.kml|\.kmz)$/i', $file))
182        {
183          rename(GMAPS_PATH.'kml/'.$file, GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file);
184        }
185      }
186
187      GPCCore::rmDir(GMAPS_PATH.'kml');
188
189      $tablesUpdate=array(
190        $this->tables['maps'] => array(
191          'zoomLevelMaxActivated' => " ADD COLUMN `zoomLevelMaxActivated` CHAR(1)  NOT NULL DEFAULT 'n' AFTER `style` ",
192        )
193      );
194
195      $tablef=new GPCTables(array($this->tables['maps']));
196      $tablef->updateTablesFields($tablesUpdate);
197
198      unset($tablesUpdate);
199    }
200
201    /**
202     * update from release 1.1.0
203     *
204     */
205    private function updateFrom_010100()
206    {
207
208      $tablesUpdate=array(
209        $this->tables['category_maps'] => array(
210          'forceDisplay' => " ADD COLUMN `forceDisplay` CHAR(1)  NOT NULL DEFAULT 'n' AFTER `title` ",
211        )
212      );
213
214      $tablef=new GPCTables(array($this->tables['category_maps']));
215      $tablef->updateTablesFields($tablesUpdate);
216
217      unset($tablesUpdate);
218    }
219
220
221
222  } //class
223
224?>
Note: See TracBrowser for help on using the repository browser.