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

Last change on this file since 7479 was 7479, checked in by grum, 13 years ago

implement feature:1950

  • Property svn:executable set to *
File size: 6.8 KB
RevLine 
[7054]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');
[7386]19   include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php');
[7054]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    {
[7308]44      if(!file_exists(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY))
45      {
46        mkdir(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY, 0755, true);
47      }
48
[7054]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(
[7125]56"CREATE TABLE `".$this->tables['maps']."` (
[7054]57  `id` int(10) unsigned NOT NULL auto_increment,
58  `name` varchar(80) NOT NULL,
[7125]59  `displayType` char(2) NOT NULL,
60  `sizeMode` char(1) NOT NULL,
[7054]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',
[7177]68  `streetViewControl` char(1) NOT NULL default 'n',
[7054]69  `style` varchar(512) NOT NULL,
[7308]70  `zoomLevelMaxActivated` char(1) NOT NULL default 'n',
[7125]71  PRIMARY KEY  (`id`)
[7054]72)",
[7125]73"CREATE TABLE `".$this->tables['category_maps']."` (
[7054]74  `id` int(10) unsigned NOT NULL auto_increment,
[7125]75  `categoryId` smallint(5) unsigned NOT NULL,
76  `mapId` int(11) NOT NULL,
77  `imgSort` smallint(5) unsigned NOT NULL default '0',
[7054]78  `applySubCat` char(1) NOT NULL default 'y',
[7132]79  `kmlFileId` int(10) unsigned NOT NULL default '0',
[7054]80  `kmlFileUrl` varchar(255) NOT NULL,
[7125]81  `icon` varchar(255) NOT NULL,
[7139]82  `marker` varchar(255) NOT NULL,
[7125]83  `title` varchar(200) NOT NULL,
[7479]84  `forceDisplay` char(1) NOT NULL default 'n',
[7054]85  PRIMARY KEY  (`id`),
[7125]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`)
[7132]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`)
[7054]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    {
[7386]125      GPCCore::rmDir(dirname(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY));
[7054]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      {
[7479]142        case '01.00.00':
[7308]143          $this->updateFrom_010000();
[7479]144        case '01.00.01':
145        case '01.00.02':
146          $this->updateFrom_010002();
[7054]147        default:
148          // nothing to do...
149          break;
150      }
151
152      $this->config['installed']=GMAPS_VERSION2;
153      $this->saveConfig();
154
155      GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED);
[7128]156      GPCRequestBuilder::register($this->getPluginName(), dirname($this->getFileLocation()).'/gmaps_rb_callback.class.inc.php');
[7054]157      return('');
158    }
159
160    public function deactivate()
161    {
162      GPCRequestBuilder::unregister($this->getPluginName());
163    }
164
[7308]165
166    /**
167     * update from release 1.0.0
168     *
169     *  - create the /local/plugins/GMaps/kml directory
170     *  - move kml files from /plugins/GMaps/kml directory to the new directory
171     *  - remove the /plugins/GMaps/kml directory
172     */
173    private function updateFrom_010000()
174    {
[7386]175      if(!file_exists(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY))
176          mkdir(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY, 0755, true);
[7308]177
178      $directory=scandir(GMAPS_PATH.'kml/');
179      foreach($directory as $file)
180      {
181        $ext=(pathinfo($file, PATHINFO_EXTENSION));
182        if(preg_match('/.*(?:\.kml|\.kmz)$/i', $file))
183        {
184          rename(GMAPS_PATH.'kml/'.$file, GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file);
185        }
186      }
187
[7386]188      GPCCore::rmDir(GMAPS_PATH.'kml');
[7308]189
190      $tablesUpdate=array(
[7386]191        $this->tables['maps'] => array(
[7308]192          'zoomLevelMaxActivated' => " ADD COLUMN `zoomLevelMaxActivated` CHAR(1)  NOT NULL DEFAULT 'n' AFTER `style` ",
193        )
194      );
195
196      $tablef=new GPCTables(array($this->tables['maps']));
197      $tablef->updateTablesFields($tablesUpdate);
198
199      unset($tablesUpdate);
200    }
201
[7479]202    /**
203     * update from release 1.0.2
204     *
205     */
206    private function updateFrom_010002()
207    {
208
209      $tablesUpdate=array(
210        $this->tables['category_maps'] => array(
211          'forceDisplay' => " ADD COLUMN `forceDisplay` CHAR(1)  NOT NULL DEFAULT 'n' AFTER `title` ",
212        )
213      );
214
215      $tablef=new GPCTables(array($this->tables['category_maps']));
216      $tablef->updateTablesFields($tablesUpdate);
217
218      unset($tablesUpdate);
219    }
220
221
222
[7054]223  } //class
224
225?>
Note: See TracBrowser for help on using the repository browser.