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

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

Fix bugs on the install/update process

  • Property svn:executable set to *
File size: 6.2 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  PRIMARY KEY  (`id`),
85  KEY `byCategorie` (`categoryId`,`mapId`)
86)",
87"CREATE TABLE `".$this->tables['cache']."` (
88  `userId` smallint(5) NOT NULL,
89  `requestId` timestamp NOT NULL default '0000-00-00 00:00:00',
90  `imageId` mediumint(8) NOT NULL,
91  `latitude` decimal(20,17) NOT NULL default '0.00000000000000000',
92  `longitude` decimal(20,17) NOT NULL default '0.00000000000000000',
93  `imageName` varchar(255) NOT NULL,
94  `imageTnFile` varchar(255) NOT NULL,
95  `imageCatsId` varchar(255) NOT NULL,
96  `imageCatsNames` varchar(255) NOT NULL,
97  `imageCatsPLink` varchar(255) NOT NULL,
98  PRIMARY KEY  USING BTREE (`userId`,`requestId`,`imageId`)
99)",
100"CREATE TABLE `".$this->tables['kmlfiles']."` (
101  `id` int(10) unsigned NOT NULL auto_increment,
102  `file` varchar(255) NOT NULL,
103  `name` varchar(255) NOT NULL,
104  `fileDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
105  `fileSize` mediumint(8) unsigned NOT NULL,
106  PRIMARY KEY  (`id`)
107)"
108      );
109
110      $tables_def = create_table_add_character_set($tables_def);
111      $result=$this->tablef->create($tables_def);
112      unset($tables_def);
113
114      GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED);
115      return($result);
116    }
117
118
119    /*
120        function for uninstall process
121    */
122    public function uninstall()
123    {
124      GPCCore::rmDir(dirname(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY));
125      $this->deleteConfig();
126      $this->tablef->drop();
127      GPCCore::unregister($this->getPluginName());
128      return('');
129    }
130
131    public function activate()
132    {
133      $this->initConfig();
134      $this->loadConfig();
135
136      /*
137       * migration code
138       */
139      switch($this->config['installed'])
140      {
141        case '01.00.00';
142          $this->updateFrom_010000();
143        default:
144          // nothing to do...
145          break;
146      }
147
148      $this->config['installed']=GMAPS_VERSION2;
149      $this->saveConfig();
150
151      GPCCore::register($this->getPluginName(), GMAPS_VERSION, GMAPS_GPC_NEEDED);
152      GPCRequestBuilder::register($this->getPluginName(), dirname($this->getFileLocation()).'/gmaps_rb_callback.class.inc.php');
153      return('');
154    }
155
156    public function deactivate()
157    {
158      GPCRequestBuilder::unregister($this->getPluginName());
159    }
160
161
162    /**
163     * update from release 1.0.0
164     *
165     *  - create the /local/plugins/GMaps/kml directory
166     *  - move kml files from /plugins/GMaps/kml directory to the new directory
167     *  - remove the /plugins/GMaps/kml directory
168     */
169    private function updateFrom_010000()
170    {
171      if(!file_exists(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY))
172          mkdir(GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY, 0755, true);
173
174      $directory=scandir(GMAPS_PATH.'kml/');
175      foreach($directory as $file)
176      {
177        $ext=(pathinfo($file, PATHINFO_EXTENSION));
178        if(preg_match('/.*(?:\.kml|\.kmz)$/i', $file))
179        {
180          rename(GMAPS_PATH.'kml/'.$file, GPCCore::getPiwigoSystemPath().self::KML_DIRECTORY.$file);
181        }
182      }
183
184      GPCCore::rmDir(GMAPS_PATH.'kml');
185
186      $tablesUpdate=array(
187        $this->tables['maps'] => array(
188          'zoomLevelMaxActivated' => " ADD COLUMN `zoomLevelMaxActivated` CHAR(1)  NOT NULL DEFAULT 'n' AFTER `style` ",
189        )
190      );
191
192      $tablef=new GPCTables(array($this->tables['maps']));
193      $tablef->updateTablesFields($tablesUpdate);
194
195      unset($tablesUpdate);
196    }
197
198  } //class
199
200?>
Note: See TracBrowser for help on using the repository browser.